• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ftobjs.h                                                               */
4 /*                                                                         */
5 /*    The FreeType private base classes (specification).                   */
6 /*                                                                         */
7 /*  Copyright 1996-2017 by                                                 */
8 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9 /*                                                                         */
10 /*  This file is part of the FreeType project, and may only be used,       */
11 /*  modified, and distributed under the terms of the FreeType project      */
12 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13 /*  this file you indicate that you have read the license and              */
14 /*  understand and accept it fully.                                        */
15 /*                                                                         */
16 /***************************************************************************/
17 
18 
19   /*************************************************************************/
20   /*                                                                       */
21   /*  This file contains the definition of all internal FreeType classes.  */
22   /*                                                                       */
23   /*************************************************************************/
24 
25 
26 #ifndef FTOBJS_H_
27 #define FTOBJS_H_
28 
29 #include <ft2build.h>
30 #include FT_RENDER_H
31 #include FT_SIZES_H
32 #include FT_LCD_FILTER_H
33 #include FT_INTERNAL_MEMORY_H
34 #include FT_INTERNAL_GLYPH_LOADER_H
35 #include FT_INTERNAL_DRIVER_H
36 #include FT_INTERNAL_AUTOHINT_H
37 #include FT_INTERNAL_SERVICE_H
38 #include FT_INTERNAL_PIC_H
39 
40 #ifdef FT_CONFIG_OPTION_INCREMENTAL
41 #include FT_INCREMENTAL_H
42 #endif
43 
44 
45 FT_BEGIN_HEADER
46 
47 
48   /*************************************************************************/
49   /*                                                                       */
50   /* Some generic definitions.                                             */
51   /*                                                                       */
52 #ifndef TRUE
53 #define TRUE  1
54 #endif
55 
56 #ifndef FALSE
57 #define FALSE  0
58 #endif
59 
60 #ifndef NULL
61 #define NULL  (void*)0
62 #endif
63 
64 
65   /*************************************************************************/
66   /*                                                                       */
67   /* The min and max functions missing in C.  As usual, be careful not to  */
68   /* write things like FT_MIN( a++, b++ ) to avoid side effects.           */
69   /*                                                                       */
70 #define FT_MIN( a, b )  ( (a) < (b) ? (a) : (b) )
71 #define FT_MAX( a, b )  ( (a) > (b) ? (a) : (b) )
72 
73 #define FT_ABS( a )     ( (a) < 0 ? -(a) : (a) )
74 
75   /*
76    *  Approximate sqrt(x*x+y*y) using the `alpha max plus beta min'
77    *  algorithm.  We use alpha = 1, beta = 3/8, giving us results with a
78    *  largest error less than 7% compared to the exact value.
79    */
80 #define FT_HYPOT( x, y )                 \
81           ( x = FT_ABS( x ),             \
82             y = FT_ABS( y ),             \
83             x > y ? x + ( 3 * y >> 3 )   \
84                   : y + ( 3 * x >> 3 ) )
85 
86   /* we use FT_TYPEOF to suppress signedness compilation warnings */
87 #define FT_PAD_FLOOR( x, n )  ( (x) & ~FT_TYPEOF( x )( (n)-1 ) )
88 #define FT_PAD_ROUND( x, n )  FT_PAD_FLOOR( (x) + ((n)/2), n )
89 #define FT_PAD_CEIL( x, n )   FT_PAD_FLOOR( (x) + ((n)-1), n )
90 
91 #define FT_PIX_FLOOR( x )     ( (x) & ~FT_TYPEOF( x )63 )
92 #define FT_PIX_ROUND( x )     FT_PIX_FLOOR( (x) + 32 )
93 #define FT_PIX_CEIL( x )      FT_PIX_FLOOR( (x) + 63 )
94 
95 
96   /*
97    *  character classification functions -- since these are used to parse
98    *  font files, we must not use those in <ctypes.h> which are
99    *  locale-dependent
100    */
101 #define  ft_isdigit( x )   ( ( (unsigned)(x) - '0' ) < 10U )
102 
103 #define  ft_isxdigit( x )  ( ( (unsigned)(x) - '0' ) < 10U || \
104                              ( (unsigned)(x) - 'a' ) < 6U  || \
105                              ( (unsigned)(x) - 'A' ) < 6U  )
106 
107   /* the next two macros assume ASCII representation */
108 #define  ft_isupper( x )  ( ( (unsigned)(x) - 'A' ) < 26U )
109 #define  ft_islower( x )  ( ( (unsigned)(x) - 'a' ) < 26U )
110 
111 #define  ft_isalpha( x )  ( ft_isupper( x ) || ft_islower( x ) )
112 #define  ft_isalnum( x )  ( ft_isdigit( x ) || ft_isalpha( x ) )
113 
114 
115   /*************************************************************************/
116   /*************************************************************************/
117   /*************************************************************************/
118   /****                                                                 ****/
119   /****                                                                 ****/
120   /****                       C H A R M A P S                           ****/
121   /****                                                                 ****/
122   /****                                                                 ****/
123   /*************************************************************************/
124   /*************************************************************************/
125   /*************************************************************************/
126 
127   /* handle to internal charmap object */
128   typedef struct FT_CMapRec_*              FT_CMap;
129 
130   /* handle to charmap class structure */
131   typedef const struct FT_CMap_ClassRec_*  FT_CMap_Class;
132 
133   /* internal charmap object structure */
134   typedef struct  FT_CMapRec_
135   {
136     FT_CharMapRec  charmap;
137     FT_CMap_Class  clazz;
138 
139   } FT_CMapRec;
140 
141   /* typecase any pointer to a charmap handle */
142 #define FT_CMAP( x )              ((FT_CMap)( x ))
143 
144   /* obvious macros */
145 #define FT_CMAP_PLATFORM_ID( x )  FT_CMAP( x )->charmap.platform_id
146 #define FT_CMAP_ENCODING_ID( x )  FT_CMAP( x )->charmap.encoding_id
147 #define FT_CMAP_ENCODING( x )     FT_CMAP( x )->charmap.encoding
148 #define FT_CMAP_FACE( x )         FT_CMAP( x )->charmap.face
149 
150 
151   /* class method definitions */
152   typedef FT_Error
153   (*FT_CMap_InitFunc)( FT_CMap     cmap,
154                        FT_Pointer  init_data );
155 
156   typedef void
157   (*FT_CMap_DoneFunc)( FT_CMap  cmap );
158 
159   typedef FT_UInt
160   (*FT_CMap_CharIndexFunc)( FT_CMap    cmap,
161                             FT_UInt32  char_code );
162 
163   typedef FT_UInt
164   (*FT_CMap_CharNextFunc)( FT_CMap     cmap,
165                            FT_UInt32  *achar_code );
166 
167   typedef FT_UInt
168   (*FT_CMap_CharVarIndexFunc)( FT_CMap    cmap,
169                                FT_CMap    unicode_cmap,
170                                FT_UInt32  char_code,
171                                FT_UInt32  variant_selector );
172 
173   typedef FT_Bool
174   (*FT_CMap_CharVarIsDefaultFunc)( FT_CMap    cmap,
175                                    FT_UInt32  char_code,
176                                    FT_UInt32  variant_selector );
177 
178   typedef FT_UInt32 *
179   (*FT_CMap_VariantListFunc)( FT_CMap    cmap,
180                               FT_Memory  mem );
181 
182   typedef FT_UInt32 *
183   (*FT_CMap_CharVariantListFunc)( FT_CMap    cmap,
184                                   FT_Memory  mem,
185                                   FT_UInt32  char_code );
186 
187   typedef FT_UInt32 *
188   (*FT_CMap_VariantCharListFunc)( FT_CMap    cmap,
189                                   FT_Memory  mem,
190                                   FT_UInt32  variant_selector );
191 
192 
193   typedef struct  FT_CMap_ClassRec_
194   {
195     FT_ULong               size;
196 
197     FT_CMap_InitFunc       init;
198     FT_CMap_DoneFunc       done;
199     FT_CMap_CharIndexFunc  char_index;
200     FT_CMap_CharNextFunc   char_next;
201 
202     /* Subsequent entries are special ones for format 14 -- the variant */
203     /* selector subtable which behaves like no other                    */
204 
205     FT_CMap_CharVarIndexFunc      char_var_index;
206     FT_CMap_CharVarIsDefaultFunc  char_var_default;
207     FT_CMap_VariantListFunc       variant_list;
208     FT_CMap_CharVariantListFunc   charvariant_list;
209     FT_CMap_VariantCharListFunc   variantchar_list;
210 
211   } FT_CMap_ClassRec;
212 
213 
214 #ifndef FT_CONFIG_OPTION_PIC
215 
216 #define FT_DECLARE_CMAP_CLASS( class_ )              \
217   FT_CALLBACK_TABLE const  FT_CMap_ClassRec class_;
218 
219 #define FT_DEFINE_CMAP_CLASS(       \
220           class_,                   \
221           size_,                    \
222           init_,                    \
223           done_,                    \
224           char_index_,              \
225           char_next_,               \
226           char_var_index_,          \
227           char_var_default_,        \
228           variant_list_,            \
229           charvariant_list_,        \
230           variantchar_list_ )       \
231   FT_CALLBACK_TABLE_DEF             \
232   const FT_CMap_ClassRec  class_ =  \
233   {                                 \
234     size_,                          \
235     init_,                          \
236     done_,                          \
237     char_index_,                    \
238     char_next_,                     \
239     char_var_index_,                \
240     char_var_default_,              \
241     variant_list_,                  \
242     charvariant_list_,              \
243     variantchar_list_               \
244   };
245 
246 #else /* FT_CONFIG_OPTION_PIC */
247 
248 #define FT_DECLARE_CMAP_CLASS( class_ )                  \
249   void                                                   \
250   FT_Init_Class_ ## class_( FT_Library         library,  \
251                             FT_CMap_ClassRec*  clazz );
252 
253 #define FT_DEFINE_CMAP_CLASS(                            \
254           class_,                                        \
255           size_,                                         \
256           init_,                                         \
257           done_,                                         \
258           char_index_,                                   \
259           char_next_,                                    \
260           char_var_index_,                               \
261           char_var_default_,                             \
262           variant_list_,                                 \
263           charvariant_list_,                             \
264           variantchar_list_ )                            \
265   void                                                   \
266   FT_Init_Class_ ## class_( FT_Library         library,  \
267                             FT_CMap_ClassRec*  clazz )   \
268   {                                                      \
269     FT_UNUSED( library );                                \
270                                                          \
271     clazz->size             = size_;                     \
272     clazz->init             = init_;                     \
273     clazz->done             = done_;                     \
274     clazz->char_index       = char_index_;               \
275     clazz->char_next        = char_next_;                \
276     clazz->char_var_index   = char_var_index_;           \
277     clazz->char_var_default = char_var_default_;         \
278     clazz->variant_list     = variant_list_;             \
279     clazz->charvariant_list = charvariant_list_;         \
280     clazz->variantchar_list = variantchar_list_;         \
281   }
282 
283 #endif /* FT_CONFIG_OPTION_PIC */
284 
285 
286   /* create a new charmap and add it to charmap->face */
287   FT_BASE( FT_Error )
288   FT_CMap_New( FT_CMap_Class  clazz,
289                FT_Pointer     init_data,
290                FT_CharMap     charmap,
291                FT_CMap       *acmap );
292 
293   /* destroy a charmap and remove it from face's list */
294   FT_BASE( void )
295   FT_CMap_Done( FT_CMap  cmap );
296 
297 
298   /*************************************************************************/
299   /*                                                                       */
300   /* <Struct>                                                              */
301   /*    FT_Face_InternalRec                                                */
302   /*                                                                       */
303   /* <Description>                                                         */
304   /*    This structure contains the internal fields of each FT_Face        */
305   /*    object.  These fields may change between different releases of     */
306   /*    FreeType.                                                          */
307   /*                                                                       */
308   /* <Fields>                                                              */
309   /*    max_points ::                                                      */
310   /*      The maximum number of points used to store the vectorial outline */
311   /*      of any glyph in this face.  If this value cannot be known in     */
312   /*      advance, or if the face isn't scalable, this should be set to 0. */
313   /*      Only relevant for scalable formats.                              */
314   /*                                                                       */
315   /*    max_contours ::                                                    */
316   /*      The maximum number of contours used to store the vectorial       */
317   /*      outline of any glyph in this face.  If this value cannot be      */
318   /*      known in advance, or if the face isn't scalable, this should be  */
319   /*      set to 0.  Only relevant for scalable formats.                   */
320   /*                                                                       */
321   /*    transform_matrix ::                                                */
322   /*      A 2x2 matrix of 16.16 coefficients used to transform glyph       */
323   /*      outlines after they are loaded from the font.  Only used by the  */
324   /*      convenience functions.                                           */
325   /*                                                                       */
326   /*    transform_delta ::                                                 */
327   /*      A translation vector used to transform glyph outlines after they */
328   /*      are loaded from the font.  Only used by the convenience          */
329   /*      functions.                                                       */
330   /*                                                                       */
331   /*    transform_flags ::                                                 */
332   /*      Some flags used to classify the transform.  Only used by the     */
333   /*      convenience functions.                                           */
334   /*                                                                       */
335   /*    services ::                                                        */
336   /*      A cache for frequently used services.  It should be only         */
337   /*      accessed with the macro `FT_FACE_LOOKUP_SERVICE'.                */
338   /*                                                                       */
339   /*    incremental_interface ::                                           */
340   /*      If non-null, the interface through which glyph data and metrics  */
341   /*      are loaded incrementally for faces that do not provide all of    */
342   /*      this data when first opened.  This field exists only if          */
343   /*      @FT_CONFIG_OPTION_INCREMENTAL is defined.                        */
344   /*                                                                       */
345   /*    refcount ::                                                        */
346   /*      A counter initialized to~1 at the time an @FT_Face structure is  */
347   /*      created.  @FT_Reference_Face increments this counter, and        */
348   /*      @FT_Done_Face only destroys a face if the counter is~1,          */
349   /*      otherwise it simply decrements it.                               */
350   /*                                                                       */
351   typedef struct  FT_Face_InternalRec_
352   {
353     FT_Matrix           transform_matrix;
354     FT_Vector           transform_delta;
355     FT_Int              transform_flags;
356 
357     FT_ServiceCacheRec  services;
358 
359 #ifdef FT_CONFIG_OPTION_INCREMENTAL
360     FT_Incremental_InterfaceRec*  incremental_interface;
361 #endif
362 
363     FT_Int              refcount;
364 
365   } FT_Face_InternalRec;
366 
367 
368   /*************************************************************************/
369   /*                                                                       */
370   /* <Struct>                                                              */
371   /*    FT_Slot_InternalRec                                                */
372   /*                                                                       */
373   /* <Description>                                                         */
374   /*    This structure contains the internal fields of each FT_GlyphSlot   */
375   /*    object.  These fields may change between different releases of     */
376   /*    FreeType.                                                          */
377   /*                                                                       */
378   /* <Fields>                                                              */
379   /*    loader            :: The glyph loader object used to load outlines */
380   /*                         into the glyph slot.                          */
381   /*                                                                       */
382   /*    flags             :: Possible values are zero or                   */
383   /*                         FT_GLYPH_OWN_BITMAP.  The latter indicates    */
384   /*                         that the FT_GlyphSlot structure owns the      */
385   /*                         bitmap buffer.                                */
386   /*                                                                       */
387   /*    glyph_transformed :: Boolean.  Set to TRUE when the loaded glyph   */
388   /*                         must be transformed through a specific        */
389   /*                         font transformation.  This is _not_ the same  */
390   /*                         as the face transform set through             */
391   /*                         FT_Set_Transform().                           */
392   /*                                                                       */
393   /*    glyph_matrix      :: The 2x2 matrix corresponding to the glyph     */
394   /*                         transformation, if necessary.                 */
395   /*                                                                       */
396   /*    glyph_delta       :: The 2d translation vector corresponding to    */
397   /*                         the glyph transformation, if necessary.       */
398   /*                                                                       */
399   /*    glyph_hints       :: Format-specific glyph hints management.       */
400   /*                                                                       */
401 
402 #define FT_GLYPH_OWN_BITMAP  0x1U
403 
404   typedef struct  FT_Slot_InternalRec_
405   {
406     FT_GlyphLoader  loader;
407     FT_UInt         flags;
408     FT_Bool         glyph_transformed;
409     FT_Matrix       glyph_matrix;
410     FT_Vector       glyph_delta;
411     void*           glyph_hints;
412 
413   } FT_GlyphSlot_InternalRec;
414 
415 
416 #if 0
417 
418   /*************************************************************************/
419   /*                                                                       */
420   /* <Struct>                                                              */
421   /*    FT_Size_InternalRec                                                */
422   /*                                                                       */
423   /* <Description>                                                         */
424   /*    This structure contains the internal fields of each FT_Size        */
425   /*    object.  Currently, it's empty.                                    */
426   /*                                                                       */
427   /*************************************************************************/
428 
429   typedef struct  FT_Size_InternalRec_
430   {
431     /* empty */
432 
433   } FT_Size_InternalRec;
434 
435 #endif
436 
437 
438   /*************************************************************************/
439   /*************************************************************************/
440   /*************************************************************************/
441   /****                                                                 ****/
442   /****                                                                 ****/
443   /****                         M O D U L E S                           ****/
444   /****                                                                 ****/
445   /****                                                                 ****/
446   /*************************************************************************/
447   /*************************************************************************/
448   /*************************************************************************/
449 
450 
451   /*************************************************************************/
452   /*                                                                       */
453   /* <Struct>                                                              */
454   /*    FT_ModuleRec                                                       */
455   /*                                                                       */
456   /* <Description>                                                         */
457   /*    A module object instance.                                          */
458   /*                                                                       */
459   /* <Fields>                                                              */
460   /*    clazz   :: A pointer to the module's class.                        */
461   /*                                                                       */
462   /*    library :: A handle to the parent library object.                  */
463   /*                                                                       */
464   /*    memory  :: A handle to the memory manager.                         */
465   /*                                                                       */
466   typedef struct  FT_ModuleRec_
467   {
468     FT_Module_Class*  clazz;
469     FT_Library        library;
470     FT_Memory         memory;
471 
472   } FT_ModuleRec;
473 
474 
475   /* typecast an object to an FT_Module */
476 #define FT_MODULE( x )          ((FT_Module)( x ))
477 #define FT_MODULE_CLASS( x )    FT_MODULE( x )->clazz
478 #define FT_MODULE_LIBRARY( x )  FT_MODULE( x )->library
479 #define FT_MODULE_MEMORY( x )   FT_MODULE( x )->memory
480 
481 
482 #define FT_MODULE_IS_DRIVER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
483                                     FT_MODULE_FONT_DRIVER )
484 
485 #define FT_MODULE_IS_RENDERER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
486                                       FT_MODULE_RENDERER )
487 
488 #define FT_MODULE_IS_HINTER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
489                                     FT_MODULE_HINTER )
490 
491 #define FT_MODULE_IS_STYLER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
492                                     FT_MODULE_STYLER )
493 
494 #define FT_DRIVER_IS_SCALABLE( x )  ( FT_MODULE_CLASS( x )->module_flags & \
495                                       FT_MODULE_DRIVER_SCALABLE )
496 
497 #define FT_DRIVER_USES_OUTLINES( x )  !( FT_MODULE_CLASS( x )->module_flags & \
498                                          FT_MODULE_DRIVER_NO_OUTLINES )
499 
500 #define FT_DRIVER_HAS_HINTER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
501                                      FT_MODULE_DRIVER_HAS_HINTER )
502 
503 #define FT_DRIVER_HINTS_LIGHTLY( x )  ( FT_MODULE_CLASS( x )->module_flags & \
504                                         FT_MODULE_DRIVER_HINTS_LIGHTLY )
505 
506 
507   /*************************************************************************/
508   /*                                                                       */
509   /* <Function>                                                            */
510   /*    FT_Get_Module_Interface                                            */
511   /*                                                                       */
512   /* <Description>                                                         */
513   /*    Finds a module and returns its specific interface as a typeless    */
514   /*    pointer.                                                           */
515   /*                                                                       */
516   /* <Input>                                                               */
517   /*    library     :: A handle to the library object.                     */
518   /*                                                                       */
519   /*    module_name :: The module's name (as an ASCII string).             */
520   /*                                                                       */
521   /* <Return>                                                              */
522   /*    A module-specific interface if available, 0 otherwise.             */
523   /*                                                                       */
524   /* <Note>                                                                */
525   /*    You should better be familiar with FreeType internals to know      */
526   /*    which module to look for, and what its interface is :-)            */
527   /*                                                                       */
528   FT_BASE( const void* )
529   FT_Get_Module_Interface( FT_Library   library,
530                            const char*  mod_name );
531 
532   FT_BASE( FT_Pointer )
533   ft_module_get_service( FT_Module    module,
534                          const char*  service_id,
535                          FT_Bool      global );
536 
537 #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
538   FT_BASE( FT_Error )
539   ft_property_string_set( FT_Library        library,
540                           const FT_String*  module_name,
541                           const FT_String*  property_name,
542                           FT_String*        value );
543 #endif
544 
545   /* */
546 
547 
548   /*************************************************************************/
549   /*************************************************************************/
550   /*************************************************************************/
551   /****                                                                 ****/
552   /****                                                                 ****/
553   /****   F A C E,   S I Z E   &   G L Y P H   S L O T   O B J E C T S  ****/
554   /****                                                                 ****/
555   /****                                                                 ****/
556   /*************************************************************************/
557   /*************************************************************************/
558   /*************************************************************************/
559 
560   /* a few macros used to perform easy typecasts with minimal brain damage */
561 
562 #define FT_FACE( x )          ((FT_Face)(x))
563 #define FT_SIZE( x )          ((FT_Size)(x))
564 #define FT_SLOT( x )          ((FT_GlyphSlot)(x))
565 
566 #define FT_FACE_DRIVER( x )   FT_FACE( x )->driver
567 #define FT_FACE_LIBRARY( x )  FT_FACE_DRIVER( x )->root.library
568 #define FT_FACE_MEMORY( x )   FT_FACE( x )->memory
569 #define FT_FACE_STREAM( x )   FT_FACE( x )->stream
570 
571 #define FT_SIZE_FACE( x )     FT_SIZE( x )->face
572 #define FT_SLOT_FACE( x )     FT_SLOT( x )->face
573 
574 #define FT_FACE_SLOT( x )     FT_FACE( x )->glyph
575 #define FT_FACE_SIZE( x )     FT_FACE( x )->size
576 
577 
578   /*************************************************************************/
579   /*                                                                       */
580   /* <Function>                                                            */
581   /*    FT_New_GlyphSlot                                                   */
582   /*                                                                       */
583   /* <Description>                                                         */
584   /*    It is sometimes useful to have more than one glyph slot for a      */
585   /*    given face object.  This function is used to create additional     */
586   /*    slots.  All of them are automatically discarded when the face is   */
587   /*    destroyed.                                                         */
588   /*                                                                       */
589   /* <Input>                                                               */
590   /*    face  :: A handle to a parent face object.                         */
591   /*                                                                       */
592   /* <Output>                                                              */
593   /*    aslot :: A handle to a new glyph slot object.                      */
594   /*                                                                       */
595   /* <Return>                                                              */
596   /*    FreeType error code.  0 means success.                             */
597   /*                                                                       */
598   FT_BASE( FT_Error )
599   FT_New_GlyphSlot( FT_Face        face,
600                     FT_GlyphSlot  *aslot );
601 
602 
603   /*************************************************************************/
604   /*                                                                       */
605   /* <Function>                                                            */
606   /*    FT_Done_GlyphSlot                                                  */
607   /*                                                                       */
608   /* <Description>                                                         */
609   /*    Destroys a given glyph slot.  Remember however that all slots are  */
610   /*    automatically destroyed with its parent.  Using this function is   */
611   /*    not always mandatory.                                              */
612   /*                                                                       */
613   /* <Input>                                                               */
614   /*    slot :: A handle to a target glyph slot.                           */
615   /*                                                                       */
616   FT_BASE( void )
617   FT_Done_GlyphSlot( FT_GlyphSlot  slot );
618 
619  /* */
620 
621 #define FT_REQUEST_WIDTH( req )                                            \
622           ( (req)->horiResolution                                          \
623               ? ( (req)->width * (FT_Pos)(req)->horiResolution + 36 ) / 72 \
624               : (req)->width )
625 
626 #define FT_REQUEST_HEIGHT( req )                                            \
627           ( (req)->vertResolution                                           \
628               ? ( (req)->height * (FT_Pos)(req)->vertResolution + 36 ) / 72 \
629               : (req)->height )
630 
631 
632   /* Set the metrics according to a bitmap strike. */
633   FT_BASE( void )
634   FT_Select_Metrics( FT_Face   face,
635                      FT_ULong  strike_index );
636 
637 
638   /* Set the metrics according to a size request. */
639   FT_BASE( void )
640   FT_Request_Metrics( FT_Face          face,
641                       FT_Size_Request  req );
642 
643 
644   /* Match a size request against `available_sizes'. */
645   FT_BASE( FT_Error )
646   FT_Match_Size( FT_Face          face,
647                  FT_Size_Request  req,
648                  FT_Bool          ignore_width,
649                  FT_ULong*        size_index );
650 
651 
652   /* Use the horizontal metrics to synthesize the vertical metrics. */
653   /* If `advance' is zero, it is also synthesized.                  */
654   FT_BASE( void )
655   ft_synthesize_vertical_metrics( FT_Glyph_Metrics*  metrics,
656                                   FT_Pos             advance );
657 
658 
659   /* Free the bitmap of a given glyphslot when needed (i.e., only when it */
660   /* was allocated with ft_glyphslot_alloc_bitmap).                       */
661   FT_BASE( void )
662   ft_glyphslot_free_bitmap( FT_GlyphSlot  slot );
663 
664 
665   /* Allocate a new bitmap buffer in a glyph slot. */
666   FT_BASE( FT_Error )
667   ft_glyphslot_alloc_bitmap( FT_GlyphSlot  slot,
668                              FT_ULong      size );
669 
670 
671   /* Set the bitmap buffer in a glyph slot to a given pointer.  The buffer */
672   /* will not be freed by a later call to ft_glyphslot_free_bitmap.        */
673   FT_BASE( void )
674   ft_glyphslot_set_bitmap( FT_GlyphSlot  slot,
675                            FT_Byte*      buffer );
676 
677 
678   /*************************************************************************/
679   /*************************************************************************/
680   /*************************************************************************/
681   /****                                                                 ****/
682   /****                                                                 ****/
683   /****                        R E N D E R E R S                        ****/
684   /****                                                                 ****/
685   /****                                                                 ****/
686   /*************************************************************************/
687   /*************************************************************************/
688   /*************************************************************************/
689 
690 
691 #define FT_RENDERER( x )      ((FT_Renderer)( x ))
692 #define FT_GLYPH( x )         ((FT_Glyph)( x ))
693 #define FT_BITMAP_GLYPH( x )  ((FT_BitmapGlyph)( x ))
694 #define FT_OUTLINE_GLYPH( x ) ((FT_OutlineGlyph)( x ))
695 
696 
697   typedef struct  FT_RendererRec_
698   {
699     FT_ModuleRec            root;
700     FT_Renderer_Class*      clazz;
701     FT_Glyph_Format         glyph_format;
702     FT_Glyph_Class          glyph_class;
703 
704     FT_Raster               raster;
705     FT_Raster_Render_Func   raster_render;
706     FT_Renderer_RenderFunc  render;
707 
708   } FT_RendererRec;
709 
710 
711   /*************************************************************************/
712   /*************************************************************************/
713   /*************************************************************************/
714   /****                                                                 ****/
715   /****                                                                 ****/
716   /****                    F O N T   D R I V E R S                      ****/
717   /****                                                                 ****/
718   /****                                                                 ****/
719   /*************************************************************************/
720   /*************************************************************************/
721   /*************************************************************************/
722 
723 
724   /* typecast a module into a driver easily */
725 #define FT_DRIVER( x )        ((FT_Driver)(x))
726 
727   /* typecast a module as a driver, and get its driver class */
728 #define FT_DRIVER_CLASS( x )  FT_DRIVER( x )->clazz
729 
730 
731   /*************************************************************************/
732   /*                                                                       */
733   /* <Struct>                                                              */
734   /*    FT_DriverRec                                                       */
735   /*                                                                       */
736   /* <Description>                                                         */
737   /*    The root font driver class.  A font driver is responsible for      */
738   /*    managing and loading font files of a given format.                 */
739   /*                                                                       */
740   /*  <Fields>                                                             */
741   /*     root         :: Contains the fields of the root module class.     */
742   /*                                                                       */
743   /*     clazz        :: A pointer to the font driver's class.  Note that  */
744   /*                     this is NOT root.clazz.  `class' wasn't used      */
745   /*                     as it is a reserved word in C++.                  */
746   /*                                                                       */
747   /*     faces_list   :: The list of faces currently opened by this        */
748   /*                     driver.                                           */
749   /*                                                                       */
750   /*     glyph_loader :: Unused.  Used to be glyph loader for all faces    */
751   /*                     managed by this driver.                           */
752   /*                                                                       */
753   typedef struct  FT_DriverRec_
754   {
755     FT_ModuleRec     root;
756     FT_Driver_Class  clazz;
757     FT_ListRec       faces_list;
758     FT_GlyphLoader   glyph_loader;
759 
760   } FT_DriverRec;
761 
762 
763   /*************************************************************************/
764   /*************************************************************************/
765   /*************************************************************************/
766   /****                                                                 ****/
767   /****                                                                 ****/
768   /****                       L I B R A R I E S                         ****/
769   /****                                                                 ****/
770   /****                                                                 ****/
771   /*************************************************************************/
772   /*************************************************************************/
773   /*************************************************************************/
774 
775 
776   /* This hook is used by the TrueType debugger.  It must be set to an */
777   /* alternate truetype bytecode interpreter function.                 */
778 #define FT_DEBUG_HOOK_TRUETYPE            0
779 
780 
781   typedef void  (*FT_Bitmap_LcdFilterFunc)( FT_Bitmap*      bitmap,
782                                             FT_Render_Mode  render_mode,
783                                             FT_Library      library );
784 
785 
786   /*************************************************************************/
787   /*                                                                       */
788   /* <Struct>                                                              */
789   /*    FT_LibraryRec                                                      */
790   /*                                                                       */
791   /* <Description>                                                         */
792   /*    The FreeType library class.  This is the root of all FreeType      */
793   /*    data.  Use FT_New_Library() to create a library object, and        */
794   /*    FT_Done_Library() to discard it and all child objects.             */
795   /*                                                                       */
796   /* <Fields>                                                              */
797   /*    memory           :: The library's memory object.  Manages memory   */
798   /*                        allocation.                                    */
799   /*                                                                       */
800   /*    version_major    :: The major version number of the library.       */
801   /*                                                                       */
802   /*    version_minor    :: The minor version number of the library.       */
803   /*                                                                       */
804   /*    version_patch    :: The current patch level of the library.        */
805   /*                                                                       */
806   /*    num_modules      :: The number of modules currently registered     */
807   /*                        within this library.  This is set to 0 for new */
808   /*                        libraries.  New modules are added through the  */
809   /*                        FT_Add_Module() API function.                  */
810   /*                                                                       */
811   /*    modules          :: A table used to store handles to the currently */
812   /*                        registered modules. Note that each font driver */
813   /*                        contains a list of its opened faces.           */
814   /*                                                                       */
815   /*    renderers        :: The list of renderers currently registered     */
816   /*                        within the library.                            */
817   /*                                                                       */
818   /*    cur_renderer     :: The current outline renderer.  This is a       */
819   /*                        shortcut used to avoid parsing the list on     */
820   /*                        each call to FT_Outline_Render().  It is a     */
821   /*                        handle to the current renderer for the         */
822   /*                        FT_GLYPH_FORMAT_OUTLINE format.                */
823   /*                                                                       */
824   /*    auto_hinter      :: XXX                                            */
825   /*                                                                       */
826   /*    raster_pool      :: The raster object's render pool.  This can     */
827   /*                        ideally be changed dynamically at run-time.    */
828   /*                                                                       */
829   /*    raster_pool_size :: The size of the render pool in bytes.          */
830   /*                                                                       */
831   /*    debug_hooks      :: XXX                                            */
832   /*                                                                       */
833   /*    lcd_filter       :: If subpixel rendering is activated, the        */
834   /*                        selected LCD filter mode.                      */
835   /*                                                                       */
836   /*    lcd_extra        :: If subpixel rendering is activated, the number */
837   /*                        of extra pixels needed for the LCD filter.     */
838   /*                                                                       */
839   /*    lcd_weights      :: If subpixel rendering is activated, the LCD    */
840   /*                        filter weights, if any.                        */
841   /*                                                                       */
842   /*    lcd_filter_func  :: If subpixel rendering is activated, the LCD    */
843   /*                        filtering callback function.                   */
844   /*                                                                       */
845   /*    pic_container    :: Contains global structs and tables, instead    */
846   /*                        of defining them globally.                     */
847   /*                                                                       */
848   /*    refcount         :: A counter initialized to~1 at the time an      */
849   /*                        @FT_Library structure is created.              */
850   /*                        @FT_Reference_Library increments this counter, */
851   /*                        and @FT_Done_Library only destroys a library   */
852   /*                        if the counter is~1, otherwise it simply       */
853   /*                        decrements it.                                 */
854   /*                                                                       */
855   typedef struct  FT_LibraryRec_
856   {
857     FT_Memory          memory;           /* library's memory manager */
858 
859     FT_Int             version_major;
860     FT_Int             version_minor;
861     FT_Int             version_patch;
862 
863     FT_UInt            num_modules;
864     FT_Module          modules[FT_MAX_MODULES];  /* module objects  */
865 
866     FT_ListRec         renderers;        /* list of renderers        */
867     FT_Renderer        cur_renderer;     /* current outline renderer */
868     FT_Module          auto_hinter;
869 
870     FT_Byte*           raster_pool;      /* scan-line conversion */
871                                          /* render pool          */
872     FT_ULong           raster_pool_size; /* size of render pool in bytes */
873 
874     FT_DebugHook_Func  debug_hooks[4];
875 
876 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
877     FT_LcdFilter             lcd_filter;
878     FT_Int                   lcd_extra;        /* number of extra pixels */
879     FT_Byte                  lcd_weights[5];   /* filter weights, if any */
880     FT_Bitmap_LcdFilterFunc  lcd_filter_func;  /* filtering callback     */
881 #endif
882 
883 #ifdef FT_CONFIG_OPTION_PIC
884     FT_PIC_Container   pic_container;
885 #endif
886 
887     FT_Int             refcount;
888 
889   } FT_LibraryRec;
890 
891 
892   FT_BASE( FT_Renderer )
893   FT_Lookup_Renderer( FT_Library       library,
894                       FT_Glyph_Format  format,
895                       FT_ListNode*     node );
896 
897   FT_BASE( FT_Error )
898   FT_Render_Glyph_Internal( FT_Library      library,
899                             FT_GlyphSlot    slot,
900                             FT_Render_Mode  render_mode );
901 
902   typedef const char*
903   (*FT_Face_GetPostscriptNameFunc)( FT_Face  face );
904 
905   typedef FT_Error
906   (*FT_Face_GetGlyphNameFunc)( FT_Face     face,
907                                FT_UInt     glyph_index,
908                                FT_Pointer  buffer,
909                                FT_UInt     buffer_max );
910 
911   typedef FT_UInt
912   (*FT_Face_GetGlyphNameIndexFunc)( FT_Face     face,
913                                     FT_String*  glyph_name );
914 
915 
916 #ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
917 
918   /*************************************************************************/
919   /*                                                                       */
920   /* <Function>                                                            */
921   /*    FT_New_Memory                                                      */
922   /*                                                                       */
923   /* <Description>                                                         */
924   /*    Creates a new memory object.                                       */
925   /*                                                                       */
926   /* <Return>                                                              */
927   /*    A pointer to the new memory object.  0 in case of error.           */
928   /*                                                                       */
929   FT_BASE( FT_Memory )
930   FT_New_Memory( void );
931 
932 
933   /*************************************************************************/
934   /*                                                                       */
935   /* <Function>                                                            */
936   /*    FT_Done_Memory                                                     */
937   /*                                                                       */
938   /* <Description>                                                         */
939   /*    Discards memory manager.                                           */
940   /*                                                                       */
941   /* <Input>                                                               */
942   /*    memory :: A handle to the memory manager.                          */
943   /*                                                                       */
944   FT_BASE( void )
945   FT_Done_Memory( FT_Memory  memory );
946 
947 #endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */
948 
949 
950   /* Define default raster's interface.  The default raster is located in  */
951   /* `src/base/ftraster.c'.                                                */
952   /*                                                                       */
953   /* Client applications can register new rasters through the              */
954   /* FT_Set_Raster() API.                                                  */
955 
956 #ifndef FT_NO_DEFAULT_RASTER
957   FT_EXPORT_VAR( FT_Raster_Funcs )  ft_default_raster;
958 #endif
959 
960 
961   /*************************************************************************/
962   /*************************************************************************/
963   /*************************************************************************/
964   /****                                                                 ****/
965   /****                                                                 ****/
966   /****                      P I C   S U P P O R T                      ****/
967   /****                                                                 ****/
968   /****                                                                 ****/
969   /*************************************************************************/
970   /*************************************************************************/
971   /*************************************************************************/
972 
973 
974   /* PIC support macros for ftimage.h */
975 
976 
977   /*************************************************************************/
978   /*                                                                       */
979   /* <Macro>                                                               */
980   /*    FT_DEFINE_OUTLINE_FUNCS                                            */
981   /*                                                                       */
982   /* <Description>                                                         */
983   /*    Used to initialize an instance of FT_Outline_Funcs struct.         */
984   /*    When FT_CONFIG_OPTION_PIC is defined an init function will need    */
985   /*    to be called with a pre-allocated structure to be filled.          */
986   /*    When FT_CONFIG_OPTION_PIC is not defined the struct will be        */
987   /*    allocated in the global scope (or the scope where the macro        */
988   /*    is used).                                                          */
989   /*                                                                       */
990 #ifndef FT_CONFIG_OPTION_PIC
991 
992 #define FT_DEFINE_OUTLINE_FUNCS(           \
993           class_,                          \
994           move_to_,                        \
995           line_to_,                        \
996           conic_to_,                       \
997           cubic_to_,                       \
998           shift_,                          \
999           delta_ )                         \
1000   static const  FT_Outline_Funcs class_ =  \
1001   {                                        \
1002     move_to_,                              \
1003     line_to_,                              \
1004     conic_to_,                             \
1005     cubic_to_,                             \
1006     shift_,                                \
1007     delta_                                 \
1008   };
1009 
1010 #else /* FT_CONFIG_OPTION_PIC */
1011 
1012 #define FT_DEFINE_OUTLINE_FUNCS(                     \
1013           class_,                                    \
1014           move_to_,                                  \
1015           line_to_,                                  \
1016           conic_to_,                                 \
1017           cubic_to_,                                 \
1018           shift_,                                    \
1019           delta_ )                                   \
1020   static FT_Error                                    \
1021   Init_Class_ ## class_( FT_Outline_Funcs*  clazz )  \
1022   {                                                  \
1023     clazz->move_to  = move_to_;                      \
1024     clazz->line_to  = line_to_;                      \
1025     clazz->conic_to = conic_to_;                     \
1026     clazz->cubic_to = cubic_to_;                     \
1027     clazz->shift    = shift_;                        \
1028     clazz->delta    = delta_;                        \
1029                                                      \
1030     return FT_Err_Ok;                                \
1031   }
1032 
1033 #endif /* FT_CONFIG_OPTION_PIC */
1034 
1035 
1036   /*************************************************************************/
1037   /*                                                                       */
1038   /* <Macro>                                                               */
1039   /*    FT_DEFINE_RASTER_FUNCS                                             */
1040   /*                                                                       */
1041   /* <Description>                                                         */
1042   /*    Used to initialize an instance of FT_Raster_Funcs struct.          */
1043   /*    When FT_CONFIG_OPTION_PIC is defined an init function will need    */
1044   /*    to be called with a pre-allocated structure to be filled.          */
1045   /*    When FT_CONFIG_OPTION_PIC is not defined the struct will be        */
1046   /*    allocated in the global scope (or the scope where the macro        */
1047   /*    is used).                                                          */
1048   /*                                                                       */
1049 #ifndef FT_CONFIG_OPTION_PIC
1050 
1051 #define FT_DEFINE_RASTER_FUNCS(    \
1052           class_,                  \
1053           glyph_format_,           \
1054           raster_new_,             \
1055           raster_reset_,           \
1056           raster_set_mode_,        \
1057           raster_render_,          \
1058           raster_done_ )           \
1059   const FT_Raster_Funcs  class_ =  \
1060   {                                \
1061     glyph_format_,                 \
1062     raster_new_,                   \
1063     raster_reset_,                 \
1064     raster_set_mode_,              \
1065     raster_render_,                \
1066     raster_done_                   \
1067   };
1068 
1069 #else /* FT_CONFIG_OPTION_PIC */
1070 
1071 #define FT_DEFINE_RASTER_FUNCS(                        \
1072           class_,                                      \
1073           glyph_format_,                               \
1074           raster_new_,                                 \
1075           raster_reset_,                               \
1076           raster_set_mode_,                            \
1077           raster_render_,                              \
1078           raster_done_ )                               \
1079   void                                                 \
1080   FT_Init_Class_ ## class_( FT_Raster_Funcs*  clazz )  \
1081   {                                                    \
1082     clazz->glyph_format    = glyph_format_;            \
1083     clazz->raster_new      = raster_new_;              \
1084     clazz->raster_reset    = raster_reset_;            \
1085     clazz->raster_set_mode = raster_set_mode_;         \
1086     clazz->raster_render   = raster_render_;           \
1087     clazz->raster_done     = raster_done_;             \
1088   }
1089 
1090 #endif /* FT_CONFIG_OPTION_PIC */
1091 
1092 
1093   /* PIC support macros for ftrender.h */
1094 
1095 
1096   /*************************************************************************/
1097   /*                                                                       */
1098   /* <Macro>                                                               */
1099   /*    FT_DEFINE_GLYPH                                                    */
1100   /*                                                                       */
1101   /* <Description>                                                         */
1102   /*    Used to initialize an instance of FT_Glyph_Class struct.           */
1103   /*    When FT_CONFIG_OPTION_PIC is defined an init function will need    */
1104   /*    to be called with a pre-allocated structure to be filled.          */
1105   /*    When FT_CONFIG_OPTION_PIC is not defined the struct will be        */
1106   /*    allocated in the global scope (or the scope where the macro        */
1107   /*    is used).                                                          */
1108   /*                                                                       */
1109 #ifndef FT_CONFIG_OPTION_PIC
1110 
1111 #define FT_DEFINE_GLYPH(          \
1112           class_,                 \
1113           size_,                  \
1114           format_,                \
1115           init_,                  \
1116           done_,                  \
1117           copy_,                  \
1118           transform_,             \
1119           bbox_,                  \
1120           prepare_ )              \
1121   FT_CALLBACK_TABLE_DEF           \
1122   const FT_Glyph_Class  class_ =  \
1123   {                               \
1124     size_,                        \
1125     format_,                      \
1126     init_,                        \
1127     done_,                        \
1128     copy_,                        \
1129     transform_,                   \
1130     bbox_,                        \
1131     prepare_                      \
1132   };
1133 
1134 #else /* FT_CONFIG_OPTION_PIC */
1135 
1136 #define FT_DEFINE_GLYPH(                              \
1137           class_,                                     \
1138           size_,                                      \
1139           format_,                                    \
1140           init_,                                      \
1141           done_,                                      \
1142           copy_,                                      \
1143           transform_,                                 \
1144           bbox_,                                      \
1145           prepare_ )                                  \
1146   void                                                \
1147   FT_Init_Class_ ## class_( FT_Glyph_Class*  clazz )  \
1148   {                                                   \
1149     clazz->glyph_size      = size_;                   \
1150     clazz->glyph_format    = format_;                 \
1151     clazz->glyph_init      = init_;                   \
1152     clazz->glyph_done      = done_;                   \
1153     clazz->glyph_copy      = copy_;                   \
1154     clazz->glyph_transform = transform_;              \
1155     clazz->glyph_bbox      = bbox_;                   \
1156     clazz->glyph_prepare   = prepare_;                \
1157   }
1158 
1159 #endif /* FT_CONFIG_OPTION_PIC */
1160 
1161 
1162   /*************************************************************************/
1163   /*                                                                       */
1164   /* <Macro>                                                               */
1165   /*    FT_DECLARE_RENDERER                                                */
1166   /*                                                                       */
1167   /* <Description>                                                         */
1168   /*    Used to create a forward declaration of a                          */
1169   /*    FT_Renderer_Class struct instance.                                 */
1170   /*                                                                       */
1171   /* <Macro>                                                               */
1172   /*    FT_DEFINE_RENDERER                                                 */
1173   /*                                                                       */
1174   /* <Description>                                                         */
1175   /*    Used to initialize an instance of FT_Renderer_Class struct.        */
1176   /*                                                                       */
1177   /*    When FT_CONFIG_OPTION_PIC is defined a `create' function will      */
1178   /*    need to be called with a pointer where the allocated structure is  */
1179   /*    returned.  And when it is no longer needed a `destroy' function    */
1180   /*    needs to be called to release that allocation.                     */
1181   /*    `ftinit.c' (ft_create_default_module_classes) already contains     */
1182   /*    a mechanism to call these functions for the default modules        */
1183   /*    described in `ftmodule.h'.                                         */
1184   /*                                                                       */
1185   /*    Notice that the created `create' and `destroy' functions call      */
1186   /*    `pic_init' and `pic_free' to allow you to manually allocate and    */
1187   /*    initialize any additional global data, like a module specific      */
1188   /*    interface, and put them in the global pic container defined in     */
1189   /*    `ftpic.h'.  If you don't need them just implement the functions as */
1190   /*    empty to resolve the link error.  Also the `pic_init' and          */
1191   /*    `pic_free' functions should be declared in `pic.h', to be referred */
1192   /*    by the renderer definition calling `FT_DEFINE_RENDERER' in the     */
1193   /*    following.                                                         */
1194   /*                                                                       */
1195   /*    When FT_CONFIG_OPTION_PIC is not defined the struct will be        */
1196   /*    allocated in the global scope (or the scope where the macro        */
1197   /*    is used).                                                          */
1198   /*                                                                       */
1199 #ifndef FT_CONFIG_OPTION_PIC
1200 
1201 #define FT_DECLARE_RENDERER( class_ )               \
1202   FT_EXPORT_VAR( const FT_Renderer_Class ) class_;
1203 
1204 #define FT_DEFINE_RENDERER(                  \
1205           class_,                            \
1206           flags_,                            \
1207           size_,                             \
1208           name_,                             \
1209           version_,                          \
1210           requires_,                         \
1211           interface_,                        \
1212           init_,                             \
1213           done_,                             \
1214           get_interface_,                    \
1215           glyph_format_,                     \
1216           render_glyph_,                     \
1217           transform_glyph_,                  \
1218           get_glyph_cbox_,                   \
1219           set_mode_,                         \
1220           raster_class_ )                    \
1221   FT_CALLBACK_TABLE_DEF                      \
1222   const FT_Renderer_Class  class_ =          \
1223   {                                          \
1224     FT_DEFINE_ROOT_MODULE( flags_,           \
1225                            size_,            \
1226                            name_,            \
1227                            version_,         \
1228                            requires_,        \
1229                            interface_,       \
1230                            init_,            \
1231                            done_,            \
1232                            get_interface_ )  \
1233     glyph_format_,                           \
1234                                              \
1235     render_glyph_,                           \
1236     transform_glyph_,                        \
1237     get_glyph_cbox_,                         \
1238     set_mode_,                               \
1239                                              \
1240     raster_class_                            \
1241   };
1242 
1243 #else /* FT_CONFIG_OPTION_PIC */
1244 
1245 #define FT_DECLARE_RENDERER( class_ )  FT_DECLARE_MODULE( class_ )
1246 
1247 #define FT_DEFINE_RENDERER(                                      \
1248           class_,                                                \
1249           flags_,                                                \
1250           size_,                                                 \
1251           name_,                                                 \
1252           version_,                                              \
1253           requires_,                                             \
1254           interface_,                                            \
1255           init_,                                                 \
1256           done_,                                                 \
1257           get_interface_,                                        \
1258           glyph_format_,                                         \
1259           render_glyph_,                                         \
1260           transform_glyph_,                                      \
1261           get_glyph_cbox_,                                       \
1262           set_mode_,                                             \
1263           raster_class_ )                                        \
1264   void                                                           \
1265   FT_Destroy_Class_ ## class_( FT_Library        library,        \
1266                                FT_Module_Class*  clazz )         \
1267   {                                                              \
1268     FT_Renderer_Class*  rclazz = (FT_Renderer_Class*)clazz;      \
1269     FT_Memory           memory = library->memory;                \
1270                                                                  \
1271                                                                  \
1272     class_ ## _pic_free( library );                              \
1273     if ( rclazz )                                                \
1274       FT_FREE( rclazz );                                         \
1275   }                                                              \
1276                                                                  \
1277                                                                  \
1278   FT_Error                                                       \
1279   FT_Create_Class_ ## class_( FT_Library         library,        \
1280                               FT_Module_Class**  output_class )  \
1281   {                                                              \
1282     FT_Renderer_Class*  clazz = NULL;                            \
1283     FT_Error            error;                                   \
1284     FT_Memory           memory = library->memory;                \
1285                                                                  \
1286                                                                  \
1287     if ( FT_ALLOC( clazz, sizeof ( *clazz ) ) )                  \
1288       return error;                                              \
1289                                                                  \
1290     error = class_ ## _pic_init( library );                      \
1291     if ( error )                                                 \
1292     {                                                            \
1293       FT_FREE( clazz );                                          \
1294       return error;                                              \
1295     }                                                            \
1296                                                                  \
1297     FT_DEFINE_ROOT_MODULE( flags_,                               \
1298                            size_,                                \
1299                            name_,                                \
1300                            version_,                             \
1301                            requires_,                            \
1302                            interface_,                           \
1303                            init_,                                \
1304                            done_,                                \
1305                            get_interface_ )                      \
1306                                                                  \
1307     clazz->glyph_format    = glyph_format_;                      \
1308                                                                  \
1309     clazz->render_glyph    = render_glyph_;                      \
1310     clazz->transform_glyph = transform_glyph_;                   \
1311     clazz->get_glyph_cbox  = get_glyph_cbox_;                    \
1312     clazz->set_mode        = set_mode_;                          \
1313                                                                  \
1314     clazz->raster_class    = raster_class_;                      \
1315                                                                  \
1316     *output_class = (FT_Module_Class*)clazz;                     \
1317                                                                  \
1318     return FT_Err_Ok;                                            \
1319   }
1320 
1321 #endif /* FT_CONFIG_OPTION_PIC */
1322 
1323 
1324   /* PIC support macros for ftmodapi.h **/
1325 
1326 
1327 #ifdef FT_CONFIG_OPTION_PIC
1328 
1329   /*************************************************************************/
1330   /*                                                                       */
1331   /* <FuncType>                                                            */
1332   /*    FT_Module_Creator                                                  */
1333   /*                                                                       */
1334   /* <Description>                                                         */
1335   /*    A function used to create (allocate) a new module class object.    */
1336   /*    The object's members are initialized, but the module itself is     */
1337   /*    not.                                                               */
1338   /*                                                                       */
1339   /* <Input>                                                               */
1340   /*    memory       :: A handle to the memory manager.                    */
1341   /*    output_class :: Initialized with the newly allocated class.        */
1342   /*                                                                       */
1343   typedef FT_Error
1344   (*FT_Module_Creator)( FT_Memory          memory,
1345                         FT_Module_Class**  output_class );
1346 
1347   /*************************************************************************/
1348   /*                                                                       */
1349   /* <FuncType>                                                            */
1350   /*    FT_Module_Destroyer                                                */
1351   /*                                                                       */
1352   /* <Description>                                                         */
1353   /*    A function used to destroy (deallocate) a module class object.     */
1354   /*                                                                       */
1355   /* <Input>                                                               */
1356   /*    memory :: A handle to the memory manager.                          */
1357   /*    clazz  :: Module class to destroy.                                 */
1358   /*                                                                       */
1359   typedef void
1360   (*FT_Module_Destroyer)( FT_Memory         memory,
1361                           FT_Module_Class*  clazz );
1362 
1363 #endif
1364 
1365 
1366   /*************************************************************************/
1367   /*                                                                       */
1368   /* <Macro>                                                               */
1369   /*    FT_DECLARE_MODULE                                                  */
1370   /*                                                                       */
1371   /* <Description>                                                         */
1372   /*    Used to create a forward declaration of a                          */
1373   /*    FT_Module_Class struct instance.                                   */
1374   /*                                                                       */
1375   /* <Macro>                                                               */
1376   /*    FT_DEFINE_MODULE                                                   */
1377   /*                                                                       */
1378   /* <Description>                                                         */
1379   /*    Used to initialize an instance of an FT_Module_Class struct.       */
1380   /*                                                                       */
1381   /*    When FT_CONFIG_OPTION_PIC is defined a `create' function needs     */
1382   /*    to be called with a pointer where the allocated structure is       */
1383   /*    returned.  And when it is no longer needed a `destroy' function    */
1384   /*    needs to be called to release that allocation.                     */
1385   /*    `ftinit.c' (ft_create_default_module_classes) already contains     */
1386   /*    a mechanism to call these functions for the default modules        */
1387   /*    described in `ftmodule.h'.                                         */
1388   /*                                                                       */
1389   /*    Notice that the created `create' and `destroy' functions call      */
1390   /*    `pic_init' and `pic_free' to allow you to manually allocate and    */
1391   /*    initialize any additional global data, like a module specific      */
1392   /*    interface, and put them in the global pic container defined in     */
1393   /*    `ftpic.h'.  If you don't need them just implement the functions as */
1394   /*    empty to resolve the link error.  Also the `pic_init' and          */
1395   /*    `pic_free' functions should be declared in `pic.h', to be referred */
1396   /*    by the module definition calling `FT_DEFINE_MODULE' in the         */
1397   /*    following.                                                         */
1398   /*                                                                       */
1399   /*    When FT_CONFIG_OPTION_PIC is not defined the struct will be        */
1400   /*    allocated in the global scope (or the scope where the macro        */
1401   /*    is used).                                                          */
1402   /*                                                                       */
1403   /* <Macro>                                                               */
1404   /*    FT_DEFINE_ROOT_MODULE                                              */
1405   /*                                                                       */
1406   /* <Description>                                                         */
1407   /*    Used to initialize an instance of an FT_Module_Class struct inside */
1408   /*    another struct that contains it or in a function that initializes  */
1409   /*    that containing struct.                                            */
1410   /*                                                                       */
1411 #ifndef FT_CONFIG_OPTION_PIC
1412 
1413 #define FT_DECLARE_MODULE( class_ )  \
1414   FT_CALLBACK_TABLE                  \
1415   const FT_Module_Class  class_;
1416 
1417 #define FT_DEFINE_ROOT_MODULE(  \
1418           flags_,               \
1419           size_,                \
1420           name_,                \
1421           version_,             \
1422           requires_,            \
1423           interface_,           \
1424           init_,                \
1425           done_,                \
1426           get_interface_ )      \
1427   {                             \
1428     flags_,                     \
1429     size_,                      \
1430                                 \
1431     name_,                      \
1432     version_,                   \
1433     requires_,                  \
1434                                 \
1435     interface_,                 \
1436                                 \
1437     init_,                      \
1438     done_,                      \
1439     get_interface_,             \
1440   },
1441 
1442 #define FT_DEFINE_MODULE(         \
1443           class_,                 \
1444           flags_,                 \
1445           size_,                  \
1446           name_,                  \
1447           version_,               \
1448           requires_,              \
1449           interface_,             \
1450           init_,                  \
1451           done_,                  \
1452           get_interface_ )        \
1453   FT_CALLBACK_TABLE_DEF           \
1454   const FT_Module_Class class_ =  \
1455   {                               \
1456     flags_,                       \
1457     size_,                        \
1458                                   \
1459     name_,                        \
1460     version_,                     \
1461     requires_,                    \
1462                                   \
1463     interface_,                   \
1464                                   \
1465     init_,                        \
1466     done_,                        \
1467     get_interface_,               \
1468   };
1469 
1470 
1471 #else /* FT_CONFIG_OPTION_PIC */
1472 
1473 #define FT_DECLARE_MODULE( class_ )                               \
1474   FT_Error                                                        \
1475   FT_Create_Class_ ## class_( FT_Library         library,         \
1476                               FT_Module_Class**  output_class );  \
1477   void                                                            \
1478   FT_Destroy_Class_ ## class_( FT_Library        library,         \
1479                                FT_Module_Class*  clazz );
1480 
1481 #define FT_DEFINE_ROOT_MODULE(                      \
1482           flags_,                                   \
1483           size_,                                    \
1484           name_,                                    \
1485           version_,                                 \
1486           requires_,                                \
1487           interface_,                               \
1488           init_,                                    \
1489           done_,                                    \
1490           get_interface_ )                          \
1491     clazz->root.module_flags     = flags_;          \
1492     clazz->root.module_size      = size_;           \
1493     clazz->root.module_name      = name_;           \
1494     clazz->root.module_version   = version_;        \
1495     clazz->root.module_requires  = requires_;       \
1496                                                     \
1497     clazz->root.module_interface = interface_;      \
1498                                                     \
1499     clazz->root.module_init      = init_;           \
1500     clazz->root.module_done      = done_;           \
1501     clazz->root.get_interface    = get_interface_;
1502 
1503 #define FT_DEFINE_MODULE(                                        \
1504           class_,                                                \
1505           flags_,                                                \
1506           size_,                                                 \
1507           name_,                                                 \
1508           version_,                                              \
1509           requires_,                                             \
1510           interface_,                                            \
1511           init_,                                                 \
1512           done_,                                                 \
1513           get_interface_ )                                       \
1514   void                                                           \
1515   FT_Destroy_Class_ ## class_( FT_Library        library,        \
1516                                FT_Module_Class*  clazz )         \
1517   {                                                              \
1518     FT_Memory memory = library->memory;                          \
1519                                                                  \
1520                                                                  \
1521     class_ ## _pic_free( library );                              \
1522     if ( clazz )                                                 \
1523       FT_FREE( clazz );                                          \
1524   }                                                              \
1525                                                                  \
1526                                                                  \
1527   FT_Error                                                       \
1528   FT_Create_Class_ ## class_( FT_Library         library,        \
1529                               FT_Module_Class**  output_class )  \
1530   {                                                              \
1531     FT_Memory         memory = library->memory;                  \
1532     FT_Module_Class*  clazz  = NULL;                             \
1533     FT_Error          error;                                     \
1534                                                                  \
1535                                                                  \
1536     if ( FT_ALLOC( clazz, sizeof ( *clazz ) ) )                  \
1537       return error;                                              \
1538     error = class_ ## _pic_init( library );                      \
1539     if ( error )                                                 \
1540     {                                                            \
1541       FT_FREE( clazz );                                          \
1542       return error;                                              \
1543     }                                                            \
1544                                                                  \
1545     clazz->module_flags     = flags_;                            \
1546     clazz->module_size      = size_;                             \
1547     clazz->module_name      = name_;                             \
1548     clazz->module_version   = version_;                          \
1549     clazz->module_requires  = requires_;                         \
1550                                                                  \
1551     clazz->module_interface = interface_;                        \
1552                                                                  \
1553     clazz->module_init      = init_;                             \
1554     clazz->module_done      = done_;                             \
1555     clazz->get_interface    = get_interface_;                    \
1556                                                                  \
1557     *output_class = clazz;                                       \
1558                                                                  \
1559     return FT_Err_Ok;                                            \
1560   }
1561 
1562 #endif /* FT_CONFIG_OPTION_PIC */
1563 
1564 
1565 FT_END_HEADER
1566 
1567 #endif /* FTOBJS_H_ */
1568 
1569 
1570 /* END */
1571