sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
psaux.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * psaux.h
4 *
5 * Auxiliary functions and data structures related to PostScript fonts
6 * (specification).
7 *
8 * Copyright (C) 1996-2025 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 */
18
19
24#ifndef PSAUX_H_
25#define PSAUX_H_
26
27
35
36
37
38FT_BEGIN_HEADER
39
40
41 /**************************************************************************
42 *
43 * PostScript modules driver class.
44 */
45 typedef struct PS_DriverRec_
46 {
47 FT_DriverRec root;
48
49 FT_UInt hinting_engine;
50 FT_Bool no_stem_darkening;
51 FT_Int darken_params[8];
52 FT_Int32 random_seed;
53
54 } PS_DriverRec, *PS_Driver;
55
56
57 /*************************************************************************/
58 /*************************************************************************/
59 /***** *****/
60 /***** T1_TABLE *****/
61 /***** *****/
62 /*************************************************************************/
63 /*************************************************************************/
64
65
66 typedef struct PS_TableRec_* PS_Table;
67 typedef const struct PS_Table_FuncsRec_* PS_Table_Funcs;
68
69
70 /**************************************************************************
71 *
72 * @struct:
73 * PS_Table_FuncsRec
74 *
75 * @description:
76 * A set of function pointers to manage PS_Table objects.
77 *
78 * @fields:
79 * table_init ::
80 * Used to initialize a table.
81 *
82 * table_done ::
83 * Finalizes resp. destroy a given table.
84 *
85 * table_add ::
86 * Adds a new object to a table.
87 *
88 * table_release ::
89 * Releases table data, then finalizes it.
90 */
91 typedef struct PS_Table_FuncsRec_
92 {
93 FT_Error
94 (*init)( PS_Table table,
95 FT_Int count,
96 FT_Memory memory );
97
98 void
99 (*done)( PS_Table table );
100
101 FT_Error
102 (*add)( PS_Table table,
103 FT_Int idx,
104 const void* object,
105 FT_UInt length );
106
107 void
108 (*release)( PS_Table table );
109
110 } PS_Table_FuncsRec;
111
112
113 /**************************************************************************
114 *
115 * @struct:
116 * PS_TableRec
117 *
118 * @description:
119 * A PS_Table is a simple object used to store an array of objects in a
120 * single memory block.
121 *
122 * @fields:
123 * block ::
124 * The address in memory of the growheap's block. This can change
125 * between two object adds, due to reallocation.
126 *
127 * cursor ::
128 * The current top of the grow heap within its block.
129 *
130 * capacity ::
131 * The current size of the heap block. Increments by 1kByte chunks.
132 *
133 * init ::
134 * Set to 0xDEADBEEF if 'elements' and 'lengths' have been allocated.
135 *
136 * max_elems ::
137 * The maximum number of elements in table.
138 *
139 * elements ::
140 * A table of element addresses within the block.
141 *
142 * lengths ::
143 * A table of element sizes within the block.
144 *
145 * memory ::
146 * The object used for memory operations (alloc/realloc).
147 *
148 * funcs ::
149 * A table of method pointers for this object.
150 */
151 typedef struct PS_TableRec_
152 {
153 FT_Byte* block; /* current memory block */
154 FT_Offset cursor; /* current cursor in memory block */
155 FT_Offset capacity; /* current size of memory block */
156 FT_ULong init;
157
158 FT_Int max_elems;
159 FT_Byte** elements; /* addresses of table elements */
160 FT_UInt* lengths; /* lengths of table elements */
161
162 FT_Memory memory;
163 PS_Table_FuncsRec funcs;
164
165 } PS_TableRec;
166
167
168 /*************************************************************************/
169 /*************************************************************************/
170 /***** *****/
171 /***** T1 FIELDS & TOKENS *****/
172 /***** *****/
173 /*************************************************************************/
174 /*************************************************************************/
175
176 typedef struct PS_ParserRec_* PS_Parser;
177
178 typedef struct T1_TokenRec_* T1_Token;
179
180 typedef struct T1_FieldRec_* T1_Field;
181
182
183 /* simple enumeration type used to identify token types */
184 typedef enum T1_TokenType_
185 {
186 T1_TOKEN_TYPE_NONE = 0,
187 T1_TOKEN_TYPE_ANY,
188 T1_TOKEN_TYPE_STRING,
189 T1_TOKEN_TYPE_ARRAY,
190 T1_TOKEN_TYPE_KEY, /* aka `name' */
191
192 /* do not remove */
193 T1_TOKEN_TYPE_MAX
194
195 } T1_TokenType;
196
197
198 /* a simple structure used to identify tokens */
199 typedef struct T1_TokenRec_
200 {
201 FT_Byte* start; /* first character of token in input stream */
202 FT_Byte* limit; /* first character after the token */
203 T1_TokenType type; /* type of token */
204
205 } T1_TokenRec;
206
207
208 /* enumeration type used to identify object fields */
209 typedef enum T1_FieldType_
210 {
211 T1_FIELD_TYPE_NONE = 0,
212 T1_FIELD_TYPE_BOOL,
213 T1_FIELD_TYPE_INTEGER,
214 T1_FIELD_TYPE_FIXED,
215 T1_FIELD_TYPE_FIXED_1000,
216 T1_FIELD_TYPE_STRING,
217 T1_FIELD_TYPE_KEY,
218 T1_FIELD_TYPE_BBOX,
219 T1_FIELD_TYPE_MM_BBOX,
220 T1_FIELD_TYPE_INTEGER_ARRAY,
221 T1_FIELD_TYPE_FIXED_ARRAY,
222 T1_FIELD_TYPE_CALLBACK,
223
224 /* do not remove */
225 T1_FIELD_TYPE_MAX
226
227 } T1_FieldType;
228
229
230 typedef enum T1_FieldLocation_
231 {
232 T1_FIELD_LOCATION_NONE = 0,
233 T1_FIELD_LOCATION_CID_INFO,
234 T1_FIELD_LOCATION_FONT_DICT,
235 T1_FIELD_LOCATION_FONT_EXTRA,
236 T1_FIELD_LOCATION_FONT_INFO,
237 T1_FIELD_LOCATION_PRIVATE,
238 T1_FIELD_LOCATION_BBOX,
239 T1_FIELD_LOCATION_LOADER,
240 T1_FIELD_LOCATION_FACE,
241 T1_FIELD_LOCATION_BLEND,
242
243 /* do not remove */
244 T1_FIELD_LOCATION_MAX
245
246 } T1_FieldLocation;
247
248
249 typedef void
250 (*T1_Field_ParseFunc)( FT_Face face,
251 FT_Pointer parser );
252
253
254 /* structure type used to model object fields */
255 typedef struct T1_FieldRec_
256 {
257 FT_UInt len; /* field identifier length */
258 const char* ident; /* field identifier */
259 T1_FieldLocation location;
260 T1_FieldType type; /* type of field */
261 T1_Field_ParseFunc reader;
262 FT_UInt offset; /* offset of field in object */
263 FT_Byte size; /* size of field in bytes */
264 FT_UInt array_max; /* maximum number of elements for */
265 /* array */
266 FT_UInt count_offset; /* offset of element count for */
267 /* arrays; must not be zero if in */
268 /* use -- in other words, a */
269 /* `num_FOO' element must not */
270 /* start the used structure if we */
271 /* parse a `FOO' array */
272 FT_UInt dict; /* where we expect it */
273 } T1_FieldRec;
274
275#define T1_FIELD_DICT_FONTDICT ( 1 << 0 ) /* also FontInfo and FDArray */
276#define T1_FIELD_DICT_PRIVATE ( 1 << 1 )
277
278
279
280#define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname, _dict ) \
281 { \
282 sizeof ( _ident ) - 1, \
283 _ident, T1CODE, _type, \
284 NULL, \
285 FT_FIELD_OFFSET( _fname ), \
286 FT_FIELD_SIZE( _fname ), \
287 0, 0, \
288 _dict \
289 },
290
291#define T1_NEW_CALLBACK_FIELD( _ident, _reader, _dict ) \
292 { \
293 sizeof ( _ident ) - 1, \
294 _ident, T1CODE, T1_FIELD_TYPE_CALLBACK, \
295 (T1_Field_ParseFunc)_reader, \
296 0, 0, \
297 0, 0, \
298 _dict \
299 },
300
301#define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max, _dict ) \
302 { \
303 sizeof ( _ident ) - 1, \
304 _ident, T1CODE, _type, \
305 NULL, \
306 FT_FIELD_OFFSET( _fname ), \
307 FT_FIELD_SIZE_DELTA( _fname ), \
308 _max, \
309 FT_FIELD_OFFSET( num_ ## _fname ), \
310 _dict \
311 },
312
313#define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max, _dict ) \
314 { \
315 sizeof ( _ident ) - 1, \
316 _ident, T1CODE, _type, \
317 NULL, \
318 FT_FIELD_OFFSET( _fname ), \
319 FT_FIELD_SIZE_DELTA( _fname ), \
320 _max, 0, \
321 _dict \
322 },
323
324
325#define T1_FIELD_BOOL( _ident, _fname, _dict ) \
326 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BOOL, _fname, _dict )
327
328#define T1_FIELD_NUM( _ident, _fname, _dict ) \
329 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER, _fname, _dict )
330
331#define T1_FIELD_FIXED( _ident, _fname, _dict ) \
332 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED, _fname, _dict )
333
334#define T1_FIELD_FIXED_1000( _ident, _fname, _dict ) \
335 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_1000, _fname, \
336 _dict )
337
338#define T1_FIELD_STRING( _ident, _fname, _dict ) \
339 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_STRING, _fname, _dict )
340
341#define T1_FIELD_KEY( _ident, _fname, _dict ) \
342 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_KEY, _fname, _dict )
343
344#define T1_FIELD_BBOX( _ident, _fname, _dict ) \
345 T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BBOX, _fname, _dict )
346
347
348#define T1_FIELD_NUM_TABLE( _ident, _fname, _fmax, _dict ) \
349 T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
350 _fname, _fmax, _dict )
351
352#define T1_FIELD_FIXED_TABLE( _ident, _fname, _fmax, _dict ) \
353 T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
354 _fname, _fmax, _dict )
355
356#define T1_FIELD_NUM_TABLE2( _ident, _fname, _fmax, _dict ) \
357 T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
358 _fname, _fmax, _dict )
359
360#define T1_FIELD_FIXED_TABLE2( _ident, _fname, _fmax, _dict ) \
361 T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
362 _fname, _fmax, _dict )
363
364#define T1_FIELD_CALLBACK( _ident, _name, _dict ) \
365 T1_NEW_CALLBACK_FIELD( _ident, _name, _dict )
366
367#define T1_FIELD_ZERO \
368 { \
369 0, \
370 NULL, T1_FIELD_LOCATION_NONE, T1_FIELD_TYPE_NONE, \
371 NULL, 0, 0, 0, 0, 0 \
372 }
373
374
375 /*************************************************************************/
376 /*************************************************************************/
377 /***** *****/
378 /***** T1 PARSER *****/
379 /***** *****/
380 /*************************************************************************/
381 /*************************************************************************/
382
383 typedef const struct PS_Parser_FuncsRec_* PS_Parser_Funcs;
384
385 typedef struct PS_Parser_FuncsRec_
386 {
387 void
388 (*init)( PS_Parser parser,
389 FT_Byte* base,
390 FT_Byte* limit,
391 FT_Memory memory );
392
393 void
394 (*done)( PS_Parser parser );
395
396 void
397 (*skip_spaces)( PS_Parser parser );
398 void
399 (*skip_PS_token)( PS_Parser parser );
400
401 FT_Long
402 (*to_int)( PS_Parser parser );
403 FT_Fixed
404 (*to_fixed)( PS_Parser parser,
405 FT_Int power_ten );
406
407 FT_Error
408 (*to_bytes)( PS_Parser parser,
409 FT_Byte* bytes,
410 FT_Offset max_bytes,
411 FT_ULong* pnum_bytes,
412 FT_Bool delimiters );
413
414 FT_Int
415 (*to_coord_array)( PS_Parser parser,
416 FT_Int max_coords,
417 FT_Short* coords );
418 FT_Int
419 (*to_fixed_array)( PS_Parser parser,
420 FT_Int max_values,
421 FT_Fixed* values,
422 FT_Int power_ten );
423
424 void
425 (*to_token)( PS_Parser parser,
426 T1_Token token );
427 void
428 (*to_token_array)( PS_Parser parser,
429 T1_Token tokens,
430 FT_UInt max_tokens,
431 FT_Int* pnum_tokens );
432
433 FT_Error
434 (*load_field)( PS_Parser parser,
435 const T1_Field field,
436 void** objects,
437 FT_UInt max_objects,
438 FT_ULong* pflags );
439
440 FT_Error
441 (*load_field_table)( PS_Parser parser,
442 const T1_Field field,
443 void** objects,
444 FT_UInt max_objects,
445 FT_ULong* pflags );
446
447 } PS_Parser_FuncsRec;
448
449
450 /**************************************************************************
451 *
452 * @struct:
453 * PS_ParserRec
454 *
455 * @description:
456 * A PS_Parser is an object used to parse a Type 1 font very quickly.
457 *
458 * @fields:
459 * cursor ::
460 * The current position in the text.
461 *
462 * base ::
463 * Start of the processed text.
464 *
465 * limit ::
466 * End of the processed text.
467 *
468 * error ::
469 * The last error returned.
470 *
471 * memory ::
472 * The object used for memory operations (alloc/realloc).
473 *
474 * funcs ::
475 * A table of functions for the parser.
476 */
477 typedef struct PS_ParserRec_
478 {
479 FT_Byte* cursor;
480 FT_Byte* base;
481 FT_Byte* limit;
482 FT_Error error;
483 FT_Memory memory;
484
485 PS_Parser_FuncsRec funcs;
486
487 } PS_ParserRec;
488
489
490 /*************************************************************************/
491 /*************************************************************************/
492 /***** *****/
493 /***** PS BUILDER *****/
494 /***** *****/
495 /*************************************************************************/
496 /*************************************************************************/
497
498
499 typedef struct PS_Builder_ PS_Builder;
500 typedef const struct PS_Builder_FuncsRec_* PS_Builder_Funcs;
501
502 typedef struct PS_Builder_FuncsRec_
503 {
504 void
505 (*init)( PS_Builder* ps_builder,
506 void* builder,
507 FT_Bool is_t1 );
508
509 void
510 (*done)( PS_Builder* builder );
511
512 } PS_Builder_FuncsRec;
513
514
515 /**************************************************************************
516 *
517 * @struct:
518 * PS_Builder
519 *
520 * @description:
521 * A structure used during glyph loading to store its outline.
522 *
523 * @fields:
524 * memory ::
525 * The current memory object.
526 *
527 * face ::
528 * The current face object.
529 *
530 * glyph ::
531 * The current glyph slot.
532 *
533 * loader ::
534 * XXX
535 *
536 * base ::
537 * The base glyph outline.
538 *
539 * current ::
540 * The current glyph outline.
541 *
542 * pos_x ::
543 * The horizontal translation (if composite glyph).
544 *
545 * pos_y ::
546 * The vertical translation (if composite glyph).
547 *
548 * left_bearing ::
549 * The left side bearing point.
550 *
551 * advance ::
552 * The horizontal advance vector.
553 *
554 * bbox ::
555 * Unused.
556 *
557 * path_begun ::
558 * A flag which indicates that a new path has begun.
559 *
560 * load_points ::
561 * If this flag is not set, no points are loaded.
562 *
563 * no_recurse ::
564 * Set but not used.
565 *
566 * metrics_only ::
567 * A boolean indicating that we only want to compute the metrics of a
568 * given glyph, not load all of its points.
569 *
570 * is_t1 ::
571 * Set if current font type is Type 1.
572 *
573 * funcs ::
574 * An array of function pointers for the builder.
575 */
577 {
578 FT_Memory memory;
579 FT_Face face;
580 CFF_GlyphSlot glyph;
581 FT_GlyphLoader loader;
582 FT_Outline* base;
583 FT_Outline* current;
584
585 FT_Pos* pos_x;
586 FT_Pos* pos_y;
587
588 FT_Vector* left_bearing;
589 FT_Vector* advance;
590
591 FT_BBox* bbox; /* bounding box */
592 FT_Bool path_begun;
593 FT_Bool load_points;
594 FT_Bool no_recurse;
595
596 FT_Bool metrics_only;
597 FT_Bool is_t1;
598
599 PS_Builder_FuncsRec funcs;
600
601 };
602
603
604 /*************************************************************************/
605 /*************************************************************************/
606 /***** *****/
607 /***** PS DECODER *****/
608 /***** *****/
609 /*************************************************************************/
610 /*************************************************************************/
611
612#define PS_MAX_OPERANDS 48
613#define PS_MAX_SUBRS_CALLS 16 /* maximum subroutine nesting; */
614 /* only 10 are allowed but there exist */
615 /* fonts like `HiraKakuProN-W3.ttf' */
616 /* (Hiragino Kaku Gothic ProN W3; */
617 /* 8.2d6e1; 2014-12-19) that exceed */
618 /* this limit */
619
620 /* execution context charstring zone */
621
622 typedef struct PS_Decoder_Zone_
623 {
624 FT_Byte* base;
625 FT_Byte* limit;
626 FT_Byte* cursor;
627
628 } PS_Decoder_Zone;
629
630
631 typedef FT_Error
632 (*CFF_Decoder_Get_Glyph_Callback)( TT_Face face,
633 FT_UInt glyph_index,
634 FT_Byte** pointer,
635 FT_ULong* length );
636
637 typedef void
638 (*CFF_Decoder_Free_Glyph_Callback)( TT_Face face,
639 FT_Byte** pointer,
640 FT_ULong length );
641
642
643 typedef struct PS_Decoder_
644 {
645 PS_Builder builder;
646
647 FT_Fixed stack[PS_MAX_OPERANDS + 1];
648 FT_Fixed* top;
649
650 PS_Decoder_Zone zones[PS_MAX_SUBRS_CALLS + 1];
651 PS_Decoder_Zone* zone;
652
653 FT_Int flex_state;
654 FT_Int num_flex_vectors;
655 FT_Vector flex_vectors[7];
656
657 CFF_Font cff;
658 CFF_SubFont current_subfont; /* for current glyph_index */
659 FT_Generic* cf2_instance;
660
661 FT_Pos* glyph_width;
662 FT_Bool width_only;
663 FT_Int num_hints;
664
665 FT_UInt num_locals;
666 FT_UInt num_globals;
667
668 FT_Int locals_bias;
669 FT_Int globals_bias;
670
671 FT_Byte** locals;
672 FT_Byte** globals;
673
674 FT_Byte** glyph_names; /* for pure CFF fonts only */
675 FT_UInt num_glyphs; /* number of glyphs in font */
676
677 FT_Render_Mode hint_mode;
678
679 FT_Bool seac;
680
681 CFF_Decoder_Get_Glyph_Callback get_glyph_callback;
682 CFF_Decoder_Free_Glyph_Callback free_glyph_callback;
683
684 /* Type 1 stuff */
685 FT_Service_PsCMaps psnames; /* for seac */
686
687 FT_Int lenIV; /* internal for sub routine calls */
688 FT_UInt* locals_len; /* array of subrs length (optional) */
689 FT_Hash locals_hash; /* used if `num_subrs' was massaged */
690
691 FT_Matrix font_matrix;
692 FT_Vector font_offset;
693
694 PS_Blend blend; /* for multiple master support */
695
696 FT_Long* buildchar;
697 FT_UInt len_buildchar;
698
699 } PS_Decoder;
700
701
702 /*************************************************************************/
703 /*************************************************************************/
704 /***** *****/
705 /***** T1 BUILDER *****/
706 /***** *****/
707 /*************************************************************************/
708 /*************************************************************************/
709
710
711 typedef struct T1_BuilderRec_* T1_Builder;
712
713
714 typedef FT_Error
715 (*T1_Builder_Check_Points_Func)( T1_Builder builder,
716 FT_Int count );
717
718 typedef void
719 (*T1_Builder_Add_Point_Func)( T1_Builder builder,
720 FT_Pos x,
721 FT_Pos y,
722 FT_Byte flag );
723
724 typedef FT_Error
725 (*T1_Builder_Add_Point1_Func)( T1_Builder builder,
726 FT_Pos x,
727 FT_Pos y );
728
729 typedef FT_Error
730 (*T1_Builder_Add_Contour_Func)( T1_Builder builder );
731
732 typedef FT_Error
733 (*T1_Builder_Start_Point_Func)( T1_Builder builder,
734 FT_Pos x,
735 FT_Pos y );
736
737 typedef void
738 (*T1_Builder_Close_Contour_Func)( T1_Builder builder );
739
740
741 typedef const struct T1_Builder_FuncsRec_* T1_Builder_Funcs;
742
743 typedef struct T1_Builder_FuncsRec_
744 {
745 void
746 (*init)( T1_Builder builder,
747 FT_Face face,
748 FT_Size size,
749 FT_GlyphSlot slot,
750 FT_Bool hinting );
751
752 void
753 (*done)( T1_Builder builder );
754
755 T1_Builder_Check_Points_Func check_points;
756 T1_Builder_Add_Point_Func add_point;
757 T1_Builder_Add_Point1_Func add_point1;
758 T1_Builder_Add_Contour_Func add_contour;
759 T1_Builder_Start_Point_Func start_point;
760 T1_Builder_Close_Contour_Func close_contour;
761
762 } T1_Builder_FuncsRec;
763
764
765 /* an enumeration type to handle charstring parsing states */
766 typedef enum T1_ParseState_
767 {
768 T1_Parse_Start,
769 T1_Parse_Have_Width,
770 T1_Parse_Have_Moveto,
771 T1_Parse_Have_Path
772
773 } T1_ParseState;
774
775
776 /**************************************************************************
777 *
778 * @struct:
779 * T1_BuilderRec
780 *
781 * @description:
782 * A structure used during glyph loading to store its outline.
783 *
784 * @fields:
785 * memory ::
786 * The current memory object.
787 *
788 * face ::
789 * The current face object.
790 *
791 * glyph ::
792 * The current glyph slot.
793 *
794 * loader ::
795 * XXX
796 *
797 * base ::
798 * The base glyph outline.
799 *
800 * current ::
801 * The current glyph outline.
802 *
803 * max_points ::
804 * maximum points in builder outline
805 *
806 * max_contours ::
807 * Maximum number of contours in builder outline.
808 *
809 * pos_x ::
810 * The horizontal translation (if composite glyph).
811 *
812 * pos_y ::
813 * The vertical translation (if composite glyph).
814 *
815 * left_bearing ::
816 * The left side bearing point.
817 *
818 * advance ::
819 * The horizontal advance vector.
820 *
821 * bbox ::
822 * Unused.
823 *
824 * parse_state ::
825 * An enumeration which controls the charstring parsing state.
826 *
827 * load_points ::
828 * If this flag is not set, no points are loaded.
829 *
830 * no_recurse ::
831 * Set but not used.
832 *
833 * metrics_only ::
834 * A boolean indicating that we only want to compute the metrics of a
835 * given glyph, not load all of its points.
836 *
837 * funcs ::
838 * An array of function pointers for the builder.
839 */
840 typedef struct T1_BuilderRec_
841 {
842 FT_Memory memory;
843 FT_Face face;
844 FT_GlyphSlot glyph;
845 FT_GlyphLoader loader;
846 FT_Outline* base;
847 FT_Outline* current;
848
849 FT_Pos pos_x;
850 FT_Pos pos_y;
851
852 FT_Vector left_bearing;
853 FT_Vector advance;
854
855 FT_BBox bbox; /* bounding box */
856 T1_ParseState parse_state;
857 FT_Bool load_points;
858 FT_Bool no_recurse;
859
860 FT_Bool metrics_only;
861
862 void* hints_funcs; /* hinter-specific */
863 void* hints_globals; /* hinter-specific */
864
865 T1_Builder_FuncsRec funcs;
866
867 } T1_BuilderRec;
868
869
870 /*************************************************************************/
871 /*************************************************************************/
872 /***** *****/
873 /***** T1 DECODER *****/
874 /***** *****/
875 /*************************************************************************/
876 /*************************************************************************/
877
878#if 0
879
880 /**************************************************************************
881 *
882 * T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine
883 * calls during glyph loading.
884 */
885#define T1_MAX_SUBRS_CALLS 8
886
887
888 /**************************************************************************
889 *
890 * T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A
891 * minimum of 16 is required.
892 */
893#define T1_MAX_CHARSTRINGS_OPERANDS 32
894
895#endif /* 0 */
896
897
898 typedef struct T1_Decoder_ZoneRec_
899 {
900 FT_Byte* cursor;
901 FT_Byte* base;
902 FT_Byte* limit;
903
904 } T1_Decoder_ZoneRec, *T1_Decoder_Zone;
905
906
907 typedef struct T1_DecoderRec_* T1_Decoder;
908 typedef const struct T1_Decoder_FuncsRec_* T1_Decoder_Funcs;
909
910
911 typedef FT_Error
912 (*T1_Decoder_Callback)( T1_Decoder decoder,
913 FT_UInt glyph_index );
914
915
916 typedef struct T1_Decoder_FuncsRec_
917 {
918 FT_Error
919 (*init)( T1_Decoder decoder,
920 FT_Face face,
921 FT_Size size,
922 FT_GlyphSlot slot,
923 FT_Byte** glyph_names,
924 PS_Blend blend,
925 FT_Bool hinting,
926 FT_Render_Mode hint_mode,
927 T1_Decoder_Callback callback );
928
929 void
930 (*done)( T1_Decoder decoder );
931
932#ifdef T1_CONFIG_OPTION_OLD_ENGINE
933 FT_Error
934 (*parse_charstrings_old)( T1_Decoder decoder,
935 FT_Byte* base,
936 FT_UInt len );
937#else
938 FT_Error
939 (*parse_metrics)( T1_Decoder decoder,
940 FT_Byte* base,
941 FT_UInt len );
942#endif
943
944 FT_Error
945 (*parse_charstrings)( PS_Decoder* decoder,
946 FT_Byte* charstring_base,
947 FT_ULong charstring_len );
948
949
950 } T1_Decoder_FuncsRec;
951
952
953 typedef struct T1_DecoderRec_
954 {
955 T1_BuilderRec builder;
956
957 FT_Long stack[T1_MAX_CHARSTRINGS_OPERANDS];
958 FT_Long* top;
959
960 T1_Decoder_ZoneRec zones[T1_MAX_SUBRS_CALLS + 1];
961 T1_Decoder_Zone zone;
962
963 FT_Service_PsCMaps psnames; /* for seac */
964 FT_UInt num_glyphs;
965 FT_Byte** glyph_names;
966
967 FT_Int lenIV; /* internal for sub routine calls */
968 FT_Int num_subrs;
969 FT_Byte** subrs;
970 FT_UInt* subrs_len; /* array of subrs length (optional) */
971 FT_Hash subrs_hash; /* used if `num_subrs' was massaged */
972
973 FT_Matrix font_matrix;
974 FT_Vector font_offset;
975
976 FT_Int flex_state;
977 FT_Int num_flex_vectors;
978 FT_Vector flex_vectors[7];
979
980 PS_Blend blend; /* for multiple master support */
981
982 FT_Render_Mode hint_mode;
983
984 T1_Decoder_Callback parse_callback;
985 T1_Decoder_FuncsRec funcs;
986
987 FT_Long* buildchar;
988 FT_UInt len_buildchar;
989
990 FT_Bool seac;
991
992 FT_Generic cf2_instance;
993
994 } T1_DecoderRec;
995
996
997 /*************************************************************************/
998 /*************************************************************************/
999 /***** *****/
1000 /***** CFF BUILDER *****/
1001 /***** *****/
1002 /*************************************************************************/
1003 /*************************************************************************/
1004
1005
1006 typedef struct CFF_Builder_ CFF_Builder;
1007
1008
1009 typedef FT_Error
1010 (*CFF_Builder_Check_Points_Func)( CFF_Builder* builder,
1011 FT_Int count );
1012
1013 typedef void
1014 (*CFF_Builder_Add_Point_Func)( CFF_Builder* builder,
1015 FT_Pos x,
1016 FT_Pos y,
1017 FT_Byte flag );
1018 typedef FT_Error
1019 (*CFF_Builder_Add_Point1_Func)( CFF_Builder* builder,
1020 FT_Pos x,
1021 FT_Pos y );
1022 typedef FT_Error
1023 (*CFF_Builder_Start_Point_Func)( CFF_Builder* builder,
1024 FT_Pos x,
1025 FT_Pos y );
1026 typedef void
1027 (*CFF_Builder_Close_Contour_Func)( CFF_Builder* builder );
1028
1029 typedef FT_Error
1030 (*CFF_Builder_Add_Contour_Func)( CFF_Builder* builder );
1031
1032 typedef const struct CFF_Builder_FuncsRec_* CFF_Builder_Funcs;
1033
1035 {
1036 void
1037 (*init)( CFF_Builder* builder,
1038 TT_Face face,
1039 CFF_Size size,
1040 CFF_GlyphSlot glyph,
1041 FT_Bool hinting );
1042
1043 void
1044 (*done)( CFF_Builder* builder );
1045
1046 CFF_Builder_Check_Points_Func check_points;
1047 CFF_Builder_Add_Point_Func add_point;
1048 CFF_Builder_Add_Point1_Func add_point1;
1049 CFF_Builder_Add_Contour_Func add_contour;
1050 CFF_Builder_Start_Point_Func start_point;
1051 CFF_Builder_Close_Contour_Func close_contour;
1052
1053 } CFF_Builder_FuncsRec;
1054
1055
1056 /**************************************************************************
1057 *
1058 * @struct:
1059 * CFF_Builder
1060 *
1061 * @description:
1062 * A structure used during glyph loading to store its outline.
1063 *
1064 * @fields:
1065 * memory ::
1066 * The current memory object.
1067 *
1068 * face ::
1069 * The current face object.
1070 *
1071 * glyph ::
1072 * The current glyph slot.
1073 *
1074 * loader ::
1075 * The current glyph loader.
1076 *
1077 * base ::
1078 * The base glyph outline.
1079 *
1080 * current ::
1081 * The current glyph outline.
1082 *
1083 * pos_x ::
1084 * The horizontal translation (if composite glyph).
1085 *
1086 * pos_y ::
1087 * The vertical translation (if composite glyph).
1088 *
1089 * left_bearing ::
1090 * The left side bearing point.
1091 *
1092 * advance ::
1093 * The horizontal advance vector.
1094 *
1095 * bbox ::
1096 * Unused.
1097 *
1098 * path_begun ::
1099 * A flag which indicates that a new path has begun.
1100 *
1101 * load_points ::
1102 * If this flag is not set, no points are loaded.
1103 *
1104 * no_recurse ::
1105 * Set but not used.
1106 *
1107 * metrics_only ::
1108 * A boolean indicating that we only want to compute the metrics of a
1109 * given glyph, not load all of its points.
1110 *
1111 * hints_funcs ::
1112 * Auxiliary pointer for hinting.
1113 *
1114 * hints_globals ::
1115 * Auxiliary pointer for hinting.
1116 *
1117 * funcs ::
1118 * A table of method pointers for this object.
1119 */
1121 {
1122 FT_Memory memory;
1123 TT_Face face;
1124 CFF_GlyphSlot glyph;
1125 FT_GlyphLoader loader;
1126 FT_Outline* base;
1127 FT_Outline* current;
1128
1129 FT_Pos pos_x;
1130 FT_Pos pos_y;
1131
1132 FT_Vector left_bearing;
1133 FT_Vector advance;
1134
1135 FT_BBox bbox; /* bounding box */
1136
1137 FT_Bool path_begun;
1138 FT_Bool load_points;
1139 FT_Bool no_recurse;
1140
1141 FT_Bool metrics_only;
1142
1143 void* hints_funcs; /* hinter-specific */
1144 void* hints_globals; /* hinter-specific */
1145
1146 CFF_Builder_FuncsRec funcs;
1147 };
1148
1149
1150 /*************************************************************************/
1151 /*************************************************************************/
1152 /***** *****/
1153 /***** CFF DECODER *****/
1154 /***** *****/
1155 /*************************************************************************/
1156 /*************************************************************************/
1157
1158
1159#define CFF_MAX_OPERANDS 48
1160#define CFF_MAX_SUBRS_CALLS 16 /* maximum subroutine nesting; */
1161 /* only 10 are allowed but there exist */
1162 /* fonts like `HiraKakuProN-W3.ttf' */
1163 /* (Hiragino Kaku Gothic ProN W3; */
1164 /* 8.2d6e1; 2014-12-19) that exceed */
1165 /* this limit */
1166#define CFF_MAX_TRANS_ELEMENTS 32
1167
1168 /* execution context charstring zone */
1169
1170 typedef struct CFF_Decoder_Zone_
1171 {
1172 FT_Byte* base;
1173 FT_Byte* limit;
1174 FT_Byte* cursor;
1175
1176 } CFF_Decoder_Zone;
1177
1178
1179 typedef struct CFF_Decoder_
1180 {
1181 CFF_Builder builder;
1182 CFF_Font cff;
1183
1184 FT_Fixed stack[CFF_MAX_OPERANDS + 1];
1185 FT_Fixed* top;
1186
1187 CFF_Decoder_Zone zones[CFF_MAX_SUBRS_CALLS + 1];
1188 CFF_Decoder_Zone* zone;
1189
1190 FT_Int flex_state;
1191 FT_Int num_flex_vectors;
1192 FT_Vector flex_vectors[7];
1193
1194 FT_Pos glyph_width;
1195 FT_Pos nominal_width;
1196
1197 FT_Bool read_width;
1198 FT_Bool width_only;
1199 FT_Int num_hints;
1200 FT_Fixed buildchar[CFF_MAX_TRANS_ELEMENTS];
1201
1202 FT_UInt num_locals;
1203 FT_UInt num_globals;
1204
1205 FT_Int locals_bias;
1206 FT_Int globals_bias;
1207
1208 FT_Byte** locals;
1209 FT_Byte** globals;
1210
1211 FT_Byte** glyph_names; /* for pure CFF fonts only */
1212 FT_UInt num_glyphs; /* number of glyphs in font */
1213
1214 FT_Render_Mode hint_mode;
1215
1216 FT_Bool seac;
1217
1218 CFF_SubFont current_subfont; /* for current glyph_index */
1219
1220 CFF_Decoder_Get_Glyph_Callback get_glyph_callback;
1221 CFF_Decoder_Free_Glyph_Callback free_glyph_callback;
1222
1223 } CFF_Decoder;
1224
1225
1226 typedef const struct CFF_Decoder_FuncsRec_* CFF_Decoder_Funcs;
1227
1229 {
1230 void
1231 (*init)( CFF_Decoder* decoder,
1232 TT_Face face,
1233 CFF_Size size,
1234 CFF_GlyphSlot slot,
1235 FT_Bool hinting,
1236 FT_Render_Mode hint_mode,
1237 CFF_Decoder_Get_Glyph_Callback get_callback,
1238 CFF_Decoder_Free_Glyph_Callback free_callback );
1239
1240 FT_Error
1241 (*prepare)( CFF_Decoder* decoder,
1242 CFF_Size size,
1243 FT_UInt glyph_index );
1244
1245#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
1246 FT_Error
1247 (*parse_charstrings_old)( CFF_Decoder* decoder,
1248 FT_Byte* charstring_base,
1249 FT_ULong charstring_len,
1250 FT_Bool in_dict );
1251#endif
1252
1253 FT_Error
1254 (*parse_charstrings)( PS_Decoder* decoder,
1255 FT_Byte* charstring_base,
1256 FT_ULong charstring_len );
1257
1258 } CFF_Decoder_FuncsRec;
1259
1260
1261 /*************************************************************************/
1262 /*************************************************************************/
1263 /***** *****/
1264 /***** AFM PARSER *****/
1265 /***** *****/
1266 /*************************************************************************/
1267 /*************************************************************************/
1268
1269 typedef struct AFM_ParserRec_* AFM_Parser;
1270
1272 {
1273 FT_Error
1274 (*init)( AFM_Parser parser,
1275 FT_Memory memory,
1276 FT_Byte* base,
1277 FT_Byte* limit );
1278
1279 void
1280 (*done)( AFM_Parser parser );
1281
1282 FT_Error
1283 (*parse)( AFM_Parser parser );
1284
1285 } AFM_Parser_FuncsRec;
1286
1287
1288 typedef struct AFM_StreamRec_* AFM_Stream;
1289
1290
1291 /**************************************************************************
1292 *
1293 * @struct:
1294 * AFM_ParserRec
1295 *
1296 * @description:
1297 * An AFM_Parser is a parser for the AFM files.
1298 *
1299 * @fields:
1300 * memory ::
1301 * The object used for memory operations (alloc and realloc).
1302 *
1303 * stream ::
1304 * This is an opaque object.
1305 *
1306 * FontInfo ::
1307 * The result will be stored here.
1308 *
1309 * get_index ::
1310 * A user provided function to get a glyph index by its name.
1311 */
1312 typedef struct AFM_ParserRec_
1313 {
1314 FT_Memory memory;
1315 AFM_Stream stream;
1316
1317 AFM_FontInfo FontInfo;
1318
1319 FT_Int
1320 (*get_index)( const char* name,
1321 FT_Offset len,
1322 void* user_data );
1323
1324 void* user_data;
1325
1326 } AFM_ParserRec;
1327
1328
1329 /*************************************************************************/
1330 /*************************************************************************/
1331 /***** *****/
1332 /***** TYPE1 CHARMAPS *****/
1333 /***** *****/
1334 /*************************************************************************/
1335 /*************************************************************************/
1336
1337 typedef const struct T1_CMap_ClassesRec_* T1_CMap_Classes;
1338
1339 typedef struct T1_CMap_ClassesRec_
1340 {
1341 FT_CMap_Class standard;
1342 FT_CMap_Class expert;
1343 FT_CMap_Class custom;
1344 FT_CMap_Class unicode;
1345
1346 } T1_CMap_ClassesRec;
1347
1348
1349 /*************************************************************************/
1350 /*************************************************************************/
1351 /***** *****/
1352 /***** PSAux Module Interface *****/
1353 /***** *****/
1354 /*************************************************************************/
1355 /*************************************************************************/
1356
1357 typedef struct PSAux_ServiceRec_
1358 {
1359 /* don't use `PS_Table_Funcs' and friends to avoid compiler warnings */
1360 const PS_Table_FuncsRec* ps_table_funcs;
1361 const PS_Parser_FuncsRec* ps_parser_funcs;
1362 const T1_Builder_FuncsRec* t1_builder_funcs;
1363 const T1_Decoder_FuncsRec* t1_decoder_funcs;
1364
1365 void
1366 (*t1_decrypt)( FT_Byte* buffer,
1367 FT_Offset length,
1368 FT_UShort seed );
1369
1370 FT_UInt32
1371 (*cff_random)( FT_UInt32 r );
1372
1373 void
1374 (*ps_decoder_init)( PS_Decoder* ps_decoder,
1375 void* decoder,
1376 FT_Bool is_t1 );
1377
1378 void
1379 (*t1_make_subfont)( FT_Face face,
1380 PS_Private priv,
1381 CFF_SubFont subfont );
1382
1383 T1_CMap_Classes t1_cmap_classes;
1384
1385 /* fields after this comment line were added after version 2.1.10 */
1386 const AFM_Parser_FuncsRec* afm_parser_funcs;
1387
1388 const CFF_Decoder_FuncsRec* cff_decoder_funcs;
1389
1390 } PSAux_ServiceRec, *PSAux_Service;
1391
1392 /* backward compatible type definition */
1393 typedef PSAux_ServiceRec PSAux_Interface;
1394
1395
1396 /*************************************************************************/
1397 /*************************************************************************/
1398 /***** *****/
1399 /***** Some convenience functions *****/
1400 /***** *****/
1401 /*************************************************************************/
1402 /*************************************************************************/
1403
1404#define IS_PS_NEWLINE( ch ) \
1405 ( (ch) == '\r' || \
1406 (ch) == '\n' )
1407
1408#define IS_PS_SPACE( ch ) \
1409 ( (ch) == ' ' || \
1410 IS_PS_NEWLINE( ch ) || \
1411 (ch) == '\t' || \
1412 (ch) == '\f' || \
1413 (ch) == '\0' )
1414
1415#define IS_PS_SPECIAL( ch ) \
1416 ( (ch) == '/' || \
1417 (ch) == '(' || (ch) == ')' || \
1418 (ch) == '<' || (ch) == '>' || \
1419 (ch) == '[' || (ch) == ']' || \
1420 (ch) == '{' || (ch) == '}' || \
1421 (ch) == '%' )
1422
1423#define IS_PS_DELIM( ch ) \
1424 ( IS_PS_SPACE( ch ) || \
1425 IS_PS_SPECIAL( ch ) )
1426
1427#define IS_PS_DIGIT( ch ) \
1428 ( (ch) >= '0' && (ch) <= '9' )
1429
1430#define IS_PS_XDIGIT( ch ) \
1431 ( IS_PS_DIGIT( ch ) || \
1432 ( (ch) >= 'A' && (ch) <= 'F' ) || \
1433 ( (ch) >= 'a' && (ch) <= 'f' ) )
1434
1435#define IS_PS_BASE85( ch ) \
1436 ( (ch) >= '!' && (ch) <= 'u' )
1437
1438#define IS_PS_TOKEN( cur, limit, token ) \
1439 ( (char)(cur)[0] == (token)[0] && \
1440 ( (cur) + sizeof ( (token) ) == (limit) || \
1441 ( (cur) + sizeof( (token) ) < (limit) && \
1442 IS_PS_DELIM( (cur)[sizeof ( (token) ) - 1] ) ) ) && \
1443 ft_strncmp( (char*)(cur), (token), sizeof ( (token) ) - 1 ) == 0 )
1444
1445
1446FT_END_HEADER
1447
1448#endif /* PSAUX_H_ */
1449
1450
1451/* END */