• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  *
3  * ftdrv.h
4  *
5  *   FreeType internal font driver interface (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 #ifndef FTDRV_H_
20 #define FTDRV_H_
21 
22 
23 #include <freetype/ftmodapi.h>
24 
25 #include "compiler-macros.h"
26 
27 FT_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   typedef FT_Error
64   (*FT_Slot_LoadFunc)( FT_GlyphSlot  slot,
65                        FT_Size       size,
66                        FT_UInt       glyph_index,
67                        FT_Int32      load_flags );
68 
69 
70   typedef FT_Error
71   (*FT_Face_GetKerningFunc)( FT_Face     face,
72                              FT_UInt     left_glyph,
73                              FT_UInt     right_glyph,
74                              FT_Vector*  kerning );
75 
76 
77   typedef FT_Error
78   (*FT_Face_AttachFunc)( FT_Face    face,
79                          FT_Stream  stream );
80 
81 
82   typedef FT_Error
83   (*FT_Face_GetAdvancesFunc)( FT_Face    face,
84                               FT_UInt    first,
85                               FT_UInt    count,
86                               FT_Int32   flags,
87                               FT_Fixed*  advances );
88 
89 
90   /**************************************************************************
91    *
92    * @struct:
93    *   FT_Driver_ClassRec
94    *
95    * @description:
96    *   The font driver class.  This structure mostly contains pointers to
97    *   driver methods.
98    *
99    * @fields:
100    *   root ::
101    *     The parent module.
102    *
103    *   face_object_size ::
104    *     The size of a face object in bytes.
105    *
106    *   size_object_size ::
107    *     The size of a size object in bytes.
108    *
109    *   slot_object_size ::
110    *     The size of a glyph object in bytes.
111    *
112    *   init_face ::
113    *     The format-specific face constructor.
114    *
115    *   done_face ::
116    *     The format-specific face destructor.
117    *
118    *   init_size ::
119    *     The format-specific size constructor.
120    *
121    *   done_size ::
122    *     The format-specific size destructor.
123    *
124    *   init_slot ::
125    *     The format-specific slot constructor.
126    *
127    *   done_slot ::
128    *     The format-specific slot destructor.
129    *
130    *
131    *   load_glyph ::
132    *     A function handle to load a glyph to a slot.  This field is
133    *     mandatory!
134    *
135    *   get_kerning ::
136    *     A function handle to return the unscaled kerning for a given pair of
137    *     glyphs.  Can be set to 0 if the format doesn't support kerning.
138    *
139    *   attach_file ::
140    *     This function handle is used to read additional data for a face from
141    *     another file/stream.  For example, this can be used to add data from
142    *     AFM or PFM files on a Type 1 face, or a CIDMap on a CID-keyed face.
143    *
144    *   get_advances ::
145    *     A function handle used to return advance widths of 'count' glyphs
146    *     (in font units), starting at 'first'.  The 'vertical' flag must be
147    *     set to get vertical advance heights.  The 'advances' buffer is
148    *     caller-allocated.  The idea of this function is to be able to
149    *     perform device-independent text layout without loading a single
150    *     glyph image.
151    *
152    *   request_size ::
153    *     A handle to a function used to request the new character size.  Can
154    *     be set to 0 if the scaling done in the base layer suffices.
155    *
156    *   select_size ::
157    *     A handle to a function used to select a new fixed size.  It is used
158    *     only if @FT_FACE_FLAG_FIXED_SIZES is set.  Can be set to 0 if the
159    *     scaling done in the base layer suffices.
160    *
161    * @note:
162    *   Most function pointers, with the exception of `load_glyph`, can be set
163    *   to 0 to indicate a default behaviour.
164    */
165   typedef struct  FT_Driver_ClassRec_
166   {
167     FT_Module_Class          root;
168 
169     FT_Long                  face_object_size;
170     FT_Long                  size_object_size;
171     FT_Long                  slot_object_size;
172 
173     FT_Face_InitFunc         init_face;
174     FT_Face_DoneFunc         done_face;
175 
176     FT_Size_InitFunc         init_size;
177     FT_Size_DoneFunc         done_size;
178 
179     FT_Slot_InitFunc         init_slot;
180     FT_Slot_DoneFunc         done_slot;
181 
182     FT_Slot_LoadFunc         load_glyph;
183 
184     FT_Face_GetKerningFunc   get_kerning;
185     FT_Face_AttachFunc       attach_file;
186     FT_Face_GetAdvancesFunc  get_advances;
187 
188     /* since version 2.2 */
189     FT_Size_RequestFunc      request_size;
190     FT_Size_SelectFunc       select_size;
191 
192   } FT_Driver_ClassRec, *FT_Driver_Class;
193 
194 
195   /**************************************************************************
196    *
197    * @macro:
198    *   FT_DECLARE_DRIVER
199    *
200    * @description:
201    *   Used to create a forward declaration of an FT_Driver_ClassRec struct
202    *   instance.
203    *
204    * @macro:
205    *   FT_DEFINE_DRIVER
206    *
207    * @description:
208    *   Used to initialize an instance of FT_Driver_ClassRec struct.
209    *
210    *   `ftinit.c` (ft_create_default_module_classes) already contains a
211    *   mechanism to call these functions for the default modules described in
212    *   `ftmodule.h`.
213    *
214    *   The struct will be allocated in the global scope (or the scope where
215    *   the macro is used).
216    */
217 #define FT_DECLARE_DRIVER( class_ )  \
218   FT_CALLBACK_TABLE                  \
219   const FT_Driver_ClassRec  class_;
220 
221 #define FT_DEFINE_DRIVER(                    \
222           class_,                            \
223           flags_,                            \
224           size_,                             \
225           name_,                             \
226           version_,                          \
227           requires_,                         \
228           interface_,                        \
229           init_,                             \
230           done_,                             \
231           get_interface_,                    \
232           face_object_size_,                 \
233           size_object_size_,                 \
234           slot_object_size_,                 \
235           init_face_,                        \
236           done_face_,                        \
237           init_size_,                        \
238           done_size_,                        \
239           init_slot_,                        \
240           done_slot_,                        \
241           load_glyph_,                       \
242           get_kerning_,                      \
243           attach_file_,                      \
244           get_advances_,                     \
245           request_size_,                     \
246           select_size_ )                     \
247   FT_CALLBACK_TABLE_DEF                      \
248   const FT_Driver_ClassRec  class_ =         \
249   {                                          \
250     FT_DEFINE_ROOT_MODULE( flags_,           \
251                            size_,            \
252                            name_,            \
253                            version_,         \
254                            requires_,        \
255                            interface_,       \
256                            init_,            \
257                            done_,            \
258                            get_interface_ )  \
259                                              \
260     face_object_size_,                       \
261     size_object_size_,                       \
262     slot_object_size_,                       \
263                                              \
264     init_face_,                              \
265     done_face_,                              \
266                                              \
267     init_size_,                              \
268     done_size_,                              \
269                                              \
270     init_slot_,                              \
271     done_slot_,                              \
272                                              \
273     load_glyph_,                             \
274                                              \
275     get_kerning_,                            \
276     attach_file_,                            \
277     get_advances_,                           \
278                                              \
279     request_size_,                           \
280     select_size_                             \
281   };
282 
283 
284 FT_END_HEADER
285 
286 #endif /* FTDRV_H_ */
287 
288 
289 /* END */
290