summaryrefslogtreecommitdiff
path: root/Build/source/libs/freetype2/src/cid/cidload.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/freetype2/src/cid/cidload.c')
-rw-r--r--Build/source/libs/freetype2/src/cid/cidload.c413
1 files changed, 254 insertions, 159 deletions
diff --git a/Build/source/libs/freetype2/src/cid/cidload.c b/Build/source/libs/freetype2/src/cid/cidload.c
index 56112919876..8d96ea6ee46 100644
--- a/Build/source/libs/freetype2/src/cid/cidload.c
+++ b/Build/source/libs/freetype2/src/cid/cidload.c
@@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 font loader (body). */
/* */
-/* Copyright 1996-2001 by */
+/* Copyright 1996-2001, 2002, 2003, 2004, 2005 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -26,9 +26,6 @@
#include "ciderrs.h"
-#include <stdio.h>
-#include <ctype.h> /* for isspace(), isalnum() */
-
/*************************************************************************/
/* */
@@ -41,8 +38,8 @@
/* read a single offset */
- FT_LOCAL_DEF FT_Long
- cid_get_offset( FT_Byte** start,
+ FT_LOCAL_DEF( FT_Long )
+ cid_get_offset( FT_Byte* *start,
FT_Byte offsize )
{
FT_Long result;
@@ -60,24 +57,6 @@
}
- FT_LOCAL_DEF void
- cid_decrypt( FT_Byte* buffer,
- FT_Offset length,
- FT_UShort seed )
- {
- while ( length > 0 )
- {
- FT_Byte plain;
-
-
- plain = (FT_Byte)( *buffer ^ ( seed >> 8 ) );
- seed = (FT_UShort)( ( *buffer + seed ) * 52845U + 22719 );
- *buffer++ = plain;
- length--;
- }
- }
-
-
/*************************************************************************/
/*************************************************************************/
/***** *****/
@@ -88,19 +67,19 @@
static FT_Error
- cid_load_keyword( CID_Face face,
- CID_Loader* loader,
- const T1_Field* keyword )
+ cid_load_keyword( CID_Face face,
+ CID_Loader* loader,
+ const T1_Field keyword )
{
- FT_Error error;
- CID_Parser* parser = &loader->parser;
- FT_Byte* object;
- void* dummy_object;
- CID_Info* cid = &face->cid;
+ FT_Error error;
+ CID_Parser* parser = &loader->parser;
+ FT_Byte* object;
+ void* dummy_object;
+ CID_FaceInfo cid = &face->cid;
/* if the keyword has a dedicated callback, call it */
- if ( keyword->type == t1_field_callback )
+ if ( keyword->type == T1_FIELD_TYPE_CALLBACK )
{
keyword->reader( (FT_Face)face, parser );
error = parser->root.error;
@@ -110,17 +89,21 @@
/* we must now compute the address of our target object */
switch ( keyword->location )
{
- case t1_field_cid_info:
+ case T1_FIELD_LOCATION_CID_INFO:
object = (FT_Byte*)cid;
break;
- case t1_field_font_info:
+ case T1_FIELD_LOCATION_FONT_INFO:
object = (FT_Byte*)&cid->font_info;
break;
+ case T1_FIELD_LOCATION_BBOX:
+ object = (FT_Byte*)&cid->font_bbox;
+ break;
+
default:
{
- CID_FontDict* dict;
+ CID_FaceDict dict;
if ( parser->num_dict < 0 )
@@ -134,7 +117,7 @@
dict = cid->font_dicts + parser->num_dict;
switch ( keyword->location )
{
- case t1_field_private:
+ case T1_FIELD_LOCATION_PRIVATE:
object = (FT_Byte*)&dict->private_dict;
break;
@@ -147,46 +130,28 @@
dummy_object = object;
/* now, load the keyword data in the object's field(s) */
- if ( keyword->type == t1_field_integer_array ||
- keyword->type == t1_field_fixed_array )
- error = CID_Load_Field_Table( &loader->parser, keyword,
- &dummy_object );
+ if ( keyword->type == T1_FIELD_TYPE_INTEGER_ARRAY ||
+ keyword->type == T1_FIELD_TYPE_FIXED_ARRAY )
+ error = cid_parser_load_field_table( &loader->parser, keyword,
+ &dummy_object );
else
- error = CID_Load_Field( &loader->parser, keyword, &dummy_object );
+ error = cid_parser_load_field( &loader->parser,
+ keyword, &dummy_object );
Exit:
return error;
}
FT_CALLBACK_DEF( FT_Error )
- parse_font_bbox( CID_Face face,
- CID_Parser* parser )
- {
- FT_Fixed temp[4];
- FT_BBox* bbox = &face->cid.font_bbox;
-
-
- (void)CID_ToFixedArray( parser, 4, temp, 0 );
- bbox->xMin = FT_RoundFix( temp[0] );
- bbox->yMin = FT_RoundFix( temp[1] );
- bbox->xMax = FT_RoundFix( temp[2] );
- bbox->yMax = FT_RoundFix( temp[3] );
-
- return CID_Err_Ok; /* this is a callback function; */
- /* we must return an error code */
- }
-
-
- FT_CALLBACK_DEF( FT_Error )
parse_font_matrix( CID_Face face,
CID_Parser* parser )
{
- FT_Matrix* matrix;
- FT_Vector* offset;
- CID_FontDict* dict;
- FT_Face root = (FT_Face)&face->root;
- FT_Fixed temp[6];
- FT_Fixed temp_scale;
+ FT_Matrix* matrix;
+ FT_Vector* offset;
+ CID_FaceDict dict;
+ FT_Face root = (FT_Face)&face->root;
+ FT_Fixed temp[6];
+ FT_Fixed temp_scale;
if ( parser->num_dict >= 0 )
@@ -195,13 +160,13 @@
matrix = &dict->font_matrix;
offset = &dict->font_offset;
- (void)CID_ToFixedArray( parser, 6, temp, 3 );
+ (void)cid_parser_to_fixed_array( parser, 6, temp, 3 );
- temp_scale = ABS( temp[3] );
+ temp_scale = FT_ABS( temp[3] );
- /* Set Units per EM based on FontMatrix values. We set the value to */
+ /* Set units per EM based on FontMatrix values. We set the value to */
/* `1000/temp_scale', because temp_scale was already multiplied by */
- /* 1000 (in t1_tofixed(), from psobjs.c). */
+ /* 1000 (in `t1_tofixed', from psobjs.c). */
root->units_per_EM = (FT_UShort)( FT_DivFix( 0x10000L,
FT_DivFix( temp_scale, 1000 ) ) );
@@ -226,7 +191,7 @@
offset->y = temp[5] >> 16;
}
- return CID_Err_Ok; /* this is a callback function; */
+ return CID_Err_Ok; /* this is a callback function; */
/* we must return an error code */
}
@@ -235,20 +200,20 @@
parse_fd_array( CID_Face face,
CID_Parser* parser )
{
- CID_Info* cid = &face->cid;
- FT_Memory memory = face->root.memory;
- FT_Error error = CID_Err_Ok;
- FT_Long num_dicts;
+ CID_FaceInfo cid = &face->cid;
+ FT_Memory memory = face->root.memory;
+ FT_Error error = CID_Err_Ok;
+ FT_Long num_dicts;
- num_dicts = CID_ToInt( parser );
+ num_dicts = cid_parser_to_int( parser );
if ( !cid->font_dicts )
{
FT_Int n;
- if ( ALLOC_ARRAY( cid->font_dicts, num_dicts, CID_FontDict ) )
+ if ( FT_NEW_ARRAY( cid->font_dicts, num_dicts ) )
goto Exit;
cid->num_dicts = (FT_UInt)num_dicts;
@@ -256,7 +221,7 @@
/* don't forget to set a few defaults */
for ( n = 0; n < cid->num_dicts; n++ )
{
- CID_FontDict* dict = cid->font_dicts + n;
+ CID_FaceDict dict = cid->font_dicts + n;
/* default value for lenIV */
@@ -270,25 +235,16 @@
static
- const T1_Field cid_field_records[] =
+ const T1_FieldRec cid_field_records[] =
{
#include "cidtoken.h"
- T1_FIELD_CALLBACK( "FontBBox", parse_font_bbox )
- T1_FIELD_CALLBACK( "FDArray", parse_fd_array )
+ T1_FIELD_CALLBACK( "FDArray", parse_fd_array )
T1_FIELD_CALLBACK( "FontMatrix", parse_font_matrix )
- { 0, t1_field_cid_info, t1_field_none, 0, 0, 0, 0, 0 }
- };
-
- static int
- is_alpha( char c )
- {
- return ( isalnum( (int)c ) ||
- c == '.' ||
- c == '_' );
- }
+ { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0 }
+ };
static FT_Error
@@ -302,44 +258,61 @@
parser->root.cursor = base;
parser->root.limit = base + size;
- parser->root.error = 0;
+ parser->root.error = CID_Err_Ok;
{
FT_Byte* cur = base;
FT_Byte* limit = cur + size;
- for ( ;cur < limit; cur++ )
+ for (;;)
{
+ FT_Byte* newlimit;
+
+
+ parser->root.cursor = cur;
+ cid_parser_skip_spaces( parser );
+
+ if ( parser->root.cursor >= limit )
+ newlimit = limit - 1 - 17;
+ else
+ newlimit = parser->root.cursor - 17;
+
/* look for `%ADOBeginFontDict' */
- if ( *cur == '%' && cur + 20 < limit &&
- strncmp( (char*)cur, "%ADOBeginFontDict", 17 ) == 0 )
+ for ( ; cur < newlimit; cur++ )
{
- cur += 17;
-
- /* if /FDArray was found, then cid->num_dicts is > 0, and */
- /* we can start increasing parser->num_dict */
- if ( face->cid.num_dicts > 0 )
- parser->num_dict++;
+ if ( *cur == '%' &&
+ ft_strncmp( (char*)cur, "%ADOBeginFontDict", 17 ) == 0 )
+ {
+ /* if /FDArray was found, then cid->num_dicts is > 0, and */
+ /* we can start increasing parser->num_dict */
+ if ( face->cid.num_dicts > 0 )
+ parser->num_dict++;
+ }
}
+
+ cur = parser->root.cursor;
+ /* no error can occur in cid_parser_skip_spaces */
+ if ( cur >= limit )
+ break;
+
+ cid_parser_skip_PS_token( parser );
+ if ( parser->root.cursor >= limit || parser->root.error )
+ break;
+
/* look for immediates */
- else if ( *cur == '/' && cur + 2 < limit )
+ if ( *cur == '/' && cur + 2 < limit )
{
- FT_Byte* cur2;
- FT_Int len;
+ FT_PtrDist len;
cur++;
+ len = parser->root.cursor - cur;
- cur2 = cur;
- while ( cur2 < limit && is_alpha( *cur2 ) )
- cur2++;
-
- len = (FT_Int)( cur2 - cur );
if ( len > 0 && len < 22 )
{
/* now compare the immediate name to the keyword table */
- const T1_Field* keyword = cid_field_records;
+ T1_Field keyword = (T1_Field)cid_field_records;
for (;;)
@@ -351,10 +324,10 @@
if ( !name )
break;
- if ( cur[0] == name[0] &&
- len == (FT_Int)strlen( (const char*)name ) )
+ if ( cur[0] == name[0] &&
+ len == (FT_PtrDist)ft_strlen( (const char*)name ) )
{
- FT_Int n;
+ FT_PtrDist n;
for ( n = 1; n < len; n++ )
@@ -364,15 +337,11 @@
if ( n >= len )
{
/* we found it - run the parsing callback */
- parser->root.cursor = cur2;
- CID_Skip_Spaces( parser );
parser->root.error = cid_load_keyword( face,
loader,
keyword );
if ( parser->root.error )
return parser->root.error;
-
- cur = parser->root.cursor;
break;
}
}
@@ -380,6 +349,8 @@
}
}
}
+
+ cur = parser->root.cursor;
}
}
return parser->root.error;
@@ -390,68 +361,69 @@
static FT_Error
cid_read_subrs( CID_Face face )
{
- CID_Info* cid = &face->cid;
- FT_Memory memory = face->root.memory;
- FT_Stream stream = face->root.stream;
- FT_Error error;
- FT_Int n;
- CID_Subrs* subr;
- FT_UInt max_offsets = 0;
- FT_ULong* offsets = 0;
-
-
- if ( ALLOC_ARRAY( face->subrs, cid->num_dicts, CID_Subrs ) )
+ CID_FaceInfo cid = &face->cid;
+ FT_Memory memory = face->root.memory;
+ FT_Stream stream = face->cid_stream;
+ FT_Error error;
+ FT_Int n;
+ CID_Subrs subr;
+ FT_UInt max_offsets = 0;
+ FT_ULong* offsets = 0;
+ PSAux_Service psaux = (PSAux_Service)face->psaux;
+
+
+ if ( FT_NEW_ARRAY( face->subrs, cid->num_dicts ) )
goto Exit;
subr = face->subrs;
for ( n = 0; n < cid->num_dicts; n++, subr++ )
{
- CID_FontDict* dict = cid->font_dicts + n;
- FT_Int lenIV = dict->private_dict.lenIV;
- FT_UInt count, num_subrs = dict->num_subrs;
- FT_ULong data_len;
- FT_Byte* p;
+ CID_FaceDict dict = cid->font_dicts + n;
+ FT_Int lenIV = dict->private_dict.lenIV;
+ FT_UInt count, num_subrs = dict->num_subrs;
+ FT_ULong data_len;
+ FT_Byte* p;
/* reallocate offsets array if needed */
if ( num_subrs + 1 > max_offsets )
{
- FT_UInt new_max = ( num_subrs + 1 + 3 ) & -4;
+ FT_UInt new_max = FT_PAD_CEIL( num_subrs + 1, 4 );
- if ( REALLOC_ARRAY( offsets, max_offsets, new_max, FT_ULong ) )
+ if ( FT_RENEW_ARRAY( offsets, max_offsets, new_max ) )
goto Fail;
max_offsets = new_max;
}
/* read the subrmap's offsets */
- if ( FILE_Seek( cid->data_offset + dict->subrmap_offset ) ||
- ACCESS_Frame( ( num_subrs + 1 ) * dict->sd_bytes ) )
+ if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) ||
+ FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) )
goto Fail;
p = (FT_Byte*)stream->cursor;
for ( count = 0; count <= num_subrs; count++ )
offsets[count] = cid_get_offset( &p, (FT_Byte)dict->sd_bytes );
- FORGET_Frame();
+ FT_FRAME_EXIT();
/* now, compute the size of subrs charstrings, */
/* allocate, and read them */
data_len = offsets[num_subrs] - offsets[0];
- if ( ALLOC_ARRAY( subr->code, num_subrs + 1, FT_Byte* ) ||
- ALLOC( subr->code[0], data_len ) )
+ if ( FT_NEW_ARRAY( subr->code, num_subrs + 1 ) ||
+ FT_ALLOC( subr->code[0], data_len ) )
goto Fail;
- if ( FILE_Seek( cid->data_offset + offsets[0] ) ||
- FILE_Read( subr->code[0], data_len ) )
+ if ( FT_STREAM_SEEK( cid->data_offset + offsets[0] ) ||
+ FT_STREAM_READ( subr->code[0], data_len ) )
goto Fail;
/* set up pointers */
for ( count = 1; count <= num_subrs; count++ )
{
- FT_UInt len;
+ FT_ULong len;
len = offsets[count] - offsets[count - 1];
@@ -463,11 +435,11 @@
{
for ( count = 0; count < num_subrs; count++ )
{
- FT_UInt len;
+ FT_ULong len;
len = offsets[count + 1] - offsets[count];
- cid_decrypt( subr->code[count], len, 4330 );
+ psaux->t1_decrypt( subr->code[count], len, 4330 );
}
}
@@ -475,7 +447,7 @@
}
Exit:
- FREE( offsets );
+ FT_FREE( offsets );
return error;
Fail:
@@ -484,11 +456,11 @@
for ( n = 0; n < cid->num_dicts; n++ )
{
if ( face->subrs[n].code )
- FREE( face->subrs[n].code[0] );
+ FT_FREE( face->subrs[n].code[0] );
- FREE( face->subrs[n].code );
+ FT_FREE( face->subrs[n].code );
}
- FREE( face->subrs );
+ FT_FREE( face->subrs );
}
goto Exit;
}
@@ -500,7 +472,7 @@
{
FT_UNUSED( face );
- MEM_Set( loader, 0, sizeof ( *loader ) );
+ FT_MEM_ZERO( loader, sizeof ( *loader ) );
}
@@ -511,23 +483,123 @@
/* finalize parser */
- CID_Done_Parser( parser );
+ cid_parser_done( parser );
}
- FT_LOCAL_DEF FT_Error
- CID_Open_Face( CID_Face face )
+ static FT_Error
+ cid_hex_to_binary( FT_Byte* data,
+ FT_Long data_len,
+ FT_ULong offset,
+ CID_Face face )
{
- CID_Loader loader;
- CID_Parser* parser;
+ FT_Stream stream = face->root.stream;
FT_Error error;
+ FT_Byte buffer[256];
+ FT_Byte *p, *plimit;
+ FT_Byte *d, *dlimit;
+ FT_Byte val;
+
+ FT_Bool upper_nibble, done;
+
+
+ if ( FT_STREAM_SEEK( offset ) )
+ goto Exit;
+
+ d = data;
+ dlimit = d + data_len;
+ p = buffer;
+ plimit = p;
+
+ upper_nibble = 1;
+ done = 0;
+
+ while ( d < dlimit )
+ {
+ if ( p >= plimit )
+ {
+ FT_ULong oldpos = FT_STREAM_POS();
+ FT_ULong size = stream->size - oldpos;
+
+
+ if ( size == 0 )
+ {
+ error = CID_Err_Syntax_Error;
+ goto Exit;
+ }
+
+ if ( FT_STREAM_READ( buffer, 256 > size ? size : 256 ) )
+ goto Exit;
+ p = buffer;
+ plimit = p + FT_STREAM_POS() - oldpos;
+ }
+
+ if ( ft_isdigit( *p ) )
+ val = (FT_Byte)( *p - '0' );
+ else if ( *p >= 'a' && *p <= 'f' )
+ val = (FT_Byte)( *p - 'a' );
+ else if ( *p >= 'A' && *p <= 'F' )
+ val = (FT_Byte)( *p - 'A' + 10 );
+ else if ( *p == ' ' ||
+ *p == '\t' ||
+ *p == '\r' ||
+ *p == '\n' ||
+ *p == '\f' ||
+ *p == '\0' )
+ {
+ p++;
+ continue;
+ }
+ else if ( *p == '>' )
+ {
+ val = 0;
+ done = 1;
+ }
+ else
+ {
+ error = CID_Err_Syntax_Error;
+ goto Exit;
+ }
+
+ if ( upper_nibble )
+ *d = (FT_Byte)( val << 4 );
+ else
+ {
+ *d = (FT_Byte)( *d + val );
+ d++;
+ }
+
+ upper_nibble = (FT_Byte)( 1 - upper_nibble );
+
+ if ( done )
+ break;
+
+ p++;
+ }
+
+ error = CID_Err_Ok;
+
+ Exit:
+ return error;
+ }
+
+
+ FT_LOCAL_DEF( FT_Error )
+ cid_face_open( CID_Face face,
+ FT_Int face_index )
+ {
+ CID_Loader loader;
+ CID_Parser* parser;
+ FT_Memory memory = face->root.memory;
+ FT_Error error;
+
t1_init_loader( &loader, face );
parser = &loader.parser;
- error = CID_New_Parser( parser, face->root.stream, face->root.memory,
- (PSAux_Interface*)face->psaux );
+ error = cid_parser_new( parser, face->root.stream, face->root.memory,
+ (PSAux_Service)face->psaux );
if ( error )
goto Exit;
@@ -537,7 +609,30 @@
if ( error )
goto Exit;
- face->cid.data_offset = loader.parser.data_offset;
+ if ( face_index < 0 )
+ goto Exit;
+
+ if ( FT_NEW( face->cid_stream ) )
+ goto Exit;
+
+ if ( parser->binary_length )
+ {
+ /* we must convert the data section from hexadecimal to binary */
+ if ( FT_ALLOC( face->binary_data, parser->binary_length ) ||
+ cid_hex_to_binary( face->binary_data, parser->binary_length,
+ parser->data_offset, face ) )
+ goto Exit;
+
+ FT_Stream_OpenMemory( face->cid_stream,
+ face->binary_data, parser->binary_length );
+ face->cid.data_offset = 0;
+ }
+ else
+ {
+ *face->cid_stream = *face->root.stream;
+ face->cid.data_offset = loader.parser.data_offset;
+ }
+
error = cid_read_subrs( face );
Exit: