shithub: freetype+ttf2subf

Download patch

ref: 0eb6316fde158730f6a50670435ad68d3e00286c
parent: 3b1f206b04a05f07a86944669e36e67b0145e60b
author: Alexei Podtelezhnikov <[email protected]>
date: Fri Feb 1 15:24:00 EST 2013

[pcf] Streamline parsing of PCF encoding table.

* src/pcf/pcfread.c (pcf_get_encodings): Use simpler double for-loop.
Reallocate array instead of using temporary storage.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-02-01  Alexei Podtelezhnikov  <[email protected]>
+
+	[pcf] Streamline parsing of PCF encoding table.
+
+	* src/pcf/pcfread.c (pcf_get_encodings): Use simpler double for-loop.
+	Reallocate array instead of using temporary storage.
+
 2013-02-01  Werner Lemberg  <[email protected]>
 
 	Fix Savannah bug #38227.
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -2,7 +2,7 @@
 
     FreeType font driver for pcf fonts
 
-  Copyright 2000-2010, 2012 by
+  Copyright 2000-2010, 2012, 2013 by
   Francesco Zappa Nardelli
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -771,8 +771,8 @@
     int           firstCol, lastCol;
     int           firstRow, lastRow;
     int           nencoding, encodingOffset;
-    int           i, j;
-    PCF_Encoding  tmpEncoding = NULL, encoding = 0;
+    int           i, j, k;
+    PCF_Encoding  encoding = NULL;
 
 
     error = pcf_seek_to_table_type( stream,
@@ -819,7 +819,7 @@
 
     nencoding = ( lastCol - firstCol + 1 ) * ( lastRow - firstRow + 1 );
 
-    if ( FT_NEW_ARRAY( tmpEncoding, nencoding ) )
+    if ( FT_NEW_ARRAY( encoding, nencoding ) )
       return PCF_Err_Out_Of_Memory;
 
     error = FT_Stream_EnterFrame( stream, 2 * nencoding );
@@ -826,49 +826,40 @@
     if ( error )
       goto Bail;
 
-    for ( i = 0, j = 0 ; i < nencoding; i++ )
+    k = 0;
+    for ( i = firstRow; i <= lastRow; i++ )
     {
-      if ( PCF_BYTE_ORDER( format ) == MSBFirst )
-        encodingOffset = FT_GET_SHORT();
-      else
-        encodingOffset = FT_GET_SHORT_LE();
-
-      if ( encodingOffset != -1 )
+      for ( j = firstCol; j <= lastCol; j++ )
       {
-        tmpEncoding[j].enc = ( ( ( i / ( lastCol - firstCol + 1 ) ) +
-                                 firstRow ) * 256 ) +
-                               ( ( i % ( lastCol - firstCol + 1 ) ) +
-                                 firstCol );
+        if ( PCF_BYTE_ORDER( format ) == MSBFirst )
+          encodingOffset = FT_GET_SHORT();
+        else
+          encodingOffset = FT_GET_SHORT_LE();
 
-        tmpEncoding[j].glyph = (FT_Short)encodingOffset;
+        if ( encodingOffset != -1 )
+        {
+          encoding[k].enc   = i * 256 + j;
+          encoding[k].glyph = (FT_Short)encodingOffset;
 
-        FT_TRACE5(( "  code %d (0x%04X): idx %d\n",
-                    tmpEncoding[j].enc, tmpEncoding[j].enc,
-                    tmpEncoding[j].glyph ));
+          FT_TRACE5(( "  code %d (0x%04X): idx %d\n",
+                      encoding[k].enc, encoding[k].enc, encoding[k].glyph ));
 
-        j++;
+          k++;
+        }
       }
     }
     FT_Stream_ExitFrame( stream );
 
-    if ( FT_NEW_ARRAY( encoding, j ) )
+    if ( FT_RENEW_ARRAY( encoding, nencoding, k ) )
       goto Bail;
 
-    for ( i = 0; i < j; i++ )
-    {
-      encoding[i].enc   = tmpEncoding[i].enc;
-      encoding[i].glyph = tmpEncoding[i].glyph;
-    }
-
-    face->nencodings = j;
+    face->nencodings = k;
     face->encodings  = encoding;
-    FT_FREE( tmpEncoding );
 
     return error;
 
   Bail:
     FT_FREE( encoding );
-    FT_FREE( tmpEncoding );
     return error;
   }