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