1 /***************************************************************************/ 2 /* */ 3 /* ftdrv.h */ 4 /* */ 5 /* FreeType internal font driver interface (specification). */ 6 /* */ 7 /* Copyright 1996-2018 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 <ft2build.h> 24 #include FT_MODULE_H 25 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 :: The parent module. */ 101 /* */ 102 /* face_object_size :: The size of a face object in bytes. */ 103 /* */ 104 /* size_object_size :: The size of a size object in bytes. */ 105 /* */ 106 /* slot_object_size :: The size of a glyph object in bytes. */ 107 /* */ 108 /* init_face :: The format-specific face constructor. */ 109 /* */ 110 /* done_face :: The format-specific face destructor. */ 111 /* */ 112 /* init_size :: The format-specific size constructor. */ 113 /* */ 114 /* done_size :: The format-specific size destructor. */ 115 /* */ 116 /* init_slot :: The format-specific slot constructor. */ 117 /* */ 118 /* done_slot :: The format-specific slot destructor. */ 119 /* */ 120 /* */ 121 /* load_glyph :: A function handle to load a glyph to a slot. */ 122 /* This field is mandatory! */ 123 /* */ 124 /* get_kerning :: A function handle to return the unscaled */ 125 /* kerning for a given pair of glyphs. Can be */ 126 /* set to 0 if the format doesn't support */ 127 /* kerning. */ 128 /* */ 129 /* attach_file :: This function handle is used to read */ 130 /* additional data for a face from another */ 131 /* file/stream. For example, this can be used to */ 132 /* add data from AFM or PFM files on a Type 1 */ 133 /* face, or a CIDMap on a CID-keyed face. */ 134 /* */ 135 /* get_advances :: A function handle used to return advance */ 136 /* widths of `count' glyphs (in font units), */ 137 /* starting at `first'. The `vertical' flag must */ 138 /* be set to get vertical advance heights. The */ 139 /* `advances' buffer is caller-allocated. */ 140 /* The idea of this function is to be able to */ 141 /* perform device-independent text layout without */ 142 /* loading a single glyph image. */ 143 /* */ 144 /* request_size :: A handle to a function used to request the new */ 145 /* character size. Can be set to 0 if the */ 146 /* scaling done in the base layer suffices. */ 147 /* */ 148 /* select_size :: A handle to a function used to select a new */ 149 /* fixed size. It is used only if */ 150 /* @FT_FACE_FLAG_FIXED_SIZES is set. Can be set */ 151 /* to 0 if the scaling done in the base layer */ 152 /* suffices. */ 153 /* <Note> */ 154 /* Most function pointers, with the exception of `load_glyph', can be */ 155 /* set to 0 to indicate a default behaviour. */ 156 /* */ 157 typedef struct FT_Driver_ClassRec_ 158 { 159 FT_Module_Class root; 160 161 FT_Long face_object_size; 162 FT_Long size_object_size; 163 FT_Long slot_object_size; 164 165 FT_Face_InitFunc init_face; 166 FT_Face_DoneFunc done_face; 167 168 FT_Size_InitFunc init_size; 169 FT_Size_DoneFunc done_size; 170 171 FT_Slot_InitFunc init_slot; 172 FT_Slot_DoneFunc done_slot; 173 174 FT_Slot_LoadFunc load_glyph; 175 176 FT_Face_GetKerningFunc get_kerning; 177 FT_Face_AttachFunc attach_file; 178 FT_Face_GetAdvancesFunc get_advances; 179 180 /* since version 2.2 */ 181 FT_Size_RequestFunc request_size; 182 FT_Size_SelectFunc select_size; 183 184 } FT_Driver_ClassRec, *FT_Driver_Class; 185 186 187 /*************************************************************************/ 188 /* */ 189 /* <Macro> */ 190 /* FT_DECLARE_DRIVER */ 191 /* */ 192 /* <Description> */ 193 /* Used to create a forward declaration of an FT_Driver_ClassRec */ 194 /* struct instance. */ 195 /* */ 196 /* <Macro> */ 197 /* FT_DEFINE_DRIVER */ 198 /* */ 199 /* <Description> */ 200 /* Used to initialize an instance of FT_Driver_ClassRec struct. */ 201 /* */ 202 /* When FT_CONFIG_OPTION_PIC is defined a `create' function has to be */ 203 /* called with a pointer where the allocated structure is returned. */ 204 /* And when it is no longer needed a `destroy' function needs to be */ 205 /* called to release that allocation. */ 206 /* */ 207 /* `ftinit.c' (ft_create_default_module_classes) already contains a */ 208 /* mechanism to call these functions for the default modules */ 209 /* described in `ftmodule.h'. */ 210 /* */ 211 /* Notice that the created `create' and `destroy' functions call */ 212 /* `pic_init' and `pic_free' to allow you to manually allocate and */ 213 /* initialize any additional global data, like a module specific */ 214 /* interface, and put them in the global pic container defined in */ 215 /* `ftpic.h'. If you don't need them just implement the functions as */ 216 /* empty to resolve the link error. Also the `pic_init' and */ 217 /* `pic_free' functions should be declared in `pic.h', to be referred */ 218 /* by driver definition calling `FT_DEFINE_DRIVER' in following. */ 219 /* */ 220 /* When FT_CONFIG_OPTION_PIC is not defined the struct will be */ 221 /* allocated in the global scope (or the scope where the macro is */ 222 /* used). */ 223 /* */ 224 #ifndef FT_CONFIG_OPTION_PIC 225 226 #define FT_DECLARE_DRIVER( class_ ) \ 227 FT_CALLBACK_TABLE \ 228 const FT_Driver_ClassRec class_; 229 230 #define FT_DEFINE_DRIVER( \ 231 class_, \ 232 flags_, \ 233 size_, \ 234 name_, \ 235 version_, \ 236 requires_, \ 237 interface_, \ 238 init_, \ 239 done_, \ 240 get_interface_, \ 241 face_object_size_, \ 242 size_object_size_, \ 243 slot_object_size_, \ 244 init_face_, \ 245 done_face_, \ 246 init_size_, \ 247 done_size_, \ 248 init_slot_, \ 249 done_slot_, \ 250 load_glyph_, \ 251 get_kerning_, \ 252 attach_file_, \ 253 get_advances_, \ 254 request_size_, \ 255 select_size_ ) \ 256 FT_CALLBACK_TABLE_DEF \ 257 const FT_Driver_ClassRec class_ = \ 258 { \ 259 FT_DEFINE_ROOT_MODULE( flags_, \ 260 size_, \ 261 name_, \ 262 version_, \ 263 requires_, \ 264 interface_, \ 265 init_, \ 266 done_, \ 267 get_interface_ ) \ 268 \ 269 face_object_size_, \ 270 size_object_size_, \ 271 slot_object_size_, \ 272 \ 273 init_face_, \ 274 done_face_, \ 275 \ 276 init_size_, \ 277 done_size_, \ 278 \ 279 init_slot_, \ 280 done_slot_, \ 281 \ 282 load_glyph_, \ 283 \ 284 get_kerning_, \ 285 attach_file_, \ 286 get_advances_, \ 287 \ 288 request_size_, \ 289 select_size_ \ 290 }; 291 292 #else /* FT_CONFIG_OPTION_PIC */ 293 294 #define FT_DECLARE_DRIVER( class_ ) FT_DECLARE_MODULE( class_ ) 295 296 #define FT_DEFINE_DRIVER( \ 297 class_, \ 298 flags_, \ 299 size_, \ 300 name_, \ 301 version_, \ 302 requires_, \ 303 interface_, \ 304 init_, \ 305 done_, \ 306 get_interface_, \ 307 face_object_size_, \ 308 size_object_size_, \ 309 slot_object_size_, \ 310 init_face_, \ 311 done_face_, \ 312 init_size_, \ 313 done_size_, \ 314 init_slot_, \ 315 done_slot_, \ 316 load_glyph_, \ 317 get_kerning_, \ 318 attach_file_, \ 319 get_advances_, \ 320 request_size_, \ 321 select_size_ ) \ 322 void \ 323 FT_Destroy_Class_ ## class_( FT_Library library, \ 324 FT_Module_Class* clazz ) \ 325 { \ 326 FT_Memory memory = library->memory; \ 327 FT_Driver_Class dclazz = (FT_Driver_Class)clazz; \ 328 \ 329 \ 330 class_ ## _pic_free( library ); \ 331 if ( dclazz ) \ 332 FT_FREE( dclazz ); \ 333 } \ 334 \ 335 \ 336 FT_Error \ 337 FT_Create_Class_ ## class_( FT_Library library, \ 338 FT_Module_Class** output_class ) \ 339 { \ 340 FT_Driver_Class clazz = NULL; \ 341 FT_Error error; \ 342 FT_Memory memory = library->memory; \ 343 \ 344 \ 345 if ( FT_ALLOC( clazz, sizeof ( *clazz ) ) ) \ 346 return error; \ 347 \ 348 error = class_ ## _pic_init( library ); \ 349 if ( error ) \ 350 { \ 351 FT_FREE( clazz ); \ 352 return error; \ 353 } \ 354 \ 355 FT_DEFINE_ROOT_MODULE( flags_, \ 356 size_, \ 357 name_, \ 358 version_, \ 359 requires_, \ 360 interface_, \ 361 init_, \ 362 done_, \ 363 get_interface_ ) \ 364 \ 365 clazz->face_object_size = face_object_size_; \ 366 clazz->size_object_size = size_object_size_; \ 367 clazz->slot_object_size = slot_object_size_; \ 368 \ 369 clazz->init_face = init_face_; \ 370 clazz->done_face = done_face_; \ 371 \ 372 clazz->init_size = init_size_; \ 373 clazz->done_size = done_size_; \ 374 \ 375 clazz->init_slot = init_slot_; \ 376 clazz->done_slot = done_slot_; \ 377 \ 378 clazz->load_glyph = load_glyph_; \ 379 \ 380 clazz->get_kerning = get_kerning_; \ 381 clazz->attach_file = attach_file_; \ 382 clazz->get_advances = get_advances_; \ 383 \ 384 clazz->request_size = request_size_; \ 385 clazz->select_size = select_size_; \ 386 \ 387 *output_class = (FT_Module_Class*)clazz; \ 388 \ 389 return FT_Err_Ok; \ 390 } 391 392 393 #endif /* FT_CONFIG_OPTION_PIC */ 394 395 FT_END_HEADER 396 397 #endif /* FTDRV_H_ */ 398 399 400 /* END */ 401