freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] autohinter suggestions


From: David Chester
Subject: [Devel] autohinter suggestions
Date: Thu, 23 Jan 2003 21:24:31 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030109

Hello.

David Turner wrote:

I didn't include your blue-scale patch yet because I believe it should be possible to perform the same thing in a much more pleasant way that doesn't involve calling FT_Set_Char_Size within the auto-hinter.


I've attached a patch which does the same thing as the initial bluescale
patch, but it uses FT_Outline_Transform and rescales the metrics instead
of calling FT_Set_Char_Size.  This seems like a much cleaner way to go.

On a somewhat unrelated note, I have noticed that the "custom fix" in
the kerning code in the autohinter seems to do more harm than good.  I
am referring to line 1432 in ahhint.c, where it reads:

           /* try to fix certain bad advance computations */
if ( hinter->pp2.x + hinter->pp1.x == edge2->pos && old_rsb > 4 )
             hinter->pp2.x += 64;

When looking at Times New Roman at size 15 (with the attached patch
applied), for instnace, there is a significant improvement in the
consistency of the kerning if those lines are _not_ executed.  Since
ftview doesn't use the same calculations for kerning as ftstring or xft,
and since it is hard to notice on just one string of text, I have posted
an example from konqueror showing the difference:

http://www.cs.mcgill.ca/~dchest/xfthack/tnr-kerning.png

Are there other cases where those lines show an improvement?  I tried
a few fonts and sizes and only noticed an improvement without them.  Is
there any chance that those lines could be removed?

Thanks,

David Chester




diff -ru /home/dchest/ft-clean-cvs/freetype2/src/autohint/ahhint.c 
./src/autohint/ahhint.c
--- /home/dchest/ft-clean-cvs/freetype2/src/autohint/ahhint.c   2003-01-23 
15:03:28.000000000 -0500
+++ ./src/autohint/ahhint.c     2003-01-23 17:30:41.000000000 -0500
@@ -1189,7 +1189,40 @@
     globals->y_scale = y_scale;
   }
 
+  static void
+  ah_rescale_metrics( FT_Face            face,
+                      FT_Size_Metrics*   f_metrics,
+                      FT_Glyph_Metrics*  g_metrics,
+                      FT_Fixed           x_factor,
+                      FT_Fixed           y_factor )
+  {
+    /* Rescale face and glyph metrics */
+
+    f_metrics->ascender    = ( FT_MulFix( face->ascender,
+                                          f_metrics->y_scale ) + 32 ) & -64;
 
+    f_metrics->descender   = ( FT_MulFix( face->descender,
+                                          f_metrics->y_scale ) + 32 ) & -64;
+
+    f_metrics->height      = ( FT_MulFix( face->height,
+                                          f_metrics->y_scale ) + 32 ) & -64;
+
+    f_metrics->max_advance = ( FT_MulFix( face->max_advance_width,
+                                          f_metrics->x_scale ) + 32 ) & -64;
+  
+    g_metrics->width  = FT_MulFix( g_metrics->width,  x_factor );
+    g_metrics->height = FT_MulFix( g_metrics->height, y_factor );
+    
+    g_metrics->horiBearingX = FT_MulFix( g_metrics->horiBearingX, x_factor );
+    g_metrics->horiBearingY = FT_MulFix( g_metrics->horiBearingY, y_factor );
+    g_metrics->horiAdvance  = FT_MulFix( g_metrics->horiAdvance,  x_factor );
+
+    g_metrics->vertBearingX = FT_MulFix( g_metrics->vertBearingX, x_factor );
+    g_metrics->vertBearingY = FT_MulFix( g_metrics->vertBearingY, y_factor );
+    g_metrics->vertAdvance  = FT_MulFix( g_metrics->vertAdvance,  y_factor );
+    
+  }
+  
   static void
   ah_hinter_align( AH_Hinter  hinter )
   {
@@ -1322,6 +1355,44 @@
     if ( error )
       goto Exit;
 
+    {
+      /* scale the outline so the AH_BLUE_SMALL_TOP edge is already aligned */
+        
+      FT_Matrix          matrix;
+      FT_Pos             active_blue, fitted_blue;
+      FT_Fixed           y_factor, x_factor;
+      FT_Fixed           narrow_adjust = 0.985 * 0x10000L;
+      AH_Globals         globals = &hinter->globals->design;
+      FT_Size_Metrics*   metrics = &face->size->metrics;
+        
+
+      active_blue = FT_MulFix( globals->blue_shoots[AH_BLUE_SMALL_TOP], 
+                               y_scale );
+                               
+      fitted_blue = ( active_blue + 32 ) & -64;
+      
+      y_factor = FT_DivFix( ( 0x10000L * fitted_blue ),
+                            ( 0x10000L * active_blue ) );
+      
+      if ( y_factor > 0x10000L )
+        x_factor = narrow_adjust;  
+      else
+        x_factor = y_factor;
+      
+      matrix.xx = x_factor;
+      matrix.xy = 0;
+      matrix.yx = 0;
+      matrix.yy = y_factor;
+              
+      FT_Outline_Transform( &slot->outline, &matrix );
+      
+      metrics->x_scale = FT_MulFix( x_factor, metrics->x_scale );
+      metrics->y_scale = FT_MulFix( y_factor, metrics->y_scale );
+       
+      ah_rescale_metrics( face, metrics, &slot->metrics, x_factor, y_factor );
+      
+    }
+          
     /* Set `hinter->transformed' after loading with FT_LOAD_NO_RECURSE. */
     hinter->transformed = internal->glyph_transformed;
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]