39#define FT_COMPONENT psobjs
73 FT_LOCAL_DEF( FT_Error )
74 ps_table_new( PS_Table table,
81 table->memory = memory;
82 if ( FT_NEW_ARRAY( table->elements, count ) ||
83 FT_NEW_ARRAY( table->lengths, count ) )
86 table->max_elems = count;
87 table->init = 0xDEADBEEFUL;
92 *(PS_Table_FuncsRec*)&table->funcs = ps_table_funcs;
96 FT_FREE( table->elements );
103 ps_table_realloc( PS_Table table,
106 FT_Memory memory = table->memory;
107 FT_Byte* old_base = table->block;
112 if ( FT_REALLOC( table->block, table->capacity, new_size ) )
116 if ( old_base && table->block != old_base )
118 FT_Byte** offset = table->elements;
119 FT_Byte** limit = offset + table->max_elems;
122 for ( ; offset < limit; offset++ )
125 *offset = table->block + ( *offset - old_base );
129 table->capacity = new_size;
161 FT_LOCAL_DEF( FT_Error )
162 ps_table_add( PS_Table table,
167 if ( idx < 0 || idx >= table->max_elems )
169 FT_ERROR((
"ps_table_add: invalid index\n" ));
170 return FT_THROW( Invalid_Argument );
174 if ( table->cursor + length > table->capacity )
177 FT_Offset new_size = table->capacity;
178 FT_PtrDist in_offset;
181 in_offset = (FT_Byte*)
object - table->block;
182 if ( in_offset < 0 || (FT_Offset)in_offset >= table->capacity )
185 while ( new_size < table->cursor + length )
189 new_size += ( new_size >> 2 ) + 1;
190 new_size = FT_PAD_CEIL( new_size, 1024 );
193 error = ps_table_realloc( table, new_size );
197 if ( in_offset >= 0 )
198 object = table->block + in_offset;
202 table->elements[idx] = FT_OFFSET( table->block, table->cursor );
203 table->lengths [idx] = length;
206 FT_MEM_COPY( table->block + table->cursor,
object, length );
208 table->cursor += length;
227 ps_table_done( PS_Table table )
230 ps_table_realloc( table, table->cursor );
235 ps_table_release( PS_Table table )
237 FT_Memory memory = table->memory;
240 if ( table->init == 0xDEADBEEFUL )
242 FT_FREE( table->block );
243 FT_FREE( table->elements );
244 FT_FREE( table->lengths );
262 skip_comment( FT_Byte* *acur,
265 FT_Byte* cur = *acur;
268 while ( cur < limit )
270 if ( IS_PS_NEWLINE( *cur ) )
280 skip_spaces( FT_Byte* *acur,
283 FT_Byte* cur = *acur;
286 while ( cur < limit )
288 if ( !IS_PS_SPACE( *cur ) )
292 skip_comment( &cur, limit );
303#define IS_OCTAL_DIGIT( c ) ( '0' <= (c) && (c) <= '7' )
310 skip_literal_string( FT_Byte* *acur,
313 FT_Byte* cur = *acur;
315 FT_Error error = FT_ERR( Invalid_File_Format );
319 while ( cur < limit )
355 for ( i = 0; i < 3 && cur < limit; i++ )
357 if ( !IS_OCTAL_DIGIT( *cur ) )
386 skip_string( FT_Byte* *acur,
389 FT_Byte* cur = *acur;
390 FT_Error err = FT_Err_Ok;
393 while ( ++cur < limit )
396 skip_spaces( &cur, limit );
400 if ( !IS_PS_XDIGIT( *cur ) )
404 if ( cur < limit && *cur !=
'>' )
406 FT_ERROR((
"skip_string: missing closing delimiter `>'\n" ));
407 err = FT_THROW( Invalid_File_Format );
425 skip_procedure( FT_Byte* *acur,
430 FT_Error error = FT_Err_Ok;
433 FT_ASSERT( **acur ==
'{' );
435 for ( cur = *acur; cur < limit && error == FT_Err_Ok; cur++ )
453 error = skip_literal_string( &cur, limit );
457 error = skip_string( &cur, limit );
461 skip_comment( &cur, limit );
471 error = FT_THROW( Invalid_File_Format );
488 ps_parser_skip_PS_token( PS_Parser parser )
494 FT_Byte* cur = parser->cursor;
495 FT_Byte* limit = parser->limit;
496 FT_Error error = FT_Err_Ok;
499 skip_spaces( &cur, limit );
504 if ( *cur ==
'[' || *cur ==
']' )
514 error = skip_procedure( &cur, limit );
520 error = skip_literal_string( &cur, limit );
526 if ( cur + 1 < limit && *( cur + 1 ) ==
'<' )
532 error = skip_string( &cur, limit );
540 if ( cur >= limit || *cur !=
'>' )
542 FT_ERROR((
"ps_parser_skip_PS_token:"
543 " unexpected closing delimiter `>'\n" ));
544 error = FT_THROW( Invalid_File_Format );
555 while ( cur < limit )
559 if ( IS_PS_DELIM( *cur ) )
566 if ( cur < limit && cur == parser->cursor )
568 FT_ERROR((
"ps_parser_skip_PS_token:"
569 " current token is `%c' which is self-delimiting\n",
572 " but invalid at this point\n" ));
574 error = FT_THROW( Invalid_File_Format );
580 parser->error = error;
581 parser->cursor = cur;
586 ps_parser_skip_spaces( PS_Parser parser )
588 skip_spaces( &parser->cursor, parser->limit );
596 ps_parser_to_token( PS_Parser parser,
604 token->type = T1_TOKEN_TYPE_NONE;
609 ps_parser_skip_spaces( parser );
611 cur = parser->cursor;
612 limit = parser->limit;
621 token->type = T1_TOKEN_TYPE_STRING;
624 if ( skip_literal_string( &cur, limit ) == FT_Err_Ok )
630 token->type = T1_TOKEN_TYPE_ARRAY;
633 if ( skip_procedure( &cur, limit ) == FT_Err_Ok )
642 token->type = T1_TOKEN_TYPE_ARRAY;
644 token->start = cur++;
647 parser->cursor = cur;
648 ps_parser_skip_spaces( parser );
649 cur = parser->cursor;
651 while ( cur < limit && !parser->error )
657 else if ( *cur ==
']' )
662 token->limit = ++cur;
667 parser->cursor = cur;
668 ps_parser_skip_PS_token( parser );
670 ps_parser_skip_spaces ( parser );
671 cur = parser->cursor;
678 token->type = ( *cur ==
'/' ) ? T1_TOKEN_TYPE_KEY : T1_TOKEN_TYPE_ANY;
679 ps_parser_skip_PS_token( parser );
680 cur = parser->cursor;
681 if ( !parser->error )
688 token->type = T1_TOKEN_TYPE_NONE;
691 parser->cursor = cur;
699 ps_parser_to_token_array( PS_Parser parser,
702 FT_Int* pnum_tokens )
710 ps_parser_to_token( parser, &master );
712 if ( master.type == T1_TOKEN_TYPE_ARRAY )
714 FT_Byte* old_cursor = parser->cursor;
715 FT_Byte* old_limit = parser->limit;
716 T1_Token cur = tokens;
717 T1_Token limit = cur + max_tokens;
721 parser->cursor = master.start + 1;
722 parser->limit = master.limit - 1;
724 while ( parser->cursor < parser->limit )
729 ps_parser_to_token( parser, &token );
733 if ( tokens && cur < limit )
739 *pnum_tokens = (FT_Int)( cur - tokens );
741 parser->cursor = old_cursor;
742 parser->limit = old_limit;
752 ps_tocoordarray( FT_Byte* *acur,
757 FT_Byte* cur = *acur;
779 while ( cur < limit )
786 skip_spaces( &cur, limit );
798 if ( coords && count >= max_coords )
803 *( coords ? &coords[count] : &dummy ) =
804 (FT_Short)( PS_Conv_ToFixed( &cur, limit, 0 ) >> 16 );
806 if ( old_cur == cur )
831 ps_tofixedarray( FT_Byte* *acur,
837 FT_Byte* cur = *acur;
859 while ( cur < limit )
866 skip_spaces( &cur, limit );
878 if ( values && count >= max_values )
883 *( values ? &values[count] : &dummy ) =
884 PS_Conv_ToFixed( &cur, limit, power_ten );
886 if ( old_cur == cur )
907 ps_tostring( FT_Byte** cursor,
911 FT_Byte* cur = *cursor;
927 while ( cur < limit && ( *cur ==
' ' || *cur ==
'\t' ) )
929 if ( cur + 1 >= limit )
939 for ( ; cur < limit; cur++ )
944 else if ( *cur ==
')' )
952 len = (FT_UInt)( cur - *cursor );
953 if ( cur >= limit || FT_QALLOC( result, len + 1 ) )
957 FT_MEM_COPY( result, *cursor, len );
967 ps_tobool( FT_Byte* *acur,
970 FT_Byte* cur = *acur;
975 if ( cur + 3 < limit &&
984 else if ( cur + 4 < limit &&
1002 FT_LOCAL_DEF( FT_Error )
1003 ps_parser_load_field( PS_Parser parser,
1004 const T1_Field field,
1006 FT_UInt max_objects,
1019 ps_parser_to_token( parser, &token );
1026 limit = token.limit;
1031 if ( type == T1_FIELD_TYPE_BBOX )
1034 FT_Byte* old_cur = parser->cursor;
1035 FT_Byte* old_limit = parser->limit;
1039 parser->cursor = token.start + 1;
1040 parser->limit = token.limit - 1;
1042 ps_parser_to_token( parser, &token2 );
1043 parser->cursor = old_cur;
1044 parser->limit = old_limit;
1046 if ( token2.type == T1_TOKEN_TYPE_ARRAY )
1048 type = T1_FIELD_TYPE_MM_BBOX;
1052 else if ( token.type == T1_TOKEN_TYPE_ARRAY )
1054 count = max_objects;
1058 if ( max_objects == 0 )
1068 for ( ; count > 0; count--, idx++ )
1070 FT_Byte* q = (FT_Byte*)objects[idx] + field->offset;
1074 skip_spaces( &cur, limit );
1078 case T1_FIELD_TYPE_BOOL:
1079 val = ps_tobool( &cur, limit );
1080 FT_TRACE4((
" %s", val ?
"true" :
"false" ));
1083 case T1_FIELD_TYPE_FIXED:
1084 val = PS_Conv_ToFixed( &cur, limit, 0 );
1085 FT_TRACE4((
" %f", (
double)val / 65536 ));
1088 case T1_FIELD_TYPE_FIXED_1000:
1089 val = PS_Conv_ToFixed( &cur, limit, 3 );
1090 FT_TRACE4((
" %f", (
double)val / 65536 / 1000 ));
1093 case T1_FIELD_TYPE_INTEGER:
1094 val = PS_Conv_ToInt( &cur, limit );
1095 FT_TRACE4((
" %ld", val ));
1099 switch ( field->size )
1101 case (8 / FT_CHAR_BIT):
1102 *(FT_Byte*)q = (FT_Byte)val;
1105 case (16 / FT_CHAR_BIT):
1106 *(FT_UShort*)q = (FT_UShort)val;
1109 case (32 / FT_CHAR_BIT):
1110 *(FT_UInt32*)q = (FT_UInt32)val;
1118 case T1_FIELD_TYPE_STRING:
1119 case T1_FIELD_TYPE_KEY:
1121 FT_Memory memory = parser->memory;
1122 FT_UInt len = (FT_UInt)( limit - cur );
1123 FT_String*
string = NULL;
1131 if ( token.type == T1_TOKEN_TYPE_KEY )
1137 else if ( token.type == T1_TOKEN_TYPE_STRING )
1148 FT_ERROR((
"ps_parser_load_field:"
1149 " expected a name or string\n" ));
1151 " but found token of type %u instead\n",
1153 error = FT_THROW( Invalid_File_Format );
1159 if ( *(FT_String**)q )
1161 FT_TRACE0((
"ps_parser_load_field: overwriting field %s\n",
1163 FT_FREE( *(FT_String**)q );
1166 if ( FT_QALLOC(
string, len + 1 ) )
1169 FT_MEM_COPY(
string, cur, len );
1172#ifdef FT_DEBUG_LEVEL_TRACE
1173 if ( token.type == T1_TOKEN_TYPE_STRING )
1174 FT_TRACE4((
" (%s)",
string ));
1176 FT_TRACE4((
" /%s",
string ));
1179 *(FT_String**)q =
string;
1183 case T1_FIELD_TYPE_BBOX:
1186 FT_BBox* bbox = (FT_BBox*)q;
1190 result = ps_tofixedarray( &cur, limit, 4, temp, 0 );
1194 FT_ERROR((
"ps_parser_load_field:"
1195 " expected four integers in bounding box\n" ));
1196 error = FT_THROW( Invalid_File_Format );
1200 bbox->xMin = FT_RoundFix( temp[0] );
1201 bbox->yMin = FT_RoundFix( temp[1] );
1202 bbox->xMax = FT_RoundFix( temp[2] );
1203 bbox->yMax = FT_RoundFix( temp[3] );
1205 FT_TRACE4((
" [%ld %ld %ld %ld]",
1209 bbox->yMax / 65536 ));
1213 case T1_FIELD_TYPE_MM_BBOX:
1215 FT_Memory memory = parser->memory;
1216 FT_Fixed* temp = NULL;
1221 if ( FT_QNEW_ARRAY( temp, max_objects * 4 ) )
1224 for ( i = 0; i < 4; i++ )
1226 result = ps_tofixedarray( &cur, limit, (FT_Int)max_objects,
1227 temp + i * max_objects, 0 );
1228 if ( result < 0 || (FT_UInt)result < max_objects )
1230 FT_ERROR((
"ps_parser_load_field:"
1231 " expected %u integer%s in the %s subarray\n",
1232 max_objects, max_objects > 1 ?
"s" :
"",
1234 : ( i == 1 ?
"second"
1235 : ( i == 2 ?
"third"
1238 " of /FontBBox in the /Blend dictionary\n" ));
1239 error = FT_THROW( Invalid_File_Format );
1245 skip_spaces( &cur, limit );
1248 FT_TRACE4((
" [" ));
1249 for ( i = 0; i < max_objects; i++ )
1251 FT_BBox* bbox = (FT_BBox*)objects[i];
1254 bbox->xMin = FT_RoundFix( temp[i ] );
1255 bbox->yMin = FT_RoundFix( temp[i + max_objects] );
1256 bbox->xMax = FT_RoundFix( temp[i + 2 * max_objects] );
1257 bbox->yMax = FT_RoundFix( temp[i + 3 * max_objects] );
1259 FT_TRACE4((
" [%ld %ld %ld %ld]",
1263 bbox->yMax / 65536 ));
1279 *pflags |= 1L << field->flag_bit;
1281 FT_UNUSED( pflags );
1290 error = FT_THROW( Invalid_File_Format );
1295#define T1_MAX_TABLE_ELEMENTS 32
1298 FT_LOCAL_DEF( FT_Error )
1299 ps_parser_load_field_table( PS_Parser parser,
1300 const T1_Field field,
1302 FT_UInt max_objects,
1305 T1_TokenRec elements[T1_MAX_TABLE_ELEMENTS];
1307 FT_Int num_elements;
1308 FT_Error error = FT_Err_Ok;
1309 FT_Byte* old_cursor;
1311 T1_FieldRec fieldrec = *(T1_Field)field;
1314 fieldrec.type = T1_FIELD_TYPE_INTEGER;
1315 if ( field->type == T1_FIELD_TYPE_FIXED_ARRAY ||
1316 field->type == T1_FIELD_TYPE_BBOX )
1317 fieldrec.type = T1_FIELD_TYPE_FIXED;
1319 ps_parser_to_token_array( parser, elements,
1320 T1_MAX_TABLE_ELEMENTS, &num_elements );
1321 if ( num_elements < 0 )
1323 error = FT_ERR( Ignore );
1326 if ( (FT_UInt)num_elements > field->array_max )
1327 num_elements = (FT_Int)field->array_max;
1329 old_cursor = parser->cursor;
1330 old_limit = parser->limit;
1334 if ( field->type != T1_FIELD_TYPE_BBOX && field->count_offset != 0 )
1335 *(FT_Byte*)( (FT_Byte*)objects[0] + field->count_offset ) =
1336 (FT_Byte)num_elements;
1338 FT_TRACE4((
" [" ));
1342 for ( ; num_elements > 0; num_elements--, token++ )
1344 parser->cursor = token->start;
1345 parser->limit = token->limit;
1347 error = ps_parser_load_field( parser,
1355 fieldrec.offset += fieldrec.size;
1362 *pflags |= 1L << field->flag_bit;
1364 FT_UNUSED( pflags );
1367 parser->cursor = old_cursor;
1368 parser->limit = old_limit;
1375 FT_LOCAL_DEF( FT_Long )
1376 ps_parser_to_int( PS_Parser parser )
1378 ps_parser_skip_spaces( parser );
1379 return PS_Conv_ToInt( &parser->cursor, parser->limit );
1385 FT_LOCAL_DEF( FT_Error )
1386 ps_parser_to_bytes( PS_Parser parser,
1388 FT_Offset max_bytes,
1389 FT_ULong* pnum_bytes,
1390 FT_Bool delimiters )
1392 FT_Error error = FT_Err_Ok;
1396 ps_parser_skip_spaces( parser );
1397 cur = parser->cursor;
1399 if ( cur >= parser->limit )
1406 FT_ERROR((
"ps_parser_to_bytes: Missing starting delimiter `<'\n" ));
1407 error = FT_THROW( Invalid_File_Format );
1414 *pnum_bytes = PS_Conv_ASCIIHexDecode( &cur,
1419 parser->cursor = cur;
1423 if ( cur < parser->limit && *cur !=
'>' )
1425 FT_ERROR((
"ps_parser_to_bytes: Missing closing delimiter `>'\n" ));
1426 error = FT_THROW( Invalid_File_Format );
1438 FT_LOCAL_DEF( FT_Fixed )
1439 ps_parser_to_fixed( PS_Parser parser,
1442 ps_parser_skip_spaces( parser );
1443 return PS_Conv_ToFixed( &parser->cursor, parser->limit, power_ten );
1447 FT_LOCAL_DEF( FT_Int )
1448 ps_parser_to_coord_array( PS_Parser parser,
1452 ps_parser_skip_spaces( parser );
1453 return ps_tocoordarray( &parser->cursor, parser->limit,
1454 max_coords, coords );
1458 FT_LOCAL_DEF( FT_Int )
1459 ps_parser_to_fixed_array( PS_Parser parser,
1464 ps_parser_skip_spaces( parser );
1465 return ps_tofixedarray( &parser->cursor, parser->limit,
1466 max_values, values, power_ten );
1472 FT_LOCAL_DEF( FT_String* )
1473 T1_ToString( PS_Parser parser )
1475 return ps_tostring( &parser->cursor, parser->limit, parser->memory );
1479 FT_LOCAL_DEF( FT_Bool )
1480 T1_ToBool( PS_Parser parser )
1482 return ps_tobool( &parser->cursor, parser->limit );
1488 FT_LOCAL_DEF(
void )
1489 ps_parser_init( PS_Parser parser,
1494 parser->error = FT_Err_Ok;
1495 parser->base = base;
1496 parser->limit = limit;
1497 parser->cursor = base;
1498 parser->memory = memory;
1499 parser->funcs = ps_parser_funcs;
1503 FT_LOCAL_DEF(
void )
1504 ps_parser_done( PS_Parser parser )
1506 FT_UNUSED( parser );
1543 FT_LOCAL_DEF(
void )
1544 t1_builder_init( T1_Builder builder,
1550 builder->parse_state = T1_Parse_Start;
1551 builder->load_points = 1;
1553 builder->face = face;
1554 builder->glyph = glyph;
1555 builder->memory = face->memory;
1559 FT_GlyphLoader loader = glyph->internal->loader;
1562 builder->loader = loader;
1563 builder->base = &loader->base.outline;
1564 builder->current = &loader->current.outline;
1565 FT_GlyphLoader_Rewind( loader );
1567 builder->hints_globals = size->internal->module_data;
1568 builder->hints_funcs = NULL;
1571 builder->hints_funcs = glyph->internal->glyph_hints;
1577 builder->left_bearing.x = 0;
1578 builder->left_bearing.y = 0;
1579 builder->advance.x = 0;
1580 builder->advance.y = 0;
1582 builder->funcs = t1_builder_funcs;
1600 FT_LOCAL_DEF(
void )
1601 t1_builder_done( T1_Builder builder )
1603 FT_GlyphSlot glyph = builder->glyph;
1607 glyph->outline = *builder->base;
1612 FT_LOCAL_DEF( FT_Error )
1613 t1_builder_check_points( T1_Builder builder,
1616 return FT_GLYPHLOADER_CHECK_POINTS( builder->loader, count, 0 );
1621 FT_LOCAL_DEF(
void )
1622 t1_builder_add_point( T1_Builder builder,
1627 FT_Outline* outline = builder->current;
1630 if ( builder->load_points )
1632 FT_Vector* point = outline->points + outline->n_points;
1633 FT_Byte* control = outline->tags + outline->n_points;
1636 point->x = FIXED_TO_INT( x );
1637 point->y = FIXED_TO_INT( y );
1638 *control = (FT_Byte)( flag ? FT_CURVE_TAG_ON : FT_CURVE_TAG_CUBIC );
1640 outline->n_points++;
1645 FT_LOCAL_DEF( FT_Error )
1646 t1_builder_add_point1( T1_Builder builder,
1653 error = t1_builder_check_points( builder, 1 );
1655 t1_builder_add_point( builder, x, y, 1 );
1662 FT_LOCAL_DEF( FT_Error )
1663 t1_builder_add_contour( T1_Builder builder )
1665 FT_Outline* outline = builder->current;
1672 FT_ERROR((
"t1_builder_add_contour: no outline to add points to\n" ));
1673 return FT_THROW( Invalid_File_Format );
1676 if ( !builder->load_points )
1678 outline->n_contours++;
1682 error = FT_GLYPHLOADER_CHECK_POINTS( builder->loader, 0, 1 );
1685 if ( outline->n_contours > 0 )
1686 outline->contours[outline->n_contours - 1] = outline->n_points - 1;
1688 outline->n_contours++;
1696 FT_LOCAL_DEF( FT_Error )
1697 t1_builder_start_point( T1_Builder builder,
1701 FT_Error error = FT_ERR( Invalid_File_Format );
1706 if ( builder->parse_state == T1_Parse_Have_Path )
1710 builder->parse_state = T1_Parse_Have_Path;
1711 error = t1_builder_add_contour( builder );
1713 error = t1_builder_add_point1( builder, x, y );
1721 FT_LOCAL_DEF(
void )
1722 t1_builder_close_contour( T1_Builder builder )
1724 FT_Outline* outline = builder->current;
1731 first = outline->n_contours <= 1
1732 ? 0 : outline->contours[outline->n_contours - 2] + 1;
1736 if ( outline->n_contours && first == outline->n_points )
1738 outline->n_contours--;
1744 if ( outline->n_points > 1 )
1746 FT_Vector* p1 = outline->points + first;
1747 FT_Vector* p2 = outline->points + outline->n_points - 1;
1748 FT_Byte* control = outline->tags + outline->n_points - 1;
1753 if ( p1->x == p2->x && p1->y == p2->y )
1754 if ( *control == FT_CURVE_TAG_ON )
1755 outline->n_points--;
1758 if ( outline->n_contours > 0 )
1762 if ( first == outline->n_points - 1 )
1764 outline->n_contours--;
1765 outline->n_points--;
1768 outline->contours[outline->n_contours - 1] = outline->n_points - 1;
1807 FT_LOCAL_DEF(
void )
1808 cff_builder_init( CFF_Builder* builder,
1811 CFF_GlyphSlot glyph,
1814 builder->path_begun = 0;
1815 builder->load_points = 1;
1817 builder->face = face;
1818 builder->glyph = glyph;
1819 builder->memory = face->root.memory;
1823 FT_GlyphLoader loader = glyph->root.internal->loader;
1826 builder->loader = loader;
1827 builder->base = &loader->base.outline;
1828 builder->current = &loader->current.outline;
1829 FT_GlyphLoader_Rewind( loader );
1831 builder->hints_globals = NULL;
1832 builder->hints_funcs = NULL;
1834 if ( hinting && size )
1836 FT_Size ftsize = FT_SIZE( size );
1837 CFF_Internal internal = (CFF_Internal)ftsize->internal->module_data;
1841 builder->hints_globals = (
void *)internal->topfont;
1842 builder->hints_funcs = glyph->root.internal->glyph_hints;
1850 builder->left_bearing.x = 0;
1851 builder->left_bearing.y = 0;
1852 builder->advance.x = 0;
1853 builder->advance.y = 0;
1855 builder->funcs = cff_builder_funcs;
1873 FT_LOCAL_DEF(
void )
1874 cff_builder_done( CFF_Builder* builder )
1876 CFF_GlyphSlot glyph = builder->glyph;
1880 glyph->root.outline = *builder->base;
1885 FT_LOCAL_DEF( FT_Error )
1886 cff_check_points( CFF_Builder* builder,
1889 return FT_GLYPHLOADER_CHECK_POINTS( builder->loader, count, 0 );
1894 FT_LOCAL_DEF(
void )
1895 cff_builder_add_point( CFF_Builder* builder,
1900 FT_Outline* outline = builder->current;
1903 if ( builder->load_points )
1905 FT_Vector* point = outline->points + outline->n_points;
1906 FT_Byte* control = outline->tags + outline->n_points;
1908#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
1909 PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( builder->face );
1912 if ( driver->hinting_engine == FT_HINTING_FREETYPE )
1924 *control = (FT_Byte)( flag ? FT_CURVE_TAG_ON : FT_CURVE_TAG_CUBIC );
1927 outline->n_points++;
1932 FT_LOCAL_DEF( FT_Error )
1933 cff_builder_add_point1( CFF_Builder* builder,
1940 error = cff_check_points( builder, 1 );
1942 cff_builder_add_point( builder, x, y, 1 );
1949 FT_LOCAL_DEF( FT_Error )
1950 cff_builder_add_contour( CFF_Builder* builder )
1952 FT_Outline* outline = builder->current;
1956 if ( !builder->load_points )
1958 outline->n_contours++;
1962 error = FT_GLYPHLOADER_CHECK_POINTS( builder->loader, 0, 1 );
1965 if ( outline->n_contours > 0 )
1966 outline->contours[outline->n_contours - 1] = outline->n_points - 1;
1968 outline->n_contours++;
1976 FT_LOCAL_DEF( FT_Error )
1977 cff_builder_start_point( CFF_Builder* builder,
1981 FT_Error error = FT_Err_Ok;
1985 if ( !builder->path_begun )
1987 builder->path_begun = 1;
1988 error = cff_builder_add_contour( builder );
1990 error = cff_builder_add_point1( builder, x, y );
1998 FT_LOCAL_DEF(
void )
1999 cff_builder_close_contour( CFF_Builder* builder )
2001 FT_Outline* outline = builder->current;
2008 first = outline->n_contours <= 1
2009 ? 0 : outline->contours[outline->n_contours - 2] + 1;
2013 if ( outline->n_contours && first == outline->n_points )
2015 outline->n_contours--;
2021 if ( outline->n_points > 1 )
2023 FT_Vector* p1 = outline->points + first;
2024 FT_Vector* p2 = outline->points + outline->n_points - 1;
2025 FT_Byte* control = outline->tags + outline->n_points - 1;
2030 if ( p1->x == p2->x && p1->y == p2->y )
2031 if ( *control == FT_CURVE_TAG_ON )
2032 outline->n_points--;
2035 if ( outline->n_contours > 0 )
2039 if ( first == outline->n_points - 1 )
2041 outline->n_contours--;
2042 outline->n_points--;
2045 outline->contours[outline->n_contours - 1] = outline->n_points - 1;
2083 FT_LOCAL_DEF(
void )
2084 ps_builder_init( PS_Builder* ps_builder,
2088 FT_ZERO( ps_builder );
2092 T1_Builder t1builder = (T1_Builder)builder;
2095 ps_builder->memory = t1builder->memory;
2096 ps_builder->face = (FT_Face)t1builder->face;
2097 ps_builder->glyph = (CFF_GlyphSlot)t1builder->glyph;
2098 ps_builder->loader = t1builder->loader;
2099 ps_builder->base = t1builder->base;
2100 ps_builder->current = t1builder->current;
2102 ps_builder->pos_x = &t1builder->pos_x;
2103 ps_builder->pos_y = &t1builder->pos_y;
2105 ps_builder->left_bearing = &t1builder->left_bearing;
2106 ps_builder->advance = &t1builder->advance;
2108 ps_builder->bbox = &t1builder->bbox;
2109 ps_builder->path_begun = 0;
2110 ps_builder->load_points = t1builder->load_points;
2111 ps_builder->no_recurse = t1builder->no_recurse;
2113 ps_builder->metrics_only = t1builder->metrics_only;
2117 CFF_Builder* cffbuilder = (CFF_Builder*)builder;
2120 ps_builder->memory = cffbuilder->memory;
2121 ps_builder->face = (FT_Face)cffbuilder->face;
2122 ps_builder->glyph = cffbuilder->glyph;
2123 ps_builder->loader = cffbuilder->loader;
2124 ps_builder->base = cffbuilder->base;
2125 ps_builder->current = cffbuilder->current;
2127 ps_builder->pos_x = &cffbuilder->pos_x;
2128 ps_builder->pos_y = &cffbuilder->pos_y;
2130 ps_builder->left_bearing = &cffbuilder->left_bearing;
2131 ps_builder->advance = &cffbuilder->advance;
2133 ps_builder->bbox = &cffbuilder->bbox;
2134 ps_builder->path_begun = cffbuilder->path_begun;
2135 ps_builder->load_points = cffbuilder->load_points;
2136 ps_builder->no_recurse = cffbuilder->no_recurse;
2138 ps_builder->metrics_only = cffbuilder->metrics_only;
2141 ps_builder->is_t1 = is_t1;
2142 ps_builder->funcs = ps_builder_funcs;
2160 FT_LOCAL_DEF(
void )
2161 ps_builder_done( PS_Builder* builder )
2163 CFF_GlyphSlot glyph = builder->glyph;
2167 glyph->root.outline = *builder->base;
2172 FT_LOCAL_DEF( FT_Error )
2173 ps_builder_check_points( PS_Builder* builder,
2176 return FT_GLYPHLOADER_CHECK_POINTS( builder->loader, count, 0 );
2181 FT_LOCAL_DEF(
void )
2182 ps_builder_add_point( PS_Builder* builder,
2187 FT_Outline* outline = builder->current;
2190 if ( builder->load_points )
2192 FT_Vector* point = outline->points + outline->n_points;
2193 FT_Byte* control = outline->tags + outline->n_points;
2195#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
2196 PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( builder->face );
2199 if ( !builder->is_t1 &&
2200 driver->hinting_engine == FT_HINTING_FREETYPE )
2207#ifdef T1_CONFIG_OPTION_OLD_ENGINE
2208#ifndef CFF_CONFIG_OPTION_OLD_ENGINE
2209 PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( builder->face );
2211 if ( builder->is_t1 &&
2212 driver->hinting_engine == FT_HINTING_FREETYPE )
2214 point->x = FIXED_TO_INT( x );
2215 point->y = FIXED_TO_INT( y );
2224 *control = (FT_Byte)( flag ? FT_CURVE_TAG_ON : FT_CURVE_TAG_CUBIC );
2226 outline->n_points++;
2231 FT_LOCAL_DEF( FT_Error )
2232 ps_builder_add_point1( PS_Builder* builder,
2239 error = ps_builder_check_points( builder, 1 );
2241 ps_builder_add_point( builder, x, y, 1 );
2248 FT_LOCAL_DEF( FT_Error )
2249 ps_builder_add_contour( PS_Builder* builder )
2251 FT_Outline* outline = builder->current;
2258 FT_ERROR((
"ps_builder_add_contour: no outline to add points to\n" ));
2259 return FT_THROW( Invalid_File_Format );
2262 if ( !builder->load_points )
2264 outline->n_contours++;
2268 error = FT_GLYPHLOADER_CHECK_POINTS( builder->loader, 0, 1 );
2271 if ( outline->n_contours > 0 )
2272 outline->contours[outline->n_contours - 1] = outline->n_points - 1;
2274 outline->n_contours++;
2282 FT_LOCAL_DEF( FT_Error )
2283 ps_builder_start_point( PS_Builder* builder,
2287 FT_Error error = FT_Err_Ok;
2291 if ( !builder->path_begun )
2293 builder->path_begun = 1;
2294 error = ps_builder_add_contour( builder );
2296 error = ps_builder_add_point1( builder, x, y );
2304 FT_LOCAL_DEF(
void )
2305 ps_builder_close_contour( PS_Builder* builder )
2307 FT_Outline* outline = builder->current;
2314 first = outline->n_contours <= 1
2315 ? 0 : outline->contours[outline->n_contours - 2] + 1;
2319 if ( outline->n_contours && first == outline->n_points )
2321 outline->n_contours--;
2327 if ( outline->n_points > 1 )
2329 FT_Vector* p1 = outline->points + first;
2330 FT_Vector* p2 = outline->points + outline->n_points - 1;
2331 FT_Byte* control = outline->tags + outline->n_points - 1;
2336 if ( p1->x == p2->x && p1->y == p2->y )
2337 if ( *control == FT_CURVE_TAG_ON )
2338 outline->n_points--;
2341 if ( outline->n_contours > 0 )
2345 if ( first == outline->n_points - 1 )
2347 outline->n_contours--;
2348 outline->n_points--;
2351 outline->contours[outline->n_contours - 1] = outline->n_points - 1;
2385 FT_LOCAL_DEF(
void )
2386 ps_decoder_init( PS_Decoder* ps_decoder,
2390 FT_ZERO( ps_decoder );
2394 T1_Decoder t1_decoder = (T1_Decoder)decoder;
2397 ps_builder_init( &ps_decoder->builder,
2398 &t1_decoder->builder,
2401 ps_decoder->cf2_instance = &t1_decoder->cf2_instance;
2402 ps_decoder->psnames = t1_decoder->psnames;
2404 ps_decoder->num_glyphs = t1_decoder->num_glyphs;
2405 ps_decoder->glyph_names = t1_decoder->glyph_names;
2406 ps_decoder->hint_mode = t1_decoder->hint_mode;
2407 ps_decoder->blend = t1_decoder->blend;
2409 ps_decoder->num_locals = (FT_UInt)t1_decoder->num_subrs;
2410 ps_decoder->locals = t1_decoder->subrs;
2411 ps_decoder->locals_len = t1_decoder->subrs_len;
2412 ps_decoder->locals_hash = t1_decoder->subrs_hash;
2414 ps_decoder->buildchar = t1_decoder->buildchar;
2415 ps_decoder->len_buildchar = t1_decoder->len_buildchar;
2417 ps_decoder->lenIV = t1_decoder->lenIV;
2421 CFF_Decoder* cff_decoder = (CFF_Decoder*)decoder;
2424 ps_builder_init( &ps_decoder->builder,
2425 &cff_decoder->builder,
2428 ps_decoder->cff = cff_decoder->cff;
2429 ps_decoder->cf2_instance = &cff_decoder->cff->cf2_instance;
2430 ps_decoder->current_subfont = cff_decoder->current_subfont;
2432 ps_decoder->num_globals = cff_decoder->num_globals;
2433 ps_decoder->globals = cff_decoder->globals;
2434 ps_decoder->globals_bias = cff_decoder->globals_bias;
2435 ps_decoder->num_locals = cff_decoder->num_locals;
2436 ps_decoder->locals = cff_decoder->locals;
2437 ps_decoder->locals_bias = cff_decoder->locals_bias;
2439 ps_decoder->glyph_width = &cff_decoder->glyph_width;
2440 ps_decoder->width_only = cff_decoder->width_only;
2442 ps_decoder->hint_mode = cff_decoder->hint_mode;
2444 ps_decoder->get_glyph_callback = cff_decoder->get_glyph_callback;
2445 ps_decoder->free_glyph_callback = cff_decoder->free_glyph_callback;
2452 FT_LOCAL_DEF(
void )
2453 t1_make_subfont( FT_Face face,
2455 CFF_SubFont subfont )
2457 CFF_Private cpriv = &subfont->private_dict;
2464 count = cpriv->num_blue_values = priv->num_blue_values;
2465 for ( n = 0; n < count; n++ )
2466 cpriv->blue_values[n] = cf2_intToFixed( priv->blue_values[n] );
2468 count = cpriv->num_other_blues = priv->num_other_blues;
2469 for ( n = 0; n < count; n++ )
2470 cpriv->other_blues[n] = cf2_intToFixed( priv->other_blues[n] );
2472 count = cpriv->num_family_blues = priv->num_family_blues;
2473 for ( n = 0; n < count; n++ )
2474 cpriv->family_blues[n] = cf2_intToFixed( priv->family_blues[n] );
2476 count = cpriv->num_family_other_blues = priv->num_family_other_blues;
2477 for ( n = 0; n < count; n++ )
2478 cpriv->family_other_blues[n] =
2479 cf2_intToFixed( priv->family_other_blues[n] );
2481 cpriv->blue_scale = priv->blue_scale;
2482 cpriv->blue_shift = (FT_Pos)priv->blue_shift;
2483 cpriv->blue_fuzz = (FT_Pos)priv->blue_fuzz;
2485 cpriv->standard_width = (FT_Pos)priv->standard_width[0];
2486 cpriv->standard_height = (FT_Pos)priv->standard_height[0];
2488 count = cpriv->num_snap_widths = priv->num_snap_widths;
2489 for ( n = 0; n < count; n++ )
2490 cpriv->snap_widths[n] = (FT_Pos)priv->snap_widths[n];
2492 count = cpriv->num_snap_heights = priv->num_snap_heights;
2493 for ( n = 0; n < count; n++ )
2494 cpriv->snap_heights[n] = (FT_Pos)priv->snap_heights[n];
2496 cpriv->force_bold = priv->force_bold;
2497 cpriv->lenIV = priv->lenIV;
2498 cpriv->language_group = priv->language_group;
2499 cpriv->expansion_factor = priv->expansion_factor;
2501 cpriv->subfont = subfont;
2505 if ( face->internal->random_seed != -1 )
2509 subfont->random = (FT_UInt32)face->internal->random_seed;
2510 if ( face->internal->random_seed )
2514 face->internal->random_seed = (FT_Int32)cff_random(
2515 (FT_UInt32)face->internal->random_seed );
2517 }
while ( face->internal->random_seed < 0 );
2520 if ( !subfont->random )
2526 seed = (FT_UInt32)( (FT_Offset)(
char*)&seed ^
2527 (FT_Offset)(
char*)&face ^
2528 (FT_Offset)(
char*)&subfont );
2529 seed = seed ^ ( seed >> 10 ) ^ ( seed >> 20 );
2533 subfont->random = seed;
2538 FT_LOCAL_DEF(
void )
2539 t1_decrypt( FT_Byte* buffer,
2543 PS_Conv_EexecDecode( &buffer,
2544 FT_OFFSET( buffer, length ),
2551 FT_LOCAL_DEF( FT_UInt32 )
2552 cff_random( FT_UInt32 r )