Page 1 of 1

Cross-platform fonts

Posted: Fri Feb 13, 2009 3:15 am
by mpthompson
I'm relatively new to wxWidgets so I hope this question isn't silly. I'm working on a cross-platform application where I would like drawings created using wxDC methods to be bit identical across Windows, Mac and Linux platforms.

My issue concerns fonts selected into the DC. I'm assuming that the following code will select into the DC a font that is unique to each platform and be rendered in subtly different ways. Is this correct?

Code: Select all

dc.DrawText("Test Text", textPos.x, textPos.y);
If so, are there techniques I can use to select into the DC a cross-platform bitmap font that will render identical on various platforms?

Any help or suggestions on places to look for a solution would be appreciated.


Mike Thompson

Posted: Fri Feb 13, 2009 3:04 pm
by Auria
This is unfortunately the case; worse, I found that not all platforms interpret font sizes the same way (on mac, for instance, fonts are much smaller than on GTK). Unfortunately I have found no way to get exactly the same render. You might try to ask for a specific font name, though you would need to make sure it's installed everywhere. For size, I know there is wxSMALL_FONT or something like that; otherwise you'll probably need to just use trial-and-error :?

Posted: Fri Feb 13, 2009 3:25 pm
by Disch
If worse comes to worse you can distribute the desired font file with your program (or embed it) and use something like FreeType, which takes a font file and renders glyphs from it. You won't be able to use wx's usual text rendering functions but you could wrap some kind of wx interface around it so that each character would be a Blit().

Would be a lot of work and wouldn't be as flexible in a lot of ways (something like setting a background color or changing the font color would likely require re-rendering the entire font), but if you're desperate for consistency...

Posted: Fri Feb 13, 2009 6:14 pm
by mpthompson
OK, thanks for the confirmation regarding the rendering of text on the DC. I'll try to get by with the "trial and error" approach of choosing the fonts that best match each other on a cross-platform basis. If that doesn't work I guess I'll have to come up with a more complex approach as described above and use a method of rendering text independent of the wxDC functions.

If I do come up with some solution I'll post a follow up.