Bad return code when loading miniwindow fonts under Wine

Posted by Izocinoc on Sat 20 Dec 2008 12:16 AM — 3 posts, 13,911 views.

#0
The function WindowFont appears to return eOK regardless of whether the font is loaded correctly. I am running MUSHClient version 4.37 on Ubuntu. I put together the following test script.


font_name = "bad_font_name"
if WindowFont(win, "test_font", font_name, 8, false, false, false, false, 0, 49) == error_code.eOK then
  Note('Font loaded successfully')
else
  Note('Error loading font')
end

fonts = WindowFontList(win)
if fonts then
  for _, v in ipairs (fonts) do 
    Note (v .. " -> " .. WindowFontInfo(win, v, 21)) 
  end
end


When I run the script, I get the output:
Font loaded successfully
test_font -> Courier New


It looks like WindowFont is returning eOK even though I'm passing it a bad font name, and I'm ending up with Courier New loaded.
Netherlands #1
This bug has been confirmed here on plain WXP, too. :)
Australia Forum Administrator #2
It's not exactly a bug - you asked for a font which matched various specifications, and Windows (or Wine) did the best it could to match those. You did, after all, get a font loaded.

By comparison, if you create a word processor document using a font (eg. Comic) and then open it on a PC that doesn't have Comic installed, rather than no font at all, you are likely to end up with Courier, or the font that best matches the one you wanted (eg. serif / sans-serif), such as Helvetica.

If it really bothers you, you could make a wrapper function that loads the wanted font, and then checks that the font name (from WindowFontInfo) actually matches the font you wanted.

I assume you want some sort of font, so an approximation is better than nothing. You could do what I did in another thread, and check what is available, like this:


-- use 8 pt Dina or 10 pt Courier
  local fonts = utils.getfontfamilies ()

  -- choose a font that exists
  
  if fonts.Dina then
    font_name = "Dina"    
  elseif fonts ["Lucida Sans Unicode"] then
    font_name = "Lucida Sans Unicode"
  else
    font_size = 10
    font_name = "Courier"
  end -- if


This is checking for Dina or Lucida Sans Unicode, and then failing that, uses Courier. A similar bit of code could work its way from your most preferred to least preferred font.