* src/cff/cffload.c (CFF_Load_Charset): Improved error messages.
(CFF_Load_Charset, CFF_Load_Encoding): Remove unnecessary variable
definition.
* src/cff/t2gload.c (t2_lookup_glyph_by_stdcharcode,
t2_operator_seac): Added these functions for use in implementing the
seac emulation provided by the Type 2 endchar operator.
(T2_Parse_CharStrings): Added seac emulation for the endchar
operator.
CFF_Done_Encoding, CFF_Done_Charset): Extended to load and parse the
charset/encoding tables, and free the memory used by them when the
CFF driver is finished with them. Added tables
diff --git a/ChangeLog b/ChangeLog
index fce13b0..9cbcc3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2000-12-30 Werner Lemberg <wl@gnu.org>
+
+ * src/cff/cffload.c (CFF_Load_Charset): Improved error messages.
+ (CFF_Load_Charset, CFF_Load_Encoding): Remove unnecessary variable
+ definition.
+
2000-12-30 Tom Kacvinsky <tjk@ams.org>
* include/freetype/internal/t2types.h,
@@ -5,15 +11,16 @@
CFF_Encoding and CFF_Encoding for the new implementations of the
charset and encoding parsers in the CFF driver.
- * src/cff/t2gload.c (t2_lookup_glyph_by_stdcharcode, t2_operator_seac):
- Added these functions for use in implementing the seac emulation
- provided by the Type 2 endchar operator.
- (T2_Parse_CharStrings): Added seac emulation for the endchar operator.
+ * src/cff/t2gload.c (t2_lookup_glyph_by_stdcharcode,
+ t2_operator_seac): Added these functions for use in implementing the
+ seac emulation provided by the Type 2 endchar operator.
+ (T2_Parse_CharStrings): Added seac emulation for the endchar
+ operator.
* src/cff/cffload.c (CFF_Load_Encoding, CFF_Load_Charset,
- CFF_Done_Encoding, CFF_Done_Charset): Extended to load and parse the
- charset/encoding tables, and free the memory used by them when the CFF
- driver is finished with them. Added tables
+ CFF_Done_Encoding, CFF_Done_Charset): Extended to load and parse the
+ charset/encoding tables, and free the memory used by them when the
+ CFF driver is finished with them. Added tables
cff_isoadobe_charset
cff_expert_charset
diff --git a/include/freetype/internal/cfftypes.h b/include/freetype/internal/cfftypes.h
index c245931..f1a0fdf 100644
--- a/include/freetype/internal/cfftypes.h
+++ b/include/freetype/internal/cfftypes.h
@@ -64,7 +64,7 @@
/* a compact CFF Charset table */
- typedef struct CFF_Charset_
+ typedef struct CFF_Charset_
{
FT_UInt format;
FT_ULong offset;
@@ -75,7 +75,7 @@
/* a compact CFF Encoding table */
- typedef struct CFF_Encoding_
+ typedef struct CFF_Encoding_
{
FT_UInt format;
FT_ULong offset;
diff --git a/src/cff/cffload.c b/src/cff/cffload.c
index a6bf98a..5ce05da 100644
--- a/src/cff/cffload.c
+++ b/src/cff/cffload.c
@@ -27,6 +27,7 @@
#include FT_SOURCE_FILE(cff,cffload.h)
#include FT_SOURCE_FILE(cff,cffparse.h)
+
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
@@ -36,7 +37,9 @@
#undef FT_COMPONENT
#define FT_COMPONENT trace_t2load
- static const FT_UShort cff_isoadobe_charset[229] =
+
+ static
+ const FT_UShort cff_isoadobe_charset[229] =
{
0,
1,
@@ -269,7 +272,8 @@
228
};
- static const FT_UShort cff_expert_charset[166] =
+ static
+ const FT_UShort cff_expert_charset[166] =
{
0,
1,
@@ -439,7 +443,8 @@
378
};
- static const FT_UShort cff_expertsubset_charset[87] =
+ static
+ const FT_UShort cff_expertsubset_charset[87] =
{
0,
1,
@@ -530,7 +535,8 @@
346
};
- static const FT_UShort cff_standard_encoding[256] =
+ static
+ const FT_UShort cff_standard_encoding[256] =
{
0,
0,
@@ -790,8 +796,8 @@
0
};
-
- static const FT_UShort cff_expert_encoding[256] =
+ static
+ const FT_UShort cff_expert_encoding[256] =
{
0,
0,
@@ -1492,12 +1498,14 @@
{
FT_Memory memory = stream->memory;
+
FREE( charset->sids );
charset->format = 0;
charset->offset = 0;
charset->sids = 0;
}
+
static
FT_Error CFF_Load_Charset( CFF_Charset* charset,
FT_UInt num_glyphs,
@@ -1505,9 +1513,10 @@
FT_ULong base_offset,
FT_ULong offset )
{
- FT_Memory memory = stream->memory;
- FT_Error error = 0;
- FT_UShort glyph_sid;
+ FT_Memory memory = stream->memory;
+ FT_Error error = 0;
+ FT_UShort glyph_sid;
+
charset->offset = base_offset + offset;
@@ -1522,8 +1531,9 @@
{
FT_UInt j;
+
/* Allocate memory for sids. */
- if ( ALLOC( charset->sids, num_glyphs * sizeof( FT_UShort ) ) )
+ if ( ALLOC( charset->sids, num_glyphs * sizeof ( FT_UShort ) ) )
goto Exit;
/* assign the .notdef glyph */
@@ -1532,7 +1542,6 @@
switch ( charset->format )
{
case 0:
-
for ( j = 1; j < num_glyphs; j++ )
{
if ( READ_UShort( glyph_sid ) )
@@ -1548,6 +1557,7 @@
FT_UInt nleft;
FT_UInt i;
+
j = 1;
while ( j < num_glyphs )
@@ -1572,7 +1582,6 @@
/* Fill in the range of sids -- `nleft + 1' glyphs. */
for ( i = 0; i <= nleft; i++, j++, glyph_sid++ )
charset->sids[j] = glyph_sid;
-
}
}
break;
@@ -1582,85 +1591,80 @@
error = FT_Err_Invalid_File_Format;
goto Exit;
}
-
}
else
{
-
/* Parse default tables corresponding to offset == 0, 1, or 2. */
/* CFF specification intimates the following: */
/* */
/* In order to use a predefined charset, the following must be */
- /* true: the charset constructed for the glyphs in the font's */
+ /* true: The charset constructed for the glyphs in the font's */
/* charstrings dictionary must match the predefined charset in */
/* the first num_glyphs, and hence must match the predefined */
/* charset *exactly*. */
switch ( offset )
{
-
case 0:
-
if ( num_glyphs != 229 )
{
- FT_ERROR(("CFF_Load_Charset: implicit charset not equal to predefined charset!\n" ));
+ FT_ERROR(("CFF_Load_Charset: implicit charset not equal to\n"
+ "predefined charset (Adobe ISO-Latin)!\n" ));
error = FT_Err_Invalid_File_Format;
goto Exit;
}
/* Allocate memory for sids. */
- if ( ALLOC( charset->sids, num_glyphs * sizeof( FT_UShort ) ) )
+ if ( ALLOC( charset->sids, num_glyphs * sizeof ( FT_UShort ) ) )
goto Exit;
- /* Copy the predefined charset into the allocated memory. */
+ /* Copy the predefined charset into the allocated memory. */
MEM_Copy( charset->sids, cff_isoadobe_charset,
- num_glyphs * sizeof( FT_UShort ) );
+ num_glyphs * sizeof ( FT_UShort ) );
break;
case 1:
-
if ( num_glyphs != 166 )
{
- FT_ERROR(( "CFF_Load_Charset: implicit charset not equal to predefined charset!\n" ));
+ FT_ERROR(( "CFF_Load_Charset: implicit charset not equal to\n"
+ "predefined charset (Adobe Expert)!\n" ));
error = FT_Err_Invalid_File_Format;
goto Exit;
}
/* Allocate memory for sids. */
- if ( ALLOC( charset->sids, num_glyphs * sizeof( FT_UShort ) ) )
+ if ( ALLOC( charset->sids, num_glyphs * sizeof ( FT_UShort ) ) )
goto Exit;
/* Copy the predefined charset into the allocated memory. */
MEM_Copy( charset->sids, cff_expert_charset,
- num_glyphs * sizeof( FT_UShort ) );
+ num_glyphs * sizeof ( FT_UShort ) );
break;
case 2:
-
if ( num_glyphs != 87 )
{
- FT_ERROR(( "CFF_Load_Charset: implicit charset not equal to predefined charset!\n" ));
+ FT_ERROR(( "CFF_Load_Charset: implicit charset not equal to\n"
+ "predefined charset (Adobe Expert Subset)!\n" ));
error = FT_Err_Invalid_File_Format;
goto Exit;
}
/* Allocate memory for sids. */
- if ( ALLOC( charset->sids, num_glyphs * sizeof( FT_UShort ) ) )
+ if ( ALLOC( charset->sids, num_glyphs * sizeof ( FT_UShort ) ) )
goto Exit;
/* Copy the predefined charset into the allocated memory. */
MEM_Copy( charset->sids, cff_expertsubset_charset,
- num_glyphs * sizeof( FT_UShort ) );
+ num_glyphs * sizeof ( FT_UShort ) );
break;
default:
-
error = FT_Err_Invalid_File_Format;
goto Exit;
-
}
}
@@ -1670,8 +1674,6 @@
if ( error )
if ( charset->sids )
{
- FT_Memory memory = stream->memory;
-
if ( charset->sids )
FREE( charset->sids );
charset->format = 0;
@@ -1682,6 +1684,7 @@
return error;
}
+
static
FT_Error CFF_Load_Encoding( CFF_Encoding* encoding,
CFF_Charset* charset,
@@ -1690,14 +1693,15 @@
FT_ULong base_offset,
FT_ULong offset )
{
- FT_Memory memory = stream->memory;
- FT_Error error = 0;
+ FT_Memory memory = stream->memory;
+ FT_Error error = 0;
FT_UInt count;
FT_UInt j;
FT_UShort glyph_sid;
FT_Byte glyph_code;
- /* Check for charset->sids. If we do not have this, we fail. */
+
+ /* Check for charset->sids. If we do not have this, we fail. */
if ( !charset->sids )
{
error = FT_Err_Invalid_File_Format;
@@ -1706,18 +1710,18 @@
/* Allocate memory for sids/codes -- there are at most 256 sids/codes */
/* for an encoding. */
- if ( ALLOC( encoding->sids, 256 * sizeof( FT_UShort ) ) ||
- ALLOC( encoding->codes, 256 * sizeof( FT_UShort ) ) )
+ if ( ALLOC( encoding->sids, 256 * sizeof ( FT_UShort ) ) ||
+ ALLOC( encoding->codes, 256 * sizeof ( FT_UShort ) ) )
goto Exit;
- /* Zero out the code to gid/sid mappings. */
+ /* Zero out the code to gid/sid mappings. */
for ( j = 0; j < 255; j++ )
{
encoding->sids [j] = 0;
encoding->codes[j] = 0;
}
- /* Note: the encoding table in a CFF font is indexed by glyph index, */
+ /* Note: The encoding table in a CFF font is indexed by glyph index, */
/* where the first encoded glyph index is 1. Hence, we read the char */
/* code (`glyph_code') at index j and make the assignment: */
/* */
@@ -1743,7 +1747,6 @@
switch ( encoding->format & 0x7F )
{
case 0:
-
for ( j = 1; j <= count; j++ )
{
if ( READ_Byte( glyph_code ) )
@@ -1757,7 +1760,6 @@
encoding->codes[glyph_code] = j;
/* Assign code to SID mapping. */
-
encoding->sids[glyph_code] = charset->sids[j];
}
@@ -1769,25 +1771,24 @@
FT_Byte i = 1;
FT_Byte k;
+
/* Parse the Format1 ranges. */
for ( j = 0; j < count; j++, i += nleft )
{
-
- /* Read the first glyph code of the range. */
+ /* Read the first glyph code of the range. */
if ( READ_Byte( glyph_code ) )
goto Exit;
- /* Read the number of codes in the range. */
+ /* Read the number of codes in the range. */
if ( READ_Byte( nleft ) )
goto Exit;
/* Increment nleft, so we read `nleft + 1' codes/sids. */
nleft++;
- /* Fill in the range of codes/sids. */
+ /* Fill in the range of codes/sids. */
for ( k = i; k < nleft + i; k++, glyph_code++ )
{
-
/* Make sure k is not too big. */
if ( k > num_glyphs )
goto Exit;
@@ -1797,15 +1798,13 @@
/* Assign code to SID mapping. */
encoding->sids[glyph_code] = charset->sids[k];
-
}
}
}
-
break;
default:
- FT_ERROR(( "CFF.Load_Encoding: invalid table format!\n" ));
+ FT_ERROR(( "CFF_Load_Encoding: invalid table format!\n" ));
error = FT_Err_Invalid_File_Format;
goto Exit;
}
@@ -1815,27 +1814,25 @@
{
FT_UInt glyph_id;
+
/* count supplements */
if ( READ_Byte( count ) )
goto Exit;
for ( j = 0; j < count; j++ )
{
-
- /* Read supplemental glyph code. */
+ /* Read supplemental glyph code. */
if ( READ_Byte( glyph_code ) )
goto Exit;
- /* Read the SID associated with this glyph code */
+ /* Read the SID associated with this glyph code. */
if ( READ_UShort( glyph_sid ) )
goto Exit;
- /* Assign code to SID mapping. */
+ /* Assign code to SID mapping. */
encoding->sids[glyph_code] = glyph_sid;
- /* Assign code to GID mapping. */
-
- /* First, lookup GID which has been assigned */
+ /* First, lookup GID which has been assigned to */
/* SID glyph_sid. */
for ( glyph_id = 0; glyph_id < num_glyphs; glyph_id++ )
{
@@ -1843,17 +1840,16 @@
break;
}
- /* Now, make the assignment. */
+ /* Now, make the assignment. */
encoding->codes[glyph_code] = glyph_id;
-
}
}
-
}
else
{
FT_UInt i;
+
/* We take into account the fact a CFF font can use a predefined */
/* encoding without containing all of the glyphs encoded by this */
/* encoding (see the note at the end of section 12 in the CFF */
@@ -1861,12 +1857,10 @@
switch ( offset )
{
-
case 0:
-
- /* First, copy the code to SID mapping. */
+ /* First, copy the code to SID mapping. */
MEM_Copy( encoding->sids, cff_standard_encoding,
- 256 * sizeof( FT_UShort ) );
+ 256 * sizeof ( FT_UShort ) );
/* Construct code to GID mapping from code */
/* to SID mapping and charset. */
@@ -1875,7 +1869,6 @@
/* If j is encoded, find the GID for it. */
if ( encoding->sids[j] )
{
-
for ( i = 1; i < num_glyphs; i++ )
/* We matched, so break. */
if ( charset->sids[i] == encoding->sids[j] )
@@ -1893,14 +1886,12 @@
encoding->codes[j] = i;
}
}
-
break;
case 1:
-
/* First, copy the code to SID mapping. */
MEM_Copy( encoding->sids, cff_expert_encoding,
- 256 * sizeof( FT_UShort ) );
+ 256 * sizeof ( FT_UShort ) );
/* Construct code to GID mapping from code to SID mapping */
/* and charset. */
@@ -1909,7 +1900,6 @@
/* If j is encoded, find the GID for it. */
if ( encoding->sids[j] )
{
-
for ( i = 1; i < num_glyphs; i++ )
/* We matched, so break. */
if ( charset->sids[i] == encoding->sids[j] )
@@ -1927,15 +1917,13 @@
encoding->codes[j] = i;
}
}
-
break;
default:
- FT_ERROR(( "CFF.Load_Encoding: invalid table format!\n" ));
+ FT_ERROR(( "CFF_Load_Encoding: invalid table format!\n" ));
error = FT_Err_Invalid_File_Format;
goto Exit;
break;
-
}
}
@@ -1946,8 +1934,6 @@
{
if ( encoding->sids || encoding->codes )
{
- FT_Memory memory = stream->memory;
-
if ( encoding->sids )
FREE( encoding->sids );
@@ -1961,7 +1947,6 @@
}
return error;
-
}
@@ -2231,8 +2216,12 @@
if ( error )
goto Exit;
- error = CFF_Load_Encoding( &font->encoding, &font->charset, font->num_glyphs,
- stream, base_offset, dict->encoding_offset );
+ error = CFF_Load_Encoding( &font->encoding,
+ &font->charset,
+ font->num_glyphs,
+ stream,
+ base_offset,
+ dict->encoding_offset );
if ( error )
goto Exit;
diff --git a/src/cff/cffparse.c b/src/cff/cffparse.c
index ff4ab71..81dab42 100644
--- a/src/cff/cffparse.c
+++ b/src/cff/cffparse.c
@@ -310,6 +310,7 @@
FT_Error error;
FT_Fixed temp;
+
error = T2_Err_Stack_Underflow;
if ( parser->top >= parser->stack + 6 )
diff --git a/src/cff/t2gload.c b/src/cff/t2gload.c
index 9dd83e3..bd43080 100644
--- a/src/cff/t2gload.c
+++ b/src/cff/t2gload.c
@@ -513,6 +513,7 @@
outline->contours[outline->n_contours - 1] = outline->n_points - 1;
}
+
static
FT_Int t2_lookup_glyph_by_stdcharcode( CFF_Font* cff,
FT_Int charcode )
@@ -520,6 +521,7 @@
FT_UInt n;
FT_UShort glyph_sid;
+
/* check range of standard char code */
if ( charcode < 0 || charcode > 255 )
return -1;
@@ -530,7 +532,6 @@
for ( n = 0; n < cff->num_glyphs; n++ )
{
-
if ( cff->charset.sids[n] == glyph_sid )
return n;
}
@@ -538,6 +539,7 @@
return -1;
}
+
static
FT_Error t2_operator_seac( T2_Decoder* decoder,
FT_Pos adx,
@@ -554,6 +556,7 @@
FT_Byte* charstring;
FT_ULong charstring_len;
+
bchar_index = t2_lookup_glyph_by_stdcharcode( cff, bchar );
achar_index = t2_lookup_glyph_by_stdcharcode( cff, achar );
@@ -564,7 +567,7 @@
return T2_Err_Syntax_Error;
}
- /* if we are trying to load a composite glyph, do not load the */
+ /* If we are trying to load a composite glyph, do not load the */
/* accent character and return the array of subglyphs. */
if ( decoder->builder.no_recurse )
{
@@ -607,7 +610,6 @@
&charstring, &charstring_len );
if ( !error )
{
-
error = T2_Parse_CharStrings( decoder, charstring, charstring_len );
if ( error )
@@ -618,7 +620,7 @@
n_base_points = base->n_points;
- /* save the left bearing and width of the base character */
+ /* Save the left bearing and width of the base character */
/* as they will be erased by the next load. */
left_bearing = decoder->builder.left_bearing;
@@ -627,12 +629,11 @@
decoder->builder.left_bearing.x = 0;
decoder->builder.left_bearing.y = 0;
- /* Now load `achar' on top of the base outline */
+ /* Now load `achar' on top of the base outline. */
error = CFF_Access_Element( &cff->charstrings_index, achar_index,
&charstring, &charstring_len );
if ( !error )
{
-
error = T2_Parse_CharStrings( decoder, charstring, charstring_len );
if ( error )
@@ -641,15 +642,17 @@
CFF_Forget_Element( &cff->charstrings_index, &charstring );
}
- /* restore the left side bearing and advance width of the base character */
+ /* Restore the left side bearing and advance width */
+ /* of the base character. */
decoder->builder.left_bearing = left_bearing;
decoder->builder.advance = advance;
- /* Finally, move the accent */
+ /* Finally, move the accent. */
if ( decoder->builder.load_points )
{
FT_Outline dummy;
+
dummy.n_points = base->n_points - n_base_points;
dummy.points = base->points + n_base_points;
@@ -1008,8 +1011,8 @@
break;
case t2_op_endchar:
- /* If there is a width specified for endchar, we either have 1 */
- /* argument or 5 arguments. We like to argue. */
+ /* If there is a width specified for endchar, we either have */
+ /* 1 argument or 5 arguments. We like to argue. */
set_width_ok = ( ( num_args == 5 ) || ( num_args == 1 ) );
break;
@@ -1579,12 +1582,11 @@
FT_TRACE4(( " endchar" ));
/* We are going to emulate the seac operator. */
- if ( num_args == 4)
+ if ( num_args == 4 )
{
-
error = t2_operator_seac( decoder, args[0] >> 16, args[1] >> 16,
args[2] >> 16, args[3] >> 16 );
- args += 4;
+ args += 4;
}
if ( !error )
@@ -2099,6 +2101,7 @@
FT_Matrix font_matrix;
FT_Vector font_offset;
+
if ( load_flags & FT_LOAD_NO_RECURSE )
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
@@ -2151,13 +2154,13 @@
/* bearing the yMax. */
if ( !error )
{
-
- /* for composite glyphs, return only left side bearing and */
- /* advance width */
+ /* For composite glyphs, return only left side bearing and */
+ /* advance width. */
if ( load_flags & FT_LOAD_NO_RECURSE )
{
FT_Slot_Internal internal = glyph->root.internal;
+
glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x;
glyph->root.metrics.horiAdvance = decoder.glyph_width;
internal->glyph_matrix = font_matrix;
@@ -2171,8 +2174,8 @@
/* copy the _unscaled_ advance width */
- metrics->horiAdvance = decoder.glyph_width;
- glyph->root.linearHoriAdvance = decoder.glyph_width;
+ metrics->horiAdvance = decoder.glyph_width;
+ glyph->root.linearHoriAdvance = decoder.glyph_width;
glyph->root.internal->glyph_transformed = 0;
/* make up vertical metrics */