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_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' 77 * algorithm. We use alpha = 1, beta = 3/8, giving us results with a 78 * largest error less than 7% compared to the exact value. 79 */ 80 #define FT_HYPOT( x, y ) \ 81 ( x = FT_ABS( x ), \ 82 y = FT_ABS( y ), \ 83 x > y ? x + ( 3 * y >> 3 ) \ 84 : y + ( 3 * x >> 3 ) ) 85 86 /* we use 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 114 * font files, we must not use those in <ctypes.h> which are 115 * locale-dependent 116 */ 117 #define ft_isdigit( x ) ( ( (unsigned)(x) - '0' ) < 10U ) 118 119 #define ft_isxdigit( x ) ( ( (unsigned)(x) - '0' ) < 10U || \ 120 ( (unsigned)(x) - 'a' ) < 6U || \ 121 ( (unsigned)(x) - 'A' ) < 6U ) 122 123 /* the next two macros assume ASCII representation */ 124 #define ft_isupper( x ) ( ( (unsigned)(x) - 'A' ) < 26U ) 125 #define ft_islower( x ) ( ( (unsigned)(x) - 'a' ) < 26U ) 126 127 #define ft_isalpha( x ) ( ft_isupper( x ) || ft_islower( x ) ) 128 #define ft_isalnum( x ) ( ft_isdigit( x ) || ft_isalpha( x ) ) 129 130 131 /*************************************************************************/ 132 /*************************************************************************/ 133 /*************************************************************************/ 134 /**** ****/ 135 /**** ****/ 136 /**** C H A R M A P S ****/ 137 /**** ****/ 138 /**** ****/ 139 /*************************************************************************/ 140 /*************************************************************************/ 141 /*************************************************************************/ 142 143 /* handle to internal charmap object */ 144 typedef struct FT_CMapRec_* FT_CMap; 145 146 /* handle to charmap class structure */ 147 typedef const struct FT_CMap_ClassRec_* FT_CMap_Class; 148 149 /* internal charmap object structure */ 150 typedef struct FT_CMapRec_ 151 { 152 FT_CharMapRec charmap; 153 FT_CMap_Class clazz; 154 155 } FT_CMapRec; 156 157 /* typecast any pointer to a charmap handle */ 158 #define FT_CMAP( x ) ( (FT_CMap)( x ) ) 159 160 /* obvious macros */ 161 #define FT_CMAP_PLATFORM_ID( x ) FT_CMAP( x )->charmap.platform_id 162 #define FT_CMAP_ENCODING_ID( x ) FT_CMAP( x )->charmap.encoding_id 163 #define FT_CMAP_ENCODING( x ) FT_CMAP( x )->charmap.encoding 164 #define FT_CMAP_FACE( x ) FT_CMAP( x )->charmap.face 165 166 167 /* class method definitions */ 168 typedef FT_Error 169 (*FT_CMap_InitFunc)( FT_CMap cmap, 170 FT_Pointer init_data ); 171 172 typedef void 173 (*FT_CMap_DoneFunc)( FT_CMap cmap ); 174 175 typedef FT_UInt 176 (*FT_CMap_CharIndexFunc)( FT_CMap cmap, 177 FT_UInt32 char_code ); 178 179 typedef FT_UInt 180 (*FT_CMap_CharNextFunc)( FT_CMap cmap, 181 FT_UInt32 *achar_code ); 182 183 typedef FT_UInt 184 (*FT_CMap_CharVarIndexFunc)( FT_CMap cmap, 185 FT_CMap unicode_cmap, 186 FT_UInt32 char_code, 187 FT_UInt32 variant_selector ); 188 189 typedef FT_Bool 190 (*FT_CMap_CharVarIsDefaultFunc)( FT_CMap cmap, 191 FT_UInt32 char_code, 192 FT_UInt32 variant_selector ); 193 194 typedef FT_UInt32 * 195 (*FT_CMap_VariantListFunc)( FT_CMap cmap, 196 FT_Memory mem ); 197 198 typedef FT_UInt32 * 199 (*FT_CMap_CharVariantListFunc)( FT_CMap cmap, 200 FT_Memory mem, 201 FT_UInt32 char_code ); 202 203 typedef FT_UInt32 * 204 (*FT_CMap_VariantCharListFunc)( FT_CMap cmap, 205 FT_Memory mem, 206 FT_UInt32 variant_selector ); 207 208 209 typedef struct FT_CMap_ClassRec_ 210 { 211 FT_ULong size; 212 213 FT_CMap_InitFunc init; 214 FT_CMap_DoneFunc done; 215 FT_CMap_CharIndexFunc char_index; 216 FT_CMap_CharNextFunc char_next; 217 218 /* Subsequent entries are special ones for format 14 -- the variant */ 219 /* selector subtable which behaves like no other */ 220 221 FT_CMap_CharVarIndexFunc char_var_index; 222 FT_CMap_CharVarIsDefaultFunc char_var_default; 223 FT_CMap_VariantListFunc variant_list; 224 FT_CMap_CharVariantListFunc charvariant_list; 225 FT_CMap_VariantCharListFunc variantchar_list; 226 227 } FT_CMap_ClassRec; 228 229 230 #define FT_DECLARE_CMAP_CLASS( class_ ) \ 231 FT_CALLBACK_TABLE const FT_CMap_ClassRec class_; 232 233 #define FT_DEFINE_CMAP_CLASS( \ 234 class_, \ 235 size_, \ 236 init_, \ 237 done_, \ 238 char_index_, \ 239 char_next_, \ 240 char_var_index_, \ 241 char_var_default_, \ 242 variant_list_, \ 243 charvariant_list_, \ 244 variantchar_list_ ) \ 245 FT_CALLBACK_TABLE_DEF \ 246 const FT_CMap_ClassRec class_ = \ 247 { \ 248 size_, \ 249 init_, \ 250 done_, \ 251 char_index_, \ 252 char_next_, \ 253 char_var_index_, \ 254 char_var_default_, \ 255 variant_list_, \ 256 charvariant_list_, \ 257 variantchar_list_ \ 258 }; 259 260 261 /* create a new charmap and add it to charmap->face */ 262 FT_BASE( FT_Error ) 263 FT_CMap_New( FT_CMap_Class clazz, 264 FT_Pointer init_data, 265 FT_CharMap charmap, 266 FT_CMap *acmap ); 267 268 /* destroy a charmap and remove it from face's list */ 269 FT_BASE( void ) 270 FT_CMap_Done( FT_CMap cmap ); 271 272 273 /* add LCD padding to CBox */ 274 FT_BASE( void ) 275 ft_lcd_padding( FT_BBox* cbox, 276 FT_GlyphSlot slot, 277 FT_Render_Mode mode ); 278 279 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING 280 281 typedef void (*FT_Bitmap_LcdFilterFunc)( FT_Bitmap* bitmap, 282 FT_Render_Mode render_mode, 283 FT_Byte* weights ); 284 285 286 /* This is the default LCD filter, an in-place, 5-tap FIR filter. */ 287 FT_BASE( void ) 288 ft_lcd_filter_fir( FT_Bitmap* bitmap, 289 FT_Render_Mode mode, 290 FT_LcdFiveTapFilter weights ); 291 292 #endif /* FT_CONFIG_OPTION_SUBPIXEL_RENDERING */ 293 294 /************************************************************************** 295 * 296 * @struct: 297 * FT_Face_InternalRec 298 * 299 * @description: 300 * This structure contains the internal fields of each FT_Face 301 * object. These fields may change between different releases of 302 * FreeType. 303 * 304 * @fields: 305 * max_points :: 306 * The maximum number of points used to store the vectorial outline 307 * of any glyph in this face. If this value cannot be known in 308 * advance, or if the face isn't scalable, this should be set to 0. 309 * Only relevant for scalable formats. 310 * 311 * max_contours :: 312 * The maximum number of contours used to store the vectorial 313 * outline of any glyph in this face. If this value cannot be 314 * known in advance, or if the face isn't scalable, this should be 315 * set to 0. Only relevant for scalable formats. 316 * 317 * transform_matrix :: 318 * A 2x2 matrix of 16.16 coefficients used to transform glyph 319 * outlines after they are loaded from the font. Only used by the 320 * convenience functions. 321 * 322 * transform_delta :: 323 * A translation vector used to transform glyph outlines after they 324 * are loaded from the font. Only used by the convenience 325 * functions. 326 * 327 * transform_flags :: 328 * Some flags used to classify the transform. Only used by the 329 * convenience functions. 330 * 331 * services :: 332 * A cache for frequently used services. It should be only 333 * accessed with the macro `FT_FACE_LOOKUP_SERVICE'. 334 * 335 * incremental_interface :: 336 * If non-null, the interface through which glyph data and metrics 337 * are loaded incrementally for faces that do not provide all of 338 * this data when first opened. This field exists only if 339 * @FT_CONFIG_OPTION_INCREMENTAL is defined. 340 * 341 * no_stem_darkening :: 342 * Overrides the module-level default, see @stem-darkening[cff], 343 * for example. FALSE and TRUE toggle stem darkening on and off, 344 * respectively, value~-1 means to use the module/driver default. 345 * 346 * random_seed :: 347 * If positive, override the seed value for the CFF `random' 348 * operator. Value~0 means to use the font's value. Value~-1 349 * means to use the CFF driver's default. 350 * 351 * lcd_weights :: 352 * lcd_filter_func :: 353 * These fields specify the LCD filtering weights and callback 354 * function for ClearType-style subpixel rendering. 355 * 356 * refcount :: 357 * A counter initialized to~1 at the time an @FT_Face structure is 358 * created. @FT_Reference_Face increments this counter, and 359 * @FT_Done_Face only destroys a face if the counter is~1, 360 * otherwise it simply decrements it. 361 */ 362 typedef struct FT_Face_InternalRec_ 363 { 364 FT_Matrix transform_matrix; 365 FT_Vector transform_delta; 366 FT_Int transform_flags; 367 368 FT_ServiceCacheRec services; 369 370 #ifdef FT_CONFIG_OPTION_INCREMENTAL 371 FT_Incremental_InterfaceRec* incremental_interface; 372 #endif 373 374 FT_Char no_stem_darkening; 375 FT_Int32 random_seed; 376 377 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING 378 FT_LcdFiveTapFilter lcd_weights; /* filter weights, if any */ 379 FT_Bitmap_LcdFilterFunc lcd_filter_func; /* filtering callback */ 380 #endif 381 382 FT_Int refcount; 383 384 } FT_Face_InternalRec; 385 386 387 /************************************************************************** 388 * 389 * @struct: 390 * FT_Slot_InternalRec 391 * 392 * @description: 393 * This structure contains the internal fields of each FT_GlyphSlot 394 * object. These fields may change between different releases of 395 * FreeType. 396 * 397 * @fields: 398 * loader :: 399 * The glyph loader object used to load outlines 400 * into the glyph slot. 401 * 402 * flags :: 403 * Possible values are zero or 404 * FT_GLYPH_OWN_BITMAP. The latter indicates 405 * that the FT_GlyphSlot structure owns the 406 * bitmap buffer. 407 * 408 * glyph_transformed :: 409 * Boolean. Set to TRUE when the loaded glyph 410 * must be transformed through a specific 411 * font transformation. This is _not_ the same 412 * as the face transform set through 413 * FT_Set_Transform(). 414 * 415 * glyph_matrix :: 416 * The 2x2 matrix corresponding to the glyph 417 * transformation, if necessary. 418 * 419 * glyph_delta :: 420 * The 2d translation vector corresponding to 421 * the glyph transformation, if necessary. 422 * 423 * glyph_hints :: 424 * Format-specific glyph hints management. 425 * 426 * load_flags :: 427 * The load flags passed as an argument to @FT_Load_Glyph while 428 * initializing the glyph slot. 429 */ 430 431 #define FT_GLYPH_OWN_BITMAP 0x1U 432 433 typedef struct FT_Slot_InternalRec_ 434 { 435 FT_GlyphLoader loader; 436 FT_UInt flags; 437 FT_Bool glyph_transformed; 438 FT_Matrix glyph_matrix; 439 FT_Vector glyph_delta; 440 void* glyph_hints; 441 442 FT_Int32 load_flags; 443 444 } FT_GlyphSlot_InternalRec; 445 446 447 /************************************************************************** 448 * 449 * @struct: 450 * FT_Size_InternalRec 451 * 452 * @description: 453 * This structure contains the internal fields of each FT_Size 454 * object. 455 * 456 * @fields: 457 * module_data :: 458 * Data specific to a driver module. 459 * 460 * autohint_mode :: 461 * The used auto-hinting mode. 462 * 463 * autohint_metrics :: 464 * Metrics used by the auto-hinter. 465 * 466 */ 467 468 typedef struct FT_Size_InternalRec_ 469 { 470 void* module_data; 471 472 FT_Render_Mode autohint_mode; 473 FT_Size_Metrics autohint_metrics; 474 475 } FT_Size_InternalRec; 476 477 478 /*************************************************************************/ 479 /*************************************************************************/ 480 /*************************************************************************/ 481 /**** ****/ 482 /**** ****/ 483 /**** M O D U L E S ****/ 484 /**** ****/ 485 /**** ****/ 486 /*************************************************************************/ 487 /*************************************************************************/ 488 /*************************************************************************/ 489 490 491 /************************************************************************** 492 * 493 * @struct: 494 * FT_ModuleRec 495 * 496 * @description: 497 * A module object instance. 498 * 499 * @fields: 500 * clazz :: 501 * A pointer to the module's class. 502 * 503 * library :: 504 * A handle to the parent library object. 505 * 506 * memory :: 507 * 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 521 #define FT_MODULE_CLASS( x ) FT_MODULE( x )->clazz 522 #define FT_MODULE_LIBRARY( x ) FT_MODULE( x )->library 523 #define FT_MODULE_MEMORY( x ) FT_MODULE( x )->memory 524 525 526 #define FT_MODULE_IS_DRIVER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ 527 FT_MODULE_FONT_DRIVER ) 528 529 #define FT_MODULE_IS_RENDERER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ 530 FT_MODULE_RENDERER ) 531 532 #define FT_MODULE_IS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ 533 FT_MODULE_HINTER ) 534 535 #define FT_MODULE_IS_STYLER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ 536 FT_MODULE_STYLER ) 537 538 #define FT_DRIVER_IS_SCALABLE( x ) ( FT_MODULE_CLASS( x )->module_flags & \ 539 FT_MODULE_DRIVER_SCALABLE ) 540 541 #define FT_DRIVER_USES_OUTLINES( x ) !( FT_MODULE_CLASS( x )->module_flags & \ 542 FT_MODULE_DRIVER_NO_OUTLINES ) 543 544 #define FT_DRIVER_HAS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \ 545 FT_MODULE_DRIVER_HAS_HINTER ) 546 547 #define FT_DRIVER_HINTS_LIGHTLY( x ) ( FT_MODULE_CLASS( x )->module_flags & \ 548 FT_MODULE_DRIVER_HINTS_LIGHTLY ) 549 550 551 /************************************************************************** 552 * 553 * @function: 554 * FT_Get_Module_Interface 555 * 556 * @description: 557 * Finds a module and returns its specific interface as a typeless 558 * pointer. 559 * 560 * @input: 561 * library :: 562 * A handle to the library object. 563 * 564 * module_name :: 565 * The module's name (as an ASCII string). 566 * 567 * @return: 568 * A module-specific interface if available, 0 otherwise. 569 * 570 * @note: 571 * You should better be familiar with FreeType internals to know 572 * which module to look for, and what its interface is :-) 573 */ 574 FT_BASE( const void* ) 575 FT_Get_Module_Interface( FT_Library library, 576 const char* mod_name ); 577 578 FT_BASE( FT_Pointer ) 579 ft_module_get_service( FT_Module module, 580 const char* service_id, 581 FT_Bool global ); 582 583 #ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES 584 FT_BASE( FT_Error ) 585 ft_property_string_set( FT_Library library, 586 const FT_String* module_name, 587 const FT_String* property_name, 588 FT_String* value ); 589 #endif 590 591 /* */ 592 593 594 /*************************************************************************/ 595 /*************************************************************************/ 596 /*************************************************************************/ 597 /**** ****/ 598 /**** ****/ 599 /**** F A C E, S I Z E & G L Y P H S L O T O B J E C T S ****/ 600 /**** ****/ 601 /**** ****/ 602 /*************************************************************************/ 603 /*************************************************************************/ 604 /*************************************************************************/ 605 606 /* a few macros used to perform easy typecasts with minimal brain damage */ 607 608 #define FT_FACE( x ) ( (FT_Face)(x) ) 609 #define FT_SIZE( x ) ( (FT_Size)(x) ) 610 #define FT_SLOT( x ) ( (FT_GlyphSlot)(x) ) 611 612 #define FT_FACE_DRIVER( x ) FT_FACE( x )->driver 613 #define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library 614 #define FT_FACE_MEMORY( x ) FT_FACE( x )->memory 615 #define FT_FACE_STREAM( x ) FT_FACE( x )->stream 616 617 #define FT_SIZE_FACE( x ) FT_SIZE( x )->face 618 #define FT_SLOT_FACE( x ) FT_SLOT( x )->face 619 620 #define FT_FACE_SLOT( x ) FT_FACE( x )->glyph 621 #define FT_FACE_SIZE( x ) FT_FACE( x )->size 622 623 624 /************************************************************************** 625 * 626 * @function: 627 * FT_New_GlyphSlot 628 * 629 * @description: 630 * It is sometimes useful to have more than one glyph slot for a 631 * given face object. This function is used to create additional 632 * slots. All of them are automatically discarded when the face is 633 * destroyed. 634 * 635 * @input: 636 * face :: 637 * A handle to a parent face object. 638 * 639 * @output: 640 * aslot :: 641 * A handle to a new glyph slot object. 642 * 643 * @return: 644 * FreeType error code. 0 means success. 645 */ 646 FT_BASE( FT_Error ) 647 FT_New_GlyphSlot( FT_Face face, 648 FT_GlyphSlot *aslot ); 649 650 651 /************************************************************************** 652 * 653 * @function: 654 * FT_Done_GlyphSlot 655 * 656 * @description: 657 * Destroys a given glyph slot. Remember however that all slots are 658 * automatically destroyed with its parent. Using this function is 659 * not always mandatory. 660 * 661 * @input: 662 * slot :: 663 * A handle to a target glyph slot. 664 */ 665 FT_BASE( void ) 666 FT_Done_GlyphSlot( FT_GlyphSlot slot ); 667 668 /* */ 669 670 #define FT_REQUEST_WIDTH( req ) \ 671 ( (req)->horiResolution \ 672 ? ( (req)->width * (FT_Pos)(req)->horiResolution + 36 ) / 72 \ 673 : (req)->width ) 674 675 #define FT_REQUEST_HEIGHT( req ) \ 676 ( (req)->vertResolution \ 677 ? ( (req)->height * (FT_Pos)(req)->vertResolution + 36 ) / 72 \ 678 : (req)->height ) 679 680 681 /* Set the metrics according to a bitmap strike. */ 682 FT_BASE( void ) 683 FT_Select_Metrics( FT_Face face, 684 FT_ULong strike_index ); 685 686 687 /* Set the metrics according to a size request. */ 688 FT_BASE( void ) 689 FT_Request_Metrics( FT_Face face, 690 FT_Size_Request req ); 691 692 693 /* Match a size request against `available_sizes'. */ 694 FT_BASE( FT_Error ) 695 FT_Match_Size( FT_Face face, 696 FT_Size_Request req, 697 FT_Bool ignore_width, 698 FT_ULong* size_index ); 699 700 701 /* Use the horizontal metrics to synthesize the vertical metrics. */ 702 /* If `advance' is zero, it is also synthesized. */ 703 FT_BASE( void ) 704 ft_synthesize_vertical_metrics( FT_Glyph_Metrics* metrics, 705 FT_Pos advance ); 706 707 708 /* Free the bitmap of a given glyphslot when needed (i.e., only when it */ 709 /* was allocated with ft_glyphslot_alloc_bitmap). */ 710 FT_BASE( void ) 711 ft_glyphslot_free_bitmap( FT_GlyphSlot slot ); 712 713 714 /* Preset bitmap metrics of an outline glyphslot prior to rendering. */ 715 FT_BASE( void ) 716 ft_glyphslot_preset_bitmap( FT_GlyphSlot slot, 717 FT_Render_Mode mode, 718 const FT_Vector* origin ); 719 720 /* Allocate a new bitmap buffer in a glyph slot. */ 721 FT_BASE( FT_Error ) 722 ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot, 723 FT_ULong size ); 724 725 726 /* Set the bitmap buffer in a glyph slot to a given pointer. The buffer */ 727 /* will not be freed by a later call to ft_glyphslot_free_bitmap. */ 728 FT_BASE( void ) 729 ft_glyphslot_set_bitmap( FT_GlyphSlot slot, 730 FT_Byte* buffer ); 731 732 733 /*************************************************************************/ 734 /*************************************************************************/ 735 /*************************************************************************/ 736 /**** ****/ 737 /**** ****/ 738 /**** R E N D E R E R S ****/ 739 /**** ****/ 740 /**** ****/ 741 /*************************************************************************/ 742 /*************************************************************************/ 743 /*************************************************************************/ 744 745 746 #define FT_RENDERER( x ) ( (FT_Renderer)(x) ) 747 #define FT_GLYPH( x ) ( (FT_Glyph)(x) ) 748 #define FT_BITMAP_GLYPH( x ) ( (FT_BitmapGlyph)(x) ) 749 #define FT_OUTLINE_GLYPH( x ) ( (FT_OutlineGlyph)(x) ) 750 751 752 typedef struct FT_RendererRec_ 753 { 754 FT_ModuleRec root; 755 FT_Renderer_Class* clazz; 756 FT_Glyph_Format glyph_format; 757 FT_Glyph_Class glyph_class; 758 759 FT_Raster raster; 760 FT_Raster_Render_Func raster_render; 761 FT_Renderer_RenderFunc render; 762 763 } FT_RendererRec; 764 765 766 /*************************************************************************/ 767 /*************************************************************************/ 768 /*************************************************************************/ 769 /**** ****/ 770 /**** ****/ 771 /**** F O N T D R I V E R S ****/ 772 /**** ****/ 773 /**** ****/ 774 /*************************************************************************/ 775 /*************************************************************************/ 776 /*************************************************************************/ 777 778 779 /* typecast a module into a driver easily */ 780 #define FT_DRIVER( x ) ( (FT_Driver)(x) ) 781 782 /* typecast a module as a driver, and get its driver class */ 783 #define FT_DRIVER_CLASS( x ) FT_DRIVER( x )->clazz 784 785 786 /************************************************************************** 787 * 788 * @struct: 789 * FT_DriverRec 790 * 791 * @description: 792 * The root font driver class. A font driver is responsible for 793 * managing and loading font files of a given format. 794 * 795 * @fields: 796 * root :: 797 * Contains the fields of the root module class. 798 * 799 * clazz :: 800 * A pointer to the font driver's class. Note that 801 * this is NOT root.clazz. `class' wasn't used 802 * as it is a reserved word in C++. 803 * 804 * faces_list :: 805 * The list of faces currently opened by this 806 * driver. 807 * 808 * glyph_loader :: 809 * Unused. Used to be glyph loader for all faces 810 * managed by this driver. 811 */ 812 typedef struct FT_DriverRec_ 813 { 814 FT_ModuleRec root; 815 FT_Driver_Class clazz; 816 FT_ListRec faces_list; 817 FT_GlyphLoader glyph_loader; 818 819 } FT_DriverRec; 820 821 822 /*************************************************************************/ 823 /*************************************************************************/ 824 /*************************************************************************/ 825 /**** ****/ 826 /**** ****/ 827 /**** L I B R A R I E S ****/ 828 /**** ****/ 829 /**** ****/ 830 /*************************************************************************/ 831 /*************************************************************************/ 832 /*************************************************************************/ 833 834 835 /* This hook is used by the TrueType debugger. It must be set to an */ 836 /* alternate truetype bytecode interpreter function. */ 837 #define FT_DEBUG_HOOK_TRUETYPE 0 838 839 840 /************************************************************************** 841 * 842 * @struct: 843 * FT_LibraryRec 844 * 845 * @description: 846 * The FreeType library class. This is the root of all FreeType 847 * data. Use FT_New_Library() to create a library object, and 848 * FT_Done_Library() to discard it and all child objects. 849 * 850 * @fields: 851 * memory :: 852 * The library's memory object. Manages memory 853 * allocation. 854 * 855 * version_major :: 856 * The major version number of the library. 857 * 858 * version_minor :: 859 * The minor version number of the library. 860 * 861 * version_patch :: 862 * The current patch level of the library. 863 * 864 * num_modules :: 865 * The number of modules currently registered 866 * within this library. This is set to 0 for new 867 * libraries. New modules are added through the 868 * FT_Add_Module() API function. 869 * 870 * modules :: 871 * A table used to store handles to the currently 872 * registered modules. Note that each font driver 873 * contains a list of its opened faces. 874 * 875 * renderers :: 876 * The list of renderers currently registered 877 * within the library. 878 * 879 * cur_renderer :: 880 * The current outline renderer. This is a 881 * shortcut used to avoid parsing the list on 882 * each call to FT_Outline_Render(). It is a 883 * handle to the current renderer for the 884 * FT_GLYPH_FORMAT_OUTLINE format. 885 * 886 * auto_hinter :: 887 * The auto-hinter module interface. 888 * 889 * debug_hooks :: 890 * An array of four function pointers that allow 891 * debuggers to hook into a font format's 892 * interpreter. Currently, only the TrueType 893 * bytecode debugger uses this. 894 * 895 * lcd_weights :: 896 * The LCD filter weights for ClearType-style 897 * subpixel rendering. 898 * 899 * lcd_filter_func :: 900 * The LCD filtering callback function for 901 * for ClearType-style subpixel rendering. 902 * 903 * lcd_geometry :: 904 * This array specifies LCD subpixel geometry 905 * and controls Harmony LCD rendering technique, 906 * alternative to ClearType. 907 * 908 * pic_container :: 909 * Contains global structs and tables, instead 910 * of defining them globally. 911 * 912 * refcount :: 913 * A counter initialized to~1 at the time an 914 * @FT_Library structure is created. 915 * @FT_Reference_Library increments this counter, 916 * and @FT_Done_Library only destroys a library 917 * if the counter is~1, otherwise it simply 918 * decrements it. 919 */ 920 typedef struct FT_LibraryRec_ 921 { 922 FT_Memory memory; /* library's memory manager */ 923 924 FT_Int version_major; 925 FT_Int version_minor; 926 FT_Int version_patch; 927 928 FT_UInt num_modules; 929 FT_Module modules[FT_MAX_MODULES]; /* module objects */ 930 931 FT_ListRec renderers; /* list of renderers */ 932 FT_Renderer cur_renderer; /* current outline renderer */ 933 FT_Module auto_hinter; 934 935 FT_DebugHook_Func debug_hooks[4]; 936 937 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING 938 FT_LcdFiveTapFilter lcd_weights; /* filter weights, if any */ 939 FT_Bitmap_LcdFilterFunc lcd_filter_func; /* filtering callback */ 940 #else 941 FT_Vector lcd_geometry[3]; /* RGB subpixel positions */ 942 #endif 943 944 FT_Int refcount; 945 946 } FT_LibraryRec; 947 948 949 FT_BASE( FT_Renderer ) 950 FT_Lookup_Renderer( FT_Library library, 951 FT_Glyph_Format format, 952 FT_ListNode* node ); 953 954 FT_BASE( FT_Error ) 955 FT_Render_Glyph_Internal( FT_Library library, 956 FT_GlyphSlot slot, 957 FT_Render_Mode render_mode ); 958 959 typedef const char* 960 (*FT_Face_GetPostscriptNameFunc)( FT_Face face ); 961 962 typedef FT_Error 963 (*FT_Face_GetGlyphNameFunc)( FT_Face face, 964 FT_UInt glyph_index, 965 FT_Pointer buffer, 966 FT_UInt buffer_max ); 967 968 typedef FT_UInt 969 (*FT_Face_GetGlyphNameIndexFunc)( FT_Face face, 970 FT_String* glyph_name ); 971 972 973 #ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM 974 975 /************************************************************************** 976 * 977 * @function: 978 * FT_New_Memory 979 * 980 * @description: 981 * Creates a new memory object. 982 * 983 * @return: 984 * A pointer to the new memory object. 0 in case of error. 985 */ 986 FT_BASE( FT_Memory ) 987 FT_New_Memory( void ); 988 989 990 /************************************************************************** 991 * 992 * @function: 993 * FT_Done_Memory 994 * 995 * @description: 996 * Discards memory manager. 997 * 998 * @input: 999 * memory :: 1000 * A handle to the memory manager. 1001 */ 1002 FT_BASE( void ) 1003 FT_Done_Memory( FT_Memory memory ); 1004 1005 #endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */ 1006 1007 1008 /* Define default raster's interface. The default raster is located in */ 1009 /* `src/base/ftraster.c'. */ 1010 /* */ 1011 /* Client applications can register new rasters through the */ 1012 /* FT_Set_Raster() API. */ 1013 1014 #ifndef FT_NO_DEFAULT_RASTER 1015 FT_EXPORT_VAR( FT_Raster_Funcs ) ft_default_raster; 1016 #endif 1017 1018 1019 /************************************************************************** 1020 * 1021 * @macro: 1022 * FT_DEFINE_OUTLINE_FUNCS 1023 * 1024 * @description: 1025 * Used to initialize an instance of FT_Outline_Funcs struct. 1026 * The struct will be allocated in the global scope (or the scope 1027 * where the macro is used). 1028 */ 1029 #define FT_DEFINE_OUTLINE_FUNCS( \ 1030 class_, \ 1031 move_to_, \ 1032 line_to_, \ 1033 conic_to_, \ 1034 cubic_to_, \ 1035 shift_, \ 1036 delta_ ) \ 1037 static const FT_Outline_Funcs class_ = \ 1038 { \ 1039 move_to_, \ 1040 line_to_, \ 1041 conic_to_, \ 1042 cubic_to_, \ 1043 shift_, \ 1044 delta_ \ 1045 }; 1046 1047 1048 /************************************************************************** 1049 * 1050 * @macro: 1051 * FT_DEFINE_RASTER_FUNCS 1052 * 1053 * @description: 1054 * Used to initialize an instance of FT_Raster_Funcs struct. 1055 * The struct will be allocated in the global scope (or the scope 1056 * where the macro is used). 1057 */ 1058 #define FT_DEFINE_RASTER_FUNCS( \ 1059 class_, \ 1060 glyph_format_, \ 1061 raster_new_, \ 1062 raster_reset_, \ 1063 raster_set_mode_, \ 1064 raster_render_, \ 1065 raster_done_ ) \ 1066 const FT_Raster_Funcs class_ = \ 1067 { \ 1068 glyph_format_, \ 1069 raster_new_, \ 1070 raster_reset_, \ 1071 raster_set_mode_, \ 1072 raster_render_, \ 1073 raster_done_ \ 1074 }; 1075 1076 1077 1078 /************************************************************************** 1079 * 1080 * @macro: 1081 * FT_DEFINE_GLYPH 1082 * 1083 * @description: 1084 * The struct will be allocated in the global scope (or the scope 1085 * where the macro is used). 1086 */ 1087 #define FT_DEFINE_GLYPH( \ 1088 class_, \ 1089 size_, \ 1090 format_, \ 1091 init_, \ 1092 done_, \ 1093 copy_, \ 1094 transform_, \ 1095 bbox_, \ 1096 prepare_ ) \ 1097 FT_CALLBACK_TABLE_DEF \ 1098 const FT_Glyph_Class class_ = \ 1099 { \ 1100 size_, \ 1101 format_, \ 1102 init_, \ 1103 done_, \ 1104 copy_, \ 1105 transform_, \ 1106 bbox_, \ 1107 prepare_ \ 1108 }; 1109 1110 1111 /************************************************************************** 1112 * 1113 * @macro: 1114 * FT_DECLARE_RENDERER 1115 * 1116 * @description: 1117 * Used to create a forward declaration of a 1118 * FT_Renderer_Class struct instance. 1119 * 1120 * @macro: 1121 * FT_DEFINE_RENDERER 1122 * 1123 * @description: 1124 * Used to initialize an instance of FT_Renderer_Class struct. 1125 * 1126 * The struct will be allocated in the global scope (or the scope 1127 * where the macro is used). 1128 */ 1129 #define FT_DECLARE_RENDERER( class_ ) \ 1130 FT_EXPORT_VAR( const FT_Renderer_Class ) class_; 1131 1132 #define FT_DEFINE_RENDERER( \ 1133 class_, \ 1134 flags_, \ 1135 size_, \ 1136 name_, \ 1137 version_, \ 1138 requires_, \ 1139 interface_, \ 1140 init_, \ 1141 done_, \ 1142 get_interface_, \ 1143 glyph_format_, \ 1144 render_glyph_, \ 1145 transform_glyph_, \ 1146 get_glyph_cbox_, \ 1147 set_mode_, \ 1148 raster_class_ ) \ 1149 FT_CALLBACK_TABLE_DEF \ 1150 const FT_Renderer_Class class_ = \ 1151 { \ 1152 FT_DEFINE_ROOT_MODULE( flags_, \ 1153 size_, \ 1154 name_, \ 1155 version_, \ 1156 requires_, \ 1157 interface_, \ 1158 init_, \ 1159 done_, \ 1160 get_interface_ ) \ 1161 glyph_format_, \ 1162 \ 1163 render_glyph_, \ 1164 transform_glyph_, \ 1165 get_glyph_cbox_, \ 1166 set_mode_, \ 1167 \ 1168 raster_class_ \ 1169 }; 1170 1171 1172 /************************************************************************** 1173 * 1174 * @macro: 1175 * FT_DECLARE_MODULE 1176 * 1177 * @description: 1178 * Used to create a forward declaration of a 1179 * FT_Module_Class struct instance. 1180 * 1181 * @macro: 1182 * FT_DEFINE_MODULE 1183 * 1184 * @description: 1185 * Used to initialize an instance of an FT_Module_Class struct. 1186 * 1187 * The struct will be allocated in the global scope (or the scope 1188 * where the macro is used). 1189 * 1190 * @macro: 1191 * FT_DEFINE_ROOT_MODULE 1192 * 1193 * @description: 1194 * Used to initialize an instance of an FT_Module_Class struct inside 1195 * another struct that contains it or in a function that initializes 1196 * that containing struct. 1197 */ 1198 #define FT_DECLARE_MODULE( class_ ) \ 1199 FT_CALLBACK_TABLE \ 1200 const FT_Module_Class class_; 1201 1202 #define FT_DEFINE_ROOT_MODULE( \ 1203 flags_, \ 1204 size_, \ 1205 name_, \ 1206 version_, \ 1207 requires_, \ 1208 interface_, \ 1209 init_, \ 1210 done_, \ 1211 get_interface_ ) \ 1212 { \ 1213 flags_, \ 1214 size_, \ 1215 \ 1216 name_, \ 1217 version_, \ 1218 requires_, \ 1219 \ 1220 interface_, \ 1221 \ 1222 init_, \ 1223 done_, \ 1224 get_interface_, \ 1225 }, 1226 1227 #define FT_DEFINE_MODULE( \ 1228 class_, \ 1229 flags_, \ 1230 size_, \ 1231 name_, \ 1232 version_, \ 1233 requires_, \ 1234 interface_, \ 1235 init_, \ 1236 done_, \ 1237 get_interface_ ) \ 1238 FT_CALLBACK_TABLE_DEF \ 1239 const FT_Module_Class class_ = \ 1240 { \ 1241 flags_, \ 1242 size_, \ 1243 \ 1244 name_, \ 1245 version_, \ 1246 requires_, \ 1247 \ 1248 interface_, \ 1249 \ 1250 init_, \ 1251 done_, \ 1252 get_interface_, \ 1253 }; 1254 1255 1256 FT_END_HEADER 1257 1258 #endif /* FTOBJS_H_ */ 1259 1260 1261 /* END */ 1262