Commit facd9af5424bab34d3aae75ed151225aa5551f0a

Wu, Chia-I (吳佳一) 2006-02-22T07:59:35

* modules.cfg: Compile in ftotval.c and ftxf86.c by default for ABI compatibility. * src/sfnt/sfobjs.c (sfnt_done_face): Fix a memory leak. * src/sfnt/ttsbit0.c (tt_sbit_decoder_load_bit_aligned, tt_sbit_decoder_load_byte_aligned) [FT_OPTIMIZE_MEMORY]: Fix sbit loading. (only tested with bit aligned sbit with x_pos == 0) * src/truetype/ttpload.c (tt_face_load_hdmx, tt_face_get_device_metrics) [FT_OPTIMIZE_MEMORY]: hdmx is not actually used.

diff --git a/ChangeLog b/ChangeLog
index fcbc5e9..27f2c3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2006-02-22  Chia-I Wu  <b90201047@ntu.edu.tw>
+
+	* modules.cfg: Compile in ftotval.c and ftxf86.c by default for ABI
+	compatibility.
+
+	* src/sfnt/sfobjs.c (sfnt_done_face): Fix a memory leak.
+
+	* src/sfnt/ttsbit0.c (tt_sbit_decoder_load_bit_aligned,
+	tt_sbit_decoder_load_byte_aligned) [FT_OPTIMIZE_MEMORY]: Fix sbit
+	loading. (only tested with bit aligned sbit with x_pos == 0)
+
+	* src/truetype/ttpload.c (tt_face_load_hdmx,
+	tt_face_get_device_metrics) [FT_OPTIMIZE_MEMORY]: hdmx is not actually
+	used.
+
 2006-02-21  David Turner  <david@freetype.org>
 
     * include/freetype/ftmodapi.h, include/internal/ftserv.h,
diff --git a/modules.cfg b/modules.cfg
index f251fd8..cf357cf 100644
--- a/modules.cfg
+++ b/modules.cfg
@@ -176,7 +176,7 @@ BASE_EXTENSIONS += ftmm.c
 # Interface for otvalid module (which is required).
 #
 # See include/freetype/ftotval.h for the API.
-# BASE_EXTENSIONS += ftotval.c
+BASE_EXTENSIONS += ftotval.c
 
 # Interface for accessing PFR-specific data.  Needs PFR font driver.
 #
@@ -209,7 +209,7 @@ BASE_EXTENSIONS += ftwinfnt.c
 # server.
 #
 # See include/freetype/ftxf86.h for the API.
-# BASE_EXTENSIONS += ftxf86.c
+BASE_EXTENSIONS += ftxf86.c
 
 
 ####
diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c
index 6b780e3..1516806 100644
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -1022,7 +1022,7 @@
     }
 
     /* freeing the horizontal metrics */
-#ifdef FT_OPTIMIZE_MEMORY
+#if defined FT_OPTIMIZE_MEMORY && !defined FT_CONFIG_OPTION_OLD_INTERNALS
     {
       FT_Stream  stream = FT_FACE_STREAM( face );
 
diff --git a/src/sfnt/ttsbit0.c b/src/sfnt/ttsbit0.c
index 1ade208..1a5efc9 100644
--- a/src/sfnt/ttsbit0.c
+++ b/src/sfnt/ttsbit0.c
@@ -489,9 +489,18 @@
         }
 
         if ( w > 0 )
-          wval = (FT_UInt)(wval | ( *p++ & ( 0xFF00U >> w ) ) );
+          wval = (FT_UInt)( wval | ( *p++ & ( 0xFF00U >> w ) ) );
+
+        /* all bits read and there are ( x_pos + w ) bits to be written */
 
         write[0] = (FT_Byte)( write[0] | ( wval >> x_pos ) );
+
+        if ( x_pos + w > 8 )
+        {
+          write++;
+          wval <<= 8;
+          write[0] = (FT_Byte)( write[0] | ( wval >> x_pos ) );
+        }
       }
     }
 
@@ -509,9 +518,9 @@
   {
     FT_Error    error = SFNT_Err_Ok;
     FT_Byte*    line;
-    FT_Int      bit_height, bit_width, pitch, width, height, h;
+    FT_Int      bit_height, bit_width, pitch, width, height, h, nbits;
     FT_Bitmap*  bitmap;
-    FT_UInt32   rval;
+    FT_UShort   rval;
 
 
     if ( !decoder->bitmap_allocated )
@@ -538,7 +547,7 @@
       goto Exit;
     }
 
-    if ( p + ( ( width + 7 ) >> 3 ) * height > limit )
+    if ( p + ( ( width  * height + 7 ) >> 3 ) > limit )
     {
       error = SFNT_Err_Invalid_File_Format;
       goto Exit;
@@ -547,39 +556,61 @@
     /* now do the blit */
     line  += y_pos * pitch + ( x_pos >> 3 );
     x_pos &= 7;
-    rval   = 0x10000UL;
+
+    /* the higher byte of `rval' is used as a buffer */
+    rval   = 0;
+    nbits  = 0;
 
     for ( h = height; h > 0; h--, line += pitch )
     {
-      FT_Byte*   write = line;
-      FT_UInt32  wval  = 0x100 << x_pos;
-      FT_Int     w;
+      FT_Byte*  write = line;
+      FT_Int    w = width;
 
 
-      for ( w = width; w >= 8; w -= 8 )
+      if ( x_pos )
       {
-        if ( rval & 0x10000UL )
-          rval = 0x100 | *p++;
-
-        wval |= rval & 0x80;
-
-        wval <<= 1;
-        rval <<= 1;
+        w = ( width < 8 - x_pos ) ? width : 8 - x_pos;
 
-        if ( wval & 0x10000UL )
+        if ( nbits < w )
         {
-          write[0] = (FT_Byte)( write[0] | ( wval >> 8 ) );
-          write   += 1;
-          wval     = 0x100;
+          rval  |= *p++;
+          nbits += 8 - w;
+        }
+        else
+        {
+          rval  >>= 8;
+          nbits  -= w;
         }
+
+        *write++ |= ( ( rval >> nbits ) & 0xFF ) & ~( 0xFF << w );
+        rval <<= 8;
+
+        w = width - w;
       }
 
-      if ( wval != 0x100 )
+      for ( ; w >= 8; w -= 8 )
       {
-        while ( wval > 0x1FF )
-          wval >>= 1;
+        rval     |= *p++;
+        *write++ |= ( rval >> nbits ) & 0xFF;
 
-        write[0] = (FT_Byte)( write[0] | wval );
+        rval <<= 8;
+      }
+
+      if ( w > 0 )
+      {
+        if ( nbits < w )
+        {
+          rval   |= *p++;
+          *write |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w );
+          nbits  += 8 - w;
+
+          rval <<= 8;
+        }
+        else
+        {
+          *write |= ( ( rval >> nbits ) & 0xFF ) & ( 0xFF00U >> w );
+          nbits  -= w;
+        }
       }
     }
 
diff --git a/src/truetype/ttpload.c b/src/truetype/ttpload.c
index 04c2031..da2677b 100644
--- a/src/truetype/ttpload.c
+++ b/src/truetype/ttpload.c
@@ -582,6 +582,7 @@
     
     face->hdmx_record_count = nn;
     face->hdmx_table_size   = table_size;
+    face->hdmx_record_size  = record_size;
 
   Exit:
     return error;
@@ -723,7 +724,7 @@
       {
         gindex += 2;
         if ( gindex < record_size )
-          result = record + gindex;
+          result = record + nn * record_size + gindex;
         break;
       }