1
/***************************************************************************/
5
/* Auxiliary functions and data structures related to PostScript fonts */
8
/* Copyright 1996-2001, 2002, 2003, 2004 by */
9
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
11
/* This file is part of the FreeType project, and may only be used, */
12
/* modified, and distributed under the terms of the FreeType project */
13
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14
/* this file you indicate that you have read the license and */
15
/* understand and accept it fully. */
17
/***************************************************************************/
25
#include FT_INTERNAL_OBJECTS_H
26
#include FT_INTERNAL_TYPE1_TYPES_H
27
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
33
/*************************************************************************/
34
/*************************************************************************/
36
/***** T1_TABLE *****/
38
/*************************************************************************/
39
/*************************************************************************/
42
typedef struct PS_TableRec_* PS_Table;
43
typedef const struct PS_Table_FuncsRec_* PS_Table_Funcs;
46
/*************************************************************************/
49
/* PS_Table_FuncsRec */
52
/* A set of function pointers to manage PS_Table objects. */
55
/* table_init :: Used to initialize a table. */
57
/* table_done :: Finalizes resp. destroy a given table. */
59
/* table_add :: Adds a new object to a table. */
61
/* table_release :: Releases table data, then finalizes it. */
63
typedef struct PS_Table_FuncsRec_
66
(*init)( PS_Table table,
71
(*done)( PS_Table table );
74
(*add)( PS_Table table,
80
(*release)( PS_Table table );
85
/*************************************************************************/
91
/* A PS_Table is a simple object used to store an array of objects in */
92
/* a single memory block. */
95
/* block :: The address in memory of the growheap's block. This */
96
/* can change between two object adds, due to */
99
/* cursor :: The current top of the grow heap within its block. */
101
/* capacity :: The current size of the heap block. Increments by */
104
/* max_elems :: The maximum number of elements in table. */
106
/* num_elems :: The current number of elements in table. */
108
/* elements :: A table of element addresses within the block. */
110
/* lengths :: A table of element sizes within the block. */
112
/* memory :: The object used for memory operations */
113
/* (alloc/realloc). */
115
/* funcs :: A table of method pointers for this object. */
117
typedef struct PS_TableRec_
119
FT_Byte* block; /* current memory block */
120
FT_Offset cursor; /* current cursor in memory block */
121
FT_Offset capacity; /* current size of memory block */
126
FT_Byte** elements; /* addresses of table elements */
127
FT_PtrDist* lengths; /* lengths of table elements */
130
PS_Table_FuncsRec funcs;
135
/*************************************************************************/
136
/*************************************************************************/
138
/***** T1 FIELDS & TOKENS *****/
140
/*************************************************************************/
141
/*************************************************************************/
143
typedef struct PS_ParserRec_* PS_Parser;
145
typedef struct T1_TokenRec_* T1_Token;
147
typedef struct T1_FieldRec_* T1_Field;
150
/* simple enumeration type used to identify token types */
151
typedef enum T1_TokenType_
153
T1_TOKEN_TYPE_NONE = 0,
155
T1_TOKEN_TYPE_STRING,
164
/* a simple structure used to identify tokens */
165
typedef struct T1_TokenRec_
167
FT_Byte* start; /* first character of token in input stream */
168
FT_Byte* limit; /* first character after the token */
169
T1_TokenType type; /* type of token */
174
/* enumeration type used to identify object fields */
175
typedef enum T1_FieldType_
177
T1_FIELD_TYPE_NONE = 0,
179
T1_FIELD_TYPE_INTEGER,
181
T1_FIELD_TYPE_FIXED_1000,
182
T1_FIELD_TYPE_STRING,
185
T1_FIELD_TYPE_INTEGER_ARRAY,
186
T1_FIELD_TYPE_FIXED_ARRAY,
187
T1_FIELD_TYPE_CALLBACK,
195
typedef enum T1_FieldLocation_
197
T1_FIELD_LOCATION_CID_INFO,
198
T1_FIELD_LOCATION_FONT_DICT,
199
T1_FIELD_LOCATION_FONT_INFO,
200
T1_FIELD_LOCATION_PRIVATE,
201
T1_FIELD_LOCATION_BBOX,
204
T1_FIELD_LOCATION_MAX
210
(*T1_Field_ParseFunc)( FT_Face face,
214
/* structure type used to model object fields */
215
typedef struct T1_FieldRec_
217
const char* ident; /* field identifier */
218
T1_FieldLocation location;
219
T1_FieldType type; /* type of field */
220
T1_Field_ParseFunc reader;
221
FT_UInt offset; /* offset of field in object */
222
FT_Byte size; /* size of field in bytes */
223
FT_UInt array_max; /* maximal number of elements for */
225
FT_UInt count_offset; /* offset of element count for */
230
#define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname ) \
232
_ident, T1CODE, _type, \
234
FT_FIELD_OFFSET( _fname ), \
235
FT_FIELD_SIZE( _fname ), \
239
#define T1_NEW_CALLBACK_FIELD( _ident, _reader ) \
241
_ident, T1CODE, T1_FIELD_TYPE_CALLBACK, \
242
(T1_Field_ParseFunc)_reader, \
247
#define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max ) \
249
_ident, T1CODE, _type, \
251
FT_FIELD_OFFSET( _fname ), \
252
FT_FIELD_SIZE_DELTA( _fname ), \
254
FT_FIELD_OFFSET( num_ ## _fname ) \
257
#define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max ) \
259
_ident, T1CODE, _type, \
261
FT_FIELD_OFFSET( _fname ), \
262
FT_FIELD_SIZE_DELTA( _fname ), \
267
#define T1_FIELD_BOOL( _ident, _fname ) \
268
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BOOL, _fname )
270
#define T1_FIELD_NUM( _ident, _fname ) \
271
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER, _fname )
273
#define T1_FIELD_FIXED( _ident, _fname ) \
274
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED, _fname )
276
#define T1_FIELD_FIXED_1000( _ident, _fname ) \
277
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_1000, _fname )
279
#define T1_FIELD_STRING( _ident, _fname ) \
280
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_STRING, _fname )
282
#define T1_FIELD_KEY( _ident, _fname ) \
283
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_KEY, _fname )
285
#define T1_FIELD_BBOX( _ident, _fname ) \
286
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BBOX, _fname )
289
#define T1_FIELD_NUM_TABLE( _ident, _fname, _fmax ) \
290
T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
293
#define T1_FIELD_FIXED_TABLE( _ident, _fname, _fmax ) \
294
T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
297
#define T1_FIELD_NUM_TABLE2( _ident, _fname, _fmax ) \
298
T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
301
#define T1_FIELD_FIXED_TABLE2( _ident, _fname, _fmax ) \
302
T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
305
#define T1_FIELD_CALLBACK( _ident, _name ) \
306
T1_NEW_CALLBACK_FIELD( _ident, _name )
309
/*************************************************************************/
310
/*************************************************************************/
312
/***** T1 PARSER *****/
314
/*************************************************************************/
315
/*************************************************************************/
317
typedef const struct PS_Parser_FuncsRec_* PS_Parser_Funcs;
319
typedef struct PS_Parser_FuncsRec_
322
(*init)( PS_Parser parser,
328
(*done)( PS_Parser parser );
331
(*skip_spaces)( PS_Parser parser );
333
(*skip_PS_token)( PS_Parser parser );
336
(*to_int)( PS_Parser parser );
338
(*to_fixed)( PS_Parser parser,
342
(*to_bytes)( PS_Parser parser,
346
FT_Bool delimiters );
349
(*to_coord_array)( PS_Parser parser,
353
(*to_fixed_array)( PS_Parser parser,
359
(*to_token)( PS_Parser parser,
362
(*to_token_array)( PS_Parser parser,
365
FT_Int* pnum_tokens );
368
(*load_field)( PS_Parser parser,
369
const T1_Field field,
375
(*load_field_table)( PS_Parser parser,
376
const T1_Field field,
381
} PS_Parser_FuncsRec;
384
/*************************************************************************/
390
/* A PS_Parser is an object used to parse a Type 1 font very quickly. */
393
/* cursor :: The current position in the text. */
395
/* base :: Start of the processed text. */
397
/* limit :: End of the processed text. */
399
/* error :: The last error returned. */
401
/* memory :: The object used for memory operations (alloc/realloc). */
403
/* funcs :: A table of functions for the parser. */
405
typedef struct PS_ParserRec_
413
PS_Parser_FuncsRec funcs;
418
/*************************************************************************/
419
/*************************************************************************/
421
/***** T1 BUILDER *****/
423
/*************************************************************************/
424
/*************************************************************************/
427
typedef struct T1_BuilderRec_* T1_Builder;
431
(*T1_Builder_Check_Points_Func)( T1_Builder builder,
435
(*T1_Builder_Add_Point_Func)( T1_Builder builder,
441
(*T1_Builder_Add_Point1_Func)( T1_Builder builder,
446
(*T1_Builder_Add_Contour_Func)( T1_Builder builder );
449
(*T1_Builder_Start_Point_Func)( T1_Builder builder,
454
(*T1_Builder_Close_Contour_Func)( T1_Builder builder );
457
typedef const struct T1_Builder_FuncsRec_* T1_Builder_Funcs;
459
typedef struct T1_Builder_FuncsRec_
462
(*init)( T1_Builder builder,
469
(*done)( T1_Builder builder );
471
T1_Builder_Check_Points_Func check_points;
472
T1_Builder_Add_Point_Func add_point;
473
T1_Builder_Add_Point1_Func add_point1;
474
T1_Builder_Add_Contour_Func add_contour;
475
T1_Builder_Start_Point_Func start_point;
476
T1_Builder_Close_Contour_Func close_contour;
478
} T1_Builder_FuncsRec;
481
/* an enumeration type to handle charstring parsing states */
482
typedef enum T1_ParseState_
486
T1_Parse_Have_Moveto,
492
/*************************************************************************/
498
/* A structure used during glyph loading to store its outline. */
501
/* memory :: The current memory object. */
503
/* face :: The current face object. */
505
/* glyph :: The current glyph slot. */
509
/* base :: The base glyph outline. */
511
/* current :: The current glyph outline. */
513
/* max_points :: maximum points in builder outline */
515
/* max_contours :: Maximal number of contours in builder outline. */
517
/* last :: The last point position. */
519
/* scale_x :: The horizontal scale (FUnits to sub-pixels). */
521
/* scale_y :: The vertical scale (FUnits to sub-pixels). */
523
/* pos_x :: The horizontal translation (if composite glyph). */
525
/* pos_y :: The vertical translation (if composite glyph). */
527
/* left_bearing :: The left side bearing point. */
529
/* advance :: The horizontal advance vector. */
531
/* bbox :: Unused. */
533
/* parse_state :: An enumeration which controls the charstring */
536
/* load_points :: If this flag is not set, no points are loaded. */
538
/* no_recurse :: Set but not used. */
540
/* metrics_only :: A boolean indicating that we only want to compute */
541
/* the metrics of a given glyph, not load all of its */
544
/* funcs :: An array of function pointers for the builder. */
546
typedef struct T1_BuilderRec_
551
FT_GlyphLoader loader;
563
FT_Vector left_bearing;
566
FT_BBox bbox; /* bounding box */
567
T1_ParseState parse_state;
572
FT_Bool metrics_only;
574
void* hints_funcs; /* hinter-specific */
575
void* hints_globals; /* hinter-specific */
577
T1_Builder_FuncsRec funcs;
582
/*************************************************************************/
583
/*************************************************************************/
585
/***** T1 DECODER *****/
587
/*************************************************************************/
588
/*************************************************************************/
592
/*************************************************************************/
594
/* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */
595
/* calls during glyph loading. */
597
#define T1_MAX_SUBRS_CALLS 8
600
/*************************************************************************/
602
/* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */
603
/* minimum of 16 is required. */
605
#define T1_MAX_CHARSTRINGS_OPERANDS 32
610
typedef struct T1_Decoder_ZoneRec_
616
} T1_Decoder_ZoneRec, *T1_Decoder_Zone;
619
typedef struct T1_DecoderRec_* T1_Decoder;
620
typedef const struct T1_Decoder_FuncsRec_* T1_Decoder_Funcs;
624
(*T1_Decoder_Callback)( T1_Decoder decoder,
625
FT_UInt glyph_index );
628
typedef struct T1_Decoder_FuncsRec_
631
(*init)( T1_Decoder decoder,
635
FT_Byte** glyph_names,
638
FT_Render_Mode hint_mode,
639
T1_Decoder_Callback callback );
642
(*done)( T1_Decoder decoder );
645
(*parse_charstrings)( T1_Decoder decoder,
649
} T1_Decoder_FuncsRec;
652
typedef struct T1_DecoderRec_
654
T1_BuilderRec builder;
656
FT_Long stack[T1_MAX_CHARSTRINGS_OPERANDS];
659
T1_Decoder_ZoneRec zones[T1_MAX_SUBRS_CALLS + 1];
660
T1_Decoder_Zone zone;
662
FT_Service_PsCMaps psnames; /* for seac */
664
FT_Byte** glyph_names;
666
FT_Int lenIV; /* internal for sub routine calls */
669
FT_PtrDist* subrs_len; /* array of subrs length (optional) */
671
FT_Matrix font_matrix;
672
FT_Vector font_offset;
675
FT_Int num_flex_vectors;
676
FT_Vector flex_vectors[7];
678
PS_Blend blend; /* for multiple master support */
680
FT_Render_Mode hint_mode;
682
T1_Decoder_Callback parse_callback;
683
T1_Decoder_FuncsRec funcs;
688
/*************************************************************************/
689
/*************************************************************************/
691
/***** TYPE1 CHARMAPS *****/
693
/*************************************************************************/
694
/*************************************************************************/
696
typedef const struct T1_CMap_ClassesRec_* T1_CMap_Classes;
698
typedef struct T1_CMap_ClassesRec_
700
FT_CMap_Class standard;
701
FT_CMap_Class expert;
702
FT_CMap_Class custom;
703
FT_CMap_Class unicode;
705
} T1_CMap_ClassesRec;
708
/*************************************************************************/
709
/*************************************************************************/
711
/***** PSAux Module Interface *****/
713
/*************************************************************************/
714
/*************************************************************************/
716
typedef struct PSAux_ServiceRec_
718
/* don't use `PS_Table_Funcs' and friends to avoid compiler warnings */
719
const PS_Table_FuncsRec* ps_table_funcs;
720
const PS_Parser_FuncsRec* ps_parser_funcs;
721
const T1_Builder_FuncsRec* t1_builder_funcs;
722
const T1_Decoder_FuncsRec* t1_decoder_funcs;
725
(*t1_decrypt)( FT_Byte* buffer,
729
T1_CMap_Classes t1_cmap_classes;
731
} PSAux_ServiceRec, *PSAux_Service;
733
/* backwards-compatible type definition */
734
typedef PSAux_ServiceRec PSAux_Interface;
738
#endif /* __PSAUX_H__ */