1 /***************************************************************************/
5 /* Auxiliary functions and data structures related to PostScript fonts */
8 /* Copyright 1996-2004, 2006, 2008, 2009, 2012 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 /* init :: Set to 0xDEADBEEF if `elements' and `lengths' have */
105 /* been allocated. */
107 /* max_elems :: The maximum number of elements in table. */
109 /* num_elems :: The current number of elements in table. */
111 /* elements :: A table of element addresses within the block. */
113 /* lengths :: A table of element sizes within the block. */
115 /* memory :: The object used for memory operations */
116 /* (alloc/realloc). */
118 /* funcs :: A table of method pointers for this object. */
120 typedef struct PS_TableRec_
122 FT_Byte
* block
; /* current memory block */
123 FT_Offset cursor
; /* current cursor in memory block */
124 FT_Offset capacity
; /* current size of memory block */
129 FT_Byte
** elements
; /* addresses of table elements */
130 FT_PtrDist
* lengths
; /* lengths of table elements */
133 PS_Table_FuncsRec funcs
;
138 /*************************************************************************/
139 /*************************************************************************/
141 /***** T1 FIELDS & TOKENS *****/
143 /*************************************************************************/
144 /*************************************************************************/
146 typedef struct PS_ParserRec_
* PS_Parser
;
148 typedef struct T1_TokenRec_
* T1_Token
;
150 typedef struct T1_FieldRec_
* T1_Field
;
153 /* simple enumeration type used to identify token types */
154 typedef enum T1_TokenType_
156 T1_TOKEN_TYPE_NONE
= 0,
158 T1_TOKEN_TYPE_STRING
,
160 T1_TOKEN_TYPE_KEY
, /* aka `name' */
168 /* a simple structure used to identify tokens */
169 typedef struct T1_TokenRec_
171 FT_Byte
* start
; /* first character of token in input stream */
172 FT_Byte
* limit
; /* first character after the token */
173 T1_TokenType type
; /* type of token */
178 /* enumeration type used to identify object fields */
179 typedef enum T1_FieldType_
181 T1_FIELD_TYPE_NONE
= 0,
183 T1_FIELD_TYPE_INTEGER
,
185 T1_FIELD_TYPE_FIXED_1000
,
186 T1_FIELD_TYPE_STRING
,
189 T1_FIELD_TYPE_MM_BBOX
,
190 T1_FIELD_TYPE_INTEGER_ARRAY
,
191 T1_FIELD_TYPE_FIXED_ARRAY
,
192 T1_FIELD_TYPE_CALLBACK
,
200 typedef enum T1_FieldLocation_
202 T1_FIELD_LOCATION_CID_INFO
,
203 T1_FIELD_LOCATION_FONT_DICT
,
204 T1_FIELD_LOCATION_FONT_EXTRA
,
205 T1_FIELD_LOCATION_FONT_INFO
,
206 T1_FIELD_LOCATION_PRIVATE
,
207 T1_FIELD_LOCATION_BBOX
,
208 T1_FIELD_LOCATION_LOADER
,
209 T1_FIELD_LOCATION_FACE
,
210 T1_FIELD_LOCATION_BLEND
,
213 T1_FIELD_LOCATION_MAX
219 (*T1_Field_ParseFunc
)( FT_Face face
,
223 /* structure type used to model object fields */
224 typedef struct T1_FieldRec_
226 const char* ident
; /* field identifier */
227 T1_FieldLocation location
;
228 T1_FieldType type
; /* type of field */
229 T1_Field_ParseFunc reader
;
230 FT_UInt offset
; /* offset of field in object */
231 FT_Byte size
; /* size of field in bytes */
232 FT_UInt array_max
; /* maximum number of elements for */
234 FT_UInt count_offset
; /* offset of element count for */
235 /* arrays; must not be zero if in */
236 /* use -- in other words, a */
237 /* `num_FOO' element must not */
238 /* start the used structure if we */
239 /* parse a `FOO' array */
240 FT_UInt dict
; /* where we expect it */
243 #define T1_FIELD_DICT_FONTDICT ( 1 << 0 ) /* also FontInfo and FDArray */
244 #define T1_FIELD_DICT_PRIVATE ( 1 << 1 )
248 #define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname, _dict ) \
250 _ident, T1CODE, _type, \
252 FT_FIELD_OFFSET( _fname ), \
253 FT_FIELD_SIZE( _fname ), \
258 #define T1_NEW_CALLBACK_FIELD( _ident, _reader, _dict ) \
260 _ident, T1CODE, T1_FIELD_TYPE_CALLBACK, \
261 (T1_Field_ParseFunc)_reader, \
267 #define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max, _dict ) \
269 _ident, T1CODE, _type, \
271 FT_FIELD_OFFSET( _fname ), \
272 FT_FIELD_SIZE_DELTA( _fname ), \
274 FT_FIELD_OFFSET( num_ ## _fname ), \
278 #define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max, _dict ) \
280 _ident, T1CODE, _type, \
282 FT_FIELD_OFFSET( _fname ), \
283 FT_FIELD_SIZE_DELTA( _fname ), \
289 #define T1_FIELD_BOOL( _ident, _fname, _dict ) \
290 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BOOL, _fname, _dict )
292 #define T1_FIELD_NUM( _ident, _fname, _dict ) \
293 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER, _fname, _dict )
295 #define T1_FIELD_FIXED( _ident, _fname, _dict ) \
296 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED, _fname, _dict )
298 #define T1_FIELD_FIXED_1000( _ident, _fname, _dict ) \
299 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_1000, _fname, \
302 #define T1_FIELD_STRING( _ident, _fname, _dict ) \
303 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_STRING, _fname, _dict )
305 #define T1_FIELD_KEY( _ident, _fname, _dict ) \
306 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_KEY, _fname, _dict )
308 #define T1_FIELD_BBOX( _ident, _fname, _dict ) \
309 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BBOX, _fname, _dict )
312 #define T1_FIELD_NUM_TABLE( _ident, _fname, _fmax, _dict ) \
313 T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
314 _fname, _fmax, _dict )
316 #define T1_FIELD_FIXED_TABLE( _ident, _fname, _fmax, _dict ) \
317 T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
318 _fname, _fmax, _dict )
320 #define T1_FIELD_NUM_TABLE2( _ident, _fname, _fmax, _dict ) \
321 T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
322 _fname, _fmax, _dict )
324 #define T1_FIELD_FIXED_TABLE2( _ident, _fname, _fmax, _dict ) \
325 T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
326 _fname, _fmax, _dict )
328 #define T1_FIELD_CALLBACK( _ident, _name, _dict ) \
329 T1_NEW_CALLBACK_FIELD( _ident, _name, _dict )
332 /*************************************************************************/
333 /*************************************************************************/
335 /***** T1 PARSER *****/
337 /*************************************************************************/
338 /*************************************************************************/
340 typedef const struct PS_Parser_FuncsRec_
* PS_Parser_Funcs
;
342 typedef struct PS_Parser_FuncsRec_
345 (*init
)( PS_Parser parser
,
351 (*done
)( PS_Parser parser
);
354 (*skip_spaces
)( PS_Parser parser
);
356 (*skip_PS_token
)( PS_Parser parser
);
359 (*to_int
)( PS_Parser parser
);
361 (*to_fixed
)( PS_Parser parser
,
365 (*to_bytes
)( PS_Parser parser
,
369 FT_Bool delimiters
);
372 (*to_coord_array
)( PS_Parser parser
,
376 (*to_fixed_array
)( PS_Parser parser
,
382 (*to_token
)( PS_Parser parser
,
385 (*to_token_array
)( PS_Parser parser
,
388 FT_Int
* pnum_tokens
);
391 (*load_field
)( PS_Parser parser
,
392 const T1_Field field
,
398 (*load_field_table
)( PS_Parser parser
,
399 const T1_Field field
,
404 } PS_Parser_FuncsRec
;
407 /*************************************************************************/
413 /* A PS_Parser is an object used to parse a Type 1 font very quickly. */
416 /* cursor :: The current position in the text. */
418 /* base :: Start of the processed text. */
420 /* limit :: End of the processed text. */
422 /* error :: The last error returned. */
424 /* memory :: The object used for memory operations (alloc/realloc). */
426 /* funcs :: A table of functions for the parser. */
428 typedef struct PS_ParserRec_
436 PS_Parser_FuncsRec funcs
;
441 /*************************************************************************/
442 /*************************************************************************/
444 /***** T1 BUILDER *****/
446 /*************************************************************************/
447 /*************************************************************************/
450 typedef struct T1_BuilderRec_
* T1_Builder
;
454 (*T1_Builder_Check_Points_Func
)( T1_Builder builder
,
458 (*T1_Builder_Add_Point_Func
)( T1_Builder builder
,
464 (*T1_Builder_Add_Point1_Func
)( T1_Builder builder
,
469 (*T1_Builder_Add_Contour_Func
)( T1_Builder builder
);
472 (*T1_Builder_Start_Point_Func
)( T1_Builder builder
,
477 (*T1_Builder_Close_Contour_Func
)( T1_Builder builder
);
480 typedef const struct T1_Builder_FuncsRec_
* T1_Builder_Funcs
;
482 typedef struct T1_Builder_FuncsRec_
485 (*init
)( T1_Builder builder
,
492 (*done
)( T1_Builder builder
);
494 T1_Builder_Check_Points_Func check_points
;
495 T1_Builder_Add_Point_Func add_point
;
496 T1_Builder_Add_Point1_Func add_point1
;
497 T1_Builder_Add_Contour_Func add_contour
;
498 T1_Builder_Start_Point_Func start_point
;
499 T1_Builder_Close_Contour_Func close_contour
;
501 } T1_Builder_FuncsRec
;
504 /* an enumeration type to handle charstring parsing states */
505 typedef enum T1_ParseState_
509 T1_Parse_Have_Moveto
,
515 /*************************************************************************/
521 /* A structure used during glyph loading to store its outline. */
524 /* memory :: The current memory object. */
526 /* face :: The current face object. */
528 /* glyph :: The current glyph slot. */
532 /* base :: The base glyph outline. */
534 /* current :: The current glyph outline. */
536 /* max_points :: maximum points in builder outline */
538 /* max_contours :: Maximum number of contours in builder outline. */
540 /* pos_x :: The horizontal translation (if composite glyph). */
542 /* pos_y :: The vertical translation (if composite glyph). */
544 /* left_bearing :: The left side bearing point. */
546 /* advance :: The horizontal advance vector. */
548 /* bbox :: Unused. */
550 /* parse_state :: An enumeration which controls the charstring */
553 /* load_points :: If this flag is not set, no points are loaded. */
555 /* no_recurse :: Set but not used. */
557 /* metrics_only :: A boolean indicating that we only want to compute */
558 /* the metrics of a given glyph, not load all of its */
561 /* funcs :: An array of function pointers for the builder. */
563 typedef struct T1_BuilderRec_
568 FT_GlyphLoader loader
;
575 FT_Vector left_bearing
;
578 FT_BBox bbox
; /* bounding box */
579 T1_ParseState parse_state
;
583 FT_Bool metrics_only
;
585 void* hints_funcs
; /* hinter-specific */
586 void* hints_globals
; /* hinter-specific */
588 T1_Builder_FuncsRec funcs
;
593 /*************************************************************************/
594 /*************************************************************************/
596 /***** T1 DECODER *****/
598 /*************************************************************************/
599 /*************************************************************************/
603 /*************************************************************************/
605 /* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */
606 /* calls during glyph loading. */
608 #define T1_MAX_SUBRS_CALLS 8
611 /*************************************************************************/
613 /* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */
614 /* minimum of 16 is required. */
616 #define T1_MAX_CHARSTRINGS_OPERANDS 32
621 typedef struct T1_Decoder_ZoneRec_
627 } T1_Decoder_ZoneRec
, *T1_Decoder_Zone
;
630 typedef struct T1_DecoderRec_
* T1_Decoder
;
631 typedef const struct T1_Decoder_FuncsRec_
* T1_Decoder_Funcs
;
635 (*T1_Decoder_Callback
)( T1_Decoder decoder
,
636 FT_UInt glyph_index
);
639 typedef struct T1_Decoder_FuncsRec_
642 (*init
)( T1_Decoder decoder
,
646 FT_Byte
** glyph_names
,
649 FT_Render_Mode hint_mode
,
650 T1_Decoder_Callback callback
);
653 (*done
)( T1_Decoder decoder
);
656 (*parse_charstrings
)( T1_Decoder decoder
,
660 } T1_Decoder_FuncsRec
;
663 typedef struct T1_DecoderRec_
665 T1_BuilderRec builder
;
667 FT_Long stack
[T1_MAX_CHARSTRINGS_OPERANDS
];
670 T1_Decoder_ZoneRec zones
[T1_MAX_SUBRS_CALLS
+ 1];
671 T1_Decoder_Zone zone
;
673 FT_Service_PsCMaps psnames
; /* for seac */
675 FT_Byte
** glyph_names
;
677 FT_Int lenIV
; /* internal for sub routine calls */
680 FT_PtrDist
* subrs_len
; /* array of subrs length (optional) */
682 FT_Matrix font_matrix
;
683 FT_Vector font_offset
;
686 FT_Int num_flex_vectors
;
687 FT_Vector flex_vectors
[7];
689 PS_Blend blend
; /* for multiple master support */
691 FT_Render_Mode hint_mode
;
693 T1_Decoder_Callback parse_callback
;
694 T1_Decoder_FuncsRec funcs
;
697 FT_UInt len_buildchar
;
704 /*************************************************************************/
705 /*************************************************************************/
707 /***** AFM PARSER *****/
709 /*************************************************************************/
710 /*************************************************************************/
712 typedef struct AFM_ParserRec_
* AFM_Parser
;
714 typedef struct AFM_Parser_FuncsRec_
717 (*init
)( AFM_Parser parser
,
723 (*done
)( AFM_Parser parser
);
726 (*parse
)( AFM_Parser parser
);
728 } AFM_Parser_FuncsRec
;
731 typedef struct AFM_StreamRec_
* AFM_Stream
;
734 /*************************************************************************/
740 /* An AFM_Parser is a parser for the AFM files. */
743 /* memory :: The object used for memory operations (alloc and */
746 /* stream :: This is an opaque object. */
748 /* FontInfo :: The result will be stored here. */
750 /* get_index :: A user provided function to get a glyph index by its */
753 typedef struct AFM_ParserRec_
758 AFM_FontInfo FontInfo
;
761 (*get_index
)( const char* name
,
770 /*************************************************************************/
771 /*************************************************************************/
773 /***** TYPE1 CHARMAPS *****/
775 /*************************************************************************/
776 /*************************************************************************/
778 typedef const struct T1_CMap_ClassesRec_
* T1_CMap_Classes
;
780 typedef struct T1_CMap_ClassesRec_
782 FT_CMap_Class standard
;
783 FT_CMap_Class expert
;
784 FT_CMap_Class custom
;
785 FT_CMap_Class unicode
;
787 } T1_CMap_ClassesRec
;
790 /*************************************************************************/
791 /*************************************************************************/
793 /***** PSAux Module Interface *****/
795 /*************************************************************************/
796 /*************************************************************************/
798 typedef struct PSAux_ServiceRec_
800 /* don't use `PS_Table_Funcs' and friends to avoid compiler warnings */
801 const PS_Table_FuncsRec
* ps_table_funcs
;
802 const PS_Parser_FuncsRec
* ps_parser_funcs
;
803 const T1_Builder_FuncsRec
* t1_builder_funcs
;
804 const T1_Decoder_FuncsRec
* t1_decoder_funcs
;
807 (*t1_decrypt
)( FT_Byte
* buffer
,
811 T1_CMap_Classes t1_cmap_classes
;
813 /* fields after this comment line were added after version 2.1.10 */
814 const AFM_Parser_FuncsRec
* afm_parser_funcs
;
816 } PSAux_ServiceRec
, *PSAux_Service
;
818 /* backwards-compatible type definition */
819 typedef PSAux_ServiceRec PSAux_Interface
;
822 /*************************************************************************/
823 /*************************************************************************/
825 /***** Some convenience functions *****/
827 /*************************************************************************/
828 /*************************************************************************/
830 #define IS_PS_NEWLINE( ch ) \
834 #define IS_PS_SPACE( ch ) \
836 IS_PS_NEWLINE( ch ) || \
841 #define IS_PS_SPECIAL( ch ) \
843 (ch) == '(' || (ch) == ')' || \
844 (ch) == '<' || (ch) == '>' || \
845 (ch) == '[' || (ch) == ']' || \
846 (ch) == '{' || (ch) == '}' || \
849 #define IS_PS_DELIM( ch ) \
850 ( IS_PS_SPACE( ch ) || \
851 IS_PS_SPECIAL( ch ) )
853 #define IS_PS_DIGIT( ch ) \
854 ( (ch) >= '0' && (ch) <= '9' )
856 #define IS_PS_XDIGIT( ch ) \
857 ( IS_PS_DIGIT( ch ) || \
858 ( (ch) >= 'A' && (ch) <= 'F' ) || \
859 ( (ch) >= 'a' && (ch) <= 'f' ) )
861 #define IS_PS_BASE85( ch ) \
862 ( (ch) >= '!' && (ch) <= 'u' )
864 #define IS_PS_TOKEN( cur, limit, token ) \
865 ( (char)(cur)[0] == (token)[0] && \
866 ( (cur) + sizeof ( (token) ) == (limit) || \
867 ( (cur) + sizeof( (token) ) < (limit) && \
868 IS_PS_DELIM( (cur)[sizeof ( (token) ) - 1] ) ) ) && \
869 ft_strncmp( (char*)(cur), (token), sizeof ( (token) ) - 1 ) == 0 )
874 #endif /* __PSAUX_H__ */