The next round of formatting, checking documentation, etc.

This commit is contained in:
Werner Lemberg 2000-06-13 23:21:00 +00:00
parent 78575dc0d1
commit 7a4fda8821
22 changed files with 2334 additions and 1818 deletions

View File

@ -16,6 +16,7 @@
/***************************************************************************/ /***************************************************************************/
#include <freetype/freetype.h>
#include <freetype/internal/ftdebug.h> #include <freetype/internal/ftdebug.h>
#include <freetype/internal/ftstream.h> #include <freetype/internal/ftstream.h>
#include <freetype/internal/sfnt.h> #include <freetype/internal/sfnt.h>
@ -24,6 +25,8 @@
#include <t2driver.h> #include <t2driver.h>
#include <t2gload.h> #include <t2gload.h>
#include <freetype/internal/t2errors.h>
/*************************************************************************/ /*************************************************************************/
/* */ /* */
@ -47,6 +50,7 @@
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
#undef PAIR_TAG #undef PAIR_TAG
#define PAIR_TAG( left, right ) ( ( (TT_ULong)left << 16 ) | \ #define PAIR_TAG( left, right ) ( ( (TT_ULong)left << 16 ) | \
(TT_ULong)right ) (TT_ULong)right )
@ -74,12 +78,12 @@
/* formats. */ /* formats. */
/* */ /* */
/* <Return> */ /* <Return> */
/* FreeType error code. 0 means success. */ /* TrueType error code. 0 means success. */
/* */ /* */
/* <Note> */ /* <Note> */
/* Only horizontal layouts (left-to-right & right-to-left) are */ /* Only horizontal layouts (left-to-right & right-to-left) are */
/* supported by this function. Other layouts, or more sophisticated */ /* 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). */ /* interface is meant to be simple). */
/* */ /* */
/* They can be implemented by format-specific interfaces. */ /* They can be implemented by format-specific interfaces. */
@ -94,7 +98,7 @@
if ( !face ) if ( !face )
return FT_Err_Invalid_Face_Handle; return T2_Err_Invalid_Face_Handle;
kerning->x = 0; kerning->x = 0;
kerning->y = 0; kerning->y = 0;
@ -111,7 +115,7 @@
while ( left <= right ) while ( left <= right )
{ {
TT_Int middle = left + ((right-left) >> 1); TT_Int middle = left + ( ( right - left ) >> 1 );
TT_ULong cur_pair; TT_ULong cur_pair;
@ -122,14 +126,14 @@
goto Found; goto Found;
if ( cur_pair < search_tag ) if ( cur_pair < search_tag )
left = middle+1; left = middle + 1;
else else
right = middle-1; right = middle - 1;
} }
} }
Exit: Exit:
return FT_Err_Ok; return T2_Err_Ok;
Found: Found:
kerning->x = pair->value; kerning->x = pair->value;
@ -163,47 +167,54 @@
/* and vertical) expressed in fractional points. */ /* and vertical) expressed in fractional points. */
/* */ /* */
/* <Input> */ /* <Input> */
/* char_width :: The character width expressed in 26.6 fractional */ /* char_width :: The character width expressed in 26.6 */
/* points. */ /* fractional points. */
/* char_height :: The character height 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. */
/* */ /* */
/* <InOut> */ /* <InOut> */
/* size :: A handle to the target size object. */ /* size :: A handle to the target size object. */
/* */ /* */
/* <Return> */ /* <Return> */
/* FreeType error code. 0 means success. */ /* TrueType error code. 0 means success. */
/* */ /* */
static static
TT_Error Set_Char_Sizes( T2_Size size, TT_Error Set_Char_Sizes( T2_Size size,
FT_F26Dot6 char_width, TT_F26Dot6 char_width,
FT_F26Dot6 char_height, TT_F26Dot6 char_height,
FT_UInt horz_resolution, TT_UInt horz_resolution,
FT_UInt vert_resolution ) TT_UInt vert_resolution )
{ {
FT_Size_Metrics* metrics = &size->metrics; FT_Size_Metrics* metrics = &size->metrics;
T2_Face face = (T2_Face)size->face; T2_Face face = (T2_Face)size->face;
FT_Long dim_x, dim_y; FT_Long dim_x, dim_y;
/* This bit flag, when set, indicates that the pixel size must be */ /* 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. */ /* bit set, as hinting won't work really well otherwise. */
/* */ /* */
/* However, for those rare fonts who do not set it, we override */ /* However, for those rare fonts who do not set it, we override */
/* the default computations performed by the base layer. I really */ /* the default computations performed by the base layer. I */
/* don't know if this is useful, but hey, that's the spec :-) */ /* 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 */ /* Compute pixel sizes in 26.6 units */
dim_x = (char_width * horz_resolution) / 72; dim_x = ( char_width * horz_resolution ) / 72;
dim_y = (char_height * vert_resolution) / 72; dim_y = ( char_height * vert_resolution ) / 72;
metrics->x_scale = FT_DivFix( dim_x, face->root.units_per_EM ); 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->y_scale = FT_DivFix( dim_y, face->root.units_per_EM );
metrics->x_ppem = (TT_UShort)(dim_x >> 6); metrics->x_ppem = (TT_UShort)( dim_x >> 6 );
metrics->y_ppem = (TT_UShort)(dim_y >> 6); metrics->y_ppem = (TT_UShort)( dim_y >> 6 );
} }
return T2_Reset_Size( size ); return T2_Reset_Size( size );
@ -228,15 +239,15 @@
/* size :: A handle to the target size object. */ /* size :: A handle to the target size object. */
/* */ /* */
/* <Return> */ /* <Return> */
/* FreeType error code. 0 means success */ /* TrueType error code. 0 means success. */
/* */ /* */
static static
FT_Error Set_Pixel_Sizes( T2_Size size, TT_Error Set_Pixel_Sizes( T2_Size size,
FT_UInt pixel_width, TT_UInt pixel_width,
FT_UInt pixel_height ) TT_UInt pixel_height )
{ {
UNUSED(pixel_width); UNUSED( pixel_width );
UNUSED(pixel_height); UNUSED( pixel_height );
return T2_Reset_Size( size ); return T2_Reset_Size( size );
} }
@ -255,7 +266,7 @@
/* will be loaded. */ /* will be loaded. */
/* */ /* */
/* size :: A handle to the source face size at which the glyph */ /* 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. */ /* glyph_index :: The index of the glyph in the font file. */
/* */ /* */
@ -264,27 +275,23 @@
/* glyph loading process (e.g., whether the outline */ /* glyph loading process (e.g., whether the outline */
/* should be scaled, whether to load bitmaps or not, */ /* should be scaled, whether to load bitmaps or not, */
/* whether to hint the outline, etc). */ /* whether to hint the outline, etc). */
/* <Output> */
/* result :: A set of bit flags indicating the type of data that */
/* was loaded in the glyph slot (outline, bitmap, */
/* pixmap, etc). */
/* */ /* */
/* <Return> */ /* <Return> */
/* FreeType error code. 0 means success. */ /* TrueType error code. 0 means success. */
/* */ /* */
static static
FT_Error Load_Glyph( T2_GlyphSlot slot, TT_Error Load_Glyph( T2_GlyphSlot slot,
T2_Size size, T2_Size size,
FT_UShort glyph_index, TT_UShort glyph_index,
FT_UInt load_flags ) TT_UInt load_flags )
{ {
FT_Error error; TT_Error error;
if ( !slot ) 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 ) if ( !size )
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
@ -296,7 +303,7 @@
{ {
/* these two object must have the same parent */ /* these two object must have the same parent */
if ( size->face != slot->root.face ) 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 */ /* now load the glyph outline if necessary */
@ -336,13 +343,14 @@
/* Glyph index. 0 means `undefined character code'. */ /* Glyph index. 0 means `undefined character code'. */
/* */ /* */
static static
FT_UInt Get_Char_Index( TT_CharMap charmap, TT_UInt Get_Char_Index( TT_CharMap charmap,
FT_Long charcode ) TT_Long charcode )
{ {
FT_Error error; TT_Error error;
T2_Face face; T2_Face face;
TT_CMapTable* cmap; TT_CMapTable* cmap;
cmap = &charmap->cmap; cmap = &charmap->cmap;
face = (T2_Face)charmap->root.face; face = (T2_Face)charmap->root.face;
@ -351,29 +359,47 @@
{ {
SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt; SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt;
error = sfnt->load_charmap( face, cmap, face->root.stream ); error = sfnt->load_charmap( face, cmap, face->root.stream );
if (error) return error; if ( error )
return 0;
cmap->loaded = TRUE; 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 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" ); FT_Driver sfntd = FT_Get_Driver( driver->root.library, "sfnt" );
SFNT_Interface* sfnt; SFNT_Interface* sfnt;
/* only return the default interface from the SFNT module */ /* only return the default interface from the SFNT module */
if (sfntd) if ( sfntd )
{ {
sfnt = (SFNT_Interface*)(sfntd->interface.format_interface); sfnt = (SFNT_Interface*)(sfntd->interface.format_interface);
if (sfnt) if ( sfnt )
return sfnt->get_interface( (FT_Driver)driver, interface ); return sfnt->get_interface( (FT_Driver)driver, interface );
} }
return 0; return 0;
} }
@ -393,27 +419,29 @@
(void*)0, (void*)0,
(FTDriver_initDriver) T2_Init_Driver, (FTDriver_initDriver) T2_Init_Driver,
(FTDriver_doneDriver) T2_Done_Driver, (FTDriver_doneDriver) T2_Done_Driver,
(FTDriver_getInterface) t2_get_interface, (FTDriver_getInterface) t2_get_interface,
(FTDriver_initFace) T2_Init_Face, (FTDriver_initFace) T2_Init_Face,
(FTDriver_doneFace) T2_Done_Face, (FTDriver_doneFace) T2_Done_Face,
(FTDriver_getKerning) Get_Kerning, (FTDriver_getKerning) Get_Kerning,
(FTDriver_initSize) T2_Init_Size, (FTDriver_initSize) T2_Init_Size,
(FTDriver_doneSize) T2_Done_Size, (FTDriver_doneSize) T2_Done_Size,
(FTDriver_setCharSizes) Set_Char_Sizes, (FTDriver_setCharSizes) Set_Char_Sizes,
(FTDriver_setPixelSizes) Set_Pixel_Sizes, (FTDriver_setPixelSizes) Set_Pixel_Sizes,
(FTDriver_initGlyphSlot) T2_Init_GlyphSlot, (FTDriver_initGlyphSlot) T2_Init_GlyphSlot,
(FTDriver_doneGlyphSlot) T2_Done_GlyphSlot, (FTDriver_doneGlyphSlot) T2_Done_GlyphSlot,
(FTDriver_loadGlyph) Load_Glyph, (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 */ /* format-specific interface can then be retrieved through the method */
/* interface->get_format_interface. */ /* 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; return &cff_driver_interface;
} }
#endif /* CONFIG_OPTION_DYNAMIC_DRIVERS */ #endif /* CONFIG_OPTION_DYNAMIC_DRIVERS */

View File

@ -4,7 +4,7 @@
/* */ /* */
/* High-level OpenType driver interface (specification). */ /* High-level OpenType driver interface (specification). */
/* */ /* */
/* Copyright 1996-1999 by */ /* Copyright 1996-2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used, */ /* This file is part of the FreeType project, and may only be used, */
@ -19,13 +19,12 @@
#ifndef T2DRIVER_H #ifndef T2DRIVER_H
#define T2DRIVER_H #define T2DRIVER_H
#include <freetype/freetype.h>
#include <freetype/internal/ftdriver.h> #include <freetype/internal/ftdriver.h>
#include <freetype/ttnameid.h>
#include <t2objs.h> #include <t2objs.h>
#include <freetype/internal/t2errors.h>
FT_EXPORT_VAR(const FT_DriverInterface) cff_driver_interface; FT_EXPORT_VAR( const FT_DriverInterface ) cff_driver_interface;
#endif /* T2DRIVER_H */ #endif /* T2DRIVER_H */

File diff suppressed because it is too large Load Diff

View File

@ -4,11 +4,11 @@
/* */ /* */
/* OpenType Glyph Loader (specification). */ /* OpenType Glyph Loader (specification). */
/* */ /* */
/* Copyright 1996-1999 by */ /* Copyright 1996-2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used */ /* This file is part of the FreeType project, and may only be used, */
/* modified and distributed under the terms of the FreeType project */ /* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */ /* this file you indicate that you have read the license and */
/* understand and accept it fully. */ /* understand and accept it fully. */
@ -19,55 +19,71 @@
#ifndef T2GLOAD_H #ifndef T2GLOAD_H
#define T2GLOAD_H #define T2GLOAD_H
#include <freetype/freetype.h>
#include <t2objs.h> #include <t2objs.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#define T2_MAX_OPERANDS 48
#define T2_MAX_SUBRS_CALLS 32
/*************************************************************************/ #define T2_MAX_OPERANDS 48
/* */ #define T2_MAX_SUBRS_CALLS 32
/* <Structure> T2_Builder */
/* */
/* <Description> */
/* a structure used during glyph loading to store its outline. */
/* */
/* <Fields> */
/* 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.. */
/* */
typedef struct T2_Builder_
/*************************************************************************/
/* */
/* <Structure> */
/* T2_Builder */
/* */
/* <Description> */
/* A structure used during glyph loading to store its outline. */
/* */
/* <Fields> */
/* 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; FT_Memory memory;
TT_Face face; TT_Face face;
@ -76,107 +92,104 @@
FT_Outline current; /* the current glyph outline */ FT_Outline current; /* the current glyph outline */
FT_Outline base; /* the composite glyph outline */ FT_Outline base; /* the composite glyph outline */
FT_Int max_points; /* capacity of base outline in points */ TT_Int max_points; /* capacity of base outline in points */
FT_Int max_contours; /* capacity of base outline in contours */ TT_Int max_contours; /* capacity of base outline in contours */
FT_Vector last; TT_Vector last;
FT_Fixed scale_x; TT_Fixed scale_x;
FT_Fixed scale_y; TT_Fixed scale_y;
FT_Pos pos_x; TT_Pos pos_x;
FT_Pos pos_y; TT_Pos pos_y;
FT_Vector left_bearing; TT_Vector left_bearing;
FT_Vector advance; TT_Vector advance;
FT_BBox bbox; /* bounding box */ TT_BBox bbox; /* bounding box */
FT_Bool path_begun; TT_Bool path_begun;
FT_Bool load_points; TT_Bool load_points;
FT_Bool no_recurse; TT_Bool no_recurse;
FT_Error error; /* only used for memory errors */ TT_Error error; /* only used for memory errors */
FT_Bool metrics_only; TT_Bool metrics_only;
} T2_Builder; } T2_Builder;
/* execution context charstring zone */ /* execution context charstring zone */
typedef struct T2_Decoder_Zone_
typedef struct T2_Decoder_Zone_
{ {
FT_Byte* base; TT_Byte* base;
FT_Byte* limit; TT_Byte* limit;
FT_Byte* cursor; TT_Byte* cursor;
} T2_Decoder_Zone; } T2_Decoder_Zone;
typedef struct T2_Decoder_ typedef struct T2_Decoder_
{ {
T2_Builder builder; T2_Builder builder;
CFF_Font* cff; CFF_Font* cff;
FT_Fixed stack[ T2_MAX_OPERANDS+1 ]; TT_Fixed stack[T2_MAX_OPERANDS + 1];
FT_Fixed* top; TT_Fixed* top;
T2_Decoder_Zone zones[ T2_MAX_SUBRS_CALLS+1 ]; T2_Decoder_Zone zones[T2_MAX_SUBRS_CALLS + 1];
T2_Decoder_Zone* zone; T2_Decoder_Zone* zone;
FT_Int flex_state; TT_Int flex_state;
FT_Int num_flex_vectors; TT_Int num_flex_vectors;
FT_Vector flex_vectors[7]; TT_Vector flex_vectors[7];
FT_Pos glyph_width; TT_Pos glyph_width;
FT_Pos nominal_width; TT_Pos nominal_width;
FT_Bool read_width;
FT_Int num_hints;
FT_Fixed* buildchar;
FT_Int len_buildchar;
FT_UInt num_locals; TT_Bool read_width;
FT_UInt num_globals; TT_Int num_hints;
TT_Fixed* buildchar;
FT_Int locals_bias; TT_Int len_buildchar;
FT_Int globals_bias;
FT_Byte** locals;
FT_Byte** globals;
TT_UInt num_locals;
TT_UInt num_globals;
TT_Int locals_bias;
TT_Int globals_bias;
TT_Byte** locals;
TT_Byte** globals;
} T2_Decoder; } T2_Decoder;
LOCAL_DEF LOCAL_DEF
void T2_Init_Decoder( T2_Decoder* decoder, void T2_Init_Decoder( T2_Decoder* decoder,
TT_Face face, TT_Face face,
T2_Size size, T2_Size size,
T2_GlyphSlot slot ); T2_GlyphSlot slot );
#if 0 /* unused until we support pure CFF fonts */ #if 0 /* unused until we support pure CFF fonts */
/* Compute the maximum advance width of a font through quick parsing */ /* Compute the maximum advance width of a font through quick parsing */
LOCAL_DEF LOCAL_DEF
FT_Error T2_Compute_Max_Advance( TT_Face face, TT_Error T2_Compute_Max_Advance( TT_Face face,
FT_Int *max_advance ); TT_Int* max_advance );
#endif #endif
/* This function is exported, because it is used by the T1Dump utility */ /* This function is exported, because it is used by the T1Dump utility */
LOCAL_DEF LOCAL_DEF
FT_Error T2_Parse_CharStrings( T2_Decoder* decoder, TT_Error T2_Parse_CharStrings( T2_Decoder* decoder,
FT_Byte* charstring_base, TT_Byte* charstring_base,
FT_Int charstring_len ); TT_Int charstring_len );
LOCAL_DEF LOCAL_DEF
FT_Error T2_Load_Glyph( T2_GlyphSlot glyph, TT_Error T2_Load_Glyph( T2_GlyphSlot glyph,
T2_Size size, T2_Size size,
FT_Int glyph_index, TT_Int glyph_index,
FT_Int load_flags ); TT_Int load_flags );
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -21,7 +21,7 @@
#include <freetype/internal/ftstream.h> #include <freetype/internal/ftstream.h>
#include <freetype/internal/psnames.h> #include <freetype/internal/psnames.h>
#include <freetype/fterrors.h> #include <freetype/internal/t2errors.h>
#include <freetype/tttags.h> #include <freetype/tttags.h>
#include <t2load.h> #include <t2load.h>
#include <t2parse.h> #include <t2parse.h>
@ -39,37 +39,42 @@
/* read a CFF offset from memory */ /* read a CFF offset from memory */
static static
FT_ULong t2_get_offset( FT_Byte* p, TT_ULong t2_get_offset( TT_Byte* p,
FT_Byte off_size ) TT_Byte off_size )
{ {
FT_ULong result; TT_ULong result;
for ( result = 0; off_size > 0; off_size-- ) for ( result = 0; off_size > 0; off_size-- )
result = (result <<= 8) | *p++; result = ( result <<= 8 ) | *p++;
return result; return result;
} }
static static
FT_Error t2_new_cff_index( CFF_Index* index, TT_Error t2_new_cff_index( CFF_Index* index,
FT_Stream stream, FT_Stream stream,
FT_Bool load ) TT_Bool load )
{ {
FT_Error error; TT_Error error;
FT_Memory memory = stream->memory; 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; index->stream = stream;
if ( !READ_UShort( count ) && if ( !READ_UShort( count ) &&
count > 0 ) count > 0 )
{ {
FT_Byte* p; TT_Byte* p;
FT_Byte offsize; TT_Byte offsize;
FT_ULong data_size; TT_ULong data_size;
FT_ULong* poff; 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 */ /* then access the offset table to compute the index's total size */
if ( READ_Byte( offsize ) ) if ( READ_Byte( offsize ) )
goto Exit; goto Exit;
@ -77,15 +82,16 @@
index->stream = stream; index->stream = stream;
index->count = count; index->count = count;
index->off_size = offsize; 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 ) || if ( ALLOC_ARRAY( index->offsets, count + 1, FT_ULong ) ||
ACCESS_Frame( data_size )) ACCESS_Frame( data_size ) )
goto Exit; goto Exit;
poff = index->offsets; poff = index->offsets;
p = (FT_Byte*)stream->cursor; p = (TT_Byte*)stream->cursor;
for ( ; (FT_Short)count >= 0; count-- )
for ( ; (TT_Short)count >= 0; count-- )
{ {
poff[0] = t2_get_offset( p, offsize ); poff[0] = t2_get_offset( p, offsize );
poff++; poff++;
@ -95,9 +101,9 @@
FORGET_Frame(); FORGET_Frame();
index->data_offset = FILE_Pos(); index->data_offset = FILE_Pos();
data_size = poff[-1]-1; data_size = poff[-1] - 1;
if (load) if ( load )
{ {
/* load the data */ /* load the data */
if ( EXTRACT_Frame( data_size, index->bytes ) ) if ( EXTRACT_Frame( data_size, index->bytes ) )
@ -109,8 +115,9 @@
(void)FILE_Skip( data_size ); (void)FILE_Skip( data_size );
} }
} }
Exit: Exit:
if (error) if ( error )
FREE( index->offsets ); FREE( index->offsets );
return error; return error;
@ -124,88 +131,96 @@
{ {
FT_Stream stream = index->stream; FT_Stream stream = index->stream;
FT_Memory memory = stream->memory; FT_Memory memory = stream->memory;
if (index->bytes)
if ( index->bytes )
RELEASE_Frame( index->bytes ); RELEASE_Frame( index->bytes );
FREE( index->offsets ); FREE( index->offsets );
MEM_Set( index, 0, sizeof(*index) ); MEM_Set( index, 0, sizeof ( *index ) );
} }
} }
static static
FT_Error t2_explicit_cff_index( CFF_Index* index, TT_Error t2_explicit_cff_index( CFF_Index* index,
FT_Byte** *table ) TT_Byte*** table )
{ {
FT_Error error = 0; TT_Error error = 0;
FT_Memory memory = index->stream->memory; FT_Memory memory = index->stream->memory;
FT_UInt n, offset, old_offset; TT_UInt n, offset, old_offset;
FT_Byte** t; 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; old_offset = 1;
for ( n = 0; n <= index->count; n++ ) for ( n = 0; n <= index->count; n++ )
{ {
offset = index->offsets[n]; offset = index->offsets[n];
if (!offset) if ( !offset )
offset = old_offset; offset = old_offset;
t[n] = index->bytes + offset - 1; t[n] = index->bytes + offset - 1;
old_offset = offset; old_offset = offset;
} }
*table = t; *table = t;
} }
return error;
return error;
} }
LOCAL_FUNC LOCAL_FUNC
FT_Error T2_Access_Element( CFF_Index* index, TT_Error T2_Access_Element( CFF_Index* index,
FT_UInt element, TT_UInt element,
FT_Byte* *pbytes, TT_Byte** pbytes,
FT_ULong *pbyte_len ) TT_ULong* pbyte_len )
{ {
FT_Error error = 0; TT_Error error = 0;
if ( index && index->count > element ) if ( index && index->count > element )
{ {
/* compute start and end offsets */ /* compute start and end offsets */
FT_ULong off1, off2; TT_ULong off1, off2;
off1 = index->offsets[element]; off1 = index->offsets[element];
if (off1) if ( off1 )
{ {
do do
{ {
element++; element++;
off2 = index->offsets[element]; off2 = index->offsets[element];
} }
while (off2 == 0 && element < index->count); while ( off2 == 0 && element < index->count );
if (!off2)
if ( !off2 )
off1 = 0; off1 = 0;
} }
/* access element */ /* access element */
if (off1) if ( off1 )
{ {
*pbyte_len = off2 - off1; *pbyte_len = off2 - off1;
if (index->bytes) if ( index->bytes )
{ {
/* this index was completely loaded in memory, that's easy */ /* this index was completely loaded in memory, that's easy */
*pbytes = index->bytes + off1 - 1; *pbytes = index->bytes + off1 - 1;
} }
else else
{ {
/* this index is still on disk/file, access it through a frame */ /* this index is still on disk/file, access it through a frame */
FT_Stream stream = index->stream; FT_Stream stream = index->stream;
if ( FILE_Seek( index->data_offset + off1 - 1 ) || if ( FILE_Seek( index->data_offset + off1 - 1 ) ||
EXTRACT_Frame( off2-off1, *pbytes ) ) EXTRACT_Frame( off2 - off1, *pbytes ) )
goto Exit; goto Exit;
} }
} }
@ -217,8 +232,8 @@
} }
} }
else else
error = FT_Err_Invalid_Argument; error = T2_Err_Invalid_Argument;
Exit: Exit:
return error; return error;
} }
@ -226,30 +241,34 @@
LOCAL_FUNC LOCAL_FUNC
void T2_Forget_Element( CFF_Index* index, 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; FT_Stream stream = index->stream;
RELEASE_Frame( *pbytes ); RELEASE_Frame( *pbytes );
} }
} }
LOCAL_FUNC LOCAL_FUNC
FT_String* T2_Get_Name( CFF_Index* index, TT_String* T2_Get_Name( CFF_Index* index,
FT_UInt element ) TT_UInt element )
{ {
FT_Memory memory = index->stream->memory; FT_Memory memory = index->stream->memory;
FT_Byte* bytes; TT_Byte* bytes;
FT_ULong byte_len; TT_ULong byte_len;
FT_Error error; TT_Error error;
FT_String* name = 0; TT_String* name = 0;
error = T2_Access_Element( index, element, &bytes, &byte_len ); error = T2_Access_Element( index, element, &bytes, &byte_len );
if (error) goto Exit; if ( error )
goto Exit;
if ( !ALLOC( name, byte_len+1 ) )
if ( !ALLOC( name, byte_len + 1 ) )
{ {
MEM_Copy( name, bytes, byte_len ); MEM_Copy( name, bytes, byte_len );
name[byte_len] = 0; name[byte_len] = 0;
@ -258,60 +277,69 @@
Exit: Exit:
return name; return name;
} }
#if 0 /* unused until we fully support pure-CFF fonts */ #if 0 /* unused until we fully support pure-CFF fonts */
LOCAL_FUNC LOCAL_FUNC
FT_String* T2_Get_String( CFF_Index* index, TT_String* T2_Get_String( CFF_Index* index,
FT_UInt sid, TT_UInt sid,
PSNames_Interface* interface ) PSNames_Interface* interface )
{ {
/* if it's not a standard string, return it */ /* if it is not a standard string, return it */
if ( sid > 390 ) if ( sid > 390 )
return T2_Get_Name( index, 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 ); const char* adobe_name = interface->adobe_std_strings( sid );
FT_UInt len; TT_UInt len;
if (adobe_name)
if ( adobe_name )
{ {
FT_Memory memory = index->stream->memory; FT_Memory memory = index->stream->memory;
FT_Error error; TT_Error error;
len = (FT_UInt)strlen(adobe_name);
if ( !ALLOC( name, len+1 ) ) len = (TT_UInt)strlen( adobe_name );
if ( !ALLOC( name, len + 1 ) )
{ {
MEM_Copy( name, adobe_name, len ); MEM_Copy( name, adobe_name, len );
name[len] = 0; name[len] = 0;
} }
} }
return name; return name;
} }
} }
#endif
#endif /* 0 */
LOCAL_FUNC LOCAL_FUNC
FT_Error T2_Load_CFF_Font( FT_Stream stream, FT_Error T2_Load_CFF_Font( FT_Stream stream,
FT_Int face_index, TT_Int face_index,
CFF_Font* font ) CFF_Font* font )
{ {
static const FT_Frame_Field cff_header_fields[] = { static const FT_Frame_Field cff_header_fields[] =
FT_FRAME_START(4), {
FT_FRAME_BYTE( CFF_Font, version_major ), FT_FRAME_START( 4 ),
FT_FRAME_BYTE( CFF_Font, version_minor ), FT_FRAME_BYTE( CFF_Font, version_major ),
FT_FRAME_BYTE( CFF_Font, header_size ), FT_FRAME_BYTE( CFF_Font, version_minor ),
FT_FRAME_BYTE( CFF_Font, absolute_offsize ), FT_FRAME_BYTE( CFF_Font, header_size ),
FT_FRAME_END }; FT_FRAME_BYTE( CFF_Font, absolute_offsize ),
FT_FRAME_END
};
FT_Error error; FT_Error error;
FT_Memory memory = stream->memory; FT_Memory memory = stream->memory;
FT_ULong base_offset; FT_ULong base_offset;
MEM_Set( font, 0, sizeof(*font) );
MEM_Set( font, 0, sizeof ( *font ) );
font->stream = stream; font->stream = stream;
font->memory = memory; font->memory = memory;
base_offset = FILE_Pos(); base_offset = FILE_Pos();
@ -325,7 +353,7 @@
font->header_size < 4 || font->header_size < 4 ||
font->absolute_offsize > 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; error = FT_Err_Unknown_File_Format;
goto Exit; goto Exit;
} }
@ -338,126 +366,138 @@
t2_new_cff_index( &font->top_dict_index, stream, 0 ) || t2_new_cff_index( &font->top_dict_index, stream, 0 ) ||
t2_new_cff_index( &font->string_index, stream, 0 ) || t2_new_cff_index( &font->string_index, stream, 0 ) ||
t2_new_cff_index( &font->global_subrs_index, stream, 1 ); 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; 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 )); FT_ERROR(( "T2_Load_CFF_Font: incorrect face index = %d\n",
error = FT_Err_Invalid_Argument; face_index ));
error = T2_Err_Invalid_Argument;
} }
/* in case of a font format check, simply exit now */ /* in case of a font format check, simply exit now */
if (face_index >= 0) if ( face_index >= 0 )
{ {
T2_Parser parser; T2_Parser parser;
FT_Byte* dict; TT_Byte* dict;
FT_ULong dict_len; TT_ULong dict_len;
CFF_Index* index = &font->top_dict_index; CFF_Index* index = &font->top_dict_index;
CFF_Top_Dict* top = &font->top_dict; 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 ); T2_Parser_Init( &parser, T2CODE_TOPDICT, &font->top_dict );
/* set defaults */ /* set defaults */
memset( top, 0, sizeof(*top) ); memset( top, 0, sizeof ( *top ) );
top->underline_position = -100; top->underline_position = -100;
top->underline_thickness = 50; top->underline_thickness = 50;
top->charstring_type = 2; top->charstring_type = 2;
top->font_matrix.xx = 0x10000; top->font_matrix.xx = 0x10000L;
top->font_matrix.yy = 0x10000; top->font_matrix.yy = 0x10000L;
top->cid_count = 8720; top->cid_count = 8720;
error = T2_Access_Element( index, face_index, &dict, &dict_len ) || error = T2_Access_Element( index, face_index, &dict, &dict_len ) ||
T2_Parser_Run( &parser, dict, dict + dict_len ); T2_Parser_Run( &parser, dict, dict + dict_len );
T2_Forget_Element( &font->top_dict_index, &dict ); T2_Forget_Element( &font->top_dict_index, &dict );
if (error) goto Exit;
if ( error )
goto Exit;
/* parse the private dictionary, if any */ /* parse the private dictionary, if any */
if (font->top_dict.private_offset && font->top_dict.private_size) if (font->top_dict.private_offset && font->top_dict.private_size)
{ {
CFF_Private* priv = &font->private_dict; CFF_Private* priv = &font->private_dict;
/* set defaults */ /* set defaults */
priv->blue_shift = 7; priv->blue_shift = 7;
priv->blue_fuzz = 1; priv->blue_fuzz = 1;
priv->lenIV = -1; priv->lenIV = -1;
priv->expansion_factor = (FT_Fixed)0.06*0x10000; priv->expansion_factor = (TT_Fixed)0.06 * 0x10000L;
priv->blue_scale = (FT_Fixed)0.039625*0x10000; priv->blue_scale = (TT_Fixed)0.039625 * 0x10000L;
T2_Parser_Init( &parser, T2CODE_PRIVATE, priv ); T2_Parser_Init( &parser, T2CODE_PRIVATE, priv );
if ( FILE_Seek( base_offset + font->top_dict.private_offset ) || if ( FILE_Seek( base_offset + font->top_dict.private_offset ) ||
ACCESS_Frame( font->top_dict.private_size ) ) ACCESS_Frame( font->top_dict.private_size ) )
goto Exit; goto Exit;
error = T2_Parser_Run( &parser, error = T2_Parser_Run( &parser,
(FT_Byte*)stream->cursor, (TT_Byte*)stream->cursor,
(FT_Byte*)stream->limit ); (TT_Byte*)stream->limit );
FORGET_Frame(); FORGET_Frame();
if (error) goto Exit; if ( error )
goto Exit;
} }
/* read the charstrings index now */ /* read the charstrings index now */
if ( font->top_dict.charstrings_offset == 0 ) 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; error = FT_Err_Unknown_File_Format;
goto Exit; goto Exit;
} }
if ( FILE_Seek( base_offset + font->top_dict.charstrings_offset ) ) if ( FILE_Seek( base_offset + font->top_dict.charstrings_offset ) )
goto Exit; goto Exit;
error = t2_new_cff_index( &font->charstrings_index, stream, 0 ); error = t2_new_cff_index( &font->charstrings_index, stream, 0 );
if (error) goto Exit; if ( error )
goto Exit;
/* read the local subrs, if any */ /* 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 + error = t2_new_cff_index( &font->local_subrs_index, stream, 1 );
font->private_dict.local_subrs_offset ) ) if ( error )
goto Exit; goto Exit;
error = t2_new_cff_index( &font->local_subrs_index, stream, 1 );
if (error) goto Exit;
} }
/* explicit the global and local subrs */ /* explicit the global and local subrs */
if (font->private_dict.local_subrs_offset) { if ( font->private_dict.local_subrs_offset )
font->num_local_subrs = font->local_subrs_index.count; font->num_local_subrs = font->local_subrs_index.count;
} else { else
font->num_local_subrs = 0; font->num_local_subrs = 0;
}
font->num_global_subrs = font->global_subrs_index.count; 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) { if ( font->private_dict.local_subrs_offset )
error |= t2_explicit_cff_index( &font->local_subrs_index, &font->local_subrs ) ; 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 ); font->font_name = T2_Get_Name( &font->name_index, face_index );
Exit: Exit:
return error; return error;
} }
LOCAL_FUNC LOCAL_FUNC
void T2_Done_CFF_Font( CFF_Font* font ) void T2_Done_CFF_Font( CFF_Font* font )
{ {
FT_Memory memory = font->memory; FT_Memory memory = font->memory;
t2_done_cff_index( &font->global_subrs_index ); t2_done_cff_index( &font->global_subrs_index );
t2_done_cff_index( &font->string_index ); t2_done_cff_index( &font->string_index );
t2_done_cff_index( &font->top_dict_index ); t2_done_cff_index( &font->top_dict_index );
@ -465,20 +505,9 @@
t2_done_cff_index( &font->charstrings_index ); t2_done_cff_index( &font->charstrings_index );
FREE( font->local_subrs ); FREE( font->local_subrs );
FREE( font->global_subrs ); FREE( font->global_subrs );
FREE( font->font_name ); FREE( font->font_name );
} }
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***** *****/
/***** TYPE 2 TABLES DECODING.. *****/
/***** *****/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/* END */ /* END */

