Cross-platform fonts Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mpthompson
In need of some credit
In need of some credit
Posts: 8
Joined: Fri Feb 13, 2009 1:43 am

Cross-platform fonts

Post 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

wxFont font(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
dc.SetFont(font);
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.

Thanks,

Mike Thompson
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post 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 :?
User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post 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...
mpthompson
In need of some credit
In need of some credit
Posts: 8
Joined: Fri Feb 13, 2009 1:43 am

Post 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.
Post Reply