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