View File

@ -4,11 +4,11 @@
/* */ /* */
/* OpenType glyph data/program tables loader (specification). */ /* OpenType glyph data/program tables loader (specification). */
/* */ /* */
/* Copyright 1996-1999 by */ /* Copyright 1996-2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used */ /* This file is part of the FreeType project, and may only be used, */
/* modified and distributed under the terms of the FreeType project */ /* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */ /* this file you indicate that you have read the license and */
/* understand and accept it fully. */ /* understand and accept it fully. */
@ -25,33 +25,35 @@
extern "C" { extern "C" {
#endif #endif
LOCAL_FUNC LOCAL_DEF
FT_String* T2_Get_Name( CFF_Index* index, FT_String* T2_Get_Name( CFF_Index* index,
FT_UInt element ); FT_UInt element );
#if 0 /* will be used later for pure-CFF font support */ #if 0 /* will be used later for pure-CFF font support */
LOCAL_DEF LOCAL_DEF
FT_String* T2_Get_String( CFF_Index* index, TT_String* T2_Get_String( CFF_Index* index,
FT_UInt sid, TT_UInt sid,
PSNames_Interface* interface ); PSNames_Interface* interface );
#endif #endif
LOCAL_DEF LOCAL_DEF
FT_Error T2_Access_Element( CFF_Index* index, TT_Error T2_Access_Element( CFF_Index* index,
FT_UInt element, TT_UInt element,
FT_Byte* *pbytes, TT_Byte** pbytes,
FT_ULong *pbyte_len ); TT_ULong* pbyte_len );
LOCAL_DEF LOCAL_DEF
void T2_Forget_Element( CFF_Index* index, void T2_Forget_Element( CFF_Index* index,
FT_Byte* *pbytes ); TT_Byte** pbytes );
LOCAL_FUNC LOCAL_DEF
FT_Error T2_Load_CFF_Font( FT_Stream stream, TT_Error T2_Load_CFF_Font( FT_Stream stream,
FT_Int face_index, TT_Int face_index,
CFF_Font* font ); CFF_Font* font );
LOCAL_FUNC LOCAL_DEF
void T2_Done_CFF_Font( CFF_Font* font ); void T2_Done_CFF_Font( CFF_Font* font );

View File

@ -53,11 +53,18 @@
/* T2_Init_Face */ /* T2_Init_Face */
/* */ /* */
/* <Description> */ /* <Description> */
/* Initializes a given TrueType face object. */ /* Initializes a given OpenType face object. */
/* */ /* */
/* <Input> */ /* <Input> */
/* resource :: The source font resource. */ /* stream :: The source font stream. */
/* */
/* face_index :: The index of the font face in the resource. */ /* face_index :: The index of the font face in the resource. */
/* */
/* num_params :: Number of additional generic parameters. Ignored. */
/* */
/* params :: Additional generic parameters. Ignored. */
/* */
/* <InOut> */
/* face :: The newly built face object. */ /* face :: The newly built face object. */
/* */ /* */
/* <Return> */ /* <Return> */
@ -70,70 +77,77 @@
FT_Int num_params, FT_Int num_params,
FT_Parameter* params ) FT_Parameter* params )
{ {
TT_Error error; TT_Error error;
FT_Driver sfnt_driver; FT_Driver sfnt_driver;
SFNT_Interface* sfnt; SFNT_Interface* sfnt;
sfnt_driver = FT_Get_Driver( face->root.driver->library, "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); sfnt = (SFNT_Interface*)(sfnt_driver->interface.format_interface);
if (!sfnt) goto Bad_Format; if ( !sfnt )
goto Bad_Format;
/* create input stream from resource */ /* create input stream from resource */
if ( FILE_Seek(0) ) if ( FILE_Seek( 0 ) )
goto Exit; 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 ); 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 != 0x4f54544fL ) /* OpenType/CFF font */
if ( face->format_tag != 0x4f54544f ) /* OpenType/CFF font */
{ {
FT_TRACE2(( "[not a valid OpenType/CFF font]\n" )); FT_TRACE2(( "[not a valid OpenType/CFF font]\n" ));
goto Bad_Format; 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 ) if ( face_index < 0 )
return FT_Err_Ok; return T2_Err_Ok;
/* Load font directory */ /* Load font directory */
error = sfnt->load_face( stream, face, face_index, num_params, params ); 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.. */ /* now, load the CFF part of the file.. */
error = face->goto_table( face, TTAG_CFF, stream, 0 ); error = face->goto_table( face, TTAG_CFF, stream, 0 );
if (error) goto Exit; if ( error )
goto Exit;
{ {
CFF_Font* cff; CFF_Font* cff;
FT_Memory memory = face->root.memory; FT_Memory memory = face->root.memory;
FT_Face root; FT_Face root;
if ( ALLOC( cff, sizeof(*cff) ) )
if ( ALLOC( cff, sizeof ( *cff ) ) )
goto Exit; goto Exit;
face->other = cff; face->other = cff;
error = T2_Load_CFF_Font( stream, face_index, 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 */ /* 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; root = &face->root;
} }
Exit: Exit:
return error; return error;
Bad_Format:
Bad_Format:
error = FT_Err_Unknown_File_Format; error = FT_Err_Unknown_File_Format;
goto Exit; goto Exit;
} }
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Function> */ /* <Function> */
@ -149,23 +163,26 @@
void T2_Done_Face( T2_Face face ) void T2_Done_Face( T2_Face face )
{ {
FT_Memory memory = face->root.memory; FT_Memory memory = face->root.memory;
#if 0 #if 0
FT_Stream stream = face->root.stream; FT_Stream stream = face->root.stream;
#endif #endif
SFNT_Interface* sfnt = face->sfnt; SFNT_Interface* sfnt = face->sfnt;
if (sfnt)
sfnt->done_face(face); if ( sfnt )
sfnt->done_face( face );
{ {
CFF_Font* cff = (CFF_Font*)face->other; CFF_Font* cff = (CFF_Font*)face->other;
if (cff)
if ( cff )
{ {
T2_Done_CFF_Font(cff); T2_Done_CFF_Font( cff );
FREE(face->other); FREE( face->other );
} }
} }
} }
@ -193,7 +210,8 @@
LOCAL_DEF LOCAL_DEF
FT_Error T2_Init_Size( T2_Size size ) FT_Error T2_Init_Size( T2_Size size )
{ {
UNUSED(size); UNUSED( size );
return 0; return 0;
} }
@ -212,7 +230,7 @@
LOCAL_FUNC LOCAL_FUNC
void T2_Done_Size( T2_Size size ) void T2_Done_Size( T2_Size size )
{ {
UNUSED(size); UNUSED( size );
} }
@ -229,14 +247,15 @@
/* size :: A handle to the target size object. */ /* size :: A handle to the target size object. */
/* */ /* */
LOCAL_DEF 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; T2_Face face = (T2_Face)size->face;
FT_Size_Metrics* metrics = &size->metrics; 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 ) 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 */ /* Compute root ascender, descender, test height, and max_advance */
metrics->ascender = ( FT_MulFix( face->root.ascender, metrics->ascender = ( FT_MulFix( face->root.ascender,
@ -250,6 +269,7 @@
metrics->max_advance = ( FT_MulFix( face->root.max_advance_width, metrics->max_advance = ( FT_MulFix( face->root.max_advance_width,
metrics->x_scale ) + 32 ) & -64; metrics->x_scale ) + 32 ) & -64;
return error; return error;
} }
@ -269,10 +289,11 @@
/* TrueType error code. 0 means success. */ /* TrueType error code. 0 means success. */
/* */ /* */
LOCAL_FUNC 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; FT_Library library = slot->root.face->driver->library;
slot->max_points = 0; slot->max_points = 0;
slot->max_contours = 0; slot->max_contours = 0;
slot->root.bitmap.buffer = 0; slot->root.bitmap.buffer = 0;
@ -284,7 +305,7 @@
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Function> */ /* <Function> */
/* TT_Done_GlyphSlot */ /* T2_Done_GlyphSlot */
/* */ /* */
/* <Description> */ /* <Description> */
/* The OpenType glyph slot finalizer. */ /* The OpenType glyph slot finalizer. */
@ -298,7 +319,8 @@
FT_Library library = slot->root.face->driver->library; FT_Library library = slot->root.face->driver->library;
FT_Memory memory = library->memory; 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 ); FREE( slot->root.bitmap.buffer );
FT_Outline_Done( library, &slot->root.outline ); FT_Outline_Done( library, &slot->root.outline );
@ -321,19 +343,22 @@
/* TrueType error code. 0 means success. */ /* TrueType error code. 0 means success. */
/* */ /* */
LOCAL_FUNC 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_Memory memory = driver->root.memory;
FT_Error error; FT_Error error;
error = FT_New_GlyphZone( memory, 0, 0, &driver->zone ); error = FT_New_GlyphZone( memory, 0, 0, &driver->zone );
if (error) return error; if ( error )
return error;
/* init extension registry if needed */ /* init extension registry if needed */
#ifdef T2_CONFIG_OPTION_EXTEND_ENGINE
#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE
return TT_Init_Extensions( driver ); return TT_Init_Extensions( driver );
#else #else
return FT_Err_Ok; return T2_Err_Ok;
#endif #endif
} }
@ -341,19 +366,20 @@
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Function> */ /* <Function> */
/* TT_Done_Driver */ /* T2_Done_Driver */
/* */ /* */
/* <Description> */ /* <Description> */
/* Finalizes a given TrueType driver. */ /* Finalizes a given OpenType driver. */
/* */ /* */
/* <Input> */ /* <Input> */
/* driver :: A handle to the target TrueType driver. */ /* driver :: A handle to the target OpenType driver. */
/* */ /* */
LOCAL_FUNC LOCAL_FUNC
void T2_Done_Driver( T2_Driver driver ) void T2_Done_Driver( T2_Driver driver )
{ {
/* destroy extensions registry if needed */ /* destroy extensions registry if needed */
#ifdef T2_CONFIG_OPTION_EXTEND_ENGINE
#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE
TT_Done_Extensions( driver ); TT_Done_Extensions( driver );
#endif #endif

View File

@ -2,13 +2,13 @@
/* */ /* */
/* t2objs.h */ /* t2objs.h */
/* */ /* */
/* Objects manager (specification). */ /* OpenType objects manager (specification). */
/* */ /* */
/* Copyright 1996-1999 by */ /* Copyright 1996-2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */ /* */
/* This file is part of the FreeType project, and may only be used */ /* This file is part of the FreeType project, and may only be used, */
/* modified and distributed under the terms of the FreeType project */ /* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */ /* this file you indicate that you have read the license and */
/* understand and accept it fully. */ /* understand and accept it fully. */
@ -42,6 +42,7 @@
typedef TT_Face T2_Face; typedef TT_Face T2_Face;
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Type> */ /* <Type> */
@ -61,23 +62,18 @@
/* <Description> */ /* <Description> */
/* A handle to an OpenType glyph slot object. */ /* A handle to an OpenType glyph slot object. */
/* */ /* */
/* <Note> */
/* This is a direct typedef of FT_GlyphSlot, as there is nothing */
/* specific about the OpenType glyph slot. */
/* */
typedef struct T2_GlyphSlotRec_ typedef struct T2_GlyphSlotRec_
{ {
FT_GlyphSlotRec root; FT_GlyphSlotRec root;
FT_Bool hint; TT_Bool hint;
FT_Bool scaled; TT_Bool scaled;
FT_Int max_points; TT_Int max_points;
FT_Int max_contours; TT_Int max_contours;
FT_Fixed x_scale; TT_Fixed x_scale;
FT_Fixed y_scale; TT_Fixed y_scale;
} T2_GlyphSlotRec, *T2_GlyphSlot; } T2_GlyphSlotRec, *T2_GlyphSlot;
@ -89,9 +85,9 @@
/* */ /* */
typedef struct T2_Transform_ typedef struct T2_Transform_
{ {
FT_Fixed xx, xy; /* transformation matrix coefficients */ TT_Fixed xx, xy; /* transformation matrix coefficients */
FT_Fixed yx, yy; TT_Fixed yx, yy;
FT_F26Dot6 ox, oy; /* offsets */ TT_F26Dot6 ox, oy; /* offsets */
} T2_Transform; } T2_Transform;
@ -110,38 +106,55 @@
} T2_DriverRec; } 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, LOCAL_DEF
T2_Face face, void T2_Done_Face( T2_Face face );
TT_Int face_index,
TT_Int num_params,
FT_Parameter* params );
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
LOCAL_DEF void T2_Done_Size ( T2_Size size ); void T2_Done_Size( T2_Size size );
LOCAL_DEF FT_Error T2_Reset_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
LOCAL_DEF void T2_Done_GlyphSlot( T2_GlyphSlot slot ); 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
LOCAL_DEF void T2_Done_Driver( T2_Driver driver ); void T2_Done_Driver( T2_Driver driver );
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -17,7 +17,7 @@
#include <t2parse.h> #include <t2parse.h>
#include <freetype/fterrors.h> #include <freetype/internal/t2errors.h>
/*************************************************************************/ /*************************************************************************/
@ -33,6 +33,7 @@
#define T2_Err_Stack_Underflow FT_Err_Invalid_Argument #define T2_Err_Stack_Underflow FT_Err_Invalid_Argument
#define T2_Err_Syntax_Error FT_Err_Invalid_Argument #define T2_Err_Syntax_Error FT_Err_Invalid_Argument
enum enum
{ {
t2_kind_none = 0, t2_kind_none = 0,
@ -42,83 +43,87 @@
t2_kind_bool, t2_kind_bool,
t2_kind_delta, t2_kind_delta,
t2_kind_callback, t2_kind_callback,
t2_kind_max /* do not remove */ t2_kind_max /* do not remove */
}; };
/* now generate handlers for the most simple fields */ /* 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 kind;
int code; int code;
FT_UInt offset; TT_UInt offset;
FT_Byte size; TT_Byte size;
T2_Field_Reader reader; T2_Field_Reader reader;
FT_UInt array_max; TT_UInt array_max;
FT_UInt count_offset; TT_UInt count_offset;
} T2_Field_Handler; } T2_Field_Handler;
LOCAL_FUNC 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->top = parser->stack;
parser->object_code = code; parser->object_code = code;
parser->object = object; parser->object = object;
} }
/* reads an integer */ /* reads an integer */
static static
FT_Long parse_t2_integer( FT_Byte* start, TT_Long parse_t2_integer( TT_Byte* start,
FT_Byte* limit ) TT_Byte* limit )
{ {
FT_Byte* p = start; TT_Byte* p = start;
FT_Int v = *p++; TT_Int v = *p++;
FT_Long val = 0; TT_Long val = 0;
if (v == 28)
if ( v == 28 )
{ {
if ( p+2 > limit ) goto Bad; if ( p + 2 > limit )
val = (FT_Short)(((FT_Int)p[0] << 8) | p[1]); goto Bad;
val = (TT_Short)( ( (TT_Int)p[0] << 8 ) | p[1] );
p += 2; p += 2;
} }
else if (v == 29) else if ( v == 29 )
{ {
if ( p+4 > limit ) goto Bad; if ( p + 4 > limit )
val = ((FT_Long)p[0] << 24) | goto Bad;
((FT_Long)p[1] << 16) |
((FT_Long)p[2] << 8) | p[3]; val = ( (TT_Long)p[0] << 24 ) |
( (TT_Long)p[1] << 16 ) |
( (TT_Long)p[2] << 8 ) | p[3];
p += 4; p += 4;
} }
else if (v < 247) else if ( v < 247 )
{ {
val = v - 139; val = v - 139;
} }
else if (v < 251) else if ( v < 251 )
{ {
if (p+1 > limit) goto Bad; if ( p + 1 > limit )
val = (v-247)*256 + p[0]+108; goto Bad;
p ++;
val = ( v - 247 ) * 256 + p[0] + 108;
p++;
} }
else else
{ {
if (p+1 > limit) goto Bad; if ( p + 1 > limit )
val = -(v-251)*256 - p[0]-108; goto Bad;
p ++;
val = -( v - 251 ) * 256 - p[0] - 108;
p++;
} }
Exit: Exit:
@ -132,15 +137,16 @@
/* reads a real */ /* reads a real */
static static
FT_Fixed parse_t2_real( FT_Byte* start, TT_Fixed parse_t2_real( TT_Byte* start,
FT_Byte* limit, TT_Byte* limit,
FT_Int power_ten ) TT_Int power_ten )
{ {
FT_Byte* p = start; TT_Byte* p = start;
FT_Long num, divider, result, exp; TT_Long num, divider, result, exp;
FT_Int sign = 0, exp_sign = 0; TT_Int sign = 0, exp_sign = 0;
FT_Byte nib; TT_Byte nib;
FT_Byte phase; TT_Byte phase;
result = 0; result = 0;
num = 0; num = 0;
@ -149,86 +155,98 @@
/* first of all, read the integer part */ /* first of all, read the integer part */
phase = 4; phase = 4;
p--; p--;
for (;;) for (;;)
{ {
/* read one nibble at a time */ /* read one nibble at a time */
if (phase && ++p >= limit) goto Bad; if ( phase && ++p >= limit )
nib = (p[0] >> phase) & 0xF; goto Bad;
phase = 4-phase;
if (nib == 0xE) nib = ( p[0] >> phase ) & 0xF;
phase = 4 - phase;
if ( nib == 0xE )
sign = 1; sign = 1;
else if (nib > 9) else if ( nib > 9 )
break; break;
else else
result = result*10 + nib; result = result * 10 + nib;
} }
/* read decimal part, if any */ /* read decimal part, if any */
if (nib == 0xa) if ( nib == 0xa )
for (;;) for (;;)
{ {
/* read one nibble at a time */ /* read one nibble at a time */
if (!phase && ++p >= limit) goto Bad; if ( !phase && ++p >= limit )
phase = 4-phase; goto Bad;
nib = (p[0] >> phase) & 0xF;
if (nib >= 10) phase = 4 - phase;
nib = ( p[0] >> phase ) & 0xF;
if ( nib >= 10 )
break; break;
if (divider < 10000000L) if (divider < 10000000L)
{ {
num = num*10 + nib; num = num * 10 + nib;
divider *= 10; divider *= 10;
} }
} }
/* read exponent, if any */ /* read exponent, if any */
if (nib == 12) if ( nib == 12 )
{ {
exp_sign = 1; exp_sign = 1;
nib = 11; nib = 11;
} }
if (nib == 11)
if ( nib == 11 )
{ {
exp = 0; exp = 0;
for (;;) for (;;)
{ {
/* read one nibble at a time */ /* read one nibble at a time */
if (!phase && ++p >= limit) goto Bad; if ( !phase && ++p >= limit )
phase = 4-phase; goto Bad;
nib = (p[0] >> phase) & 0xF;
if (nib >= 10) phase = 4 - phase;
nib = ( p[0] >> phase ) & 0xF;
if ( nib >= 10 )
break; break;
exp = exp*10 + nib; exp = exp * 10 + nib;
} }
if (exp_sign)
if ( exp_sign )
exp = -exp; exp = -exp;
power_ten += exp; power_ten += exp;
} }
/* raise to power of ten if needed */ /* raise to power of ten if needed */
while (power_ten > 0) while ( power_ten > 0 )
{ {
result = result*10; result = result * 10;
num = num*10; num = num * 10;
power_ten--; power_ten--;
} }
while (power_ten < 0) while ( power_ten < 0 )
{ {
result = result/10; result = result / 10;
divider = divider*10; divider = divider * 10;
power_ten++; power_ten++;
} }
if (num) if ( num )
result += FT_DivFix( num, divider ); result += FT_DivFix( num, divider );
if (sign) if ( sign )
result = -result; result = -result;
Exit: Exit:
@ -242,32 +260,34 @@
/* reads a number, either integer or real */ /* reads a number, either integer or real */
static 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): return ( **d == 30 ? ( parse_t2_real( d[0], d[1], 0 ) >> 16 )
parse_t2_integer( d[0], d[1] ) ); : parse_t2_integer( d[0], d[1] ) );
} }
/* reads a floating point number, either integer or real */ /* reads a floating point number, either integer or real */
static 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 ) : return ( **d == 30 ? parse_t2_real( d[0], d[1], 0 )
parse_t2_integer( d[0], d[1] ) << 16 ); : parse_t2_integer( d[0], d[1] ) << 16 );
} }
static 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; CFF_Top_Dict* dict = (CFF_Top_Dict*)parser->object;
FT_Matrix* matrix = &dict->font_matrix; TT_Matrix* matrix = &dict->font_matrix;
FT_Byte** data = parser->stack; TT_Byte** data = parser->stack;
FT_Error error; TT_Error error;
error = T2_Err_Stack_Underflow; error = T2_Err_Stack_Underflow;
if (parser->top >= parser->stack + 4)
if ( parser->top >= parser->stack + 4 )
{ {
matrix->xx = t2_parse_fixed( data++ ); matrix->xx = t2_parse_fixed( data++ );
matrix->yx = t2_parse_fixed( data++ ); matrix->yx = t2_parse_fixed( data++ );
@ -275,20 +295,23 @@
matrix->yy = t2_parse_fixed( data ); matrix->yy = t2_parse_fixed( data );
error = 0; error = 0;
} }
return error; return error;
} }
static 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; CFF_Top_Dict* dict = (CFF_Top_Dict*)parser->object;
FT_BBox* bbox = &dict->font_bbox; FT_BBox* bbox = &dict->font_bbox;
FT_Byte** data = parser->stack; TT_Byte** data = parser->stack;
FT_Error error; TT_Error error;
error = T2_Err_Stack_Underflow; error = T2_Err_Stack_Underflow;
if (parser->top >= parser->stack + 4)
if ( parser->top >= parser->stack + 4 )
{ {
bbox->xMin = t2_parse_num( data++ ); bbox->xMin = t2_parse_num( data++ );
bbox->yMin = t2_parse_num( data++ ); bbox->yMin = t2_parse_num( data++ );
@ -296,247 +319,288 @@
bbox->yMax = t2_parse_num( data ); bbox->yMax = t2_parse_num( data );
error = 0; error = 0;
} }
return error; return error;
} }
static 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; CFF_Top_Dict* dict = (CFF_Top_Dict*)parser->object;
FT_Byte** data = parser->stack; TT_Byte** data = parser->stack;
FT_Error error; TT_Error error;
error = T2_Err_Stack_Underflow; 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_size = t2_parse_num( data++ );
dict->private_offset = t2_parse_num( data ); dict->private_offset = t2_parse_num( data );
error = 0; error = 0;
} }
return error; return error;
} }
static 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; CFF_Top_Dict* dict = (CFF_Top_Dict*)parser->object;
FT_Byte** data = parser->stack; TT_Byte** data = parser->stack;
FT_Error error; TT_Error error;
error = T2_Err_Stack_Underflow; 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_registry = (TT_UInt)t2_parse_num( data++ );
dict->cid_ordering = (FT_UInt)t2_parse_num( data++ ); dict->cid_ordering = (TT_UInt)t2_parse_num( data++ );
dict->cid_supplement = (FT_ULong)t2_parse_num( data ); dict->cid_supplement = (TT_ULong)t2_parse_num( data );
error = 0; error = 0;
} }
return error; 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_REF( s, f ) ( ((s*)0)->f )
#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_FIELD_CALLBACK( code, name ) \ #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 #undef T2_FIELD
#define T2_FIELD( code, name, kind ) \ #define T2_FIELD( code, name, kind ) \
{ kind, code | T2CODE, \ { \
(FT_UInt)(char*)&T2_REF( T2TYPE, name ), \ kind, \
sizeof( T2_REF( T2TYPE, name ) ), \ code | T2CODE, \
0 }, (TT_UInt)(char*)&T2_REF( T2TYPE, name ), \
sizeof( T2_REF( T2TYPE, name ) ), \
#undef T2_FIELD_DELTA 0 \
#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 ) },
#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_TOPDICT 0x1000
#define T2CODE_PRIVATE 0x2000 #define T2CODE_PRIVATE 0x2000
static const T2_Field_Handler t2_field_handlers[] = static const T2_Field_Handler t2_field_handlers[] =
{ {
#include <t2tokens.h> #include <t2tokens.h>
{ 0, 0, 0, 0, 0, 0, 0 } { 0, 0, 0, 0, 0, 0, 0 }
}; };
LOCAL_FUNC LOCAL_FUNC
FT_Error T2_Parser_Run( T2_Parser* parser, TT_Error T2_Parser_Run( T2_Parser* parser,
FT_Byte* start, TT_Byte* start,
FT_Byte* limit ) TT_Byte* limit )
{ {
FT_Byte* p = start; TT_Byte* p = start;
FT_Error error = 0; TT_Error error = 0;
parser->top = parser->stack; parser->top = parser->stack;
parser->start = start; parser->start = start;
parser->limit = limit; parser->limit = limit;
parser->cursor = start; parser->cursor = start;
while (p < limit) while ( p < limit )
{ {
FT_Byte v = *p; TT_Byte v = *p;
if ( v >= 27 && v != 31 ) if ( v >= 27 && v != 31 )
{ {
/* its a number, we'll push its position on the stack */ /* it's a number; we will push its position on the stack */
if (parser->top - parser->stack >= T2_MAX_STACK_DEPTH) if ( parser->top - parser->stack >= T2_MAX_STACK_DEPTH )
goto Stack_Overflow; goto Stack_Overflow;
*parser->top ++ = p; *parser->top ++ = p;
/* now, skip it */ /* now, skip it */
if (v == 30) if ( v == 30 )
{ {
/* skip real number */ /* skip real number */
for (;;) for (;;)
{ {
if (p >= limit) goto Syntax_Error; if ( p >= limit )
goto Syntax_Error;
v = p[0] >> 4; v = p[0] >> 4;
if (v == 15) break; if ( v == 15 )
break;
v = p[0] & 0xF; v = p[0] & 0xF;
if (v == 15) break; if ( v == 15 )
break;
p++; p++;
} }
p++; p++;
} }
else if (v == 28) else if ( v == 28 )
p += 2; p += 2;
else if (v == 29) else if ( v == 29 )
p += 4; p += 4;
else if (v > 246) else if ( v > 246 )
p += 1; p += 1;
} }
else else
{ {
/* this is not a number, hence it's an operator. Compute its code */ /* this is not a number, hence it's an operator. Compute its code */
/* and look for it in our current list.. */ /* and look for it in our current list. */
FT_UInt code;
FT_Int num_args = parser->top - parser->stack; TT_UInt code;
TT_Int num_args = parser->top - parser->stack;
const T2_Field_Handler* field; const T2_Field_Handler* field;
/* first of all, a trivial check */ /* first of all, a trivial check */
if ( num_args < 1 ) goto Stack_Underflow; if ( num_args < 1 )
goto Stack_Underflow;
*parser->top = p; *parser->top = p;
code = v; code = v;
if (v == 12) if ( v == 12 )
{ {
/* two byte operator */ /* two byte operator */
p++; p++;
code = 0x100 | p[0]; code = 0x100 | p[0];
} }
code = code | parser->object_code; code = code | parser->object_code;
for ( field = t2_field_handlers; field->kind; field++ ) for ( field = t2_field_handlers; field->kind; field++ )
{ {
if (field->code == code) if ( field->code == code )
{ {
/* we found our field's handler, read it.. */ /* we found our field's handler; read it */
FT_Long val; TT_Long val;
FT_Byte* q = (FT_Byte*)parser->object + field->offset; TT_Byte* q = (TT_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;
FT_Long val;
FT_Byte** data = parser->stack; switch ( field->kind )
{
if (num_args > field->array_max) case t2_kind_bool:
num_args = field->array_max; case t2_kind_string:
case t2_kind_num:
/* store count */ val = t2_parse_num( parser->stack );
*qcount = (FT_Byte)num_args; goto Store_Number;
val = 0; case t2_kind_fixed:
while (num_args > 0) val = t2_parse_fixed( parser->stack );
{
val += t2_parse_num( data++ ); Store_Number:
switch (field->size) switch ( field->size )
{ {
case 1: *(FT_Byte*) q = (FT_Byte)val; break; case 1:
case 2: *(FT_Short*)q = (FT_Short)val; break; *(TT_Byte*)q = (TT_Byte)val;
default: *(FT_Long*)q = val; break;
} case 2:
q += field->size; *(TT_Short*)q = (TT_Short)val;
num_args--; break;
} default:
} *(TT_Long*)q = val;
break; }
break;
default: /* callback */
error = field->reader( parser ); case t2_kind_delta:
if (error) goto Exit; {
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; goto Found;
} }
} }
/* this is an unknown operator, or it is unsupported, we will ignore */ /* this is an unknown operator, or it is unsupported; */
/* it for now... */ /* we will ignore it for now. */
Found: Found:
/* clear stack */ /* clear stack */
parser->top = parser->stack; parser->top = parser->stack;
} }
p++; p++;
} }
Exit: Exit:
return error; return error;
Stack_Overflow: Stack_Overflow:
error = FT_Err_Invalid_Argument; error = T2_Err_Invalid_Argument;
goto Exit; goto Exit;
Stack_Underflow: Stack_Underflow:
error = FT_Err_Invalid_Argument; error = T2_Err_Invalid_Argument;
goto Exit; goto Exit;
Syntax_Error: Syntax_Error:
error = FT_Err_Invalid_Argument; error = T2_Err_Invalid_Argument;
goto Exit; goto Exit;
}
}
/* END */

View File

@ -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 #ifndef T2PARSE_H
#define T2PARSE_H #define T2PARSE_H
@ -6,31 +24,47 @@
#define T2_MAX_STACK_DEPTH 96 #define T2_MAX_STACK_DEPTH 96
#define T2CODE_TOPDICT 0x1000 #define T2CODE_TOPDICT 0x1000
#define T2CODE_PRIVATE 0x2000 #define T2CODE_PRIVATE 0x2000
typedef struct T2_Parser_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct T2_Parser_
{ {
FT_Byte* start; TT_Byte* start;
FT_Byte* limit; TT_Byte* limit;
FT_Byte* cursor; TT_Byte* cursor;
FT_Byte* stack[ T2_MAX_STACK_DEPTH+1 ]; TT_Byte* stack[T2_MAX_STACK_DEPTH + 1];
FT_Byte** top; TT_Byte** top;
FT_UInt object_code; TT_UInt object_code;
void* object; void* object;
} T2_Parser; } T2_Parser;
LOCAL_DEF 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 LOCAL_DEF
FT_Error T2_Parser_Run( T2_Parser* parser, TT_Error T2_Parser_Run( T2_Parser* parser,
FT_Byte* start, TT_Byte* start,
FT_Byte* limit ); TT_Byte* limit );
#ifdef __cplusplus
}
#endif
#endif /* T2PARSE_H */ #endif /* T2PARSE_H */
/* END */

View File

@ -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 T2TYPE
#undef T2CODE #undef T2CODE
@ -28,7 +45,7 @@
T2_FIELD_STRING ( 0x115, postscript ) T2_FIELD_STRING ( 0x115, postscript )
T2_FIELD_STRING ( 0x116, base_font_name ) T2_FIELD_STRING ( 0x116, base_font_name )
#if 0 #if 0
T2_FIELD_DELTA ( 0x117, base_font_blend, 16 ) T2_FIELD_DELTA ( 0x117, base_font_blend, 16 )
T2_FIELD_CALLBACK( 0x118, multiple_master ) T2_FIELD_CALLBACK( 0x118, multiple_master )
T2_FIELD_CALLBACK( 0x119, blend_axit_types ) T2_FIELD_CALLBACK( 0x119, blend_axit_types )
@ -48,8 +65,9 @@
T2_FIELD_NUM ( 0x127, chameleon ) T2_FIELD_NUM ( 0x127, chameleon )
#endif #endif
#undef T2TYPE
#undef T2CODE #undef T2TYPE
#undef T2CODE
#define T2TYPE CFF_Private #define T2TYPE CFF_Private
#define T2CODE T2CODE_PRIVATE #define T2CODE T2CODE_PRIVATE
@ -74,3 +92,5 @@
T2_FIELD_NUM ( 20, default_width ) T2_FIELD_NUM ( 20, default_width )
T2_FIELD_NUM ( 21, nominal_width ) T2_FIELD_NUM ( 21, nominal_width )
/* END */

View File

@ -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 <cidafm.h> #include <cidafm.h>
#include <freetype/internal/ftstream.h> #include <freetype/internal/ftstream.h>
#include <freetype/internal/t1types.h> #include <freetype/internal/t1types.h>
#include <stdlib.h> /* for qsort */ #include <freetype/internal/t1errors.h>
#include <stdlib.h> /* for qsort() */
#include <string.h> /* for strcmp() */
#include <ctype.h> /* for isalnum() */
LOCAL_FUNC 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 ); FREE( afm->kern_pairs );
afm->num_pairs = 0; afm->num_pairs = 0;
} }
#undef IS_KERN_PAIR #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') || \ #define IS_ALPHANUM( c ) ( isalnum( c ) || \
(c >= 'a' && c <= 'z') || \ c == '_' || \
(c >= '0' && c <= '9') || \ c == '.' )
(c == '_' && c == '.') )
/* read a glyph name and return the equivalent glyph index */
/* read a glyph name and return the equivalent glyph index */
static 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; T1_Byte* p = *start;
FT_Int len; T1_Int len;
FT_UInt result = 0; T1_UInt result = 0;
char temp[64]; char temp[64];
/* skip whitespace */ /* skip whitespace */
while ( (*p == ' ' || *p == '\t' || *p == ':' || *p == ';') && p < limit ) while ( ( *p == ' ' || *p == '\t' || *p == ':' || *p == ';' ) &&
p < limit )
p++; p++;
*start = p; *start = p;
/* now, read glyph name */ /* now, read glyph name */
while ( IS_ALPHANUM(*p) && p < limit ) p++; while ( IS_ALPHANUM( *p ) && p < limit )
p++;
len = p - *start; 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 */ /* copy glyph name to intermediate array */
MEM_Copy( temp, *start, len ); MEM_Copy( temp, *start, len );
@ -55,7 +81,8 @@
{ {
char* gname = (char*)type1->glyph_names[n]; 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; result = n;
break; break;
@ -67,16 +94,18 @@
} }
/* read an integer */ /* read an integer */
static 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 sum = 0;
int sign = 1; int sign = 1;
/* skip everything that is not a number */ /* skip everything that is not a number */
while ( p < limit && (*p < '0' || *p > '9') ) while ( p < limit && !isdigit( *p ) )
{ {
sign = 1; sign = 1;
if (*p == '-') if (*p == '-')
@ -85,70 +114,75 @@
p++; p++;
} }
while ( p < limit && (*p >= '0' && *p < '9') ) while ( p < limit && isdigit( *p ) )
{ {
sum = sum*10 + (*p - '0'); sum = sum * 10 + ( *p - '0' );
p++; p++;
} }
*start = p; *start = p;
return sum*sign;
return sum * sign;
} }
#undef KERN_INDEX #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 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* pair1 = (T1_Kern_Pair*)a;
T1_Kern_Pair* pair2 = (T1_Kern_Pair*)b; T1_Kern_Pair* pair2 = (T1_Kern_Pair*)b;
FT_ULong index1 = KERN_INDEX(pair1->glyph1,pair1->glyph2); T1_ULong index1 = KERN_INDEX( pair1->glyph1, pair1->glyph2 );
FT_ULong index2 = KERN_INDEX(pair2->glyph1,pair2->glyph2); T1_ULong index2 = KERN_INDEX( pair2->glyph1, pair2->glyph2 );
return ( index1 - index2 ); 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 LOCAL_FUNC
FT_Error CID_Read_AFM( FT_Face t1_face, T1_Error CID_Read_AFM( FT_Face t1_face,
FT_Stream stream ) FT_Stream stream )
{ {
FT_Error error; T1_Error error;
FT_Memory memory = stream->memory; FT_Memory memory = stream->memory;
FT_Byte* start; T1_Byte* start;
FT_Byte* limit; T1_Byte* limit;
FT_Byte* p; T1_Byte* p;
FT_Int count = 0; T1_Int count = 0;
T1_Kern_Pair* pair; T1_Kern_Pair* pair;
T1_Font* type1 = &((T1_Face)t1_face)->type1; T1_Font* type1 = &((T1_Face)t1_face)->type1;
T1_AFM* afm = 0; T1_AFM* afm = 0;
if ( ACCESS_Frame(stream->size) )
if ( ACCESS_Frame( stream->size ) )
return error; return error;
start = (FT_Byte*)stream->cursor; start = (T1_Byte*)stream->cursor;
limit = (FT_Byte*)stream->limit; limit = (T1_Byte*)stream->limit;
p = start; p = start;
/* we are now going to count the occurences of "KP" or "KPX" in */ /* we are now going to count the occurences of "KP" or "KPX" in */
/* the AFM file.. */ /* the AFM file. */
count = 0; 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++; count++;
} }
/* Actually, kerning pairs are simply optional !! */ /* Actually, kerning pairs are simply optional! */
if (count == 0) if ( count == 0 )
goto Exit; goto Exit;
/* allocate the pairs */ /* allocate the pairs */
if ( ALLOC( afm, sizeof(*afm ) ) || if ( ALLOC( afm, sizeof ( *afm ) ) ||
ALLOC_ARRAY( afm->kern_pairs, count, T1_Kern_Pair ) ) ALLOC_ARRAY( afm->kern_pairs, count, T1_Kern_Pair ) )
goto Exit; goto Exit;
@ -159,15 +193,17 @@
/* save in face object */ /* save in face object */
((T1_Face)t1_face)->afm_data = afm; ((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) */ /* skip keyword (KP or KPX) */
q = p+2; q = p + 2;
if (*q == 'X') q++; if ( *q == 'X' )
q++;
pair->glyph1 = afm_atoindex( &q, limit, type1 ); pair->glyph1 = afm_atoindex( &q, limit, type1 );
pair->glyph2 = 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 */ /* 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: Exit:
if (error) if ( error )
FREE( afm ); FREE( afm );
FORGET_Frame(); FORGET_Frame();
return error; return error;
} }
/* find the kerning for a given glyph pair */ /* find the kerning for a given glyph pair */
LOCAL_FUNC LOCAL_FUNC
void CID_Get_Kerning( T1_AFM* afm, void CID_Get_Kerning( T1_AFM* afm,
FT_UInt glyph1, T1_UInt glyph1,
FT_UInt glyph2, T1_UInt glyph2,
FT_Vector* kerning ) T1_Vector* kerning )
{ {
T1_Kern_Pair *min, *mid, *max; T1_Kern_Pair *min, *mid, *max;
FT_ULong index = KERN_INDEX(glyph1,glyph2); T1_ULong index = KERN_INDEX( glyph1, glyph2 );
/* simple binary search */ /* simple binary search */
min = afm->kern_pairs; 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 ) if ( midi == index )
{ {
*kerning = mid->kerning; *kerning = mid->kerning;
return; return;
} }
if ( midi < index ) min = mid+1; if ( midi < index )
else max = mid-1; min = mid + 1;
else
max = mid - 1;
} }
kerning->x = 0; kerning->x = 0;
kerning->y = 0; kerning->y = 0;
} }
/* END */

