diff --git a/src/cff/t2driver.c b/src/cff/t2driver.c index fe29559b9..e596aa520 100644 --- a/src/cff/t2driver.c +++ b/src/cff/t2driver.c @@ -16,6 +16,7 @@ /***************************************************************************/ +#include #include #include #include @@ -24,6 +25,8 @@ #include #include +#include + /*************************************************************************/ /* */ @@ -47,6 +50,7 @@ /*************************************************************************/ /*************************************************************************/ + #undef PAIR_TAG #define PAIR_TAG( left, right ) ( ( (TT_ULong)left << 16 ) | \ (TT_ULong)right ) @@ -74,12 +78,12 @@ /* formats. */ /* */ /* */ - /* FreeType error code. 0 means success. */ + /* TrueType error code. 0 means success. */ /* */ /* */ /* Only horizontal layouts (left-to-right & right-to-left) are */ /* supported by this function. Other layouts, or more sophisticated */ - /* kernings are out of scope of this method (the basic driver */ + /* kernings, are out of scope of this method (the basic driver */ /* interface is meant to be simple). */ /* */ /* They can be implemented by format-specific interfaces. */ @@ -94,7 +98,7 @@ if ( !face ) - return FT_Err_Invalid_Face_Handle; + return T2_Err_Invalid_Face_Handle; kerning->x = 0; kerning->y = 0; @@ -111,7 +115,7 @@ while ( left <= right ) { - TT_Int middle = left + ((right-left) >> 1); + TT_Int middle = left + ( ( right - left ) >> 1 ); TT_ULong cur_pair; @@ -122,14 +126,14 @@ goto Found; if ( cur_pair < search_tag ) - left = middle+1; + left = middle + 1; else - right = middle-1; + right = middle - 1; } } Exit: - return FT_Err_Ok; + return T2_Err_Ok; Found: kerning->x = pair->value; @@ -163,47 +167,54 @@ /* and vertical) expressed in fractional points. */ /* */ /* */ - /* char_width :: The character width expressed in 26.6 fractional */ - /* points. */ - /* char_height :: The character height expressed in 26.6 fractional */ - /* points. */ + /* char_width :: The character width expressed in 26.6 */ + /* fractional points. */ + /* */ + /* char_height :: The character height expressed in 26.6 */ + /* fractional points. */ + /* */ + /* horz_resolution :: The horizontal resolution of the output device. */ + /* */ + /* vert_resolution :: The vertical resolution of the output device. */ /* */ /* */ /* size :: A handle to the target size object. */ /* */ /* */ - /* FreeType error code. 0 means success. */ + /* TrueType error code. 0 means success. */ /* */ static TT_Error Set_Char_Sizes( T2_Size size, - FT_F26Dot6 char_width, - FT_F26Dot6 char_height, - FT_UInt horz_resolution, - FT_UInt vert_resolution ) + TT_F26Dot6 char_width, + TT_F26Dot6 char_height, + TT_UInt horz_resolution, + TT_UInt vert_resolution ) { FT_Size_Metrics* metrics = &size->metrics; T2_Face face = (T2_Face)size->face; FT_Long dim_x, dim_y; + /* This bit flag, when set, indicates that the pixel size must be */ - /* truncated to an integer. Nearly all TrueType fonts have this */ + /* truncated to an integer. Nearly all TrueType fonts have this */ /* bit set, as hinting won't work really well otherwise. */ /* */ /* However, for those rare fonts who do not set it, we override */ - /* the default computations performed by the base layer. I really */ - /* don't know if this is useful, but hey, that's the spec :-) */ + /* the default computations performed by the base layer. I */ + /* really don't know whether this is useful, but hey, that's the */ + /* spec :-) */ /* */ - if ( (face->header.Flags & 8) == 0 ) + if ( ( face->header.Flags & 8 ) == 0 ) { /* Compute pixel sizes in 26.6 units */ - dim_x = (char_width * horz_resolution) / 72; - dim_y = (char_height * vert_resolution) / 72; + dim_x = ( char_width * horz_resolution ) / 72; + dim_y = ( char_height * vert_resolution ) / 72; metrics->x_scale = FT_DivFix( dim_x, face->root.units_per_EM ); metrics->y_scale = FT_DivFix( dim_y, face->root.units_per_EM ); - metrics->x_ppem = (TT_UShort)(dim_x >> 6); - metrics->y_ppem = (TT_UShort)(dim_y >> 6); + metrics->x_ppem = (TT_UShort)( dim_x >> 6 ); + metrics->y_ppem = (TT_UShort)( dim_y >> 6 ); } return T2_Reset_Size( size ); @@ -228,15 +239,15 @@ /* size :: A handle to the target size object. */ /* */ /* */ - /* FreeType error code. 0 means success */ + /* TrueType error code. 0 means success. */ /* */ static - FT_Error Set_Pixel_Sizes( T2_Size size, - FT_UInt pixel_width, - FT_UInt pixel_height ) + TT_Error Set_Pixel_Sizes( T2_Size size, + TT_UInt pixel_width, + TT_UInt pixel_height ) { - UNUSED(pixel_width); - UNUSED(pixel_height); + UNUSED( pixel_width ); + UNUSED( pixel_height ); return T2_Reset_Size( size ); } @@ -255,7 +266,7 @@ /* will be loaded. */ /* */ /* size :: A handle to the source face size at which the glyph */ - /* must be scaled/loaded/etc. */ + /* must be scaled, loaded, etc. */ /* */ /* glyph_index :: The index of the glyph in the font file. */ /* */ @@ -264,27 +275,23 @@ /* glyph loading process (e.g., whether the outline */ /* should be scaled, whether to load bitmaps or not, */ /* whether to hint the outline, etc). */ - /* */ - /* result :: A set of bit flags indicating the type of data that */ - /* was loaded in the glyph slot (outline, bitmap, */ - /* pixmap, etc). */ /* */ /* */ - /* FreeType error code. 0 means success. */ + /* TrueType error code. 0 means success. */ /* */ static - FT_Error Load_Glyph( T2_GlyphSlot slot, + TT_Error Load_Glyph( T2_GlyphSlot slot, T2_Size size, - FT_UShort glyph_index, - FT_UInt load_flags ) + TT_UShort glyph_index, + TT_UInt load_flags ) { - FT_Error error; + TT_Error error; if ( !slot ) - return FT_Err_Invalid_Handle; + return T2_Err_Invalid_Glyph_Handle; - /* check that we want a scaled outline or bitmap */ + /* check whether we want a scaled outline or bitmap */ if ( !size ) load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; @@ -296,7 +303,7 @@ { /* these two object must have the same parent */ if ( size->face != slot->root.face ) - return FT_Err_Invalid_Face_Handle; + return T2_Err_Invalid_Face_Handle; } /* now load the glyph outline if necessary */ @@ -336,13 +343,14 @@ /* Glyph index. 0 means `undefined character code'. */ /* */ static - FT_UInt Get_Char_Index( TT_CharMap charmap, - FT_Long charcode ) + TT_UInt Get_Char_Index( TT_CharMap charmap, + TT_Long charcode ) { - FT_Error error; + TT_Error error; T2_Face face; TT_CMapTable* cmap; + cmap = &charmap->cmap; face = (T2_Face)charmap->root.face; @@ -351,29 +359,47 @@ { SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt; + error = sfnt->load_charmap( face, cmap, face->root.stream ); - if (error) return error; + if ( error ) + return 0; cmap->loaded = TRUE; } - return (cmap->get_index ? cmap->get_index( cmap, charcode ) : 0 ); + return ( cmap->get_index ? cmap->get_index( cmap, charcode ) : 0 ); } + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /**** ****/ + /**** ****/ + /**** D R I V E R I N T E R F A C E ****/ + /**** ****/ + /**** ****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + static - FTDriver_Interface t2_get_interface( T2_Driver driver, const char* interface ) + FTDriver_Interface t2_get_interface( T2_Driver driver, + const char* interface ) { FT_Driver sfntd = FT_Get_Driver( driver->root.library, "sfnt" ); SFNT_Interface* sfnt; - + + /* only return the default interface from the SFNT module */ - if (sfntd) + if ( sfntd ) { sfnt = (SFNT_Interface*)(sfntd->interface.format_interface); - if (sfnt) + if ( sfnt ) return sfnt->get_interface( (FT_Driver)driver, interface ); } + return 0; } @@ -393,27 +419,29 @@ (void*)0, - (FTDriver_initDriver) T2_Init_Driver, - (FTDriver_doneDriver) T2_Done_Driver, - (FTDriver_getInterface) t2_get_interface, + (FTDriver_initDriver) T2_Init_Driver, + (FTDriver_doneDriver) T2_Done_Driver, + (FTDriver_getInterface) t2_get_interface, - (FTDriver_initFace) T2_Init_Face, - (FTDriver_doneFace) T2_Done_Face, - (FTDriver_getKerning) Get_Kerning, + (FTDriver_initFace) T2_Init_Face, + (FTDriver_doneFace) T2_Done_Face, + (FTDriver_getKerning) Get_Kerning, - (FTDriver_initSize) T2_Init_Size, - (FTDriver_doneSize) T2_Done_Size, - (FTDriver_setCharSizes) Set_Char_Sizes, - (FTDriver_setPixelSizes) Set_Pixel_Sizes, + (FTDriver_initSize) T2_Init_Size, + (FTDriver_doneSize) T2_Done_Size, + (FTDriver_setCharSizes) Set_Char_Sizes, + (FTDriver_setPixelSizes) Set_Pixel_Sizes, - (FTDriver_initGlyphSlot) T2_Init_GlyphSlot, - (FTDriver_doneGlyphSlot) T2_Done_GlyphSlot, - (FTDriver_loadGlyph) Load_Glyph, + (FTDriver_initGlyphSlot) T2_Init_GlyphSlot, + (FTDriver_doneGlyphSlot) T2_Done_GlyphSlot, + (FTDriver_loadGlyph) Load_Glyph, - (FTDriver_getCharIndex) Get_Char_Index, + (FTDriver_getCharIndex) Get_Char_Index, }; +#ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS + /*************************************************************************/ /* */ @@ -434,13 +462,12 @@ /* format-specific interface can then be retrieved through the method */ /* interface->get_format_interface. */ /* */ -#ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS - - EXPORT_FUNC(FT_DriverInterface*) getDriverInterface( void ) + EXPORT_FUNC( FT_DriverInterface* ) getDriverInterface( void ) { return &cff_driver_interface; } + #endif /* CONFIG_OPTION_DYNAMIC_DRIVERS */ diff --git a/src/cff/t2driver.h b/src/cff/t2driver.h index 7aaf111ed..225c5ad37 100644 --- a/src/cff/t2driver.h +++ b/src/cff/t2driver.h @@ -4,7 +4,7 @@ /* */ /* High-level OpenType driver interface (specification). */ /* */ -/* Copyright 1996-1999 by */ +/* Copyright 1996-2000 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -19,13 +19,12 @@ #ifndef T2DRIVER_H #define T2DRIVER_H +#include #include -#include #include -#include - FT_EXPORT_VAR(const FT_DriverInterface) cff_driver_interface; + FT_EXPORT_VAR( const FT_DriverInterface ) cff_driver_interface; #endif /* T2DRIVER_H */ diff --git a/src/cff/t2gload.c b/src/cff/t2gload.c index d5d066fc7..d93c6b91e 100644 --- a/src/cff/t2gload.c +++ b/src/cff/t2gload.c @@ -25,6 +25,8 @@ #include #include +#include + /*************************************************************************/ /* */ @@ -39,12 +41,15 @@ typedef enum T2_Operator_ { t2_op_unknown = 0, + t2_op_rmoveto, t2_op_hmoveto, t2_op_vmoveto, + t2_op_rlineto, t2_op_hlineto, t2_op_vlineto, + t2_op_rrcurveto, t2_op_hhcurveto, t2_op_hvcurveto, @@ -52,17 +57,22 @@ t2_op_rlinecurve, t2_op_vhcurveto, t2_op_vvcurveto, + t2_op_flex, t2_op_hflex, t2_op_hflex1, t2_op_flex1, + t2_op_endchar, + t2_op_hstem, t2_op_vstem, t2_op_hstemhm, t2_op_vstemhm, + t2_op_hintmask, t2_op_cntrmask, + t2_op_abs, t2_op_add, t2_op_sub, @@ -71,37 +81,45 @@ t2_op_random, t2_op_mul, t2_op_sqrt, + t2_op_blend, + t2_op_drop, t2_op_exch, t2_op_index, t2_op_roll, t2_op_dup, + t2_op_put, t2_op_get, t2_op_store, t2_op_load, + t2_op_and, t2_op_or, t2_op_not, t2_op_eq, t2_op_ifelse, + t2_op_callsubr, t2_op_callgsubr, t2_op_return, + /* do not remove */ t2_op_max - + } T2_Operator; - #define T2_COUNT_CHECK_WIDTH 0x80 - #define T2_COUNT_EXACT 0x40 - #define T2_COUNT_CLEAR_STACK 0x20 + +#define T2_COUNT_CHECK_WIDTH 0x80 +#define T2_COUNT_EXACT 0x40 +#define T2_COUNT_CLEAR_STACK 0x20 + static const FT_Byte t2_argument_counts[] = { 0, /* unknown */ - + 2 | T2_COUNT_CHECK_WIDTH | T2_COUNT_EXACT, /* rmoveto */ 1 | T2_COUNT_CHECK_WIDTH | T2_COUNT_EXACT, 1 | T2_COUNT_CHECK_WIDTH | T2_COUNT_EXACT, @@ -123,16 +141,16 @@ 9, 11, - 0, /* enchar */ - + 0, /* endchar */ + 2 | T2_COUNT_CHECK_WIDTH, /* hstem */ 2 | T2_COUNT_CHECK_WIDTH, 2 | T2_COUNT_CHECK_WIDTH, 2 | T2_COUNT_CHECK_WIDTH, - + 0, /* hintmask */ 0, /* cntrmask */ - + 1, /* abs */ 2, 2, @@ -141,64 +159,63 @@ 0, 2, 1, - + 1, /* blend */ - + 1, /* drop */ 2, 1, 2, 1, - + 2, /* put */ 1, 4, 3, - + 2, /* and */ 2, 1, 2, 4, - + 1, /* callsubr */ 1, 0 }; - /* required for the tracing mode */ -#undef FT_COMPONENT -#define FT_COMPONENT trace_ttgload + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********** *********/ + /********** *********/ + /********** GENERIC CHARSTRING PARSING *********/ + /********** *********/ + /********** *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ - /**********************************************************************/ - /**********************************************************************/ - /**********************************************************************/ - /********** *********/ - /********** *********/ - /********** GENERIC CHARSTRINGS PARSING *********/ - /********** *********/ - /********** *********/ - /**********************************************************************/ - /**********************************************************************/ - /**********************************************************************/ - -/********************************************************************* - * - * - * T2_Init_Builder - * - * - * Initialise a given glyph builder. - * - * - * builder :: glyph builder to initialise - * face :: current face object - * size :: current size object - * glyph :: current glyph object - * - *********************************************************************/ - + /*************************************************************************/ + /* */ + /* */ + /* T2_Init_Builder */ + /* */ + /* */ + /* Initializes a given glyph builder. */ + /* */ + /* */ + /* builder :: A pointer to the glyph builder to initialize. */ + /* */ + /* */ + /* face :: The current face object. */ + /* */ + /* size :: The current size object. */ + /* */ + /* glyph :: The current glyph object. */ + /* */ static void T2_Init_Builder( T2_Builder* builder, TT_Face face, @@ -212,14 +229,14 @@ builder->glyph = glyph; builder->memory = face->root.memory; - if (glyph) + if ( glyph ) { builder->base = glyph->root.outline; builder->max_points = glyph->max_points; builder->max_contours = glyph->max_contours; } - if (size) + if ( size ) { builder->scale_x = size->metrics.x_scale; builder->scale_y = size->metrics.y_scale; @@ -239,27 +256,26 @@ } -/********************************************************************* - * - * - * T2_Done_Builder - * - * - * Finalise a given glyph builder. Its content can still be - * used after the call, but the function saves important information - * within the corresponding glyph slot. - * - * - * builder :: glyph builder to initialise - * - *********************************************************************/ - + /*************************************************************************/ + /* */ + /* */ + /* T2_Done_Builder */ + /* */ + /* */ + /* Finalizes a given glyph builder. Its contents can still be used */ + /* after the call, but the function saves important information */ + /* within the corresponding glyph slot. */ + /* */ + /* */ + /* builder :: A pointer to the glyph builder to finalize. */ + /* */ static - void T2_Done_Builder( T2_Builder* builder ) + void T2_Done_Builder( T2_Builder* builder ) { T2_GlyphSlot glyph = builder->glyph; - if (glyph) + + if ( glyph ) { glyph->root.outline = builder->base; glyph->max_points = builder->max_points; @@ -268,36 +284,55 @@ } - -/********************************************************************* - * - * - * T2_Init_Decoder - * - * - * Initialise a given Type 2 decoder for parsing - * - * - * decoder :: Type 1 decoder to initialise - * funcs :: hinter functions interface - * - *********************************************************************/ - - static FT_Int t2_compute_bias( FT_UInt num_subrs ) + /*************************************************************************/ + /* */ + /* */ + /* t2_compute_bias */ + /* */ + /* */ + /* Computes the bias value in dependence of the number of glyph */ + /* subroutines. */ + /* */ + /* */ + /* num_subrs :: The number of glyph subroutines. */ + /* */ + /* */ + /* The bias value. */ + static + TT_Int t2_compute_bias( TT_UInt num_subrs ) { - FT_Int result; - - if (num_subrs < 1240) + TT_Int result; + + + if ( num_subrs < 1240 ) result = 107; - else if (num_subrs < 33900) + else if ( num_subrs < 33900 ) result = 1131; else result = 32768; - + return result; } + /*************************************************************************/ + /* */ + /* */ + /* T2_Init_Decoder */ + /* */ + /* */ + /* Initializes a given glyph decoder. */ + /* */ + /* */ + /* decoder :: A pointer to the glyph builder to initialize. */ + /* */ + /* */ + /* face :: The current face object. */ + /* */ + /* size :: The current size object. */ + /* */ + /* slot :: The current glyph object. */ + /* */ LOCAL_FUNC void T2_Init_Decoder( T2_Decoder* decoder, TT_Face face, @@ -305,55 +340,58 @@ T2_GlyphSlot slot ) { CFF_Font* cff = (CFF_Font*)face->other; - - /* clear everything */ - MEM_Set( decoder, 0, sizeof(*decoder) ); - /* initialise builder */ + + /* clear everything */ + MEM_Set( decoder, 0, sizeof ( *decoder ) ); + + /* initialize builder */ T2_Init_Builder( &decoder->builder, face, size, slot ); - - /* initialise Type2 decoder */ + + /* initialize Type2 decoder */ decoder->num_locals = cff->num_local_subrs; decoder->num_globals = cff->num_global_subrs; decoder->locals = cff->local_subrs; decoder->globals = cff->global_subrs; decoder->locals_bias = t2_compute_bias( decoder->num_locals ); decoder->globals_bias = t2_compute_bias( decoder->num_globals ); - + decoder->glyph_width = cff->private_dict.default_width; decoder->nominal_width = cff->private_dict.nominal_width; } - /* check that there is enough room for "count" more points */ + /* check that there is enough room for `count' more points */ static - FT_Error check_points( T2_Builder* builder, - FT_Int count ) + TT_Error check_points( T2_Builder* builder, + TT_Int count ) { FT_Outline* base = &builder->base; FT_Outline* outline = &builder->current; - if (!builder->load_points) - return FT_Err_Ok; + + if ( !builder->load_points ) + return T2_Err_Ok; count += base->n_points + outline->n_points; /* realloc points table if necessary */ if ( count >= builder->max_points ) { - FT_Error error; + TT_Error error; FT_Memory memory = builder->memory; - FT_Int increment = outline->points - base->points; - FT_Int current = builder->max_points; + TT_Int increment = outline->points - base->points; + TT_Int current = builder->max_points; + while ( builder->max_points < count ) builder->max_points += 8; if ( REALLOC_ARRAY( base->points, current, - builder->max_points, FT_Vector ) || + builder->max_points, TT_Vector ) || REALLOC_ARRAY( base->tags, current, - builder->max_points, FT_Byte ) ) + builder->max_points, TT_Byte ) ) { builder->error = error; return error; @@ -362,27 +400,30 @@ outline->points = base->points + increment; outline->tags = base->tags + increment; } - return FT_Err_Ok; + + return T2_Err_Ok; } /* add a new point, do not check room */ static void add_point( T2_Builder* builder, - FT_Pos x, - FT_Pos y, - FT_Byte flag ) + TT_Pos x, + TT_Pos y, + TT_Byte flag ) { FT_Outline* outline = &builder->current; - if (builder->load_points) + + if ( builder->load_points ) { - FT_Vector* point = outline->points + outline->n_points; - FT_Byte* control = (FT_Byte*)outline->tags + outline->n_points; + TT_Vector* point = outline->points + outline->n_points; + TT_Byte* control = (FT_Byte*)outline->tags + outline->n_points; + point->x = x >> 16; point->y = y >> 16; - *control = ( flag ? FT_Curve_Tag_On : FT_Curve_Tag_Cubic ); + *control = flag ? FT_Curve_Tag_On : FT_Curve_Tag_Cubic; builder->last = *point; } @@ -393,14 +434,15 @@ /* check room for a new on-curve point, then add it */ static - FT_Error add_point1( T2_Builder* builder, - FT_Pos x, - FT_Pos y ) + TT_Error add_point1( T2_Builder* builder, + TT_Pos x, + TT_Pos y ) { - FT_Error error; + TT_Error error; - error = check_points(builder,1); - if (!error) + + error = check_points( builder, 1 ); + if ( !error ) add_point( builder, x, y, 1 ); return error; @@ -409,30 +451,32 @@ /* check room for a new contour, then add it */ static - FT_Error add_contour( T2_Builder* builder ) + TT_Error add_contour( T2_Builder* builder ) { FT_Outline* base = &builder->base; FT_Outline* outline = &builder->current; - if (!builder->load_points) + + if ( !builder->load_points ) { outline->n_contours++; - return FT_Err_Ok; + return T2_Err_Ok; } /* realloc contours array if necessary */ if ( base->n_contours + outline->n_contours >= builder->max_contours && builder->load_points ) { - FT_Error error; - FT_Memory memory = builder->memory; - FT_Int increment = outline->contours - base->contours; - FT_Int current = builder->max_contours; + TT_Error error; + FT_Memory memory = builder->memory; + TT_Int increment = outline->contours - base->contours; + TT_Int current = builder->max_contours; + builder->max_contours += 4; if ( REALLOC_ARRAY( base->contours, - current, builder->max_contours, FT_Short ) ) + current, builder->max_contours, TT_Short ) ) { builder->error = error; return error; @@ -441,28 +485,33 @@ outline->contours = base->contours + increment; } - if (outline->n_contours > 0) - outline->contours[ outline->n_contours-1 ] = outline->n_points-1; + if ( outline->n_contours > 0 ) + outline->contours[outline->n_contours - 1] = outline->n_points - 1; outline->n_contours++; - return FT_Err_Ok; + + return T2_Err_Ok; } + /* if a path was begun, add its first on-curve point */ static - FT_Error start_point( T2_Builder* builder, - FT_Pos x, - FT_Pos y ) + TT_Error start_point( T2_Builder* builder, + TT_Pos x, + TT_Pos y ) { - /* test wether we're building a new contour */ - if (!builder->path_begun) + /* test whether we are building a new contour */ + if ( !builder->path_begun ) { - FT_Error error; + TT_Error error; + builder->path_begun = 1; error = add_contour( builder ); - if (error) return error; + if ( error ) + return error; } + return add_point1( builder, x, y ); } @@ -473,77 +522,77 @@ { FT_Outline* outline = &builder->current; + if ( outline->n_contours > 0 ) - outline->contours[outline->n_contours-1] = outline->n_points-1; + outline->contours[outline->n_contours - 1] = outline->n_points - 1; } -/********************************************************************* - * - * - * T2_Parse_CharStrings - * - * - * Parses a given Type 1 charstrings program - * - * - * decoder :: current Type 1 decoder - * charstring_base :: base of the charstring stream - * charstring_len :: length in bytes of the charstring stream - * num_subrs :: number of sub-routines - * subrs_base :: array of sub-routines addresses - * subrs_len :: array of sub-routines lengths - * - * - * Error code. 0 means success. - * - *********************************************************************/ - #define USE_ARGS(n) top -= n; if (top < decoder->stack) goto Stack_Underflow + /*************************************************************************/ + /* */ + /* */ + /* T2_Parse_CharStrings */ + /* */ + /* */ + /* Parses a given Type 2 charstrings program. */ + /* */ + /* */ + /* decoder :: The current Type 1 decoder. */ + /* */ + /* */ + /* charstring_base :: The base of the charstring stream. */ + /* */ + /* charstring_len :: The length in bytes of the charstring stream. */ + /* */ + /* */ + /* TrueType error code. 0 means success. */ + /* */ LOCAL_FUNC - FT_Error T2_Parse_CharStrings( T2_Decoder* decoder, - FT_Byte* charstring_base, - FT_Int charstring_len ) + TT_Error T2_Parse_CharStrings( T2_Decoder* decoder, + TT_Byte* charstring_base, + TT_Int charstring_len ) { - FT_Error error; + TT_Error error; T2_Decoder_Zone* zone; - FT_Byte* ip; - FT_Byte* limit; + TT_Byte* ip; + TT_Byte* limit; T2_Builder* builder = &decoder->builder; FT_Outline* outline; - FT_Pos x, y; - FT_Fixed seed; - FT_Fixed* stack; + TT_Pos x, y; + TT_Fixed seed; + TT_Fixed* stack; + /* set default width */ - decoder->num_hints = 0; - decoder->read_width = 1; - + decoder->num_hints = 0; + decoder->read_width = 1; + /* compute random seed from stack address of parameter */ - seed = (FT_Fixed)(char*)&seed ^ - (FT_Fixed)(char*)&decoder ^ - (FT_Fixed)(char*)&charstring_base; - seed = (seed ^ (seed >> 10) ^ (seed >> 20)) & 0xFFFF; - if (seed == 0) + seed = (FT_Fixed)(char*)&seed ^ + (FT_Fixed)(char*)&decoder ^ + (FT_Fixed)(char*)&charstring_base; + seed = ( seed ^ ( seed >> 10 ) ^ ( seed >> 20 ) ) & 0xFFFF; + if ( seed == 0 ) seed = 0x7384; - - /* First of all, initialise the decoder */ + + /* First of all, initialize the decoder */ decoder->top = decoder->stack; decoder->zone = decoder->zones; zone = decoder->zones; stack = decoder->top; - builder->path_begun = 0; + builder->path_begun = 0; zone->base = charstring_base; limit = zone->limit = charstring_base + charstring_len; ip = zone->cursor = zone->base; - error = FT_Err_Ok; + error = T2_Err_Ok; outline = &builder->current; - + x = builder->pos_x; y = builder->pos_y; @@ -551,8 +600,9 @@ while ( ip < limit ) { T2_Operator op; - FT_Byte v; - FT_Byte count; + TT_Byte v; + TT_Byte count; + /********************************************************************/ /* */ @@ -560,902 +610,1074 @@ /* */ /* */ v = *ip++; - if (v >= 32 || v == 28) + if ( v >= 32 || v == 28 ) { - FT_Int shift = 16; - FT_Long val; - + TT_Int shift = 16; + TT_Long val; + + /* this is an operand, push it on the stack */ - if ( v == 28) + if ( v == 28 ) { - if ( ip+1 >= limit ) goto Syntax_Error; - val = (FT_Short)(((FT_Int)ip[0] << 8) + ip[1]); + if ( ip + 1 >= limit ) + goto Syntax_Error; + val = (FT_Short)( ( (FT_Int)ip[0] << 8 ) + ip[1] ); ip += 2; } else if ( v < 247 ) val = v - 139; else if ( v < 251 ) { - if ( ip >= limit ) goto Syntax_Error; - val = (v-247)*256 + *ip++ + 108; + if ( ip >= limit ) + goto Syntax_Error; + val = (v - 247) * 256 + *ip++ + 108; } else if ( v < 255 ) { - if ( ip >= limit ) goto Syntax_Error; - val = -((v-251)*256) - *ip++ - 108; + if ( ip >= limit ) + goto Syntax_Error; + val = -( v - 251 ) * 256 - *ip++ - 108; } else { - if ( ip + 3 >= limit ) goto Syntax_Error; - val = ((FT_Long)ip[0] << 24) | - ((FT_Long)ip[1] << 16) | - ((FT_Long)ip[2] << 8) | ip[3]; + if ( ip + 3 >= limit ) + goto Syntax_Error; + val = ( (FT_Long)ip[0] << 24 ) | + ( (FT_Long)ip[1] << 16 ) | + ( (FT_Long)ip[2] << 8 ) | ip[3]; ip += 4; - shift = 0; + shift = 0; } - if (decoder->top - stack >= T2_MAX_OPERANDS) + if ( decoder->top - stack >= T2_MAX_OPERANDS ) goto Stack_Overflow; - - val <<= shift; - *decoder->top ++ = val; - - #ifdef FT_DEBUG_LEVEL_TRACE - if (!(val & 0xFFFF)) - FT_TRACE4(( " %d", (FT_Int)(val >> 16) )); + + val <<= shift; + *decoder->top++ = val; + +#ifdef FT_DEBUG_LEVEL_TRACE + if ( !( val & 0xFFFF ) ) + FT_TRACE4(( " %d", (FT_Int)( val >> 16 ) )); else FT_TRACE4(( " %.2f", val/65536.0 )); - #endif +#endif + } else { - FT_Fixed* args = decoder->top; - FT_Int num_args = args - decoder->stack; - FT_Int req_args; - + TT_Fixed* args = decoder->top; + TT_Int num_args = args - decoder->stack; + TT_Int req_args; + + /* find operator */ op = t2_op_unknown; - switch (v) + switch ( v ) { - case 1: op = t2_op_hstem; break; - case 3: op = t2_op_vstem; break; - case 4: op = t2_op_vmoveto; break; - case 5: op = t2_op_rlineto; break; - case 6: op = t2_op_hlineto; break; - case 7: op = t2_op_vlineto; break; - case 8: op = t2_op_rrcurveto; break; - case 10: op = t2_op_callsubr; break; - case 11: op = t2_op_return; break; - case 12: + case 1: + op = t2_op_hstem; + break; + case 3: + op = t2_op_vstem; + break; + case 4: + op = t2_op_vmoveto; + break; + case 5: + op = t2_op_rlineto; + break; + case 6: + op = t2_op_hlineto; + break; + case 7: + op = t2_op_vlineto; + break; + case 8: + op = t2_op_rrcurveto; + break; + case 10: + op = t2_op_callsubr; + break; + case 11: + op = t2_op_return; + break; + case 12: + { + if ( ip >= limit ) + goto Syntax_Error; + v = *ip++; + + switch ( v ) { - if (ip >= limit) goto Syntax_Error; - v = *ip++; - switch (v) - { - case 3: op = t2_op_and; break; - case 4: op = t2_op_or; break; - case 5: op = t2_op_not; break; - case 8: op = t2_op_store; break; - case 9: op = t2_op_abs; break; - case 10: op = t2_op_add; break; - case 11: op = t2_op_sub; break; - case 12: op = t2_op_div; break; - case 13: op = t2_op_load; break; - case 14: op = t2_op_neg; break; - case 15: op = t2_op_eq; break; - case 18: op = t2_op_drop; break; - case 20: op = t2_op_put; break; - case 21: op = t2_op_get; break; - case 22: op = t2_op_ifelse; break; - case 23: op = t2_op_random; break; - case 24: op = t2_op_mul; break; - case 26: op = t2_op_sqrt; break; - case 27: op = t2_op_dup; break; - case 28: op = t2_op_exch; break; - case 29: op = t2_op_index; break; - case 30: op = t2_op_roll; break; - case 34: op = t2_op_hflex; break; - case 35: op = t2_op_flex; break; - case 36: op = t2_op_hflex1; break; - case 37: op = t2_op_flex1; break; - default: - /* decrement ip for syntax error message */ - ip--; - } + case 3: + op = t2_op_and; + break; + case 4: + op = t2_op_or; + break; + case 5: + op = t2_op_not; + break; + case 8: + op = t2_op_store; + break; + case 9: + op = t2_op_abs; + break; + case 10: + op = t2_op_add; + break; + case 11: + op = t2_op_sub; + break; + case 12: + op = t2_op_div; + break; + case 13: + op = t2_op_load; + break; + case 14: + op = t2_op_neg; + break; + case 15: + op = t2_op_eq; + break; + case 18: + op = t2_op_drop; + break; + case 20: + op = t2_op_put; + break; + case 21: + op = t2_op_get; + break; + case 22: + op = t2_op_ifelse; + break; + case 23: + op = t2_op_random; + break; + case 24: + op = t2_op_mul; + break; + case 26: + op = t2_op_sqrt; + break; + case 27: + op = t2_op_dup; + break; + case 28: + op = t2_op_exch; + break; + case 29: + op = t2_op_index; + break; + case 30: + op = t2_op_roll; + break; + case 34: + op = t2_op_hflex; + break; + case 35: + op = t2_op_flex; + break; + case 36: + op = t2_op_hflex1; + break; + case 37: + op = t2_op_flex1; + break; + default: + /* decrement ip for syntax error message */ + ip--; } - break; - - case 14: op = t2_op_endchar; break; - case 16: op = t2_op_blend; break; - case 18: op = t2_op_hstemhm; break; - case 19: op = t2_op_hintmask; break; - case 20: op = t2_op_cntrmask; break; - case 21: op = t2_op_rmoveto; break; - case 22: op = t2_op_hmoveto; break; - case 23: op = t2_op_vstemhm; break; - case 24: op = t2_op_rcurveline; break; - case 25: op = t2_op_rlinecurve; break; - case 26: op = t2_op_vvcurveto; break; - case 27: op = t2_op_hhcurveto; break; - case 29: op = t2_op_callgsubr; break; - case 30: op = t2_op_vhcurveto; break; - case 31: op = t2_op_hvcurveto; break; - default: - ; + } + break; + case 14: + op = t2_op_endchar; + break; + case 16: + op = t2_op_blend; + break; + case 18: + op = t2_op_hstemhm; + break; + case 19: + op = t2_op_hintmask; + break; + case 20: + op = t2_op_cntrmask; + break; + case 21: + op = t2_op_rmoveto; + break; + case 22: + op = t2_op_hmoveto; + break; + case 23: + op = t2_op_vstemhm; + break; + case 24: + op = t2_op_rcurveline; + break; + case 25: + op = t2_op_rlinecurve; + break; + case 26: + op = t2_op_vvcurveto; + break; + case 27: + op = t2_op_hhcurveto; + break; + case 29: + op = t2_op_callgsubr; + break; + case 30: + op = t2_op_vhcurveto; + break; + case 31: + op = t2_op_hvcurveto; + break; + default: + ; } if ( op == t2_op_unknown ) goto Syntax_Error; /* check arguments */ req_args = count = t2_argument_counts[op]; - if (req_args & T2_COUNT_CHECK_WIDTH) + if ( req_args & T2_COUNT_CHECK_WIDTH ) { args = stack; if ( decoder->read_width ) { - decoder->glyph_width = decoder->nominal_width + (stack[0] >> 16); + decoder->glyph_width = decoder->nominal_width + + ( stack[0] >> 16 ); decoder->read_width = 0; num_args--; args++; } req_args = 0; } - + req_args &= 15; - if (num_args < req_args) goto Stack_Underflow; + if ( num_args < req_args ) + goto Stack_Underflow; args -= req_args; num_args -= req_args; - - switch (op) + + switch ( op ) { - case t2_op_hstem: - case t2_op_vstem: - case t2_op_hstemhm: - case t2_op_vstemhm: - { - /* if the number of arguments is no even, the first one */ - /* is simply the glyph width.. encoded as the difference */ - /* to nominalWidthX */ - FT_TRACE4(( op == t2_op_hstem ? " hstem" : - op == t2_op_vstem ? " vstem" : - op == t2_op_hstemhm ? " hstemhm" : - " vstemhm" )); - decoder->num_hints += num_args/2; - args = stack; - } - break; - - case t2_op_hintmask: - case t2_op_cntrmask: - { - FT_TRACE4(( op == t2_op_hintmask ? " hintmask" : " cntrmask" )); - decoder->num_hints += num_args/2; - ip += (decoder->num_hints+7) >> 3; - if (ip >= limit) goto Syntax_Error; - args = stack; - } - break; - - case t2_op_rmoveto: - { - FT_TRACE4(( " rmoveto" )); - close_contour( builder ); - builder->path_begun = 0; - x += args[0]; - y += args[1]; - args = stack; - } - break; - - case t2_op_vmoveto: - { - FT_TRACE4(( " vmoveto" )); - close_contour( builder ); - builder->path_begun = 0; - y += args[0]; - args = stack; - } - break; - - case t2_op_hmoveto: - { - FT_TRACE4(( " vmoveto" )); - close_contour( builder ); - builder->path_begun = 0; - x += args[0]; - args = stack; - } - break; - - case t2_op_rlineto: - { - FT_TRACE4(( " rlineto" )); + case t2_op_hstem: + case t2_op_vstem: + case t2_op_hstemhm: + case t2_op_vstemhm: + /* if the number of arguments is no even, the first one */ + /* is simply the glyph width.. encoded as the difference */ + /* to nominalWidthX */ + FT_TRACE4(( op == t2_op_hstem ? " hstem" : + op == t2_op_vstem ? " vstem" : + op == t2_op_hstemhm ? " hstemhm" : + " vstemhm" )); + decoder->num_hints += num_args / 2; + args = stack; + break; - if ( start_point ( builder, x, y ) || - check_points( builder, num_args/2 ) ) goto Memory_Error; + case t2_op_hintmask: + case t2_op_cntrmask: + FT_TRACE4(( op == t2_op_hintmask ? " hintmask" : + " cntrmask" )); - if ( num_args < 2 || num_args & 1 ) goto Stack_Underflow; - args = stack; - while ( args < decoder->top ) - { + decoder->num_hints += num_args / 2; + ip += ( decoder->num_hints + 7 ) >> 3; + if ( ip >= limit ) + goto Syntax_Error; + args = stack; + break; + + case t2_op_rmoveto: + FT_TRACE4(( " rmoveto" )); + + close_contour( builder ); + builder->path_begun = 0; + x += args[0]; + y += args[1]; + args = stack; + break; + + case t2_op_vmoveto: + FT_TRACE4(( " vmoveto" )); + + close_contour( builder ); + builder->path_begun = 0; + y += args[0]; + args = stack; + break; + + case t2_op_hmoveto: + FT_TRACE4(( " vmoveto" )); + + close_contour( builder ); + builder->path_begun = 0; + x += args[0]; + args = stack; + break; + + case t2_op_rlineto: + FT_TRACE4(( " rlineto" )); + + if ( start_point ( builder, x, y ) || + check_points( builder, num_args / 2 ) ) + goto Memory_Error; + + if ( num_args < 2 || num_args & 1 ) + goto Stack_Underflow; + + args = stack; + while ( args < decoder->top ) + { + x += args[0]; + y += args[1]; + add_point( builder, x, y, 1 ); + args += 2; + } + args = stack; + break; + + case t2_op_hlineto: + case t2_op_vlineto: + { + TT_Int phase = ( op == t2_op_hlineto ); + + + FT_TRACE4(( op == t2_op_hlineto ? " hlineto" : + " vlineto" )); + + if ( start_point ( builder, x, y ) || + check_points( builder, num_args ) ) + goto Memory_Error; + + args = stack; + while (args < decoder->top ) + { + if ( phase ) x += args[0]; - y += args[1]; - add_point( builder, x, y, 1 ); - args += 2; - } - args = stack; - } - break; - - case t2_op_hlineto: - case t2_op_vlineto: - { - FT_Int phase = ( op == t2_op_hlineto ); - - FT_TRACE4(( op == t2_op_hlineto ? " hlineto" : " vlineto" )); - - if ( start_point ( builder, x, y ) || - check_points( builder, num_args ) ) goto Memory_Error; - - args = stack; - while (args < decoder->top ) - { - if (phase) x += args[0]; - else y += args[0]; - - if (add_point1( builder, x, y )) goto Memory_Error; - args++; - phase ^= 1; - } - args = stack; - } - break; - - case t2_op_rrcurveto: - { - FT_TRACE4(( " rrcurveto" )); - - /* check number of arguments, must be a multiple of 6 */ - if (num_args % 6 != 0) goto Stack_Underflow; - - if ( start_point ( builder, x, y ) || - check_points( builder, num_args/2 ) ) goto Memory_Error; - - args = stack; - while (args < decoder->top) - { - x += args[0]; - y += args[1]; - add_point( builder, x, y, 0 ); - x += args[2]; - y += args[3]; - add_point( builder, x, y, 0 ); - x += args[4]; - y += args[5]; - add_point( builder, x, y, 1 ); - args += 6; - } - args = stack; - } - break; - - case t2_op_vvcurveto: - { - FT_TRACE4(( " vvcurveto" )); - - if ( start_point ( builder, x, y ) ) goto Memory_Error; - - args = stack; - if (num_args & 1) - { - x += args[0]; - args++; - num_args--; - } - if (num_args % 4 != 0) goto Stack_Underflow; - if (check_points( builder, 3*(num_args/4) )) goto Memory_Error; - - while (args < decoder->top) - { + else y += args[0]; + + if ( add_point1( builder, x, y ) ) + goto Memory_Error; + + args++; + phase ^= 1; + } + args = stack; + } + break; + + case t2_op_rrcurveto: + FT_TRACE4(( " rrcurveto" )); + + /* check number of arguments, must be a multiple of 6 */ + if ( num_args % 6 != 0 ) + goto Stack_Underflow; + + if ( start_point ( builder, x, y ) || + check_points( builder, num_args / 2 ) ) + goto Memory_Error; + + args = stack; + while ( args < decoder->top ) + { + x += args[0]; + y += args[1]; + add_point( builder, x, y, 0 ); + x += args[2]; + y += args[3]; + add_point( builder, x, y, 0 ); + x += args[4]; + y += args[5]; + add_point( builder, x, y, 1 ); + args += 6; + } + args = stack; + break; + + case t2_op_vvcurveto: + FT_TRACE4(( " vvcurveto" )); + + if ( start_point ( builder, x, y ) ) + goto Memory_Error; + + args = stack; + if ( num_args & 1 ) + { + x += args[0]; + args++; + num_args--; + } + + if ( num_args % 4 != 0 ) + goto Stack_Underflow; + + if ( check_points( builder, 3 * ( num_args / 4 ) ) ) + goto Memory_Error; + + while ( args < decoder->top ) + { + y += args[0]; + add_point( builder, x, y, 0 ); + x += args[1]; + y += args[2]; + add_point( builder, x, y, 0 ); + y += args[3]; + add_point( builder, x, y, 1 ); + args += 4; + } + args = stack; + break; + + case t2_op_hhcurveto: + FT_TRACE4(( " hhcurveto" )); + + if ( start_point ( builder, x, y ) ) + goto Memory_Error; + + args = stack; + if ( num_args & 1 ) + { + y += args[0]; + args++; + num_args--; + } + + if ( num_args % 4 != 0 ) + goto Stack_Underflow; + + if ( check_points( builder, 3 * ( num_args / 4 ) ) ) + goto Memory_Error; + + while ( args < decoder->top ) + { + x += args[0]; + add_point( builder, x, y, 0 ); + x += args[1]; + y += args[2]; + add_point( builder, x, y, 0 ); + x += args[3]; + add_point( builder, x, y, 1 ); + args += 4; + } + args = stack; + break; + + case t2_op_vhcurveto: + case t2_op_hvcurveto: + { + TT_Int phase; + + + FT_TRACE4(( op == t2_op_vhcurveto ? " vhcurveto" : + " hvcurveto" )); + + if ( start_point ( builder, x, y ) ) + goto Memory_Error; + + args = stack; + if (num_args < 4 || ( num_args % 4 ) > 1 ) + goto Stack_Underflow; + + if ( check_points( builder, ( num_args / 4 ) * 3 ) ) + goto Stack_Underflow; + + phase = ( op == t2_op_hvcurveto ); + while ( num_args >= 4 ) + { + num_args -= 4; + if ( phase ) + { + x += args[0]; add_point( builder, x, y, 0 ); x += args[1]; y += args[2]; add_point( builder, x, y, 0 ); y += args[3]; + if ( num_args == 1 ) + x += args[4]; add_point( builder, x, y, 1 ); - args += 4; } - args = stack; - } - break; - - case t2_op_hhcurveto: - { - FT_TRACE4(( " hhcurveto" )); - - if ( start_point ( builder, x, y ) ) goto Memory_Error; - args = stack; - if (num_args & 1) + else { y += args[0]; - args++; - num_args--; - } - if (num_args % 4 != 0) goto Stack_Underflow; - if (check_points( builder, 3*(num_args/4) )) goto Memory_Error; - - while (args < decoder->top) - { - x += args[0]; add_point( builder, x, y, 0 ); x += args[1]; y += args[2]; add_point( builder, x, y, 0 ); x += args[3]; - add_point( builder, x, y, 1 ); - args += 4; - } - args = stack; - } - break; - - case t2_op_vhcurveto: - case t2_op_hvcurveto: - { - FT_Int phase; - - FT_TRACE4(( op == t2_op_vhcurveto ? " vhcurveto" : " hvcurveto" )); - - if ( start_point ( builder, x, y ) ) goto Memory_Error; - args = stack; - if (num_args < 4 || (num_args % 4) > 1 ) goto Stack_Underflow; - if (check_points( builder, (num_args/4)*3 )) goto Stack_Underflow; - phase = ( op == t2_op_hvcurveto ); - while (num_args >= 4) - { - num_args -= 4; - if (phase) - { - x += args[0]; - add_point( builder, x, y, 0 ); - x += args[1]; - y += args[2]; - add_point( builder, x, y, 0 ); - y += args[3]; - if (num_args == 1) - x += args[4]; - add_point( builder, x, y, 1 ); - } - else - { - y += args[0]; - add_point( builder, x, y, 0 ); - x += args[1]; - y += args[2]; - add_point( builder, x, y, 0 ); - x += args[3]; - if (num_args == 1) - y += args[4]; - add_point( builder, x, y, 1 ); - } - args += 4; - phase ^= 1; - } - args = stack; - } - break; - - case t2_op_rlinecurve: - case t2_op_rcurveline: - { - FT_Int mod6 = num_args % 6; - - FT_TRACE4(( op == t2_op_rcurveline ? " rcurveline" : - " rlinecurve" )); - - if ( num_args < 8 || (mod6 != 0 && mod6 != 2) ) - goto Stack_Underflow; - - if ( start_point ( builder, x, y ) || - check_points( builder, (num_args/6)*3 + mod6/2 ) ) - goto Memory_Error; - - args = stack; - if (op == t2_op_rlinecurve && mod6) - { - x += args[0]; - y += args[1]; - add_point( builder, x, y, 1 ); - args += 2; - num_args -= 2; - } - while (num_args >= 6) - { - x += args[0]; - y += args[1]; - add_point( builder, x, y, 0 ); - x += args[2]; - y += args[3]; - add_point( builder, x, y, 0 ); - x += args[4]; - y += args[5]; - add_point( builder, x, y, 1 ); - args += 6; - num_args -= 6; - } - if ( op == t2_op_rcurveline && num_args) - { - x += args[0]; - y += args[1]; + if ( num_args == 1 ) + y += args[4]; add_point( builder, x, y, 1 ); } - args = stack; + args += 4; + phase ^= 1; } - break; - - case t2_op_endchar: - { - FT_TRACE4(( " endchar" )); - close_contour( builder ); - - /* add current outline to the glyph slot */ - builder->base.n_points += builder->current.n_points; - builder->base.n_contours += builder->current.n_contours; - - /* return now !! */ - FT_TRACE4(( "\n\n" )); - return FT_Err_Ok; - } - - case t2_op_abs: - { - FT_TRACE4(( " abs" )); - if (args[0] < 0) - args[0] = -args[0]; - args++; - } - break; - - case t2_op_add: - { - FT_TRACE4(( " add" )); - args[0] += args[1]; - args++; - } - break; - - case t2_op_sub: - { - FT_TRACE4(( " sub" )); - args[0] -= args[1]; - args++; - } - break; - - case t2_op_div: - { - FT_TRACE4(( " div" )); - args[0] = FT_DivFix( args[0], args[1] ); - args++; - } - break; - - case t2_op_neg: - { - FT_TRACE4(( " neg" )); - args[0] = -args[0]; - args++; - } - break; - - case t2_op_random: - { - FT_Fixed rand; - - FT_TRACE4(( " rand" )); - rand = seed; - if (rand >= 0x8000) - rand++; - - args[0] = rand; - seed = FT_MulFix( seed, 0x10000 - seed ); - if (seed == 0) seed += 0x2873; - args++; - } - break; - - case t2_op_mul: - { - FT_TRACE4(( " mul" )); - args[0] = FT_MulFix( args[0], args[1] ); - args++; - } - break; - - case t2_op_sqrt: - { - FT_TRACE4(( " sqrt" )); - if (args[0] > 0) - { - FT_Int count = 9; - FT_Fixed root = args[0]; - FT_Fixed new_root; - - for (;;) - { - new_root = ( root + FT_DivFix(args[0],root) + 1 ) >> 1; - if (new_root == root || count <= 0) - break; - root = new_root; - } - args[0] = new_root; - } - else - args[0] = 0; - args++; - } - break; - - case t2_op_drop: - { - /* nothing */ - FT_TRACE4(( " drop" )); - } - break; - - case t2_op_exch: - { - FT_Fixed tmp; - FT_TRACE4(( " exch" )); - tmp = args[0]; - args[0] = args[1]; - args[1] = tmp; - args += 2; - } - break; - - case t2_op_index: - { - FT_Int index = args[0] >> 16; - FT_TRACE4(( " index" )); - if (index < 0) - index = 0; - else if (index > num_args-2) - index = num_args-2; - args[0] = args[-(index+1)]; - args++; - } - break; - - case t2_op_roll: - { - FT_Int count = (FT_Int)(args[0] >> 16); - FT_Int index = (FT_Int)(args[1] >> 16); - - FT_TRACE4(( " roll" )); - - if (count <= 0) - count = 1; - - args -= count; - if (args < stack) goto Stack_Underflow; - if (index >= 0) - { - while (index > 0) - { - FT_Fixed tmp = args[count-1]; - FT_Int i; - for ( i = count-2; i >= 0; i-- ) - args[i+1] = args[i]; - args[0] = tmp; - index--; - } - } - else - { - while (index < 0) - { - FT_Fixed tmp = args[0]; - FT_Int i; - for ( i = 0; i < count-1; i++ ) - args[i] = args[i+1]; - args[count-1] = tmp; - index++; - } - } - args += count; - } - break; - - case t2_op_dup: - { - FT_TRACE4(( " dup" )); - args[1] = args[0]; - args++; - } - break; - - case t2_op_put: - { - FT_Fixed val = args[0]; - FT_Int index = (FT_Int)(args[1] >> 16); - - FT_TRACE4(( " put" )); - if (index >= 0 && index < decoder->len_buildchar) - decoder->buildchar[index] = val; - } - break; - - case t2_op_get: - { - FT_Int index = (FT_Int)(args[0] >> 16); - FT_Fixed val = 0; - FT_TRACE4(( " get" )); - - if (index >= 0 && index < decoder->len_buildchar) - val = decoder->buildchar[index]; - - args[0] = val; - args++; - } - break; + args = stack; + } + break; - case t2_op_store: - FT_TRACE4(( " store ")); - goto Unimplemented; - - case t2_op_load: + case t2_op_rlinecurve: + case t2_op_rcurveline: + { + TT_Int mod6 = num_args % 6; + + + FT_TRACE4(( op == t2_op_rcurveline ? " rcurveline" : + " rlinecurve" )); + + if ( num_args < 8 || ( mod6 != 0 && mod6 != 2 ) ) + goto Stack_Underflow; + + if ( start_point ( builder, x, y ) || + check_points( builder, ( num_args / 6 ) * 3 + mod6 / 2 ) ) + goto Memory_Error; + + args = stack; + if ( op == t2_op_rlinecurve && mod6 ) + { + x += args[0]; + y += args[1]; + add_point( builder, x, y, 1 ); + args += 2; + num_args -= 2; + } + + while ( num_args >= 6 ) + { + x += args[0]; + y += args[1]; + add_point( builder, x, y, 0 ); + x += args[2]; + y += args[3]; + add_point( builder, x, y, 0 ); + x += args[4]; + y += args[5]; + add_point( builder, x, y, 1 ); + args += 6; + num_args -= 6; + } + + if ( op == t2_op_rcurveline && num_args ) + { + x += args[0]; + y += args[1]; + add_point( builder, x, y, 1 ); + } + args = stack; + } + break; + + case t2_op_endchar: + FT_TRACE4(( " endchar" )); + + close_contour( builder ); + + /* add current outline to the glyph slot */ + builder->base.n_points += builder->current.n_points; + builder->base.n_contours += builder->current.n_contours; + + /* return now! */ + FT_TRACE4(( "\n\n" )); + return T2_Err_Ok; + + case t2_op_abs: + FT_TRACE4(( " abs" )); + + if ( args[0] < 0 ) + args[0] = -args[0]; + args++; + break; + + case t2_op_add: + FT_TRACE4(( " add" )); + + args[0] += args[1]; + args++; + break; + + case t2_op_sub: + FT_TRACE4(( " sub" )); + + args[0] -= args[1]; + args++; + break; + + case t2_op_div: + FT_TRACE4(( " div" )); + + args[0] = FT_DivFix( args[0], args[1] ); + args++; + break; + + case t2_op_neg: + FT_TRACE4(( " neg" )); + + args[0] = -args[0]; + args++; + break; + + case t2_op_random: + { + TT_Fixed rand; + + + FT_TRACE4(( " rand" )); + + rand = seed; + if ( rand >= 0x8000 ) + rand++; + + args[0] = rand; + seed = FT_MulFix( seed, 0x10000L - seed ); + if ( seed == 0 ) + seed += 0x2873; + args++; + } + break; + + case t2_op_mul: + FT_TRACE4(( " mul" )); + + args[0] = FT_MulFix( args[0], args[1] ); + args++; + break; + + case t2_op_sqrt: + FT_TRACE4(( " sqrt" )); + + if ( args[0] > 0 ) + { + TT_Int count = 9; + TT_Fixed root = args[0]; + TT_Fixed new_root; + + + for (;;) + { + new_root = ( root + FT_DivFix(args[0],root) + 1 ) >> 1; + if ( new_root == root || count <= 0 ) + break; + root = new_root; + } + args[0] = new_root; + } + else + args[0] = 0; + args++; + break; + + case t2_op_drop: + /* nothing */ + FT_TRACE4(( " drop" )); + break; + + case t2_op_exch: + { + TT_Fixed tmp; + + + FT_TRACE4(( " exch" )); + + tmp = args[0]; + args[0] = args[1]; + args[1] = tmp; + args += 2; + } + break; + + case t2_op_index: + { + TT_Int index = args[0] >> 16; + + + FT_TRACE4(( " index" )); + + if ( index < 0 ) + index = 0; + else if ( index > num_args - 2 ) + index = num_args - 2; + args[0] = args[-( index + 1 )]; + args++; + } + break; + + case t2_op_roll: + { + TT_Int count = (FT_Int)( args[0] >> 16 ); + TT_Int index = (FT_Int)( args[1] >> 16 ); + + + FT_TRACE4(( " roll" )); + + if ( count <= 0 ) + count = 1; + + args -= count; + if ( args < stack ) + goto Stack_Underflow; + + if ( index >= 0 ) + { + while ( index > 0 ) + { + TT_Fixed tmp = args[count - 1]; + TT_Int i; + + + for ( i = count - 2; i >= 0; i-- ) + args[i + 1] = args[i]; + args[0] = tmp; + index--; + } + } + else + { + while (index < 0) + { + TT_Fixed tmp = args[0]; + TT_Int i; + + + for ( i = 0; i < count - 1; i++ ) + args[i] = args[i + 1]; + args[count - 1] = tmp; + index++; + } + } + args += count; + } + break; + + case t2_op_dup: + FT_TRACE4(( " dup" )); + + args[1] = args[0]; + args++; + break; + + case t2_op_put: + { + TT_Fixed val = args[0]; + TT_Int index = (FT_Int)( args[1] >> 16 ); + + + FT_TRACE4(( " put" )); + if ( index >= 0 && index < decoder->len_buildchar ) + decoder->buildchar[index] = val; + } + break; + + case t2_op_get: + { + FT_Int index = (FT_Int)( args[0] >> 16 ); + FT_Fixed val = 0; + + + FT_TRACE4(( " get" )); + + if ( index >= 0 && index < decoder->len_buildchar ) + val = decoder->buildchar[index]; + + args[0] = val; + args++; + } + break; + + case t2_op_store: + FT_TRACE4(( " store ")); + + goto Unimplemented; + + case t2_op_load: FT_TRACE4(( " load" )); - goto Unimplemented; - case t2_op_and: - { - FT_Fixed cond = args[0] && args[1]; - FT_TRACE4(( " and" )); - args[0] = cond ? 0x10000 : 0; - args++; - } - break; + goto Unimplemented; - case t2_op_or: - { - FT_Fixed cond = args[0] || args[1]; - FT_TRACE4(( " or" )); - args[0] = cond ? 0x10000 : 0; - args++; - } - break; - - case t2_op_eq: - { - FT_Fixed cond = !args[0]; - FT_TRACE4(( " eq" )); - args[0] = cond ? 0x10000 : 0; - args++; - } - break; - - case t2_op_ifelse: - { - FT_Fixed cond = args[2] <= args[3]; - FT_TRACE4(( " ifelse" )); - if (!cond) - args[0] = args[1]; - args++; - } - break; - - case t2_op_callsubr: - { - FT_UInt index = (FT_UInt)((args[0] >> 16) + decoder->locals_bias); - - FT_TRACE4(( " callsubr(%d)", index )); - if (index >= decoder->num_locals) - { - FT_ERROR(( "T2.Parse_Charstrings: invalid local subr index\n" )); - goto Syntax_Error; - } - - if ( zone - decoder->zones >= T2_MAX_SUBRS_CALLS ) - { - FT_ERROR(( "T2.Parse_CharStrings : too many nested subrs\n" )); - goto Syntax_Error; - } - - zone->cursor = ip; /* save current instruction pointer */ - - zone++; - zone->base = decoder->locals[index]; - zone->limit = decoder->locals[index+1]; - zone->cursor = zone->base; - - if (!zone->base) - { - FT_ERROR(( "T2.Parse_CharStrings : invoking empty subrs !!\n" )); - goto Syntax_Error; - } - - decoder->zone = zone; - ip = zone->base; - limit = zone->limit; - } - break; - - case t2_op_callgsubr: - { - FT_UInt index = (FT_UInt)((args[0] >> 16) + decoder->globals_bias); - - FT_TRACE4(( " callgsubr(%d)", index )); - if (index >= decoder->num_globals) - { - FT_ERROR(( "T2.Parse_Charstrings: invalid global subr index\n" )); - goto Syntax_Error; - } + case t2_op_and: + { + FT_Fixed cond = args[0] && args[1]; - if ( zone - decoder->zones >= T2_MAX_SUBRS_CALLS ) - { - FT_ERROR(( "T2.Parse_CharStrings : too many nested subrs\n" )); - goto Syntax_Error; - } - - zone->cursor = ip; /* save current instruction pointer */ - - zone++; - zone->base = decoder->globals[index]; - zone->limit = decoder->globals[index+1]; - zone->cursor = zone->base; - - if (!zone->base) - { - FT_ERROR(( "T2.Parse_CharStrings : invoking empty subrs !!\n" )); - goto Syntax_Error; - } - - decoder->zone = zone; - ip = zone->base; - limit = zone->limit; - } - break; - - case t2_op_return: - { - FT_TRACE4(( " return" )); - if ( decoder->zone <= decoder->zones ) - { - FT_ERROR(( "T2.Parse_CharStrings : unexpected return\n" )); - goto Syntax_Error; - } - - decoder->zone--; - zone = decoder->zone; - ip = zone->cursor; - limit = zone->limit; - } - break; - default: - - Unimplemented: - FT_ERROR(( "Unimplemented opcode: %d", ip[-1] )); - if (ip[-1] == 12) - { - FT_ERROR(( " %d", ip[0] )); - } - FT_ERROR(( "\n" )); - return FT_Err_Unimplemented_Feature; + FT_TRACE4(( " and" )); + + args[0] = cond ? 0x10000L : 0; + args++; + } + break; + + case t2_op_or: + { + FT_Fixed cond = args[0] || args[1]; + + + FT_TRACE4(( " or" )); + + args[0] = cond ? 0x10000L : 0; + args++; + } + break; + + case t2_op_eq: + { + FT_Fixed cond = !args[0]; + + + FT_TRACE4(( " eq" )); + + args[0] = cond ? 0x10000L : 0; + args++; + } + break; + + case t2_op_ifelse: + { + FT_Fixed cond = (args[2] <= args[3]); + + + FT_TRACE4(( " ifelse" )); + + if ( !cond ) + args[0] = args[1]; + args++; + } + break; + + case t2_op_callsubr: + { + TT_UInt index = (FT_UInt)( ( args[0] >> 16 ) + + decoder->locals_bias ); + + + FT_TRACE4(( " callsubr(%d)", index )); + + if ( index >= decoder->num_locals ) + { + FT_ERROR(( "T2_Parse_Charstrings: invalid local subr index\n" )); + goto Syntax_Error; + } + + if ( zone - decoder->zones >= T2_MAX_SUBRS_CALLS ) + { + FT_ERROR(( "T2_Parse_CharStrings: too many nested subrs\n" )); + goto Syntax_Error; + } + + zone->cursor = ip; /* save current instruction pointer */ + + zone++; + zone->base = decoder->locals[index]; + zone->limit = decoder->locals[index+1]; + zone->cursor = zone->base; + + if ( !zone->base ) + { + FT_ERROR(( "T2_Parse_CharStrings: invoking empty subrs!\n" )); + goto Syntax_Error; + } + + decoder->zone = zone; + ip = zone->base; + limit = zone->limit; + } + break; + + case t2_op_callgsubr: + { + TT_UInt index = (FT_UInt)( ( args[0] >> 16 ) + + decoder->globals_bias ); + + + FT_TRACE4(( " callgsubr(%d)", index )); + + if ( index >= decoder->num_globals ) + { + FT_ERROR(( "T2_Parse_Charstrings: invalid global subr index\n" )); + goto Syntax_Error; + } + + if ( zone - decoder->zones >= T2_MAX_SUBRS_CALLS ) + { + FT_ERROR(( "T2_Parse_CharStrings: too many nested subrs\n" )); + goto Syntax_Error; + } + + zone->cursor = ip; /* save current instruction pointer */ + + zone++; + zone->base = decoder->globals[index]; + zone->limit = decoder->globals[index+1]; + zone->cursor = zone->base; + + if ( !zone->base ) + { + FT_ERROR(( "T2_Parse_CharStrings: invoking empty subrs!\n" )); + goto Syntax_Error; + } + + decoder->zone = zone; + ip = zone->base; + limit = zone->limit; + } + break; + + case t2_op_return: + FT_TRACE4(( " return" )); + + if ( decoder->zone <= decoder->zones ) + { + FT_ERROR(( "T2_Parse_CharStrings: unexpected return\n" )); + goto Syntax_Error; + } + + decoder->zone--; + zone = decoder->zone; + ip = zone->cursor; + limit = zone->limit; + break; + + default: + Unimplemented: + FT_ERROR(( "Unimplemented opcode: %d", ip[-1] )); + + if ( ip[-1] == 12 ) + FT_ERROR(( " %d", ip[0] )); + FT_ERROR(( "\n" )); + return T2_Err_Unimplemented_Feature; } - decoder->top = args; - + + decoder->top = args; + } /* general operator processing */ } /* while ip < limit */ + FT_TRACE4(( "..end..\n\n" )); + return error; Syntax_Error: - return FT_Err_Invalid_File_Format; + return T2_Err_Invalid_File_Format; Stack_Underflow: return T2_Err_Too_Few_Arguments; Stack_Overflow: return T2_Err_Stack_Overflow; - + Memory_Error: return builder->error; } + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********** *********/ + /********** *********/ + /********** COMPUTE THE MAXIMUM ADVANCE WIDTH *********/ + /********** *********/ + /********** The following code is in charge of computing *********/ + /********** the maximum advance width of the font. It *********/ + /********** quickly processes each glyph charstring to *********/ + /********** extract the value from either a `sbw' or `seac' *********/ + /********** operator. *********/ + /********** *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ - /**********************************************************************/ - /**********************************************************************/ - /**********************************************************************/ - /********** *********/ - /********** *********/ - /********** COMPUTE THE MAXIMUM ADVANCE WIDTH *********/ - /********** *********/ - /********** The following code is in charge of computing *********/ - /********** the maximum advance width of the font. It *********/ - /********** quickly process each glyph charstring to *********/ - /********** extract the value from either a "sbw" or "seac" *********/ - /********** operator. *********/ - /********** *********/ - /**********************************************************************/ - /**********************************************************************/ - /**********************************************************************/ #if 0 /* unused until we support pure CFF fonts */ + + LOCAL_FUNC - FT_Error T2_Compute_Max_Advance( TT_Face face, - FT_Int *max_advance ) + TT_Error T2_Compute_Max_Advance( TT_Face face, + TT_Int* max_advance ) { - FT_Error error = 0; + TT_Error error = 0; T2_Decoder decoder; - FT_Int glyph_index; + TT_Int glyph_index; CFF_Font* cff = (CFF_Font*)face->other; + *max_advance = 0; - /* Initialise load decoder */ + /* Initialize load decoder */ T2_Init_Decoder( &decoder, face, 0, 0 ); decoder.builder.metrics_only = 1; decoder.builder.load_points = 0; /* For each glyph, parse the glyph charstring and extract */ - /* the advance width.. */ - for ( glyph_index = 0; glyph_index < face->root.num_glyphs; glyph_index++ ) + /* the advance width. */ + for ( glyph_index = 0; glyph_index < face->root.num_glyphs; + glyph_index++ ) { - FT_Byte* charstring; - FT_ULong charstring_len; - + TT_Byte* charstring; + TT_ULong charstring_len; + + /* now get load the unscaled outline */ error = T2_Access_Element( &cff->charstrings_index, glyph_index, &charstring, &charstring_len ); - if (!error) + if ( !error ) { error = T2_Parse_CharStrings( &decoder, charstring, charstring_len ); - + T2_Forget_Element( &cff->charstrings_index, &charstring ); } - /* ignore the error if one occured - skip to next glyph */ + + /* ignore the error if one has occured - skip to next glyph */ error = 0; } *max_advance = decoder.builder.advance.x; - return FT_Err_Ok; - } -#endif - /**********************************************************************/ - /**********************************************************************/ - /**********************************************************************/ - /********** *********/ - /********** *********/ - /********** UNHINTED GLYPH LOADER *********/ - /********** *********/ - /********** The following code is in charge of loading a *********/ - /********** single outline. It completely ignores hinting *********/ - /********** and is used when FT_LOAD_NO_HINTING is set. *********/ - /********** *********/ - /**********************************************************************/ - /**********************************************************************/ - /**********************************************************************/ + return T2_Err_Ok; + } + + +#endif /* 0 */ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********** *********/ + /********** *********/ + /********** UNHINTED GLYPH LOADER *********/ + /********** *********/ + /********** The following code is in charge of loading a *********/ + /********** single outline. It completely ignores hinting *********/ + /********** and is used when FT_LOAD_NO_HINTING is set. *********/ + /********** *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ LOCAL_FUNC - FT_Error T2_Load_Glyph( T2_GlyphSlot glyph, + TT_Error T2_Load_Glyph( T2_GlyphSlot glyph, T2_Size size, - FT_Int glyph_index, - FT_Int load_flags ) + TT_Int glyph_index, + TT_Int load_flags ) { - FT_Error error; - T2_Decoder decoder; - TT_Face face = (TT_Face)glyph->root.face; - FT_Bool hinting; - CFF_Font* cff = (CFF_Font*)face->other; + TT_Error error; + T2_Decoder decoder; + TT_Face face = (TT_Face)glyph->root.face; + TT_Bool hinting; + CFF_Font* cff = (CFF_Font*)face->other; - if (load_flags & FT_LOAD_NO_RECURSE) + + if ( load_flags & FT_LOAD_NO_RECURSE ) load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; glyph->x_scale = size->metrics.x_scale; @@ -1472,18 +1694,20 @@ { FT_Byte* charstring; FT_ULong charstring_len; - + + T2_Init_Decoder( &decoder, face, size, glyph ); - decoder.builder.no_recurse = (FT_Bool)!!(load_flags & FT_LOAD_NO_RECURSE); + decoder.builder.no_recurse = + (FT_Bool)( load_flags & FT_LOAD_NO_RECURSE ); /* now load the unscaled outline */ error = T2_Access_Element( &cff->charstrings_index, glyph_index, &charstring, &charstring_len ); - if (!error) + if ( !error ) { error = T2_Parse_CharStrings( &decoder, charstring, charstring_len ); - + T2_Forget_Element( &cff->charstrings_index, &charstring ); } @@ -1491,34 +1715,36 @@ T2_Done_Builder( &decoder.builder ); } - /* Now, set the metrics.. - this is rather simple, as : */ - /* the left side bearing is the xMin, and the top side */ - /* bearing the yMax.. */ - if (!error) + /* Now, set the metrics - this is rather simple, as */ + /* the left side bearing is the xMin, and the top side */ + /* bearing the yMax. */ + if ( !error ) { /* for composite glyphs, return only the left side bearing and the */ /* advance width.. */ if ( load_flags & FT_LOAD_NO_RECURSE ) { -#if 0 +#if 0 glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x; glyph->root.metrics.horiAdvance = decoder.builder.advance.x; #else glyph->root.metrics.horiBearingX = decoder.builder.left_bearing.x; glyph->root.metrics.horiAdvance = decoder.glyph_width; -#endif +#endif /* 0 */ } else { FT_BBox cbox; FT_Glyph_Metrics* metrics = &glyph->root.metrics; + /* copy the _unscaled_ advance width */ -#if 0 +#if 0 metrics->horiAdvance = decoder.builder.advance.x; #else metrics->horiAdvance = decoder.glyph_width; -#endif +#endif /* 0 */ + /* make up vertical metrics */ metrics->vertBearingX = 0; metrics->vertBearingY = 0; @@ -1532,20 +1758,21 @@ glyph->root.outline.flags |= ft_outline_reverse_fill; - /* +#if 0 glyph->root.outline.second_pass = TRUE; - glyph->root.outline.high_precision = ( size->root.metrics.y_ppem < 24 ); + glyph->root.outline.high_precision = size->root.metrics.y_ppem < 24; glyph->root.outline.dropout_mode = 2; - */ +#endif - if ( (load_flags & FT_LOAD_NO_SCALE) == 0 ) + if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 ) { /* scale the outline and the metrics */ - FT_Int n; - FT_Outline* cur = &decoder.builder.base; - FT_Vector* vec = cur->points; - FT_Fixed x_scale = glyph->x_scale; - FT_Fixed y_scale = glyph->y_scale; + TT_Int n; + FT_Outline* cur = &decoder.builder.base; + TT_Vector* vec = cur->points; + TT_Fixed x_scale = glyph->x_scale; + TT_Fixed y_scale = glyph->y_scale; + /* First of all, scale the points */ for ( n = cur->n_points; n > 0; n--, vec++ ) @@ -1565,13 +1792,15 @@ } /* apply the font matrix */ - /* FT_Outline_Transform( &glyph->root.outline, cff->font_matrix ); */ +#if 0 + FT_Outline_Transform( &glyph->root.outline, cff->font_matrix ); +#endif /* compute the other metrics */ FT_Outline_Get_CBox( &glyph->root.outline, &cbox ); /* grid fit the bounding box if necessary */ - if (hinting) + if ( hinting ) { cbox.xMin &= -64; cbox.yMin &= -64; @@ -1586,7 +1815,9 @@ metrics->horiBearingY = cbox.yMax; } } + return error; } + /* END */ diff --git a/src/cff/t2gload.h b/src/cff/t2gload.h index aa1c9a310..07329fb80 100644 --- a/src/cff/t2gload.h +++ b/src/cff/t2gload.h @@ -4,11 +4,11 @@ /* */ /* OpenType Glyph Loader (specification). */ /* */ -/* Copyright 1996-1999 by */ +/* Copyright 1996-2000 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ -/* This file is part of the FreeType project, and may only be used */ -/* modified and distributed under the terms of the FreeType project */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ /* this file you indicate that you have read the license and */ /* understand and accept it fully. */ @@ -19,55 +19,71 @@ #ifndef T2GLOAD_H #define T2GLOAD_H +#include #include #ifdef __cplusplus extern "C" { #endif - #define T2_MAX_OPERANDS 48 - #define T2_MAX_SUBRS_CALLS 32 -/*************************************************************************/ -/* */ -/* T2_Builder */ -/* */ -/* */ -/* a structure used during glyph loading to store its outline. */ -/* */ -/* */ -/* system :: current system object */ -/* face :: current face object */ -/* glyph :: current glyph slot */ -/* */ -/* current :: current glyph outline */ -/* base :: base glyph outline */ -/* */ -/* max_points :: maximum points in builder outline */ -/* max_contours :: maximum contours in builder outline */ -/* */ -/* last :: last point position */ -/* */ -/* scale_x :: horizontal scale ( FUnits to sub-pixels ) */ -/* scale_y :: vertical scale ( FUnits to sub-pixels ) */ -/* pos_x :: horizontal translation (composite glyphs) */ -/* pos_y :: vertical translation (composite glyph) */ -/* */ -/* left_bearing :: left side bearing point */ -/* advance :: horizontal advance vector */ -/* */ -/* path_begun :: flag, indicates that a new path has begun */ -/* load_points :: flag, if not set, no points are loaded */ -/* */ -/* error :: an error code that is only used to report */ -/* memory allocation problems.. */ -/* */ -/* metrics_only :: a boolean indicating that we only want to */ -/* compute the metrics of a given glyph, not load */ -/* all of its points.. */ -/* */ +#define T2_MAX_OPERANDS 48 +#define T2_MAX_SUBRS_CALLS 32 - typedef struct T2_Builder_ + + /*************************************************************************/ + /* */ + /* */ + /* T2_Builder */ + /* */ + /* */ + /* A structure used during glyph loading to store its outline. */ + /* */ + /* */ + /* memory :: The current memory object. */ + /* */ + /* face :: The current face object. */ + /* */ + /* glyph :: The current glyph slot. */ + /* */ + /* current :: The current glyph outline. */ + /* */ + /* base :: The base glyph outline. */ + /* */ + /* max_points :: maximum points in builder outline */ + /* */ + /* max_contours :: Maximal number of contours in builder outline. */ + /* */ + /* last :: The last point position. */ + /* */ + /* scale_x :: The horizontal scale (FUnits to sub-pixels). */ + /* */ + /* scale_y :: The vertical scale (FUnits to sub-pixels). */ + /* */ + /* pos_x :: The horizontal translation (if composite glyph). */ + /* */ + /* pos_y :: The vertical translation (if composite glyph). */ + /* */ + /* left_bearing :: The left side bearing point. */ + /* */ + /* advance :: The horizontal advance vector. */ + /* */ + /* bbox :: Unused. */ + /* */ + /* path_begun :: A flag which indicates that a new path has begun. */ + /* */ + /* load_points :: If this flag is not set, no points are loaded. */ + /* */ + /* no_recurse :: Set but not used. */ + /* */ + /* error :: An error code that is only used to report memory */ + /* allocation problems. */ + /* */ + /* metrics_only :: A boolean indicating that we only want to compute */ + /* the metrics of a given glyph, not load all of its */ + /* points. */ + /* */ + typedef struct T2_Builder_ { FT_Memory memory; TT_Face face; @@ -76,107 +92,104 @@ FT_Outline current; /* the current glyph outline */ FT_Outline base; /* the composite glyph outline */ - FT_Int max_points; /* capacity of base outline in points */ - FT_Int max_contours; /* capacity of base outline in contours */ + TT_Int max_points; /* capacity of base outline in points */ + TT_Int max_contours; /* capacity of base outline in contours */ - FT_Vector last; + TT_Vector last; - FT_Fixed scale_x; - FT_Fixed scale_y; + TT_Fixed scale_x; + TT_Fixed scale_y; - FT_Pos pos_x; - FT_Pos pos_y; + TT_Pos pos_x; + TT_Pos pos_y; - FT_Vector left_bearing; - FT_Vector advance; + TT_Vector left_bearing; + TT_Vector advance; - FT_BBox bbox; /* bounding box */ - FT_Bool path_begun; - FT_Bool load_points; - FT_Bool no_recurse; + TT_BBox bbox; /* bounding box */ + TT_Bool path_begun; + TT_Bool load_points; + TT_Bool no_recurse; - FT_Error error; /* only used for memory errors */ - FT_Bool metrics_only; + TT_Error error; /* only used for memory errors */ + TT_Bool metrics_only; } T2_Builder; /* execution context charstring zone */ - typedef struct T2_Decoder_Zone_ + + typedef struct T2_Decoder_Zone_ { - FT_Byte* base; - FT_Byte* limit; - FT_Byte* cursor; + TT_Byte* base; + TT_Byte* limit; + TT_Byte* cursor; } T2_Decoder_Zone; - typedef struct T2_Decoder_ + typedef struct T2_Decoder_ { - T2_Builder builder; - CFF_Font* cff; + T2_Builder builder; + CFF_Font* cff; - FT_Fixed stack[ T2_MAX_OPERANDS+1 ]; - FT_Fixed* top; + TT_Fixed stack[T2_MAX_OPERANDS + 1]; + TT_Fixed* top; - T2_Decoder_Zone zones[ T2_MAX_SUBRS_CALLS+1 ]; - T2_Decoder_Zone* zone; + T2_Decoder_Zone zones[T2_MAX_SUBRS_CALLS + 1]; + T2_Decoder_Zone* zone; - FT_Int flex_state; - FT_Int num_flex_vectors; - FT_Vector flex_vectors[7]; + TT_Int flex_state; + TT_Int num_flex_vectors; + TT_Vector flex_vectors[7]; - FT_Pos glyph_width; - FT_Pos nominal_width; - - FT_Bool read_width; - FT_Int num_hints; - FT_Fixed* buildchar; - FT_Int len_buildchar; + TT_Pos glyph_width; + TT_Pos nominal_width; - FT_UInt num_locals; - FT_UInt num_globals; - - FT_Int locals_bias; - FT_Int globals_bias; - - FT_Byte** locals; - FT_Byte** globals; + TT_Bool read_width; + TT_Int num_hints; + TT_Fixed* buildchar; + TT_Int len_buildchar; + TT_UInt num_locals; + TT_UInt num_globals; + + TT_Int locals_bias; + TT_Int globals_bias; + + TT_Byte** locals; + TT_Byte** globals; } T2_Decoder; - LOCAL_DEF - void T2_Init_Decoder( T2_Decoder* decoder, - TT_Face face, - T2_Size size, - T2_GlyphSlot slot ); + void T2_Init_Decoder( T2_Decoder* decoder, + TT_Face face, + T2_Size size, + T2_GlyphSlot slot ); #if 0 /* unused until we support pure CFF fonts */ + /* Compute the maximum advance width of a font through quick parsing */ LOCAL_DEF - FT_Error T2_Compute_Max_Advance( TT_Face face, - FT_Int *max_advance ); + TT_Error T2_Compute_Max_Advance( TT_Face face, + TT_Int* max_advance ); + #endif /* This function is exported, because it is used by the T1Dump utility */ LOCAL_DEF - FT_Error T2_Parse_CharStrings( T2_Decoder* decoder, - FT_Byte* charstring_base, - FT_Int charstring_len ); - - + TT_Error T2_Parse_CharStrings( T2_Decoder* decoder, + TT_Byte* charstring_base, + TT_Int charstring_len ); LOCAL_DEF - FT_Error T2_Load_Glyph( T2_GlyphSlot glyph, + TT_Error T2_Load_Glyph( T2_GlyphSlot glyph, T2_Size size, - FT_Int glyph_index, - FT_Int load_flags ); - - + TT_Int glyph_index, + TT_Int load_flags ); #ifdef __cplusplus diff --git a/src/cff/t2load.c b/src/cff/t2load.c index 69db32f39..d5e990b8b 100644 --- a/src/cff/t2load.c +++ b/src/cff/t2load.c @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -39,37 +39,42 @@ /* read a CFF offset from memory */ static - FT_ULong t2_get_offset( FT_Byte* p, - FT_Byte off_size ) + TT_ULong t2_get_offset( TT_Byte* p, + TT_Byte off_size ) { - FT_ULong result; + TT_ULong result; + + for ( result = 0; off_size > 0; off_size-- ) - result = (result <<= 8) | *p++; + result = ( result <<= 8 ) | *p++; + return result; } - static - FT_Error t2_new_cff_index( CFF_Index* index, + TT_Error t2_new_cff_index( CFF_Index* index, FT_Stream stream, - FT_Bool load ) + TT_Bool load ) { - FT_Error error; + TT_Error error; FT_Memory memory = stream->memory; - FT_UShort count; + TT_UShort count; + + + MEM_Set( index, 0, sizeof ( *index ) ); - MEM_Set( index, 0, sizeof(*index) ); index->stream = stream; if ( !READ_UShort( count ) && count > 0 ) { - FT_Byte* p; - FT_Byte offsize; - FT_ULong data_size; - FT_ULong* poff; + TT_Byte* p; + TT_Byte offsize; + TT_ULong data_size; + TT_ULong* poff; - /* there is at least one element, read the offset size */ + + /* there is at least one element; read the offset size */ /* then access the offset table to compute the index's total size */ if ( READ_Byte( offsize ) ) goto Exit; @@ -77,15 +82,16 @@ index->stream = stream; index->count = count; index->off_size = offsize; - data_size = (FT_ULong)(count+1) * offsize; + data_size = (TT_ULong)( count + 1 ) * offsize; - if ( ALLOC_ARRAY( index->offsets, count+1, FT_ULong ) || - ACCESS_Frame( data_size )) + if ( ALLOC_ARRAY( index->offsets, count + 1, FT_ULong ) || + ACCESS_Frame( data_size ) ) goto Exit; poff = index->offsets; - p = (FT_Byte*)stream->cursor; - for ( ; (FT_Short)count >= 0; count-- ) + p = (TT_Byte*)stream->cursor; + + for ( ; (TT_Short)count >= 0; count-- ) { poff[0] = t2_get_offset( p, offsize ); poff++; @@ -95,9 +101,9 @@ FORGET_Frame(); index->data_offset = FILE_Pos(); - data_size = poff[-1]-1; + data_size = poff[-1] - 1; - if (load) + if ( load ) { /* load the data */ if ( EXTRACT_Frame( data_size, index->bytes ) ) @@ -109,8 +115,9 @@ (void)FILE_Skip( data_size ); } } + Exit: - if (error) + if ( error ) FREE( index->offsets ); return error; @@ -124,88 +131,96 @@ { FT_Stream stream = index->stream; FT_Memory memory = stream->memory; - - if (index->bytes) + + + if ( index->bytes ) RELEASE_Frame( index->bytes ); FREE( index->offsets ); - MEM_Set( index, 0, sizeof(*index) ); + MEM_Set( index, 0, sizeof ( *index ) ); } } static - FT_Error t2_explicit_cff_index( CFF_Index* index, - FT_Byte** *table ) + TT_Error t2_explicit_cff_index( CFF_Index* index, + TT_Byte*** table ) { - FT_Error error = 0; - FT_Memory memory = index->stream->memory; - FT_UInt n, offset, old_offset; - FT_Byte** t; + TT_Error error = 0; + FT_Memory memory = index->stream->memory; + TT_UInt n, offset, old_offset; + TT_Byte** t; - *table = 0; - if ( index->count > 0 && !ALLOC_ARRAY( t, index->count+1, FT_Byte* ) ) + + *table = 0; + + if ( index->count > 0 && !ALLOC_ARRAY( t, index->count + 1, TT_Byte* ) ) { old_offset = 1; for ( n = 0; n <= index->count; n++ ) { offset = index->offsets[n]; - if (!offset) + if ( !offset ) offset = old_offset; - + t[n] = index->bytes + offset - 1; - + old_offset = offset; } *table = t; } - return error; + + return error; } LOCAL_FUNC - FT_Error T2_Access_Element( CFF_Index* index, - FT_UInt element, - FT_Byte* *pbytes, - FT_ULong *pbyte_len ) + TT_Error T2_Access_Element( CFF_Index* index, + TT_UInt element, + TT_Byte** pbytes, + TT_ULong* pbyte_len ) { - FT_Error error = 0; + TT_Error error = 0; + if ( index && index->count > element ) { /* compute start and end offsets */ - FT_ULong off1, off2; - + TT_ULong off1, off2; + + off1 = index->offsets[element]; - if (off1) + if ( off1 ) { do { element++; off2 = index->offsets[element]; } - while (off2 == 0 && element < index->count); - if (!off2) + while ( off2 == 0 && element < index->count ); + + if ( !off2 ) off1 = 0; } - + /* access element */ - if (off1) + if ( off1 ) { *pbyte_len = off2 - off1; - - if (index->bytes) + + if ( index->bytes ) { /* this index was completely loaded in memory, that's easy */ - *pbytes = index->bytes + off1 - 1; + *pbytes = index->bytes + off1 - 1; } else { /* this index is still on disk/file, access it through a frame */ FT_Stream stream = index->stream; - + + if ( FILE_Seek( index->data_offset + off1 - 1 ) || - EXTRACT_Frame( off2-off1, *pbytes ) ) + EXTRACT_Frame( off2 - off1, *pbytes ) ) goto Exit; } } @@ -217,8 +232,8 @@ } } else - error = FT_Err_Invalid_Argument; - + error = T2_Err_Invalid_Argument; + Exit: return error; } @@ -226,30 +241,34 @@ LOCAL_FUNC void T2_Forget_Element( CFF_Index* index, - FT_Byte* *pbytes ) + TT_Byte** pbytes ) { - if (index->bytes == 0) + if ( index->bytes == 0 ) { FT_Stream stream = index->stream; + + RELEASE_Frame( *pbytes ); } - } + } LOCAL_FUNC - FT_String* T2_Get_Name( CFF_Index* index, - FT_UInt element ) + TT_String* T2_Get_Name( CFF_Index* index, + TT_UInt element ) { - FT_Memory memory = index->stream->memory; - FT_Byte* bytes; - FT_ULong byte_len; - FT_Error error; - FT_String* name = 0; - + FT_Memory memory = index->stream->memory; + TT_Byte* bytes; + TT_ULong byte_len; + TT_Error error; + TT_String* name = 0; + + error = T2_Access_Element( index, element, &bytes, &byte_len ); - if (error) goto Exit; - - if ( !ALLOC( name, byte_len+1 ) ) + if ( error ) + goto Exit; + + if ( !ALLOC( name, byte_len + 1 ) ) { MEM_Copy( name, bytes, byte_len ); name[byte_len] = 0; @@ -258,60 +277,69 @@ Exit: return name; - } + } #if 0 /* unused until we fully support pure-CFF fonts */ + LOCAL_FUNC - FT_String* T2_Get_String( CFF_Index* index, - FT_UInt sid, + TT_String* T2_Get_String( CFF_Index* index, + TT_UInt sid, PSNames_Interface* interface ) { - /* if it's not a standard string, return it */ + /* if it is not a standard string, return it */ if ( sid > 390 ) return T2_Get_Name( index, sid - 390 ); - - /* that's a standard string, fetch a copy from the psnamed module */ + + /* that's a standard string, fetch a copy from the PSName module */ { - FT_String* name = 0; + TT_String* name = 0; const char* adobe_name = interface->adobe_std_strings( sid ); - FT_UInt len; - - if (adobe_name) + TT_UInt len; + + + if ( adobe_name ) { FT_Memory memory = index->stream->memory; - FT_Error error; - - len = (FT_UInt)strlen(adobe_name); - if ( !ALLOC( name, len+1 ) ) + TT_Error error; + + + len = (TT_UInt)strlen( adobe_name ); + if ( !ALLOC( name, len + 1 ) ) { MEM_Copy( name, adobe_name, len ); name[len] = 0; } } + return name; } - } -#endif + } + +#endif /* 0 */ + LOCAL_FUNC - FT_Error T2_Load_CFF_Font( FT_Stream stream, - FT_Int face_index, - CFF_Font* font ) + FT_Error T2_Load_CFF_Font( FT_Stream stream, + TT_Int face_index, + CFF_Font* font ) { - static const FT_Frame_Field cff_header_fields[] = { - FT_FRAME_START(4), - FT_FRAME_BYTE( CFF_Font, version_major ), - FT_FRAME_BYTE( CFF_Font, version_minor ), - FT_FRAME_BYTE( CFF_Font, header_size ), - FT_FRAME_BYTE( CFF_Font, absolute_offsize ), - FT_FRAME_END }; + static const FT_Frame_Field cff_header_fields[] = + { + FT_FRAME_START( 4 ), + FT_FRAME_BYTE( CFF_Font, version_major ), + FT_FRAME_BYTE( CFF_Font, version_minor ), + FT_FRAME_BYTE( CFF_Font, header_size ), + FT_FRAME_BYTE( CFF_Font, absolute_offsize ), + FT_FRAME_END + }; - FT_Error error; - FT_Memory memory = stream->memory; - FT_ULong base_offset; + FT_Error error; + FT_Memory memory = stream->memory; + FT_ULong base_offset; - MEM_Set( font, 0, sizeof(*font) ); + + MEM_Set( font, 0, sizeof ( *font ) ); font->stream = stream; font->memory = memory; base_offset = FILE_Pos(); @@ -325,7 +353,7 @@ font->header_size < 4 || font->absolute_offsize > 4 ) { - FT_ERROR(( "incorrect CFF font header !!\n" )); + FT_ERROR(( "incorrect CFF font header!\n" )); error = FT_Err_Unknown_File_Format; goto Exit; } @@ -338,126 +366,138 @@ t2_new_cff_index( &font->top_dict_index, stream, 0 ) || t2_new_cff_index( &font->string_index, stream, 0 ) || t2_new_cff_index( &font->global_subrs_index, stream, 1 ); - if (error) goto Exit; + if ( error ) + goto Exit; - /* well, we don't really forget the "disabled" fonts.. */ + /* well, we don't really forget the `disabled' fonts... */ font->num_faces = font->name_index.count; - if (face_index >= font->num_faces) + if ( face_index >= font->num_faces ) { - FT_ERROR(( "T2.Load_Font: incorrect face index = %d\n", face_index )); - error = FT_Err_Invalid_Argument; + FT_ERROR(( "T2_Load_CFF_Font: incorrect face index = %d\n", + face_index )); + error = T2_Err_Invalid_Argument; } /* in case of a font format check, simply exit now */ - if (face_index >= 0) + if ( face_index >= 0 ) { - T2_Parser parser; - FT_Byte* dict; - FT_ULong dict_len; - CFF_Index* index = &font->top_dict_index; - CFF_Top_Dict* top = &font->top_dict; + T2_Parser parser; + TT_Byte* dict; + TT_ULong dict_len; + CFF_Index* index = &font->top_dict_index; + CFF_Top_Dict* top = &font->top_dict; - /* parse the top-level font dictionary */ + + /* parse the top-level font dictionary */ T2_Parser_Init( &parser, T2CODE_TOPDICT, &font->top_dict ); /* set defaults */ - memset( top, 0, sizeof(*top) ); + memset( top, 0, sizeof ( *top ) ); + top->underline_position = -100; top->underline_thickness = 50; top->charstring_type = 2; - top->font_matrix.xx = 0x10000; - top->font_matrix.yy = 0x10000; + top->font_matrix.xx = 0x10000L; + top->font_matrix.yy = 0x10000L; top->cid_count = 8720; - + error = T2_Access_Element( index, face_index, &dict, &dict_len ) || T2_Parser_Run( &parser, dict, dict + dict_len ); T2_Forget_Element( &font->top_dict_index, &dict ); - if (error) goto Exit; - + + if ( error ) + goto Exit; + /* parse the private dictionary, if any */ if (font->top_dict.private_offset && font->top_dict.private_size) { CFF_Private* priv = &font->private_dict; - + + /* set defaults */ priv->blue_shift = 7; priv->blue_fuzz = 1; priv->lenIV = -1; - priv->expansion_factor = (FT_Fixed)0.06*0x10000; - priv->blue_scale = (FT_Fixed)0.039625*0x10000; + priv->expansion_factor = (TT_Fixed)0.06 * 0x10000L; + priv->blue_scale = (TT_Fixed)0.039625 * 0x10000L; T2_Parser_Init( &parser, T2CODE_PRIVATE, priv ); - + if ( FILE_Seek( base_offset + font->top_dict.private_offset ) || ACCESS_Frame( font->top_dict.private_size ) ) goto Exit; error = T2_Parser_Run( &parser, - (FT_Byte*)stream->cursor, - (FT_Byte*)stream->limit ); - FORGET_Frame(); - if (error) goto Exit; + (TT_Byte*)stream->cursor, + (TT_Byte*)stream->limit ); + FORGET_Frame(); + if ( error ) + goto Exit; } - + /* read the charstrings index now */ if ( font->top_dict.charstrings_offset == 0 ) { - FT_ERROR(( "T2.New_CFF_Font: no charstrings offset !!\n" )); + FT_ERROR(( "T2_Load_CFF_Font: no charstrings offset!\n" )); error = FT_Err_Unknown_File_Format; goto Exit; } - + if ( FILE_Seek( base_offset + font->top_dict.charstrings_offset ) ) goto Exit; - + error = t2_new_cff_index( &font->charstrings_index, stream, 0 ); - if (error) goto Exit; + if ( error ) + goto Exit; /* read the local subrs, if any */ - if (font->private_dict.local_subrs_offset) { + if ( font->private_dict.local_subrs_offset ) + { + if ( FILE_Seek( base_offset + font->top_dict.private_offset + + font->private_dict.local_subrs_offset ) ) + goto Exit; - if ( FILE_Seek( base_offset + font->top_dict.private_offset + - font->private_dict.local_subrs_offset ) ) - goto Exit; - - error = t2_new_cff_index( &font->local_subrs_index, stream, 1 ); - if (error) goto Exit; + error = t2_new_cff_index( &font->local_subrs_index, stream, 1 ); + if ( error ) + goto Exit; } - + /* explicit the global and local subrs */ - if (font->private_dict.local_subrs_offset) { - font->num_local_subrs = font->local_subrs_index.count; - } else { - font->num_local_subrs = 0; - } + if ( font->private_dict.local_subrs_offset ) + font->num_local_subrs = font->local_subrs_index.count; + else + font->num_local_subrs = 0; font->num_global_subrs = font->global_subrs_index.count; - - error = t2_explicit_cff_index( &font->global_subrs_index, &font->global_subrs ) ; + error = t2_explicit_cff_index( &font->global_subrs_index, + &font->global_subrs ) ; - if (font->private_dict.local_subrs_offset) { - error |= t2_explicit_cff_index( &font->local_subrs_index, &font->local_subrs ) ; - } + if ( font->private_dict.local_subrs_offset ) + error |= t2_explicit_cff_index( &font->local_subrs_index, + &font->local_subrs ) ; - if (error) goto Exit; + if ( error ) + goto Exit; } - /* get the font name */ + /* get the font name */ font->font_name = T2_Get_Name( &font->name_index, face_index ); Exit: return error; } + LOCAL_FUNC void T2_Done_CFF_Font( CFF_Font* font ) { FT_Memory memory = font->memory; - + + t2_done_cff_index( &font->global_subrs_index ); t2_done_cff_index( &font->string_index ); t2_done_cff_index( &font->top_dict_index ); @@ -465,20 +505,9 @@ t2_done_cff_index( &font->charstrings_index ); FREE( font->local_subrs ); - FREE( font->global_subrs ); + FREE( font->global_subrs ); FREE( font->font_name ); } - - /***********************************************************************/ - /***********************************************************************/ - /***********************************************************************/ - /***** *****/ - /***** TYPE 2 TABLES DECODING.. *****/ - /***** *****/ - /***********************************************************************/ - /***********************************************************************/ - /***********************************************************************/ - /* END */ diff --git a/src/cff/t2load.h b/src/cff/t2load.h index d8a3adcdb..b388f988f 100644 --- a/src/cff/t2load.h +++ b/src/cff/t2load.h @@ -4,11 +4,11 @@ /* */ /* OpenType glyph data/program tables loader (specification). */ /* */ -/* Copyright 1996-1999 by */ +/* Copyright 1996-2000 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ -/* This file is part of the FreeType project, and may only be used */ -/* modified and distributed under the terms of the FreeType project */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ /* this file you indicate that you have read the license and */ /* understand and accept it fully. */ @@ -25,33 +25,35 @@ extern "C" { #endif - LOCAL_FUNC + LOCAL_DEF FT_String* T2_Get_Name( CFF_Index* index, FT_UInt element ); #if 0 /* will be used later for pure-CFF font support */ + LOCAL_DEF - FT_String* T2_Get_String( CFF_Index* index, - FT_UInt sid, + TT_String* T2_Get_String( CFF_Index* index, + TT_UInt sid, PSNames_Interface* interface ); + #endif LOCAL_DEF - FT_Error T2_Access_Element( CFF_Index* index, - FT_UInt element, - FT_Byte* *pbytes, - FT_ULong *pbyte_len ); + TT_Error T2_Access_Element( CFF_Index* index, + TT_UInt element, + TT_Byte** pbytes, + TT_ULong* pbyte_len ); LOCAL_DEF void T2_Forget_Element( CFF_Index* index, - FT_Byte* *pbytes ); + TT_Byte** pbytes ); - LOCAL_FUNC - FT_Error T2_Load_CFF_Font( FT_Stream stream, - FT_Int face_index, + LOCAL_DEF + TT_Error T2_Load_CFF_Font( FT_Stream stream, + TT_Int face_index, CFF_Font* font ); - LOCAL_FUNC + LOCAL_DEF void T2_Done_CFF_Font( CFF_Font* font ); diff --git a/src/cff/t2objs.c b/src/cff/t2objs.c index d08f8d6df..ffab17e29 100644 --- a/src/cff/t2objs.c +++ b/src/cff/t2objs.c @@ -53,11 +53,18 @@ /* T2_Init_Face */ /* */ /* */ - /* Initializes a given TrueType face object. */ + /* Initializes a given OpenType face object. */ /* */ /* */ - /* resource :: The source font resource. */ + /* stream :: The source font stream. */ + /* */ /* face_index :: The index of the font face in the resource. */ + /* */ + /* num_params :: Number of additional generic parameters. Ignored. */ + /* */ + /* params :: Additional generic parameters. Ignored. */ + /* */ + /* */ /* face :: The newly built face object. */ /* */ /* */ @@ -70,70 +77,77 @@ FT_Int num_params, FT_Parameter* params ) { - TT_Error error; - FT_Driver sfnt_driver; - SFNT_Interface* sfnt; + TT_Error error; + FT_Driver sfnt_driver; + SFNT_Interface* sfnt; + sfnt_driver = FT_Get_Driver( face->root.driver->library, "sfnt" ); - if (!sfnt_driver) goto Bad_Format; + if ( !sfnt_driver ) + goto Bad_Format; sfnt = (SFNT_Interface*)(sfnt_driver->interface.format_interface); - if (!sfnt) goto Bad_Format; + if ( !sfnt ) + goto Bad_Format; /* create input stream from resource */ - if ( FILE_Seek(0) ) + if ( FILE_Seek( 0 ) ) goto Exit; - /* check that we have a valid TrueType file */ + /* check that we have a valid OpenType file */ error = sfnt->init_face( stream, face, face_index, num_params, params ); - if (error) goto Exit; + if ( error ) + goto Exit; - /* We must also be able to accept Mac/GX fonts, as well as OT ones */ - if ( face->format_tag != 0x4f54544f ) /* OpenType/CFF font */ + if ( face->format_tag != 0x4f54544fL ) /* OpenType/CFF font */ { FT_TRACE2(( "[not a valid OpenType/CFF font]\n" )); goto Bad_Format; } - /* If we're performing a simple font format check, exit immediately */ + /* If we are performing a simple font format check, exit immediately */ if ( face_index < 0 ) - return FT_Err_Ok; + return T2_Err_Ok; /* Load font directory */ error = sfnt->load_face( stream, face, face_index, num_params, params ); - if ( error ) goto Exit; + if ( error ) + goto Exit; /* now, load the CFF part of the file.. */ error = face->goto_table( face, TTAG_CFF, stream, 0 ); - if (error) goto Exit; + if ( error ) + goto Exit; { CFF_Font* cff; FT_Memory memory = face->root.memory; FT_Face root; - - if ( ALLOC( cff, sizeof(*cff) ) ) + + + if ( ALLOC( cff, sizeof ( *cff ) ) ) goto Exit; - + face->other = cff; error = T2_Load_CFF_Font( stream, face_index, cff ); - if (error) goto Exit; + if ( error ) + goto Exit; - /* complement the root flags with some interesting information */ + /* Complement the root flags with some interesting information. */ /* note that for OpenType/CFF, there is no need to do this, but */ - /* this will be necessary for pure CFF fonts through.. */ + /* this will be necessary for pure CFF fonts through. */ root = &face->root; } Exit: return error; - Bad_Format: + + Bad_Format: error = FT_Err_Unknown_File_Format; goto Exit; } - /*************************************************************************/ /* */ /* */ @@ -149,23 +163,26 @@ void T2_Done_Face( T2_Face face ) { FT_Memory memory = face->root.memory; -#if 0 +#if 0 FT_Stream stream = face->root.stream; #endif SFNT_Interface* sfnt = face->sfnt; - if (sfnt) - sfnt->done_face(face); + + if ( sfnt ) + sfnt->done_face( face ); { CFF_Font* cff = (CFF_Font*)face->other; - if (cff) + + + if ( cff ) { - T2_Done_CFF_Font(cff); - FREE(face->other); + T2_Done_CFF_Font( cff ); + FREE( face->other ); } - } + } } @@ -193,7 +210,8 @@ LOCAL_DEF FT_Error T2_Init_Size( T2_Size size ) { - UNUSED(size); + UNUSED( size ); + return 0; } @@ -212,7 +230,7 @@ LOCAL_FUNC void T2_Done_Size( T2_Size size ) { - UNUSED(size); + UNUSED( size ); } @@ -229,14 +247,15 @@ /* size :: A handle to the target size object. */ /* */ LOCAL_DEF - FT_Error T2_Reset_Size( T2_Size size ) + TT_Error T2_Reset_Size( T2_Size size ) { T2_Face face = (T2_Face)size->face; FT_Size_Metrics* metrics = &size->metrics; - FT_Error error = FT_Err_Ok; + TT_Error error = T2_Err_Ok; + if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 ) - return FT_Err_Invalid_Argument; + return T2_Err_Invalid_PPem; /* Compute root ascender, descender, test height, and max_advance */ metrics->ascender = ( FT_MulFix( face->root.ascender, @@ -250,6 +269,7 @@ metrics->max_advance = ( FT_MulFix( face->root.max_advance_width, metrics->x_scale ) + 32 ) & -64; + return error; } @@ -269,10 +289,11 @@ /* TrueType error code. 0 means success. */ /* */ LOCAL_FUNC - FT_Error T2_Init_GlyphSlot( T2_GlyphSlot slot ) + TT_Error T2_Init_GlyphSlot( T2_GlyphSlot slot ) { FT_Library library = slot->root.face->driver->library; + slot->max_points = 0; slot->max_contours = 0; slot->root.bitmap.buffer = 0; @@ -284,7 +305,7 @@ /*************************************************************************/ /* */ /* */ - /* TT_Done_GlyphSlot */ + /* T2_Done_GlyphSlot */ /* */ /* */ /* The OpenType glyph slot finalizer. */ @@ -298,7 +319,8 @@ FT_Library library = slot->root.face->driver->library; FT_Memory memory = library->memory; - if (slot->root.flags & ft_glyph_own_bitmap) + + if ( slot->root.flags & ft_glyph_own_bitmap ) FREE( slot->root.bitmap.buffer ); FT_Outline_Done( library, &slot->root.outline ); @@ -321,19 +343,22 @@ /* TrueType error code. 0 means success. */ /* */ LOCAL_FUNC - FT_Error T2_Init_Driver( T2_Driver driver ) + TT_Error T2_Init_Driver( T2_Driver driver ) { FT_Memory memory = driver->root.memory; FT_Error error; + error = FT_New_GlyphZone( memory, 0, 0, &driver->zone ); - if (error) return error; + if ( error ) + return error; /* init extension registry if needed */ -#ifdef T2_CONFIG_OPTION_EXTEND_ENGINE + +#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE return TT_Init_Extensions( driver ); #else - return FT_Err_Ok; + return T2_Err_Ok; #endif } @@ -341,19 +366,20 @@ /*************************************************************************/ /* */ /* */ - /* TT_Done_Driver */ + /* T2_Done_Driver */ /* */ /* */ - /* Finalizes a given TrueType driver. */ + /* Finalizes a given OpenType driver. */ /* */ /* */ - /* driver :: A handle to the target TrueType driver. */ + /* driver :: A handle to the target OpenType driver. */ /* */ LOCAL_FUNC void T2_Done_Driver( T2_Driver driver ) { /* destroy extensions registry if needed */ -#ifdef T2_CONFIG_OPTION_EXTEND_ENGINE + +#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE TT_Done_Extensions( driver ); #endif diff --git a/src/cff/t2objs.h b/src/cff/t2objs.h index b3aaab0d2..4672c9bf6 100644 --- a/src/cff/t2objs.h +++ b/src/cff/t2objs.h @@ -2,13 +2,13 @@ /* */ /* t2objs.h */ /* */ -/* Objects manager (specification). */ +/* OpenType objects manager (specification). */ /* */ -/* Copyright 1996-1999 by */ +/* Copyright 1996-2000 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ -/* This file is part of the FreeType project, and may only be used */ -/* modified and distributed under the terms of the FreeType project */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ /* this file you indicate that you have read the license and */ /* understand and accept it fully. */ @@ -42,6 +42,7 @@ typedef TT_Face T2_Face; + /*************************************************************************/ /* */ /* */ @@ -61,23 +62,18 @@ /* */ /* A handle to an OpenType glyph slot object. */ /* */ - /* */ - /* This is a direct typedef of FT_GlyphSlot, as there is nothing */ - /* specific about the OpenType glyph slot. */ - /* */ - typedef struct T2_GlyphSlotRec_ { FT_GlyphSlotRec root; - FT_Bool hint; - FT_Bool scaled; + TT_Bool hint; + TT_Bool scaled; - FT_Int max_points; - FT_Int max_contours; + TT_Int max_points; + TT_Int max_contours; - FT_Fixed x_scale; - FT_Fixed y_scale; + TT_Fixed x_scale; + TT_Fixed y_scale; } T2_GlyphSlotRec, *T2_GlyphSlot; @@ -89,9 +85,9 @@ /* */ typedef struct T2_Transform_ { - FT_Fixed xx, xy; /* transformation matrix coefficients */ - FT_Fixed yx, yy; - FT_F26Dot6 ox, oy; /* offsets */ + TT_Fixed xx, xy; /* transformation matrix coefficients */ + TT_Fixed yx, yy; + TT_F26Dot6 ox, oy; /* offsets */ } T2_Transform; @@ -110,38 +106,55 @@ } T2_DriverRec; - /*************************************************************************/ - /* Face Funcs */ + /*************************************************************************/ + /* */ + /* Face functions */ + /* */ + LOCAL_DEF + FT_Error T2_Init_Face( FT_Stream stream, + T2_Face face, + TT_Int face_index, + TT_Int num_params, + FT_Parameter* params ); - LOCAL_DEF FT_Error T2_Init_Face( FT_Stream stream, - T2_Face face, - TT_Int face_index, - TT_Int num_params, - FT_Parameter* params ); - - LOCAL_DEF void T2_Done_Face( T2_Face face ); + LOCAL_DEF + void T2_Done_Face( T2_Face face ); - /*************************************************************************/ - /* Size funcs */ + /*************************************************************************/ + /* */ + /* Size functions */ + /* */ + LOCAL_DEF + FT_Error T2_Init_Size( T2_Size size ); - LOCAL_DEF FT_Error T2_Init_Size ( T2_Size size ); - LOCAL_DEF void T2_Done_Size ( T2_Size size ); - LOCAL_DEF FT_Error T2_Reset_Size( T2_Size size ); + LOCAL_DEF + void T2_Done_Size( T2_Size size ); + + LOCAL_DEF + TT_Error T2_Reset_Size( T2_Size size ); - /*************************************************************************/ - /* GlyphSlot funcs */ + /*************************************************************************/ + /* */ + /* GlyphSlot functions */ + /* */ + LOCAL_DEF + TT_Error T2_Init_GlyphSlot( T2_GlyphSlot slot ); - LOCAL_DEF FT_Error T2_Init_GlyphSlot( T2_GlyphSlot slot ); - LOCAL_DEF void T2_Done_GlyphSlot( T2_GlyphSlot slot ); + LOCAL_DEF + void T2_Done_GlyphSlot( T2_GlyphSlot slot ); - /*************************************************************************/ - /* Driver funcs */ + /*************************************************************************/ + /* */ + /* Driver functions */ + /* */ + LOCAL_DEF + TT_Error T2_Init_Driver( T2_Driver driver ); - LOCAL_DEF FT_Error T2_Init_Driver( T2_Driver driver ); - LOCAL_DEF void T2_Done_Driver( T2_Driver driver ); + LOCAL_DEF + void T2_Done_Driver( T2_Driver driver ); #ifdef __cplusplus diff --git a/src/cff/t2parse.c b/src/cff/t2parse.c index 548cef28d..90659dca9 100644 --- a/src/cff/t2parse.c +++ b/src/cff/t2parse.c @@ -17,7 +17,7 @@ #include -#include +#include /*************************************************************************/ @@ -33,6 +33,7 @@ #define T2_Err_Stack_Underflow FT_Err_Invalid_Argument #define T2_Err_Syntax_Error FT_Err_Invalid_Argument + enum { t2_kind_none = 0, @@ -42,83 +43,87 @@ t2_kind_bool, t2_kind_delta, t2_kind_callback, - + t2_kind_max /* do not remove */ }; /* now generate handlers for the most simple fields */ - typedef FT_Error (*T2_Field_Reader)( T2_Parser* parser ); + typedef TT_Error (*T2_Field_Reader)( T2_Parser* parser ); - typedef struct T2_Field_Handler_ + typedef struct T2_Field_Handler_ { int kind; int code; - FT_UInt offset; - FT_Byte size; + TT_UInt offset; + TT_Byte size; T2_Field_Reader reader; - FT_UInt array_max; - FT_UInt count_offset; - + TT_UInt array_max; + TT_UInt count_offset; + } T2_Field_Handler; - - - LOCAL_FUNC - void T2_Parser_Init( T2_Parser* parser, FT_UInt code, void* object ) + void T2_Parser_Init( T2_Parser* parser, + TT_UInt code, + void* object ) { - MEM_Set(parser,0,sizeof(*parser)); + MEM_Set( parser, 0, sizeof ( *parser ) ); + parser->top = parser->stack; parser->object_code = code; parser->object = object; } - - - - - /* reads an integer */ static - FT_Long parse_t2_integer( FT_Byte* start, - FT_Byte* limit ) + TT_Long parse_t2_integer( TT_Byte* start, + TT_Byte* limit ) { - FT_Byte* p = start; - FT_Int v = *p++; - FT_Long val = 0; + TT_Byte* p = start; + TT_Int v = *p++; + TT_Long val = 0; - if (v == 28) + + if ( v == 28 ) { - if ( p+2 > limit ) goto Bad; - val = (FT_Short)(((FT_Int)p[0] << 8) | p[1]); + if ( p + 2 > limit ) + goto Bad; + + val = (TT_Short)( ( (TT_Int)p[0] << 8 ) | p[1] ); p += 2; } - else if (v == 29) + else if ( v == 29 ) { - if ( p+4 > limit ) goto Bad; - val = ((FT_Long)p[0] << 24) | - ((FT_Long)p[1] << 16) | - ((FT_Long)p[2] << 8) | p[3]; + if ( p + 4 > limit ) + goto Bad; + + val = ( (TT_Long)p[0] << 24 ) | + ( (TT_Long)p[1] << 16 ) | + ( (TT_Long)p[2] << 8 ) | p[3]; p += 4; } - else if (v < 247) + else if ( v < 247 ) { val = v - 139; } - else if (v < 251) + else if ( v < 251 ) { - if (p+1 > limit) goto Bad; - val = (v-247)*256 + p[0]+108; - p ++; + if ( p + 1 > limit ) + goto Bad; + + val = ( v - 247 ) * 256 + p[0] + 108; + p++; } else { - if (p+1 > limit) goto Bad; - val = -(v-251)*256 - p[0]-108; - p ++; + if ( p + 1 > limit ) + goto Bad; + + val = -( v - 251 ) * 256 - p[0] - 108; + p++; } Exit: @@ -132,15 +137,16 @@ /* reads a real */ static - FT_Fixed parse_t2_real( FT_Byte* start, - FT_Byte* limit, - FT_Int power_ten ) + TT_Fixed parse_t2_real( TT_Byte* start, + TT_Byte* limit, + TT_Int power_ten ) { - FT_Byte* p = start; - FT_Long num, divider, result, exp; - FT_Int sign = 0, exp_sign = 0; - FT_Byte nib; - FT_Byte phase; + TT_Byte* p = start; + TT_Long num, divider, result, exp; + TT_Int sign = 0, exp_sign = 0; + TT_Byte nib; + TT_Byte phase; + result = 0; num = 0; @@ -149,86 +155,98 @@ /* first of all, read the integer part */ phase = 4; p--; + for (;;) { /* read one nibble at a time */ - if (phase && ++p >= limit) goto Bad; - nib = (p[0] >> phase) & 0xF; - phase = 4-phase; + if ( phase && ++p >= limit ) + goto Bad; - if (nib == 0xE) + nib = ( p[0] >> phase ) & 0xF; + phase = 4 - phase; + + if ( nib == 0xE ) sign = 1; - else if (nib > 9) + else if ( nib > 9 ) break; else - result = result*10 + nib; + result = result * 10 + nib; } /* read decimal part, if any */ - if (nib == 0xa) + if ( nib == 0xa ) for (;;) { /* read one nibble at a time */ - if (!phase && ++p >= limit) goto Bad; - phase = 4-phase; - nib = (p[0] >> phase) & 0xF; + if ( !phase && ++p >= limit ) + goto Bad; - if (nib >= 10) + phase = 4 - phase; + nib = ( p[0] >> phase ) & 0xF; + + if ( nib >= 10 ) break; if (divider < 10000000L) { - num = num*10 + nib; + num = num * 10 + nib; divider *= 10; } } /* read exponent, if any */ - if (nib == 12) + if ( nib == 12 ) { exp_sign = 1; nib = 11; } - if (nib == 11) + + if ( nib == 11 ) { exp = 0; + for (;;) { /* read one nibble at a time */ - if (!phase && ++p >= limit) goto Bad; - phase = 4-phase; - nib = (p[0] >> phase) & 0xF; + if ( !phase && ++p >= limit ) + goto Bad; - if (nib >= 10) + phase = 4 - phase; + nib = ( p[0] >> phase ) & 0xF; + + if ( nib >= 10 ) break; - exp = exp*10 + nib; + exp = exp * 10 + nib; } - if (exp_sign) + + if ( exp_sign ) exp = -exp; power_ten += exp; } /* raise to power of ten if needed */ - while (power_ten > 0) + while ( power_ten > 0 ) { - result = result*10; - num = num*10; + result = result * 10; + num = num * 10; + power_ten--; } - while (power_ten < 0) + while ( power_ten < 0 ) { - result = result/10; - divider = divider*10; + result = result / 10; + divider = divider * 10; + power_ten++; } - if (num) + if ( num ) result += FT_DivFix( num, divider ); - if (sign) + if ( sign ) result = -result; Exit: @@ -242,32 +260,34 @@ /* reads a number, either integer or real */ static - FT_Long t2_parse_num( FT_Byte** d ) + TT_Long t2_parse_num( TT_Byte** d ) { - return ( **d == 30 ? (parse_t2_real ( d[0], d[1], 0 ) >> 16): - parse_t2_integer( d[0], d[1] ) ); + return ( **d == 30 ? ( parse_t2_real( d[0], d[1], 0 ) >> 16 ) + : parse_t2_integer( d[0], d[1] ) ); } + /* reads a floating point number, either integer or real */ static - FT_Fixed t2_parse_fixed( FT_Byte** d ) + TT_Fixed t2_parse_fixed( TT_Byte** d ) { - return ( **d == 30 ? parse_t2_real( d[0], d[1], 0 ) : - parse_t2_integer( d[0], d[1] ) << 16 ); + return ( **d == 30 ? parse_t2_real( d[0], d[1], 0 ) + : parse_t2_integer( d[0], d[1] ) << 16 ); } - static - FT_Error parse_font_matrix( T2_Parser* parser ) + TT_Error parse_font_matrix( T2_Parser* parser ) { CFF_Top_Dict* dict = (CFF_Top_Dict*)parser->object; - FT_Matrix* matrix = &dict->font_matrix; - FT_Byte** data = parser->stack; - FT_Error error; + TT_Matrix* matrix = &dict->font_matrix; + TT_Byte** data = parser->stack; + TT_Error error; + error = T2_Err_Stack_Underflow; - if (parser->top >= parser->stack + 4) + + if ( parser->top >= parser->stack + 4 ) { matrix->xx = t2_parse_fixed( data++ ); matrix->yx = t2_parse_fixed( data++ ); @@ -275,20 +295,23 @@ matrix->yy = t2_parse_fixed( data ); error = 0; } + return error; } static - FT_Error parse_font_bbox( T2_Parser* parser ) + TT_Error parse_font_bbox( T2_Parser* parser ) { CFF_Top_Dict* dict = (CFF_Top_Dict*)parser->object; FT_BBox* bbox = &dict->font_bbox; - FT_Byte** data = parser->stack; - FT_Error error; + TT_Byte** data = parser->stack; + TT_Error error; + error = T2_Err_Stack_Underflow; - if (parser->top >= parser->stack + 4) + + if ( parser->top >= parser->stack + 4 ) { bbox->xMin = t2_parse_num( data++ ); bbox->yMin = t2_parse_num( data++ ); @@ -296,247 +319,288 @@ bbox->yMax = t2_parse_num( data ); error = 0; } + return error; } static - FT_Error parse_private_dict( T2_Parser* parser ) + TT_Error parse_private_dict( T2_Parser* parser ) { - CFF_Top_Dict* dict = (CFF_Top_Dict*)parser->object; - FT_Byte** data = parser->stack; - FT_Error error; + CFF_Top_Dict* dict = (CFF_Top_Dict*)parser->object; + TT_Byte** data = parser->stack; + TT_Error error; + error = T2_Err_Stack_Underflow; - if (parser->top >= parser->stack + 2) + + if ( parser->top >= parser->stack + 2 ) { dict->private_size = t2_parse_num( data++ ); dict->private_offset = t2_parse_num( data ); error = 0; } + return error; } static - FT_Error parse_cid_ros( T2_Parser* parser ) + TT_Error parse_cid_ros( T2_Parser* parser ) { CFF_Top_Dict* dict = (CFF_Top_Dict*)parser->object; - FT_Byte** data = parser->stack; - FT_Error error; + TT_Byte** data = parser->stack; + TT_Error error; + error = T2_Err_Stack_Underflow; - if (parser->top >= parser->stack + 3) + + if ( parser->top >= parser->stack + 3 ) { - dict->cid_registry = (FT_UInt)t2_parse_num( data++ ); - dict->cid_ordering = (FT_UInt)t2_parse_num( data++ ); - dict->cid_supplement = (FT_ULong)t2_parse_num( data ); + dict->cid_registry = (TT_UInt)t2_parse_num( data++ ); + dict->cid_ordering = (TT_UInt)t2_parse_num( data++ ); + dict->cid_supplement = (TT_ULong)t2_parse_num( data ); error = 0; } + return error; } +#define T2_FIELD_NUM( code, name ) \ + T2_FIELD( code, name, t2_kind_num ) +#define T2_FIELD_FIXED( code, name ) \ + T2_FIELD( code, name, t2_kind_fixed ) +#define T2_FIELD_STRING( code, name ) \ + T2_FIELD( code, name, t2_kind_string ) +#define T2_FIELD_BOOL( code, name ) \ + T2_FIELD( code, name, t2_kind_bool ) +#define T2_FIELD_DELTA( code, name,max ) \ + T2_FIELD( code, name, t2_kind_delta ) -#define T2_FIELD_NUM(code,name) T2_FIELD( code, name, t2_kind_num ) -#define T2_FIELD_FIXED(code,name) T2_FIELD( code, name, t2_kind_fixed ) -#define T2_FIELD_STRING(code,name) T2_FIELD( code, name, t2_kind_string ) -#define T2_FIELD_BOOL(code,name) T2_FIELD( code, name, t2_kind_bool ) -#define T2_FIELD_DELTA(code,name,max) T2_FIELD( code, name, t2_kind_delta ) - - -#define T2_REF(s,f) (((s*)0)->f) +#define T2_REF( s, f ) ( ((s*)0)->f ) #define T2_FIELD_CALLBACK( code, name ) \ - { t2_kind_callback, code | T2CODE, 0, 0, parse_ ## name, 0, 0 }, - + { \ + t2_kind_callback, \ + code | T2CODE, \ + 0, 0, \ + parse_ ## name, \ + 0, 0 }, + #undef T2_FIELD -#define T2_FIELD( code, name, kind ) \ - { kind, code | T2CODE, \ - (FT_UInt)(char*)&T2_REF( T2TYPE, name ), \ - sizeof( T2_REF( T2TYPE, name ) ), \ - 0 }, - -#undef T2_FIELD_DELTA -#define T2_FIELD_DELTA( code, name, max ) \ - { t2_kind_delta, code | T2CODE, \ - (FT_UInt)(char*)&T2_REF( T2TYPE, name ), \ - sizeof( T2_REF( T2TYPE, name ) ), \ - 0, \ - max, (FT_UInt)(char*)&T2_REF( T2TYPE, num_ ## name ) }, +#define T2_FIELD( code, name, kind ) \ + { \ + kind, \ + code | T2CODE, \ + (TT_UInt)(char*)&T2_REF( T2TYPE, name ), \ + sizeof( T2_REF( T2TYPE, name ) ), \ + 0 \ + }, +#undef T2_FIELD_DELTA +#define T2_FIELD_DELTA( code, name, max ) \ + { \ + t2_kind_delta, \ + code | T2CODE, \ + (TT_UInt)(char*)&T2_REF( T2TYPE, name ), \ + sizeof( T2_REF( T2TYPE, name ) ), \ + 0, \ + max, \ + (TT_UInt)(char*)&T2_REF( T2TYPE, num_ ## name ) \ + }, #define T2CODE_TOPDICT 0x1000 #define T2CODE_PRIVATE 0x2000 static const T2_Field_Handler t2_field_handlers[] = { - #include +#include { 0, 0, 0, 0, 0, 0, 0 } }; LOCAL_FUNC - FT_Error T2_Parser_Run( T2_Parser* parser, - FT_Byte* start, - FT_Byte* limit ) + TT_Error T2_Parser_Run( T2_Parser* parser, + TT_Byte* start, + TT_Byte* limit ) { - FT_Byte* p = start; - FT_Error error = 0; - + TT_Byte* p = start; + TT_Error error = 0; + + parser->top = parser->stack; parser->start = start; parser->limit = limit; parser->cursor = start; - - while (p < limit) + + while ( p < limit ) { - FT_Byte v = *p; + TT_Byte v = *p; + + if ( v >= 27 && v != 31 ) { - /* its a number, we'll push its position on the stack */ - if (parser->top - parser->stack >= T2_MAX_STACK_DEPTH) + /* it's a number; we will push its position on the stack */ + if ( parser->top - parser->stack >= T2_MAX_STACK_DEPTH ) goto Stack_Overflow; *parser->top ++ = p; - + /* now, skip it */ - if (v == 30) + if ( v == 30 ) { /* skip real number */ for (;;) { - if (p >= limit) goto Syntax_Error; + if ( p >= limit ) + goto Syntax_Error; v = p[0] >> 4; - if (v == 15) break; + if ( v == 15 ) + break; v = p[0] & 0xF; - if (v == 15) break; + if ( v == 15 ) + break; p++; } p++; } - else if (v == 28) + else if ( v == 28 ) p += 2; - else if (v == 29) + else if ( v == 29 ) p += 4; - else if (v > 246) + else if ( v > 246 ) p += 1; } else { - /* this is not a number, hence it's an operator. Compute its code */ - /* and look for it in our current list.. */ - FT_UInt code; - FT_Int num_args = parser->top - parser->stack; + /* this is not a number, hence it's an operator. Compute its code */ + /* and look for it in our current list. */ + + TT_UInt code; + TT_Int num_args = parser->top - parser->stack; const T2_Field_Handler* field; + /* first of all, a trivial check */ - if ( num_args < 1 ) goto Stack_Underflow; + if ( num_args < 1 ) + goto Stack_Underflow; *parser->top = p; code = v; - if (v == 12) + if ( v == 12 ) { /* two byte operator */ p++; code = 0x100 | p[0]; } code = code | parser->object_code; - + for ( field = t2_field_handlers; field->kind; field++ ) { - if (field->code == code) + if ( field->code == code ) { - /* we found our field's handler, read it.. */ - FT_Long val; - FT_Byte* q = (FT_Byte*)parser->object + field->offset; - - switch (field->kind) - { - case t2_kind_bool: - case t2_kind_string: - case t2_kind_num: - val = t2_parse_num( parser->stack ); - goto Store_Number; - - case t2_kind_fixed: - val = t2_parse_fixed( parser->stack ); - - Store_Number: - switch (field->size) - { - case 1: *(FT_Byte*) q = (FT_Byte)val; break; - case 2: *(FT_Short*)q = (FT_Short)val; break; - default: *(FT_Long*)q = val; - } - break; - - - case t2_kind_delta: - { - FT_Byte* qcount = (FT_Byte*)parser->object + - field->count_offset; + /* we found our field's handler; read it */ + TT_Long val; + TT_Byte* q = (TT_Byte*)parser->object + field->offset; - FT_Long val; - FT_Byte** data = parser->stack; - - if (num_args > field->array_max) - num_args = field->array_max; - - /* store count */ - *qcount = (FT_Byte)num_args; - - val = 0; - while (num_args > 0) - { - val += t2_parse_num( data++ ); - switch (field->size) - { - case 1: *(FT_Byte*) q = (FT_Byte)val; break; - case 2: *(FT_Short*)q = (FT_Short)val; break; - default: *(FT_Long*)q = val; - } - q += field->size; - num_args--; - } - } - break; - - default: /* callback */ - error = field->reader( parser ); - if (error) goto Exit; + + switch ( field->kind ) + { + case t2_kind_bool: + case t2_kind_string: + case t2_kind_num: + val = t2_parse_num( parser->stack ); + goto Store_Number; + + case t2_kind_fixed: + val = t2_parse_fixed( parser->stack ); + + Store_Number: + switch ( field->size ) + { + case 1: + *(TT_Byte*)q = (TT_Byte)val; + break; + case 2: + *(TT_Short*)q = (TT_Short)val; + break; + default: + *(TT_Long*)q = val; + } + break; + + case t2_kind_delta: + { + TT_Byte* qcount = (TT_Byte*)parser->object + + field->count_offset; + + TT_Long val; + TT_Byte** data = parser->stack; + + + if ( num_args > field->array_max ) + num_args = field->array_max; + + /* store count */ + *qcount = (TT_Byte)num_args; + + val = 0; + while ( num_args > 0 ) + { + val += t2_parse_num( data++ ); + switch ( field->size ) + { + case 1: + *(TT_Byte*)q = (TT_Byte)val; + break; + case 2: + *(TT_Short*)q = (TT_Short)val; + break; + default: + *(TT_Long*)q = val; + } + + q += field->size; + num_args--; + } + } + break; + + default: /* callback */ + error = field->reader( parser ); + if ( error ) + goto Exit; } goto Found; } } - /* this is an unknown operator, or it is unsupported, we will ignore */ - /* it for now... */ + /* this is an unknown operator, or it is unsupported; */ + /* we will ignore it for now. */ - Found: + Found: /* clear stack */ parser->top = parser->stack; } p++; } + Exit: return error; - + Stack_Overflow: - error = FT_Err_Invalid_Argument; + error = T2_Err_Invalid_Argument; goto Exit; - + Stack_Underflow: - error = FT_Err_Invalid_Argument; + error = T2_Err_Invalid_Argument; goto Exit; - + Syntax_Error: - error = FT_Err_Invalid_Argument; + error = T2_Err_Invalid_Argument; goto Exit; - - } - - - + } +/* END */ diff --git a/src/cff/t2parse.h b/src/cff/t2parse.h index 840cfb7ac..2e6325570 100644 --- a/src/cff/t2parse.h +++ b/src/cff/t2parse.h @@ -1,3 +1,21 @@ +/***************************************************************************/ +/* */ +/* t2parse.h */ +/* */ +/* OpenType parser (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + #ifndef T2PARSE_H #define T2PARSE_H @@ -6,31 +24,47 @@ #define T2_MAX_STACK_DEPTH 96 -#define T2CODE_TOPDICT 0x1000 -#define T2CODE_PRIVATE 0x2000 +#define T2CODE_TOPDICT 0x1000 +#define T2CODE_PRIVATE 0x2000 - typedef struct T2_Parser_ + +#ifdef __cplusplus + extern "C" { +#endif + + + typedef struct T2_Parser_ { - FT_Byte* start; - FT_Byte* limit; - FT_Byte* cursor; - - FT_Byte* stack[ T2_MAX_STACK_DEPTH+1 ]; - FT_Byte** top; - - FT_UInt object_code; + TT_Byte* start; + TT_Byte* limit; + TT_Byte* cursor; + + TT_Byte* stack[T2_MAX_STACK_DEPTH + 1]; + TT_Byte** top; + + TT_UInt object_code; void* object; - + } T2_Parser; LOCAL_DEF - void T2_Parser_Init( T2_Parser* parser, FT_UInt code, void* object ); - + void T2_Parser_Init( T2_Parser* parser, + TT_UInt code, + void* object ); LOCAL_DEF - FT_Error T2_Parser_Run( T2_Parser* parser, - FT_Byte* start, - FT_Byte* limit ); + TT_Error T2_Parser_Run( T2_Parser* parser, + TT_Byte* start, + TT_Byte* limit ); + + +#ifdef __cplusplus + } +#endif + #endif /* T2PARSE_H */ + + +/* END */ diff --git a/src/cff/t2tokens.h b/src/cff/t2tokens.h index 878f6c5cf..7b6e4e6c5 100644 --- a/src/cff/t2tokens.h +++ b/src/cff/t2tokens.h @@ -1,3 +1,20 @@ +/***************************************************************************/ +/* */ +/* t2tokens.h */ +/* */ +/* OpenType token definitions (specification only). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + #undef T2TYPE #undef T2CODE @@ -28,7 +45,7 @@ T2_FIELD_STRING ( 0x115, postscript ) T2_FIELD_STRING ( 0x116, base_font_name ) -#if 0 +#if 0 T2_FIELD_DELTA ( 0x117, base_font_blend, 16 ) T2_FIELD_CALLBACK( 0x118, multiple_master ) T2_FIELD_CALLBACK( 0x119, blend_axit_types ) @@ -48,8 +65,9 @@ T2_FIELD_NUM ( 0x127, chameleon ) #endif -#undef T2TYPE -#undef T2CODE + +#undef T2TYPE +#undef T2CODE #define T2TYPE CFF_Private #define T2CODE T2CODE_PRIVATE @@ -74,3 +92,5 @@ T2_FIELD_NUM ( 20, default_width ) T2_FIELD_NUM ( 21, nominal_width ) + +/* END */ diff --git a/src/cid/cidafm.c b/src/cid/cidafm.c index 48282f991..1bd27884d 100644 --- a/src/cid/cidafm.c +++ b/src/cid/cidafm.c @@ -1,50 +1,76 @@ -/*************************************************************************** - * - * t1afm.c - support for reading Type 1 AFM files - * - * - ***************************************************************************/ +/***************************************************************************/ +/* */ +/* cidafm.c */ +/* */ +/* AFM support for CID-keyed fonts (body). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + #include #include #include -#include /* for qsort */ +#include + +#include /* for qsort() */ +#include /* for strcmp() */ +#include /* for isalnum() */ + LOCAL_FUNC - void CID_Done_AFM( FT_Memory memory, T1_AFM* afm ) + void CID_Done_AFM( FT_Memory memory, + T1_AFM* afm ) { FREE( afm->kern_pairs ); afm->num_pairs = 0; } + #undef IS_KERN_PAIR -#define IS_KERN_PAIR(p) ( p[0] == 'K' && p[1] == 'P' ) +#define IS_KERN_PAIR( p ) ( p[0] == 'K' && p[1] == 'P' ) -#define IS_ALPHANUM(c) ( (c >= 'A' && c <= 'Z') || \ - (c >= 'a' && c <= 'z') || \ - (c >= '0' && c <= '9') || \ - (c == '_' && c == '.') ) +#define IS_ALPHANUM( c ) ( isalnum( c ) || \ + c == '_' || \ + c == '.' ) - /* read a glyph name and return the equivalent glyph index */ + + /* read a glyph name and return the equivalent glyph index */ static - FT_UInt afm_atoindex( FT_Byte* *start, FT_Byte* limit, T1_Font* type1 ) + T1_UInt afm_atoindex( T1_Byte** start, + T1_Byte* limit, + T1_Font* type1 ) { - FT_Byte* p = *start; - FT_Int len; - FT_UInt result = 0; - char temp[64]; + T1_Byte* p = *start; + T1_Int len; + T1_UInt result = 0; + char temp[64]; + /* skip whitespace */ - while ( (*p == ' ' || *p == '\t' || *p == ':' || *p == ';') && p < limit ) + while ( ( *p == ' ' || *p == '\t' || *p == ':' || *p == ';' ) && + p < limit ) p++; *start = p; /* now, read glyph name */ - while ( IS_ALPHANUM(*p) && p < limit ) p++; + while ( IS_ALPHANUM( *p ) && p < limit ) + p++; + len = p - *start; - if (len > 0 && len < 64) + + if ( len > 0 && len < 64 ) { - FT_Int n; + T1_Int n; + /* copy glyph name to intermediate array */ MEM_Copy( temp, *start, len ); @@ -55,7 +81,8 @@ { char* gname = (char*)type1->glyph_names[n]; - if ( gname && gname[0] == temp[0] && strcmp(gname,temp) == 0 ) + + if ( gname && gname[0] == temp[0] && strcmp( gname, temp ) == 0 ) { result = n; break; @@ -67,16 +94,18 @@ } - /* read an integer */ + /* read an integer */ static - int afm_atoi( FT_Byte** start, FT_Byte* limit ) + int afm_atoi( T1_Byte** start, + T1_Byte* limit ) { - FT_Byte* p = *start; + T1_Byte* p = *start; int sum = 0; int sign = 1; + /* skip everything that is not a number */ - while ( p < limit && (*p < '0' || *p > '9') ) + while ( p < limit && !isdigit( *p ) ) { sign = 1; if (*p == '-') @@ -85,70 +114,75 @@ p++; } - while ( p < limit && (*p >= '0' && *p < '9') ) + while ( p < limit && isdigit( *p ) ) { - sum = sum*10 + (*p - '0'); + sum = sum * 10 + ( *p - '0' ); p++; } *start = p; - return sum*sign; + + return sum * sign; } #undef KERN_INDEX -#define KERN_INDEX(g1,g2) (((FT_ULong)g1 << 16) | g2) +#define KERN_INDEX( g1, g2 ) ( ( (T1_ULong)g1 << 16 ) | g2 ) - /* compare two kerning pairs */ + + /* compare two kerning pairs */ static - int compare_kern_pairs( const void* a, const void* b ) + int compare_kern_pairs( const void* a, + const void* b ) { T1_Kern_Pair* pair1 = (T1_Kern_Pair*)a; T1_Kern_Pair* pair2 = (T1_Kern_Pair*)b; - FT_ULong index1 = KERN_INDEX(pair1->glyph1,pair1->glyph2); - FT_ULong index2 = KERN_INDEX(pair2->glyph1,pair2->glyph2); + T1_ULong index1 = KERN_INDEX( pair1->glyph1, pair1->glyph2 ); + T1_ULong index2 = KERN_INDEX( pair2->glyph1, pair2->glyph2 ); + return ( index1 - index2 ); } - /* parse an AFM file - for now, only read the kerning pairs */ + /* parse an AFM file - for now, only read the kerning pairs */ LOCAL_FUNC - FT_Error CID_Read_AFM( FT_Face t1_face, - FT_Stream stream ) + T1_Error CID_Read_AFM( FT_Face t1_face, + FT_Stream stream ) { - FT_Error error; + T1_Error error; FT_Memory memory = stream->memory; - FT_Byte* start; - FT_Byte* limit; - FT_Byte* p; - FT_Int count = 0; + T1_Byte* start; + T1_Byte* limit; + T1_Byte* p; + T1_Int count = 0; T1_Kern_Pair* pair; T1_Font* type1 = &((T1_Face)t1_face)->type1; T1_AFM* afm = 0; - if ( ACCESS_Frame(stream->size) ) + + if ( ACCESS_Frame( stream->size ) ) return error; - start = (FT_Byte*)stream->cursor; - limit = (FT_Byte*)stream->limit; + start = (T1_Byte*)stream->cursor; + limit = (T1_Byte*)stream->limit; p = start; /* we are now going to count the occurences of "KP" or "KPX" in */ - /* the AFM file.. */ + /* the AFM file. */ count = 0; - for ( p = start; p < limit-3; p++ ) + for ( p = start; p < limit - 3; p++ ) { - if ( IS_KERN_PAIR(p) ) + if ( IS_KERN_PAIR( p ) ) count++; } - /* Actually, kerning pairs are simply optional !! */ - if (count == 0) + /* Actually, kerning pairs are simply optional! */ + if ( count == 0 ) goto Exit; /* allocate the pairs */ - if ( ALLOC( afm, sizeof(*afm ) ) || + if ( ALLOC( afm, sizeof ( *afm ) ) || ALLOC_ARRAY( afm->kern_pairs, count, T1_Kern_Pair ) ) goto Exit; @@ -159,15 +193,17 @@ /* save in face object */ ((T1_Face)t1_face)->afm_data = afm; - for ( p = start; p < limit-3; p++ ) + for ( p = start; p < limit - 3; p++ ) { - if ( IS_KERN_PAIR(p) ) + if ( IS_KERN_PAIR( p ) ) { - FT_Byte* q; + T1_Byte* q; + /* skip keyword (KP or KPX) */ - q = p+2; - if (*q == 'X') q++; + q = p + 2; + if ( *q == 'X' ) + q++; pair->glyph1 = afm_atoindex( &q, limit, type1 ); pair->glyph2 = afm_atoindex( &q, limit, type1 ); @@ -182,47 +218,56 @@ } /* now, sort the kern pairs according to their glyph indices */ - qsort( afm->kern_pairs, count, sizeof(T1_Kern_Pair), compare_kern_pairs ); + qsort( afm->kern_pairs, count, sizeof ( T1_Kern_Pair ), + compare_kern_pairs ); Exit: - if (error) + if ( error ) FREE( afm ); FORGET_Frame(); + return error; } - /* find the kerning for a given glyph pair */ + /* find the kerning for a given glyph pair */ LOCAL_FUNC void CID_Get_Kerning( T1_AFM* afm, - FT_UInt glyph1, - FT_UInt glyph2, - FT_Vector* kerning ) + T1_UInt glyph1, + T1_UInt glyph2, + T1_Vector* kerning ) { T1_Kern_Pair *min, *mid, *max; - FT_ULong index = KERN_INDEX(glyph1,glyph2); + T1_ULong index = KERN_INDEX( glyph1, glyph2 ); + /* simple binary search */ min = afm->kern_pairs; - max = min + afm->num_pairs-1; + max = min + afm->num_pairs - 1; - while (min <= max) + while ( min <= max ) { - FT_ULong midi; + T1_ULong midi; - mid = min + (max-min)/2; - midi = KERN_INDEX(mid->glyph1,mid->glyph2); + + mid = min + ( max - min ) / 2; + midi = KERN_INDEX( mid->glyph1, mid->glyph2 ); if ( midi == index ) { *kerning = mid->kerning; return; } - if ( midi < index ) min = mid+1; - else max = mid-1; + if ( midi < index ) + min = mid + 1; + else + max = mid - 1; } + kerning->x = 0; kerning->y = 0; } + +/* END */ diff --git a/src/cid/cidafm.h b/src/cid/cidafm.h index ad4fe2fe4..4bc7c85ac 100644 --- a/src/cid/cidafm.h +++ b/src/cid/cidafm.h @@ -1,49 +1,61 @@ -/*************************************************************************** - * - * t1afm.h - support for reading Type 1 AFM files - * - * - ***************************************************************************/ +/***************************************************************************/ +/* */ +/* cidafm.h */ +/* */ +/* AFM support for CID-keyed fonts (specification). */ +/* */ +/* Copyright 1996-2000 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + #ifndef T1AFM_H #define T1AFM_H -#include +#include -/* In this version, we only read the kerning table from the */ -/* AFM file. We may add support for ligatures a bit later.. */ + typedef struct T1_Kern_Pair_ + { + T1_UInt glyph1; + T1_UInt glyph2; + T1_Vector kerning; -typedef struct T1_Kern_Pair_ -{ - FT_UInt glyph1; - FT_UInt glyph2; - FT_Vector kerning; + } T1_Kern_Pair; -} T1_Kern_Pair; + typedef struct T1_AFM_ + { + T1_Int num_pairs; + T1_Kern_Pair* kern_pairs; + } T1_AFM; -typedef struct T1_AFM_ -{ - FT_Int num_pairs; - T1_Kern_Pair* kern_pairs; - -} T1_AFM; #if 0 LOCAL_DEF -FT_Error CID_Read_AFM( FT_Face face, +T1_Error CID_Read_AFM( FT_Face face, FT_Stream stream ); LOCAL_DEF -void CID_Done_AFM( FT_Memory memory, - T1_AFM* afm ); +void CID_Done_AFM( FT_Memory memory, + T1_AFM* afm ); LOCAL_DEF void CID_Get_Kerning( T1_AFM* afm, - FT_UInt glyph1, - FT_UInt glyph2, - FT_Vector* kerning ); + T1_UInt glyph1, + T1_UInt glyph2, + T1_Vector* kerning ); + #endif #endif /* T1AFM_H */ + + +/* END */ diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c index 928554bb8..63cde406a 100644 --- a/src/sfnt/sfobjs.c +++ b/src/sfnt/sfobjs.c @@ -16,10 +16,11 @@ /***************************************************************************/ -#include +#include #include #include #include +#include /*************************************************************************/ @@ -49,13 +50,13 @@ /* Character string. NULL if no name is present. */ /* */ static - FT_String* Get_Name( TT_Face face, - FT_UShort nameid ) + TT_String* Get_Name( TT_Face face, + TT_UShort nameid ) { FT_Memory memory = face->root.memory; - FT_UShort n; + TT_UShort n; TT_NameRec* rec; - FT_Bool wide_chars = 1; + TT_Bool wide_chars = 1; rec = face->name_table.names; @@ -64,7 +65,7 @@ if ( rec->nameID == nameid ) { /* found the name - now create an ASCII string from it */ - FT_Bool found = 0; + TT_Bool found = 0; /* test for Microsoft English language */ @@ -88,8 +89,8 @@ /* found a Unicode name */ if ( found ) { - FT_String* string; - FT_UInt len; + TT_String* string; + TT_UInt len; if ( wide_chars ) @@ -172,13 +173,13 @@ LOCAL_FUNC - FT_Error SFNT_Init_Face( FT_Stream stream, + TT_Error SFNT_Init_Face( FT_Stream stream, TT_Face face, TT_Int face_index, TT_Int num_params, FT_Parameter* params ) { - FT_Error error; + TT_Error error; SFNT_Interface* sfnt; PSNames_Interface* psnames; SFNT_Header sfnt_header; @@ -249,7 +250,7 @@ #undef LOAD_ -#define LOAD_( x ) ( (error = sfnt->load_##x( face, stream )) != FT_Err_Ok ) +#define LOAD_( x ) ( (error = sfnt->load_##x( face, stream )) != TT_Err_Ok ) LOCAL_FUNC @@ -259,7 +260,7 @@ TT_Int num_params, FT_Parameter* params ) { - FT_Error error; + TT_Error error; SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt; @@ -268,10 +269,10 @@ LOAD_( max_profile ) || /* load the `hhea' & `hmtx' tables at once */ - ( error = sfnt->load_metrics( face, stream, 0 ) ) != FT_Err_Ok || + ( error = sfnt->load_metrics( face, stream, 0 ) ) != TT_Err_Ok || /* try to load the `vhea' & `vmtx' at once if present */ - ( error = sfnt->load_metrics( face, stream, 1 ) ) != FT_Err_Ok || + ( error = sfnt->load_metrics( face, stream, 1 ) ) != TT_Err_Ok || LOAD_( charmaps ) || LOAD_( names ) || @@ -294,7 +295,7 @@ goto Exit; #ifdef TT_CONFIG_OPTION_EXTEND_ENGINE - if ( ( error = TT_Extension_Create( face ) ) != FT_Err_Ok ) + if ( ( error = TT_Extension_Create( face ) ) != TT_Err_Ok ) goto Exit; #endif @@ -304,7 +305,7 @@ /* now set up root fields */ { FT_Face root = &face->root; - FT_Int flags; + TT_Int flags; TT_CharMap charmap; TT_Int n; FT_Memory memory; @@ -377,8 +378,8 @@ for ( n = 0; n < root->num_charmaps; n++, charmap++ ) { - FT_Int platform = charmap->cmap.platformID; - FT_Int encoding = charmap->cmap.platformEncodingID; + TT_Int platform = charmap->cmap.platformID; + TT_Int encoding = charmap->cmap.platformEncodingID; charmap->root.face = (FT_Face)face; @@ -501,7 +502,7 @@ /* freeing the character mapping tables */ if (sfnt && sfnt->load_charmaps ) { - FT_UShort n; + TT_UShort n; for ( n = 0; n < face->num_charmaps; n++ ) diff --git a/src/sfnt/sfobjs.h b/src/sfnt/sfobjs.h index 380a1fc62..564ed26b0 100644 --- a/src/sfnt/sfobjs.h +++ b/src/sfnt/sfobjs.h @@ -24,14 +24,14 @@ LOCAL_DEF - FT_Error SFNT_Init_Face( FT_Stream stream, + TT_Error SFNT_Init_Face( FT_Stream stream, TT_Face face, TT_Int face_index, TT_Int num_params, FT_Parameter* params ); LOCAL_DEF - FT_Error SFNT_Load_Face( FT_Stream stream, + TT_Error SFNT_Load_Face( FT_Stream stream, TT_Face face, TT_Int face_index, TT_Int num_params, diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c index 8a8fc8475..aad9047af 100644 --- a/src/sfnt/ttload.c +++ b/src/sfnt/ttload.c @@ -157,9 +157,9 @@ TT_Long face_index, SFNT_Header* sfnt ) { - TT_Error error; - TT_ULong format_tag; - FT_Memory memory = stream->memory; + TT_Error error; + TT_ULong format_tag; + FT_Memory memory = stream->memory; const FT_Frame_Field sfnt_header_fields[] = { diff --git a/src/sfnt/ttpost.c b/src/sfnt/ttpost.c index 5a6a70cf6..697dd1c18 100644 --- a/src/sfnt/ttpost.c +++ b/src/sfnt/ttpost.c @@ -62,7 +62,7 @@ /* the 258 default Mac PS glyph names */ - FT_String* TT_Post_Default_Names[258] = + TT_String* TT_Post_Default_Names[258] = { /* 0 */ ".notdef", ".null", "CR", "space", "exclam", diff --git a/src/sfnt/ttsbit.c b/src/sfnt/ttsbit.c index 66e06f018..f8ef409d8 100644 --- a/src/sfnt/ttsbit.c +++ b/src/sfnt/ttsbit.c @@ -63,18 +63,18 @@ /* */ static void blit_sbit( FT_Bitmap* target, - FT_Byte* source, - FT_Int line_bits, - FT_Bool byte_padded, - FT_Int x_offset, - FT_Int y_offset ) + TT_Byte* source, + TT_Int line_bits, + TT_Bool byte_padded, + TT_Int x_offset, + TT_Int y_offset ) { - FT_Byte* line_buff; - FT_Int line_incr; - FT_Int height; + TT_Byte* line_buff; + TT_Int line_incr; + TT_Int height; - FT_UShort acc; - FT_Byte loaded; + TT_UShort acc; + TT_Byte loaded; /* first of all, compute starting write position */ @@ -102,10 +102,10 @@ for ( height = target->rows; height > 0; height-- ) { - FT_Byte* cur = line_buff; /* current write cursor */ - FT_Int count = line_bits; /* # of bits to extract per line */ - FT_Byte shift = x_offset & 7; /* current write shift */ - FT_Byte space = 8 - shift; + TT_Byte* cur = line_buff; /* current write cursor */ + TT_Int count = line_bits; /* # of bits to extract per line */ + TT_Byte shift = x_offset & 7; /* current write shift */ + TT_Byte space = 8 - shift; /* first of all, read individual source bytes */ @@ -115,18 +115,18 @@ { do { - FT_Byte val; + TT_Byte val; /* ensure that there are at least 8 bits in the accumulator */ if ( loaded < 8 ) { - acc |= (FT_UShort)*source++ << ( 8 - loaded ); + acc |= (TT_UShort)*source++ << ( 8 - loaded ); loaded += 8; } /* now write one byte */ - val = (FT_Byte)( acc >> 8 ); + val = (TT_Byte)( acc >> 8 ); if ( shift ) { cur[0] |= val >> shift; @@ -150,18 +150,18 @@ /* now write remaining bits (count < 8) */ if ( count > 0 ) { - FT_Byte val; + TT_Byte val; /* ensure that there are at least `count' bits in the accumulator */ if ( loaded < count ) { - acc |= (FT_UShort)*source++ << ( 8 - loaded ); + acc |= (TT_UShort)*source++ << ( 8 - loaded ); loaded += 8; } /* now write remaining bits */ - val = ( (FT_Byte)( acc >> 8 ) ) & ~( 0xFF >> count ); + val = ( (TT_Byte)( acc >> 8 ) ) & ~( 0xFF >> count ); cur[0] |= val >> shift; if ( count > space ) @@ -1148,7 +1148,7 @@ /* don't forget to multiply `x_offset' by `map->pix_bits' as */ /* the sbit blitter doesn't make a difference between pixmap */ /* depths. */ - blit_sbit( map, (FT_Byte*)stream->cursor, line_bits, pad_bytes, + blit_sbit( map, (TT_Byte*)stream->cursor, line_bits, pad_bytes, x_offset * pix_bits, y_offset ); FORGET_Frame(); @@ -1403,8 +1403,8 @@ if ( strike->flags & 1 ) { /* in case of a horizontal strike only */ - FT_Int advance; - FT_Int top; + TT_Int advance; + TT_Int top; advance = strike->hori.ascender - strike->hori.descender; diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c index e2e3592d4..6a0dd4979 100644 --- a/src/truetype/ttdriver.c +++ b/src/truetype/ttdriver.c @@ -48,7 +48,6 @@ /*************************************************************************/ - #undef PAIR_TAG #define PAIR_TAG( left, right ) ( ( (TT_ULong)left << 16 ) | \ (TT_ULong)right ) @@ -397,6 +396,7 @@ /*************************************************************************/ /*************************************************************************/ + static FTDriver_Interface tt_get_interface( TT_Driver driver, const char* interface ) diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c index 5853ec893..20cd40ac0 100644 --- a/src/truetype/ttgload.c +++ b/src/truetype/ttgload.c @@ -681,7 +681,7 @@ do { TT_Fixed xx, xy, yy, yx; - FT_UInt total_subglyphs; + TT_UInt total_subglyphs; /* grow the `glyph->subglyphs' table if necessary */ @@ -689,7 +689,7 @@ if ( total_subglyphs >= glyph->max_subglyphs ) { - FT_UInt new_max = glyph->max_subglyphs; + TT_UInt new_max = glyph->max_subglyphs; FT_Memory memory = loader->face->root.memory; @@ -1113,8 +1113,9 @@ if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) && loader->load_flags & FT_LOAD_LINEAR ) { - FT_Pos em_size = face->root.units_per_EM; - FT_Pos pixel_size = (FT_Pos)face->root.size->metrics.x_ppem << 16; + TT_Pos em_size = face->root.units_per_EM; + TT_Pos pixel_size = (TT_Pos)face->root.size->metrics.x_ppem << 16; + lsb2 = FT_MulDiv( lsb2, pixel_size, em_size ); adv2 = FT_MulDiv( adv2, pixel_size, em_size ); diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c index 76780da62..3701ce898 100644 --- a/src/truetype/ttinterp.c +++ b/src/truetype/ttinterp.c @@ -854,7 +854,7 @@ static TT_F26Dot6 Norm( TT_F26Dot6 X, TT_F26Dot6 Y ) { - FT_Int64 T1, T2; + TT_INT64 T1, T2; MUL_64( X, X, T1 ); diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c index ee4c846c3..a023233bf 100644 --- a/src/truetype/ttobjs.c +++ b/src/truetype/ttobjs.c @@ -133,7 +133,6 @@ } - /*************************************************************************/ /* */ /* */ @@ -645,7 +644,7 @@ TT_Error TT_Init_Driver( TT_Driver driver ) { FT_Memory memory = driver->root.memory; - FT_Error error; + TT_Error error; error = FT_New_GlyphZone( memory, 0, 0, &driver->zone );