shithub: freetype+ttf2subf

Download patch

ref: bce2986d0d884886ae76e024b55199996cf6b52c
parent: 2b30c17fd389586fe8955b9346fc665f73accb30
author: David Turner <[email protected]>
date: Fri Dec 14 09:52:58 EST 2001

fixing hinted advance width bug in all font drivers

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2001-12-14  David Turner  <[email protected]>
+
+    * src/truetype/ttgload.c (TT_Load_Glyph), src/type1/t1gload.c
+    (T1_Load_Glyph), src/cid/cidgload.c (CID_Load_Glyph), src/cff/cffgload.c
+    (CFF_Load_Glyph): fixed an important bug common to all font drivers (the
+    advance width was never hinted when it should)
+
+
 2001-12-12  David Turner  <[email protected]>
 
     * src/pshint/pshglob.c: adding correct BlueScale/BlueShift support,
@@ -24,7 +32,7 @@
 
 	* docs/FTL.TXT: Simple fix (change "LICENSE.TXT" to "FTL.TXT").
 
-	* builds/unix/freetype2.m4: New file for checking configure paths. 
+	* builds/unix/freetype2.m4: New file for checking configure paths.
 	We need to install it in $(prefix)/share/aclocal/freetype2.m4 but I
 	didn't modify builds/unix/install.mk yet.
 
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -35,6 +35,7 @@
   /*                                                                       */
 #define FREETYPE_MAJOR 2
 #define FREETYPE_MINOR 0
+#define FREETYPE_PATCH 5
 
 
 #include <ft2build.h>
--- a/include/freetype/ftglyph.h
+++ b/include/freetype/ftglyph.h
@@ -65,6 +65,24 @@
 
   /*************************************************************************/
   /*                                                                       */
+  /* <Type>                                                                */
+  /*    FT_Glyph                                                           */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Handle to an object used to model generic glyph images. It's a     */
+  /*    pointer to the @FT_GlyphRec structure and can contain a glyph      */
+  /*    bitmap or pointer..                                                */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    glyph objects are not owned by the library. You must thus release  */
+  /*    them manually (through @FT_Done_Glyph) _before_ calling            */
+  /*    @FT_Done_FreeType.                                                 */
+  /*                                                                       */
+  typedef struct FT_GlyphRec_*    FT_Glyph;
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* <Struct>                                                              */
   /*    FT_GlyphRec                                                        */
   /*                                                                       */
@@ -88,11 +106,23 @@
     FT_Glyph_Format        format;
     FT_Vector              advance;
 
-  } FT_GlyphRec, *FT_Glyph;
+  } FT_GlyphRec;
 
 
   /*************************************************************************/
   /*                                                                       */
+  /* <Type>                                                                */
+  /*    FT_BitmapGlyph                                                     */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Handle to an object used to model a bitmap glyph image. This is    */
+  /*    a sub-class of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec      */
+  /*                                                                       */
+  typedef struct FT_BitmapGlyphRec_*    FT_BitmapGlyph;
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* <Struct>                                                              */
   /*    FT_BitmapGlyphRec                                                  */
   /*                                                                       */
@@ -128,11 +158,23 @@
     FT_Int       top;
     FT_Bitmap    bitmap;
 
-  } FT_BitmapGlyphRec, *FT_BitmapGlyph;
+  } FT_BitmapGlyphRec;
 
 
   /*************************************************************************/
   /*                                                                       */
+  /* <Type>                                                                */
+  /*    FT_OutlineGlyph                                                    */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Handle to an object used to model an outline glyph image. This is  */
+  /*    a sub-class of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec     */
+  /*                                                                       */
+  typedef struct FT_OutlineGlyphRec_*    FT_OutlineGlyph;
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* <Struct>                                                              */
   /*    FT_OutlineGlyphRec                                                 */
   /*                                                                       */
@@ -162,7 +204,7 @@
     FT_GlyphRec  root;
     FT_Outline   outline;
 
