32#define Fix2Int( f ) ( (FT_Int) (FT_Short)( (f) >> 16 ) )
33#define Fix2UInt( f ) ( (FT_UInt)(FT_Short)( (f) >> 16 ) )
43#define FT_COMPONENT t1decode
46 typedef enum T1_Operator_
82 const FT_Int t1_args_count[op_max] =
134 FT_LOCAL_DEF( FT_Int )
135 t1_lookup_glyph_by_stdcharcode_ps( PS_Decoder* decoder,
139 const FT_String* glyph_name;
140 FT_Service_PsCMaps psnames = decoder->psnames;
144 if ( charcode < 0 || charcode > 255 )
147 glyph_name = psnames->adobe_std_strings(
148 psnames->adobe_std_encoding[charcode]);
150 for ( n = 0; n < decoder->num_glyphs; n++ )
152 FT_String* name = (FT_String*)decoder->glyph_names[n];
156 name[0] == glyph_name[0] &&
157 ft_strcmp( name, glyph_name ) == 0 )
165#ifdef T1_CONFIG_OPTION_OLD_ENGINE
188 t1_lookup_glyph_by_stdcharcode( T1_Decoder decoder,
192 const FT_String* glyph_name;
193 FT_Service_PsCMaps psnames = decoder->psnames;
197 if ( charcode < 0 || charcode > 255 )
200 glyph_name = psnames->adobe_std_strings(
201 psnames->adobe_std_encoding[charcode]);
203 for ( n = 0; n < decoder->num_glyphs; n++ )
205 FT_String* name = (FT_String*)decoder->glyph_names[n];
209 name[0] == glyph_name[0] &&
210 ft_strcmp( name, glyph_name ) == 0 )
219 FT_LOCAL_DEF( FT_Error )
220 t1_decoder_parse_glyph( T1_Decoder decoder,
223 return decoder->parse_callback( decoder, glyph );
258 t1operator_seac( T1_Decoder decoder,
266 FT_Int bchar_index, achar_index;
268 FT_Int n_base_points;
269 FT_Outline* base = decoder->builder.base;
271 FT_Vector left_bearing, advance;
273#ifdef FT_CONFIG_OPTION_INCREMENTAL
274 T1_Face face = (T1_Face)decoder->builder.face;
280 FT_ERROR((
"t1operator_seac: invalid nested seac\n" ));
281 return FT_THROW( Syntax_Error );
284 if ( decoder->builder.metrics_only )
286 FT_ERROR((
"t1operator_seac: unexpected seac\n" ));
287 return FT_THROW( Syntax_Error );
291 adx += decoder->builder.left_bearing.x;
295#ifdef FT_CONFIG_OPTION_INCREMENTAL
296 if ( decoder->glyph_names == 0 &&
297 !face->root.internal->incremental_interface )
299 if ( decoder->glyph_names == 0 )
302 FT_ERROR((
"t1operator_seac:"
303 " glyph names table not available in this font\n" ));
304 return FT_THROW( Syntax_Error );
307#ifdef FT_CONFIG_OPTION_INCREMENTAL
308 if ( face->root.internal->incremental_interface )
317 bchar_index = t1_lookup_glyph_by_stdcharcode( decoder, bchar );
318 achar_index = t1_lookup_glyph_by_stdcharcode( decoder, achar );
321 if ( bchar_index < 0 || achar_index < 0 )
323 FT_ERROR((
"t1operator_seac:"
324 " invalid seac character code arguments\n" ));
325 return FT_THROW( Syntax_Error );
330 if ( decoder->builder.no_recurse )
332 FT_GlyphSlot glyph = (FT_GlyphSlot)decoder->builder.glyph;
333 FT_GlyphLoader loader = glyph->internal->loader;
338 error = FT_GlyphLoader_CheckSubGlyphs( loader, 2 );
342 subg = loader->current.subglyphs;
345 subg->index = bchar_index;
346 subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES |
347 FT_SUBGLYPH_FLAG_USE_MY_METRICS;
353 subg->index = achar_index;
354 subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES;
355 subg->arg1 = (FT_Int)FIXED_TO_INT( adx - asb );
356 subg->arg2 = (FT_Int)FIXED_TO_INT( ady );
359 glyph->num_subglyphs = 2;
360 glyph->subglyphs = loader->base.subglyphs;
361 glyph->format = FT_GLYPH_FORMAT_COMPOSITE;
363 loader->current.num_subglyphs = 2;
370 FT_GlyphLoader_Prepare( decoder->builder.loader );
375 left_bearing = decoder->builder.left_bearing;
376 advance = decoder->builder.advance;
379 decoder->seac = TRUE;
380 error = t1_decoder_parse_glyph( decoder, (FT_UInt)bchar_index );
381 decoder->seac = FALSE;
388 if ( decoder->builder.parse_state != T1_Parse_Have_Width )
390 left_bearing = decoder->builder.left_bearing;
391 advance = decoder->builder.advance;
394 decoder->builder.left_bearing.x = 0;
395 decoder->builder.left_bearing.y = 0;
397 decoder->builder.pos_x = adx - asb;
398 decoder->builder.pos_y = ady;
404 decoder->seac = TRUE;
405 error = t1_decoder_parse_glyph( decoder, (FT_UInt)achar_index );
406 decoder->seac = FALSE;
413 decoder->builder.left_bearing = left_bearing;
414 decoder->builder.advance = advance;
416 decoder->builder.pos_x = 0;
417 decoder->builder.pos_y = 0;
445 FT_LOCAL_DEF( FT_Error )
446 t1_decoder_parse_charstrings( T1_Decoder decoder,
447 FT_Byte* charstring_base,
448 FT_UInt charstring_len )
451 T1_Decoder_Zone zone;
454 T1_Builder builder = &decoder->builder;
455 FT_Pos x, y, orig_x, orig_y;
456 FT_Int known_othersubr_result_cnt = 0;
457 FT_Int unknown_othersubr_result_cnt = 0;
461 T1_Hints_Funcs hinter;
463#ifdef FT_DEBUG_LEVEL_TRACE
469 seed = (FT_Fixed)( ( (FT_Offset)(
char*)&seed ^
470 (FT_Offset)(
char*)&decoder ^
471 (FT_Offset)(
char*)&charstring_base ) &
473 seed = ( seed ^ ( seed >> 10 ) ^ ( seed >> 20 ) ) & 0xFFFFL;
478 decoder->top = decoder->stack;
479 decoder->zone = decoder->zones;
480 zone = decoder->zones;
482 builder->parse_state = T1_Parse_Start;
484 hinter = (T1_Hints_Funcs)builder->hints_funcs;
488 FT_ASSERT( ( decoder->len_buildchar == 0 ) ==
489 ( decoder->buildchar == NULL ) );
491 if ( decoder->buildchar && decoder->len_buildchar > 0 )
492 FT_ARRAY_ZERO( decoder->buildchar, decoder->len_buildchar );
494 zone->base = charstring_base;
495 limit = zone->limit = charstring_base + charstring_len;
496 ip = zone->cursor = zone->base;
500 x = orig_x = builder->pos_x;
501 y = orig_y = builder->pos_y;
505 hinter->open( hinter->hints );
512 FT_Long* top = decoder->top;
513 T1_Operator op = op_none;
517 FT_ASSERT( known_othersubr_result_cnt == 0 ||
518 unknown_othersubr_result_cnt == 0 );
520#ifdef FT_DEBUG_LEVEL_TRACE
523 FT_TRACE5((
" (%td)", decoder->top - decoder->stack ));
597 FT_ERROR((
"t1_decoder_parse_charstrings:"
598 " invalid escape (12+EOF)\n" ));
623 op = op_callothersubr;
629 op = op_setcurrentpoint;
633 FT_ERROR((
"t1_decoder_parse_charstrings:"
634 " invalid escape (12+%d)\n",
641 if ( ip + 4 > limit )
643 FT_ERROR((
"t1_decoder_parse_charstrings:"
644 " unexpected EOF in integer\n" ));
648 value = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) |
649 ( (FT_UInt32)ip[1] << 16 ) |
650 ( (FT_UInt32)ip[2] << 8 ) |
661 if ( value > 32000 || value < -32000 )
664 FT_ERROR((
"t1_decoder_parse_charstrings:"
665 " no `div' after large integer\n" ));
672 value = (FT_Int32)( (FT_UInt32)value << 16 );
681 value = (FT_Int32)ip[-1] - 139;
686 FT_ERROR((
"t1_decoder_parse_charstrings:"
687 " unexpected EOF in integer\n" ));
692 value = ( ( ip[-2] - 247 ) * 256 ) + ip[-1] + 108;
694 value = -( ( ( ip[-2] - 251 ) * 256 ) + ip[-1] + 108 );
698 value = (FT_Int32)( (FT_UInt32)value << 16 );
702 FT_ERROR((
"t1_decoder_parse_charstrings:"
703 " invalid byte (%d)\n", ip[-1] ));
708 if ( unknown_othersubr_result_cnt > 0 )
720 unknown_othersubr_result_cnt = 0;
725 if ( large_int && !( op == op_none || op == op_div ) )
727 FT_ERROR((
"t1_decoder_parse_charstrings:"
728 " no `div' after large integer\n" ));
740 if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS )
742 FT_ERROR((
"t1_decoder_parse_charstrings: stack overflow\n" ));
746#ifdef FT_DEBUG_LEVEL_TRACE
748 FT_TRACE4((
" %d", value ));
750 FT_TRACE4((
" %d", value / 65536 ));
756 else if ( op == op_callothersubr )
762#ifdef FT_DEBUG_LEVEL_TRACE
763 FT_TRACE4((
" callothersubr\n" ));
767 if ( top - decoder->stack < 2 )
768 goto Stack_Underflow;
772 subr_no = Fix2Int( top[1] );
773 arg_cnt = Fix2Int( top[0] );
787 if ( arg_cnt > top - decoder->stack )
788 goto Stack_Underflow;
792 known_othersubr_result_cnt = 0;
793 unknown_othersubr_result_cnt = 0;
815 goto Unexpected_OtherSubr;
817 if ( !decoder->flex_state ||
818 decoder->num_flex_vectors != 7 )
820 FT_ERROR((
"t1_decoder_parse_charstrings:"
821 " unexpected flex end\n" ));
828 known_othersubr_result_cnt = 2;
833 goto Unexpected_OtherSubr;
835 if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ||
836 FT_SET_ERROR( t1_builder_check_points( builder, 6 ) ) )
839 decoder->flex_state = 1;
840 decoder->num_flex_vectors = 0;
849 goto Unexpected_OtherSubr;
851 if ( !decoder->flex_state )
853 FT_ERROR((
"t1_decoder_parse_charstrings:"
854 " missing flex start\n" ));
861 idx = decoder->num_flex_vectors++;
862 if ( idx > 0 && idx < 7 )
868 if ( FT_SET_ERROR( t1_builder_check_points( builder, 1 ) ) )
871 t1_builder_add_point( builder,
874 (FT_Byte)( idx == 3 || idx == 6 ) );
881 goto Unexpected_OtherSubr;
883 known_othersubr_result_cnt = 1;
886 hinter->reset( hinter->hints,
887 (FT_UInt)builder->current->n_points );
893 top = decoder->stack;
902 PS_Blend blend = decoder->blend;
903 FT_UInt num_points, nn, mm;
910 FT_ERROR((
"t1_decoder_parse_charstrings:"
911 " unexpected multiple masters operator\n" ));
915 num_points = (FT_UInt)subr_no - 13 + ( subr_no == 18 );
916 if ( arg_cnt != (FT_Int)( num_points * blend->num_designs ) )
918 FT_ERROR((
"t1_decoder_parse_charstrings:"
919 " incorrect number of multiple masters arguments\n" ));
939 delta = top + num_points;
941 for ( nn = 0; nn < num_points; nn++ )
943 FT_Long tmp = values[0];
946 for ( mm = 1; mm < blend->num_designs; mm++ )
949 blend->weight_vector[mm] ) );
954 known_othersubr_result_cnt = (FT_Int)num_points;
964 PS_Blend blend = decoder->blend;
967 if ( arg_cnt != 1 || !blend )
968 goto Unexpected_OtherSubr;
970 idx = Fix2Int( top[0] );
973 (FT_UInt)idx + blend->num_designs > decoder->len_buildchar )
974 goto Unexpected_OtherSubr;
976 ft_memcpy( &decoder->buildchar[idx],
977 blend->weight_vector,
979 sizeof ( blend->weight_vector[0] ) );
987 goto Unexpected_OtherSubr;
989 top[0] = ADD_LONG( top[0], top[1] );
991 known_othersubr_result_cnt = 1;
998 goto Unexpected_OtherSubr;
1000 top[0] = SUB_LONG( top[0], top[1] );
1002 known_othersubr_result_cnt = 1;
1009 goto Unexpected_OtherSubr;
1011 top[0] = FT_MulFix( top[0], top[1] );
1013 known_othersubr_result_cnt = 1;
1019 if ( arg_cnt != 2 || top[1] == 0 )
1020 goto Unexpected_OtherSubr;
1022 top[0] = FT_DivFix( top[0], top[1] );
1024 known_othersubr_result_cnt = 1;
1032 PS_Blend blend = decoder->blend;
1035 if ( arg_cnt != 2 || !blend )
1036 goto Unexpected_OtherSubr;
1038 idx = Fix2UInt( top[1] );
1040 if ( idx >= decoder->len_buildchar )
1041 goto Unexpected_OtherSubr;
1043 decoder->buildchar[idx] = top[0];
1053 PS_Blend blend = decoder->blend;
1056 if ( arg_cnt != 1 || !blend )
1057 goto Unexpected_OtherSubr;
1059 idx = Fix2UInt( top[0] );
1061 if ( idx >= decoder->len_buildchar )
1062 goto Unexpected_OtherSubr;
1064 top[0] = decoder->buildchar[idx];
1067 known_othersubr_result_cnt = 1;
1075 XXX which routine has left its mark on the (PostScript) stack?;
1084 goto Unexpected_OtherSubr;
1086 if ( top[2] > top[3] )
1089 known_othersubr_result_cnt = 1;
1096 goto Unexpected_OtherSubr;
1103 if ( Rand >= 0x8000L )
1108 seed = FT_MulFix( seed, 0x10000L - seed );
1113 known_othersubr_result_cnt = 1;
1117 if ( arg_cnt >= 0 && subr_no >= 0 )
1119 FT_ERROR((
"t1_decoder_parse_charstrings:"
1120 " unknown othersubr [%d %d], wish me luck\n",
1121 arg_cnt, subr_no ));
1122 unknown_othersubr_result_cnt = arg_cnt;
1127 Unexpected_OtherSubr:
1128 FT_ERROR((
"t1_decoder_parse_charstrings:"
1129 " invalid othersubr [%d %d]\n", arg_cnt, subr_no ));
1133 top += known_othersubr_result_cnt;
1139 FT_Int num_args = t1_args_count[op];
1142 FT_ASSERT( num_args >= 0 );
1144 if ( top - decoder->stack < num_args )
1145 goto Stack_Underflow;
1153#ifdef FT_DEBUG_LEVEL_TRACE
1159 case op_callothersubr:
1165 if ( top - decoder->stack != num_args )
1166 FT_TRACE0((
"t1_decoder_parse_charstrings:"
1167 " too much operands on the stack"
1168 " (seen %td, expected %d)\n",
1169 top - decoder->stack, num_args ));
1180 FT_TRACE4((
" endchar\n" ));
1182 t1_builder_close_contour( builder );
1187 if ( hinter->close( hinter->hints,
1188 (FT_UInt)builder->current->n_points ) )
1192 error = hinter->apply( hinter->hints,
1194 (PSH_Globals)builder->hints_globals,
1195 decoder->hint_mode );
1201 FT_GlyphLoader_Add( builder->loader );
1205#ifdef FT_DEBUG_LEVEL_TRACE
1207 if ( decoder->len_buildchar > 0 )
1212 FT_TRACE4((
"BuildCharArray = [ " ));
1214 for ( i = 0; i < decoder->len_buildchar; i++ )
1215 FT_TRACE4((
"%ld ", decoder->buildchar[i] ));
1217 FT_TRACE4((
"]\n" ));
1222 FT_TRACE4((
"\n" ));
1228 FT_TRACE4((
" hsbw" ));
1230 builder->parse_state = T1_Parse_Have_Width;
1232 builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1235 builder->advance.x = top[1];
1236 builder->advance.y = 0;
1238 orig_x = x = ADD_LONG( builder->pos_x, top[0] );
1239 orig_y = y = builder->pos_y;
1241 FT_UNUSED( orig_y );
1246 if ( builder->metrics_only )
1248 FT_TRACE4((
"\n" ));
1255 return t1operator_seac( decoder,
1260 Fix2Int( top[4] ) );
1263 FT_TRACE4((
" sbw" ));
1265 builder->parse_state = T1_Parse_Have_Width;
1267 builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1269 builder->left_bearing.y = ADD_LONG( builder->left_bearing.y,
1272 builder->advance.x = top[2];
1273 builder->advance.y = top[3];
1275 x = ADD_LONG( builder->pos_x, top[0] );
1276 y = ADD_LONG( builder->pos_y, top[1] );
1281 if ( builder->metrics_only )
1283 FT_TRACE4((
"\n" ));
1290 FT_TRACE4((
" closepath" ));
1293 if ( builder->parse_state == T1_Parse_Have_Path ||
1294 builder->parse_state == T1_Parse_Have_Moveto )
1295 t1_builder_close_contour( builder );
1297 builder->parse_state = T1_Parse_Have_Width;
1301 FT_TRACE4((
" hlineto" ));
1303 if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) )
1306 x = ADD_LONG( x, top[0] );
1310 FT_TRACE4((
" hmoveto" ));
1312 x = ADD_LONG( x, top[0] );
1314 if ( !decoder->flex_state )
1316 if ( builder->parse_state == T1_Parse_Start )
1318 builder->parse_state = T1_Parse_Have_Moveto;
1323 FT_TRACE4((
" hvcurveto" ));
1325 if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ||
1326 FT_SET_ERROR( t1_builder_check_points( builder, 3 ) ) )
1329 x = ADD_LONG( x, top[0] );
1330 t1_builder_add_point( builder, x, y, 0 );
1332 x = ADD_LONG( x, top[1] );
1333 y = ADD_LONG( y, top[2] );
1334 t1_builder_add_point( builder, x, y, 0 );
1336 y = ADD_LONG( y, top[3] );
1337 t1_builder_add_point( builder, x, y, 1 );
1341 FT_TRACE4((
" rlineto" ));
1343 if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) )
1346 x = ADD_LONG( x, top[0] );
1347 y = ADD_LONG( y, top[1] );
1350 if ( FT_SET_ERROR( t1_builder_add_point1( builder, x, y ) ) )
1355 FT_TRACE4((
" rmoveto" ));
1357 x = ADD_LONG( x, top[0] );
1358 y = ADD_LONG( y, top[1] );
1360 if ( !decoder->flex_state )
1362 if ( builder->parse_state == T1_Parse_Start )
1364 builder->parse_state = T1_Parse_Have_Moveto;
1369 FT_TRACE4((
" rrcurveto" ));
1371 if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ||
1372 FT_SET_ERROR( t1_builder_check_points( builder, 3 ) ) )
1375 x = ADD_LONG( x, top[0] );
1376 y = ADD_LONG( y, top[1] );
1377 t1_builder_add_point( builder, x, y, 0 );
1379 x = ADD_LONG( x, top[2] );
1380 y = ADD_LONG( y, top[3] );
1381 t1_builder_add_point( builder, x, y, 0 );
1383 x = ADD_LONG( x, top[4] );
1384 y = ADD_LONG( y, top[5] );
1385 t1_builder_add_point( builder, x, y, 1 );
1389 FT_TRACE4((
" vhcurveto" ));
1391 if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) ||
1392 FT_SET_ERROR( t1_builder_check_points( builder, 3 ) ) )
1395 y = ADD_LONG( y, top[0] );
1396 t1_builder_add_point( builder, x, y, 0 );
1398 x = ADD_LONG( x, top[1] );
1399 y = ADD_LONG( y, top[2] );
1400 t1_builder_add_point( builder, x, y, 0 );
1402 x = ADD_LONG( x, top[3] );
1403 t1_builder_add_point( builder, x, y, 1 );
1407 FT_TRACE4((
" vlineto" ));
1409 if ( FT_SET_ERROR( t1_builder_start_point( builder, x, y ) ) )
1412 y = ADD_LONG( y, top[0] );
1416 FT_TRACE4((
" vmoveto" ));
1418 y = ADD_LONG( y, top[0] );
1420 if ( !decoder->flex_state )
1422 if ( builder->parse_state == T1_Parse_Start )
1424 builder->parse_state = T1_Parse_Have_Moveto;
1429 FT_TRACE4((
" div" ));
1434 *top = FT_DivFix( top[0], top[1] );
1445 FT_TRACE4((
" callsubr" ));
1447 idx = Fix2Int( top[0] );
1449 if ( decoder->subrs_hash )
1451 size_t* val = ft_hash_num_lookup( idx,
1452 decoder->subrs_hash );
1461 if ( idx < 0 || idx >= decoder->num_subrs )
1463 FT_ERROR((
"t1_decoder_parse_charstrings:"
1464 " invalid subrs index\n" ));
1468 if ( zone - decoder->zones >= T1_MAX_SUBRS_CALLS )
1470 FT_ERROR((
"t1_decoder_parse_charstrings:"
1471 " too many nested subrs\n" ));
1482 zone->base = decoder->subrs[idx];
1484 if ( decoder->subrs_len )
1485 zone->limit = zone->base + decoder->subrs_len[idx];
1490 zone->base += ( decoder->lenIV >= 0 ? decoder->lenIV : 0 );
1491 zone->limit = decoder->subrs[idx + 1];
1494 zone->cursor = zone->base;
1498 FT_ERROR((
"t1_decoder_parse_charstrings:"
1499 " invoking empty subrs\n" ));
1503 decoder->zone = zone;
1505 limit = zone->limit;
1510 FT_TRACE4((
" pop" ));
1512 if ( known_othersubr_result_cnt > 0 )
1514 known_othersubr_result_cnt--;
1519 if ( unknown_othersubr_result_cnt == 0 )
1521 FT_ERROR((
"t1_decoder_parse_charstrings:"
1522 " no more operands for othersubr\n" ));
1526 unknown_othersubr_result_cnt--;
1531 FT_TRACE4((
" return" ));
1533 if ( zone <= decoder->zones )
1535 FT_ERROR((
"t1_decoder_parse_charstrings:"
1536 " unexpected return\n" ));
1542 limit = zone->limit;
1543 decoder->zone = zone;
1547 FT_TRACE4((
" dotsection" ));
1552 FT_TRACE4((
" hstem" ));
1558 hinter->stem( hinter->hints, 1, top );
1563 FT_TRACE4((
" hstem3" ));
1567 hinter->stem3( hinter->hints, 1, top );
1571 FT_TRACE4((
" vstem" ));
1576 top[0] = ADD_LONG( top[0], orig_x );
1577 hinter->stem( hinter->hints, 0, top );
1582 FT_TRACE4((
" vstem3" ));
1590 top[0] = ADD_LONG( top[0], dx );
1591 top[2] = ADD_LONG( top[2], dx );
1592 top[4] = ADD_LONG( top[4], dx );
1593 hinter->stem3( hinter->hints, 0, top );
1597 case op_setcurrentpoint:
1598 FT_TRACE4((
" setcurrentpoint" ));
1614 if ( decoder->flex_state != 1 )
1616 FT_ERROR((
"t1_decoder_parse_charstrings:"
1617 " unexpected `setcurrentpoint'\n" ));
1626 decoder->flex_state = 0;
1630 FT_TRACE4((
" opcode_15" ));
1635 FT_ERROR((
"t1_decoder_parse_charstrings:"
1636 " unhandled opcode %u\n", op ));
1647#ifdef FT_DEBUG_LEVEL_TRACE
1648 FT_TRACE4((
"\n" ));
1656 FT_TRACE4((
"..end..\n" ));
1657 FT_TRACE4((
"\n" ));
1663 return FT_THROW( Syntax_Error );
1666 return FT_THROW( Stack_Underflow );
1694 FT_LOCAL_DEF( FT_Error )
1695 t1_decoder_parse_metrics( T1_Decoder decoder,
1696 FT_Byte* charstring_base,
1697 FT_UInt charstring_len )
1699 T1_Decoder_Zone zone;
1702 T1_Builder builder = &decoder->builder;
1705#ifdef FT_DEBUG_LEVEL_TRACE
1711 decoder->top = decoder->stack;
1712 decoder->zone = decoder->zones;
1713 zone = decoder->zones;
1715 builder->parse_state = T1_Parse_Start;
1717 zone->base = charstring_base;
1718 limit = zone->limit = charstring_base + charstring_len;
1719 ip = zone->cursor = zone->base;
1724 while ( ip < limit )
1726 FT_Long* top = decoder->top;
1727 T1_Operator op = op_none;
1731#ifdef FT_DEBUG_LEVEL_TRACE
1734 FT_TRACE5((
" (%ld)", decoder->top - decoder->stack ));
1778 FT_ERROR((
"t1_decoder_parse_metrics:"
1779 " invalid escape (12+EOF)\n" ));
1798 if ( ip + 4 > limit )
1800 FT_ERROR((
"t1_decoder_parse_metrics:"
1801 " unexpected EOF in integer\n" ));
1805 value = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) |
1806 ( (FT_UInt32)ip[1] << 16 ) |
1807 ( (FT_UInt32)ip[2] << 8 ) |
1818 if ( value > 32000 || value < -32000 )
1822 FT_ERROR((
"t1_decoder_parse_metrics:"
1823 " no `div' after large integer\n" ));
1832 value = (FT_Int32)( (FT_UInt32)value << 16 );
1841 value = (FT_Int32)ip[-1] - 139;
1846 FT_ERROR((
"t1_decoder_parse_metrics:"
1847 " unexpected EOF in integer\n" ));
1852 value = ( ( ip[-2] - 247 ) * 256 ) + ip[-1] + 108;
1854 value = -( ( ( ip[-2] - 251 ) * 256 ) + ip[-1] + 108 );
1858 value = (FT_Int32)( (FT_UInt32)value << 16 );
1862 FT_ERROR((
"t1_decoder_parse_metrics:"
1863 " invalid byte (%d)\n", ip[-1] ));
1868 if ( large_int && !( op == op_none || op == op_div ) )
1870 FT_ERROR((
"t1_decoder_parse_metrics:"
1871 " no `div' after large integer\n" ));
1880 if ( op == op_none )
1882 if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS )
1884 FT_ERROR((
"t1_decoder_parse_metrics: stack overflow\n" ));
1888#ifdef FT_DEBUG_LEVEL_TRACE
1890 FT_TRACE4((
" %d", value ));
1892 FT_TRACE4((
" %d", value / 65536 ));
1900 FT_Int num_args = t1_args_count[op];
1903 FT_ASSERT( num_args >= 0 );
1905 if ( top - decoder->stack < num_args )
1906 goto Stack_Underflow;
1908#ifdef FT_DEBUG_LEVEL_TRACE
1918 if ( top - decoder->stack != num_args )
1919 FT_TRACE0((
"t1_decoder_parse_metrics:"
1920 " too much operands on the stack"
1921 " (seen %ld, expected %d)\n",
1922 top - decoder->stack, num_args ));
1933 FT_TRACE4((
" hsbw" ));
1935 builder->parse_state = T1_Parse_Have_Width;
1937 builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1940 builder->advance.x = top[1];
1941 builder->advance.y = 0;
1946 FT_TRACE4((
"\n" ));
1950 FT_TRACE4((
" sbw" ));
1952 builder->parse_state = T1_Parse_Have_Width;
1954 builder->left_bearing.x = ADD_LONG( builder->left_bearing.x,
1956 builder->left_bearing.y = ADD_LONG( builder->left_bearing.y,
1959 builder->advance.x = top[2];
1960 builder->advance.y = top[3];
1965 FT_TRACE4((
"\n" ));
1969 FT_TRACE4((
" div" ));
1974 *top = FT_DivFix( top[0], top[1] );
1985 FT_TRACE4((
" callsubr" ));
1987 idx = Fix2Int( top[0] );
1989 if ( decoder->subrs_hash )
1991 size_t* val = ft_hash_num_lookup( idx,
1992 decoder->subrs_hash );
2001 if ( idx < 0 || idx >= decoder->num_subrs )
2003 FT_ERROR((
"t1_decoder_parse_metrics:"
2004 " invalid subrs index\n" ));
2008 if ( zone - decoder->zones >= T1_MAX_SUBRS_CALLS )
2010 FT_ERROR((
"t1_decoder_parse_metrics:"
2011 " too many nested subrs\n" ));
2022 zone->base = decoder->subrs[idx];
2024 if ( decoder->subrs_len )
2025 zone->limit = zone->base + decoder->subrs_len[idx];
2030 zone->base += ( decoder->lenIV >= 0 ? decoder->lenIV : 0 );
2031 zone->limit = decoder->subrs[idx + 1];
2034 zone->cursor = zone->base;
2038 FT_ERROR((
"t1_decoder_parse_metrics:"
2039 " invoking empty subrs\n" ));
2043 decoder->zone = zone;
2045 limit = zone->limit;
2050 FT_TRACE4((
" return" ));
2052 if ( zone <= decoder->zones )
2054 FT_ERROR((
"t1_decoder_parse_metrics:"
2055 " unexpected return\n" ));
2061 limit = zone->limit;
2062 decoder->zone = zone;
2066 FT_ERROR((
"t1_decoder_parse_metrics:"
2067 " unhandled opcode %d\n", op ));
2077 FT_TRACE4((
"..end..\n" ));
2078 FT_TRACE4((
"\n" ));
2081 FT_ERROR((
"t1_decoder_parse_metrics:"
2082 " no width, found op %d instead\n",
2085 return FT_THROW( Syntax_Error );
2088 return FT_THROW( Stack_Underflow );
2095 FT_LOCAL_DEF( FT_Error )
2096 t1_decoder_init( T1_Decoder decoder,
2100 FT_Byte** glyph_names,
2103 FT_Render_Mode hint_mode,
2104 T1_Decoder_Callback parse_callback )
2110 FT_Service_PsCMaps psnames;
2113 FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS );
2116 FT_ERROR((
"t1_decoder_init:"
2117 " the `psnames' module is not available\n" ));
2118 return FT_THROW( Unimplemented_Feature );
2121 decoder->psnames = psnames;
2124 t1_builder_init( &decoder->builder, face, size, slot, hinting );
2130 decoder->num_glyphs = (FT_UInt)face->num_glyphs;
2131 decoder->glyph_names = glyph_names;
2132 decoder->hint_mode = hint_mode;
2133 decoder->blend = blend;
2134 decoder->parse_callback = parse_callback;
2136 decoder->funcs = t1_decoder_funcs;
2143 FT_LOCAL_DEF(
void )
2144 t1_decoder_done( T1_Decoder decoder )
2146 FT_Memory memory = decoder->builder.memory;
2149 t1_builder_done( &decoder->builder );
2151 if ( decoder->cf2_instance.finalizer )
2153 decoder->cf2_instance.finalizer( decoder->cf2_instance.data );
2154 FT_FREE( decoder->cf2_instance.data );