38#define FT_COMPONENT cffdecode
41#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
43 typedef enum CFF_Operator_
114 cff_op_callothersubr,
118 cff_op_setcurrentpoint,
126#define CFF_COUNT_CHECK_WIDTH 0x80
127#define CFF_COUNT_EXACT 0x40
128#define CFF_COUNT_CLEAR_STACK 0x20
136 static const FT_Byte cff_argument_counts[] =
140 2 | CFF_COUNT_CHECK_WIDTH | CFF_COUNT_EXACT,
141 1 | CFF_COUNT_CHECK_WIDTH | CFF_COUNT_EXACT,
142 1 | CFF_COUNT_CHECK_WIDTH | CFF_COUNT_EXACT,
144 0 | CFF_COUNT_CLEAR_STACK,
145 0 | CFF_COUNT_CLEAR_STACK,
146 0 | CFF_COUNT_CLEAR_STACK,
148 0 | CFF_COUNT_CLEAR_STACK,
149 0 | CFF_COUNT_CLEAR_STACK,
150 0 | CFF_COUNT_CLEAR_STACK,
151 0 | CFF_COUNT_CLEAR_STACK,
152 0 | CFF_COUNT_CLEAR_STACK,
153 0 | CFF_COUNT_CLEAR_STACK,
154 0 | CFF_COUNT_CLEAR_STACK,
161 0 | CFF_COUNT_CHECK_WIDTH,
163 2 | CFF_COUNT_CHECK_WIDTH,
164 2 | CFF_COUNT_CHECK_WIDTH,
165 2 | CFF_COUNT_CHECK_WIDTH,
166 2 | CFF_COUNT_CHECK_WIDTH,
168 0 | CFF_COUNT_CHECK_WIDTH,
169 0 | CFF_COUNT_CHECK_WIDTH,
215 cff_operator_seac( CFF_Decoder* decoder,
223 CFF_Builder* builder = &decoder->builder;
224 FT_Int bchar_index, achar_index;
225 TT_Face face = decoder->builder.face;
226 FT_Vector left_bearing, advance;
228 FT_ULong charstring_len;
234 FT_ERROR((
"cff_operator_seac: invalid nested seac\n" ));
235 return FT_THROW( Syntax_Error );
238 adx = ADD_LONG( adx, decoder->builder.left_bearing.x );
239 ady = ADD_LONG( ady, decoder->builder.left_bearing.y );
241#ifdef FT_CONFIG_OPTION_INCREMENTAL
244 if ( face->root.internal->incremental_interface )
252 CFF_Font cff = (CFF_Font)( face->extra.data );
255 bchar_index = cff_lookup_glyph_by_stdcharcode( cff, bchar );
256 achar_index = cff_lookup_glyph_by_stdcharcode( cff, achar );
259 if ( bchar_index < 0 || achar_index < 0 )
261 FT_ERROR((
"cff_operator_seac:"
262 " invalid seac character code arguments\n" ));
263 return FT_THROW( Syntax_Error );
268 if ( builder->no_recurse )
270 FT_GlyphSlot glyph = (FT_GlyphSlot)builder->glyph;
271 FT_GlyphLoader loader = glyph->internal->loader;
276 error = FT_GlyphLoader_CheckSubGlyphs( loader, 2 );
280 subg = loader->current.subglyphs;
283 subg->index = bchar_index;
284 subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES |
285 FT_SUBGLYPH_FLAG_USE_MY_METRICS;
291 subg->index = achar_index;
292 subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES;
293 subg->arg1 = (FT_Int)( adx >> 16 );
294 subg->arg2 = (FT_Int)( ady >> 16 );
297 glyph->num_subglyphs = 2;
298 glyph->subglyphs = loader->base.subglyphs;
299 glyph->format = FT_GLYPH_FORMAT_COMPOSITE;
301 loader->current.num_subglyphs = 2;
304 FT_GlyphLoader_Prepare( builder->loader );
307 error = decoder->get_glyph_callback( face, (FT_UInt)bchar_index,
308 &charstring, &charstring_len );
312 decoder->seac = TRUE;
313 error = cff_decoder_parse_charstrings( decoder, charstring,
315 decoder->seac = FALSE;
317 decoder->free_glyph_callback( face, &charstring, charstring_len );
326 left_bearing = builder->left_bearing;
327 advance = builder->advance;
328 glyph_width = decoder->glyph_width;
330 builder->left_bearing.x = 0;
331 builder->left_bearing.y = 0;
333 builder->pos_x = SUB_LONG( adx, asb );
334 builder->pos_y = ady;
337 error = decoder->get_glyph_callback( face, (FT_UInt)achar_index,
338 &charstring, &charstring_len );
342 decoder->seac = TRUE;
343 error = cff_decoder_parse_charstrings( decoder, charstring,
345 decoder->seac = FALSE;
347 decoder->free_glyph_callback( face, &charstring, charstring_len );
355 builder->left_bearing = left_bearing;
356 builder->advance = advance;
357 decoder->glyph_width = glyph_width;
402 cff_compute_bias( FT_Int in_charstring_type,
408 if ( in_charstring_type == 1 )
410 else if ( num_subrs < 1240 )
412 else if ( num_subrs < 33900U )
421 FT_LOCAL_DEF( FT_Int )
422 cff_lookup_glyph_by_stdcharcode( CFF_Font cff,
428 FT_Service_CFFLoad cffload;
432 if ( !cff->charset.sids )
436 if ( charcode < 0 || charcode > 255 )
441 FT_Service_CFFLoad cffload;
444 FT_FACE_FIND_GLOBAL_SERVICE( face, cffload, CFF_LOAD );
447 FT_ERROR((
"cff_lookup_glyph_by_stdcharcode:"
448 " the `cffload' module is not available\n" ));
449 return FT_THROW( Unimplemented_Feature );
453 cffload = (FT_Service_CFFLoad)cff->cffload;
456 glyph_sid = cffload->get_standard_encoding( (FT_UInt)charcode );
458 for ( n = 0; n < cff->num_glyphs; n++ )
460 if ( cff->charset.sids[n] == glyph_sid )
468#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
496 FT_LOCAL_DEF( FT_Error )
497 cff_decoder_parse_charstrings( CFF_Decoder* decoder,
498 FT_Byte* charstring_base,
499 FT_ULong charstring_len,
503 CFF_Decoder_Zone* zone;
506 CFF_Builder* builder = &decoder->builder;
509 FT_Int charstring_type =
510 decoder->cff->top_font.font_dict.charstring_type;
511 FT_UShort num_designs =
512 decoder->cff->top_font.font_dict.num_designs;
514 decoder->cff->top_font.font_dict.num_axes;
516 T2_Hints_Funcs hinter;
520 decoder->num_hints = 0;
521 decoder->read_width = 1;
524 decoder->top = decoder->stack;
525 decoder->zone = decoder->zones;
526 zone = decoder->zones;
527 stack = decoder->top;
529 hinter = (T2_Hints_Funcs)builder->hints_funcs;
531 builder->path_begun = 0;
533 if ( !charstring_base )
536 zone->base = charstring_base;
537 limit = zone->limit = charstring_base + charstring_len;
538 ip = zone->cursor = zone->base;
547 hinter->open( hinter->hints );
561 if ( v >= 32 || v == 28 )
573 if ( ip + 1 >= limit )
575 val = (FT_Short)( ( (FT_UShort)ip[0] << 8 ) | ip[1] );
579 val = (FT_Int32)v - 139;
584 val = ( (FT_Int32)v - 247 ) * 256 + *ip++ + 108;
590 val = -( (FT_Int32)v - 251 ) * 256 - *ip++ - 108;
594 if ( ip + 3 >= limit )
596 val = (FT_Int32)( ( (FT_UInt32)ip[0] << 24 ) |
597 ( (FT_UInt32)ip[1] << 16 ) |
598 ( (FT_UInt32)ip[2] << 8 ) |
601 if ( charstring_type == 2 )
604 if ( decoder->top - stack >= CFF_MAX_OPERANDS )
607 val = (FT_Int32)( (FT_UInt32)val << shift );
608 *decoder->top++ = val;
610#ifdef FT_DEBUG_LEVEL_TRACE
611 if ( !( val & 0xFFFFL ) )
612 FT_TRACE4((
" %hd", (FT_Short)( (FT_UInt32)val >> 16 ) ));
614 FT_TRACE4((
" %.5f", val / 65536.0 ));
625 FT_Fixed* args = decoder->top;
626 FT_Int num_args = (FT_Int)( args - decoder->stack );
654 op = cff_op_rrcurveto;
657 op = cff_op_closepath;
660 op = cff_op_callsubr;
673 op = cff_op_dotsection;
721 op = cff_op_callothersubr;
760 op = cff_op_setcurrentpoint;
775 FT_TRACE4((
" unknown op (12, %d)\n", v ));
792 op = cff_op_hintmask;
795 op = cff_op_cntrmask;
807 op = cff_op_rcurveline;
810 op = cff_op_rlinecurve;
813 op = cff_op_vvcurveto;
816 op = cff_op_hhcurveto;
819 op = cff_op_callgsubr;
822 op = cff_op_vhcurveto;
825 op = cff_op_hvcurveto;
828 FT_TRACE4((
" unknown op (%d)\n", v ));
832 if ( op == cff_op_unknown )
847 case cff_op_rrcurveto:
849 case cff_op_hintmask:
850 case cff_op_cntrmask:
854 case cff_op_rcurveline:
855 case cff_op_rlinecurve:
856 case cff_op_vvcurveto:
857 case cff_op_hhcurveto:
858 case cff_op_vhcurveto:
859 case cff_op_hvcurveto:
864 case cff_op_callsubr:
865 case cff_op_callgsubr:
867 case cff_op_dotsection:
870 case cff_op_closepath:
871 case cff_op_callothersubr:
874 case cff_op_setcurrentpoint:
883 req_args = cff_argument_counts[op];
884 if ( req_args & CFF_COUNT_CHECK_WIDTH )
886 if ( num_args > 0 && decoder->read_width )
903 set_width_ok = num_args & 2;
911 case cff_op_hintmask:
912 case cff_op_cntrmask:
913 set_width_ok = num_args & 1;
919 set_width_ok = in_dict
921 : ( ( num_args == 5 ) || ( num_args == 1 ) );
931 decoder->glyph_width = decoder->nominal_width +
934 if ( decoder->width_only )
945 decoder->read_width = 0;
950 if ( num_args < req_args )
951 goto Stack_Underflow;
953 num_args -= req_args;
971 op == cff_op_hstem ?
" hstem" :
972 ( op == cff_op_vstem ?
" vstem" :
973 ( op == cff_op_hstemhm ?
" hstemhm" :
" vstemhm" ) ) ));
976 hinter->stems( hinter->hints,
977 ( op == cff_op_hstem || op == cff_op_hstemhm ),
979 args - ( num_args & ~1 ) );
981 decoder->num_hints += num_args / 2;
985 case cff_op_hintmask:
986 case cff_op_cntrmask:
987 FT_TRACE4((
"%s", op == cff_op_hintmask ?
" hintmask"
997 hinter->stems( hinter->hints,
1000 args - ( num_args & ~1 ) );
1002 decoder->num_hints += num_args / 2;
1010 if ( ( ip + ( ( decoder->num_hints + 7 ) >> 3 ) ) >= limit )
1015 if ( op == cff_op_hintmask )
1016 hinter->hintmask( hinter->hints,
1017 (FT_UInt)builder->current->n_points,
1018 (FT_UInt)decoder->num_hints,
1021 hinter->counter( hinter->hints,
1022 (FT_UInt)decoder->num_hints,
1026#ifdef FT_DEBUG_LEVEL_TRACE
1031 FT_TRACE4((
" (maskbytes:" ));
1034 maskbyte < (FT_UInt)( ( decoder->num_hints + 7 ) >> 3 );
1036 FT_TRACE4((
" 0x%02X", *ip ));
1038 FT_TRACE4((
")\n" ));
1041 ip += ( decoder->num_hints + 7 ) >> 3;
1046 case cff_op_rmoveto:
1047 FT_TRACE4((
" rmoveto\n" ));
1049 cff_builder_close_contour( builder );
1050 builder->path_begun = 0;
1051 x = ADD_LONG( x, args[-2] );
1052 y = ADD_LONG( y, args[-1] );
1056 case cff_op_vmoveto:
1057 FT_TRACE4((
" vmoveto\n" ));
1059 cff_builder_close_contour( builder );
1060 builder->path_begun = 0;
1061 y = ADD_LONG( y, args[-1] );
1065 case cff_op_hmoveto:
1066 FT_TRACE4((
" hmoveto\n" ));
1068 cff_builder_close_contour( builder );
1069 builder->path_begun = 0;
1070 x = ADD_LONG( x, args[-1] );
1074 case cff_op_rlineto:
1075 FT_TRACE4((
" rlineto\n" ));
1077 if ( cff_builder_start_point( builder, x, y ) ||
1078 cff_check_points( builder, num_args / 2 ) )
1082 goto Stack_Underflow;
1084 args -= num_args & ~1;
1085 while ( args < decoder->top )
1087 x = ADD_LONG( x, args[0] );
1088 y = ADD_LONG( y, args[1] );
1089 cff_builder_add_point( builder, x, y, 1 );
1095 case cff_op_hlineto:
1096 case cff_op_vlineto:
1098 FT_Int phase = ( op == cff_op_hlineto );
1101 FT_TRACE4((
"%s\n", op == cff_op_hlineto ?
" hlineto"
1105 goto Stack_Underflow;
1109 if ( num_args == 0 )
1112 if ( cff_builder_start_point( builder, x, y ) ||
1113 cff_check_points( builder, num_args ) )
1117 while ( args < decoder->top )
1120 x = ADD_LONG( x, args[0] );
1122 y = ADD_LONG( y, args[0] );
1124 if ( cff_builder_add_point1( builder, x, y ) )
1134 case cff_op_rrcurveto:
1139 FT_TRACE4((
" rrcurveto\n" ));
1142 goto Stack_Underflow;
1144 nargs = num_args - num_args % 6;
1146 if ( cff_builder_start_point( builder, x, y ) ||
1147 cff_check_points( builder, nargs / 2 ) )
1151 while ( args < decoder->top )
1153 x = ADD_LONG( x, args[0] );
1154 y = ADD_LONG( y, args[1] );
1155 cff_builder_add_point( builder, x, y, 0 );
1157 x = ADD_LONG( x, args[2] );
1158 y = ADD_LONG( y, args[3] );
1159 cff_builder_add_point( builder, x, y, 0 );
1161 x = ADD_LONG( x, args[4] );
1162 y = ADD_LONG( y, args[5] );
1163 cff_builder_add_point( builder, x, y, 1 );
1171 case cff_op_vvcurveto:
1176 FT_TRACE4((
" vvcurveto\n" ));
1179 goto Stack_Underflow;
1184 nargs = num_args & ~2;
1186 if ( cff_builder_start_point( builder, x, y ) )
1193 x = ADD_LONG( x, args[0] );
1198 if ( cff_check_points( builder, 3 * ( nargs / 4 ) ) )
1201 while ( args < decoder->top )
1203 y = ADD_LONG( y, args[0] );
1204 cff_builder_add_point( builder, x, y, 0 );
1206 x = ADD_LONG( x, args[1] );
1207 y = ADD_LONG( y, args[2] );
1208 cff_builder_add_point( builder, x, y, 0 );
1210 y = ADD_LONG( y, args[3] );
1211 cff_builder_add_point( builder, x, y, 1 );
1219 case cff_op_hhcurveto:
1224 FT_TRACE4((
" hhcurveto\n" ));
1227 goto Stack_Underflow;
1232 nargs = num_args & ~2;
1234 if ( cff_builder_start_point( builder, x, y ) )
1240 y = ADD_LONG( y, args[0] );
1245 if ( cff_check_points( builder, 3 * ( nargs / 4 ) ) )
1248 while ( args < decoder->top )
1250 x = ADD_LONG( x, args[0] );
1251 cff_builder_add_point( builder, x, y, 0 );
1253 x = ADD_LONG( x, args[1] );
1254 y = ADD_LONG( y, args[2] );
1255 cff_builder_add_point( builder, x, y, 0 );
1257 x = ADD_LONG( x, args[3] );
1258 cff_builder_add_point( builder, x, y, 1 );
1266 case cff_op_vhcurveto:
1267 case cff_op_hvcurveto:
1273 FT_TRACE4((
"%s\n", op == cff_op_vhcurveto ?
" vhcurveto"
1276 if ( cff_builder_start_point( builder, x, y ) )
1280 goto Stack_Underflow;
1285 nargs = num_args & ~2;
1288 if ( cff_check_points( builder, ( nargs / 4 ) * 3 ) )
1289 goto Stack_Underflow;
1291 phase = ( op == cff_op_hvcurveto );
1293 while ( nargs >= 4 )
1298 x = ADD_LONG( x, args[0] );
1299 cff_builder_add_point( builder, x, y, 0 );
1301 x = ADD_LONG( x, args[1] );
1302 y = ADD_LONG( y, args[2] );
1303 cff_builder_add_point( builder, x, y, 0 );
1305 y = ADD_LONG( y, args[3] );
1307 x = ADD_LONG( x, args[4] );
1308 cff_builder_add_point( builder, x, y, 1 );
1312 y = ADD_LONG( y, args[0] );
1313 cff_builder_add_point( builder, x, y, 0 );
1315 x = ADD_LONG( x, args[1] );
1316 y = ADD_LONG( y, args[2] );
1317 cff_builder_add_point( builder, x, y, 0 );
1319 x = ADD_LONG( x, args[3] );
1321 y = ADD_LONG( y, args[4] );
1322 cff_builder_add_point( builder, x, y, 1 );
1331 case cff_op_rlinecurve:
1337 FT_TRACE4((
" rlinecurve\n" ));
1340 goto Stack_Underflow;
1342 nargs = num_args & ~1;
1343 num_lines = ( nargs - 6 ) / 2;
1345 if ( cff_builder_start_point( builder, x, y ) ||
1346 cff_check_points( builder, num_lines + 3 ) )
1352 while ( num_lines > 0 )
1354 x = ADD_LONG( x, args[0] );
1355 y = ADD_LONG( y, args[1] );
1356 cff_builder_add_point( builder, x, y, 1 );
1363 x = ADD_LONG( x, args[0] );
1364 y = ADD_LONG( y, args[1] );
1365 cff_builder_add_point( builder, x, y, 0 );
1367 x = ADD_LONG( x, args[2] );
1368 y = ADD_LONG( y, args[3] );
1369 cff_builder_add_point( builder, x, y, 0 );
1371 x = ADD_LONG( x, args[4] );
1372 y = ADD_LONG( y, args[5] );
1373 cff_builder_add_point( builder, x, y, 1 );
1379 case cff_op_rcurveline:
1385 FT_TRACE4((
" rcurveline\n" ));
1388 goto Stack_Underflow;
1390 nargs = num_args - 2;
1391 nargs = nargs - nargs % 6 + 2;
1392 num_curves = ( nargs - 2 ) / 6;
1394 if ( cff_builder_start_point( builder, x, y ) ||
1395 cff_check_points( builder, num_curves * 3 + 2 ) )
1401 while ( num_curves > 0 )
1403 x = ADD_LONG( x, args[0] );
1404 y = ADD_LONG( y, args[1] );
1405 cff_builder_add_point( builder, x, y, 0 );
1407 x = ADD_LONG( x, args[2] );
1408 y = ADD_LONG( y, args[3] );
1409 cff_builder_add_point( builder, x, y, 0 );
1411 x = ADD_LONG( x, args[4] );
1412 y = ADD_LONG( y, args[5] );
1413 cff_builder_add_point( builder, x, y, 1 );
1420 x = ADD_LONG( x, args[0] );
1421 y = ADD_LONG( y, args[1] );
1422 cff_builder_add_point( builder, x, y, 1 );
1433 FT_TRACE4((
" hflex1\n" ));
1438 if ( cff_builder_start_point( builder, x, y ) ||
1439 cff_check_points( builder, 6 ) )
1446 x = ADD_LONG( x, args[0] );
1447 y = ADD_LONG( y, args[1] );
1448 cff_builder_add_point( builder, x, y, 0 );
1451 x = ADD_LONG( x, args[2] );
1452 y = ADD_LONG( y, args[3] );
1453 cff_builder_add_point( builder, x, y, 0 );
1457 x = ADD_LONG( x, args[4] );
1458 cff_builder_add_point( builder, x, y, 1 );
1462 x = ADD_LONG( x, args[5] );
1463 cff_builder_add_point( builder, x, y, 0 );
1466 x = ADD_LONG( x, args[6] );
1467 y = ADD_LONG( y, args[7] );
1468 cff_builder_add_point( builder, x, y, 0 );
1471 x = ADD_LONG( x, args[8] );
1473 cff_builder_add_point( builder, x, y, 1 );
1484 FT_TRACE4((
" hflex\n" ));
1487 if ( cff_builder_start_point( builder, x, y ) ||
1488 cff_check_points( builder, 6 ) )
1495 x = ADD_LONG( x, args[0] );
1496 cff_builder_add_point( builder, x, y, 0 );
1499 x = ADD_LONG( x, args[1] );
1500 y = ADD_LONG( y, args[2] );
1501 cff_builder_add_point( builder, x, y, 0 );
1505 x = ADD_LONG( x, args[3] );
1506 cff_builder_add_point( builder, x, y, 1 );
1510 x = ADD_LONG( x, args[4] );
1511 cff_builder_add_point( builder, x, y, 0 );
1514 x = ADD_LONG( x, args[5] );
1516 cff_builder_add_point( builder, x, y, 0 );
1520 x = ADD_LONG( x, args[6] );
1521 cff_builder_add_point( builder, x, y, 1 );
1529 FT_Pos start_x, start_y;
1531 FT_Fixed dx = 0, dy = 0;
1533 FT_Int horizontal, count;
1537 FT_TRACE4((
" flex1\n" ));
1540 if ( cff_builder_start_point( builder, x, y ) ||
1541 cff_check_points( builder, 6 ) )
1554 for ( count = 5; count > 0; count-- )
1556 dx = ADD_LONG( dx, temp[0] );
1557 dy = ADD_LONG( dy, temp[1] );
1562 dx = NEG_LONG( dx );
1564 dy = NEG_LONG( dy );
1567 horizontal = ( dx > dy );
1569 for ( count = 5; count > 0; count-- )
1571 x = ADD_LONG( x, args[0] );
1572 y = ADD_LONG( y, args[1] );
1573 cff_builder_add_point( builder, x, y,
1574 FT_BOOL( count == 3 ) );
1581 x = ADD_LONG( x, args[0] );
1587 y = ADD_LONG( y, args[0] );
1590 cff_builder_add_point( builder, x, y, 1 );
1601 FT_TRACE4((
" flex\n" ));
1603 if ( cff_builder_start_point( builder, x, y ) ||
1604 cff_check_points( builder, 6 ) )
1607 for ( count = 6; count > 0; count-- )
1609 x = ADD_LONG( x, args[0] );
1610 y = ADD_LONG( y, args[1] );
1611 cff_builder_add_point( builder, x, y,
1612 FT_BOOL( count == 4 || count == 1 ) );
1621 FT_TRACE4((
" seac\n" ));
1623 error = cff_operator_seac( decoder,
1624 args[0], args[1], args[2],
1625 (FT_Int)( args[3] >> 16 ),
1626 (FT_Int)( args[4] >> 16 ) );
1629 FT_GlyphLoader_Add( builder->loader );
1632 FT_TRACE4((
"\n" ));
1635 case cff_op_endchar:
1640 FT_TRACE4((
" endchar\n" ));
1643 if ( num_args >= 4 )
1646 FT_Pos glyph_width = decoder->glyph_width;
1649 error = cff_operator_seac( decoder,
1650 0L, args[-4], args[-3],
1651 (FT_Int)( args[-2] >> 16 ),
1652 (FT_Int)( args[-1] >> 16 ) );
1654 decoder->glyph_width = glyph_width;
1658 cff_builder_close_contour( builder );
1663 if ( hinter->close( hinter->hints,
1664 (FT_UInt)builder->current->n_points ) )
1668 error = hinter->apply( hinter->hints,
1670 (PSH_Globals)builder->hints_globals,
1671 decoder->hint_mode );
1677 FT_GlyphLoader_Add( builder->loader );
1681 FT_TRACE4((
"\n" ));
1685 FT_TRACE4((
" abs\n" ));
1689 if ( args[0] == FT_LONG_MIN )
1690 args[0] = FT_LONG_MAX;
1698 FT_TRACE4((
" add\n" ));
1700 args[0] = ADD_LONG( args[0], args[1] );
1705 FT_TRACE4((
" sub\n" ));
1707 args[0] = SUB_LONG( args[0], args[1] );
1712 FT_TRACE4((
" div\n" ));
1714 args[0] = FT_DivFix( args[0], args[1] );
1719 FT_TRACE4((
" neg\n" ));
1721 if ( args[0] == FT_LONG_MIN )
1722 args[0] = FT_LONG_MAX;
1729 FT_UInt32* randval = in_dict ? &decoder->cff->top_font.random
1730 : &decoder->current_subfont->random;
1733 FT_TRACE4((
" random\n" ));
1737 args[0] = (FT_Fixed)( ( *randval & 0xFFFF ) + 1 );
1740 *randval = cff_random( *randval );
1745 FT_TRACE4((
" mul\n" ));
1747 args[0] = FT_MulFix( args[0], args[1] );
1752 FT_TRACE4((
" sqrt\n" ));
1755 if ( args[0] > 0x7FFFFFFFL )
1756 args[0] = 0xB504F4L;
1757 else if ( args[0] > 0 )
1758 args[0] = (FT_Fixed)FT_SqrtFixed( args[0] );
1766 FT_TRACE4((
" drop\n" ));
1775 FT_TRACE4((
" exch\n" ));
1786 FT_Int idx = (FT_Int)( args[0] >> 16 );
1789 FT_TRACE4((
" index\n" ));
1793 else if ( idx > num_args - 2 )
1795 args[0] = args[-( idx + 1 )];
1802 FT_Int count = (FT_Int)( args[0] >> 16 );
1803 FT_Int idx = (FT_Int)( args[1] >> 16 );
1806 FT_TRACE4((
" roll\n" ));
1813 goto Stack_Underflow;
1820 FT_Fixed tmp = args[count - 1];
1824 for ( i = count - 2; i >= 0; i-- )
1825 args[i + 1] = args[i];
1835 idx = -( NEG_INT( idx ) % count );
1838 FT_Fixed tmp = args[0];
1842 for ( i = 0; i < count - 1; i++ )
1843 args[i] = args[i + 1];
1844 args[count - 1] = tmp;
1853 FT_TRACE4((
" dup\n" ));
1861 FT_Fixed val = args[0];
1862 FT_UInt idx = (FT_UInt)( args[1] >> 16 );
1865 FT_TRACE4((
" put\n" ));
1871 if ( idx < CFF_MAX_TRANS_ELEMENTS )
1872 decoder->buildchar[idx] = val;
1878 FT_UInt idx = (FT_UInt)( args[0] >> 16 );
1882 FT_TRACE4((
" get\n" ));
1884 if ( idx < CFF_MAX_TRANS_ELEMENTS )
1885 val = decoder->buildchar[idx];
1898 FT_TRACE4((
" store\n" ));
1905 FT_UInt reg_idx = (FT_UInt)args[0];
1906 FT_UInt idx = (FT_UInt)args[1];
1907 FT_UInt count = (FT_UInt)args[2];
1910 FT_TRACE4((
" load\n" ));
1915 if ( reg_idx <= 2 &&
1916 idx < CFF_MAX_TRANS_ELEMENTS &&
1922 end = FT_MIN( idx + count, CFF_MAX_TRANS_ELEMENTS );
1925 decoder->buildchar[idx] = 1 << 16;
1927 for ( i = idx + 1; i < end; i++ )
1928 decoder->buildchar[i] = 0;
1938 FT_Int num_results = (FT_Int)( args[0] >> 16 );
1941 FT_TRACE4((
" blend\n" ));
1943 if ( num_results < 0 )
1946 if ( num_results > num_args ||
1947 num_results * (FT_Int)num_designs > num_args )
1948 goto Stack_Underflow;
1953 args -= num_results * ( num_designs - 1 );
1954 num_args -= num_results * ( num_designs - 1 );
1960 case cff_op_dotsection:
1962 FT_TRACE4((
" dotsection\n" ));
1965 case cff_op_closepath:
1970 FT_TRACE4((
" closepath (invalid op)\n" ));
1980 FT_TRACE4((
" hsbw (invalid op)\n" ));
1982 decoder->glyph_width =
1983 ADD_LONG( decoder->nominal_width, ( args[1] >> 16 ) );
1985 decoder->builder.left_bearing.x = args[0];
1986 decoder->builder.left_bearing.y = 0;
1988 x = ADD_LONG( decoder->builder.pos_x, args[0] );
1989 y = decoder->builder.pos_y;
1998 FT_TRACE4((
" sbw (invalid op)\n" ));
2000 decoder->glyph_width =
2001 ADD_LONG( decoder->nominal_width, ( args[2] >> 16 ) );
2003 decoder->builder.left_bearing.x = args[0];
2004 decoder->builder.left_bearing.y = args[1];
2006 x = ADD_LONG( decoder->builder.pos_x, args[0] );
2007 y = ADD_LONG( decoder->builder.pos_y, args[1] );
2011 case cff_op_setcurrentpoint:
2016 FT_TRACE4((
" setcurrentpoint (invalid op)\n" ));
2018 x = ADD_LONG( decoder->builder.pos_x, args[0] );
2019 y = ADD_LONG( decoder->builder.pos_y, args[1] );
2023 case cff_op_callothersubr:
2033 FT_TRACE4((
" callothersubr (invalid op)\n" ));
2041 arg = 2 + ( args[-2] >> 16 );
2042 if ( arg >= CFF_MAX_OPERANDS )
2043 goto Stack_Underflow;
2047 goto Stack_Underflow;
2056 FT_TRACE4((
" pop (invalid op)\n" ));
2079 FT_Fixed cond = ( args[0] && args[1] );
2082 FT_TRACE4((
" and\n" ));
2084 args[0] = cond ? 0x10000L : 0;
2091 FT_Fixed cond = ( args[0] || args[1] );
2094 FT_TRACE4((
" or\n" ));
2096 args[0] = cond ? 0x10000L : 0;
2103 FT_Fixed cond = !args[0];
2106 FT_TRACE4((
" not\n" ));
2108 args[0] = cond ? 0x10000L : 0;
2115 FT_Fixed cond = ( args[0] == args[1] );
2118 FT_TRACE4((
" eq\n" ));
2120 args[0] = cond ? 0x10000L : 0;
2127 FT_Fixed cond = ( args[2] <= args[3] );
2130 FT_TRACE4((
" ifelse\n" ));
2138 case cff_op_callsubr:
2140 FT_UInt idx = (FT_UInt)( ( args[0] >> 16 ) +
2141 decoder->locals_bias );
2144 FT_TRACE4((
" callsubr (idx %u, entering level %td)\n",
2146 zone - decoder->zones + 1 ));
2148 if ( idx >= decoder->num_locals )
2150 FT_ERROR((
"cff_decoder_parse_charstrings:"
2151 " invalid local subr index\n" ));
2155 if ( zone - decoder->zones >= CFF_MAX_SUBRS_CALLS )
2157 FT_ERROR((
"cff_decoder_parse_charstrings:"
2158 " too many nested subrs\n" ));
2165 zone->base = decoder->locals[idx];
2166 zone->limit = decoder->locals[idx + 1];
2167 zone->cursor = zone->base;
2169 if ( !zone->base || zone->limit == zone->base )
2171 FT_ERROR((
"cff_decoder_parse_charstrings:"
2172 " invoking empty subrs\n" ));
2176 decoder->zone = zone;
2178 limit = zone->limit;
2182 case cff_op_callgsubr:
2184 FT_UInt idx = (FT_UInt)( ( args[0] >> 16 ) +
2185 decoder->globals_bias );
2188 FT_TRACE4((
" callgsubr (idx %u, entering level %td)\n",
2190 zone - decoder->zones + 1 ));
2192 if ( idx >= decoder->num_globals )
2194 FT_ERROR((
"cff_decoder_parse_charstrings:"
2195 " invalid global subr index\n" ));
2199 if ( zone - decoder->zones >= CFF_MAX_SUBRS_CALLS )
2201 FT_ERROR((
"cff_decoder_parse_charstrings:"
2202 " too many nested subrs\n" ));
2209 zone->base = decoder->globals[idx];
2210 zone->limit = decoder->globals[idx + 1];
2211 zone->cursor = zone->base;
2213 if ( !zone->base || zone->limit == zone->base )
2215 FT_ERROR((
"cff_decoder_parse_charstrings:"
2216 " invoking empty subrs\n" ));
2220 decoder->zone = zone;
2222 limit = zone->limit;
2227 FT_TRACE4((
" return (leaving level %td)\n",
2228 decoder->zone - decoder->zones ));
2230 if ( decoder->zone <= decoder->zones )
2232 FT_ERROR((
"cff_decoder_parse_charstrings:"
2233 " unexpected return\n" ));
2238 zone = decoder->zone;
2240 limit = zone->limit;
2244 FT_ERROR((
"Unimplemented opcode: %d", ip[-1] ));
2247 FT_ERROR((
" %d", ip[0] ));
2250 return FT_THROW( Unimplemented_Feature );
2253 decoder->top = args;
2255 if ( decoder->top - stack >= CFF_MAX_OPERANDS )
2256 goto Stack_Overflow;
2262 FT_TRACE4((
"..end..\n" ));
2263 FT_TRACE4((
"\n" ));
2269 FT_TRACE4((
"cff_decoder_parse_charstrings:"
2270 " invalid opcode found in top DICT charstring\n"));
2271 return FT_THROW( Invalid_File_Format );
2274 FT_TRACE4((
"cff_decoder_parse_charstrings: syntax error\n" ));
2275 return FT_THROW( Invalid_File_Format );
2278 FT_TRACE4((
"cff_decoder_parse_charstrings: stack underflow\n" ));
2279 return FT_THROW( Too_Few_Arguments );
2282 FT_TRACE4((
"cff_decoder_parse_charstrings: stack overflow\n" ));
2283 return FT_THROW( Stack_Overflow );
2317 FT_LOCAL_DEF(
void )
2318 cff_decoder_init( CFF_Decoder* decoder,
2323 FT_Render_Mode hint_mode,
2324 CFF_Decoder_Get_Glyph_Callback get_callback,
2325 CFF_Decoder_Free_Glyph_Callback free_callback )
2327 CFF_Font cff = (CFF_Font)face->extra.data;
2334 cff_builder_init( &decoder->builder, face, size, slot, hinting );
2338 decoder->num_globals = cff->global_subrs_index.count;
2339 decoder->globals = cff->global_subrs;
2340 decoder->globals_bias = cff_compute_bias(
2341 cff->top_font.font_dict.charstring_type,
2342 decoder->num_globals );
2344 decoder->hint_mode = hint_mode;
2346 decoder->get_glyph_callback = get_callback;
2347 decoder->free_glyph_callback = free_callback;
2353 FT_LOCAL_DEF( FT_Error )
2354 cff_decoder_prepare( CFF_Decoder* decoder,
2356 FT_UInt glyph_index )
2358 CFF_Builder *builder = &decoder->builder;
2359 CFF_Font cff = (CFF_Font)builder->face->extra.data;
2360 CFF_SubFont sub = &cff->top_font;
2361 FT_Error error = FT_Err_Ok;
2363 FT_Service_CFFLoad cffload = (FT_Service_CFFLoad)cff->cffload;
2367 if ( cff->num_subfonts )
2369 FT_Byte fd_index = cffload->fd_select_get( &cff->fd_select,
2373 if ( fd_index >= cff->num_subfonts )
2375 FT_TRACE4((
"cff_decoder_prepare: invalid CID subfont index\n" ));
2376 error = FT_THROW( Invalid_File_Format );
2380 FT_TRACE3((
" in subfont %d:\n", fd_index ));
2382 sub = cff->subfonts[fd_index];
2384 if ( builder->hints_funcs && size )
2386 FT_Size ftsize = FT_SIZE( size );
2387 CFF_Internal internal = (CFF_Internal)ftsize->internal->module_data;
2391 builder->hints_globals = (
void *)internal->subfonts[fd_index];
2395 decoder->num_locals = sub->local_subrs_index.count;
2396 decoder->locals = sub->local_subrs;
2397 decoder->locals_bias = cff_compute_bias(
2398 decoder->cff->top_font.font_dict.charstring_type,
2399 decoder->num_locals );
2401 decoder->glyph_width = sub->private_dict.default_width;
2402 decoder->nominal_width = sub->private_dict.nominal_width;
2404 decoder->current_subfont = sub;