1 /***************************************************************************/
2 /* */
3 /* psaux.h */
4 /* */
5 /* Auxiliary functions and data structures related to PostScript fonts */
6 /* (specification). */
7 /* */
8 /* Copyright 1996-2001 by */
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* */
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. */
16 /* */
17 /***************************************************************************/
20 #ifndef __PSAUX_H__
21 #define __PSAUX_H__
24 #include <ft2build.h>
25 #include FT_INTERNAL_OBJECTS_H
26 #include FT_INTERNAL_TYPE1_TYPES_H
29 FT_BEGIN_HEADER
32 /*************************************************************************/
33 /*************************************************************************/
34 /***** *****/
35 /***** T1_TABLE *****/
36 /***** *****/
37 /*************************************************************************/
38 /*************************************************************************/
41 typedef struct PS_Table_ PS_Table;
44 /*************************************************************************/
45 /* */
46 /* <Struct> */
47 /* PS_Table_Funcs */
48 /* */
49 /* <Description> */
50 /* A set of function pointers to manage PS_Table objects. */
51 /* */
52 /* <Fields> */
53 /* table_init :: Used to initialize a table. */
54 /* */
55 /* table_done :: Finalizes resp. destroy a given table. */
56 /* */
57 /* table_add :: Adds a new object to a table. */
58 /* */
59 /* table_release :: Releases table data, then finalizes it. */
60 /* */
61 typedef struct PS_Table_Funcs_
62 {
63 FT_Error
64 (*init)( PS_Table* table,
65 FT_Int count,
66 FT_Memory memory );
68 void
69 (*done)( PS_Table* table );
71 FT_Error
72 (*add)( PS_Table* table,
73 FT_Int index,
74 void* object,
75 FT_Int length );
77 void
78 (*release)( PS_Table* table );
80 } PS_Table_Funcs;
83 /*************************************************************************/
84 /* */
85 /* <Struct> */
86 /* PS_Table */
87 /* */
88 /* <Description> */
89 /* A PS_Table is a simple object used to store an array of objects in */
90 /* a single memory block. */
91 /* */
92 /* <Fields> */
93 /* block :: The address in memory of the growheap's block. This */
94 /* can change between two object adds, due to */
95 /* reallocation. */
96 /* */
97 /* cursor :: The current top of the grow heap within its block. */
98 /* */
99 /* capacity :: The current size of the heap block. Increments by */
100 /* 1kByte chunks. */
101 /* */
102 /* max_elems :: The maximum number of elements in table. */
103 /* */
104 /* num_elems :: The current number of elements in table. */
105 /* */
106 /* elements :: A table of element addresses within the block. */
107 /* */
108 /* lengths :: A table of element sizes within the block. */
109 /* */
110 /* memory :: The object used for memory operations */
111 /* (alloc/realloc). */
112 /* */
113 /* funcs :: A table of method pointers for this object. */
114 /* */
115 struct PS_Table_
116 {
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 */
120 FT_Long init;
122 FT_Int max_elems;
123 FT_Int num_elems;
124 FT_Byte** elements; /* addresses of table elements */
125 FT_Int* lengths; /* lengths of table elements */
127 FT_Memory memory;
128 PS_Table_Funcs funcs;
130 };
133 /*************************************************************************/
134 /*************************************************************************/
135 /***** *****/
136 /***** T1 FIELDS & TOKENS *****/
137 /***** *****/
138 /*************************************************************************/
139 /*************************************************************************/
141 typedef struct T1_Parser_ T1_Parser;
143 /* simple enumeration type used to identify token types */
144 typedef enum T1_Token_Type_
145 {
146 t1_token_none = 0,
147 t1_token_any,
148 t1_token_string,
149 t1_token_array,
151 /* do not remove */
152 t1_token_max
154 } T1_Token_Type;
157 /* a simple structure used to identify tokens */
158 typedef struct T1_Token_
159 {
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 */
164 } T1_Token;
167 /* enumeration type used to identify object fields */
168 typedef enum T1_Field_Type_
169 {
170 t1_field_none = 0,
171 t1_field_bool,
172 t1_field_integer,
173 t1_field_fixed,
174 t1_field_string,
175 t1_field_integer_array,
176 t1_field_fixed_array,
177 t1_field_callback,
179 /* do not remove */
180 t1_field_max
182 } T1_Field_Type;
184 typedef enum T1_Field_Location_
185 {
186 t1_field_cid_info,
187 t1_field_font_dict,
188 t1_field_font_info,
189 t1_field_private,
191 /* do not remove */
192 t1_field_location_max
194 } T1_Field_Location;
197 typedef void
198 (*T1_Field_Parser)( FT_Face face,
199 FT_Pointer parser );
202 /* structure type used to model object fields */
203 typedef struct T1_Field_
204 {
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 */
212 /* array */
213 FT_UInt count_offset; /* offset of element count for */
214 /* arrays */
215 } T1_Field;
218 #define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname ) \
219 { \
220 _ident, T1CODE, _type, \
221 0, \
222 FT_FIELD_OFFSET( _fname ), \
223 FT_FIELD_SIZE( _fname ), \
224 0, 0 \
225 },
227 #define T1_NEW_CALLBACK_FIELD( _ident, _reader ) \
228 { \
229 _ident, T1CODE, t1_field_callback, \
230 (T1_Field_Parser)_reader, \
231 0, 0, \
232 0, 0 \
233 },
235 #define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max ) \
236 { \
237 _ident, T1CODE, _type, \
238 0, \
239 FT_FIELD_OFFSET( _fname ), \
240 FT_FIELD_SIZE_DELTA( _fname ), \
241 _max, \
242 FT_FIELD_OFFSET( num_ ## _fname ) \
243 },
245 #define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max ) \
246 { \
247 _ident, T1CODE, _type, \
248 0, \
249 FT_FIELD_OFFSET( _fname ), \
250 FT_FIELD_SIZE_DELTA( _fname ), \
251 _max, 0 \
252 },
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, \
269 _fname, _fmax )
271 #define T1_FIELD_FIXED_TABLE( _ident, _fname, _fmax ) \
272 T1_NEW_TABLE_FIELD( _ident, t1_field_fixed_array, \
273 _fname, _fmax )
275 #define T1_FIELD_NUM_TABLE2( _ident, _fname, _fmax ) \
276 T1_NEW_TABLE_FIELD2( _ident, t1_field_integer_array, \
277 _fname, _fmax )
279 #define T1_FIELD_FIXED_TABLE2( _ident, _fname, _fmax ) \
280 T1_NEW_TABLE_FIELD2( _ident, t1_field_fixed_array, \
281 _fname, _fmax )
283 #define T1_FIELD_CALLBACK( _ident, _name ) \
284 T1_NEW_CALLBACK_FIELD( _ident, _name )
289 /*************************************************************************/
290 /*************************************************************************/
291 /***** *****/
292 /***** T1 PARSER *****/
293 /***** *****/
294 /*************************************************************************/
295 /*************************************************************************/
297 typedef struct T1_Parser_Funcs_
298 {
299 void
300 (*init)( T1_Parser* parser,
301 FT_Byte* base,
302 FT_Byte* limit,
303 FT_Memory memory );
305 void
306 (*done)( T1_Parser* parser );
308 void
309 (*skip_spaces)( T1_Parser* parser );
310 void
311 (*skip_alpha)( T1_Parser* parser );
313 FT_Long
314 (*to_int)( T1_Parser* parser );
315 FT_Fixed
316 (*to_fixed)( T1_Parser* parser,
317 FT_Int power_ten );
318 FT_Int
319 (*to_coord_array)( T1_Parser* parser,
320 FT_Int max_coords,
321 FT_Short* coords );
322 FT_Int
323 (*to_fixed_array)( T1_Parser* parser,
324 FT_Int max_values,
325 FT_Fixed* values,
326 FT_Int power_ten );
328 void
329 (*to_token)( T1_Parser* parser,
330 T1_Token* token );
331 void
332 (*to_token_array)( T1_Parser* parser,
333 T1_Token* tokens,
334 FT_UInt max_tokens,
335 FT_Int* pnum_tokens );
337 FT_Error
338 (*load_field)( T1_Parser* parser,
339 const T1_Field* field,
340 void** objects,
341 FT_UInt max_objects,
342 FT_ULong* pflags );
344 FT_Error
345 (*load_field_table)( T1_Parser* parser,
346 const T1_Field* field,
347 void** objects,
348 FT_UInt max_objects,
349 FT_ULong* pflags );
351 } T1_Parser_Funcs;
354 /*************************************************************************/
355 /* */
356 /* <Struct> */
357 /* T1_Parser */
358 /* */
359 /* <Description> */
360 /* A T1_Parser is an object used to parse a Type 1 font very quickly. */
361 /* */
362 /* <Fields> */
363 /* cursor :: The current position in the text. */
364 /* */
365 /* base :: Start of the processed text. */
366 /* */
367 /* limit :: End of the processed text. */
368 /* */
369 /* error :: The last error returned. */
370 /* */
371 /* memory :: The object used for memory operations (alloc/realloc). */
372 /* */
373 /* funcs :: A table of functions for the parser. */
374 /* */
375 struct T1_Parser_
376 {
377 FT_Byte* cursor;
378 FT_Byte* base;
379 FT_Byte* limit;
380 FT_Error error;
381 FT_Memory memory;
383 T1_Parser_Funcs funcs;
384 };
388 /*************************************************************************/
389 /*************************************************************************/
390 /***** *****/
391 /***** T1 BUILDER *****/
392 /***** *****/
393 /*************************************************************************/
394 /*************************************************************************/
397 typedef struct T1_Builder_ T1_Builder;
400 typedef FT_Error
401 (*T1_Builder_Check_Points_Func)( T1_Builder* builder,
402 FT_Int count );
404 typedef void
405 (*T1_Builder_Add_Point_Func)( T1_Builder* builder,
406 FT_Pos x,
407 FT_Pos y,
408 FT_Byte flag );
410 typedef FT_Error
411 (*T1_Builder_Add_Point1_Func)( T1_Builder* builder,
412 FT_Pos x,
413 FT_Pos y );
415 typedef FT_Error
416 (*T1_Builder_Add_Contour_Func)( T1_Builder* builder );
418 typedef FT_Error
419 (*T1_Builder_Start_Point_Func)( T1_Builder* builder,
420 FT_Pos x,
421 FT_Pos y );
423 typedef void
424 (*T1_Builder_Close_Contour_Func)( T1_Builder* builder );
427 typedef struct T1_Builder_Funcs_
428 {
429 void
430 (*init)( T1_Builder* builder,
431 FT_Face face,
432 FT_Size size,
433 FT_GlyphSlot slot );
435 void
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;
445 } T1_Builder_Funcs;
449 /*************************************************************************/
450 /* */
451 /* <Structure> */
452 /* T1_Builder */
453 /* */
454 /* <Description> */
455 /* A structure used during glyph loading to store its outline. */
456 /* */
457 /* <Fields> */
458 /* memory :: The current memory object. */
459 /* */
460 /* face :: The current face object. */
461 /* */
462 /* glyph :: The current glyph slot. */
463 /* */
464 /* loader :: XXX */
465 /* */
466 /* base :: The base glyph outline. */
467 /* */
468 /* current :: The current glyph outline. */
469 /* */
470 /* max_points :: maximum points in builder outline */
471 /* */
472 /* max_contours :: Maximal number of contours in builder outline. */
473 /* */
474 /* last :: The last point position. */
475 /* */
476 /* scale_x :: The horizontal scale (FUnits to sub-pixels). */
477 /* */
478 /* scale_y :: The vertical scale (FUnits to sub-pixels). */
479 /* */
480 /* pos_x :: The horizontal translation (if composite glyph). */
481 /* */
482 /* pos_y :: The vertical translation (if composite glyph). */
483 /* */
484 /* left_bearing :: The left side bearing point. */
485 /* */
486 /* advance :: The horizontal advance vector. */
487 /* */
488 /* bbox :: Unused. */
489 /* */
490 /* path_begun :: A flag which indicates that a new path has begun. */
491 /* */
492 /* load_points :: If this flag is not set, no points are loaded. */
493 /* */
494 /* no_recurse :: Set but not used. */
495 /* */
496 /* error :: An error code that is only used to report memory */
497 /* allocation problems. */
498 /* */
499 /* metrics_only :: A boolean indicating that we only want to compute */
500 /* the metrics of a given glyph, not load all of its */
501 /* points. */
502 /* */
503 /* funcs :: An array of function pointers for the builder. */
504 /* */
505 struct T1_Builder_
506 {
507 FT_Memory memory;
508 FT_Face face;
509 FT_GlyphSlot glyph;
510 FT_GlyphLoader* loader;
511 FT_Outline* base;
512 FT_Outline* current;
514 FT_Vector last;
516 FT_Fixed scale_x;
517 FT_Fixed scale_y;
519 FT_Pos pos_x;
520 FT_Pos pos_y;
522 FT_Vector left_bearing;
523 FT_Vector advance;
525 FT_BBox bbox; /* bounding box */
526 FT_Bool path_begun;
527 FT_Bool load_points;
528 FT_Bool no_recurse;
529 FT_Bool shift;
531 FT_Error error; /* only used for memory errors */
532 FT_Bool metrics_only;
534 T1_Builder_Funcs funcs;
535 };
538 /*************************************************************************/
539 /*************************************************************************/
540 /***** *****/
541 /***** T1 DECODER *****/
542 /***** *****/
543 /*************************************************************************/
544 /*************************************************************************/
546 #if 0
548 /*************************************************************************/
549 /* */
550 /* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */
551 /* calls during glyph loading. */
552 /* */
553 #define T1_MAX_SUBRS_CALLS 8
556 /*************************************************************************/
557 /* */
558 /* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */
559 /* minimum of 16 is required. */
560 /* */
561 #define T1_MAX_CHARSTRINGS_OPERANDS 32
563 #endif /* 0 */
566 typedef struct T1_Decoder_Zone_
567 {
568 FT_Byte* cursor;
569 FT_Byte* base;
570 FT_Byte* limit;
572 } T1_Decoder_Zone;
575 typedef struct T1_Decoder_ T1_Decoder;
576 typedef struct T1_Decoder_Funcs_ T1_Decoder_Funcs;
579 typedef FT_Error
580 (*T1_Decoder_Callback)( T1_Decoder* decoder,
581 FT_UInt glyph_index );
584 struct T1_Decoder_Funcs_
585 {
586 FT_Error
587 (*init)( T1_Decoder* decoder,
588 FT_Face face,
589 FT_Size size,
590 FT_GlyphSlot slot,
591 FT_Byte** glyph_names,
592 T1_Blend* blend,
593 T1_Decoder_Callback callback );
595 void
596 (*done)( T1_Decoder* decoder );
598 FT_Error
599 (*parse_charstrings)( T1_Decoder* decoder,
600 FT_Byte* base,
601 FT_UInt len );
602 };
605 struct T1_Decoder_
606 {
607 T1_Builder builder;
609 FT_Long stack[T1_MAX_CHARSTRINGS_OPERANDS];
610 FT_Long* top;
612 T1_Decoder_Zone zones[T1_MAX_SUBRS_CALLS + 1];
613 T1_Decoder_Zone* zone;
615 PSNames_Interface* psnames; /* for seac */
616 FT_UInt num_glyphs;
617 FT_Byte** glyph_names;
619 FT_Int lenIV; /* internal for sub routine calls */
620 FT_UInt num_subrs;
621 FT_Byte** subrs;
622 FT_Int* subrs_len; /* array of subrs length (optional) */
624 FT_Matrix font_matrix;
625 FT_Vector font_offset;
627 FT_Int flex_state;
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;
635 };
638 /*************************************************************************/
639 /*************************************************************************/
640 /***** *****/
641 /***** PSAux Module Interface *****/
642 /***** *****/
643 /*************************************************************************/
644 /*************************************************************************/
646 typedef struct PSAux_Interface_
647 {
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;
653 void
654 (*t1_decrypt)( FT_Byte* buffer,
655 FT_Offset length,
656 FT_UShort seed );
658 } PSAux_Interface;
661 FT_END_HEADER
663 #endif /* __PSAUX_H__ */
666 /* END */