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 34 static const FT_UShort cff_isoadobe_charset[229] =
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
67 static const FT_UShort cff_expert_charset[166] =
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
92 static const FT_UShort cff_expertsubset_charset[87] =
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
107 static const FT_UShort cff_standard_encoding[256] =
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
143 static const FT_UShort cff_expert_encoding[256] =
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
185 return (
FT_UShort)( charcode < 256 ? cff_standard_encoding[charcode]
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 )
258 idx->off_size = offsize;
259 size = (
FT_ULong)( count + 1 ) * offsize;
266 size = cff_index_read_offset(
idx, &error );
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++ )
398 error = cff_index_load_offsets(
idx );
403 if (
idx->count > 0 &&
406 idx->data_size +
idx->count ) ) )
414 cur_offset =
idx->offsets[0] - 1;
417 if ( cur_offset >=
idx->data_size )
420 " invalid first offset value %d set to zero\n",
426 t[0] = org_bytes + cur_offset;
428 t[0] = new_bytes + cur_offset;
430 for ( n = 1; n <=
idx->count; n++ )
436 if ( next_offset == 0 ||
437 next_offset < cur_offset ||
439 next_offset = cur_offset;
442 t[
n] = org_bytes + next_offset;
445 t[
n] = new_bytes + next_offset + extra;
447 if ( next_offset != cur_offset )
449 FT_MEM_COPY( t[n - 1], org_bytes + cur_offset, t[n] - t[n - 1] );
456 cur_offset = next_offset;
478 if (
idx &&
idx->count > element )
494 off1 = cff_index_read_offset(
idx, &
error );
503 off2 = cff_index_read_offset(
idx, &
error );
505 while ( off2 == 0 && element < idx->
count );
510 off1 =
idx->offsets[element];
516 off2 =
idx->offsets[element];
518 }
while ( off2 == 0 && element < idx->
count );
524 if ( off2 > stream->
size + 1 ||
525 idx->data_offset > stream->
size - off2 + 1 )
527 FT_ERROR((
"cff_index_access_element:" 528 " offset to next entry (%d)" 529 " exceeds the end of stream (%d)\n",
530 off2, stream->
size -
idx->data_offset + 1 ));
531 off2 = stream->
size -
idx->data_offset + 1;
535 if ( off1 && off2 > off1 )
537 *pbyte_len = off2 - off1;
542 *pbytes =
idx->bytes + off1 - 1;
571 if (
idx->bytes == 0 )
615 return ( element < font->num_strings )
626 if ( sid == 0xFFFFU )
634 if ( !font->psnames )
638 return (
FT_String *)font->psnames->adobe_std_strings( sid );
655 if ( fdselect->
data )
692 fdselect->
data_size = num_ranges * 3 + 2;
700 error =
FT_THROW( Invalid_File_Format );
715 switch ( fdselect->
format )
718 fd = fdselect->
data[glyph_index];
741 if ( glyph_index < first )
747 if ( glyph_index < limit )
759 }
while ( p < p_limit );
793 for ( i = 0; i < num_glyphs; i++ )
795 if ( charset->
sids[i] > max_cid )
796 max_cid = charset->
sids[
i];
805 for ( j = num_glyphs - 1; j >= 0 ; j-- )
823 if ( cid <= charset->max_cid )
846 cff_charset_free_cids( charset, memory );
886 charset->
sids[0] = 0;
888 switch ( charset->
format )
891 if ( num_glyphs > 0 )
896 for ( j = 1; j < num_glyphs; j++ )
912 while ( j < num_glyphs )
919 if ( charset->
format == 2 )
931 if ( glyph_sid > 0xFFFFL - nleft )
933 FT_ERROR((
"cff_charset_load: invalid SID range trimmed" 934 " nleft=%d -> %d\n", nleft, 0xFFFFL - glyph_sid ));
935 nleft = (
FT_UInt )( 0xFFFFL - glyph_sid );
939 for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ )
940 charset->
sids[j] = glyph_sid;
946 FT_ERROR((
"cff_charset_load: invalid table format\n" ));
947 error =
FT_THROW( Invalid_File_Format );
966 if ( num_glyphs > 229 )
968 FT_ERROR((
"cff_charset_load: implicit charset larger than\n" 969 "predefined charset (Adobe ISO-Latin)\n" ));
970 error =
FT_THROW( Invalid_File_Format );
984 if ( num_glyphs > 166 )
986 FT_ERROR((
"cff_charset_load: implicit charset larger than\n" 987 "predefined charset (Adobe Expert)\n" ));
988 error =
FT_THROW( Invalid_File_Format );
1002 if ( num_glyphs > 87 )
1004 FT_ERROR((
"cff_charset_load: implicit charset larger than\n" 1005 "predefined charset (Adobe Expert Subset)\n" ));
1006 error =
FT_THROW( Invalid_File_Format );
1020 error =
FT_THROW( Invalid_File_Format );
1027 error = cff_charset_compute_cids( charset, num_glyphs, memory );
1049 encoding->
count = 0;
1069 if ( !charset->
sids )
1071 error =
FT_THROW( Invalid_File_Format );
1076 for ( j = 0; j < 256; j++ )
1078 encoding->
sids [j] = 0;
1079 encoding->
codes[j] = 0;
1104 switch ( encoding->
format & 0x7F )
1115 encoding->
count = count + 1;
1127 if ( j < num_glyphs )
1133 encoding->
sids[glyph_code] = charset->
sids[j];
1148 encoding->
count = 0;
1151 for ( j = 0; j <
count; j++, i += nleft )
1166 encoding->
count = nleft;
1169 for ( k = i; k < nleft +
i; k++, glyph_code++ )
1172 if ( k < num_glyphs && glyph_code < 256 )
1178 encoding->
sids[glyph_code] = charset->
sids[k];
1184 if ( encoding->
count > 256 )
1185 encoding->
count = 256;
1190 FT_ERROR((
"cff_encoding_load: invalid table format\n" ));
1191 error =
FT_THROW( Invalid_File_Format );
1196 if ( encoding->
format & 0x80 )
1205 for ( j = 0; j <
count; j++ )
1216 encoding->
sids[glyph_code] = glyph_sid;
1220 for ( gindex = 0; gindex < num_glyphs; gindex++ )
1222 if ( charset->
sids[gindex] == glyph_sid )
1253 encoding->
count = 0;
1255 error = cff_charset_compute_cids( charset, num_glyphs,
1260 for ( j = 0; j < 256; j++ )
1272 encoding->
count = j + 1;
1276 encoding->
codes[j] = 0;
1277 encoding->
sids [j] = 0;
1283 FT_ERROR((
"cff_encoding_load: invalid table format\n" ));
1284 error =
FT_THROW( Invalid_File_Format );
1372 FT_TRACE4((
" private dictionary:\n" ));
1428 #define FT_STRUCTURE CFF_FontRec 1450 font->memory = memory;
1459 if ( font->version_major != 1 ||
1460 font->header_size < 4 ||
1461 font->absolute_offsize > 4 )
1463 FT_TRACE2((
" not a CFF font header\n" ));
1479 FT_SET_ERROR( cff_index_init( &font->global_subrs_index,
1483 &font->string_pool ) ) )
1486 font->num_strings = string_index.count;
1491 subfont_index = face_index;
1493 if ( subfont_index >= (
FT_Int)font->name_index.count )
1496 " invalid subfont index for pure CFF font (%d)\n",
1502 font->num_faces = font->name_index.count;
1508 if ( font->name_index.count > 1 )
1511 " invalid CFF font with multiple subfonts\n" 1513 " in SFNT wrapper\n" ));
1520 if ( face_index < 0 )
1525 error = cff_subfont_load( &font->top_font,
1526 &font->font_dict_index,
1537 error = cff_index_init( &font->charstrings_index, stream, 0 );
1554 error = cff_index_init( &fd_index, stream, 0 );
1560 FT_TRACE0((
"cff_font_load: FD array too large in CID font\n" ));
1565 font->num_subfonts = fd_index.count;
1570 for ( idx = 0; idx < fd_index.count; idx++ )
1571 font->subfonts[idx] = sub + idx;
1574 for ( idx = 0; idx < fd_index.count; idx++ )
1576 sub = font->subfonts[
idx];
1577 FT_TRACE4((
"parsing subfont %u\n", idx ));
1578 error = cff_subfont_load( sub, &fd_index, idx,
1579 stream, base_offset, library );
1585 error = CFF_Load_FD_Select( &font->fd_select,
1586 font->charstrings_index.count,
1591 cff_index_done( &fd_index );
1597 font->num_subfonts = 0;
1602 FT_ERROR((
"cff_font_load: no charstrings offset\n" ));
1607 font->num_glyphs = font->charstrings_index.count;
1609 error = cff_index_get_pointers( &font->global_subrs_index,
1610 &font->global_subrs,
NULL );
1616 if ( font->num_glyphs > 0 )
1621 error = cff_charset_load( &font->charset, font->num_glyphs, stream,
1629 error = cff_encoding_load( &font->encoding,
1645 cff_index_done( &string_index );
1658 cff_index_done( &font->global_subrs_index );
1659 cff_index_done( &font->font_dict_index );
1660 cff_index_done( &font->name_index );
1661 cff_index_done( &font->charstrings_index );
1665 if ( font->num_subfonts > 0 )
1667 for (
idx = 0;
idx < font->num_subfonts;
idx++ )
1668 cff_subfont_done( memory, font->subfonts[
idx] );
1674 cff_encoding_done( &font->encoding );
1675 cff_charset_done( &font->charset, font->stream );
1677 cff_subfont_done( memory, &font->top_font );
1679 CFF_Done_FD_Select( &font->fd_select, font->stream );
1684 FT_FREE( font->global_subrs );
1688 if ( font->cf2_instance.finalizer )
1690 font->cf2_instance.finalizer( font->cf2_instance.data );
1691 FT_FREE( font->cf2_instance.data );
#define FT_ALLOC(ptr, size)
cff_font_done(CFF_Font font)
cff_get_standard_encoding(FT_UInt charcode)
for(n=1;n< outline->n_points;n++)
cff_index_get_name(CFF_Font font, FT_UInt element)
FT_ULong cid_fd_select_offset
CFF_IndexRec local_subrs_index
#define FT_MEM_ZERO(dest, count)
#define FT_ARRAY_COPY(dest, source, count)
FT_Fixed underline_position
cff_parser_init(CFF_Parser parser, FT_UInt code, void *object, FT_Library library)
return FT_THROW(Missing_Property)
cff_index_get_string(CFF_Font font, FT_UInt element)
FT_UInt embedded_postscript
#define FT_READ_BYTE(var)
FT_Fixed underline_thickness
#define FT_READ_USHORT(var)
FT_Fixed expansion_factor
FT_ULong local_subrs_offset
FT_BEGIN_HEADER typedef unsigned char FT_Bool
#define FT_ERROR(varformat)
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
#define FT_STREAM_SKIP(distance)
FT_ULong charstrings_offset
cff_index_get_sid_string(CFF_Font font, FT_UInt sid)
FT_ULong cid_fd_array_offset
cff_parser_run(CFF_Parser parser, FT_Byte *start, FT_Byte *limit)
#define FT_TRACE2(varformat)
CFF_PrivateRec private_dict
#define CFF_MAX_CID_FONTS
#define FT_PEEK_USHORT(p)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
#define FT_NEW_ARRAY(ptr, count)
#define FT_STREAM_SEEK(position)
GLuint const GLchar * name
#define FT_NEXT_USHORT(buffer)
#define FT_FRAME_RELEASE(bytes)
GLdouble GLdouble GLdouble GLdouble top
#define FT_SET_ERROR(expression)
local void * load(const char *name, size_t *len)
#define FT_FRAME_EXTRACT(size, bytes)
cff_charset_cid_to_gindex(CFF_Charset charset, FT_UInt cid)
GLuint GLuint GLsizei count
#define FT_FRAME_ENTER(size)
FT_TRACE0(("cff_property_set: missing property `%s'\, property_name))
#define FT_MEM_COPY(dest, source, count)
GLenum GLsizei GLenum GLenum const GLvoid * table
#define FT_STREAM_READ(buffer, count)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
#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