Commit 325c2641 authored by David Turner's avatar David Turner
Browse files

finally, the CID and Type1z driver are finished !!

Werner, please have a look at the code and start
re-formatting it :-)
parent ce73def5
LATEST CHANGES
- changed "cid" to use "psaux" too..
- added the cache sub-system. See <freetype/ftcache.h> as well as the
sources in "src/cache". Note that it compiles but is still untested
for now ..
......
......@@ -349,7 +349,7 @@
/* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */
/* calls during glyph loading. */
/* */
#define T1_MAX_SUBRS_CALLS 8
#define T1_MAX_SUBRS_CALLS 16
/*************************************************************************/
......@@ -357,7 +357,7 @@
/* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */
/* minimum of 16 is required. */
/* */
#define T1_MAX_CHARSTRINGS_OPERANDS 32
#define T1_MAX_CHARSTRINGS_OPERANDS 64
/*************************************************************************/
......
......@@ -134,6 +134,7 @@
/*************************************************************************/
/*************************************************************************/
typedef struct T1_Parser_ T1_Parser;
/* simple enumeration type used to identify token types */
typedef enum T1_Token_Type_
......@@ -169,95 +170,114 @@
t1_field_string,
t1_field_integer_array,
t1_field_fixed_array,
t1_field_callback,
/* do not remove */
t1_field_max
} T1_Field_Type;
typedef enum T1_Field_Location_
{
t1_field_cid_info,
t1_field_font_dict,
t1_field_font_info,
t1_field_private,
/* do not remove */
t1_field_location_max
} T1_Field_Location;
typedef void (*T1_Field_Parser)( FT_Face face,
FT_Pointer parser );
/* structure type used to model object fields */
typedef struct T1_Field_
{
T1_Field_Type type; /* type of field */
FT_UInt offset; /* offset of field in object */
FT_Byte size; /* size of field in bytes */
FT_UInt array_max; /* maximum number of elements for array */
FT_UInt count_offset; /* offset of element count for arrays */
FT_Int flag_bit; /* bit number for field flag */
const char* ident; /* field identifier */
T1_Field_Location location;
T1_Field_Type type; /* type of field */
T1_Field_Parser reader;
FT_UInt offset; /* offset of field in object */
FT_Byte size; /* size of field in bytes */
FT_UInt array_max; /* maximal number of elements for */
/* array */
FT_UInt count_offset; /* offset of element count for */
/* arrays */
} T1_Field;
#define T1_FIELD_BOOL( _fname ) \
{ \
t1_field_bool, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE( _fname ), \
0, 0, 0 \
}
#define T1_FIELD_NUM( _fname ) \
{ \
t1_field_integer, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE( _fname ), \
0, 0, 0 \
}
#define T1_FIELD_FIXED( _fname, _power ) \
{ \
t1_field_fixed, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE( _fname ), \
0, 0, 0 \
}
#define T1_FIELD_STRING( _fname ) \
{ \
t1_field_string, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE( _fname ), \
0, 0, 0 \
}
#define T1_FIELD_NUM_ARRAY( _fname, _fcount, _fmax ) \
#define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname ) \
{ \
t1_field_integer, \
_ident, T1CODE, _type, \
0, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE_DELTA( _fname ), \
_fmax, \
FT_FIELD_OFFSET( _fcount ), \
0 \
}
#define T1_FIELD_FIXED_ARRAY( _fname, _fcount, _fmax ) \
{ \
t1_field_fixed, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE_DELTA( _fname ), \
_fmax, \
FT_FIELD_OFFSET( _fcount ), \
0 \
}
#define T1_FIELD_NUM_ARRAY2( _fname, _fmax ) \
{ \
t1_field_integer, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE_DELTA( _fname ), \
_fmax, \
0, 0 \
}
#define T1_FIELD_FIXED_ARRAY2( _fname, _fmax ) \
{ \
t1_field_fixed, \
FT_FIELD_OFFSTE( _fname ), \
FT_FIELD_SIZE_DELTA( _fname ), \
_fmax, \
0, 0 \
}
FT_FIELD_SIZE( _fname ), \
0, 0 \
},
#define T1_NEW_CALLBACK_FIELD( _ident, _reader ) \
{ \
_ident, T1CODE, t1_field_callback, \
(T1_Field_Parser)_reader, \
0, 0, \
0, 0 \
},
#define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max ) \
{ \
_ident, T1CODE, _type, \
0, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE_DELTA( _fname ), \
_max, \
FT_FIELD_OFFSET( num_ ## _fname ) \
},
#define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max ) \
{ \
_ident, T1CODE, _type, \
0, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE_DELTA( _fname ), \
_max, 0 \
},
#define T1_FIELD_BOOL( _ident, _fname ) \
T1_NEW_SIMPLE_FIELD( _ident, t1_field_bool, _fname )
#define T1_FIELD_NUM( _ident, _fname ) \
T1_NEW_SIMPLE_FIELD( _ident, t1_field_integer, _fname )
#define T1_FIELD_FIXED( _ident, _fname ) \
T1_NEW_SIMPLE_FIELD( _ident, t1_field_fixed, _fname )
#define T1_FIELD_STRING( _ident, _fname ) \
T1_NEW_SIMPLE_FIELD( _ident, t1_field_string, _fname )
#define T1_FIELD_NUM_TABLE( _ident, _fname, _fmax ) \
T1_NEW_TABLE_FIELD( _ident, t1_field_integer_array, \
_fname, _fmax )
#define T1_FIELD_FIXED_TABLE( _ident, _fname, _fmax ) \
T1_NEW_TABLE_FIELD( _ident, t1_field_fixed_array, \
_fname, _fmax )
#define T1_FIELD_NUM_TABLE2( _ident, _fname, _fmax ) \
T1_NEW_TABLE_FIELD2( _ident, t1_field_integer_array, \
_fname, _fmax )
#define T1_FIELD_FIXED_TABLE2( _ident, _fname, _fmax ) \
T1_NEW_TABLE_FIELD2( _ident, t1_field_fixed_array, \
_fname, _fmax )
#define T1_FIELD_CALLBACK( _ident, _name ) \
T1_NEW_CALLBACK_FIELD( _ident, _name )
/*************************************************************************/
......@@ -268,10 +288,6 @@
/*************************************************************************/
/*************************************************************************/
typedef struct T1_Parser_ T1_Parser;
typedef struct T1_Parser_Funcs_
{
void (*init) ( T1_Parser* parser,
......@@ -579,6 +595,7 @@
FT_Int* subrs_len; /* array of subrs length (optional) */
FT_Matrix font_matrix;
FT_Vector font_offset;
FT_Int flex_state;
FT_Int num_flex_vectors;
......
......@@ -181,6 +181,7 @@
{
FT_FaceRec root;
void* psnames;
void* psaux;
CID_Info cid;
void* afm_data;
CID_Subrs* subrs;
......
......@@ -195,6 +195,7 @@
FT_Byte paint_type;
FT_Byte font_type;
FT_Matrix font_matrix;
FT_Vector font_offset;
FT_UInt num_subrs;
FT_ULong subrmap_offset;
......
......@@ -426,7 +426,7 @@
FTC_Image_Cache cache = queue->cache;
FT_UInt hash_index = glyph_index % queue->hash_size;
FT_List bucket = queue->buckets + hash_index;
FT_ListNode node, next;
FT_ListNode node, next = 0;
FT_Error error;
FTC_ImageNode inode;
......
This diff is collapsed.
......@@ -36,133 +36,6 @@
#endif
/*************************************************************************/
/* */
/* <Structure> */
/* CID_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 CID_Builder_
{
FT_Memory memory;
CID_Face face;
CID_GlyphSlot glyph;
FT_GlyphLoader* loader;
FT_Outline* base;
FT_Outline* current;
FT_Vector last;
FT_Fixed scale_x;
FT_Fixed scale_y;
FT_Pos pos_x;
FT_Pos pos_y;
FT_Vector left_bearing;
FT_Vector advance;
FT_BBox bbox; /* bounding box */
FT_Bool path_begun;
FT_Bool load_points;
FT_Bool no_recurse;
FT_Error error; /* only used for memory errors */
FT_Bool metrics_only;
} CID_Builder;
/* execution context charstring zone */
typedef struct CID_Decoder_Zone_
{
FT_Byte* base;
FT_Byte* limit;
FT_Byte* cursor;
} CID_Decoder_Zone;
typedef struct CID_Decoder_
{
CID_Builder builder;
FT_Int stack[T1_MAX_CHARSTRINGS_OPERANDS];
FT_Int* top;
CID_Decoder_Zone zones[T1_MAX_SUBRS_CALLS + 1];
CID_Decoder_Zone* zone;
FT_Matrix font_matrix;
CID_Subrs* subrs;
FT_UInt lenIV;
FT_Int flex_state;
FT_Int num_flex_vectors;
FT_Vector flex_vectors[7];
} CID_Decoder;
LOCAL_DEF
void CID_Init_Builder( CID_Builder* builder,
CID_Face face,
CID_Size size,
CID_GlyphSlot glyph );
LOCAL_DEF
void CID_Done_Builder( CID_Builder* builder );
LOCAL_DEF
void CID_Init_Decoder( CID_Decoder* decoder );
#if 0
......@@ -174,12 +47,6 @@
#endif
/* This function is exported, because it is used by the T1Dump utility */
LOCAL_DEF
FT_Error CID_Parse_CharStrings( CID_Decoder* decoder,
FT_Byte* charstring_base,
FT_Int charstring_len );
LOCAL_DEF
FT_Error CID_Load_Glyph( CID_GlyphSlot glyph,
CID_Size size,
......
......@@ -97,20 +97,22 @@
static
FT_Error cid_load_keyword( CID_Face face,
CID_Loader* loader,
const CID_Field_Rec* keyword )
FT_Error cid_load_keyword( CID_Face face,
CID_Loader* loader,
const T1_Field* keyword )
{
FT_Error error;
CID_Parser* parser = &loader->parser;
FT_Byte* object;
void* dummy_object;
CID_Info* cid = &face->cid;
/* if the keyword has a dedicated callback, call it */
if ( keyword->type == t1_field_callback )
{
error = keyword->reader( face, parser );
keyword->reader( (FT_Face)face, parser );
error = parser->root.error;
goto Exit;
}
......@@ -151,13 +153,15 @@
}
}
dummy_object = object;
/* now, load the keyword data in the object's field(s) */
if ( keyword->type == t1_field_integer_array ||
keyword->type == t1_field_fixed_array )
error = CID_Load_Field_Table( parser, keyword, object );
error = CID_Load_Field_Table( &loader->parser, keyword,
&dummy_object );
else
error = CID_Load_Field( parser, keyword, object );
error = CID_Load_Field( &loader->parser, keyword, &dummy_object );
Exit:
return error;
}
......@@ -187,20 +191,36 @@
CID_Parser* parser )
{
FT_Matrix* matrix;
FT_Vector* offset;
CID_FontDict* dict;
FT_Fixed temp[4];
FT_Fixed temp[6];
if ( parser->num_dict >= 0 )
{
dict = face->cid.font_dicts + parser->num_dict;
matrix = &dict->font_matrix;
offset = &dict->font_offset;
(void)CID_ToFixedArray( parser, 6, temp, 3 );
/* we need to scale the values by 1.0/temp[3] */
if ( temp[3] != 0x10000L )
{
temp[0] = FT_DivFix( temp[0], temp[3] );
temp[1] = FT_DivFix( temp[1], temp[3] );
temp[2] = FT_DivFix( temp[2], temp[3] );
temp[4] = FT_DivFix( temp[4], temp[3] );
temp[5] = FT_DivFix( temp[5], temp[3] );
temp[3] = 0x10000L;
}
(void)CID_ToFixedArray( parser, 4, temp, 3 );
matrix->xx = temp[0];
matrix->yx = temp[1];
matrix->xy = temp[2];
matrix->yy = temp[3];
offset->x = temp[4];
offset->y = temp[5];
}
return T1_Err_Ok; /* this is a callback function; */
......@@ -247,7 +267,7 @@
static
const CID_Field_Rec t1_field_records[] =
const T1_Field cid_field_records[] =
{
#ifdef FT_FLAT_COMPILE
......@@ -260,7 +280,10 @@
#endif
{ 0, t1_field_cid_info, t1_field_none, 0, 0, 0, 0, 0 }
T1_FIELD_CALLBACK( "FontBBox", parse_font_bbox )
T1_FIELD_CALLBACK( "FDArray", parse_fd_array )
T1_FIELD_CALLBACK( "FontMatrix", parse_font_matrix )
{ 0, 0, 0, 0, 0, 0, 0, 0 }
};
......@@ -273,31 +296,19 @@
}
static
void skip_whitespace( CID_Parser* parser )
{
FT_Byte* cur = parser->cursor;
while ( cur < parser->limit && isspace( *cur ) )
cur++;
parser->cursor = cur;
}
static
FT_Error parse_dict( CID_Face face,
CID_Loader* loader,
FT_Byte* base,
FT_Long size )
FT_Error cid_parse_dict( CID_Face face,
CID_Loader* loader,
FT_Byte* base,
FT_Long size )
{
CID_Parser* parser = &loader->parser;
parser->cursor = base;
parser->limit = base + size;
parser->error = 0;
parser->root.cursor = base;
parser->root.limit = base + size;
parser->root.error = 0;
{
FT_Byte* cur = base;
......@@ -334,7 +345,7 @@
if ( len > 0 && len < 22 )
{
/* now compare the immediate name to the keyword table */
const CID_Field_Rec* keyword = t1_field_records;
const T1_Field* keyword = cid_field_records;
for (;;)
......@@ -359,13 +370,13 @@
if ( n >= len )
{
/* we found it - run the parsing callback */
parser->cursor = cur2;
skip_whitespace( parser );
parser->error = cid_load_keyword( face, loader, keyword );
if ( parser->error )
return parser->error;
parser->root.cursor = cur2;
CID_Skip_Spaces( parser );
parser->root.error = cid_load_keyword( face, loader, keyword );
if ( parser->root.error )
return parser->root.error;
cur = parser->cursor;
cur = parser->root.cursor;
break;
}
}
......@@ -375,7 +386,7 @@
}
}
}
return parser->error;
return parser->root.error;
}
......@@ -515,13 +526,14 @@
t1_init_loader( &loader, face );
parser = &loader.parser;
error = CID_New_Parser( parser, face->root.stream, face->root.memory );
error = CID_New_Parser( parser, face->root.stream, face->root.memory,
(PSAux_Interface*)face->psaux );
if ( error )
goto Exit;
error = parse_dict( face, &loader,
parser->postscript,
parser->postscript_len );
error = cid_parse_dict( face, &loader,
parser->postscript,
parser->postscript_len );
if ( error )
goto Exit;
......
......@@ -21,7 +21,6 @@
#include <freetype/internal/ftstream.h>
#ifdef FT_FLAT_COMPILE
#include "cidparse.h"
......
......@@ -34,6 +34,7 @@
#include <freetype/internal/psnames.h>
#include <freetype/internal/psaux.h>
/*************************************************************************/
......@@ -132,6 +133,7 @@