summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Podtelezhnikov <apodtele@gmail.com>2013-02-01 20:24:00 -0500
committerAlexei Podtelezhnikov <apodtele@gmail.com>2013-02-01 20:24:00 -0500
commit0eb6316fde158730f6a50670435ad68d3e00286c (patch)
tree25d5f26df4d9aeb02cb8c4b5e47bc3805cb8005f
parent3b1f206b04a05f07a86944669e36e67b0145e60b (diff)
downloadfreetype2-0eb6316fde158730f6a50670435ad68d3e00286c.tar.gz
[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.
-rw-r--r--ChangeLog7
-rw-r--r--src/pcf/pcfread.c51
2 files changed, 28 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index f74cfcc15..7bd42e509 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-02-01 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [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 <wl@gnu.org>
Fix Savannah bug #38227.
diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c
index d9914c03a..7136535ed 100644
--- 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 @@ THE SOFTWARE.
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,56 +819,47 @@ THE SOFTWARE.
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 );
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;
}