-  } FT_OutlineGlyphRec, *FT_OutlineGlyph;
+  } FT_OutlineGlyphRec;
 
 
   /*************************************************************************/
--- a/src/base/ftdbgmem.c
+++ b/src/base/ftdbgmem.c
@@ -163,8 +163,8 @@
   {
     FT_Memory   memory = table->memory;
     FT_Pointer  block;
-    
 
+
     memory->user = table->memory_user;
     block = table->alloc( memory, size );
     memory->user = table;
@@ -178,8 +178,8 @@
                      FT_Pointer   block )
   {
     FT_Memory  memory = table->memory;
-    
 
+
     memory->user = table->memory_user;
     table->free( memory, block );
     memory->user = table;
@@ -297,7 +297,7 @@
 
           if ( node->size > 0 )
           {
-            printf( 
+            printf(
               "leaked memory block at address %p, size %8ld in (%s:%ld)\n",
               node->address, node->size,
               FT_FILENAME( node->alloc_file_name ),
@@ -485,8 +485,8 @@
 
     return (FT_Pointer) block;
   }
-  
 
+
   extern void
   ft_mem_debug_free( FT_Memory   memory,
                      FT_Pointer  block )
@@ -505,8 +505,8 @@
     table->file_name = NULL;
     table->line_no   = 0;
   }
-  
 
+
   extern FT_Pointer
   ft_mem_debug_realloc( FT_Memory   memory,
                         FT_Long     cur_size,
@@ -520,7 +520,7 @@
     const char*  file_name = FT_FILENAME( table->file_name );
     FT_Long      line_no   = table->line_no;
 
- 
+
     if ( block == NULL || cur_size == 0 )
       ft_mem_debug_panic( "trying to reallocate NULL in (%s:%ld)",
                            file_name, line_no );
@@ -620,7 +620,7 @@
       table->line_no   = line_no;
     }
     return FT_Alloc( memory, size, P );
-  }            
+  }
 
 
   FT_BASE_DEF( FT_Error )
@@ -640,7 +640,7 @@
       table->line_no   = line_no;
     }
     return FT_Realloc( memory, current, size, P );
-  }                    
+  }
 
 
   FT_BASE_DEF( void )
@@ -662,9 +662,9 @@
 
 
 #else  /* !FT_DEBUG_MEMORY */
- 
+
   /* ANSI C doesn't like empty source files */
-  extern const FT_Byte  _debug_mem_dummy = 0;
+  const FT_Byte  _debug_mem_dummy = 0;
 
 #endif /* !FT_DEBUG_MEMORY */
 
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -1065,18 +1065,18 @@
           FT_TRACE4(( op == cff_op_hstem   ? " hstem"   :
                     ( op == cff_op_vstem   ? " vstem"   :
                     ( op == cff_op_hstemhm ? " hstemhm" : " vstemhm" )) ));
-          
+
           if ( hinter )
             hinter->stems( hinter->hints,
                            ( op == cff_op_vstem || op == cff_op_vstemhm ),
                            num_args/2,
                            args );
-            
+
           decoder->num_hints += num_args / 2;
           args = stack;
           break;
-        
 
+
         case cff_op_hintmask:
         case cff_op_cntrmask:
           FT_TRACE4(( op == cff_op_hintmask ? " hintmask" : " cntrmask" ));
@@ -1095,7 +1095,7 @@
                                (decoder->num_hints+7) >> 3,
                                ip );
           }
