20 #include FT_INTERNAL_POSTSCRIPT_AUX_H
21 #include FT_INTERNAL_DEBUG_H
22 #include FT_INTERNAL_CALC_H
37 #define FT_COMPONENT trace_psobjs
76 table->memory = memory;
81 table->max_elems =
count;
82 table->init = 0xDEADBEEFUL;
107 for ( ; offset <
limit; offset++ )
120 FT_Byte* old_base = table->block;
125 if (
FT_ALLOC( table->block, new_size ) )
127 table->block = old_base;
134 FT_MEM_COPY( table->block, old_base, table->capacity );
139 table->capacity = new_size;
173 if ( idx < 0 || idx >= table->max_elems )
175 FT_ERROR((
"ps_table_add: invalid index\n" ));
176 return PSaux_Err_Invalid_Argument;
181 FT_ERROR((
"ps_table_add: invalid length\n" ));
182 return PSaux_Err_Invalid_Argument;
186 if ( table->cursor + length > table->capacity )
193 in_offset = (
FT_Byte*)
object - table->block;
194 if ( in_offset < 0 || (
FT_Offset)in_offset >= table->capacity )
197 while ( new_size < table->cursor + length )
201 new_size += ( new_size >> 2 ) + 1;
209 if ( in_offset >= 0 )
210 object = table->block + in_offset;
214 table->elements[
idx] = table->block + table->cursor;
216 FT_MEM_COPY( table->block + table->cursor,
object, length );
244 FT_Byte* old_base = table->block;
251 if (
FT_ALLOC( table->block, table->cursor ) )
253 FT_MEM_COPY( table->block, old_base, table->cursor );
256 table->capacity = table->cursor;
269 if ( (
FT_ULong)table->init == 0xDEADBEEFUL )
297 while ( cur < limit )
315 while ( cur < limit )
332 #define IS_OCTAL_DIGIT( c ) ( '0' <= (c) && (c) <= '7' )
348 while ( cur < limit )
384 for ( i = 0; i < 3 && cur <
limit; ++
i )
400 error = PSaux_Err_Ok;
422 while ( ++cur < limit )
433 if ( cur < limit && *cur != '>
' )
435 FT_ERROR(( "skip_string: missing closing delimiter `>'\
n" ));
436 err = PSaux_Err_Invalid_File_Format;
446 /* first character must be the opening brace that */
447 /* starts the procedure */
449 /* NB: [ and ] need not match: */
450 /* `/foo {[} def' is a valid PostScript fragment, */
451 /* even within a Type1 font */
454 skip_procedure( FT_Byte* *acur,
459 FT_Error error = PSaux_Err_Ok;
462 FT_ASSERT( **acur == '{' );
464 for ( cur = *acur; cur < limit && error == PSaux_Err_Ok; ++cur )
482 error = skip_literal_string( &cur, limit );
486 error = skip_string( &cur, limit );
490 skip_comment( &cur, limit );
497 error = PSaux_Err_Invalid_File_Format;
505 /***********************************************************************/
507 /* All exported parsing routines handle leading whitespace and stop at */
508 /* the first character which isn't part of the just handled token. */
510 /***********************************************************************/
514 ps_parser_skip_PS_token( PS_Parser parser )
516 /* Note: PostScript allows any non-delimiting, non-whitespace */
517 /* character in a name (PS Ref Manual, 3rd ed, p31). */
518 /* PostScript delimiters are (, ), <, >, [, ], {, }, /, and %. */
520 FT_Byte* cur = parser->cursor;
521 FT_Byte* limit = parser->limit;
522 FT_Error error = PSaux_Err_Ok;
525 skip_spaces( &cur, limit ); /* this also skips comments */
529 /* self-delimiting, single-character tokens */
530 if ( *cur == '[' || *cur == ']' )
536 /* skip balanced expressions (procedures and strings) */
538 if ( *cur == '{' ) /* {...} */
540 error = skip_procedure( &cur, limit );
544 if ( *cur == '(' ) /* (...) */
546 error = skip_literal_string( &cur, limit );
550 if ( *cur == '<' ) /* <...> */
552 if ( cur + 1 < limit && *(cur + 1) == '<' ) /* << */
558 error = skip_string( &cur, limit );
566 if ( cur >= limit || *cur != '>' ) /* >> */
569 " unexpected closing delimiter `>
'\n" ));
570 error = PSaux_Err_Invalid_File_Format;
581 while ( cur < limit )
583 /* *cur might be invalid (e.g., ')
' or '}
'), but this */
584 /* is handled by the test `cur == parser->cursor' below */
592 if ( cur < limit && cur == parser->cursor )
594 FT_ERROR((
"ps_parser_skip_PS_token:"
595 " current token is `%c' which is self-delimiting\n"
597 " but invalid at this point\n",
600 error = PSaux_Err_Invalid_File_Format;
603 parser->error =
error;
604 parser->cursor = cur;
634 cur = parser->cursor;
635 limit = parser->limit;
667 token->start = cur++;
670 parser->cursor = cur;
672 cur = parser->cursor;
674 while ( cur < limit && !parser->
error )
680 else if ( *cur ==
']' )
685 token->limit = ++cur;
690 parser->cursor = cur;
694 cur = parser->cursor;
703 cur = parser->cursor;
704 if ( !parser->error )
714 parser->cursor = cur;
737 FT_Byte* old_cursor = parser->cursor;
738 FT_Byte* old_limit = parser->limit;
744 parser->cursor = master.
start + 1;
745 parser->limit = master.
limit - 1;
747 while ( parser->cursor < parser->limit )
756 if ( tokens !=
NULL && cur < limit )
762 *pnum_tokens = (
FT_Int)( cur - tokens );
764 parser->cursor = old_cursor;
765 parser->
limit = old_limit;
802 while ( cur < limit )
821 if ( coords !=
NULL && count >= max_coords )
826 *( coords !=
NULL ? &coords[
count] : &dummy ) =
829 if ( old_cur == cur )
880 while ( cur < limit )
899 if ( values !=
NULL && count >= max_values )
904 *( values !=
NULL ? &values[
count] : &dummy ) =
907 if ( old_cur == cur )
948 while ( cur < limit && ( *cur ==
' ' || *cur ==
'\t' ) )
950 if ( cur + 1 >= limit )
960 for ( ; cur <
limit; cur++ )
965 else if ( *cur ==
')' )
974 if ( cur >= limit ||
FT_ALLOC( result, len + 1 ) )
996 if ( cur + 3 < limit &&
1005 else if ( cur + 4 < limit &&
1046 limit = token.
limit;
1052 FT_Byte* old_cur = parser->cursor;
1057 parser->cursor = token.
start + 1;
1058 parser->limit = token.
limit - 1;
1061 parser->cursor = old_cur;
1062 parser->limit = old_limit;
1071 if ( max_objects == 0 )
1074 count = max_objects;
1082 for ( ; count > 0; count--, idx++ )
1091 switch ( field->type )
1110 switch ( field->size )
1121 *(FT_UInt32*)q = (FT_UInt32)
val;
1159 " expected a name or string\n"
1161 " but found token of type %d instead\n",
1163 error = PSaux_Err_Invalid_File_Format;
1171 FT_TRACE0((
"ps_parser_load_field: overwriting field %s\n",
1199 " expected four integers in bounding box\n" ));
1200 error = PSaux_Err_Invalid_File_Format;
1219 *pflags |= 1L << field->flag_bit;
1224 error = PSaux_Err_Ok;
1230 error = PSaux_Err_Invalid_File_Format;
1235 #define T1_MAX_TABLE_ELEMENTS 32
1261 if ( num_elements < 0 )
1263 error = PSaux_Err_Ignore;
1266 if ( (
FT_UInt)num_elements > field->array_max )
1267 num_elements = field->array_max;
1269 old_cursor = parser->cursor;
1270 old_limit = parser->limit;
1280 for ( ; num_elements > 0; num_elements--, token++ )
1282 parser->cursor = token->
start;
1283 parser->limit = token->
limit;
1290 *pflags |= 1L << field->flag_bit;
1295 parser->cursor = old_cursor;
1296 parser->limit = old_limit;
1325 cur = parser->cursor;
1327 if ( cur >= parser->limit )
1334 FT_ERROR((
"ps_parser_to_bytes: Missing starting delimiter `<'\n" ));
1335 error = PSaux_Err_Invalid_File_Format;
1349 if ( cur < parser->limit && *cur !=
'>' )
1351 FT_ERROR((
"ps_parser_to_bytes: Missing closing delimiter `>'\n" ));
1352 error = PSaux_Err_Invalid_File_Format;
1359 parser->cursor = cur;
1382 max_coords, coords );
1394 max_values, values, power_ten );
1403 return ps_tostring( &parser->cursor, parser->limit, parser->memory );
1410 return ps_tobool( &parser->cursor, parser->limit );
1422 parser->error = PSaux_Err_Ok;
1423 parser->base = base;
1424 parser->limit =
limit;
1425 parser->cursor = base;
1426 parser->memory = memory;
1474 builder->load_points = 1;
1476 builder->face =
face;
1477 builder->glyph = glyph;
1478 builder->memory = face->memory;
1485 builder->loader = loader;
1486 builder->base = &loader->base.outline;
1487 builder->current = &loader->current.outline;
1490 builder->hints_globals = size->internal;
1491 builder->hints_funcs = 0;
1494 builder->hints_funcs = glyph->internal->glyph_hints;
1500 builder->left_bearing.x = 0;
1501 builder->left_bearing.y = 0;
1502 builder->advance.x = 0;
1503 builder->advance.y = 0;
1529 glyph->
outline = *builder->base;
1552 if ( builder->load_points )
1594 FT_ERROR((
"t1_builder_add_contour: no outline to add points to\n" ));
1595 return PSaux_Err_Invalid_File_Format;
1598 if ( !builder->load_points )
1601 return PSaux_Err_Ok;
1624 FT_Error error = PSaux_Err_Invalid_File_Format;
1630 error = PSaux_Err_Ok;
1668 if ( p1->
x == p2->
x && p1->
y == p2->
y )
1677 if ( first == outline->
n_points - 1 )
static void shift_elements(PS_Table table, FT_Byte *old_base)
#define FT_ALLOC(ptr, size)
GLenum GLsizei GLenum GLenum const GLvoid * table
GLuint const GLfloat * val
FT_BEGIN_HEADER typedef signed long FT_Pos
static FT_Error skip_string(FT_Byte **acur, FT_Byte *limit)
t1_builder_done(T1_Builder builder)
t1_builder_add_point1(T1_Builder builder, FT_Pos x, FT_Pos y)
#define FT_CURVE_TAG_CUBIC
ps_parser_load_field_table(PS_Parser parser, const T1_Field field, void **objects, FT_UInt max_objects, FT_ULong *pflags)
t1_builder_start_point(T1_Builder builder, FT_Pos x, FT_Pos y)
ps_parser_done(PS_Parser parser)
PS_Conv_EexecDecode(FT_Byte **cursor, FT_Byte *limit, FT_Byte *buffer, FT_Offset n, FT_UShort *seed)
ps_parser_to_fixed(PS_Parser parser, FT_Int power_ten)
#define IS_PS_NEWLINE(ch)
ps_parser_skip_PS_token(PS_Parser parser)
ps_parser_to_fixed_array(PS_Parser parser, FT_Int max_values, FT_Fixed *values, FT_Int power_ten)
ps_parser_to_token(PS_Parser parser, T1_Token token)
FT_BEGIN_HEADER typedef unsigned char FT_Bool
ps_table_new(PS_Table table, FT_Int count, FT_Memory memory)
FT_CALLBACK_TABLE_DEF const T1_Builder_FuncsRec t1_builder_funcs
typedefFT_BEGIN_HEADER struct FT_GlyphLoaderRec_ * FT_GlyphLoader
#define FT_ERROR(varformat)
ps_table_add(PS_Table table, FT_Int idx, void *object, FT_PtrDist length)
#define FT_PAD_CEIL(x, n)
PS_Conv_ToFixed(FT_Byte **cursor, FT_Byte *limit, FT_Int power_ten)
FT_CALLBACK_TABLE_DEF const PS_Parser_FuncsRec ps_parser_funcs
EGLContext EGLenum EGLClientBuffer buffer
struct T1_FieldRec_ * T1_Field
ps_parser_skip_spaces(PS_Parser parser)
ps_table_release(PS_Table table)
ps_parser_load_field(PS_Parser parser, const T1_Field field, void **objects, FT_UInt max_objects, FT_ULong *pflags)
ps_parser_to_int(PS_Parser parser)
#define FT_TRACE0(varformat)
PS_Conv_ASCIIHexDecode(FT_Byte **cursor, FT_Byte *limit, FT_Byte *buffer, FT_Offset n)
#define IS_OCTAL_DIGIT(c)
static void skip_spaces(FT_Byte **acur, FT_Byte *limit)
static FT_Int ps_tofixedarray(FT_Byte **acur, FT_Byte *limit, FT_Int max_values, FT_Fixed *values, FT_Int power_ten)
ps_table_done(PS_Table table)
static int ps_tobool(FT_Byte **acur, FT_Byte *limit)
t1_builder_close_contour(T1_Builder builder)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
#define FT_NEW_ARRAY(ptr, count)
EGLSurface EGLint EGLint y
t1_decrypt(FT_Byte *buffer, FT_Offset length, FT_UShort seed)
typedefFT_BEGIN_HEADER struct PS_TableRec_ * PS_Table
static FT_Error skip_literal_string(FT_Byte **acur, FT_Byte *limit)
ps_parser_to_bytes(PS_Parser parser, FT_Byte *bytes, FT_Offset max_bytes, FT_Long *pnum_bytes, FT_Bool delimiters)
ps_parser_to_coord_array(PS_Parser parser, FT_Int max_coords, FT_Short *coords)
static FT_Error skip_procedure(FT_Byte **acur, FT_Byte *limit)
#define T1_MAX_TABLE_ELEMENTS
GLdouble GLdouble GLdouble GLdouble q
FT_GlyphLoader_Rewind(FT_GlyphLoader loader)
static void skip_comment(FT_Byte **acur, FT_Byte *limit)
t1_builder_add_point(T1_Builder builder, FT_Pos x, FT_Pos y, FT_Byte flag)
ps_parser_init(PS_Parser parser, FT_Byte *base, FT_Byte *limit, FT_Memory memory)
t1_builder_add_contour(T1_Builder builder)
t1_builder_init(T1_Builder builder, FT_Face face, FT_Size size, FT_GlyphSlot glyph, FT_Bool hinting)
#define FT_MEM_COPY(dest, source, count)
PS_Conv_ToInt(FT_Byte **cursor, FT_Byte *limit)
#define FT_GLYPHLOADER_CHECK_POINTS(_loader, _points, _contours)
static FT_Int ps_tocoordarray(FT_Byte **acur, FT_Byte *limit, FT_Int max_coords, FT_Short *coords)
ps_parser_to_token_array(PS_Parser parser, T1_Token tokens, FT_UInt max_tokens, FT_Int *pnum_tokens)
t1_builder_check_points(T1_Builder builder, FT_Int count)
GLint GLsizei const GLuint64 * values
static FT_Error reallocate_t1_table(PS_Table table, FT_Long new_size)
FT_CALLBACK_TABLE_DEF const PS_Table_FuncsRec ps_table_funcs