1 /***************************************************************************/
5 /* Auxiliary functions and data structures related to PostScript fonts */
8 /* Copyright 1996-2001 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_Table_ PS_Table;
44 /*************************************************************************/
50 /* A set of function pointers to manage PS_Table objects. */
53 /* table_init :: Used to initialize a table. */
55 /* table_done :: Finalizes resp. destroy a given table. */
57 /* table_add :: Adds a new object to a table. */
59 /* table_release :: Releases table data, then finalizes it. */
61 typedef struct PS_Table_Funcs_
64 (*init)( PS_Table* table,
69 (*done)( PS_Table* table );
72 (*add)( PS_Table* table,
78 (*release)( PS_Table* table );
83 /*************************************************************************/
89 /* A PS_Table is a simple object used to store an array of objects in */
90 /* a single memory block. */
93 /* block :: The address in memory of the growheap's block. This */
94 /* can change between two object adds, due to */
97 /* cursor :: The current top of the grow heap within its block. */
99 /* capacity :: The current size of the heap block. Increments by */
102 /* max_elems :: The maximum number of elements in table. */
104 /* num_elems :: The current number of elements in table. */
106 /* elements :: A table of element addresses within the block. */
108 /* lengths :: A table of element sizes within the block. */
110 /* memory :: The object used for memory operations */
111 /* (alloc/realloc). */
113 /* funcs :: A table of method pointers for this object. */
117 FT_Byte* block; /* current memory block */
118 FT_Offset cursor; /* current cursor in memory block */
119 FT_Offset capacity; /* current size of memory block */
124 FT_Byte** elements; /* addresses of table elements */
125 FT_Int* lengths; /* lengths of table elements */
128 PS_Table_Funcs funcs;
133 /*************************************************************************/
134 /*************************************************************************/
136 /***** T1 FIELDS & TOKENS *****/
138 /*************************************************************************/
139 /*************************************************************************/
141 typedef struct T1_Parser_ T1_Parser;
143 /* simple enumeration type used to identify token types */
144 typedef enum T1_Token_Type_
157 /* a simple structure used to identify tokens */
158 typedef struct T1_Token_
160 FT_Byte* start; /* first character of token in input stream */
161 FT_Byte* limit; /* first character after the token */
162 T1_Token_Type type; /* type of token */
167 /* enumeration type used to identify object fields */
168 typedef enum T1_Field_Type_
175 t1_field_integer_array,
176 t1_field_fixed_array,
184 typedef enum T1_Field_Location_
192 t1_field_location_max
198 (*T1_Field_Parser)( FT_Face face,
202 /* structure type used to model object fields */
203 typedef struct T1_Field_
205 const char* ident; /* field identifier */
206 T1_Field_Location location;
207 T1_Field_Type type; /* type of field */
208 T1_Field_Parser reader;
209 FT_UInt offset; /* offset of field in object */
210 FT_Byte size; /* size of field in bytes */
211 FT_UInt array_max; /* maximal number of elements for */
213 FT_UInt count_offset; /* offset of element count for */
218 #define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname ) \
220 _ident, T1CODE, _type, \
222 FT_FIELD_OFFSET( _fname ), \
223 FT_FIELD_SIZE( _fname ), \
227 #define T1_NEW_CALLBACK_FIELD( _ident, _reader ) \
229 _ident, T1CODE, t1_field_callback, \
230 (T1_Field_Parser)_reader, \
235 #define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max ) \
237 _ident, T1CODE, _type, \
239 FT_FIELD_OFFSET( _fname ), \
240 FT_FIELD_SIZE_DELTA( _fname ), \
242 FT_FIELD_OFFSET( num_ ## _fname ) \
245 #define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max ) \
247 _ident, T1CODE, _type, \
249 FT_FIELD_OFFSET( _fname ), \
250 FT_FIELD_SIZE_DELTA( _fname ), \
255 #define T1_FIELD_BOOL( _ident, _fname ) \
256 T1_NEW_SIMPLE_FIELD( _ident, t1_field_bool, _fname )
258 #define T1_FIELD_NUM( _ident, _fname ) \
259 T1_NEW_SIMPLE_FIELD( _ident, t1_field_integer, _fname )
261 #define T1_FIELD_FIXED( _ident, _fname ) \
262 T1_NEW_SIMPLE_FIELD( _ident, t1_field_fixed, _fname )
264 #define T1_FIELD_STRING( _ident, _fname ) \
265 T1_NEW_SIMPLE_FIELD( _ident, t1_field_string, _fname )
267 #define T1_FIELD_NUM_TABLE( _ident, _fname, _fmax ) \
268 T1_NEW_TABLE_FIELD( _ident, t1_field_integer_array, \
271 #define T1_FIELD_FIXED_TABLE( _ident, _fname, _fmax ) \
272 T1_NEW_TABLE_FIELD( _ident, t1_field_fixed_array, \
275 #define T1_FIELD_NUM_TABLE2( _ident, _fname, _fmax ) \
276 T1_NEW_TABLE_FIELD2( _ident, t1_field_integer_array, \
279 #define T1_FIELD_FIXED_TABLE2( _ident, _fname, _fmax ) \
280 T1_NEW_TABLE_FIELD2( _ident, t1_field_fixed_array, \
283 #define T1_FIELD_CALLBACK( _ident, _name ) \
284 T1_NEW_CALLBACK_FIELD( _ident, _name )
289 /*************************************************************************/
290 /*************************************************************************/
292 /***** T1 PARSER *****/
294 /*************************************************************************/
295 /*************************************************************************/
297 typedef struct T1_Parser_Funcs_
300 (*init)( T1_Parser* parser,
306 (*done)( T1_Parser* parser );
309 (*skip_spaces)( T1_Parser* parser );
311 (*skip_alpha)( T1_Parser* parser );
314 (*to_int)( T1_Parser* parser );
316 (*to_fixed)( T1_Parser* parser,
319 (*to_coord_array)( T1_Parser* parser,
323 (*to_fixed_array)( T1_Parser* parser,
329 (*to_token)( T1_Parser* parser,
332 (*to_token_array)( T1_Parser* parser,
335 FT_Int* pnum_tokens );
338 (*load_field)( T1_Parser* parser,
339 const T1_Field* field,
345 (*load_field_table)( T1_Parser* parser,
346 const T1_Field* field,
354 /*************************************************************************/
360 /* A T1_Parser is an object used to parse a Type 1 font very quickly. */
363 /* cursor :: The current position in the text. */
365 /* base :: Start of the processed text. */
367 /* limit :: End of the processed text. */
369 /* error :: The last error returned. */
371 /* memory :: The object used for memory operations (alloc/realloc). */
373 /* funcs :: A table of functions for the parser. */
383 T1_Parser_Funcs funcs;
388 /*************************************************************************/
389 /*************************************************************************/
391 /***** T1 BUILDER *****/
393 /*************************************************************************/
394 /*************************************************************************/
397 typedef struct T1_Builder_ T1_Builder;
401 (*T1_Builder_Check_Points_Func)( T1_Builder* builder,
405 (*T1_Builder_Add_Point_Func)( T1_Builder* builder,
411 (*T1_Builder_Add_Point1_Func)( T1_Builder* builder,
416 (*T1_Builder_Add_Contour_Func)( T1_Builder* builder );
419 (*T1_Builder_Start_Point_Func)( T1_Builder* builder,
424 (*T1_Builder_Close_Contour_Func)( T1_Builder* builder );
427 typedef struct T1_Builder_Funcs_
430 (*init)( T1_Builder* builder,
436 (*done)( T1_Builder* builder );
438 T1_Builder_Check_Points_Func check_points;
439 T1_Builder_Add_Point_Func add_point;
440 T1_Builder_Add_Point1_Func add_point1;
441 T1_Builder_Add_Contour_Func add_contour;
442 T1_Builder_Start_Point_Func start_point;
443 T1_Builder_Close_Contour_Func close_contour;
449 /*************************************************************************/
455 /* A structure used during glyph loading to store its outline. */
458 /* memory :: The current memory object. */
460 /* face :: The current face object. */
462 /* glyph :: The current glyph slot. */
466 /* base :: The base glyph outline. */
468 /* current :: The current glyph outline. */
470 /* max_points :: maximum points in builder outline */
472 /* max_contours :: Maximal number of contours in builder outline. */
474 /* last :: The last point position. */
476 /* scale_x :: The horizontal scale (FUnits to sub-pixels). */
478 /* scale_y :: The vertical scale (FUnits to sub-pixels). */
480 /* pos_x :: The horizontal translation (if composite glyph). */
482 /* pos_y :: The vertical translation (if composite glyph). */
484 /* left_bearing :: The left side bearing point. */
486 /* advance :: The horizontal advance vector. */
488 /* bbox :: Unused. */
490 /* path_begun :: A flag which indicates that a new path has begun. */
492 /* load_points :: If this flag is not set, no points are loaded. */
494 /* no_recurse :: Set but not used. */
496 /* error :: An error code that is only used to report memory */
497 /* allocation problems. */
499 /* metrics_only :: A boolean indicating that we only want to compute */
500 /* the metrics of a given glyph, not load all of its */
503 /* funcs :: An array of function pointers for the builder. */
510 FT_GlyphLoader* loader;
522 FT_Vector left_bearing;
525 FT_BBox bbox; /* bounding box */
531 FT_Error error; /* only used for memory errors */
532 FT_Bool metrics_only;
534 T1_Builder_Funcs funcs;
538 /*************************************************************************/
539 /*************************************************************************/
541 /***** T1 DECODER *****/
543 /*************************************************************************/
544 /*************************************************************************/
548 /*************************************************************************/
550 /* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */
551 /* calls during glyph loading. */
553 #define T1_MAX_SUBRS_CALLS 8
556 /*************************************************************************/
558 /* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */
559 /* minimum of 16 is required. */
561 #define T1_MAX_CHARSTRINGS_OPERANDS 32
566 typedef struct T1_Decoder_Zone_
575 typedef struct T1_Decoder_ T1_Decoder;
576 typedef struct T1_Decoder_Funcs_ T1_Decoder_Funcs;
580 (*T1_Decoder_Callback)( T1_Decoder* decoder,
581 FT_UInt glyph_index );
584 struct T1_Decoder_Funcs_
587 (*init)( T1_Decoder* decoder,
591 FT_Byte** glyph_names,
593 T1_Decoder_Callback callback );
596 (*done)( T1_Decoder* decoder );
599 (*parse_charstrings)( T1_Decoder* decoder,
609 FT_Long stack[T1_MAX_CHARSTRINGS_OPERANDS];
612 T1_Decoder_Zone zones[T1_MAX_SUBRS_CALLS + 1];
613 T1_Decoder_Zone* zone;
615 PSNames_Interface* psnames; /* for seac */
617 FT_Byte** glyph_names;
619 FT_Int lenIV; /* internal for sub routine calls */
622 FT_Int* subrs_len; /* array of subrs length (optional) */
624 FT_Matrix font_matrix;
625 FT_Vector font_offset;
628 FT_Int num_flex_vectors;
629 FT_Vector flex_vectors[7];
631 T1_Blend* blend; /* for multiple master support */
633 T1_Decoder_Callback parse_callback;
634 T1_Decoder_Funcs funcs;
638 /*************************************************************************/
639 /*************************************************************************/
641 /***** PSAux Module Interface *****/
643 /*************************************************************************/
644 /*************************************************************************/
646 typedef struct PSAux_Interface_
648 const PS_Table_Funcs* ps_table_funcs;
649 const T1_Parser_Funcs* t1_parser_funcs;
650 const T1_Builder_Funcs* t1_builder_funcs;
651 const T1_Decoder_Funcs* t1_decoder_funcs;
654 (*t1_decrypt)( FT_Byte* buffer,
663 #endif /* __PSAUX_H__ */