* src/cff/cffcmap.c, src/cff/cffcmap.h, Jamfile, rules.mk: new files added

to support charmaps for CFF fonts

    * src/cff/cffload.c, src/cff/cffload.h, src/cff/cffobjs.c,
    src/cff/cffobjs.h, src/cff/cffparse.c, src/cffparse.h, src/cff/cffgload.c,
    src/cff/cffgload.h: adding support for CFF charmaps, reformatting the
    sources, and removing some bugs in the Encoding and Charset loaders
This commit is contained in:
David Turner 2002-07-10 16:52:06 +00:00
parent ee06410b0a
commit b9b2cac634
16 changed files with 781 additions and 354 deletions

View File

@ -1,3 +1,13 @@
2002-07-10 David Turner <david@freetype.org>
* src/cff/cffcmap.c, src/cff/cffcmap.h, Jamfile, rules.mk: new files added
to support charmaps for CFF fonts
* src/cff/cffload.c, src/cff/cffload.h, src/cff/cffobjs.c,
src/cff/cffobjs.h, src/cff/cffparse.c, src/cffparse.h, src/cff/cffgload.c,
src/cff/cffgload.h: adding support for CFF charmaps, reformatting the
sources, and removing some bugs in the Encoding and Charset loaders
2002-07-09 Owen Taylor <owen@redhat.com>
* src/pshinter/pshglob.c: fixed a bug that prevented the hinter from using

View File

@ -68,8 +68,9 @@ FT_BEGIN_HEADER
FT_UInt format;
FT_ULong offset;
FT_UShort* sids;
FT_UShort* codes;
FT_UInt count;
FT_UShort sids [256]; /* avoid dynamic allocations */
FT_UShort codes[256];
} CFF_EncodingRec, *CFF_Encoding;
@ -241,6 +242,9 @@ FT_BEGIN_HEADER
/* interface to PostScript hinter */
void* pshinter;
/* interface to Postscript Names service */
void* psnames;
} CFF_FontRec, *CFF_Font;

View File

@ -10,7 +10,7 @@ SubDirHdrs [ FT2_SubDir src cff ] ;
if $(FT2_MULTI)
{
_sources = cffdrivr cffgload cffload cffobjs cffparse ;
_sources = cffdrivr cffgload cffload cffobjs cffparse cffcmap ;
}
else
{

View File

@ -24,6 +24,6 @@
#include "cffload.c"
#include "cffobjs.c"
#include "cffgload.c"
#include "cffcmap.c"
/* END */

301
src/cff/cffcmap.c Normal file
View File

@ -0,0 +1,301 @@
#include "cffcmap.h"
#include "cffload.h"
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** CFF STANDARD (AND EXPERT) ENCODING CMAPS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_CALLBACK_DEF( FT_Error )
cff_cmap_encoding_init( CFF_CMapStd cmap )
{
TT_Face face = (TT_Face)FT_CMAP_FACE( cmap );
CFF_Font cff = face->extra.data;
CFF_Encoding encoding = &cff->encoding;
PSNames_Service psnames = cff->psnames;
cmap->count = encoding->count;
cmap->gids = encoding->codes;
return 0;
}
FT_CALLBACK_DEF( void )
cff_cmap_encoding_done( CFF_CMapStd cmap )
{
cmap->count = 0;
cmap->gids = NULL;
}
FT_CALLBACK_DEF( FT_UInt )
cff_cmap_encoding_char_index( CFF_CMapStd cmap,
FT_UInt32 char_code )
{
FT_UInt result = 0;
if ( char_code < cmap->count )
result = cmap->gids[ char_code ];
return result;
}
FT_CALLBACK_DEF( FT_UInt )
cff_cmap_encoding_char_next( CFF_CMapStd cmap,
FT_UInt32 *pchar_code )
{
FT_UInt result = 0;
FT_UInt32 char_code = *pchar_code;
*pchar_code = 0;
if ( char_code < cmap->count )
{
FT_UInt code = (FT_UInt)(char_code+1);
for (;;)
{
if ( code >= cmap->count )
break;
result = cmap->gids[ code ];
if ( result != 0 )
{
*pchar_code = code;
break;
}
code++;
}
}
return result;
}
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
cff_cmap_encoding_class_rec =
{
sizeof ( CFF_CMapStdRec ),
(FT_CMap_InitFunc) cff_cmap_encoding_init,
(FT_CMap_DoneFunc) cff_cmap_encoding_done,
(FT_CMap_CharIndexFunc)cff_cmap_encoding_char_index,
(FT_CMap_CharNextFunc) cff_cmap_encoding_char_next
};
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_CALLBACK_DEF( FT_Int )
cff_cmap_uni_pair_compare( const void* pair1,
const void* pair2 )
{
FT_UInt32 u1 = ((CFF_CMapUniPair)pair1)->unicode;
FT_UInt32 u2 = ((CFF_CMapUniPair)pair2)->unicode;
if ( u1 < u2 )
return -1;
if ( u1 > u2 )
return +1;
return 0;
}
FT_CALLBACK_DEF( FT_Error )
cff_cmap_unicode_init( CFF_CMapUnicode cmap )
{
FT_Error error;
FT_UInt count;
TT_Face face = (TT_Face)FT_CMAP_FACE( cmap );
FT_Memory memory = FT_FACE_MEMORY( face );
CFF_Font cff = face->extra.data;
CFF_Charset charset = &cff->charset;
PSNames_Service psnames = cff->psnames;
cmap->num_pairs = 0;
cmap->pairs = NULL;
count = face->root.num_glyphs;
if ( !FT_NEW_ARRAY( cmap->pairs, count ) )
{
FT_UInt n, new_count;
CFF_CMapUniPair pair;
FT_UInt32 uni_code;
pair = cmap->pairs;
for ( n = 0; n < count; n++ )
{
FT_UInt sid = charset->sids[n];
const char* gname;
gname = cff_index_get_sid_string( &cff->string_index, sid, psnames );
/* build unsorted pair table by matching glyph names */
if ( gname )
{
uni_code = psnames->unicode_value( gname );
if ( uni_code != 0 )
{
pair->unicode = uni_code;
pair->gindex = n;
pair++;
}
FT_FREE( gname );
}
}
new_count = (FT_UInt)( pair - cmap->pairs );
if ( new_count == 0 )
{
/* there are no unicode characters in here! */
FT_FREE( cmap->pairs );
error = FT_Err_Invalid_Argument;
}
else
{
/* re-allocate if the new array is much smaller than the original */
/* one */
if ( new_count != count && new_count < count / 2 )
{
(void)FT_RENEW_ARRAY( cmap->pairs, count, new_count );
error = 0;
}
/* sort the pairs table to allow efficient binary searches */
ft_qsort( cmap->pairs,
new_count,
sizeof ( CFF_CMapUniPairRec ),
cff_cmap_uni_pair_compare );
cmap->num_pairs = new_count;
}
}
return error;
}
FT_CALLBACK_DEF( void )
cff_cmap_unicode_done( CFF_CMapUnicode cmap )
{
FT_Face face = FT_CMAP_FACE(cmap);
FT_Memory memory = FT_FACE_MEMORY(face);
FT_FREE( cmap->pairs );
cmap->num_pairs = 0;
}
FT_CALLBACK_DEF( FT_UInt )
cff_cmap_unicode_char_index( CFF_CMapUnicode cmap,
FT_UInt32 char_code )
{
FT_UInt min = 0;
FT_UInt max = cmap->num_pairs;
FT_UInt mid;
CFF_CMapUniPair pair;
while ( min < max )
{
mid = min + ( max - min ) / 2;
pair = cmap->pairs + mid;
if ( pair->unicode == char_code )
return pair->gindex;
if ( pair->unicode < char_code )
min = mid + 1;
else
max = mid;
}
return 0;
}
FT_CALLBACK_DEF( FT_UInt )
cff_cmap_unicode_char_next( CFF_CMapUnicode cmap,
FT_UInt32 *pchar_code )
{
FT_UInt result = 0;
FT_UInt32 char_code = *pchar_code + 1;
Restart:
{
FT_UInt min = 0;
FT_UInt max = cmap->num_pairs;
FT_UInt mid;
CFF_CMapUniPair pair;
while ( min < max )
{
mid = min + ( ( max - min ) >> 1 );
pair = cmap->pairs + mid;
if ( pair->unicode == char_code )
{
result = pair->gindex;
if ( result != 0 )
goto Exit;
char_code++;
goto Restart;
}
if ( pair->unicode < char_code )
min = mid+1;
else
max = mid;
}
/* we didn't find it, but we have a pair just above it */
char_code = 0;
if ( min < cmap->num_pairs )
{
pair = cmap->pairs + min;
result = pair->gindex;
if ( result != 0 )
char_code = pair->unicode;
}
}
Exit:
*pchar_code = char_code;
return result;
}
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
cff_cmap_unicode_class_rec =
{
sizeof ( CFF_CMapUnicodeRec ),
(FT_CMap_InitFunc) cff_cmap_unicode_init,
(FT_CMap_DoneFunc) cff_cmap_unicode_done,
(FT_CMap_CharIndexFunc)cff_cmap_unicode_char_index,
(FT_CMap_CharNextFunc) cff_cmap_unicode_char_next
};

66
src/cff/cffcmap.h Normal file
View File

@ -0,0 +1,66 @@
#ifndef __CFF_CMAP_H__
#define __CFF_CMAP_H__
#include "cffobjs.h"
FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** TYPE1 STANDARD (AND EXPERT) ENCODING CMAPS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* standard (and expert) encoding cmaps */
typedef struct CFF_CMapStdRec_* CFF_CMapStd;
typedef struct CFF_CMapStdRec_
{
FT_CMapRec cmap;
FT_UInt count;
FT_UShort* gids; /* up to 256 elements */
} CFF_CMapStdRec;
FT_CALLBACK_TABLE const FT_CMap_ClassRec
cff_cmap_encoding_class_rec;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** CFF SYNTHETIC UNICODE ENCODING CMAP *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* unicode (synthetic) cmaps */
typedef struct CFF_CMapUnicodeRec_* CFF_CMapUnicode;
typedef struct CFF_CMapUniPairRec_
{
FT_UInt32 unicode;
FT_UInt gindex;
} CFF_CMapUniPairRec, *CFF_CMapUniPair;
typedef struct CFF_CMapUnicodeRec_
{
FT_CMapRec cmap;
FT_UInt num_pairs;
CFF_CMapUniPair pairs;
} CFF_CMapUnicodeRec;
FT_CALLBACK_TABLE const FT_CMap_ClassRec
cff_cmap_unicode_class_rec;
FT_END_HEADER
#endif /* __CFF_CMAP_H__ */

View File

@ -201,7 +201,7 @@
}
/* now load the glyph outline if necessary */
error = CFF_Load_Glyph( slot, size, glyph_index, load_flags );
error = cff_slot_load( slot, size, glyph_index, load_flags );
/* force drop-out mode to 2 - irrelevant now */
/* slot->outline.dropout_mode = 2; */
@ -253,7 +253,7 @@
sid = font->charset.sids[glyph_index];
/* now, lookup the name itself */
gname = CFF_Get_String( &font->string_index, sid, psnames );
gname = cff_index_get_sid_string( &font->string_index, sid, psnames );
if ( buffer_max > 0 )
{
@ -406,7 +406,7 @@
sid = charset->sids[i];
if ( sid > 390 )
name = CFF_Get_Name( &cff->string_index, sid - 391 );
name = cff_index_get_name( &cff->string_index, sid - 391 );
else
name = (FT_String *)psnames->adobe_std_strings( sid );
@ -477,8 +477,8 @@
0, /* module-specific interface */
(FT_Module_Constructor)CFF_Driver_Init,
(FT_Module_Destructor) CFF_Driver_Done,
(FT_Module_Constructor)cff_driver_init,
(FT_Module_Destructor) cff_driver_done,
(FT_Module_Requester) cff_get_interface,
},
@ -487,15 +487,15 @@
sizeof( FT_SizeRec ),
sizeof( CFF_GlyphSlotRec ),
(FT_Face_InitFunc) CFF_Face_Init,
(FT_Face_DoneFunc) CFF_Face_Done,
(FT_Size_InitFunc) CFF_Size_Init,
(FT_Size_DoneFunc) CFF_Size_Done,
(FT_Slot_InitFunc) CFF_GlyphSlot_Init,
(FT_Slot_DoneFunc) CFF_GlyphSlot_Done,
(FT_Face_InitFunc) cff_face_init,
(FT_Face_DoneFunc) cff_face_done,
(FT_Size_InitFunc) cff_size_init,
(FT_Size_DoneFunc) cff_size_done,
(FT_Slot_InitFunc) cff_slot_init,
(FT_Slot_DoneFunc) cff_slot_done,
(FT_Size_ResetPointsFunc) CFF_Size_Reset,
(FT_Size_ResetPixelsFunc) CFF_Size_Reset,
(FT_Size_ResetPointsFunc) cff_size_reset,
(FT_Size_ResetPixelsFunc) cff_size_reset,
(FT_Slot_LoadFunc) Load_Glyph,
(FT_CharMap_CharIndexFunc)cff_get_char_index,