View File

@ -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 #ifndef T1AFM_H
#define T1AFM_H #define T1AFM_H
#include <freetype/internal/ftobjs.h> #include <cidobjs.h>
/* In this version, we only read the kerning table from the */ typedef struct T1_Kern_Pair_
/* AFM file. We may add support for ligatures a bit later.. */ {
T1_UInt glyph1;
T1_UInt glyph2;
T1_Vector kerning;
typedef struct T1_Kern_Pair_ } T1_Kern_Pair;
{
FT_UInt glyph1;
FT_UInt glyph2;
FT_Vector kerning;
} 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 #if 0
LOCAL_DEF LOCAL_DEF
FT_Error CID_Read_AFM( FT_Face face, T1_Error CID_Read_AFM( FT_Face face,
FT_Stream stream ); FT_Stream stream );
LOCAL_DEF LOCAL_DEF
void CID_Done_AFM( FT_Memory memory, void CID_Done_AFM( FT_Memory memory,
T1_AFM* afm ); T1_AFM* afm );
LOCAL_DEF LOCAL_DEF
void CID_Get_Kerning( T1_AFM* afm, void CID_Get_Kerning( T1_AFM* afm,
FT_UInt glyph1, T1_UInt glyph1,
FT_UInt glyph2, T1_UInt glyph2,
FT_Vector* kerning ); T1_Vector* kerning );
#endif #endif
#endif /* T1AFM_H */ #endif /* T1AFM_H */
/* END */

