📄 cffload.c
字号:
0, 0, 145, 0, 0, 146, 147, 148, 149, 0, 0, 0, 0 }; static const FT_UShort cff_expert_encoding[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 229, 230, 0, 231, 232, 233, 234, 235, 236, 237, 238, 13, 14, 15, 99, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 27, 28, 249, 250, 251, 252, 0, 253, 254, 255, 256, 257, 0, 0, 0, 258, 0, 0, 259, 260, 261, 262, 0, 0, 263, 264, 265, 0, 266, 109, 110, 267, 268, 269, 0, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 304, 305, 306, 0, 0, 307, 308, 309, 310, 311, 0, 312, 0, 0, 312, 0, 0, 314, 315, 0, 0, 316, 317, 318, 0, 0, 0, 158, 155, 163, 319, 320, 321, 322, 323, 324, 325, 0, 0, 326, 150, 164, 169, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378 };#endif FT_LOCAL_DEF( FT_UShort ) cff_get_standard_encoding( FT_UInt charcode ) { return (FT_UShort)(charcode < 256 ? cff_standard_encoding[charcode] : 0); } /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ /* messages during execution. */ /* */#undef FT_COMPONENT#define FT_COMPONENT trace_cffload /* read a CFF offset from memory */ static FT_ULong cff_get_offset( FT_Byte* p, FT_Byte off_size ) { FT_ULong result; for ( result = 0; off_size > 0; off_size-- ) { result <<= 8; result |= *p++; } return result; } static FT_Error cff_new_index( CFF_Index idx, FT_Stream stream, FT_Bool load ) { FT_Error error; FT_Memory memory = stream->memory; FT_UShort count; FT_MEM_ZERO( idx, sizeof ( *idx ) ); idx->stream = stream; if ( !FT_READ_USHORT( count ) && count > 0 ) { FT_Byte* p; FT_Byte offsize; FT_ULong data_size; FT_ULong* poff; /* there is at least one element; read the offset size, */ /* then access the offset table to compute the index's total size */ if ( FT_READ_BYTE( offsize ) ) goto Exit; idx->stream = stream; idx->count = count; idx->off_size = offsize; data_size = (FT_ULong)( count + 1 ) * offsize; if ( FT_NEW_ARRAY( idx->offsets, count + 1 ) || FT_FRAME_ENTER( data_size ) ) goto Exit; poff = idx->offsets; p = (FT_Byte*)stream->cursor; for ( ; (FT_Short)count >= 0; count-- ) { poff[0] = cff_get_offset( p, offsize ); poff++; p += offsize; } FT_FRAME_EXIT(); idx->data_offset = FT_STREAM_POS(); data_size = poff[-1] - 1; if ( load ) { /* load the data */ if ( FT_FRAME_EXTRACT( data_size, idx->bytes ) ) goto Exit; } else { /* skip the data */ if ( FT_STREAM_SKIP( data_size ) ) goto Exit; } } Exit: if ( error ) FT_FREE( idx->offsets ); return error; } static void cff_done_index( CFF_Index idx ) { if ( idx->stream ) { FT_Stream stream = idx->stream; FT_Memory memory = stream->memory; if ( idx->bytes ) FT_FRAME_RELEASE( idx->bytes ); FT_FREE( idx->offsets ); FT_MEM_ZERO( idx, sizeof ( *idx ) ); } } /* allocate a table containing pointers to an index's elements */ static FT_Error cff_index_get_pointers( CFF_Index idx, FT_Byte*** table ) { FT_Error error = CFF_Err_Ok; FT_Memory memory = idx->stream->memory; FT_ULong n, offset, old_offset; FT_Byte** t; *table = 0; if ( idx->count > 0 && !FT_NEW_ARRAY( t, idx->count + 1 ) ) { old_offset = 1; for ( n = 0; n <= idx->count; n++ ) { offset = idx->offsets[n]; if ( !offset ) offset = old_offset; t[n] = idx->bytes + offset - 1; old_offset = offset; } *table = t; } return error; } FT_LOCAL_DEF( FT_Error ) cff_index_access_element( CFF_Index idx, FT_UInt element, FT_Byte** pbytes, FT_ULong* pbyte_len ) { FT_Error error = CFF_Err_Ok; if ( idx && idx->count > element ) { /* compute start and end offsets */ FT_ULong off1, off2 = 0; off1 = idx->offsets[element]; if ( off1 ) { do { element++; off2 = idx->offsets[element]; } while ( off2 == 0 && element < idx->count ); if ( !off2 ) off1 = 0; } /* access element */ if ( off1 ) { *pbyte_len = off2 - off1; if ( idx->bytes ) { /* this index was completely loaded in memory, that's easy */ *pbytes = idx->bytes + off1 - 1; } else { /* this index is still on disk/file, access it through a frame */ FT_Stream stream = idx->stream; if ( FT_STREAM_SEEK( idx->data_offset + off1 - 1 ) || FT_FRAME_EXTRACT( off2 - off1, *pbytes ) ) goto Exit; } } else { /* empty index element */ *pbytes = 0; *pbyte_len = 0; } } else error = CFF_Err_Invalid_Argument; Exit: return error; } FT_LOCAL_DEF( void ) cff_index_forget_element( CFF_Index idx, FT_Byte** pbytes ) { if ( idx->bytes == 0 ) { FT_Stream stream = idx->stream; FT_FRAME_RELEASE( *pbytes ); } } FT_LOCAL_DEF( FT_String* ) cff_index_get_name( CFF_Index idx, FT_UInt element ) { FT_Memory memory = idx->stream->memory; FT_Byte* bytes; FT_ULong byte_len; FT_Error error; FT_String* name = 0; error = cff_index_access_element( idx, element, &bytes, &byte_len ); if ( error ) goto Exit; if ( !FT_ALLOC( name, byte_len + 1 ) ) { FT_MEM_COPY( name, bytes, byte_len ); name[byte_len] = 0; } cff_index_forget_element( idx, &bytes ); Exit: return name; } FT_LOCAL_DEF( FT_String* ) cff_index_get_sid_string( CFF_Index idx, FT_UInt sid, FT_Service_PsCMaps psnames ) { /* value 0xFFFFU indicates a missing dictionary entry */ if ( sid == 0xFFFFU ) return 0; /* if it is not a standard string, return it */ if ( sid > 390 ) return cff_index_get_name( idx, sid - 391 ); /* CID-keyed CFF fonts don't have glyph names */ if ( !psnames ) return 0; /* that's a standard string, fetch a copy from the PSName module */ { FT_String* name = 0; const char* adobe_name = psnames->adobe_std_strings( sid ); FT_UInt len; if ( adobe_name ) { FT_Memory memory = idx->stream->memory; FT_Error error; len = (FT_UInt)ft_strlen( adobe_name ); if ( !FT_ALLOC( name, len + 1 ) ) { FT_MEM_COPY( name, adobe_name, len ); name[len] = 0; } FT_UNUSED( error ); } return name; } } /*************************************************************************/ /*************************************************************************/ /*** ***/ /*** FD Select table support ***/ /*** ***/ /*************************************************************************/ /*************************************************************************/ static void CFF_Done_FD_Select( CFF_FDSelect fdselect, FT_Stream stream ) { if ( fdselect->data ) FT_FRAME_RELEASE( fdselect->data ); fdselect->data_size = 0; fdselect->format = 0; fdselect->range_count = 0; } static FT_Error CFF_Load_FD_Select( CFF_FDSelect fdselect, FT_UInt num_glyphs, FT_Stream stream, FT_ULong offset ) { FT_Error error; FT_Byte format; FT_UInt num_ranges; /* read format */ if ( FT_STREAM_SEEK( offset ) || FT_READ_BYTE( format ) ) goto Exit; fdselect->format = format; fdselect->cache_count = 0; /* clear cache */ switch ( format ) { case 0: /* format 0, that's simple */ fdselect->data_size = num_glyphs; goto Load_Data; case 3: /* format 3, a tad more complex */ if ( FT_READ_USHORT( num_ranges ) ) goto Exit; fdselect->data_size = num_ranges * 3 + 2; Load_Data: if ( FT_FRAME_EXTRACT( fdselect->data_size, fdselect->data ) ) goto Exit; break; default: /* hmm... that's wrong */ error = CFF_Err_Invalid_File_Format; } Exit: return error; } FT_LOCAL_DEF( FT_Byte ) cff_fd_select_get( CFF_FDSelect fdselect, FT_UInt glyph_index ) { FT_Byte fd = 0; switch ( fdselect->format ) { case 0: fd = fdselect->data[glyph_index]; break; case 3: /* first, compare to cache */ if ( (FT_UInt)( glyph_index - fdselect->cache_first ) < fdselect->cache_count ) { fd = fdselect->cache_fd; break; } /* then, lookup the ranges array */ { FT_Byte* p = fdselect->data; FT_Byte* p_limit = p + fdselect->data_size; FT_Byte fd2; FT_UInt first, limit; first = FT_NEXT_USHORT( p ); do { if ( glyph_index < first ) break; fd2 = *p++; limit = FT_NEXT_USHORT( p ); if ( glyph_index < limit ) { fd = fd2; /* update cache */ fdselect->cache_first = first; fdselect->cache_count = limit-first; fdselect->cache_fd = fd2; break; } first = limit; } while ( p < p_limit ); } break; default: ; } return fd; } /*************************************************************************/ /*************************************************************************/ /*** ***/ /*** CFF font support ***/ /*** ***/ /*************************************************************************/ /*************************************************************************/ static void cff_charset_done( CFF_Charset charset, FT_Stream stream ) { FT_Memory memory = stream->memory; FT_FREE( charset->sids ); FT_FREE( charset->cids ); charset->format = 0; charset->offset = 0; } static FT_Error cff_charset_load( CFF_Charset charset, FT_UInt num_glyphs, FT_Stream stream, FT_ULong base_offset, FT_ULong offset, FT_Bool invert ) { FT_Memory memory = stream->memory; FT_Error error = CFF_Err_Ok; FT_UShort glyph_sid; /* If the the offset is greater than 2, we have to parse the */ /* charset table. */ if ( offset > 2 ) { 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; /* assign the .notdef glyph */ charset->sids[0] = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -