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