20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_OBJECTS_H
22 #include FT_INTERNAL_STREAM_H
23 #include FT_TRUETYPE_TAGS_H
24 #include FT_TYPE1_TABLES_H
36 0, 1, 2, 3, 4, 5, 6, 7,
37 8, 9, 10, 11, 12, 13, 14, 15,
38 16, 17, 18, 19, 20, 21, 22, 23,
39 24, 25, 26, 27, 28, 29, 30, 31,
40 32, 33, 34, 35, 36, 37, 38, 39,
41 40, 41, 42, 43, 44, 45, 46, 47,
42 48, 49, 50, 51, 52, 53, 54, 55,
43 56, 57, 58, 59, 60, 61, 62, 63,
44 64, 65, 66, 67, 68, 69, 70, 71,
45 72, 73, 74, 75, 76, 77, 78, 79,
46 80, 81, 82, 83, 84, 85, 86, 87,
47 88, 89, 90, 91, 92, 93, 94, 95,
48 96, 97, 98, 99, 100, 101, 102, 103,
49 104, 105, 106, 107, 108, 109, 110, 111,
50 112, 113, 114, 115, 116, 117, 118, 119,
51 120, 121, 122, 123, 124, 125, 126, 127,
52 128, 129, 130, 131, 132, 133, 134, 135,
53 136, 137, 138, 139, 140, 141, 142, 143,
54 144, 145, 146, 147, 148, 149, 150, 151,
55 152, 153, 154, 155, 156, 157, 158, 159,
56 160, 161, 162, 163, 164, 165, 166, 167,
57 168, 169, 170, 171, 172, 173, 174, 175,
58 176, 177, 178, 179, 180, 181, 182, 183,
59 184, 185, 186, 187, 188, 189, 190, 191,
60 192, 193, 194, 195, 196, 197, 198, 199,
61 200, 201, 202, 203, 204, 205, 206, 207,
62 208, 209, 210, 211, 212, 213, 214, 215,
63 216, 217, 218, 219, 220, 221, 222, 223,
64 224, 225, 226, 227, 228
69 0, 1, 229, 230, 231, 232, 233, 234,
70 235, 236, 237, 238, 13, 14, 15, 99,
71 239, 240, 241, 242, 243, 244, 245, 246,
72 247, 248, 27, 28, 249, 250, 251, 252,
73 253, 254, 255, 256, 257, 258, 259, 260,
74 261, 262, 263, 264, 265, 266, 109, 110,
75 267, 268, 269, 270, 271, 272, 273, 274,
76 275, 276, 277, 278, 279, 280, 281, 282,
77 283, 284, 285, 286, 287, 288, 289, 290,
78 291, 292, 293, 294, 295, 296, 297, 298,
79 299, 300, 301, 302, 303, 304, 305, 306,
80 307, 308, 309, 310, 311, 312, 313, 314,
81 315, 316, 317, 318, 158, 155, 163, 319,
82 320, 321, 322, 323, 324, 325, 326, 150,
83 164, 169, 327, 328, 329, 330, 331, 332,
84 333, 334, 335, 336, 337, 338, 339, 340,
85 341, 342, 343, 344, 345, 346, 347, 348,
86 349, 350, 351, 352, 353, 354, 355, 356,
87 357, 358, 359, 360, 361, 362, 363, 364,
88 365, 366, 367, 368, 369, 370, 371, 372,
89 373, 374, 375, 376, 377, 378
94 0, 1, 231, 232, 235, 236, 237, 238,
95 13, 14, 15, 99, 239, 240, 241, 242,
96 243, 244, 245, 246, 247, 248, 27, 28,
97 249, 250, 251, 253, 254, 255, 256, 257,
98 258, 259, 260, 261, 262, 263, 264, 265,
99 266, 109, 110, 267, 268, 269, 270, 272,
100 300, 301, 302, 305, 314, 315, 158, 155,
101 163, 320, 321, 322, 323, 324, 325, 326,
102 150, 164, 169, 327, 328, 329, 330, 331,
103 332, 333, 334, 335, 336, 337, 338, 339,
104 340, 341, 342, 343, 344, 345, 346
109 0, 0, 0, 0, 0, 0, 0, 0,
110 0, 0, 0, 0, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0,
113 1, 2, 3, 4, 5, 6, 7, 8,
114 9, 10, 11, 12, 13, 14, 15, 16,
115 17, 18, 19, 20, 21, 22, 23, 24,
116 25, 26, 27, 28, 29, 30, 31, 32,
117 33, 34, 35, 36, 37, 38, 39, 40,
118 41, 42, 43, 44, 45, 46, 47, 48,
119 49, 50, 51, 52, 53, 54, 55, 56,
120 57, 58, 59, 60, 61, 62, 63, 64,
121 65, 66, 67, 68, 69, 70, 71, 72,
122 73, 74, 75, 76, 77, 78, 79, 80,
123 81, 82, 83, 84, 85, 86, 87, 88,
124 89, 90, 91, 92, 93, 94, 95, 0,
125 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 0,
129 0, 96, 97, 98, 99, 100, 101, 102,
130 103, 104, 105, 106, 107, 108, 109, 110,
131 0, 111, 112, 113, 114, 0, 115, 116,
132 117, 118, 119, 120, 121, 122, 0, 123,
133 0, 124, 125, 126, 127, 128, 129, 130,
134 131, 0, 132, 133, 0, 134, 135, 136,
135 137, 0, 0, 0, 0, 0, 0, 0,
136 0, 0, 0, 0, 0, 0, 0, 0,
137 0, 138, 0, 139, 0, 0, 0, 0,
138 140, 141, 142, 143, 0, 0, 0, 0,
139 0, 144, 0, 0, 0, 145, 0, 0,
140 146, 147, 148, 149, 0, 0, 0, 0
145 0, 0, 0, 0, 0, 0, 0, 0,
146 0, 0, 0, 0, 0, 0, 0, 0,
147 0, 0, 0, 0, 0, 0, 0, 0,
148 0, 0, 0, 0, 0, 0, 0, 0,
149 1, 229, 230, 0, 231, 232, 233, 234,
150 235, 236, 237, 238, 13, 14, 15, 99,
151 239, 240, 241, 242, 243, 244, 245, 246,
152 247, 248, 27, 28, 249, 250, 251, 252,
153 0, 253, 254, 255, 256, 257, 0, 0,
154 0, 258, 0, 0, 259, 260, 261, 262,
155 0, 0, 263, 264, 265, 0, 266, 109,
156 110, 267, 268, 269, 0, 270, 271, 272,
157 273, 274, 275, 276, 277, 278, 279, 280,
158 281, 282, 283, 284, 285, 286, 287, 288,
159 289, 290, 291, 292, 293, 294, 295, 296,
160 297, 298, 299, 300, 301, 302, 303, 0,
161 0, 0, 0, 0, 0, 0, 0, 0,
162 0, 0, 0, 0, 0, 0, 0, 0,
163 0, 0, 0, 0, 0, 0, 0, 0,
164 0, 0, 0, 0, 0, 0, 0, 0,
165 0, 304, 305, 306, 0, 0, 307, 308,
166 309, 310, 311, 0, 312, 0, 0, 312,
167 0, 0, 314, 315, 0, 0, 316, 317,
168 318, 0, 0, 0, 158, 155, 163, 319,
169 320, 321, 322, 323, 324, 325, 0, 0,
170 326, 150, 164, 169, 327, 328, 329, 330,
171 331, 332, 333, 334, 335, 336, 337, 338,
172 339, 340, 341, 342, 343, 344, 345, 346,
173 347, 348, 349, 350, 351, 352, 353, 354,
174 355, 356, 357, 358, 359, 360, 361, 362,
175 363, 364, 365, 366, 367, 368, 369, 370,
176 371, 372, 373, 374, 375, 376, 377, 378
197 #define FT_COMPONENT trace_cffload
216 for ( nn = 0; nn < idx->off_size; nn++ )
217 result = ( result << 8 ) | tmp[nn];
251 if ( offsize < 1 || offsize > 4 )
253 error = CFF_Err_Invalid_Table;
258 idx->off_size = offsize;
259 size = (
FT_ULong)( count + 1 ) * offsize;
261 idx->data_offset = idx->start + 3 +
size;
272 error = CFF_Err_Invalid_Table;
276 idx->data_size = --
size;
326 if ( idx->count > 0 && idx->offsets ==
NULL )
328 FT_Byte offsize = idx->off_size;
335 data_size = (
FT_ULong)( idx->count + 1 ) * offsize;
344 p_end = p + data_size;
349 for ( ; p < p_end; p++, poff++ )
354 for ( ; p < p_end; p += 2, poff++ )
359 for ( ; p < p_end; p += 3, poff++ )
364 for ( ; p < p_end; p += 4, poff++ )
395 if ( idx->offsets ==
NULL )
402 if ( idx->count > 0 &&
405 idx->data_size + idx->count ) ) )
409 FT_Byte* org_bytes = idx->bytes;
413 cur_offset = idx->offsets[0] - 1;
416 if ( cur_offset >= idx->data_size )
419 " invalid first offset value %d set to zero\n",
425 t[0] = org_bytes + cur_offset;
427 t[0] = new_bytes + cur_offset;
429 for ( n = 1; n <= idx->count; n++ )
431 FT_ULong next_offset = idx->offsets[
n] - 1;
435 if ( next_offset == 0 ||
436 next_offset < cur_offset ||
438 next_offset = cur_offset;
441 t[
n] = org_bytes + next_offset;
444 t[
n] = new_bytes + next_offset + extra;
446 if ( next_offset != cur_offset )
448 FT_MEM_COPY( t[n - 1], org_bytes + cur_offset, t[n] - t[n - 1] );
455 cur_offset = next_offset;
477 if ( idx && idx->count > element )
487 FT_ULong pos = element * idx->off_size;
504 while ( off2 == 0 && element < idx->
count );
509 off1 = idx->offsets[element];
515 off2 = idx->offsets[element];
517 }
while ( off2 == 0 && element < idx->
count );
523 if ( off2 > stream->
size + 1 ||
524 idx->data_offset > stream->
size - off2 + 1 )
526 FT_ERROR((
"cff_index_access_element:"
527 " offset to next entry (%d)"
528 " exceeds the end of stream (%d)\n",
529 off2, stream->
size - idx->data_offset + 1 ));
530 off2 = stream->
size - idx->data_offset + 1;
534 if ( off1 && off2 > off1 )
536 *pbyte_len = off2 - off1;
541 *pbytes = idx->bytes + off1 - 1;
559 error = CFF_Err_Invalid_Argument;
570 if ( idx->bytes == 0 )
597 if ( !
FT_ALLOC( name, byte_len + 1 ) )
614 return ( element < font->num_strings )
625 if ( sid == 0xFFFFU )
633 if ( !font->psnames )
637 return (
FT_String *)font->psnames->adobe_std_strings( sid );
654 if ( fdselect->
data )
691 fdselect->
data_size = num_ranges * 3 + 2;
699 error = CFF_Err_Invalid_File_Format;
714 switch ( fdselect->format )
717 fd = fdselect->data[glyph_index];
722 if ( (
FT_UInt)( glyph_index - fdselect->cache_first ) <
723 fdselect->cache_count )
725 fd = fdselect->cache_fd;
732 FT_Byte* p_limit = p + fdselect->data_size;
740 if ( glyph_index < first )
746 if ( glyph_index < limit )
751 fdselect->cache_first =
first;
752 fdselect->cache_count = limit-
first;
753 fdselect->cache_fd = fd2;
758 }
while ( p < p_limit );
792 for ( i = 0; i < num_glyphs; i++ )
794 if ( charset->
sids[i] > max_cid )
795 max_cid = charset->
sids[
i];
804 for ( j = num_glyphs - 1; j >= 0 ; j-- )
822 if ( cid <= charset->max_cid )
823 result = charset->cids[cid];
885 charset->
sids[0] = 0;
887 switch ( charset->
format )
890 if ( num_glyphs > 0 )
895 for ( j = 1; j < num_glyphs; j++ )
911 while ( j < num_glyphs )
918 if ( charset->
format == 2 )
930 if ( glyph_sid > 0xFFFFL - nleft )
932 FT_ERROR((
"cff_charset_load: invalid SID range trimmed"
933 " nleft=%d -> %d\n", nleft, 0xFFFFL - glyph_sid ));
934 nleft = (
FT_UInt )( 0xFFFFL - glyph_sid );
938 for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ )
939 charset->
sids[j] = glyph_sid;
945 FT_ERROR((
"cff_charset_load: invalid table format\n" ));
946 error = CFF_Err_Invalid_File_Format;
965 if ( num_glyphs > 229 )
967 FT_ERROR((
"cff_charset_load: implicit charset larger than\n"
968 "predefined charset (Adobe ISO-Latin)\n" ));
969 error = CFF_Err_Invalid_File_Format;
983 if ( num_glyphs > 166 )
985 FT_ERROR((
"cff_charset_load: implicit charset larger than\n"
986 "predefined charset (Adobe Expert)\n" ));
987 error = CFF_Err_Invalid_File_Format;
1001 if ( num_glyphs > 87 )
1003 FT_ERROR((
"cff_charset_load: implicit charset larger than\n"
1004 "predefined charset (Adobe Expert Subset)\n" ));
1005 error = CFF_Err_Invalid_File_Format;
1019 error = CFF_Err_Invalid_File_Format;
1048 encoding->
count = 0;
1068 if ( !charset->
sids )
1070 error = CFF_Err_Invalid_File_Format;
1075 for ( j = 0; j < 256; j++ )
1077 encoding->
sids [
j] = 0;
1103 switch ( encoding->
format & 0x7F )
1114 encoding->
count = count + 1;
1126 if ( j < num_glyphs )
1132 encoding->
sids[glyph_code] = charset->
sids[
j];
1147 encoding->
count = 0;
1150 for ( j = 0; j <
count; j++, i += nleft )
1165 encoding->
count = nleft;
1168 for ( k = i; k < nleft +
i; k++, glyph_code++ )
1171 if ( k < num_glyphs && glyph_code < 256 )
1177 encoding->
sids[glyph_code] = charset->
sids[
k];
1183 if ( encoding->
count > 256 )
1184 encoding->
count = 256;
1189 FT_ERROR((
"cff_encoding_load: invalid table format\n" ));
1190 error = CFF_Err_Invalid_File_Format;
1195 if ( encoding->
format & 0x80 )
1204 for ( j = 0; j <
count; j++ )
1215 encoding->
sids[glyph_code] = glyph_sid;
1219 for ( gindex = 0; gindex < num_glyphs; gindex++ )
1221 if ( charset->
sids[gindex] == glyph_sid )
1252 encoding->
count = 0;
1259 for ( j = 0; j < 256; j++ )
1271 encoding->
count = j + 1;
1276 encoding->
sids [
j] = 0;
1282 FT_ERROR((
"cff_encoding_load: invalid table format\n" ));
1283 error = CFF_Err_Invalid_File_Format;
1371 FT_TRACE4((
" private dictionary:\n" ));
1427 #define FT_STRUCTURE CFF_FontRec
1448 font->memory = memory;
1449 dict = &font->top_font.font_dict;
1457 if ( font->version_major != 1 ||
1458 font->header_size < 4 ||
1459 font->absolute_offsize > 4 )
1461 FT_TRACE2((
" not a CFF font header\n" ));
1462 error = CFF_Err_Unknown_File_Format;
1481 &font->string_pool ) ) )
1484 font->num_strings = string_index.count;
1487 font->num_faces = font->name_index.count;
1488 if ( face_index >= (
FT_Int)font->num_faces )
1490 FT_ERROR((
"cff_font_load: incorrect face index = %d\n",
1492 error = CFF_Err_Invalid_Argument;
1496 if ( face_index < 0 )
1502 &font->font_dict_index,
1536 FT_TRACE0((
"cff_font_load: FD array too large in CID font\n" ));
1541 font->num_subfonts = fd_index.count;
1546 for ( idx = 0; idx < fd_index.count; idx++ )
1547 font->subfonts[idx] = sub + idx;
1550 for ( idx = 0; idx < fd_index.count; idx++ )
1552 sub = font->subfonts[
idx];
1553 FT_TRACE4((
"parsing subfont %u\n", idx ));
1555 stream, base_offset, library );
1562 font->charstrings_index.count,
1573 font->num_subfonts = 0;
1578 FT_ERROR((
"cff_font_load: no charstrings offset\n" ));
1579 error = CFF_Err_Invalid_File_Format;
1583 font->num_glyphs = font->charstrings_index.count;
1586 &font->global_subrs,
NULL );
1592 if ( font->num_glyphs > 0 )
1641 if ( font->num_subfonts > 0 )
1643 for ( idx = 0; idx < font->num_subfonts; idx++ )
1660 FT_FREE( font->global_subrs );
#define FT_ALLOC(ptr, size)
GLenum GLsizei GLenum GLenum const GLvoid * table
cff_font_done(CFF_Font font)
cff_get_standard_encoding(FT_UInt charcode)
cff_index_get_name(CFF_Font font, FT_UInt element)
static FT_Error cff_index_load_offsets(CFF_Index idx)
static void cff_subfont_done(FT_Memory memory, CFF_SubFont subfont)
FT_ULong cid_fd_select_offset
CFF_IndexRec local_subrs_index
static FT_Error cff_charset_compute_cids(CFF_Charset charset, FT_UInt num_glyphs, FT_Memory memory)
#define FT_MEM_ZERO(dest, count)
#define FT_ARRAY_COPY(dest, source, count)
static FT_ULong cff_index_read_offset(CFF_Index idx, FT_Error *errorp)
FT_Fixed underline_position
cff_parser_init(CFF_Parser parser, FT_UInt code, void *object, FT_Library library)
cff_index_get_string(CFF_Font font, FT_UInt element)
FT_UInt embedded_postscript
#define FT_READ_BYTE(var)
static const FT_UShort cff_standard_encoding[256]
FT_Fixed underline_thickness
EGLImageKHR EGLint * name
#define FT_READ_USHORT(var)
static const FT_UShort cff_expert_charset[166]
FT_Fixed expansion_factor
FT_ULong local_subrs_offset
return cff_index_get_sid_string(cff, sid)
static void cff_charset_done(CFF_Charset charset, FT_Stream stream)
FT_BEGIN_HEADER typedef unsigned char FT_Bool
static FT_Error CFF_Load_FD_Select(CFF_FDSelect fdselect, FT_UInt num_glyphs, FT_Stream stream, FT_ULong offset)
static const FT_UShort cff_expertsubset_charset[87]
#define FT_ERROR(varformat)
static void cff_encoding_done(CFF_Encoding encoding)
cff_fd_select_get(CFF_FDSelect fdselect, FT_UInt glyph_index)
cff_index_access_element(CFF_Index idx, FT_UInt element, FT_Byte **pbytes, FT_ULong *pbyte_len)
#define FT_TRACE4(varformat)
FT_BEGIN_HEADER struct CFF_IndexRec_ CFF_IndexRec
#define FT_STREAM_READ_FIELDS(fields, object)
CFF_FontRecDictRec font_dict
static FT_Error cff_index_init(CFF_Index idx, FT_Stream stream, FT_Bool load)
static void cff_index_done(CFF_Index idx)
#define FT_STREAM_SKIP(distance)
FT_ULong charstrings_offset
static const FT_UShort cff_expert_encoding[256]
FT_ULong cid_fd_array_offset
static void CFF_Done_FD_Select(CFF_FDSelect fdselect, FT_Stream stream)
#define FT_TRACE0(varformat)
cff_parser_run(CFF_Parser parser, FT_Byte *start, FT_Byte *limit)
static FT_Error cff_encoding_load(CFF_Encoding encoding, CFF_Charset charset, FT_UInt num_glyphs, FT_Stream stream, FT_ULong base_offset, FT_ULong offset)
#define FT_TRACE2(varformat)
CFF_PrivateRec private_dict
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
#define CFF_MAX_CID_FONTS
GLfloat GLfloat GLfloat top
#define FT_PEEK_USHORT(p)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
#define FT_NEW_ARRAY(ptr, count)
static FT_Error cff_index_get_pointers(CFF_Index idx, FT_Byte ***table, FT_Byte **pool)
#define FT_STREAM_SEEK(position)
static FT_Error cff_subfont_load(CFF_SubFont font, CFF_Index idx, FT_UInt font_index, FT_Stream stream, FT_ULong base_offset, FT_Library library)
#define FT_NEXT_USHORT(buffer)
#define FT_FRAME_RELEASE(bytes)
#define FT_SET_ERROR(expression)
static const FT_UShort cff_isoadobe_charset[229]
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)
#define FT_FRAME_EXTRACT(size, bytes)
cff_charset_cid_to_gindex(CFF_Charset charset, FT_UInt cid)
#define FT_FRAME_ENTER(size)
static void cff_charset_free_cids(CFF_Charset charset, FT_Memory memory)
#define FT_MEM_COPY(dest, source, count)
#define FT_STREAM_READ(buffer, count)
#define FT_FRAME_START(size)
cff_index_forget_element(CFF_Index idx, FT_Byte **pbytes)
cff_font_load(FT_Library library, FT_Stream stream, FT_Int face_index, CFF_Font font, FT_Bool pure_cff)
FT_BEGIN_HEADER struct CFF_IndexRec_ * CFF_Index