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