[mapguide-commits] r1245 - trunk/MgDev/Common/Stylization

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Mar 15 15:18:30 EDT 2007


Author: traianstanev
Date: 2007-03-15 15:18:29 -0400 (Thu, 15 Mar 2007)
New Revision: 1245

Modified:
   trunk/MgDev/Common/Stylization/RS_Font.h
   trunk/MgDev/Common/Stylization/RS_FontEngine.cpp
Log:
This submission improves on the text vertical alignment computation, in particular the Capline and Halfline alignments. The problem was that FreeType doesn't know the font's capline height design metric, so we used the ascent line instead. Those can be very different (for example by 20% of the font size), which resulted in text which should be vertically centered being off by 2 pixels, which was causing me internal bleeding. I fixed this by adding a piece of code to measure the cap height of the font. It's easy, just measure the height of the letter A. It's a cap and it has a height. Then I remember the value for future use, since measuring of text is slow.

Modified: trunk/MgDev/Common/Stylization/RS_Font.h
===================================================================
--- trunk/MgDev/Common/Stylization/RS_Font.h	2007-03-15 18:43:40 UTC (rev 1244)
+++ trunk/MgDev/Common/Stylization/RS_Font.h	2007-03-15 19:18:29 UTC (rev 1245)
@@ -42,7 +42,8 @@
             m_fullname(L""),
             m_familyname(L""),
             m_index(0),
-            m_filename(L"")
+            m_filename(L""),
+            m_capheight(0)
         {
         }
 
@@ -57,6 +58,7 @@
         short          m_ascender;
         short          m_descender;
         short          m_height;
+        short          m_capheight;
 
         short          m_max_advance_width;
         short          m_max_advance_height;

Modified: trunk/MgDev/Common/Stylization/RS_FontEngine.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/RS_FontEngine.cpp	2007-03-15 18:43:40 UTC (rev 1244)
+++ trunk/MgDev/Common/Stylization/RS_FontEngine.cpp	2007-03-15 19:18:29 UTC (rev 1245)
@@ -252,7 +252,7 @@
 //if it chooses to scale the font to make it better fit the given path
 bool RS_FontEngine::LayoutPathText(RS_TextMetrics& tm,
                         const RS_F_Point* pts, int npts, double* seglens,
-                        double param_position, RS_VAlignment valign, int layout_option)
+                        double param_position, RS_VAlignment valign, int /*layout_option*/)
 {
     int numchars = (int)tm.text.length();
     tm.char_pos.reserve(numchars);
@@ -462,9 +462,7 @@
     //return value will be positive if y goes down and negative if y goes up 
     //i.e. it's the offset we need to apply to y in the coordinate system of the 
     //renderer
-    double voffset = GetVerticalAlignmentOffset(valign, tm.font, 
-        tm.text_height, //for path labeling, using actualy string height rather than font height works better...
-        tm.font_height * 1.05, 1);
+    double voffset = GetVerticalAlignmentOffset(valign, tm.font, tm.font_height, tm.font_height * 1.05, 1);
 
     //apply vertical alignment to character position
     //horizontal alignment is ignored in this case
@@ -703,8 +701,20 @@
     double em_square_size = font->m_units_per_EM;
     double font_ascent    = font->m_ascender * actual_height / em_square_size;
     double font_descent   = font->m_descender * actual_height / em_square_size;
-    double font_capline   = actual_height;
 
+    if (font->m_capheight == 0)
+    {
+        //happy hack to get the capline since FreeType doesn't know it
+
+        RS_F_Point fpts[4];
+        MeasureString(L"A", em_square_size, font, 0.0, fpts, NULL);
+        
+        //set it on the font, so that we don't have to measure it all the time 
+        ((RS_Font*)font)->m_capheight = (short)fabs(fpts[2].y - fpts[1].y);
+    }
+
+    double font_capline = font->m_capheight * actual_height / em_square_size;
+
     switch (vAlign)
     {
     case RS_VAlignment_Descent:



More information about the mapguide-commits mailing list