1 /***************************************************************************/
5 /* Auxiliary functions and data structures related to PostScript fonts */
8 /* Copyright 1996-2001, 2002 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
32 /*************************************************************************/
33 /*************************************************************************/
35 /***** T1_TABLE *****/
37 /*************************************************************************/
38 /*************************************************************************/
41 typedef struct PS_TableRec_* PS_Table;
42 typedef const struct PS_Table_FuncsRec_* PS_Table_Funcs;
45 /*************************************************************************/
48 /* PS_Table_FuncsRec */
51 /* A set of function pointers to manage PS_Table objects. */
54 /* table_init :: Used to initialize a table. */
56 /* table_done :: Finalizes resp. destroy a given table. */
58 /* table_add :: Adds a new object to a table. */
60 /* table_release :: Releases table data, then finalizes it. */
62 typedef struct PS_Table_FuncsRec_
65 (*init)( PS_Table table,
70 (*done)( PS_Table table );
73 (*add)( PS_Table table,
79 (*release)( PS_Table table );
84 /*************************************************************************/
90 /* A PS_Table is a simple object used to store an array of objects in */
91 /* a single memory block. */
94 /* block :: The address in memory of the growheap's block. This */
95 /* can change between two object adds, due to */
98 /* cursor :: The current top of the grow heap within its block. */
100 /* capacity :: The current size of the heap block. Increments by */
103 /* max_elems :: The maximum number of elements in table. */
105 /* num_elems :: The current number of elements in table. */
107 /* elements :: A table of element addresses within the block. */
109 /* lengths :: A table of element sizes within the block. */
111 /* memory :: The object used for memory operations */
112 /* (alloc/realloc). */
114 /* funcs :: A table of method pointers for this object. */
116 typedef struct PS_TableRec_
118 FT_Byte* block; /* current memory block */
119 FT_Offset cursor; /* current cursor in memory block */
120 FT_Offset capacity; /* current size of memory block */
125 FT_Byte** elements; /* addresses of table elements */
126 FT_Int* lengths; /* lengths of table elements */
129 PS_Table_FuncsRec funcs;
134 /*************************************************************************/
135 /*************************************************************************/
137 /***** T1 FIELDS & TOKENS *****/
139 /*************************************************************************/
140 /*************************************************************************/
142 typedef struct PS_ParserRec_* PS_Parser;
144 typedef struct T1_TokenRec_* T1_Token;
146 typedef struct T1_FieldRec_* T1_Field;
149 /* simple enumeration type used to identify token types */
150 typedef enum T1_TokenType_
152 T1_TOKEN_TYPE_NONE = 0,
154 T1_TOKEN_TYPE_STRING,
163 /* a simple structure used to identify tokens */
164 typedef struct T1_TokenRec_
166 FT_Byte* start; /* first character of token in input stream */
167 FT_Byte* limit; /* first character after the token */
168 T1_TokenType type; /* type of token */
173 /* enumeration type used to identify object fields */
174 typedef enum T1_FieldType_
176 T1_FIELD_TYPE_NONE = 0,
178 T1_FIELD_TYPE_INTEGER,
180 T1_FIELD_TYPE_STRING,
182 T1_FIELD_TYPE_INTEGER_ARRAY,
183 T1_FIELD_TYPE_FIXED_ARRAY,
184 T1_FIELD_TYPE_CALLBACK,
192 typedef enum T1_FieldLocation_
194 T1_FIELD_LOCATION_CID_INFO,
195 T1_FIELD_LOCATION_FONT_DICT,
196 T1_FIELD_LOCATION_FONT_INFO,
197 T1_FIELD_LOCATION_PRIVATE,
198 T1_FIELD_LOCATION_BBOX,
201 T1_FIELD_LOCATION_MAX
207 (*T1_Field_ParseFunc)( FT_Face face,
211 /* structure type used to model object fields */
212 typedef struct T1_FieldRec_
214 const char* ident; /* field identifier */
215 T1_FieldLocation location;
216 T1_FieldType type; /* type of field */
217 T1_Field_ParseFunc reader;
218 FT_UInt offset; /* offset of field in object */
219 FT_Byte size; /* size of field in bytes */
220 FT_UInt array_max; /* maximal number of elements for */
222 FT_UInt count_offset; /* offset of element count for */
227 #define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname ) \
229 _ident, T1CODE, _type, \
231 FT_FIELD_OFFSET( _fname ), \
232 FT_FIELD_SIZE( _fname ), \
236 #define T1_NEW_CALLBACK_FIELD( _ident, _reader ) \
238 _ident, T1CODE, T1_FIELD_TYPE_CALLBACK, \
239 (T1_Field_ParseFunc)_reader, \
244 #define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max ) \
246 _ident, T1CODE, _type, \
248 FT_FIELD_OFFSET( _fname ), \
249 FT_FIELD_SIZE_DELTA( _fname ), \
251 FT_FIELD_OFFSET( num_ ## _fname ) \
254 #define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max ) \
256 _ident, T1CODE, _type, \
258 FT_FIELD_OFFSET( _fname ), \
259 FT_FIELD_SIZE_DELTA( _fname ), \
264 #define T1_FIELD_TYPE_BOOL( _ident, _fname ) \
265 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BOOL, _fname )
267 #define T1_FIELD_NUM( _ident, _fname ) \
268 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER, _fname )
270 #define T1_FIELD_FIXED( _ident, _fname ) \
271 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED, _fname )
273 #define T1_FIELD_STRING( _ident, _fname ) \
274 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_STRING, _fname )
276 #define T1_FIELD_BBOX( _ident, _fname ) \
277 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BBOX, _fname )
280 #define T1_FIELD_NUM_TABLE( _ident, _fname, _fmax ) \
281 T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
284 #define T1_FIELD_FIXED_TABLE( _ident, _fname, _fmax ) \
285 T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
288 #define T1_FIELD_NUM_TABLE2( _ident, _fname, _fmax ) \
289 T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
292 #define T1_FIELD_FIXED_TABLE2( _ident, _fname, _fmax ) \
293 T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
296 #define T1_FIELD_CALLBACK( _ident, _name ) \
297 T1_NEW_CALLBACK_FIELD( _ident, _name )
300 /*************************************************************************/
301 /*************************************************************************/
303 /***** T1 PARSER *****/
305 /*************************************************************************/
306 /*************************************************************************/
308 typedef const struct PS_Parser_FuncsRec_* PS_Parser_Funcs;
310 typedef struct PS_Parser_FuncsRec_
313 (*init)( PS_Parser parser,
319 (*done)( PS_Parser parser );
322 (*skip_spaces)( PS_Parser parser );
324 (*skip_alpha)( PS_Parser parser );
327 (*to_int)( PS_Parser parser );
329 (*to_fixed)( PS_Parser parser,
332 (*to_coord_array)( PS_Parser parser,
336 (*to_fixed_array)( PS_Parser parser,
342 (*to_token)( PS_Parser parser,
345 (*to_token_array)( PS_Parser parser,
348 FT_Int* pnum_tokens );
351 (*load_field)( PS_Parser parser,
352 const T1_Field field,
358 (*load_field_table)( PS_Parser parser,
359 const T1_Field field,
364 } PS_Parser_FuncsRec;
367 /*************************************************************************/
373 /* A PS_Parser is an object used to parse a Type 1 font very quickly. */
376 /* cursor :: The current position in the text. */
378 /* base :: Start of the processed text. */
380 /* limit :: End of the processed text. */
382 /* error :: The last error returned. */
384 /* memory :: The object used for memory operations (alloc/realloc). */
386 /* funcs :: A table of functions for the parser. */
388 typedef struct PS_ParserRec_
396 PS_Parser_FuncsRec funcs;
401 /*************************************************************************/
402 /*************************************************************************/
404 /***** T1 BUILDER *****/
406 /*************************************************************************/
407 /*************************************************************************/
410 typedef struct T1_BuilderRec_* T1_Builder;
414 (*T1_Builder_Check_Points_Func)( T1_Builder builder,
418 (*T1_Builder_Add_Point_Func)( T1_Builder builder,
424 (*T1_Builder_Add_Point1_Func)( T1_Builder builder,
429 (*T1_Builder_Add_Contour_Func)( T1_Builder builder );
432 (*T1_Builder_Start_Point_Func)( T1_Builder builder,
437 (*T1_Builder_Close_Contour_Func)( T1_Builder builder );
440 typedef const struct T1_Builder_FuncsRec_* T1_Builder_Funcs;
442 typedef struct T1_Builder_FuncsRec_
445 (*init)( T1_Builder builder,
452 (*done)( T1_Builder builder );
454 T1_Builder_Check_Points_Func check_points;
455 T1_Builder_Add_Point_Func add_point;
456 T1_Builder_Add_Point1_Func add_point1;
457 T1_Builder_Add_Contour_Func add_contour;
458 T1_Builder_Start_Point_Func start_point;
459 T1_Builder_Close_Contour_Func close_contour;
461 } T1_Builder_FuncsRec;
464 /*************************************************************************/
470 /* A structure used during glyph loading to store its outline. */
473 /* memory :: The current memory object. */
475 /* face :: The current face object. */
477 /* glyph :: The current glyph slot. */
481 /* base :: The base glyph outline. */
483 /* current :: The current glyph outline. */
485 /* max_points :: maximum points in builder outline */
487 /* max_contours :: Maximal number of contours in builder outline. */
489 /* last :: The last point position. */
491 /* scale_x :: The horizontal scale (FUnits to sub-pixels). */
493 /* scale_y :: The vertical scale (FUnits to sub-pixels). */
495 /* pos_x :: The horizontal translation (if composite glyph). */
497 /* pos_y :: The vertical translation (if composite glyph). */
499 /* left_bearing :: The left side bearing point. */
501 /* advance :: The horizontal advance vector. */
503 /* bbox :: Unused. */
505 /* path_begun :: A flag which indicates that a new path has begun. */
507 /* load_points :: If this flag is not set, no points are loaded. */
509 /* no_recurse :: Set but not used. */
511 /* error :: An error code that is only used to report memory */
512 /* allocation problems. */
514 /* metrics_only :: A boolean indicating that we only want to compute */
515 /* the metrics of a given glyph, not load all of its */
518 /* funcs :: An array of function pointers for the builder. */
520 typedef struct T1_BuilderRec_
525 FT_GlyphLoader loader;
537 FT_Vector left_bearing;
540 FT_BBox bbox; /* bounding box */
546 FT_Error error; /* only used for memory errors */
547 FT_Bool metrics_only;
549 void* hints_funcs; /* hinter-specific */
550 void* hints_globals; /* hinter-specific */
552 T1_Builder_FuncsRec funcs;
557 /*************************************************************************/
558 /*************************************************************************/
560 /***** T1 DECODER *****/
562 /*************************************************************************/
563 /*************************************************************************/
567 /*************************************************************************/
569 /* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */
570 /* calls during glyph loading. */
572 #define T1_MAX_SUBRS_CALLS 8
575 /*************************************************************************/
577 /* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */
578 /* minimum of 16 is required. */
580 #define T1_MAX_CHARSTRINGS_OPERANDS 32
585 typedef struct T1_Decoder_ZoneRec_
591 } T1_Decoder_ZoneRec, *T1_Decoder_Zone;
594 typedef struct T1_DecoderRec_* T1_Decoder;
595 typedef const struct T1_Decoder_FuncsRec_* T1_Decoder_Funcs;
599 (*T1_Decoder_Callback)( T1_Decoder decoder,
600 FT_UInt glyph_index );
603 typedef struct T1_Decoder_FuncsRec_
606 (*init)( T1_Decoder decoder,
610 FT_Byte** glyph_names,
613 FT_Render_Mode hint_mode,
614 T1_Decoder_Callback callback );
617 (*done)( T1_Decoder decoder );
620 (*parse_charstrings)( T1_Decoder decoder,
624 } T1_Decoder_FuncsRec;
627 typedef struct T1_DecoderRec_
629 T1_BuilderRec builder;
631 FT_Long stack[T1_MAX_CHARSTRINGS_OPERANDS];
634 T1_Decoder_ZoneRec zones[T1_MAX_SUBRS_CALLS + 1];
635 T1_Decoder_Zone zone;
637 PSNames_Service psnames; /* for seac */
639 FT_Byte** glyph_names;
641 FT_Int lenIV; /* internal for sub routine calls */
644 FT_Int* subrs_len; /* array of subrs length (optional) */
646 FT_Matrix font_matrix;
647 FT_Vector font_offset;
650 FT_Int num_flex_vectors;
651 FT_Vector flex_vectors[7];
653 PS_Blend blend; /* for multiple master support */
655 FT_UInt32 hint_flags;
656 FT_Render_Mode hint_mode;
658 T1_Decoder_Callback parse_callback;
659 T1_Decoder_FuncsRec funcs;
664 /*************************************************************************/
665 /*************************************************************************/
667 /***** TYPE1 CHARMAPS *****/
669 /*************************************************************************/
670 /*************************************************************************/
672 typedef const struct T1_CMap_ClassesRec_* T1_CMap_Classes;
674 typedef struct T1_CMap_ClassesRec_
676 FT_CMap_Class standard;
677 FT_CMap_Class expert;
678 FT_CMap_Class custom;
679 FT_CMap_Class unicode;
681 } T1_CMap_ClassesRec;
684 /*************************************************************************/
685 /*************************************************************************/
687 /***** PSAux Module Interface *****/
689 /*************************************************************************/
690 /*************************************************************************/
692 typedef struct PSAux_ServiceRec_
694 /* don't use `PS_Table_Funcs' and friends to avoid compiler warnings */
695 const PS_Table_FuncsRec* ps_table_funcs;
696 const PS_Parser_FuncsRec* ps_parser_funcs;
697 const T1_Builder_FuncsRec* t1_builder_funcs;
698 const T1_Decoder_FuncsRec* t1_decoder_funcs;
701 (*t1_decrypt)( FT_Byte* buffer,
705 T1_CMap_Classes t1_cmap_classes;
707 } PSAux_ServiceRec, *PSAux_Service;
709 /* backwards-compatible type definition */
710 typedef PSAux_ServiceRec PSAux_Interface;
714 #endif /* __PSAUX_H__ */