shithub: freetype+ttf2subf

Download patch

ref: adf07a930cb0ce44a57018a2c5edbc9ac8916d88
parent: 9d7e5e8b8b455c10e6429827f2e8f00047261c52
author: David Turner <[email protected]>
date: Tue Oct 30 18:51:24 EST 2001

* src/smooth/ftgrays.c: adding experimental "gamma" support. This
	produces smoother glyphs at small sizes for very little cost

	* src/autohint/ahglyph.c, src/autohint/ahhint.c: various fixes to
	the auto-hinter. They merely improve the output of sans-serif fonts.
	Note that there are still problems with serifed fonts and composites
	(accented characters)

	* tests/gview.c: updated the debugging glyph viewer to show the
	hints generated by the "autohint" module

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2001-10-29  David Turner       <[email protected]>
+
+	* src/smooth/ftgrays.c: adding experimental "gamma" support. This
+	produces smoother glyphs at small sizes for very little cost
+	
+	* src/autohint/ahglyph.c, src/autohint/ahhint.c: various fixes to
+	the auto-hinter. They merely improve the output of sans-serif fonts.
+	Note that there are still problems with serifed fonts and composites
+	(accented characters)
+	
+	* tests/gview.c: updated the debugging glyph viewer to show the
+	hints generated by the "autohint" module
+
+
 2001-10-27  David Turner       <[email protected]>
 
 	* src/cache/ftchunk.c (ftc_chunk_cache_lookup): fixed a bug that
--- a/src/autohint/ahglyph.c
+++ b/src/autohint/ahglyph.c
@@ -994,7 +994,7 @@
                 dist = -dist;
 
               if ( len < 8 )
-                score = 300 + dist;
+                score = 300*8 + dist - len*3;
               else
                 score = dist + 300/len;
 
--- a/src/autohint/ahhint.c
+++ b/src/autohint/ahhint.c
@@ -169,10 +169,12 @@
     if ( base->flags & ah_edge_done )
     {
       if ( dist >= 64 )
-        dist = ( dist + 8 ) & -64;
+        dist = (dist+8) & -64;
 
       else if ( dist <= 32 && !vertical )
         dist = ( dist + 33 ) >> 1;
+      else
+        dist = 0;
     }
 
     serif->pos = base->pos + sign * dist;
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -84,6 +84,10 @@
 #include <string.h>             /* for memcpy() */
 #include <setjmp.h>
 
+
+/* experimental support for gamma correction within the rasterizer */
+#define  GRAYS_USE_GAMMA
+
   /*************************************************************************/
   /*                                                                       */
   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
@@ -305,6 +309,10 @@
     void*    memory;
     jmp_buf  jump_buffer;
 
+#ifdef  GRAYS_USE_GAMMA
+    FT_Byte   gamma[257];
+#endif
+
   } TRaster, *PRaster;
 
 
@@ -1230,15 +1238,21 @@
 
     for ( ; count > 0; count--, spans++ )
     {
-      if ( spans->coverage )
+      FT_UInt  coverage = spans->coverage;
+
+#ifdef GRAYS_USE_GAMMA
+      coverage = raster->gamma[(FT_Byte)coverage];
+#endif
+      
+      if ( coverage )
 #if 1
-        MEM_Set( p + spans->x, (unsigned char)spans->coverage, spans->len );
+        MEM_Set( p + spans->x, (unsigned char)coverage, spans->len );
 #else /* 1 */
       {
         q     = p + spans->x;
         limit = q + spans->len;
         for ( ; q < limit; q++ )
-          q[0] = (unsigned char)spans->coverage;
+          q[0] = (unsigned char)coverage;
       }
 #endif /* 1 */
     }
@@ -1960,6 +1974,33 @@
   /**** RASTER OBJECT CREATION: In standalone mode, we simply use *****/
   /****                         a static object.                  *****/
 
+#ifdef  GRAYS_USE_GAMMA
+
+  /* initialize the "gamma" table. Yes, this is really a crummy function */
+  /* but the results look pretty good for something that simple..        */
+  /*                                                                     */
+#define  M_MAX  255
+#define  M_X    128
+#define  M_Y    96
+
+  static void
+  grays_init_gamma( PRaster  raster )
+  {
+    FT_UInt  x, a;
+    
+    for ( x = 0; x < 256; x++ )
+    {
+      if ( x <= M_X )
+        a = (x * M_Y + (M_X/2)) / M_X;
+      else
+        a = M_Y + ((x-M_X)*(M_MAX-M_Y) + (M_MAX-M_X)/2)/(M_MAX-M_X);
+      
+      raster->gamma[x] = (FT_Byte)a;
+    }
+  }
+  
+#endif /* GRAYS_USE_GAMMA */
+
 #ifdef _STANDALONE_
 
   static int
@@ -1974,6 +2015,10 @@
     *araster = (FT_Raster)&the_raster;
     MEM_Set( &the_raster, 0, sizeof ( the_raster ) );
 
+#ifdef GRAYS_USE_GAMMA
+    grays_init_gamma( (PRaster)*araster );
+#endif
+    
     return 0;
   }
 
@@ -2000,6 +2045,10 @@
     {
       raster->memory = memory;
       *araster = (FT_Raster)raster;
+
+#ifdef GRAYS_USE_GAMMA
+      grays_init_gamma( raster );
+#endif
     }
 
     return error;