PDA

View Full Version : Win32 native fonts: CreateFont vs FreeType



kbluck
09-22-2008, 05:42 AM
I think I'm almost there with my changes to enable third-party windowing library integration as described in the "Clanlib on Fltk", but I've run into one final roadblock that I need some consensus on.

I found that the CL_GraphicContext class has a Win32-only accessor: HDC get_drawable(). This is a bit of a problem for me, since I've been busily eliminating explicit references to the underlying platform-specific handles supplied by the window provider types in favor of a generic interface that can wrap other third-party providers. Now, I could hack in special support for this by requiring that adapter type to be able to provide an HDC on Win32, but it seems kludgy.

I've determined that the only place this special accessor is used appears to be in Win32 native font support. Creating fonts via Win32 API requires a DC. The problem is, this introduces a platform dependency and an assumption that there is a particular kind of window provider underneath. So, I'm trying to see if there's a way around this without having to hack in platform-specific accessors into what should be a platform-agnostic type.

My first thought is: since Clanlib is already using FreeType on Linux, is there any reason we don't want to just use FreeType all around for native fonts? In addition to solving my little problem, it would also have the advantage of helping to standardize font parameters and rendering; given the same TTF and parameters, fonts should come out much more consistently across platforms if it was always FreeType doing the rendering. We were actually just talking about getting away from Win32-specific font conventions in the "Linux Fonts" thread.

So, does using FreeType on Win32 as well as Linux/Mac seem like a good idea?

--- Kevin

rombust
09-22-2008, 06:49 AM
I added get_drawable() - it is a nasty hack, and i was meaning to remove it. ... so i will :)

The reason that we use native fonts on windows is because it looks so much nicer :)

rombust
09-22-2008, 07:35 AM
get_drawable() has now been removed from CL_GraphicContext API

I have just updated Freetype to v2.3.7 "All users should upgrade" ( http://www.freetype.org/index2.html#release-freetype-2.3.7 )

And it looks a LOT nicer. However the String Height reports an incorrect value

... Investigating...

... Fixed (simple bug)

Attached is a linux screengrab.

Compare this with the windows one (found at http://www.rtsoft.com/forums/attachment.php?attachmentid=215&d=1221120855 )

It is getting a lot better :)

kbluck
09-22-2008, 03:49 PM
> get_drawable() has now been removed from CL_GraphicContext API

Thanks, that's a big help.

I wonder how the fonts would compare if Linux and Win32 were actually using the same TTF? I'll have to get the "free" MS fonts installed on Ubuntu and see how it compares.

Installing the 'msttcorefonts' package is easy, and gets you a variety of MS fonts including the ubiquitous Arial and Times New Roman, but not the infamous Tahoma. Its crazy the extra trouble the Debian people had to undertake to observe MS's arbitrary requirement that the "filename or packaging format" must not be changed. "To promote cross-platform compatibility"... yeah, right.

Hmm, it appears that fontconfig picked up the new fonts, but FreeType seems to be munging them a bit on antialiasing. Not quite sure what to make of this; could this be an effect of the "patent-free" hinting? This computer has the Ubuntu packaged libfreetype6 v.2.3.5 installed.

--- Kevin

Magnus Norddahl
09-22-2008, 05:57 PM
At some point we probably should allow games to use freetype on Windows without trouble (or do we allow that easilly already?).

It is basically conflicting interests - when you are doing normal GUI apps you want the native font rasterizer for the platform, so you avoid the 'Safari looks weird on Windows' effect when all fonts in your app is rendered slightly different than everything else. On the other hand, a game really wants to look the same everywhere for artistic reasons, so a game would probably prefer using the freetype implementation on all platforms.

rombust
09-22-2008, 09:25 PM
Kevin, that screenshot is how it used to look on my ubuntu.

Today, through the package manager, there was an update to freetype, but i think that was was 2.3.5. I did not try it, instead I downloaded the latest one (from http://www.freetype.org )

When compiling it, i had to download the latest version of libtools (to run ./autogen.sh) and I compiled it using "./configure --prefix=/usr", but I am unsure if the prefix if required. (remember to sudo make install)

It should be very easy to make it optional for windows - to use either method (freetype or native). I'm not too sure whether to add a "use_native_font" flag to CL_Font, or create a CL_FontFreeType_Provider, like CL_FontBitmap_Provider - probably the latter would be nicer.

rombust
09-23-2008, 12:46 PM
I have changed the fonts in ClanLib SVN as follows:

1) All Sources/API/Display/Render/*font*.* moved into Sources/API/Display/Font

2) Split CL_FontProvider_Native into 2 classes: CL_FontProvider_Freetype and CL_FontProvider_Win32

3) Modified CL_OpenGLGraphicContextProvider::alloc_font() to create CL_FontProvider_Win32() for Windows Platform and CL_FontProvider_Freetype() for others Platforms

To use CL_Font_Freetype on the Win32 platform, you should be able to do:



CL_Font_Freetype font("Resources/font.ttf", 32);
CL_Font old_font = gc.set_font(font);
gc.draw_text(0, 300, cl_text("Hello World"), CL_Colorf::white);
gc.set_font(old_font);


To use CL_Font_Freetype with the GUI, you should be able to do:



CL_GUIManager gui;
...
CL_Font_Freetype font("Resources/font.ttf", 32);
gui.set_named_font(&font, "ClanLib Font", 32);
...
(Use "ClanLib Font" as the font name")


Very nice i think :)

This should work for Dicewar as well. If satisfactory, then "CL_OpenGLGraphicContextProvider::register_font()" can be removed.

*REMEMBER* To use the latest FreeType 2.3.7 for the windows platform, else the results will be terrible !

Magnus Norddahl
09-23-2008, 06:45 PM
Very nice, Mark. :)

I guess DiceWar should always use freetype - now we just need someone to volunteer compiling it for MSVC9 :)