|
|
|
@ -4,7 +4,7 @@ |
|
|
|
|
/* */ |
|
|
|
|
/* CID-keyed Type1 font loader (body). */ |
|
|
|
|
/* */ |
|
|
|
|
/* Copyright 1996-2001, 2002, 2003 by */ |
|
|
|
|
/* Copyright 1996-2001, 2002, 2003, 2004 by */ |
|
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
|
|
|
|
/* */ |
|
|
|
|
/* This file is part of the FreeType project, and may only be used, */ |
|
|
|
@ -363,7 +363,7 @@ |
|
|
|
|
{ |
|
|
|
|
CID_FaceInfo cid = &face->cid; |
|
|
|
|
FT_Memory memory = face->root.memory; |
|
|
|
|
FT_Stream stream = face->root.stream; |
|
|
|
|
FT_Stream stream = face->cid_stream; |
|
|
|
|
FT_Error error; |
|
|
|
|
FT_Int n; |
|
|
|
|
CID_Subrs subr; |
|
|
|
@ -399,7 +399,7 @@ |
|
|
|
|
|
|
|
|
|
/* read the subrmap's offsets */ |
|
|
|
|
if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) || |
|
|
|
|
FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) ) |
|
|
|
|
FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) ) |
|
|
|
|
goto Fail; |
|
|
|
|
|
|
|
|
|
p = (FT_Byte*)stream->cursor; |
|
|
|
@ -487,11 +487,111 @@ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static FT_Error |
|
|
|
|
cid_hex_to_binary( FT_Byte* data, |
|
|
|
|
FT_Long data_len, |
|
|
|
|
FT_ULong offset, |
|
|
|
|
CID_Face face ) |
|
|
|
|
{ |
|
|
|
|
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 = *p - '0'; |
|
|
|
|
else if ( *p >= 'a' && *p <= 'f' ) |
|
|
|
|
val = *p - 'a'; |
|
|
|
|
else if ( *p >= 'A' && *p <= 'F' ) |
|
|
|
|
val = *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 = val << 4; |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
*d += val; |
|
|
|
|
d++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
upper_nibble = 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 ) |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -509,7 +609,30 @@ |
|
|
|
|
if ( error ) |
|
|
|
|
goto Exit; |
|
|
|
|
|
|
|
|
|
face->cid.data_offset = loader.parser.data_offset; |
|
|
|
|
if ( face_index < 0 ) |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
if ( FT_NEW( face->cid_stream ) ) |
|
|
|
|
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: |
|
|
|
|