View File

@ -16,10 +16,11 @@
/***************************************************************************/ /***************************************************************************/
#include <freetype/internal/ftobjs.h> #include <sfobjs.h>
#include <freetype/internal/sfnt.h> #include <freetype/internal/sfnt.h>
#include <freetype/internal/psnames.h> #include <freetype/internal/psnames.h>
#include <freetype/ttnameid.h> #include <freetype/ttnameid.h>
#include <freetype/internal/tterrors.h>
/*************************************************************************/ /*************************************************************************/
@ -49,13 +50,13 @@
/* Character string. NULL if no name is present. */ /* Character string. NULL if no name is present. */
/* */ /* */
static static
FT_String* Get_Name( TT_Face face, TT_String* Get_Name( TT_Face face,
FT_UShort nameid ) TT_UShort nameid )
{ {
FT_Memory memory = face->root.memory; FT_Memory memory = face->root.memory;
FT_UShort n; TT_UShort n;
TT_NameRec* rec; TT_NameRec* rec;
FT_Bool wide_chars = 1; TT_Bool wide_chars = 1;
rec = face->name_table.names; rec = face->name_table.names;
@ -64,7 +65,7 @@
if ( rec->nameID == nameid ) if ( rec->nameID == nameid )
{ {
/* found the name - now create an ASCII string from it */ /* found the name - now create an ASCII string from it */
FT_Bool found = 0; TT_Bool found = 0;
/* test for Microsoft English language */ /* test for Microsoft English language */
@ -88,8 +89,8 @@
/* found a Unicode name */ /* found a Unicode name */
if ( found ) if ( found )
{ {
FT_String* string; TT_String* string;
FT_UInt len; TT_UInt len;
if ( wide_chars ) if ( wide_chars )
@ -172,13 +173,13 @@
LOCAL_FUNC LOCAL_FUNC
FT_Error SFNT_Init_Face( FT_Stream stream, TT_Error SFNT_Init_Face( FT_Stream stream,
TT_Face face, TT_Face face,
TT_Int face_index, TT_Int face_index,
TT_Int num_params, TT_Int num_params,
FT_Parameter* params ) FT_Parameter* params )
{ {
FT_Error error; TT_Error error;
SFNT_Interface* sfnt; SFNT_Interface* sfnt;
PSNames_Interface* psnames; PSNames_Interface* psnames;
SFNT_Header sfnt_header; SFNT_Header sfnt_header;
@ -249,7 +250,7 @@
#undef LOAD_ #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 LOCAL_FUNC
@ -259,7 +260,7 @@
TT_Int num_params, TT_Int num_params,
FT_Parameter* params ) FT_Parameter* params )
{ {
FT_Error error; TT_Error error;
SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt; SFNT_Interface* sfnt = (SFNT_Interface*)face->sfnt;
@ -268,10 +269,10 @@
LOAD_( max_profile ) || LOAD_( max_profile ) ||
/* load the `hhea' & `hmtx' tables at once */ /* 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 */ /* 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_( charmaps ) ||
LOAD_( names ) || LOAD_( names ) ||
@ -294,7 +295,7 @@
goto Exit; goto Exit;
#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE #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; goto Exit;
#endif #endif
@ -304,7 +305,7 @@
/* now set up root fields */ /* now set up root fields */
{ {
FT_Face root = &face->root; FT_Face root = &face->root;
FT_Int flags; TT_Int flags;
TT_CharMap charmap; TT_CharMap charmap;
TT_Int n; TT_Int n;
FT_Memory memory; FT_Memory memory;
@ -377,8 +378,8 @@
for ( n = 0; n < root->num_charmaps; n++, charmap++ ) for ( n = 0; n < root->num_charmaps; n++, charmap++ )
{ {
FT_Int platform = charmap->cmap.platformID; TT_Int platform = charmap->cmap.platformID;
FT_Int encoding = charmap->cmap.platformEncodingID; TT_Int encoding = charmap->cmap.platformEncodingID;
charmap->root.face = (FT_Face)face; charmap->root.face = (FT_Face)face;
@ -501,7 +502,7 @@
/* freeing the character mapping tables */ /* freeing the character mapping tables */
if (sfnt && sfnt->load_charmaps ) if (sfnt && sfnt->load_charmaps )
{ {
FT_UShort n; TT_UShort n;
for ( n = 0; n < face->num_charmaps; n++ ) for ( n = 0; n < face->num_charmaps; n++ )

View File

@ -24,14 +24,14 @@
LOCAL_DEF LOCAL_DEF
FT_Error SFNT_Init_Face( FT_Stream stream, TT_Error SFNT_Init_Face( FT_Stream stream,
TT_Face face, TT_Face face,
TT_Int face_index, TT_Int face_index,
TT_Int num_params, TT_Int num_params,
FT_Parameter* params ); FT_Parameter* params );
LOCAL_DEF LOCAL_DEF
FT_Error SFNT_Load_Face( FT_Stream stream, TT_Error SFNT_Load_Face( FT_Stream stream,
TT_Face face, TT_Face face,
TT_Int face_index, TT_Int face_index,
TT_Int num_params, TT_Int num_params,

View File

@ -157,9 +157,9 @@
TT_Long face_index, TT_Long face_index,
SFNT_Header* sfnt ) SFNT_Header* sfnt )
{ {
TT_Error error; TT_Error error;
TT_ULong format_tag; TT_ULong format_tag;
FT_Memory memory = stream->memory; FT_Memory memory = stream->memory;
const FT_Frame_Field sfnt_header_fields[] = const FT_Frame_Field sfnt_header_fields[] =
{ {

View File

@ -62,7 +62,7 @@
/* the 258 default Mac PS glyph names */ /* the 258 default Mac PS glyph names */
FT_String* TT_Post_Default_Names[258] = TT_String* TT_Post_Default_Names[258] =
{ {
/* 0 */ /* 0 */
".notdef", ".null", "CR", "space", "exclam", ".notdef", ".null", "CR", "space", "exclam",

View File

@ -63,18 +63,18 @@
/* */ /* */
static static
void blit_sbit( FT_Bitmap* target, void blit_sbit( FT_Bitmap* target,
FT_Byte* source, TT_Byte* source,
FT_Int line_bits, TT_Int line_bits,
FT_Bool byte_padded, TT_Bool byte_padded,
FT_Int x_offset, TT_Int x_offset,
FT_Int y_offset ) TT_Int y_offset )
{ {
FT_Byte* line_buff; TT_Byte* line_buff;
FT_Int line_incr; TT_Int line_incr;
FT_Int height; TT_Int height;
FT_UShort acc; TT_UShort acc;
FT_Byte loaded; TT_Byte loaded;
/* first of all, compute starting write position */ /* first of all, compute starting write position */
@ -102,10 +102,10 @@
for ( height = target->rows; height > 0; height-- ) for ( height = target->rows; height > 0; height-- )
{ {
FT_Byte* cur = line_buff; /* current write cursor */ TT_Byte* cur = line_buff; /* current write cursor */
FT_Int count = line_bits; /* # of bits to extract per line */ TT_Int count = line_bits; /* # of bits to extract per line */
FT_Byte shift = x_offset & 7; /* current write shift */ TT_Byte shift = x_offset & 7; /* current write shift */
FT_Byte space = 8 - shift; TT_Byte space = 8 - shift;
/* first of all, read individual source bytes */ /* first of all, read individual source bytes */
@ -115,18 +115,18 @@
{ {
do do
{ {
FT_Byte val; TT_Byte val;
/* ensure that there are at least 8 bits in the accumulator */ /* ensure that there are at least 8 bits in the accumulator */
if ( loaded < 8 ) if ( loaded < 8 )
{ {
acc |= (FT_UShort)*source++ << ( 8 - loaded ); acc |= (TT_UShort)*source++ << ( 8 - loaded );
loaded += 8; loaded += 8;
} }
/* now write one byte */ /* now write one byte */
val = (FT_Byte)( acc >> 8 ); val = (TT_Byte)( acc >> 8 );
if ( shift ) if ( shift )
{ {
cur[0] |= val >> shift; cur[0] |= val >> shift;
@ -150,18 +150,18 @@
/* now write remaining bits (count < 8) */ /* now write remaining bits (count < 8) */
if ( count > 0 ) if ( count > 0 )
{ {
FT_Byte val; TT_Byte val;
/* ensure that there are at least `count' bits in the accumulator */ /* ensure that there are at least `count' bits in the accumulator */
if ( loaded < count ) if ( loaded < count )
{ {
acc |= (FT_UShort)*source++ << ( 8 - loaded ); acc |= (TT_UShort)*source++ << ( 8 - loaded );
loaded += 8; loaded += 8;
} }
/* now write remaining bits */ /* now write remaining bits */
val = ( (FT_Byte)( acc >> 8 ) ) & ~( 0xFF >> count ); val = ( (TT_Byte)( acc >> 8 ) ) & ~( 0xFF >> count );
cur[0] |= val >> shift; cur[0] |= val >> shift;
if ( count > space ) if ( count > space )
@ -1148,7 +1148,7 @@
/* don't forget to multiply `x_offset' by `map->pix_bits' as */ /* don't forget to multiply `x_offset' by `map->pix_bits' as */
/* the sbit blitter doesn't make a difference between pixmap */ /* the sbit blitter doesn't make a difference between pixmap */
/* depths. */ /* 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 ); x_offset * pix_bits, y_offset );
FORGET_Frame(); FORGET_Frame();
@ -1403,8 +1403,8 @@
if ( strike->flags & 1 ) if ( strike->flags & 1 )
{ {
/* in case of a horizontal strike only */ /* in case of a horizontal strike only */
FT_Int advance; TT_Int advance;
FT_Int top; TT_Int top;
advance = strike->hori.ascender - strike->hori.descender; advance = strike->hori.ascender - strike->hori.descender;

View File

@ -48,7 +48,6 @@
/*************************************************************************/ /*************************************************************************/
#undef PAIR_TAG #undef PAIR_TAG
#define PAIR_TAG( left, right ) ( ( (TT_ULong)left << 16 ) | \ #define PAIR_TAG( left, right ) ( ( (TT_ULong)left << 16 ) | \
(TT_ULong)right ) (TT_ULong)right )
@ -397,6 +396,7 @@
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
static static
FTDriver_Interface tt_get_interface( TT_Driver driver, FTDriver_Interface tt_get_interface( TT_Driver driver,
const char* interface ) const char* interface )

View File

@ -681,7 +681,7 @@
do do
{ {
TT_Fixed xx, xy, yy, yx; TT_Fixed xx, xy, yy, yx;
FT_UInt total_subglyphs; TT_UInt total_subglyphs;
/* grow the `glyph->subglyphs' table if necessary */ /* grow the `glyph->subglyphs' table if necessary */
@ -689,7 +689,7 @@
if ( total_subglyphs >= glyph->max_subglyphs ) 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; FT_Memory memory = loader->face->root.memory;
@ -1113,8 +1113,9 @@
if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) && if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) &&
loader->load_flags & FT_LOAD_LINEAR ) loader->load_flags & FT_LOAD_LINEAR )
{ {
FT_Pos em_size = face->root.units_per_EM; TT_Pos em_size = face->root.units_per_EM;
FT_Pos pixel_size = (FT_Pos)face->root.size->metrics.x_ppem << 16; TT_Pos pixel_size = (TT_Pos)face->root.size->metrics.x_ppem << 16;
lsb2 = FT_MulDiv( lsb2, pixel_size, em_size ); lsb2 = FT_MulDiv( lsb2, pixel_size, em_size );
adv2 = FT_MulDiv( adv2, pixel_size, em_size ); adv2 = FT_MulDiv( adv2, pixel_size, em_size );

View File

@ -854,7 +854,7 @@
static TT_F26Dot6 Norm( TT_F26Dot6 X, static TT_F26Dot6 Norm( TT_F26Dot6 X,
TT_F26Dot6 Y ) TT_F26Dot6 Y )
{ {
FT_Int64 T1, T2; TT_INT64 T1, T2;
MUL_64( X, X, T1 ); MUL_64( X, X, T1 );

View File

@ -133,7 +133,6 @@
} }
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Function> */ /* <Function> */
@ -645,7 +644,7 @@
TT_Error TT_Init_Driver( TT_Driver driver ) TT_Error TT_Init_Driver( TT_Driver driver )
{ {
FT_Memory memory = driver->root.memory; FT_Memory memory = driver->root.memory;
FT_Error error; TT_Error error;
error = FT_New_GlyphZone( memory, 0, 0, &driver->zone ); error = FT_New_GlyphZone( memory, 0, 0, &driver->zone );