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