[AD] TTF addon workabout patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Attached is a patch to fix the bug I described in an earlier message. Before, font height was defined by the size you passed to the al_ttf_load_font. This is wrong for most cases, as the screen DPI is undefined. A more useful value is the maximum ascent of font's characters. This value will correspond to the height, in pixels, above the baseline of the font.

The patch achieves that by measuring the ascent of the capital 'M' character, which I guess is the highest letter in most character sets. This is a workabout right now, as I couldn't stick this check inside that loop which checks through the characters. Someone with a greater knowledge of the Free Type library can make that change.

The examples naturally have their texts moved a bit, but without major issue from what I could see.

-SiegeLord


      
Index: addons/ttf/ttf.c
===================================================================
--- addons/ttf/ttf.c	(revision 11147)
+++ addons/ttf/ttf.c	(working copy)
@@ -187,7 +187,10 @@
     TRACE("al-ttf: %s: Preparing cache for %d glyphs.\n", filename, m);
 
     f = _AL_MALLOC(sizeof *f);
-    f->height = size;
+    
+    FT_Load_Char(face, (unsigned int)0x4D, FT_LOAD_DEFAULT);
+    FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
+    f->height = face->glyph->bitmap_top;
     f->vtable = &vt;
     f->data = data;
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/