[cff] Better tracing of the parsing process.

* src/cff/cffload.c (cff_subfont_load, cff_font_load): Decorate with
FT_TRACE.

* src/cff/cffparse.c (cff_parse_font_matrix, cff_parse_font_bbox,
cff_parse_private_dict, cff_parse_cid_ros): Updated.
(CFF_FIELD_NUM, CFF_FIELD_FIXED, CFF_FIELD_FIXED_1000,
CFF_FIELD_STRING, CFF_FIELD_BOOL, CFF_FIELD_CALLBACK, CFF_FIELD,
CFF_FIELD_DELTA): Add argument for ID.
(cff_parser_run): Decorate with FT_TRACE.

* src/cff/cffparse.h (CFF_Field_Handler) [FT_DEBUG_LEVEL_TRACE]: Add
`id' member.

* src/cff/cfftoken.h: Add IDs to all fields.
This commit is contained in:
Werner Lemberg 2011-08-25 13:41:16 +02:00
parent aeaa1619de
commit 35ab70c19c
5 changed files with 286 additions and 110 deletions

View File

@ -1,3 +1,22 @@
2011-08-25 Werner Lemberg <wl@gnu.org>
[cff] Better tracing of the parsing process.
* src/cff/cffload.c (cff_subfont_load, cff_font_load): Decorate with
FT_TRACE.
* src/cff/cffparse.c (cff_parse_font_matrix, cff_parse_font_bbox,
cff_parse_private_dict, cff_parse_cid_ros): Updated.
(CFF_FIELD_NUM, CFF_FIELD_FIXED, CFF_FIELD_FIXED_1000,
CFF_FIELD_STRING, CFF_FIELD_BOOL, CFF_FIELD_CALLBACK, CFF_FIELD,
CFF_FIELD_DELTA): Add argument for ID.
(cff_parser_run): Decorate with FT_TRACE.
* src/cff/cffparse.h (CFF_Field_Handler) [FT_DEBUG_LEVEL_TRACE]: Add
`id' member.
* src/cff/cfftoken.h: Add IDs to all fields.
2011-08-16 Werner Lemberg <wl@gnu.org>
Fix Savannah bug #34022.

View File

