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