-                              
+
 #ifdef FT_DEBUG_LEVEL_TRACE
           {
             FT_UInt maskbyte;
@@ -1647,7 +1647,7 @@
           {
             if (hinter->close( hinter->hints, builder->current->n_points ))
               goto Syntax_Error;
-            
+
             /* apply hints to the loaded glyph outline now */
             hinter->apply( hinter->hints,
                            builder->current,
@@ -2301,6 +2301,15 @@
 
           metrics->vertBearingX = FT_MulFix( metrics->vertBearingX, x_scale );
           metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, y_scale );
+
+          if ( hinting )
+          {
+            metrics->horiAdvance = (metrics->horiAdvance+32) & -64;
+            metrics->vertAdvance = (metrics->vertAdvance+32) & -64;
+
+            metrics->vertBearingX = (metrics->vertBearingX+32) & -64;
+            metrics->vertBearingY = (metrics->vertBearingY+32) & -64;
+          }
         }
 
         /* compute the other metrics */
--- a/src/cid/cidgload.c
+++ b/src/cid/cidgload.c
@@ -330,6 +330,15 @@
 
           metrics->vertBearingX = FT_MulFix( metrics->vertBearingX, x_scale );
           metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, y_scale );
+
+          if ( hinting )
+          {
+            metrics->horiAdvance = (metrics->horiAdvance+32) & -64;
+            metrics->vertAdvance = (metrics->vertAdvance+32) & -64;
+
+            metrics->vertBearingX = (metrics->vertBearingX+32) & -64;
+            metrics->vertBearingY = (metrics->vertBearingY+32) & -64;
+          }
         }
 
         /* compute the other metrics */
--- a/src/pshinter/pshglob.c
+++ b/src/pshinter/pshglob.c
@@ -383,10 +383,10 @@
     /*                                                        */
     {
       FT_Int  threshold = blues->blue_shift;
-      
+
       while ( threshold > 0 && FT_MulFix( threshold, scale ) > 32 )
         threshold --;
-      
+
       blues->blue_threshold = threshold;
     }
 
@@ -434,11 +434,11 @@
 
     /* process the families now */
     for ( num = 0; num < 2; num++ )
-    { 
+    {
       PSH_Blue_Zone    zone1, zone2;
       FT_UInt          count1, count2;
       PSH_Blue_Table   normal, family;
-      
+
       switch (num)
       {
         case 0:
@@ -445,12 +445,12 @@
           normal = &blues->normal_top;
           family = &blues->family_top;
           break;
-          
+
         default:
           normal = &blues->normal_bottom;
           family = &blues->family_bottom;
       }
-      
+
       zone1  = normal->zones;
       count1 = normal->count;
       for ( ; count1 > 0; count1--, zone1++ )
@@ -640,8 +640,9 @@
 
       globals->blues.blue_scale = priv->blue_scale ? priv->blue_scale
                                                    : (0.039625*0x400000L);
-      
-      globals->blues.blue_shift = priv->blue_shift;
+
+      globals->blues.blue_shift = priv->blue_shift ? priv->blue_shift
+                                                   : 7;
 
       globals->dimension[0].scale_mult  = 0;
       globals->dimension[0].scale_delta = 0;
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -1174,6 +1174,10 @@
     glyph->metrics.horiBearingY = bbox.yMax;
     glyph->metrics.horiAdvance  = loader->pp2.x - loader->pp1.x;
 
+    /* don't forget to hint the advance when we need to */
+    if ( IS_HINTED( loader->load_flags ) )
+      glyph->metrics.horiAdvance = (glyph->metrics.horiAdvance+32) & -64;
+
     /* Now take care of vertical metrics.  In the case where there is    */
     /* no vertical information within the font (relatively common), make */
     /* up some metrics by `hand'...                                      */
--- a/src/type1/t1gload.c
+++ b/src/type1/t1gload.c
@@ -277,6 +277,15 @@
 
           metrics->vertBearingX = FT_MulFix( metrics->vertBearingX, x_scale );
           metrics->vertBearingY = FT_MulFix( metrics->vertBearingY, y_scale );
+
+          if ( hinting )
+          {
+            metrics->horiAdvance = (metrics->horiAdvance+32) & -64;
+            metrics->vertAdvance = (metrics->vertAdvance+32) & -64;
+
+            metrics->vertBearingX = (metrics->vertBearingX+32) & -64;
+            metrics->vertBearingY = (metrics->vertBearingY+32) & -64;
+          }
         }
 
         /* compute the other metrics */