@ -4,8 +4,7 @@
/* */
/* OpenType and CFF data/program tables loader (body). */
/* */
/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */
/* 2010 by */
/* Copyright 1996-2011 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -1337,7 +1336,10 @@
error = cff_index_access_element( idx, font_index, &dict, &dict_len );
if ( !error )
{
FT_TRACE4(( " top dictionary:\n" ));
error = cff_parser_run( &parser, dict, dict + dict_len );
}
cff_index_forget_element( idx, &dict );
@ -1366,6 +1368,7 @@
FT_FRAME_ENTER( font->font_dict.private_size ) )
goto Exit;
FT_TRACE4(( " private dictionary:\n" ));
error = cff_parser_run( &parser,
(FT_Byte*)stream->cursor,
(FT_Byte*)stream->limit );
@ -1494,6 +1497,7 @@
goto Exit;
/* now, parse the top-level font dictionary */
FT_TRACE4(( "parsing top-level\n" ));
error = cff_subfont_load( &font->top_font,
&font->font_dict_index,
face_index,
@ -1546,6 +1550,7 @@
for ( idx = 0; idx < fd_index.count; idx++ )
{
sub = font->subfonts[idx];
FT_TRACE4(( "parsing subfont %u\n", idx ));
error = cff_subfont_load( sub, &fd_index, idx,
stream, base_offset, library );
if ( error )

View File

@ -498,7 +498,7 @@
*upm = power_tens[scaling];
FT_TRACE4(( " font matrix: [%f %f %f %f]\n",
FT_TRACE4(( " [%f %f %f %f]\n",
(double)matrix->xx / *upm / 65536,
(double)matrix->xy / *upm / 65536,
(double)matrix->yx / *upm / 65536,
@ -529,7 +529,7 @@
bbox->yMax = FT_RoundFix( cff_parse_fixed( data ) );
error = CFF_Err_Ok;
FT_TRACE4(( " bbox: [%d %d %d %d]\n",
FT_TRACE4(( " [%d %d %d %d]\n",
bbox->xMin / 65536,
bbox->yMin / 65536,
bbox->xMax / 65536,
@ -554,6 +554,9 @@
{
dict->private_size = cff_parse_num( data++ );
dict->private_offset = cff_parse_num( data );
FT_TRACE4(( " %lu %lu\n",
dict->private_size, dict->private_offset ));
error = CFF_Err_Ok;
}
@ -573,8 +576,8 @@
if ( parser->top >= parser->stack + 3 )
{
dict->cid_registry = (FT_UInt)cff_parse_num( data++ );
dict->cid_ordering = (FT_UInt)cff_parse_num( data++ );
dict->cid_registry = (FT_UInt)cff_parse_num( data++ );
dict->cid_ordering = (FT_UInt)cff_parse_num( data++ );
if ( **data == 30 )
FT_TRACE1(( "cff_parse_cid_ros: real supplement is rounded\n" ));
dict->cid_supplement = cff_parse_num( data );
@ -583,7 +586,7 @@
dict->cid_supplement ));
error = CFF_Err_Ok;
FT_TRACE4(( " ROS: registry sid %d, ordering sid %d, supplement %d\n",
FT_TRACE4(( " %d %d %d\n",
dict->cid_registry,
dict->cid_ordering,
dict->cid_supplement ));
@ -593,18 +596,16 @@
}
#define CFF_FIELD_NUM( code, name ) \
CFF_FIELD( code, name, cff_kind_num )
#define CFF_FIELD_FIXED( code, name ) \
CFF_FIELD( code, name, cff_kind_fixed )
#define CFF_FIELD_FIXED_1000( code, name ) \
CFF_FIELD( code, name, cff_kind_fixed_thousand )
#define CFF_FIELD_STRING( code, name ) \
CFF_FIELD( code, name, cff_kind_string )
#define CFF_FIELD_BOOL( code, name ) \
CFF_FIELD( code, name, cff_kind_bool )
#define CFF_FIELD_DELTA( code, name, max ) \
CFF_FIELD( code, name, cff_kind_delta )
#define CFF_FIELD_NUM( code, name, id ) \
CFF_FIELD( code, name, id, cff_kind_num )
#define CFF_FIELD_FIXED( code, name, id ) \
CFF_FIELD( code, name, id, cff_kind_fixed )
#define CFF_FIELD_FIXED_1000( code, name, id ) \
CFF_FIELD( code, name, id, cff_kind_fixed_thousand )
#define CFF_FIELD_STRING( code, name, id ) \
CFF_FIELD( code, name, id, cff_kind_string )
#define CFF_FIELD_BOOL( code, name, id ) \
CFF_FIELD( code, name, id, cff_kind_bool )
#define CFFCODE_TOPDICT 0x1000
#define CFFCODE_PRIVATE 0x2000
@ -613,36 +614,41 @@
#ifndef FT_CONFIG_OPTION_PIC
#define CFF_FIELD_CALLBACK( code, name ) \
{ \
cff_kind_callback, \
code | CFFCODE, \
0, 0, \
cff_parse_ ## name, \
0, 0 \
},
#undef CFF_FIELD
#define CFF_FIELD( code, name, kind ) \
{ \
kind, \
code | CFFCODE, \
FT_FIELD_OFFSET( name ), \
FT_FIELD_SIZE( name ), \
0, 0, 0 \
#undef CFF_FIELD_DELTA
#ifndef FT_DEBUG_LEVEL_TRACE
#define CFF_FIELD_CALLBACK( code, name, id ) \
{ \
cff_kind_callback, \
code | CFFCODE, \
0, 0, \
cff_parse_ ## name, \
0, 0 \
},
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code, name, max ) \
{ \
cff_kind_delta, \
code | CFFCODE, \
FT_FIELD_OFFSET( name ), \
FT_FIELD_SIZE_DELTA( name ), \
0, \
max, \
FT_FIELD_OFFSET( num_ ## name ) \
},
#define CFF_FIELD( code, name, id, kind ) \
{ \
kind, \
code | CFFCODE, \
FT_FIELD_OFFSET( name ), \
FT_FIELD_SIZE( name ), \
0, 0, 0 \
},
#define CFF_FIELD_DELTA( code, name, max, id ) \
{ \
cff_kind_delta, \
code | CFFCODE, \
FT_FIELD_OFFSET( name ), \
FT_FIELD_SIZE_DELTA( name ), \
0, \
max, \
FT_FIELD_OFFSET( num_ ## name ) \
},
static const CFF_Field_Handler cff_field_handlers[] =
{
@ -653,6 +659,54 @@
};
#else /* FT_DEBUG_LEVEL_TRACE */
#define CFF_FIELD_CALLBACK( code, name, id ) \
{ \
cff_kind_callback, \
code | CFFCODE, \
0, 0, \
cff_parse_ ## name, \
0, 0, \
id \
},
#define CFF_FIELD( code, name, id, kind ) \
{ \
kind, \
code | CFFCODE, \
FT_FIELD_OFFSET( name ), \
FT_FIELD_SIZE( name ), \
0, 0, 0, \
id \
},
#define CFF_FIELD_DELTA( code, name, max, id ) \
{ \
cff_kind_delta, \
code | CFFCODE, \
FT_FIELD_OFFSET( name ), \
FT_FIELD_SIZE_DELTA( name ), \
0, \
max, \
FT_FIELD_OFFSET( num_ ## name ), \
id \
},
static const CFF_Field_Handler cff_field_handlers[] =
{
#include "cfftoken.h"
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
#endif /* FT_DEBUG_LEVEL_TRACE */
#else /* FT_CONFIG_OPTION_PIC */
@ -680,11 +734,11 @@
#undef CFF_FIELD
#define CFF_FIELD( code, name, kind ) i++;
#define CFF_FIELD( code, name, id, kind ) i++;
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code, name, max ) i++;
#define CFF_FIELD_DELTA( code, name, max, id ) i++;
#undef CFF_FIELD_CALLBACK
#define CFF_FIELD_CALLBACK( code, name ) i++;
#define CFF_FIELD_CALLBACK( code, name, id ) i++;
#include "cfftoken.h"
@ -695,8 +749,12 @@
i = 0;
#ifndef FT_DEBUG_LEVEL_TRACE
#undef CFF_FIELD_CALLBACK
#define CFF_FIELD_CALLBACK( code_, name_ ) \
#define CFF_FIELD_CALLBACK( code_, name_, id_ ) \
clazz[i].kind = cff_kind_callback; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = 0; \
@ -707,7 +765,7 @@
i++;
#undef CFF_FIELD
#define CFF_FIELD( code_, name_, kind_ ) \
#define CFF_FIELD( code_, name_, id_, kind_ ) \
clazz[i].kind = kind_; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
@ -718,7 +776,7 @@
i++; \
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code_, name_, max_ ) \
#define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \
clazz[i].kind = cff_kind_delta; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
@ -738,6 +796,61 @@
clazz[i].array_max = 0;
clazz[i].count_offset = 0;
#else /* FT_DEBUG_LEVEL_TRACE */
#undef CFF_FIELD_CALLBACK
#define CFF_FIELD_CALLBACK( code_, name_, id_ ) \
clazz[i].kind = cff_kind_callback; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = 0; \
clazz[i].size = 0; \
clazz[i].reader = cff_parse_ ## name_; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
clazz[i].id = id_; \
i++;
#undef CFF_FIELD
#define CFF_FIELD( code_, name_, id_, kind_ ) \
clazz[i].kind = kind_; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = 0; \
clazz[i].count_offset = 0; \
clazz[i].id = id_; \
i++; \
#undef CFF_FIELD_DELTA
#define CFF_FIELD_DELTA( code_, name_, max_, id_ ) \
clazz[i].kind = cff_kind_delta; \
clazz[i].code = code_ | CFFCODE; \
clazz[i].offset = FT_FIELD_OFFSET( name_ ); \
clazz[i].size = FT_FIELD_SIZE_DELTA( name_ ); \
clazz[i].reader = 0; \
clazz[i].array_max = max_; \
clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ ); \
clazz[i].id = id_; \
i++;
#include "cfftoken.h"
clazz[i].kind = 0;
clazz[i].code = 0;
clazz[i].offset = 0;
clazz[i].size = 0;
clazz[i].reader = 0;
clazz[i].array_max = 0;
clazz[i].count_offset = 0;
clazz[i].id = 0;
#endif /* FT_DEBUG_LEVEL_TRACE */
*output_class = clazz;
return CFF_Err_Ok;
@ -836,6 +949,10 @@
FT_Byte* q = (FT_Byte*)parser->object + field->offset;
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE4(( " %s", field->id ));
#endif
/* check that we have enough arguments -- except for */
/* delta encoded arrays, which can be empty */
if ( field->kind != cff_kind_delta && num_args < 1 )
@ -874,6 +991,31 @@
default: /* for 64-bit systems */
*(FT_Long*)q = val;
}
#ifdef FT_DEBUG_LEVEL_TRACE
switch ( field->kind )
{
case cff_kind_bool:
FT_TRACE4(( " %s\n", val ? "true" : "false" ));
break;
case cff_kind_string:
case cff_kind_num:
FT_TRACE4(( " %ld\n", val ));
break;
case cff_kind_fixed:
FT_TRACE4(( " %f\n", (double)val / 65536 ));
break;
case cff_kind_fixed_thousand:
FT_TRACE4(( " %f\n", (double)val / 65536 / 1000 ));
default:
; /* never reached */
}
#endif
break;
case cff_kind_delta:
@ -887,6 +1029,8 @@
if ( num_args > field->array_max )
num_args = field->array_max;
FT_TRACE4(( " [" ));
/* store count */
*qcount = (FT_Byte)num_args;
@ -912,9 +1056,13 @@
*(FT_Long*)q = val;
}
FT_TRACE4(( " %ld", val ));
q += field->size;
num_args--;
}
FT_TRACE4(( "]\n" ));
}
break;

View File

@ -4,7 +4,7 @@
/* */
/* CFF token stream parser (specification) */
/* */
/* Copyright 1996-2001, 2002, 2003 by */
/* Copyright 1996-2003, 2011 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -90,6 +90,10 @@ FT_BEGIN_HEADER
FT_UInt array_max;
FT_UInt count_offset;
#ifdef FT_DEBUG_LEVEL_TRACE
const char* id;
#endif
} CFF_Field_Handler;

View File

@ -4,7 +4,7 @@
/* */
/* CFF token definitions (specification only). */
/* */
/* Copyright 1996-2001, 2002, 2003 by */
/* Copyright 1996-2003, 2011 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@ -22,48 +22,48 @@
#undef CFFCODE
#define CFFCODE CFFCODE_TOPDICT
CFF_FIELD_STRING ( 0, version )
CFF_FIELD_STRING ( 1, notice )
CFF_FIELD_STRING ( 0x100, copyright )
CFF_FIELD_STRING ( 2, full_name )
CFF_FIELD_STRING ( 3, family_name )
CFF_FIELD_STRING ( 4, weight )
CFF_FIELD_BOOL ( 0x101, is_fixed_pitch )
CFF_FIELD_FIXED ( 0x102, italic_angle )
CFF_FIELD_FIXED ( 0x103, underline_position )
CFF_FIELD_FIXED ( 0x104, underline_thickness )
CFF_FIELD_NUM ( 0x105, paint_type )
CFF_FIELD_NUM ( 0x106, charstring_type )
CFF_FIELD_CALLBACK( 0x107, font_matrix )
CFF_FIELD_NUM ( 13, unique_id )
CFF_FIELD_CALLBACK( 5, font_bbox )
CFF_FIELD_NUM ( 0x108, stroke_width )
CFF_FIELD_NUM ( 15, charset_offset )
CFF_FIELD_NUM ( 16, encoding_offset )
CFF_FIELD_NUM ( 17, charstrings_offset )
CFF_FIELD_CALLBACK( 18, private_dict )
CFF_FIELD_NUM ( 0x114, synthetic_base )
CFF_FIELD_STRING ( 0x115, embedded_postscript )
CFF_FIELD_STRING ( 0, version, "Version" )
CFF_FIELD_STRING ( 1, notice, "Notice" )
CFF_FIELD_STRING ( 0x100, copyright, "Copyright" )
CFF_FIELD_STRING ( 2, full_name, "FullName" )
CFF_FIELD_STRING ( 3, family_name, "FamilyName" )
CFF_FIELD_STRING ( 4, weight, "Weight" )
CFF_FIELD_BOOL ( 0x101, is_fixed_pitch, "isFixedPitch" )
CFF_FIELD_FIXED ( 0x102, italic_angle, "ItalicAngle" )
CFF_FIELD_FIXED ( 0x103, underline_position, "UnderlinePosition" )
CFF_FIELD_FIXED ( 0x104, underline_thickness, "UnderlineThickness" )
CFF_FIELD_NUM ( 0x105, paint_type, "PaintType" )
CFF_FIELD_NUM ( 0x106, charstring_type, "CharstringType" )
CFF_FIELD_CALLBACK( 0x107, font_matrix, "FontMatrix" )
CFF_FIELD_NUM ( 13, unique_id, "UniqueID" )
CFF_FIELD_CALLBACK( 5, font_bbox, "FontBBox" )
CFF_FIELD_NUM ( 0x108, stroke_width, "StrokeWidth" )
CFF_FIELD_NUM ( 15, charset_offset, "charset" )
CFF_FIELD_NUM ( 16, encoding_offset, "Encoding" )
CFF_FIELD_NUM ( 17, charstrings_offset, "CharStrings" )
CFF_FIELD_CALLBACK( 18, private_dict, "Private" )
CFF_FIELD_NUM ( 0x114, synthetic_base, "SyntheticBase" )
CFF_FIELD_STRING ( 0x115, embedded_postscript, "PostScript" )
#if 0
CFF_FIELD_STRING ( 0x116, base_font_name )
CFF_FIELD_DELTA ( 0x117, base_font_blend, 16 )
CFF_FIELD_CALLBACK( 0x118, multiple_master )
CFF_FIELD_CALLBACK( 0x119, blend_axis_types )
CFF_FIELD_STRING ( 0x116, base_font_name, "BaseFontName" )
CFF_FIELD_DELTA ( 0x117, base_font_blend, 16, "BaseFontBlend" )
CFF_FIELD_CALLBACK( 0x118, multiple_master, "MultipleMaster" )
CFF_FIELD_CALLBACK( 0x119, blend_axis_types, "BlendAxisTypes" )
#endif
CFF_FIELD_CALLBACK( 0x11E, cid_ros )
CFF_FIELD_NUM ( 0x11F, cid_font_version )
CFF_FIELD_NUM ( 0x120, cid_font_revision )
CFF_FIELD_NUM ( 0x121, cid_font_type )
CFF_FIELD_NUM ( 0x122, cid_count )
CFF_FIELD_NUM ( 0x123, cid_uid_base )
CFF_FIELD_NUM ( 0x124, cid_fd_array_offset )
CFF_FIELD_NUM ( 0x125, cid_fd_select_offset )
CFF_FIELD_STRING ( 0x126, cid_font_name )
CFF_FIELD_CALLBACK( 0x11E, cid_ros, "ROS" )
CFF_FIELD_NUM ( 0x11F, cid_font_version, "CIDFontVersion" )
CFF_FIELD_NUM ( 0x120, cid_font_revision, "CIDFontRevision" )
CFF_FIELD_NUM ( 0x121, cid_font_type, "CIDFontType" )
CFF_FIELD_NUM ( 0x122, cid_count, "CIDCount" )
CFF_FIELD_NUM ( 0x123, cid_uid_base, "UIDBase" )
CFF_FIELD_NUM ( 0x124, cid_fd_array_offset, "FDArray" )
CFF_FIELD_NUM ( 0x125, cid_fd_select_offset, "FDSelect" )
CFF_FIELD_STRING ( 0x126, cid_font_name, "FontName" )
#if 0
CFF_FIELD_NUM ( 0x127, chameleon )
CFF_FIELD_NUM ( 0x127, chameleon, "Chameleon" )
#endif
@ -72,26 +72,26 @@
#undef CFFCODE
#define CFFCODE CFFCODE_PRIVATE
CFF_FIELD_DELTA ( 6, blue_values, 14 )
CFF_FIELD_DELTA ( 7, other_blues, 10 )
CFF_FIELD_DELTA ( 8, family_blues, 14 )
CFF_FIELD_DELTA ( 9, family_other_blues, 10 )
CFF_FIELD_FIXED_1000( 0x109, blue_scale )
CFF_FIELD_NUM ( 0x10A, blue_shift )
CFF_FIELD_NUM ( 0x10B, blue_fuzz )
CFF_FIELD_NUM ( 10, standard_width )
CFF_FIELD_NUM ( 11, standard_height )
CFF_FIELD_DELTA ( 0x10C, snap_widths, 13 )
CFF_FIELD_DELTA ( 0x10D, snap_heights, 13 )
CFF_FIELD_BOOL ( 0x10E, force_bold )
CFF_FIELD_FIXED ( 0x10F, force_bold_threshold )
CFF_FIELD_NUM ( 0x110, lenIV )
CFF_FIELD_NUM ( 0x111, language_group )
CFF_FIELD_FIXED ( 0x112, expansion_factor )
CFF_FIELD_NUM ( 0x113, initial_random_seed )
CFF_FIELD_NUM ( 19, local_subrs_offset )
CFF_FIELD_NUM ( 20, default_width )
CFF_FIELD_NUM ( 21, nominal_width )
CFF_FIELD_DELTA ( 6, blue_values, 14, "BlueValues" )
CFF_FIELD_DELTA ( 7, other_blues, 10, "OtherBlues" )
CFF_FIELD_DELTA ( 8, family_blues, 14, "FamilyBlues" )
CFF_FIELD_DELTA ( 9, family_other_blues, 10, "FamilyOtherBlues" )
CFF_FIELD_FIXED_1000( 0x109, blue_scale, "BlueScale" )
CFF_FIELD_NUM ( 0x10A, blue_shift, "BlueShift" )
CFF_FIELD_NUM ( 0x10B, blue_fuzz, "BlueFuzz" )
CFF_FIELD_NUM ( 10, standard_width, "StdHW" )
CFF_FIELD_NUM ( 11, standard_height, "StdVW" )
CFF_FIELD_DELTA ( 0x10C, snap_widths, 13, "StemSnapH" )
CFF_FIELD_DELTA ( 0x10D, snap_heights, 13, "StemSnapV" )
CFF_FIELD_BOOL ( 0x10E, force_bold, "ForceBold" )
CFF_FIELD_FIXED ( 0x10F, force_bold_threshold, "ForceBoldThreshold" )
CFF_FIELD_NUM ( 0x110, lenIV, "lenIV" )
CFF_FIELD_NUM ( 0x111, language_group, "LanguageGroup" )
CFF_FIELD_FIXED ( 0x112, expansion_factor, "ExpansionFactor" )
CFF_FIELD_NUM ( 0x113, initial_random_seed, "initialRandomSeed" )
CFF_FIELD_NUM ( 19, local_subrs_offset, "Subrs" )
CFF_FIELD_NUM ( 20, default_width, "defaultWidthX" )
CFF_FIELD_NUM ( 21, nominal_width, "nominalWidthX" )
/* END */