Imported Upstream version 2.13.2
[platform/upstream/freetype2.git] / include / freetype / internal / ftobjs.h
1 /****************************************************************************
2  *
3  * ftobjs.h
4  *
5  *   The FreeType private base classes (specification).
6  *
7  * Copyright (C) 1996-2023 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 <freetype/ftrender.h>
30 #include <freetype/ftsizes.h>
31 #include <freetype/ftlcdfil.h>
32 #include <freetype/internal/ftmemory.h>
33 #include <freetype/internal/ftgloadr.h>
34 #include <freetype/internal/ftdrv.h>
35 #include <freetype/internal/autohint.h>
36 #include <freetype/internal/ftserv.h>
37 #include <freetype/internal/ftcalc.h>
38
39 #ifdef FT_CONFIG_OPTION_INCREMENTAL
40 #include <freetype/ftincrem.h>
41 #endif
42
43 #include "compiler-macros.h"
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' algorithm.
77    * We use alpha = 1, beta = 3/8, giving us results with a largest error
78    * 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   /* specialized versions (for signed values)                   */
96   /* that don't produce run-time errors due to integer overflow */
97 #define FT_PAD_ROUND_LONG( x, n )  FT_PAD_FLOOR( ADD_LONG( (x), (n) / 2 ), \
98                                                  n )
99 #define FT_PAD_CEIL_LONG( x, n )   FT_PAD_FLOOR( ADD_LONG( (x), (n) - 1 ), \
100                                                  n )
101 #define FT_PIX_ROUND_LONG( x )     FT_PIX_FLOOR( ADD_LONG( (x), 32 ) )
102 #define FT_PIX_CEIL_LONG( x )      FT_PIX_FLOOR( ADD_LONG( (x), 63 ) )
103
104 #define FT_PAD_ROUND_INT32( x, n )  FT_PAD_FLOOR( ADD_INT32( (x), (n) / 2 ), \
105                                                   n )
106 #define FT_PAD_CEIL_INT32( x, n )   FT_PAD_FLOOR( ADD_INT32( (x), (n) - 1 ), \
107                                                   n )
108 #define FT_PIX_ROUND_INT32( x )     FT_PIX_FLOOR( ADD_INT32( (x), 32 ) )
109 #define FT_PIX_CEIL_INT32( x )      FT_PIX_FLOOR( ADD_INT32( (x), 63 ) )
110
111
112   /*
113    * character classification functions -- since these are used to parse font
114    * files, we must not use those in <ctypes.h> which are locale-dependent
115    */
116 #define  ft_isdigit( x )   ( ( (unsigned)(x) - '0' ) < 10U )
117
118 #define  ft_isxdigit( x )  ( ( (unsigned)(x) - '0' ) < 10U || \
119                              ( (unsigned)(x) - 'a' ) < 6U  || \
120                              ( (unsigned)(x) - 'A' ) < 6U  )
121
122   /* the next two macros assume ASCII representation */
123 #define  ft_isupper( x )  ( ( (unsigned)(x) - 'A' ) < 26U )
124 #define  ft_islower( x )  ( ( (unsigned)(x) - 'a' ) < 26U )
125
126 #define  ft_isalpha( x )  ( ft_isupper( x ) || ft_islower( x ) )
127 #define  ft_isalnum( x )  ( ft_isdigit( x ) || ft_isalpha( x ) )
128
129
130   /*************************************************************************/
131   /*************************************************************************/
132   /*************************************************************************/
133   /****                                                                 ****/
134   /****                                                                 ****/
135   /****                       C H A R M A P S                           ****/
136   /****                                                                 ****/
137   /****                                                                 ****/
138   /*************************************************************************/
139   /*************************************************************************/
140   /*************************************************************************/
141
142   /* handle to internal charmap object */
143   typedef struct FT_CMapRec_*              FT_CMap;
144
145   /* handle to charmap class structure */
146   typedef const struct FT_CMap_ClassRec_*  FT_CMap_Class;
147
148   /* internal charmap object structure */
149   typedef struct  FT_CMapRec_
150   {
151     FT_CharMapRec  charmap;
152     FT_CMap_Class  clazz;
153
154   } FT_CMapRec;
155
156   /* typecast any pointer to a charmap handle */
157 #define FT_CMAP( x )  ( (FT_CMap)( x ) )
158
159   /* obvious macros */
160 #define FT_CMAP_PLATFORM_ID( x )  FT_CMAP( x )->charmap.platform_id
161 #define FT_CMAP_ENCODING_ID( x )  FT_CMAP( x )->charmap.encoding_id
162 #define FT_CMAP_ENCODING( x )     FT_CMAP( x )->charmap.encoding
163 #define FT_CMAP_FACE( x )         FT_CMAP( x )->charmap.face
164
165
166   /* class method definitions */
167   typedef FT_Error
168   (*FT_CMap_InitFunc)( FT_CMap     cmap,
169                        FT_Pointer  init_data );
170
171   typedef void
172   (*FT_CMap_DoneFunc)( FT_CMap  cmap );
173
174   typedef FT_UInt
175   (*FT_CMap_CharIndexFunc)( FT_CMap    cmap,
176                             FT_UInt32  char_code );
177
178   typedef FT_UInt
179   (*FT_CMap_CharNextFunc)( FT_CMap     cmap,
180                            FT_UInt32  *achar_code );
181
182   typedef FT_UInt
183   (*FT_CMap_CharVarIndexFunc)( FT_CMap    cmap,
184                                FT_CMap    unicode_cmap,
185                                FT_UInt32  char_code,
186                                FT_UInt32  variant_selector );
187
188   typedef FT_Int
189   (*FT_CMap_CharVarIsDefaultFunc)( FT_CMap    cmap,
190                                    FT_UInt32  char_code,
191                                    FT_UInt32  variant_selector );
192
193   typedef FT_UInt32 *
194   (*FT_CMap_VariantListFunc)( FT_CMap    cmap,
195                               FT_Memory  mem );
196
197   typedef FT_UInt32 *
198   (*FT_CMap_CharVariantListFunc)( FT_CMap    cmap,
199                                   FT_Memory  mem,
200                                   FT_UInt32  char_code );
201
202   typedef FT_UInt32 *
203   (*FT_CMap_VariantCharListFunc)( FT_CMap    cmap,
204                                   FT_Memory  mem,
205                                   FT_UInt32  variant_selector );
206
207
208   typedef struct  FT_CMap_ClassRec_
209   {
210     FT_ULong               size;
211
212     FT_CMap_InitFunc       init;
213     FT_CMap_DoneFunc       done;
214     FT_CMap_CharIndexFunc  char_index;
215     FT_CMap_CharNextFunc   char_next;
216
217     /* Subsequent entries are special ones for format 14 -- the variant */
218     /* selector subtable which behaves like no other                    */
219
220     FT_CMap_CharVarIndexFunc      char_var_index;
221     FT_CMap_CharVarIsDefaultFunc  char_var_default;
222     FT_CMap_VariantListFunc       variant_list;
223     FT_CMap_CharVariantListFunc   charvariant_list;
224     FT_CMap_VariantCharListFunc   variantchar_list;
225
226   } FT_CMap_ClassRec;
227
228
229 #define FT_DECLARE_CMAP_CLASS( class_ )            \
230   FT_CALLBACK_TABLE const FT_CMap_ClassRec  class_;
231
232 #define FT_DEFINE_CMAP_CLASS(       \
233           class_,                   \
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   FT_CALLBACK_TABLE_DEF             \
245   const FT_CMap_ClassRec  class_ =  \
246   {                                 \
247     size_,                          \
248     init_,                          \
249     done_,                          \
250     char_index_,                    \
251     char_next_,                     \
252     char_var_index_,                \
253     char_var_default_,              \
254     variant_list_,                  \
255     charvariant_list_,              \
256     variantchar_list_               \
257   };
258
259
260   /* create a new charmap and add it to charmap->face */
261   FT_BASE( FT_Error )
262   FT_CMap_New( FT_CMap_Class  clazz,
263                FT_Pointer     init_data,
264                FT_CharMap     charmap,
265                FT_CMap       *acmap );
266
267   /* destroy a charmap and remove it from face's list */
268   FT_BASE( void )
269   FT_CMap_Done( FT_CMap  cmap );
270
271
272   /* add LCD padding to CBox */
273   FT_BASE( void )
274   ft_lcd_padding( FT_BBox*        cbox,
275                   FT_GlyphSlot    slot,
276                   FT_Render_Mode  mode );
277
278 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
279
280   typedef void  (*FT_Bitmap_LcdFilterFunc)( FT_Bitmap*      bitmap,
281                                             FT_Byte*        weights );
282
283
284   /* This is the default LCD filter, an in-place, 5-tap FIR filter. */
285   FT_BASE( void )
286   ft_lcd_filter_fir( FT_Bitmap*           bitmap,
287                      FT_LcdFiveTapFilter  weights );
288
289 #endif /* FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
290
291   /**************************************************************************
292    *
293    * @struct:
294    *   FT_Face_InternalRec
295    *
296    * @description:
297    *   This structure contains the internal fields of each FT_Face object.
298    *   These fields may change between different releases of FreeType.
299    *
300    * @fields:
301    *   max_points ::
302    *     The maximum number of points used to store the vectorial outline of
303    *     any glyph in this face.  If this value cannot be known in advance,
304    *     or if the face isn't scalable, this should be set to 0.  Only
305    *     relevant for scalable formats.
306    *
307    *   max_contours ::
308    *     The maximum number of contours 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    *   transform_matrix ::
314    *     A 2x2 matrix of 16.16 coefficients used to transform glyph outlines
315    *     after they are loaded from the font.  Only used by the convenience
316    *     functions.
317    *
318    *   transform_delta ::
319    *     A translation vector used to transform glyph outlines after they are
320    *     loaded from the font.  Only used by the convenience functions.
321    *
322    *   transform_flags ::
323    *     Some flags used to classify the transform.  Only used by the
324    *     convenience functions.
325    *
326    *   services ::
327    *     A cache for frequently used services.  It should be only accessed
328    *     with the macro `FT_FACE_LOOKUP_SERVICE`.
329    *
330    *   incremental_interface ::
331    *     If non-null, the interface through which glyph data and metrics are
332    *     loaded incrementally for faces that do not provide all of this data
333    *     when first opened.  This field exists only if
334    *     @FT_CONFIG_OPTION_INCREMENTAL is defined.
335    *
336    *   no_stem_darkening ::
337    *     Overrides the module-level default, see @stem-darkening[cff], for
338    *     example.  FALSE and TRUE toggle stem darkening on and off,
339    *     respectively, value~-1 means to use the module/driver default.
340    *
341    *   random_seed ::
342    *     If positive, override the seed value for the CFF 'random' operator.
343    *     Value~0 means to use the font's value.  Value~-1 means to use the
344    *     CFF driver's default.
345    *
346    *   lcd_weights ::
347    *   lcd_filter_func ::
348    *     These fields specify the LCD filtering weights and callback function
349    *     for ClearType-style subpixel rendering.
350    *
351    *   refcount ::
352    *     A counter initialized to~1 at the time an @FT_Face structure is
353    *     created.  @FT_Reference_Face increments this counter, and
354    *     @FT_Done_Face only destroys a face if the counter is~1, otherwise it
355    *     simply decrements it.
356    */
357   typedef struct  FT_Face_InternalRec_
358   {
359     FT_Matrix  transform_matrix;
360     FT_Vector  transform_delta;
361     FT_Int     transform_flags;
362
363     FT_ServiceCacheRec  services;
364
365 #ifdef FT_CONFIG_OPTION_INCREMENTAL
366     FT_Incremental_InterfaceRec*  incremental_interface;
367 #endif
368
369     FT_Char              no_stem_darkening;
370     FT_Int32             random_seed;
371
372 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
373     FT_LcdFiveTapFilter      lcd_weights;      /* filter weights, if any */
374     FT_Bitmap_LcdFilterFunc  lcd_filter_func;  /* filtering callback     */
375 #endif
376
377     FT_Int  refcount;
378
379   } FT_Face_InternalRec;
380
381
382   /**************************************************************************
383    *
384    * @struct:
385    *   FT_Slot_InternalRec
386    *
387    * @description:
388    *   This structure contains the internal fields of each FT_GlyphSlot
389    *   object.  These fields may change between different releases of
390    *   FreeType.
391    *
392    * @fields:
393    *   loader ::
394    *     The glyph loader object used to load outlines into the glyph slot.
395    *
396    *   flags ::
397    *     Possible values are zero or FT_GLYPH_OWN_BITMAP.  The latter
398    *     indicates that the FT_GlyphSlot structure owns the bitmap buffer.
399    *
400    *   glyph_transformed ::
401    *     Boolean.  Set to TRUE when the loaded glyph must be transformed
402    *     through a specific font transformation.  This is _not_ the same as
403    *     the face transform set through FT_Set_Transform().
404    *
405    *   glyph_matrix ::
406    *     The 2x2 matrix corresponding to the glyph transformation, if
407    *     necessary.
408    *
409    *   glyph_delta ::
410    *     The 2d translation vector corresponding to the glyph transformation,
411    *     if necessary.
412    *
413    *   glyph_hints ::
414    *     Format-specific glyph hints management.
415    *
416    *   load_flags ::
417    *     The load flags passed as an argument to @FT_Load_Glyph while
418    *     initializing the glyph slot.
419    */
420
421 #define FT_GLYPH_OWN_BITMAP    0x1U
422 #define FT_GLYPH_OWN_GZIP_SVG  0x2U
423
424   typedef struct  FT_Slot_InternalRec_
425   {
426     FT_GlyphLoader  loader;
427     FT_UInt         flags;
428     FT_Bool         glyph_transformed;
429     FT_Matrix       glyph_matrix;
430     FT_Vector       glyph_delta;
431     void*           glyph_hints;
432
433     FT_Int32        load_flags;
434
435   } FT_GlyphSlot_InternalRec;
436
437
438   /**************************************************************************
439    *
440    * @struct:
441    *   FT_Size_InternalRec
442    *
443    * @description:
444    *   This structure contains the internal fields of each FT_Size object.
445    *
446    * @fields:
447    *   module_data ::
448    *     Data specific to a driver module.
449    *
450    *   autohint_mode ::
451    *     The used auto-hinting mode.
452    *
453    *   autohint_metrics ::
454    *     Metrics used by the auto-hinter.
455    *
456    */
457
458   typedef struct  FT_Size_InternalRec_
459   {
460     void*  module_data;
461
462     FT_Render_Mode   autohint_mode;
463     FT_Size_Metrics  autohint_metrics;
464
465   } FT_Size_InternalRec;
466
467
468   /*************************************************************************/
469   /*************************************************************************/
470   /*************************************************************************/
471   /****                                                                 ****/
472   /****                                                                 ****/
473   /****                         M O D U L E S                           ****/
474   /****                                                                 ****/
475   /****                                                                 ****/
476   /*************************************************************************/
477   /*************************************************************************/
478   /*************************************************************************/
479
480
481   /**************************************************************************
482    *
483    * @struct:
484    *   FT_ModuleRec
485    *
486    * @description:
487    *   A module object instance.
488    *
489    * @fields:
490    *   clazz ::
491    *     A pointer to the module's class.
492    *
493    *   library ::
494    *     A handle to the parent library object.
495    *
496    *   memory ::
497    *     A handle to the memory manager.
498    */
499   typedef struct  FT_ModuleRec_
500   {
501     FT_Module_Class*  clazz;
502     FT_Library        library;
503     FT_Memory         memory;
504
505   } FT_ModuleRec;
506
507
508   /* typecast an object to an FT_Module */
509 #define FT_MODULE( x )  ( (FT_Module)(x) )
510
511 #define FT_MODULE_CLASS( x )    FT_MODULE( x )->clazz
512 #define FT_MODULE_LIBRARY( x )  FT_MODULE( x )->library
513 #define FT_MODULE_MEMORY( x )   FT_MODULE( x )->memory
514
515
516 #define FT_MODULE_IS_DRIVER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
517                                     FT_MODULE_FONT_DRIVER )
518
519 #define FT_MODULE_IS_RENDERER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
520                                       FT_MODULE_RENDERER )
521
522 #define FT_MODULE_IS_HINTER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
523                                     FT_MODULE_HINTER )
524
525 #define FT_MODULE_IS_STYLER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
526                                     FT_MODULE_STYLER )
527
528 #define FT_DRIVER_IS_SCALABLE( x )  ( FT_MODULE_CLASS( x )->module_flags & \
529                                       FT_MODULE_DRIVER_SCALABLE )
530
531 #define FT_DRIVER_USES_OUTLINES( x )  !( FT_MODULE_CLASS( x )->module_flags & \
532                                          FT_MODULE_DRIVER_NO_OUTLINES )
533
534 #define FT_DRIVER_HAS_HINTER( x )  ( FT_MODULE_CLASS( x )->module_flags & \
535                                      FT_MODULE_DRIVER_HAS_HINTER )
536
537 #define FT_DRIVER_HINTS_LIGHTLY( x )  ( FT_MODULE_CLASS( x )->module_flags & \
538                                         FT_MODULE_DRIVER_HINTS_LIGHTLY )
539
540
541   /**************************************************************************
542    *
543    * @function:
544    *   FT_Get_Module_Interface
545    *
546    * @description:
547    *   Finds a module and returns its specific interface as a typeless
548    *   pointer.
549    *
550    * @input:
551    *   library ::
552    *     A handle to the library object.
553    *
554    *   module_name ::
555    *     The module's name (as an ASCII string).
556    *
557    * @return:
558    *   A module-specific interface if available, 0 otherwise.
559    *
560    * @note:
561    *   You should better be familiar with FreeType internals to know which
562    *   module to look for, and what its interface is :-)
563    */
564   FT_BASE( const void* )
565   FT_Get_Module_Interface( FT_Library   library,
566                            const char*  mod_name );
567
568   FT_BASE( FT_Pointer )
569   ft_module_get_service( FT_Module    module,
570                          const char*  service_id,
571                          FT_Bool      global );
572
573 #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
574   FT_BASE( FT_Error )
575   ft_property_string_set( FT_Library        library,
576                           const FT_String*  module_name,
577                           const FT_String*  property_name,
578                           FT_String*        value );
579 #endif
580
581   /* */
582
583
584   /*************************************************************************/
585   /*************************************************************************/
586   /*************************************************************************/
587   /****                                                                 ****/
588   /****                                                                 ****/
589   /****   F A C E,   S I Z E   &   G L Y P H   S L O T   O B J E C T S  ****/
590   /****                                                                 ****/
591   /****                                                                 ****/
592   /*************************************************************************/
593   /*************************************************************************/
594   /*************************************************************************/
595
596   /* a few macros used to perform easy typecasts with minimal brain damage */
597
598 #define FT_FACE( x )          ( (FT_Face)(x) )
599 #define FT_SIZE( x )          ( (FT_Size)(x) )
600 #define FT_SLOT( x )          ( (FT_GlyphSlot)(x) )
601
602 #define FT_FACE_DRIVER( x )   FT_FACE( x )->driver
603 #define FT_FACE_LIBRARY( x )  FT_FACE_DRIVER( x )->root.library
604 #define FT_FACE_MEMORY( x )   FT_FACE( x )->memory
605 #define FT_FACE_STREAM( x )   FT_FACE( x )->stream
606
607 #define FT_SIZE_FACE( x )     FT_SIZE( x )->face
608 #define FT_SLOT_FACE( x )     FT_SLOT( x )->face
609
610 #define FT_FACE_SLOT( x )     FT_FACE( x )->glyph
611 #define FT_FACE_SIZE( x )     FT_FACE( x )->size
612
613
614   /**************************************************************************
615    *
616    * @function:
617    *   FT_New_GlyphSlot
618    *
619    * @description:
620    *   It is sometimes useful to have more than one glyph slot for a given
621    *   face object.  This function is used to create additional slots.  All
622    *   of them are automatically discarded when the face is destroyed.
623    *
624    * @input:
625    *   face ::
626    *     A handle to a parent face object.
627    *
628    * @output:
629    *   aslot ::
630    *     A handle to a new glyph slot object.
631    *
632    * @return:
633    *   FreeType error code.  0 means success.
634    */
635   FT_BASE( FT_Error )
636   FT_New_GlyphSlot( FT_Face        face,
637                     FT_GlyphSlot  *aslot );
638
639
640   /**************************************************************************
641    *
642    * @function:
643    *   FT_Done_GlyphSlot
644    *
645    * @description:
646    *   Destroys a given glyph slot.  Remember however that all slots are
647    *   automatically destroyed with its parent.  Using this function is not
648    *   always mandatory.
649    *
650    * @input:
651    *   slot ::
652    *     A handle to a target glyph slot.
653    */
654   FT_BASE( void )
655   FT_Done_GlyphSlot( FT_GlyphSlot  slot );
656
657   /* */
658
659 #define FT_REQUEST_WIDTH( req )                                            \
660           ( (req)->horiResolution                                          \
661               ? ( (req)->width * (FT_Pos)(req)->horiResolution + 36 ) / 72 \
662               : (req)->width )
663
664 #define FT_REQUEST_HEIGHT( req )                                            \
665           ( (req)->vertResolution                                           \
666               ? ( (req)->height * (FT_Pos)(req)->vertResolution + 36 ) / 72 \
667               : (req)->height )
668
669
670   /* Set the metrics according to a bitmap strike. */
671   FT_BASE( void )
672   FT_Select_Metrics( FT_Face   face,
673                      FT_ULong  strike_index );
674
675
676   /* Set the metrics according to a size request. */
677   FT_BASE( FT_Error )
678   FT_Request_Metrics( FT_Face          face,
679                       FT_Size_Request  req );
680
681
682   /* Match a size request against `available_sizes'. */
683   FT_BASE( FT_Error )
684   FT_Match_Size( FT_Face          face,
685                  FT_Size_Request  req,
686                  FT_Bool          ignore_width,
687                  FT_ULong*        size_index );
688
689
690   /* Use the horizontal metrics to synthesize the vertical metrics. */
691   /* If `advance' is zero, it is also synthesized.                  */
692   FT_BASE( void )
693   ft_synthesize_vertical_metrics( FT_Glyph_Metrics*  metrics,
694                                   FT_Pos             advance );
695
696
697   /* Free the bitmap of a given glyphslot when needed (i.e., only when it */
698   /* was allocated with ft_glyphslot_alloc_bitmap).                       */
699   FT_BASE( void )
700   ft_glyphslot_free_bitmap( FT_GlyphSlot  slot );
701
702
703   /* Preset bitmap metrics of an outline glyphslot prior to rendering */
704   /* and check whether the truncated bbox is too large for rendering. */
705   FT_BASE( FT_Bool )
706   ft_glyphslot_preset_bitmap( FT_GlyphSlot      slot,
707                               FT_Render_Mode    mode,
708                               const FT_Vector*  origin );
709
710   /* Allocate a new bitmap buffer in a glyph slot. */
711   FT_BASE( FT_Error )
712   ft_glyphslot_alloc_bitmap( FT_GlyphSlot  slot,
713                              FT_ULong      size );
714
715
716   /* Set the bitmap buffer in a glyph slot to a given pointer.  The buffer */
717   /* will not be freed by a later call to ft_glyphslot_free_bitmap.        */
718   FT_BASE( void )
719   ft_glyphslot_set_bitmap( FT_GlyphSlot  slot,
720                            FT_Byte*      buffer );
721
722
723   /*************************************************************************/
724   /*************************************************************************/
725   /*************************************************************************/
726   /****                                                                 ****/
727   /****                                                                 ****/
728   /****                        R E N D E R E R S                        ****/
729   /****                                                                 ****/
730   /****                                                                 ****/
731   /*************************************************************************/
732   /*************************************************************************/
733   /*************************************************************************/
734
735
736 #define FT_RENDERER( x )       ( (FT_Renderer)(x) )
737 #define FT_GLYPH( x )          ( (FT_Glyph)(x) )
738 #define FT_BITMAP_GLYPH( x )   ( (FT_BitmapGlyph)(x) )
739 #define FT_OUTLINE_GLYPH( x )  ( (FT_OutlineGlyph)(x) )
740
741
742   typedef struct  FT_RendererRec_
743   {
744     FT_ModuleRec            root;
745     FT_Renderer_Class*      clazz;
746     FT_Glyph_Format         glyph_format;
747     FT_Glyph_Class          glyph_class;
748
749     FT_Raster               raster;
750     FT_Raster_Render_Func   raster_render;
751     FT_Renderer_RenderFunc  render;
752
753   } FT_RendererRec;
754
755
756   /*************************************************************************/
757   /*************************************************************************/
758   /*************************************************************************/
759   /****                                                                 ****/
760   /****                                                                 ****/
761   /****                    F O N T   D R I V E R S                      ****/
762   /****                                                                 ****/
763   /****                                                                 ****/
764   /*************************************************************************/
765   /*************************************************************************/
766   /*************************************************************************/
767
768
769   /* typecast a module into a driver easily */
770 #define FT_DRIVER( x )  ( (FT_Driver)(x) )
771
772   /* typecast a module as a driver, and get its driver class */
773 #define FT_DRIVER_CLASS( x )  FT_DRIVER( x )->clazz
774
775
776   /**************************************************************************
777    *
778    * @struct:
779    *   FT_DriverRec
780    *
781    * @description:
782    *   The root font driver class.  A font driver is responsible for managing
783    *   and loading font files of a given format.
784    *
785    * @fields:
786    *   root ::
787    *     Contains the fields of the root module class.
788    *
789    *   clazz ::
790    *     A pointer to the font driver's class.  Note that this is NOT
791    *     root.clazz.  'class' wasn't used as it is a reserved word in C++.
792    *
793    *   faces_list ::
794    *     The list of faces currently opened by this driver.
795    *
796    *   glyph_loader ::
797    *     Unused.  Used to be glyph loader for all faces managed by this
798    *     driver.
799    */
800   typedef struct  FT_DriverRec_
801   {
802     FT_ModuleRec     root;
803     FT_Driver_Class  clazz;
804     FT_ListRec       faces_list;
805     FT_GlyphLoader   glyph_loader;
806
807   } FT_DriverRec;
808
809
810   /*************************************************************************/
811   /*************************************************************************/
812   /*************************************************************************/
813   /****                                                                 ****/
814   /****                                                                 ****/
815   /****                       L I B R A R I E S                         ****/
816   /****                                                                 ****/
817   /****                                                                 ****/
818   /*************************************************************************/
819   /*************************************************************************/
820   /*************************************************************************/
821
822
823   /**************************************************************************
824    *
825    * @struct:
826    *   FT_LibraryRec
827    *
828    * @description:
829    *   The FreeType library class.  This is the root of all FreeType data.
830    *   Use FT_New_Library() to create a library object, and FT_Done_Library()
831    *   to discard it and all child objects.
832    *
833    * @fields:
834    *   memory ::
835    *     The library's memory object.  Manages memory allocation.
836    *
837    *   version_major ::
838    *     The major version number of the library.
839    *
840    *   version_minor ::
841    *     The minor version number of the library.
842    *
843    *   version_patch ::
844    *     The current patch level of the library.
845    *
846    *   num_modules ::
847    *     The number of modules currently registered within this library.
848    *     This is set to 0 for new libraries.  New modules are added through
849    *     the FT_Add_Module() API function.
850    *
851    *   modules ::
852    *     A table used to store handles to the currently registered
853    *     modules. Note that each font driver contains a list of its opened
854    *     faces.
855    *
856    *   renderers ::
857    *     The list of renderers currently registered within the library.
858    *
859    *   cur_renderer ::
860    *     The current outline renderer.  This is a shortcut used to avoid
861    *     parsing the list on each call to FT_Outline_Render().  It is a
862    *     handle to the current renderer for the FT_GLYPH_FORMAT_OUTLINE
863    *     format.
864    *
865    *   auto_hinter ::
866    *     The auto-hinter module interface.
867    *
868    *   debug_hooks ::
869    *     An array of four function pointers that allow debuggers to hook into
870    *     a font format's interpreter.  Currently, only the TrueType bytecode
871    *     debugger uses this.
872    *
873    *   lcd_weights ::
874    *     The LCD filter weights for ClearType-style subpixel rendering.
875    *
876    *   lcd_filter_func ::
877    *     The LCD filtering callback function for for ClearType-style subpixel
878    *     rendering.
879    *
880    *   lcd_geometry ::
881    *     This array specifies LCD subpixel geometry and controls Harmony LCD
882    *     rendering technique, alternative to ClearType.
883    *
884    *   pic_container ::
885    *     Contains global structs and tables, instead of defining them
886    *     globally.
887    *
888    *   refcount ::
889    *     A counter initialized to~1 at the time an @FT_Library structure is
890    *     created.  @FT_Reference_Library increments this counter, and
891    *     @FT_Done_Library only destroys a library if the counter is~1,
892    *     otherwise it simply decrements it.
893    */
894   typedef struct  FT_LibraryRec_
895   {
896     FT_Memory          memory;           /* library's memory manager */
897
898     FT_Int             version_major;
899     FT_Int             version_minor;
900     FT_Int             version_patch;
901
902     FT_UInt            num_modules;
903     FT_Module          modules[FT_MAX_MODULES];  /* module objects  */
904
905     FT_ListRec         renderers;        /* list of renderers        */
906     FT_Renderer        cur_renderer;     /* current outline renderer */
907     FT_Module          auto_hinter;
908
909     FT_DebugHook_Func  debug_hooks[4];
910
911 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
912     FT_LcdFiveTapFilter      lcd_weights;      /* filter weights, if any */
913     FT_Bitmap_LcdFilterFunc  lcd_filter_func;  /* filtering callback     */
914 #else
915     FT_Vector                lcd_geometry[3];  /* RGB subpixel positions */
916 #endif
917
918     FT_Int             refcount;
919
920   } FT_LibraryRec;
921
922
923   FT_BASE( FT_Renderer )
924   FT_Lookup_Renderer( FT_Library       library,
925                       FT_Glyph_Format  format,
926                       FT_ListNode*     node );
927
928   FT_BASE( FT_Error )
929   FT_Render_Glyph_Internal( FT_Library      library,
930                             FT_GlyphSlot    slot,
931                             FT_Render_Mode  render_mode );
932
933   typedef const char*
934   (*FT_Face_GetPostscriptNameFunc)( FT_Face  face );
935
936   typedef FT_Error
937   (*FT_Face_GetGlyphNameFunc)( FT_Face     face,
938                                FT_UInt     glyph_index,
939                                FT_Pointer  buffer,
940                                FT_UInt     buffer_max );
941
942   typedef FT_UInt
943   (*FT_Face_GetGlyphNameIndexFunc)( FT_Face           face,
944                                     const FT_String*  glyph_name );
945
946
947 #ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
948
949   /**************************************************************************
950    *
951    * @function:
952    *   FT_New_Memory
953    *
954    * @description:
955    *   Creates a new memory object.
956    *
957    * @return:
958    *   A pointer to the new memory object.  0 in case of error.
959    */
960   FT_BASE( FT_Memory )
961   FT_New_Memory( void );
962
963
964   /**************************************************************************
965    *
966    * @function:
967    *   FT_Done_Memory
968    *
969    * @description:
970    *   Discards memory manager.
971    *
972    * @input:
973    *   memory ::
974    *     A handle to the memory manager.
975    */
976   FT_BASE( void )
977   FT_Done_Memory( FT_Memory  memory );
978
979 #endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */
980
981
982   /* Define default raster's interface.  The default raster is located in  */
983   /* `src/base/ftraster.c'.                                                */
984   /*                                                                       */
985   /* Client applications can register new rasters through the              */
986   /* FT_Set_Raster() API.                                                  */
987
988 #ifndef FT_NO_DEFAULT_RASTER
989   FT_EXPORT_VAR( FT_Raster_Funcs )  ft_default_raster;
990 #endif
991
992
993   /**************************************************************************
994    *
995    * @macro:
996    *   FT_DEFINE_OUTLINE_FUNCS
997    *
998    * @description:
999    *   Used to initialize an instance of FT_Outline_Funcs struct.  The struct
1000    *   will be allocated in the global scope (or the scope where the macro is
1001    *   used).
1002    */
1003 #define FT_DEFINE_OUTLINE_FUNCS(           \
1004           class_,                          \
1005           move_to_,                        \
1006           line_to_,                        \
1007           conic_to_,                       \
1008           cubic_to_,                       \
1009           shift_,                          \
1010           delta_ )                         \
1011   static const  FT_Outline_Funcs class_ =  \
1012   {                                        \
1013     move_to_,                              \
1014     line_to_,                              \
1015     conic_to_,                             \
1016     cubic_to_,                             \
1017     shift_,                                \
1018     delta_                                 \
1019   };
1020
1021
1022   /**************************************************************************
1023    *
1024    * @macro:
1025    *   FT_DEFINE_RASTER_FUNCS
1026    *
1027    * @description:
1028    *   Used to initialize an instance of FT_Raster_Funcs struct.  The struct
1029    *   will be allocated in the global scope (or the scope where the macro is
1030    *   used).
1031    */
1032 #define FT_DEFINE_RASTER_FUNCS(    \
1033           class_,                  \
1034           glyph_format_,           \
1035           raster_new_,             \
1036           raster_reset_,           \
1037           raster_set_mode_,        \
1038           raster_render_,          \
1039           raster_done_ )           \
1040   const FT_Raster_Funcs  class_ =  \
1041   {                                \
1042     glyph_format_,                 \
1043     raster_new_,                   \
1044     raster_reset_,                 \
1045     raster_set_mode_,              \
1046     raster_render_,                \
1047     raster_done_                   \
1048   };
1049
1050
1051
1052   /**************************************************************************
1053    *
1054    * @macro:
1055    *   FT_DEFINE_GLYPH
1056    *
1057    * @description:
1058    *   The struct will be allocated in the global scope (or the scope where
1059    *   the macro is used).
1060    */
1061 #define FT_DECLARE_GLYPH( class_ )                \
1062   FT_CALLBACK_TABLE const FT_Glyph_Class  class_;
1063
1064 #define FT_DEFINE_GLYPH(          \
1065           class_,                 \
1066           size_,                  \
1067           format_,                \
1068           init_,                  \
1069           done_,                  \
1070           copy_,                  \
1071           transform_,             \
1072           bbox_,                  \
1073           prepare_ )              \
1074   FT_CALLBACK_TABLE_DEF           \
1075   const FT_Glyph_Class  class_ =  \
1076   {                               \
1077     size_,                        \
1078     format_,                      \
1079     init_,                        \
1080     done_,                        \
1081     copy_,                        \
1082     transform_,                   \
1083     bbox_,                        \
1084     prepare_                      \
1085   };
1086
1087
1088   /**************************************************************************
1089    *
1090    * @macro:
1091    *   FT_DECLARE_RENDERER
1092    *
1093    * @description:
1094    *   Used to create a forward declaration of a FT_Renderer_Class struct
1095    *   instance.
1096    *
1097    * @macro:
1098    *   FT_DEFINE_RENDERER
1099    *
1100    * @description:
1101    *   Used to initialize an instance of FT_Renderer_Class struct.
1102    *
1103    *   The struct will be allocated in the global scope (or the scope where
1104    *   the macro is used).
1105    */
1106 #define FT_DECLARE_RENDERER( class_ )               \
1107   FT_EXPORT_VAR( const FT_Renderer_Class ) class_;
1108
1109 #define FT_DEFINE_RENDERER(                  \
1110           class_,                            \
1111           flags_,                            \
1112           size_,                             \
1113           name_,                             \
1114           version_,                          \
1115           requires_,                         \
1116           interface_,                        \
1117           init_,                             \
1118           done_,                             \
1119           get_interface_,                    \
1120           glyph_format_,                     \
1121           render_glyph_,                     \
1122           transform_glyph_,                  \
1123           get_glyph_cbox_,                   \
1124           set_mode_,                         \
1125           raster_class_ )                    \
1126   FT_CALLBACK_TABLE_DEF                      \
1127   const FT_Renderer_Class  class_ =          \
1128   {                                          \
1129     FT_DEFINE_ROOT_MODULE( flags_,           \
1130                            size_,            \
1131                            name_,            \
1132                            version_,         \
1133                            requires_,        \
1134                            interface_,       \
1135                            init_,            \
1136                            done_,            \
1137                            get_interface_ )  \
1138     glyph_format_,                           \
1139                                              \
1140     render_glyph_,                           \
1141     transform_glyph_,                        \
1142     get_glyph_cbox_,                         \
1143     set_mode_,                               \
1144                                              \
1145     raster_class_                            \
1146   };
1147
1148
1149   /**************************************************************************
1150    *
1151    * @macro:
1152    *   FT_DECLARE_MODULE
1153    *
1154    * @description:
1155    *   Used to create a forward declaration of a FT_Module_Class struct
1156    *   instance.
1157    *
1158    * @macro:
1159    *   FT_DEFINE_MODULE
1160    *
1161    * @description:
1162    *   Used to initialize an instance of an FT_Module_Class struct.
1163    *
1164    *   The struct will be allocated in the global scope (or the scope where
1165    *   the macro is used).
1166    *
1167    * @macro:
1168    *   FT_DEFINE_ROOT_MODULE
1169    *
1170    * @description:
1171    *   Used to initialize an instance of an FT_Module_Class struct inside
1172    *   another struct that contains it or in a function that initializes that
1173    *   containing struct.
1174    */
1175 #define FT_DECLARE_MODULE( class_ )  \
1176   FT_CALLBACK_TABLE                  \
1177   const FT_Module_Class  class_;
1178
1179 #define FT_DEFINE_ROOT_MODULE(  \
1180           flags_,               \
1181           size_,                \
1182           name_,                \
1183           version_,             \
1184           requires_,            \
1185           interface_,           \
1186           init_,                \
1187           done_,                \
1188           get_interface_ )      \
1189   {                             \
1190     flags_,                     \
1191     size_,                      \
1192                                 \
1193     name_,                      \
1194     version_,                   \
1195     requires_,                  \
1196                                 \
1197     interface_,                 \
1198                                 \
1199     init_,                      \
1200     done_,                      \
1201     get_interface_,             \
1202   },
1203
1204 #define FT_DEFINE_MODULE(         \
1205           class_,                 \
1206           flags_,                 \
1207           size_,                  \
1208           name_,                  \
1209           version_,               \
1210           requires_,              \
1211           interface_,             \
1212           init_,                  \
1213           done_,                  \
1214           get_interface_ )        \
1215   FT_CALLBACK_TABLE_DEF           \
1216   const FT_Module_Class class_ =  \
1217   {                               \
1218     flags_,                       \
1219     size_,                        \
1220                                   \
1221     name_,                        \
1222     version_,                     \
1223     requires_,                    \
1224                                   \
1225     interface_,                   \
1226                                   \
1227     init_,                        \
1228     done_,                        \
1229     get_interface_,               \
1230   };
1231
1232
1233 FT_END_HEADER
1234
1235 #endif /* FTOBJS_H_ */
1236
1237
1238 /* END */