View File

@ -207,7 +207,7 @@
/*************************************************************************/
/* */
/* <Function> */
/* CFF_Builder_Init */
/* cff_builder_init */
/* */
/* <Description> */
/* Initializes a given glyph builder. */
@ -223,7 +223,7 @@
/* glyph :: The current glyph object. */
/* */
static void
CFF_Builder_Init( CFF_Builder* builder,
cff_builder_init( CFF_Builder* builder,
TT_Face face,
CFF_Size size,
CFF_GlyphSlot glyph,
@ -276,7 +276,7 @@
/*************************************************************************/
/* */
/* <Function> */
/* CFF_Builder_Done */
/* cff_builder_done */
/* */
/* <Description> */
/* Finalizes a given glyph builder. Its contents can still be used */
@ -287,7 +287,7 @@
/* builder :: A pointer to the glyph builder to finalize. */
/* */
static void
CFF_Builder_Done( CFF_Builder* builder )
cff_builder_done( CFF_Builder* builder )
{
CFF_GlyphSlot glyph = builder->glyph;
@ -331,7 +331,7 @@
/*************************************************************************/
/* */
/* <Function> */
/* CFF_Init_Decoder */
/* cff_decoder_init */
/* */
/* <Description> */
/* Initializes a given glyph decoder. */
@ -347,7 +347,7 @@
/* slot :: The current glyph object. */
/* */
FT_LOCAL_DEF( void )
CFF_Init_Decoder( CFF_Decoder* decoder,
cff_decoder_init( CFF_Decoder* decoder,
TT_Face face,
CFF_Size size,
CFF_GlyphSlot slot,
@ -360,7 +360,7 @@
FT_MEM_SET( decoder, 0, sizeof ( *decoder ) );
/* initialize builder */
CFF_Builder_Init( &decoder->builder, face, size, slot, hinting );
cff_builder_init( &decoder->builder, face, size, slot, hinting );
/* initialize Type2 decoder */
decoder->num_globals = cff->num_global_subrs;
@ -371,7 +371,7 @@
/* this function is used to select the locals subrs array */
FT_LOCAL_DEF( void )
CFF_Prepare_Decoder( CFF_Decoder* decoder,
cff_decoder_prepare( CFF_Decoder* decoder,
FT_UInt glyph_index )
{
CFF_Font cff = (CFF_Font)decoder->builder.face->extra.data;
@ -381,7 +381,7 @@
/* manage CID fonts */
if ( cff->num_subfonts >= 1 )
{
FT_Byte fd_index = CFF_Get_FD( &cff->fd_select, glyph_index );
FT_Byte fd_index = cff_fd_select_get( &cff->fd_select, glyph_index );
sub = cff->subfonts[fd_index];
@ -407,10 +407,10 @@
/* add a new point, do not check space */
static void
add_point( CFF_Builder* builder,
FT_Pos x,
FT_Pos y,
FT_Byte flag )
cff_builder_add_point( CFF_Builder* builder,
FT_Pos x,
FT_Pos y,
FT_Byte flag )
{
FT_Outline* outline = builder->current;
@ -434,16 +434,16 @@
/* check space for a new on-curve point, then add it */
static FT_Error
add_point1( CFF_Builder* builder,
FT_Pos x,
FT_Pos y )
cff_builder_cff_builder_add_point1( CFF_Builder* builder,
FT_Pos x,
FT_Pos y )
{
FT_Error error;
error = check_points( builder, 1 );
if ( !error )
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
return error;
}
@ -451,7 +451,7 @@
/* check room for a new contour, then add it */
static FT_Error
add_contour( CFF_Builder* builder )
cff_builder_add_contour( CFF_Builder* builder )
{
FT_Outline* outline = builder->current;
FT_Error error;
@ -479,9 +479,9 @@
/* if a path was begun, add its first on-curve point */
static FT_Error
start_point( CFF_Builder* builder,
FT_Pos x,
FT_Pos y )
cff_builder_start_point( CFF_Builder* builder,
FT_Pos x,
FT_Pos y )
{
FT_Error error = 0;
@ -490,9 +490,9 @@
if ( !builder->path_begun )
{
builder->path_begun = 1;
error = add_contour( builder );
error = cff_builder_add_contour( builder );
if ( !error )
error = add_point1( builder, x, y );
error = cff_builder_cff_builder_add_point1( builder, x, y );
}
return error;
@ -501,7 +501,7 @@
/* close the current contour */
static void
close_contour( CFF_Builder* builder )
cff_builder_close_contour( CFF_Builder* builder )
{
FT_Outline* outline = builder->current;
@ -548,7 +548,7 @@
return -1;
/* Get code to SID mapping from `cff_standard_encoding'. */
glyph_sid = CFF_Get_Standard_Encoding( (FT_UInt)charcode );
glyph_sid = cff_get_standard_encoding( (FT_UInt)charcode );
for ( n = 0; n < cff->num_glyphs; n++ )
{
@ -626,16 +626,16 @@
}
/* First load `bchar' in builder */
error = CFF_Access_Element( &cff->charstrings_index, bchar_index,
error = cff_index_access_element( &cff->charstrings_index, bchar_index,
&charstring, &charstring_len );
if ( !error )
{
error = CFF_Parse_CharStrings( decoder, charstring, charstring_len );
error = cff_decoder_parse_charstrings( decoder, charstring, charstring_len );
if ( error )
goto Exit;
CFF_Forget_Element( &cff->charstrings_index, &charstring );
cff_index_forget_element( &cff->charstrings_index, &charstring );
}
n_base_points = base->n_points;
@ -650,16 +650,16 @@
decoder->builder.left_bearing.y = 0;
/* Now load `achar' on top of the base outline. */
error = CFF_Access_Element( &cff->charstrings_index, achar_index,
error = cff_index_access_element( &cff->charstrings_index, achar_index,
&charstring, &charstring_len );
if ( !error )
{
error = CFF_Parse_CharStrings( decoder, charstring, charstring_len );
error = cff_decoder_parse_charstrings( decoder, charstring, charstring_len );
if ( error )
goto Exit;
CFF_Forget_Element( &cff->charstrings_index, &charstring );
cff_index_forget_element( &cff->charstrings_index, &charstring );
}
/* Restore the left side bearing and advance width */
@ -687,7 +687,7 @@
/*************************************************************************/
/* */
/* <Function> */
/* CFF_Parse_CharStrings */
/* cff_decoder_parse_charstrings */
/* */
/* <Description> */
/* Parses a given Type 2 charstrings program. */
@ -704,7 +704,7 @@
/* FreeType error code. 0 means success. */
/* */
FT_LOCAL_DEF( FT_Error )
CFF_Parse_CharStrings( CFF_Decoder* decoder,
cff_decoder_parse_charstrings( CFF_Decoder* decoder,
FT_Byte* charstring_base,
FT_Int charstring_len )
{
@ -1147,7 +1147,7 @@
case cff_op_rmoveto:
FT_TRACE4(( " rmoveto" ));
close_contour( builder );
cff_builder_close_contour( builder );
builder->path_begun = 0;
x += args[0];
y += args[1];
@ -1157,7 +1157,7 @@
case cff_op_vmoveto:
FT_TRACE4(( " vmoveto" ));
close_contour( builder );
cff_builder_close_contour( builder );
builder->path_begun = 0;
y += args[0];
args = stack;
@ -1166,7 +1166,7 @@
case cff_op_hmoveto:
FT_TRACE4(( " hmoveto" ));
close_contour( builder );
cff_builder_close_contour( builder );
builder->path_begun = 0;
x += args[0];
args = stack;
@ -1175,7 +1175,7 @@
case cff_op_rlineto:
FT_TRACE4(( " rlineto" ));
if ( start_point ( builder, x, y ) ||
if ( cff_builder_start_point ( builder, x, y ) ||
check_points( builder, num_args / 2 ) )
goto Memory_Error;
@ -1187,7 +1187,7 @@
{
x += args[0];
y += args[1];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args += 2;
}
args = stack;
@ -1202,7 +1202,7 @@
FT_TRACE4(( op == cff_op_hlineto ? " hlineto"
: " vlineto" ));
if ( start_point ( builder, x, y ) ||
if ( cff_builder_start_point ( builder, x, y ) ||
check_points( builder, num_args ) )
goto Memory_Error;
@ -1214,7 +1214,7 @@
else
y += args[0];
if ( add_point1( builder, x, y ) )
if ( cff_builder_cff_builder_add_point1( builder, x, y ) )
goto Memory_Error;
args++;
@ -1231,7 +1231,7 @@
if ( num_args % 6 != 0 )
goto Stack_Underflow;
if ( start_point ( builder, x, y ) ||
if ( cff_builder_start_point ( builder, x, y ) ||
check_points( builder, num_args / 2 ) )
goto Memory_Error;
@ -1240,13 +1240,13 @@
{
x += args[0];
y += args[1];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[2];
y += args[3];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[4];
y += args[5];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args += 6;
}
args = stack;
@ -1255,7 +1255,7 @@
case cff_op_vvcurveto:
FT_TRACE4(( " vvcurveto" ));
if ( start_point ( builder, x, y ) )
if ( cff_builder_start_point ( builder, x, y ) )
goto Memory_Error;
args = stack;
@ -1275,12 +1275,12 @@
while ( args < decoder->top )
{
y += args[0];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[1];
y += args[2];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
y += args[3];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args += 4;
}
args = stack;
@ -1289,7 +1289,7 @@
case cff_op_hhcurveto:
FT_TRACE4(( " hhcurveto" ));
if ( start_point ( builder, x, y ) )
if ( cff_builder_start_point ( builder, x, y ) )
goto Memory_Error;
args = stack;
@ -1309,12 +1309,12 @@
while ( args < decoder->top )
{
x += args[0];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[1];
y += args[2];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[3];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args += 4;
}
args = stack;
@ -1329,7 +1329,7 @@
FT_TRACE4(( op == cff_op_vhcurveto ? " vhcurveto"
: " hvcurveto" ));
if ( start_point ( builder, x, y ) )
if ( cff_builder_start_point ( builder, x, y ) )
goto Memory_Error;
args = stack;
@ -1347,26 +1347,26 @@
if ( phase )
{
x += args[0];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[1];
y += args[2];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
y += args[3];
if ( num_args == 1 )
x += args[4];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
}
else
{
y += args[0];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[1];
y += args[2];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[3];
if ( num_args == 1 )
y += args[4];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
}
args += 4;
phase ^= 1;
@ -1385,7 +1385,7 @@
if ( num_args < 8 || ( num_args - 6 ) & 1 )
goto Stack_Underflow;
if ( start_point( builder, x, y ) ||
if ( cff_builder_start_point( builder, x, y ) ||
check_points( builder, num_lines + 3 ) )
goto Memory_Error;
@ -1396,7 +1396,7 @@
{
x += args[0];
y += args[1];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args += 2;
num_lines--;
}
@ -1404,13 +1404,13 @@
/* then the curve */
x += args[0];
y += args[1];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[2];
y += args[3];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[4];
y += args[5];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args = stack;
}
break;
@ -1425,7 +1425,7 @@
if ( num_args < 8 || ( num_args - 2 ) % 6 )
goto Stack_Underflow;
if ( start_point ( builder, x, y ) ||
if ( cff_builder_start_point ( builder, x, y ) ||
check_points( builder, num_curves*3 + 2 ) )
goto Memory_Error;
@ -1436,13 +1436,13 @@
{
x += args[0];
y += args[1];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[2];
y += args[3];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
x += args[4];
y += args[5];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args += 6;
num_curves--;
}
@ -1450,7 +1450,7 @@
/* then the final line */
x += args[0];
y += args[1];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args = stack;
}
break;
@ -1467,7 +1467,7 @@
/* adding five more points; 4 control points, 1 on-curve point */
/* make sure we have enough space for the start point if it */
/* needs to be added.. */
if ( start_point( builder, x, y ) ||
if ( cff_builder_start_point( builder, x, y ) ||
check_points( builder, 6 ) )
goto Memory_Error;
@ -1477,32 +1477,32 @@
/* first control point */
x += args[0];
y += args[1];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
/* second control point */
x += args[2];
y += args[3];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
/* join point; on curve, with y-value the same as the last */
/* control point's y-value */
x += args[4];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
/* third control point, with y-value the same as the join */
/* point's y-value */
x += args[5];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
/* fourth control point */
x += args[6];
y += args[7];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
/* ending point, with y-value the same as the start */
x += args[8];
y = start_y;
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args = stack;
break;
@ -1518,7 +1518,7 @@
args = stack;
/* adding six more points; 4 control points, 2 on-curve points */
if ( start_point( builder, x, y ) ||
if ( cff_builder_start_point( builder, x, y ) ||
check_points ( builder, 6 ) )
goto Memory_Error;
@ -1527,32 +1527,32 @@
/* first control point */
x += args[0];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
/* second control point */
x += args[1];
y += args[2];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
/* join point; on curve, with y-value the same as the last */
/* control point's y-value */
x += args[3];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
/* third control point, with y-value the same as the join */
/* point's y-value */
x += args[4];
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
/* fourth control point */
x += args[5];
y = start_y;
add_point( builder, x, y, 0 );
cff_builder_add_point( builder, x, y, 0 );
/* ending point, with y-value the same as the start point's */
/* y-value -- we don't add this point, though */
x += args[6];
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args = stack;
break;
@ -1570,7 +1570,7 @@
FT_TRACE4(( " flex1" ));
/* adding six more points; 4 control points, 2 on-curve points */
if ( start_point( builder, x, y ) ||
if ( cff_builder_start_point( builder, x, y ) ||
check_points( builder, 6 ) )
goto Memory_Error;
@ -1604,7 +1604,7 @@
{
x += args[0];
y += args[1];
add_point( builder, x, y, (FT_Bool)( count == 3 ) );
cff_builder_add_point( builder, x, y, (FT_Bool)( count == 3 ) );
args += 2;
}
@ -1620,7 +1620,7 @@
y += args[0];
}
add_point( builder, x, y, 1 );
cff_builder_add_point( builder, x, y, 1 );
args = stack;
break;
@ -1633,7 +1633,7 @@
FT_TRACE4(( " flex" ));
if ( start_point( builder, x, y ) ||
if ( cff_builder_start_point( builder, x, y ) ||
check_points( builder, 6 ) )
goto Memory_Error;
@ -1642,7 +1642,7 @@
{
x += args[0];
y += args[1];
add_point( builder, x, y,
cff_builder_add_point( builder, x, y,
(FT_Bool)( count == 3 || count == 0 ) );
args += 2;
}
@ -1666,7 +1666,7 @@
if ( !error )
error = CFF_Err_Ok;
close_contour( builder );
cff_builder_close_contour( builder );
/* close hints recording session */
if ( hinter )
@ -1967,14 +1967,14 @@
if ( idx >= decoder->num_locals )
{
FT_ERROR(( "CFF_Parse_CharStrings:" ));
FT_ERROR(( "cff_decoder_parse_charstrings:" ));
FT_ERROR(( " invalid local subr index\n" ));
goto Syntax_Error;
}
if ( zone - decoder->zones >= CFF_MAX_SUBRS_CALLS )
{
FT_ERROR(( "CFF_Parse_CharStrings: too many nested subrs\n" ));
FT_ERROR(( "cff_decoder_parse_charstrings: too many nested subrs\n" ));
goto Syntax_Error;
}
@ -1987,7 +1987,7 @@
if ( !zone->base )
{
FT_ERROR(( "CFF_Parse_CharStrings: invoking empty subrs!\n" ));
FT_ERROR(( "cff_decoder_parse_charstrings: invoking empty subrs!\n" ));
goto Syntax_Error;
}
@ -2007,14 +2007,14 @@
if ( idx >= decoder->num_globals )
{
FT_ERROR(( "CFF_Parse_CharStrings:" ));
FT_ERROR(( "cff_decoder_parse_charstrings:" ));
FT_ERROR(( " invalid global subr index\n" ));
goto Syntax_Error;
}
if ( zone - decoder->zones >= CFF_MAX_SUBRS_CALLS )
{
FT_ERROR(( "CFF_Parse_CharStrings: too many nested subrs\n" ));
FT_ERROR(( "cff_decoder_parse_charstrings: too many nested subrs\n" ));
goto Syntax_Error;
}
@ -2027,7 +2027,7 @@
if ( !zone->base )
{
FT_ERROR(( "CFF_Parse_CharStrings: invoking empty subrs!\n" ));
FT_ERROR(( "cff_decoder_parse_charstrings: invoking empty subrs!\n" ));
goto Syntax_Error;
}
@ -2042,7 +2042,7 @@
if ( decoder->zone <= decoder->zones )
{
FT_ERROR(( "CFF_Parse_CharStrings: unexpected return\n" ));
FT_ERROR(( "cff_decoder_parse_charstrings: unexpected return\n" ));
goto Syntax_Error;
}
@ -2074,15 +2074,15 @@
return error;
Syntax_Error:
FT_TRACE4(( "CFF_Parse_CharStrings: syntax error!" ));
FT_TRACE4(( "cff_decoder_parse_charstrings: syntax error!" ));
return CFF_Err_Invalid_File_Format;
Stack_Underflow:
FT_TRACE4(( "CFF_Parse_CharStrings: stack underflow!" ));
FT_TRACE4(( "cff_decoder_parse_charstrings: stack underflow!" ));
return CFF_Err_Too_Few_Arguments;
Stack_Overflow:
FT_TRACE4(( "CFF_Parse_CharStrings: stack overflow!" ));
FT_TRACE4(( "cff_decoder_parse_charstrings: stack overflow!" ));
return CFF_Err_Stack_Overflow;
Memory_Error:
@ -2112,7 +2112,7 @@
FT_LOCAL_DEF( FT_Error )
CFF_Compute_Max_Advance( TT_Face face,
cff_compute_max_advance( TT_Face face,
FT_Int* max_advance )
{
FT_Error error = 0;
@ -2124,7 +2124,7 @@
*max_advance = 0;
/* Initialize load decoder */
CFF_Init_Decoder( &decoder, face, 0, 0, 0 );
cff_decoder_init( &decoder, face, 0, 0, 0 );
decoder.builder.metrics_only = 1;
decoder.builder.load_points = 0;
@ -2139,14 +2139,14 @@
/* now get load the unscaled outline */
error = CFF_Access_Element( &cff->charstrings_index, glyph_index,
error = cff_index_access_element( &cff->charstrings_index, glyph_index,
&charstring, &charstring_len );
if ( !error )
{
CFF_Prepare_Decoder( &decoder, glyph_index );
error = CFF_Parse_CharStrings( &decoder, charstring, charstring_len );
cff_decoder_prepare( &decoder, glyph_index );
error = cff_decoder_parse_charstrings( &decoder, charstring, charstring_len );
CFF_Forget_Element( &cff->charstrings_index, &charstring );
cff_index_forget_element( &cff->charstrings_index, &charstring );
}
/* ignore the error if one has occurred -- skip to next glyph */
@ -2179,10 +2179,10 @@
FT_LOCAL_DEF( FT_Error )
CFF_Load_Glyph( CFF_GlyphSlot glyph,
CFF_Size size,
FT_Int glyph_index,
FT_Int load_flags )
cff_slot_load( CFF_GlyphSlot glyph,
CFF_Size size,
FT_Int glyph_index,
FT_Int load_flags )
{
FT_Error error;
CFF_Decoder decoder;
@ -2218,26 +2218,26 @@
FT_ULong charstring_len;
CFF_Init_Decoder( &decoder, face, size, glyph, hinting );
cff_decoder_init( &decoder, face, size, glyph, hinting );
decoder.builder.no_recurse =
(FT_Bool)( ( load_flags & FT_LOAD_NO_RECURSE ) != 0 );
/* now load the unscaled outline */
error = CFF_Access_Element( &cff->charstrings_index, glyph_index,
error = cff_index_access_element( &cff->charstrings_index, glyph_index,
&charstring, &charstring_len );
if ( !error )
{
CFF_IndexRec csindex = cff->charstrings_index;
CFF_Prepare_Decoder( &decoder, glyph_index );
error = CFF_Parse_CharStrings( &decoder, charstring, charstring_len );
cff_decoder_prepare( &decoder, glyph_index );
error = cff_decoder_parse_charstrings( &decoder, charstring, charstring_len );
CFF_Forget_Element( &cff->charstrings_index, &charstring );
cff_index_forget_element( &cff->charstrings_index, &charstring );
/* We set control_data and control_len if charstrings is loaded. */
/* See how charstring loads at CFF_Access_Element() in cffload.c. */
/* See how charstring loads at cff_index_access_element() in cffload.c. */
glyph->root.control_data =
csindex.bytes + csindex.offsets[glyph_index] - 1;
@ -2246,7 +2246,7 @@
}
/* save new glyph tables */
CFF_Builder_Done( &decoder.builder );
cff_builder_done( &decoder.builder );
}
font_matrix = cff->top_font.font_dict.font_matrix;

View File

@ -172,35 +172,35 @@ FT_BEGIN_HEADER
FT_LOCAL( void )
CFF_Init_Decoder( CFF_Decoder* decoder,
cff_decoder_init( CFF_Decoder* decoder,
TT_Face face,
CFF_Size size,
CFF_GlyphSlot slot,
FT_Bool hinting );
FT_LOCAL( void )
CFF_Prepare_Decoder( CFF_Decoder* decoder,
cff_decoder_prepare( CFF_Decoder* decoder,
FT_UInt glyph_index );
#if 0 /* unused until we support pure CFF fonts */
/* Compute the maximum advance width of a font through quick parsing */
FT_LOCAL( FT_Error )
CFF_Compute_Max_Advance( TT_Face face,
cff_compute_max_advance( TT_Face face,
FT_Int* max_advance );
#endif /* 0 */
FT_LOCAL( FT_Error )
CFF_Parse_CharStrings( CFF_Decoder* decoder,
FT_Byte* charstring_base,
FT_Int charstring_len );
cff_decoder_parse_charstrings( CFF_Decoder* decoder,
FT_Byte* charstring_base,
FT_Int charstring_len );
FT_LOCAL( FT_Error )
CFF_Load_Glyph( CFF_GlyphSlot glyph,
CFF_Size size,
FT_Int glyph_index,
FT_Int load_flags );
cff_slot_load( CFF_GlyphSlot glyph,
CFF_Size size,
FT_Int glyph_index,
FT_Int load_flags );
FT_END_HEADER

View File

@ -1047,7 +1047,7 @@
FT_LOCAL_DEF( FT_UShort )
CFF_Get_Standard_Encoding( FT_UInt charcode )
cff_get_standard_encoding( FT_UInt charcode )
{
return (FT_UShort)(charcode < 256 ? cff_standard_encoding[charcode] : 0);
}
@ -1172,9 +1172,10 @@
}
/* allocate a table containing pointers to an index's elements */
static FT_Error
cff_explicit_index( CFF_Index idx,
FT_Byte*** table )
cff_index_get_pointers( CFF_Index idx,
FT_Byte*** table )
{
FT_Error error = 0;
FT_Memory memory = idx->stream->memory;
@ -1205,10 +1206,10 @@
FT_LOCAL_DEF( FT_Error )
CFF_Access_Element( CFF_Index idx,
FT_UInt element,
FT_Byte** pbytes,
FT_ULong* pbyte_len )
cff_index_access_element( CFF_Index idx,
FT_UInt element,
FT_Byte** pbytes,
FT_ULong* pbyte_len )
{
FT_Error error = 0;
@ -1270,8 +1271,8 @@
FT_LOCAL_DEF( void )
CFF_Forget_Element( CFF_Index idx,
FT_Byte** pbytes )
cff_index_forget_element( CFF_Index idx,
FT_Byte** pbytes )
{
if ( idx->bytes == 0 )
{
@ -1284,8 +1285,8 @@
FT_LOCAL_DEF( FT_String* )
CFF_Get_Name( CFF_Index idx,
FT_UInt element )
cff_index_get_name( CFF_Index idx,
FT_UInt element )
{
FT_Memory memory = idx->stream->memory;
FT_Byte* bytes;
@ -1294,7 +1295,7 @@
FT_String* name = 0;
error = CFF_Access_Element( idx, element, &bytes, &byte_len );
error = cff_index_access_element( idx, element, &bytes, &byte_len );
if ( error )
goto Exit;
@ -1303,7 +1304,7 @@
FT_MEM_COPY( name, bytes, byte_len );
name[byte_len] = 0;
}
CFF_Forget_Element( idx, &bytes );
cff_index_forget_element( idx, &bytes );
Exit:
return name;
@ -1311,18 +1312,18 @@
FT_LOCAL_DEF( FT_String* )
CFF_Get_String( CFF_Index idx,
FT_UInt sid,
PSNames_Service psnames_interface )
cff_index_get_sid_string( CFF_Index idx,
FT_UInt sid,
PSNames_Service psnames_service )
{
/* if it is not a standard string, return it */
if ( sid > 390 )
return CFF_Get_Name( idx, sid - 391 );
return cff_index_get_name( idx, sid - 391 );
/* that's a standard string, fetch a copy from the PSName module */
{
FT_String* name = 0;
const char* adobe_name = psnames_interface->adobe_std_strings( sid );
const char* adobe_name = psnames_service->adobe_std_strings( sid );
FT_UInt len;
@ -1414,8 +1415,8 @@
FT_LOCAL_DEF( FT_Byte )
CFF_Get_FD( CFF_FDSelect select,
FT_UInt glyph_index )
cff_fd_select_get( CFF_FDSelect select,
FT_UInt glyph_index )
{
FT_Byte fd = 0;
@ -1484,23 +1485,7 @@
/*************************************************************************/
static void
CFF_Done_Encoding( CFF_Encoding encoding,
FT_Stream stream )
{
FT_Memory memory = stream->memory;
FT_FREE( encoding->codes );
FT_FREE( encoding->sids );
encoding->format = 0;
encoding->offset = 0;
encoding->codes = 0;
encoding->sids = 0;
}
static void
CFF_Done_Charset( CFF_Charset charset,
cff_charset_done( CFF_Charset charset,
FT_Stream stream )
{
FT_Memory memory = stream->memory;
@ -1509,12 +1494,11 @@
FT_FREE( charset->sids );
charset->format = 0;
charset->offset = 0;
charset->sids = 0;
}
static FT_Error
CFF_Load_Charset( CFF_Charset charset,
cff_charset_load( CFF_Charset charset,
FT_UInt num_glyphs,
FT_Stream stream,
FT_ULong base_offset,
@ -1525,13 +1509,6 @@
FT_UShort glyph_sid;
charset->offset = base_offset + offset;
/* Get the format of the table. */
if ( FT_STREAM_SEEK( charset->offset ) ||
FT_READ_BYTE( charset->format ) )
goto Exit;
/* If the the offset is greater than 2, we have to parse the */
/* charset table. */
if ( offset > 2 )
@ -1539,6 +1516,13 @@
FT_UInt j;
charset->offset = base_offset + offset;
/* Get the format of the table. */
if ( FT_STREAM_SEEK( charset->offset ) ||
FT_READ_BYTE( charset->format ) )
goto Exit;
/* Allocate memory for sids. */
if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) )
goto Exit;
@ -1549,12 +1533,15 @@
switch ( charset->format )
{
case 0:
for ( j = 1; j < num_glyphs; j++ )
if ( num_glyphs > 0 )
{
if ( FT_READ_USHORT( glyph_sid ) )
if ( FT_FRAME_ENTER( (num_glyphs-1)*2 ) )
goto Exit;
charset->sids[j] = glyph_sid;
for ( j = 1; j < num_glyphs; j++ )
charset->sids[j] = FT_GET_USHORT();
FT_FRAME_EXIT();
}
break;
@ -1587,14 +1574,14 @@
}
/* Fill in the range of sids -- `nleft + 1' glyphs. */
for ( i = 0; i <= nleft; i++, j++, glyph_sid++ )
for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ )
charset->sids[j] = glyph_sid;
}
}
break;
default:
FT_ERROR(( "CFF_Load_Charset: invalid table format!\n" ));
FT_ERROR(( "cff_charset_load: invalid table format!\n" ));
error = CFF_Err_Invalid_File_Format;
goto Exit;
}
@ -1610,12 +1597,14 @@
/* the first num_glyphs, and hence must match the predefined */
/* charset *exactly*. */
charset->offset = offset; /* record charset type */
switch ( offset )
{
case 0:
if ( num_glyphs != 229 )
{
FT_ERROR(("CFF_Load_Charset: implicit charset not equal to\n"
FT_ERROR(("cff_charset_load: implicit charset not equal to\n"
"predefined charset (Adobe ISO-Latin)!\n" ));
error = CFF_Err_Invalid_File_Format;
goto Exit;
@ -1634,7 +1623,7 @@
case 1:
if ( num_glyphs != 166 )
{
FT_ERROR(( "CFF_Load_Charset: implicit charset not equal to\n"
FT_ERROR(( "cff_charset_load: implicit charset not equal to\n"
"predefined charset (Adobe Expert)!\n" ));
error = CFF_Err_Invalid_File_Format;
goto Exit;
@ -1653,7 +1642,7 @@
case 2:
if ( num_glyphs != 87 )
{
FT_ERROR(( "CFF_Load_Charset: implicit charset not equal to\n"
FT_ERROR(( "cff_charset_load: implicit charset not equal to\n"
"predefined charset (Adobe Expert Subset)!\n" ));
error = CFF_Err_Invalid_File_Format;
goto Exit;
@ -1681,8 +1670,7 @@
if ( error )
if ( charset->sids )
{
if ( charset->sids )
FT_FREE( charset->sids );
FT_FREE( charset->sids );
charset->format = 0;
charset->offset = 0;
charset->sids = 0;
@ -1692,8 +1680,19 @@
}
static void
cff_encoding_done( CFF_Encoding encoding )
{
encoding->format = 0;
encoding->offset = 0;
encoding->count = 0;
}
static FT_Error
CFF_Load_Encoding( CFF_Encoding encoding,
cff_encoding_load( CFF_Encoding encoding,
CFF_Charset charset,
FT_UInt num_glyphs,
FT_Stream stream,
@ -1705,7 +1704,7 @@
FT_UInt count;
FT_UInt j;
FT_UShort glyph_sid;
FT_Byte glyph_code;
FT_UInt glyph_code;
/* Check for charset->sids. If we do not have this, we fail. */
@ -1715,14 +1714,8 @@
goto Exit;
}
/* Allocate memory for sids/codes -- there are at most 256 sids/codes */
/* for an encoding. */
if ( FT_NEW_ARRAY( encoding->sids, 256 ) ||
FT_NEW_ARRAY( encoding->codes, 256 ) )
goto Exit;
/* Zero out the code to gid/sid mappings. */
for ( j = 0; j < 255; j++ )
for ( j = 0; j < 256; j++ )
{
encoding->sids [j] = 0;
encoding->codes[j] = 0;
@ -1751,32 +1744,43 @@
FT_READ_BYTE( count ) )
goto Exit;
encoding->count = (count+1);
switch ( encoding->format & 0x7F )
{
case 0:
for ( j = 1; j <= count; j++ )
{
if ( FT_READ_BYTE( glyph_code ) )
FT_Byte* p;
if ( FT_FRAME_ENTER( count ) )
goto Exit;
/* Make sure j is not too big. */
if ( j > num_glyphs )
goto Exit;
p = (FT_Byte*) stream->cursor;
for ( j = 1; j <= count; j++ )
{
glyph_code = *p++;
/* Assign code to GID mapping. */
encoding->codes[glyph_code] = (FT_UShort)j;
/* Make sure j is not too big. */
if ( (FT_UInt) glyph_code < num_glyphs )
{
/* Assign code to GID mapping. */
encoding->codes[glyph_code] = (FT_UShort)j;
/* Assign code to SID mapping. */
encoding->sids[glyph_code] = charset->sids[j];
/* Assign code to SID mapping. */
encoding->sids[glyph_code] = charset->sids[j];
}
}
FT_FRAME_EXIT();
}
break;
case 1:
{
FT_Byte nleft;
FT_UInt i = 1;
FT_UInt k;
FT_Byte nleft;
FT_UInt i = 1;
FT_UInt k;
/* Parse the Format1 ranges. */
@ -1797,21 +1801,21 @@
for ( k = i; k < nleft + i; k++, glyph_code++ )
{
/* Make sure k is not too big. */
if ( k > num_glyphs )
goto Exit;
if ( k < num_glyphs && glyph_code < 256 )
{
/* Assign code to GID mapping. */
encoding->codes[glyph_code] = (FT_UShort)k;
/* Assign code to GID mapping. */
encoding->codes[glyph_code] = (FT_UShort)k;
/* Assign code to SID mapping. */
encoding->sids[glyph_code] = charset->sids[k];
/* 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_encoding_load: invalid table format!\n" ));
error = CFF_Err_Invalid_File_Format;
goto Exit;
}
@ -1819,7 +1823,7 @@
/* Parse supplemental encodings, if any. */
if ( encoding->format & 0x80 )
{
FT_UInt glyph_id;
FT_UInt gindex;
/* count supplements */
@ -1841,14 +1845,14 @@
/* First, lookup GID which has been assigned to */
/* SID glyph_sid. */
for ( glyph_id = 0; glyph_id < num_glyphs; glyph_id++ )
for ( gindex = 0; gindex < num_glyphs; gindex++ )
{
if ( charset->sids[glyph_id] == glyph_sid )
if ( charset->sids[gindex] == glyph_sid )
{
encoding->codes[glyph_code] = (FT_UShort) gindex;
break;
}
}
/* Now, make the assignment. */
encoding->codes[glyph_code] = (FT_UShort)glyph_id;
}
}
}
@ -1862,6 +1866,8 @@
/* encoding (see the note at the end of section 12 in the CFF */
/* specification). */
encoding->count = 256;
switch ( offset )
{
case 0:
@ -1869,37 +1875,14 @@
FT_MEM_COPY( encoding->sids, cff_standard_encoding,
256 * sizeof ( FT_UShort ) );
/* Construct code to GID mapping from code */
/* to SID mapping and charset. */
for ( j = 0; j < 256; j++ )
{
/* 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] )
break;
/* i will be equal to num_glyphs if we exited the above */
/* loop without a match. In this case, we also have to */
/* fix the code to SID mapping. */
if ( i == num_glyphs )
{
encoding->codes[j] = 0;
encoding->sids [j] = 0;
}
else
encoding->codes[j] = (FT_UShort)i;
}
}
break;
goto Populate;
case 1:
/* First, copy the code to SID mapping. */
FT_MEM_COPY( encoding->sids, cff_expert_encoding,
256 * sizeof ( FT_UShort ) );
Populate:
/* Construct code to GID mapping from code to SID mapping */
/* and charset. */
for ( j = 0; j < 256; j++ )
@ -1927,7 +1910,7 @@
break;
default:
FT_ERROR(( "CFF_Load_Encoding: invalid table format!\n" ));
FT_ERROR(( "cff_encoding_load: invalid table format!\n" ));
error = CFF_Err_Invalid_File_Format;
goto Exit;
}
@ -1936,28 +1919,12 @@
Exit:
/* Clean up if there was an error. */
if ( error )
{
if ( encoding->sids || encoding->codes )
{
if ( encoding->sids )
FT_FREE( encoding->sids );
if ( encoding->codes )
FT_FREE( encoding->codes );
charset->format = 0;
charset->offset = 0;
charset->sids = 0;
}
}
return error;
}
static FT_Error
CFF_Load_SubFont( CFF_SubFont font,
cff_subfont_load( CFF_SubFont font,
CFF_Index idx,
FT_UInt font_index,
FT_Stream stream,
@ -1971,7 +1938,7 @@
CFF_Private priv = &font->private_dict;
CFF_Parser_Init( &parser, CFF_CODE_TOPDICT, &font->font_dict );
cff_parser_init( &parser, CFF_CODE_TOPDICT, &font->font_dict );
/* set defaults */
FT_MEM_SET( top, 0, sizeof ( *top ) );
@ -1983,10 +1950,10 @@
top->font_matrix.yy = 0x10000L;
top->cid_count = 8720;
error = CFF_Access_Element( idx, font_index, &dict, &dict_len ) ||
CFF_Parser_Run( &parser, dict, dict + dict_len );
error = cff_index_access_element( idx, font_index, &dict, &dict_len ) ||
cff_parser_run( &parser, dict, dict + dict_len );
CFF_Forget_Element( idx, &dict );
cff_index_forget_element( idx, &dict );
if ( error )
goto Exit;
@ -2007,13 +1974,13 @@
priv->expansion_factor = (FT_Fixed)0.06 * 0x10000L;
priv->blue_scale = (FT_Fixed)0.039625 * 0x10000L;
CFF_Parser_Init( &parser, CFF_CODE_PRIVATE, priv );
cff_parser_init( &parser, CFF_CODE_PRIVATE, priv );
if ( FT_STREAM_SEEK( base_offset + font->font_dict.private_offset ) ||
FT_FRAME_ENTER( font->font_dict.private_size ) )
goto Exit;
error = CFF_Parser_Run( &parser,
error = cff_parser_run( &parser,
(FT_Byte*)stream->cursor,
(FT_Byte*)stream->limit );
FT_FRAME_EXIT();
@ -2033,7 +2000,7 @@
goto Exit;
font->num_local_subrs = font->local_subrs_index.count;
error = cff_explicit_index( &font->local_subrs_index,
error = cff_index_get_pointers( &font->local_subrs_index,
&font->local_subrs );
if ( error )
goto Exit;
@ -2045,7 +2012,7 @@
static void
CFF_Done_SubFont( FT_Memory memory,
cff_subfont_done( FT_Memory memory,
CFF_SubFont subfont )
{
if ( subfont )
@ -2057,7 +2024,7 @@
FT_LOCAL_DEF( FT_Error )
CFF_Load_Font( FT_Stream stream,
cff_font_load( FT_Stream stream,
FT_Int face_index,
CFF_Font font )
{
@ -2080,7 +2047,7 @@
CFF_FontRecDict dict;
FT_MEM_SET( font, 0, sizeof ( *font ) );
FT_ZERO( font );
font->stream = stream;
font->memory = memory;
@ -2116,7 +2083,7 @@
font->num_faces = font->name_index.count;
if ( face_index >= (FT_Int)font->num_faces )
{
FT_ERROR(( "CFF_Load_Font: incorrect face index = %d\n",
FT_ERROR(( "cff_font_load: incorrect face index = %d\n",
face_index ));
error = CFF_Err_Invalid_Argument;
}
@ -2126,7 +2093,7 @@
goto Exit;
/* now, parse the top-level font dictionary */
error = CFF_Load_SubFont( &font->top_font,
error = cff_subfont_load( &font->top_font,
&font->font_dict_index,
face_index,
stream,
@ -2153,7 +2120,7 @@
if ( fd_index.count > CFF_MAX_CID_FONTS )
{
FT_ERROR(( "CFF_Load_Font: FD array too large in CID font\n" ));
FT_ERROR(( "cff_font_load: FD array too large in CID font\n" ));
goto Fail_CID;
}
@ -2170,7 +2137,7 @@
for ( idx = 0; idx < fd_index.count; idx++ )
{
sub = font->subfonts[idx];
error = CFF_Load_SubFont( sub, &fd_index, idx,
error = cff_subfont_load( sub, &fd_index, idx,
stream, base_offset );
if ( error )
goto Fail_CID;
@ -2194,7 +2161,7 @@
/* read the charstrings index now */
if ( dict->charstrings_offset == 0 )
{
FT_ERROR(( "CFF_Load_Font: no charstrings offset!\n" ));
FT_ERROR(( "cff_font_load: no charstrings offset!\n" ));
error = CFF_Err_Unknown_File_Format;
goto Exit;
}
@ -2210,19 +2177,19 @@
font->num_global_subrs = font->global_subrs_index.count;
font->num_glyphs = font->charstrings_index.count;
error = cff_explicit_index( &font->global_subrs_index,
error = cff_index_get_pointers( &font->global_subrs_index,
&font->global_subrs ) ;
if ( error )
goto Exit;
/* read the Charset and Encoding tables when available */
error = CFF_Load_Charset( &font->charset, font->num_glyphs, stream,
error = cff_charset_load( &font->charset, font->num_glyphs, stream,
base_offset, dict->charset_offset );
if ( error )
goto Exit;
error = CFF_Load_Encoding( &font->encoding,
error = cff_encoding_load( &font->encoding,
&font->charset,
font->num_glyphs,
stream,
@ -2232,7 +2199,7 @@
goto Exit;
/* get the font name */
font->font_name = CFF_Get_Name( &font->name_index, face_index );
font->font_name = cff_index_get_name( &font->name_index, face_index );
Exit:
return error;
@ -2240,7 +2207,7 @@
FT_LOCAL_DEF( void )
CFF_Done_Font( CFF_Font font )
cff_font_done( CFF_Font font )
{
FT_Memory memory = font->memory;
FT_UInt idx;
@ -2257,15 +2224,15 @@
if ( font->num_subfonts > 0 )
{
for ( idx = 0; idx < font->num_subfonts; idx++ )
CFF_Done_SubFont( memory, font->subfonts[idx] );
cff_subfont_done( memory, font->subfonts[idx] );
FT_FREE( font->subfonts );
}
CFF_Done_Encoding( &font->encoding, font->stream );
CFF_Done_Charset( &font->charset, font->stream );
cff_encoding_done( &font->encoding );
cff_charset_done( &font->charset, font->stream );
CFF_Done_SubFont( memory, &font->top_font );
cff_subfont_done( memory, &font->top_font );
CFF_Done_FD_Select( &font->fd_select, font->stream );

View File

@ -28,42 +28,42 @@
FT_BEGIN_HEADER
FT_LOCAL( FT_UShort )
CFF_Get_Standard_Encoding( FT_UInt charcode );
cff_get_standard_encoding( FT_UInt charcode );
FT_LOCAL( FT_String* )
CFF_Get_Name( CFF_Index idx,
FT_UInt element );
cff_index_get_name( CFF_Index idx,
FT_UInt element );
FT_LOCAL( FT_String* )
CFF_Get_String( CFF_Index idx,
FT_UInt sid,
PSNames_Service psnames_interface );
cff_index_get_sid_string( CFF_Index idx,
FT_UInt sid,
PSNames_Service psnames_interface );
FT_LOCAL( FT_Error )
CFF_Access_Element( CFF_Index idx,
FT_UInt element,
FT_Byte** pbytes,
FT_ULong* pbyte_len );
cff_index_access_element( CFF_Index idx,
FT_UInt element,
FT_Byte** pbytes,
FT_ULong* pbyte_len );
FT_LOCAL( void )
CFF_Forget_Element( CFF_Index idx,
FT_Byte** pbytes );
cff_index_forget_element( CFF_Index idx,
FT_Byte** pbytes );
FT_LOCAL( FT_Error )
CFF_Load_Font( FT_Stream stream,
cff_font_load( FT_Stream stream,
FT_Int face_index,
CFF_Font font );
FT_LOCAL( void )
CFF_Done_Font( CFF_Font font );
cff_font_done( CFF_Font font );
FT_LOCAL( FT_Byte )
CFF_Get_FD( CFF_FDSelect select,
FT_UInt glyph_index );
cff_fd_select_get( CFF_FDSelect select,
FT_UInt glyph_index );
FT_END_HEADER

View File

@ -28,7 +28,7 @@
#include FT_INTERNAL_POSTSCRIPT_HINTS_H
#include "cffobjs.h"
#include "cffload.h"
#include "cffcmap.h"
#include "cfferrs.h"
@ -53,7 +53,7 @@
static PSH_Globals_Funcs
CFF_Size_Get_Globals_Funcs( CFF_Size size )
cff_size_get_globals_funcs( CFF_Size size )
{
CFF_Face face = (CFF_Face)size->face;
CFF_Font font = (CFF_FontRec *)face->extra.data;
@ -70,14 +70,14 @@
FT_LOCAL_DEF( void )
CFF_Size_Done( CFF_Size size )
cff_size_done( CFF_Size size )
{
if ( size->internal )
{
PSH_Globals_Funcs funcs;
funcs = CFF_Size_Get_Globals_Funcs( size );
funcs = cff_size_get_globals_funcs( size );
if ( funcs )
funcs->destroy( (PSH_Globals)size->internal );
@ -87,10 +87,10 @@
FT_LOCAL_DEF( FT_Error )
CFF_Size_Init( CFF_Size size )
cff_size_init( CFF_Size size )
{
FT_Error error = 0;
PSH_Globals_Funcs funcs = CFF_Size_Get_Globals_Funcs( size );
PSH_Globals_Funcs funcs = cff_size_get_globals_funcs( size );
if ( funcs )
@ -160,9 +160,9 @@
FT_LOCAL_DEF( FT_Error )
CFF_Size_Reset( CFF_Size size )
cff_size_reset( CFF_Size size )
{
PSH_Globals_Funcs funcs = CFF_Size_Get_Globals_Funcs( size );
PSH_Globals_Funcs funcs = cff_size_get_globals_funcs( size );
FT_Error error = 0;
@ -182,14 +182,14 @@
/*************************************************************************/
FT_LOCAL_DEF( void )
CFF_GlyphSlot_Done( CFF_GlyphSlot slot )
cff_slot_done( CFF_GlyphSlot slot )
{
slot->root.internal->glyph_hints = 0;
}
FT_LOCAL_DEF( FT_Error )
CFF_GlyphSlot_Init( CFF_GlyphSlot slot )
cff_slot_init( CFF_GlyphSlot slot )
{
CFF_Face face = (CFF_Face)slot->root.face;
CFF_Font font = (CFF_FontRec *)face->extra.data;
@ -224,7 +224,7 @@
/*************************************************************************/
static FT_String*
CFF_StrCopy( FT_Memory memory,
cff_strcpy( FT_Memory memory,
const FT_String* source )
{
FT_Error error;
@ -245,8 +245,9 @@
FT_LOCAL_DEF( FT_Error )
CFF_Face_Init( FT_Stream stream,
cff_face_init( FT_Stream stream,
CFF_Face face,
FT_Int face_index,
FT_Int num_params,
@ -341,11 +342,12 @@
goto Exit;
face->extra.data = cff;
error = CFF_Load_Font( stream, face_index, cff );
error = cff_font_load( stream, face_index, cff );
if ( error )
goto Exit;
cff->pshinter = pshinter;
cff->psnames = psnames;
/* Complement the root flags with some interesting information. */
/* Note that this is only necessary for pure CFF and CEF fonts. */
@ -361,7 +363,7 @@
/* we need the `PSNames' module for pure-CFF and CEF formats */
if ( !psnames )
{
FT_ERROR(( "CFF_Face_Init:" ));
FT_ERROR(( "cff_face_init:" ));
FT_ERROR(( " cannot open CFF & CEF fonts\n" ));
FT_ERROR(( " " ));
FT_ERROR(( " without the `PSNames' module\n" ));
@ -395,11 +397,11 @@
root->units_per_EM = 1000;
/* retrieve font family & style name */
root->family_name = CFF_Get_Name( &cff->name_index, face_index );
root->family_name = cff_index_get_name( &cff->name_index, face_index );
if ( dict->cid_registry )
root->style_name = CFF_StrCopy( memory, "Regular" ); /* XXXX */
root->style_name = cff_strcpy( memory, "Regular" ); /* XXXX */
else
root->style_name = CFF_Get_String( &cff->string_index,
root->style_name = cff_index_get_sid_string( &cff->string_index,
dict->weight,
psnames );
@ -445,7 +447,82 @@
root->style_flags = flags;
/* XXX: no charmaps for pure CFF fonts currently! */
/*******************************************************************/
/* */
/* Compute char maps. */
/* */
/* try to synthetize a Unicode charmap if there is none available */
/* already. If an OpenType font contains a Unicode "cmap", we */
/* will use it, wathever be in the CFF part of the file.. */
{
FT_CharMapRec cmaprec;
FT_CharMap cmap;
FT_UInt nn;
CFF_Encoding encoding = &cff->encoding;
for ( nn = 0; nn < (FT_UInt) root->num_charmaps; nn++ )
{
cmap = root->charmaps[nn];
/* Windows Unicode (3,1) ? */
if ( cmap->platform_id == 3 && cmap->platform_id == 1 )
goto Skip_Unicode;
/* Deprecated Unicode platform id ?? */
if ( cmap->platform_id == 0 )
break; /* Standard Unicode (deprecated) */
}
/* we didn't find a Unicode charmap, synthetize one */
#ifdef FT_CONFIG_OPTION_USE_CMAPS
cmaprec.face = root;
cmaprec.platform_id = 3;
cmaprec.encoding_id = 1;
cmaprec.encoding = ft_encoding_unicode;
FT_CMap_New( &cff_cmap_unicode_class_rec, NULL, &cmaprec, NULL );
Skip_Unicode:
if ( encoding->count > 0 )
{
FT_CMap_Class clazz;
cmaprec.face = root;
cmaprec.platform_id = 7; /* Adobe platform id */
switch( encoding->offset )
{
case 0:
cmaprec.encoding_id = 0;
cmaprec.encoding = ft_encoding_adobe_standard;
clazz = &cff_cmap_encoding_class_rec;
break;
case 1:
cmaprec.encoding_id = 1;
cmaprec.encoding = ft_encoding_adobe_expert;
clazz = &cff_cmap_encoding_class_rec;
break;
default:
cmaprec.encoding_id = 3;
cmaprec.encoding = ft_encoding_adobe_custom;
clazz = &cff_cmap_encoding_class_rec;
}
FT_CMap_New( clazz, NULL, &cmaprec, NULL );
#else /* !FT_CONFIG_OPTION_USE_CMAPS */
/* unimplemented !! */
#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
}
}
}
}
@ -459,7 +536,7 @@
FT_LOCAL_DEF( void )
CFF_Face_Done( CFF_Face face )
cff_face_done( CFF_Face face )
{
FT_Memory memory = face->root.memory;
SFNT_Service sfnt = (SFNT_Service)face->sfnt;
@ -474,7 +551,7 @@
if ( cff )
{
CFF_Done_Font( cff );
cff_font_done( cff );
FT_FREE( face->extra.data );
}
}
@ -482,7 +559,7 @@
FT_LOCAL_DEF( FT_Error )
CFF_Driver_Init( CFF_Driver driver )
cff_driver_init( CFF_Driver driver )
{
FT_UNUSED( driver );
@ -491,7 +568,7 @@
FT_LOCAL_DEF( void )
CFF_Driver_Done( CFF_Driver driver )
cff_driver_done( CFF_Driver driver )
{
FT_UNUSED( driver );
}

View File

@ -23,6 +23,7 @@
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_CFF_TYPES_H
#include FT_INTERNAL_TRUETYPE_TYPES_H
#include FT_INTERNAL_POSTSCRIPT_NAMES_H
@ -110,19 +111,19 @@ FT_BEGIN_HEADER
FT_LOCAL( FT_Error )
CFF_Size_Init( CFF_Size size );
cff_size_init( CFF_Size size );
FT_LOCAL( void )
CFF_Size_Done( CFF_Size size );
cff_size_done( CFF_Size size );
FT_LOCAL( FT_Error )
CFF_Size_Reset( CFF_Size size );
cff_size_reset( CFF_Size size );
FT_LOCAL( void )
CFF_GlyphSlot_Done( CFF_GlyphSlot slot );
cff_slot_done( CFF_GlyphSlot slot );
FT_LOCAL( FT_Error )
CFF_GlyphSlot_Init( CFF_GlyphSlot slot );
cff_slot_init( CFF_GlyphSlot slot );
/*************************************************************************/
@ -130,14 +131,14 @@ FT_BEGIN_HEADER
/* Face functions */
/* */
FT_LOCAL( FT_Error )
CFF_Face_Init( FT_Stream stream,
cff_face_init( FT_Stream stream,
CFF_Face face,
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params );
FT_LOCAL( void )
CFF_Face_Done( CFF_Face face );
cff_face_done( CFF_Face face );
/*************************************************************************/
@ -145,10 +146,10 @@ FT_BEGIN_HEADER
/* Driver functions */
/* */
FT_LOCAL( FT_Error )
CFF_Driver_Init( CFF_Driver driver );
cff_driver_init( CFF_Driver driver );
FT_LOCAL( void )
CFF_Driver_Done( CFF_Driver driver );
cff_driver_done( CFF_Driver driver );
FT_END_HEADER

View File

@ -64,7 +64,7 @@
FT_LOCAL_DEF( void )
CFF_Parser_Init( CFF_Parser parser,
cff_parser_init( CFF_Parser parser,
FT_UInt code,
void* object )
{
@ -480,7 +480,7 @@
FT_LOCAL_DEF( FT_Error )
CFF_Parser_Run( CFF_Parser parser,
cff_parser_run( CFF_Parser parser,
FT_Byte* start,
FT_Byte* limit )
{

View File

@ -50,12 +50,12 @@ FT_BEGIN_HEADER
FT_LOCAL( void )
CFF_Parser_Init( CFF_Parser parser,
cff_parser_init( CFF_Parser parser,
FT_UInt code,
void* object );
FT_LOCAL( FT_Error )
CFF_Parser_Run( CFF_Parser parser,
cff_parser_run( CFF_Parser parser,
FT_Byte* start,
FT_Byte* limit );

View File

@ -28,6 +28,7 @@ CFF_DRV_SRC := $(CFF_DIR_)cffobjs.c \
$(CFF_DIR_)cffload.c \
$(CFF_DIR_)cffgload.c \
$(CFF_DIR_)cffparse.c \
$(CFF_DIR_)cffcmap.c \
$(CFF_DIR_)cffdrivr.c
# CFF driver headers