1/***************************************************************************/
2/*                                                                         */
3/*  ftdriver.h                                                             */
4/*                                                                         */
5/*    FreeType font driver interface (specification).                      */
6/*                                                                         */
7/*  Copyright 1996-2003, 2006, 2008, 2011 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#ifndef __FTDRIVER_H__
20#define __FTDRIVER_H__
21
22
23#include <ft2build.h>
24#include FT_MODULE_H
25
26
27FT_BEGIN_HEADER
28
29
30  typedef FT_Error
31  (*FT_Face_InitFunc)( FT_Stream      stream,
32                       FT_Face        face,
33                       FT_Int         typeface_index,
34                       FT_Int         num_params,
35                       FT_Parameter*  parameters );
36
37  typedef void
38  (*FT_Face_DoneFunc)( FT_Face  face );
39
40
41  typedef FT_Error
42  (*FT_Size_InitFunc)( FT_Size  size );
43
44  typedef void
45  (*FT_Size_DoneFunc)( FT_Size  size );
46
47
48  typedef FT_Error
49  (*FT_Slot_InitFunc)( FT_GlyphSlot  slot );
50
51  typedef void
52  (*FT_Slot_DoneFunc)( FT_GlyphSlot  slot );
53
54
55  typedef FT_Error
56  (*FT_Size_RequestFunc)( FT_Size          size,
57                          FT_Size_Request  req );
58
59  typedef FT_Error
60  (*FT_Size_SelectFunc)( FT_Size   size,
61                         FT_ULong  size_index );
62
63#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
64
65  typedef FT_Error
66  (*FT_Size_ResetPointsFunc)( FT_Size     size,
67                              FT_F26Dot6  char_width,
68                              FT_F26Dot6  char_height,
69                              FT_UInt     horz_resolution,
70                              FT_UInt     vert_resolution );
71
72  typedef FT_Error
73  (*FT_Size_ResetPixelsFunc)( FT_Size  size,
74                              FT_UInt  pixel_width,
75                              FT_UInt  pixel_height );
76
77#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
78
79  typedef FT_Error
80  (*FT_Slot_LoadFunc)( FT_GlyphSlot  slot,
81                       FT_Size       size,
82                       FT_UInt       glyph_index,
83                       FT_Int32      load_flags );
84
85
86  typedef FT_UInt
87  (*FT_CharMap_CharIndexFunc)( FT_CharMap  charmap,
88                               FT_Long     charcode );
89
90  typedef FT_Long
91  (*FT_CharMap_CharNextFunc)( FT_CharMap  charmap,
92                              FT_Long     charcode );
93
94
95  typedef FT_Error
96  (*FT_Face_GetKerningFunc)( FT_Face     face,
97                             FT_UInt     left_glyph,
98                             FT_UInt     right_glyph,
99                             FT_Vector*  kerning );
100
101
102  typedef FT_Error
103  (*FT_Face_AttachFunc)( FT_Face    face,
104                         FT_Stream  stream );
105
106
107  typedef FT_Error
108  (*FT_Face_GetAdvancesFunc)( FT_Face    face,
109                              FT_UInt    first,
110                              FT_UInt    count,
111                              FT_Int32   flags,
112                              FT_Fixed*  advances );
113
114
115  /*************************************************************************/
116  /*                                                                       */
117  /* <Struct>                                                              */
118  /*    FT_Driver_ClassRec                                                 */
119  /*                                                                       */
120  /* <Description>                                                         */
121  /*    The font driver class.  This structure mostly contains pointers to */
122  /*    driver methods.                                                    */
123  /*                                                                       */
124  /* <Fields>                                                              */
125  /*    root             :: The parent module.                             */
126  /*                                                                       */
127  /*    face_object_size :: The size of a face object in bytes.            */
128  /*                                                                       */
129  /*    size_object_size :: The size of a size object in bytes.            */
130  /*                                                                       */
131  /*    slot_object_size :: The size of a glyph object in bytes.           */
132  /*                                                                       */
133  /*    init_face        :: The format-specific face constructor.          */
134  /*                                                                       */
135  /*    done_face        :: The format-specific face destructor.           */
136  /*                                                                       */
137  /*    init_size        :: The format-specific size constructor.          */
138  /*                                                                       */
139  /*    done_size        :: The format-specific size destructor.           */
140  /*                                                                       */
141  /*    init_slot        :: The format-specific slot constructor.          */
142  /*                                                                       */
143  /*    done_slot        :: The format-specific slot destructor.           */
144  /*                                                                       */
145  /*                                                                       */
146  /*    load_glyph       :: A function handle to load a glyph to a slot.   */
147  /*                        This field is mandatory!                       */
148  /*                                                                       */
149  /*    get_kerning      :: A function handle to return the unscaled       */
150  /*                        kerning for a given pair of glyphs.  Can be    */
151  /*                        set to 0 if the format doesn't support         */
152  /*                        kerning.                                       */
153  /*                                                                       */
154  /*    attach_file      :: This function handle is used to read           */
155  /*                        additional data for a face from another        */
156  /*                        file/stream.  For example, this can be used to */
157  /*                        add data from AFM or PFM files on a Type 1     */
158  /*                        face, or a CIDMap on a CID-keyed face.         */
159  /*                                                                       */
160  /*    get_advances     :: A function handle used to return advance       */
161  /*                        widths of `count' glyphs (in font units),      */
162  /*                        starting at `first'.  The `vertical' flag must */
163  /*                        be set to get vertical advance heights.  The   */
164  /*                        `advances' buffer is caller-allocated.         */
165  /*                        The idea of this function is to be able to     */
166  /*                        perform device-independent text layout without */
167  /*                        loading a single glyph image.                  */
168  /*                                                                       */
169  /*    request_size     :: A handle to a function used to request the new */
170  /*                        character size.  Can be set to 0 if the        */
171  /*                        scaling done in the base layer suffices.       */
172  /*                                                                       */
173  /*    select_size      :: A handle to a function used to select a new    */
174  /*                        fixed size.  It is used only if                */
175  /*                        @FT_FACE_FLAG_FIXED_SIZES is set.  Can be set  */
176  /*                        to 0 if the scaling done in the base layer     */
177  /*                        suffices.                                      */
178  /* <Note>                                                                */
179  /*    Most function pointers, with the exception of `load_glyph', can be */
180  /*    set to 0 to indicate a default behaviour.                          */
181  /*                                                                       */
182  typedef struct  FT_Driver_ClassRec_
183  {
184    FT_Module_Class           root;
185
186    FT_Long                   face_object_size;
187    FT_Long                   size_object_size;
188    FT_Long                   slot_object_size;
189
190    FT_Face_InitFunc          init_face;
191    FT_Face_DoneFunc          done_face;
192
193    FT_Size_InitFunc          init_size;
194    FT_Size_DoneFunc          done_size;
195
196    FT_Slot_InitFunc          init_slot;
197    FT_Slot_DoneFunc          done_slot;
198
199#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
200
201    FT_Size_ResetPointsFunc   set_char_sizes;
202    FT_Size_ResetPixelsFunc   set_pixel_sizes;
203
204#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
205
206    FT_Slot_LoadFunc          load_glyph;
207
208    FT_Face_GetKerningFunc    get_kerning;
209    FT_Face_AttachFunc        attach_file;
210    FT_Face_GetAdvancesFunc   get_advances;
211
212    /* since version 2.2 */
213    FT_Size_RequestFunc       request_size;
214    FT_Size_SelectFunc        select_size;
215
216  } FT_Driver_ClassRec, *FT_Driver_Class;
217
218
219  /*
220   *  The following functions are used as stubs for `set_char_sizes' and
221   *  `set_pixel_sizes'; the code uses `request_size' and `select_size'
222   *  functions instead.
223   *
224   *  Implementation is in `src/base/ftobjs.c'.
225   */
226#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
227
228  FT_BASE( FT_Error )
229  ft_stub_set_char_sizes( FT_Size     size,
230                          FT_F26Dot6  width,
231                          FT_F26Dot6  height,
232                          FT_UInt     horz_res,
233                          FT_UInt     vert_res );
234
235  FT_BASE( FT_Error )
236  ft_stub_set_pixel_sizes( FT_Size  size,
237                           FT_UInt  width,
238                           FT_UInt  height );
239
240#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
241
242  /*************************************************************************/
243  /*                                                                       */
244  /* <Macro>                                                               */
245  /*    FT_DECLARE_DRIVER                                                  */
246  /*                                                                       */
247  /* <Description>                                                         */
248  /*    Used to create a forward declaration of a                          */
249  /*    FT_Driver_ClassRec stract instance.                                */
250  /*                                                                       */
251  /* <Macro>                                                               */
252  /*    FT_DEFINE_DRIVER                                                   */
253  /*                                                                       */
254  /* <Description>                                                         */
255  /*    Used to initialize an instance of FT_Driver_ClassRec struct.       */
256  /*                                                                       */
257  /*    When FT_CONFIG_OPTION_PIC is defined a Create funtion will need    */
258  /*    to called with a pointer where the allocated stracture is returned.*/
259  /*    And when it is no longer needed a Destroy function needs           */
260  /*    to be called to release that allocation.                           */
261  /*    fcinit.c (ft_create_default_module_classes) already contains       */
262  /*    a mechanism to call these functions for the default modules        */
263  /*    described in ftmodule.h                                            */
264  /*                                                                       */
265  /*    Notice that the created Create and Destroy functions call          */
266  /*    pic_init and pic_free function to allow you to manually allocate   */
267  /*    and initialize any additional global data, like module specific    */
268  /*    interface, and put them in the global pic container defined in     */
269  /*    ftpic.h. if you don't need them just implement the functions as    */
270  /*    empty to resolve the link error.  Also the pic_init and pic_free   */
271  /*    functions should be declared in pic.h, to be referred by driver    */
272  /*    definition calling FT_DEFINE_DRIVER() in following.                */
273  /*                                                                       */
274  /*    When FT_CONFIG_OPTION_PIC is not defined the struct will be        */
275  /*    allocated in the global scope (or the scope where the macro        */
276  /*    is used).                                                          */
277  /*                                                                       */
278#ifndef FT_CONFIG_OPTION_PIC
279
280#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
281#define FT_DEFINE_DRIVERS_OLD_INTERNALS(a_,b_) \
282  a_, b_,
283#else
284  #define FT_DEFINE_DRIVERS_OLD_INTERNALS(a_,b_)
285#endif
286
287#define FT_DECLARE_DRIVER(class_)    \
288  FT_CALLBACK_TABLE                  \
289  const FT_Driver_ClassRec  class_;
290
291#define FT_DEFINE_DRIVER(class_,                                             \
292                         flags_, size_, name_, version_, requires_,          \
293                         interface_, init_, done_, get_interface_,           \
294                         face_object_size_, size_object_size_,               \
295                         slot_object_size_, init_face_, done_face_,          \
296                         init_size_, done_size_, init_slot_, done_slot_,     \
297                         old_set_char_sizes_, old_set_pixel_sizes_,          \
298                         load_glyph_, get_kerning_, attach_file_,            \
299                         get_advances_, request_size_, select_size_ )        \
300  FT_CALLBACK_TABLE_DEF                                                      \
301  const FT_Driver_ClassRec class_ =                                          \
302  {                                                                          \
303    FT_DEFINE_ROOT_MODULE(flags_,size_,name_,version_,requires_,interface_,  \
304                          init_,done_,get_interface_)                        \
305                                                                             \
306    face_object_size_,                                                       \
307    size_object_size_,                                                       \
308    slot_object_size_,                                                       \
309                                                                             \
310    init_face_,                                                              \
311    done_face_,                                                              \
312                                                                             \
313    init_size_,                                                              \
314    done_size_,                                                              \
315                                                                             \
316    init_slot_,                                                              \
317    done_slot_,                                                              \
318                                                                             \
319    FT_DEFINE_DRIVERS_OLD_INTERNALS(old_set_char_sizes_, old_set_pixel_sizes_) \
320                                                                             \
321    load_glyph_,                                                             \
322                                                                             \
323    get_kerning_,                                                            \
324    attach_file_,                                                            \
325    get_advances_,                                                           \
326                                                                             \
327    request_size_,                                                           \
328    select_size_                                                             \
329  };
330
331#else /* FT_CONFIG_OPTION_PIC */
332
333#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
334#define FT_DEFINE_DRIVERS_OLD_INTERNALS(a_,b_) \
335  clazz->set_char_sizes = a_; \
336  clazz->set_pixel_sizes = b_;
337#else
338  #define FT_DEFINE_DRIVERS_OLD_INTERNALS(a_,b_)
339#endif
340
341#define FT_DECLARE_DRIVER(class_)    FT_DECLARE_MODULE(class_)
342
343#define FT_DEFINE_DRIVER(class_,                                             \
344                         flags_, size_, name_, version_, requires_,          \
345                         interface_, init_, done_, get_interface_,           \
346                         face_object_size_, size_object_size_,               \
347                         slot_object_size_, init_face_, done_face_,          \
348                         init_size_, done_size_, init_slot_, done_slot_,     \
349                         old_set_char_sizes_, old_set_pixel_sizes_,          \
350                         load_glyph_, get_kerning_, attach_file_,            \
351                         get_advances_, request_size_, select_size_ )        \
352                                                                             \
353  void                                                                       \
354  FT_Destroy_Class_##class_( FT_Library        library,                      \
355                             FT_Module_Class*  clazz )                       \
356  {                                                                          \
357    FT_Memory       memory = library->memory;                                \
358    FT_Driver_Class dclazz = (FT_Driver_Class)clazz;                         \
359    class_##_pic_free( library );                                            \
360    if ( dclazz )                                                            \
361      FT_FREE( dclazz );                                                     \
362  }                                                                          \
363                                                                             \
364  FT_Error                                                                   \
365  FT_Create_Class_##class_( FT_Library        library,                       \
366                            FT_Module_Class**  output_class )                \
367  {                                                                          \
368    FT_Driver_Class  clazz;                                                  \
369    FT_Error         error;                                                  \
370    FT_Memory        memory = library->memory;                               \
371                                                                             \
372    if ( FT_ALLOC( clazz, sizeof(*clazz) ) )                                 \
373      return error;                                                          \
374                                                                             \
375    error = class_##_pic_init( library );                                    \
376    if(error)                                                                \
377    {                                                                        \
378      FT_FREE( clazz );                                                      \
379      return error;                                                          \
380    }                                                                        \
381                                                                             \
382    FT_DEFINE_ROOT_MODULE(flags_,size_,name_,version_,requires_,interface_,  \
383                          init_,done_,get_interface_)                        \
384                                                                             \
385    clazz->face_object_size    = face_object_size_;                          \
386    clazz->size_object_size    = size_object_size_;                          \
387    clazz->slot_object_size    = slot_object_size_;                          \
388                                                                             \
389    clazz->init_face           = init_face_;                                 \
390    clazz->done_face           = done_face_;                                 \
391                                                                             \
392    clazz->init_size           = init_size_;                                 \
393    clazz->done_size           = done_size_;                                 \
394                                                                             \
395    clazz->init_slot           = init_slot_;                                 \
396    clazz->done_slot           = done_slot_;                                 \
397                                                                             \
398    FT_DEFINE_DRIVERS_OLD_INTERNALS(old_set_char_sizes_, old_set_pixel_sizes_) \
399                                                                             \
400    clazz->load_glyph          = load_glyph_;                                \
401                                                                             \
402    clazz->get_kerning         = get_kerning_;                               \
403    clazz->attach_file         = attach_file_;                               \
404    clazz->get_advances        = get_advances_;                              \
405                                                                             \
406    clazz->request_size        = request_size_;                              \
407    clazz->select_size         = select_size_;                               \
408                                                                             \
409    *output_class = (FT_Module_Class*)clazz;                                 \
410    return FT_Err_Ok;                                                        \
411  }
412
413
414#endif /* FT_CONFIG_OPTION_PIC */
415
416FT_END_HEADER
417
418#endif /* __FTDRIVER_H__ */
419
420
421/* END */
422