1 /**************************************************************************** 2 * 3 * ftdriver.h 4 * 5 * FreeType API for controlling driver modules (specification only). 6 * 7 * Copyright (C) 2017-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 #ifndef FTDRIVER_H_ 20 #define FTDRIVER_H_ 21 22 #include <ft2build.h> 23 #include FT_FREETYPE_H 24 #include FT_PARAMETER_TAGS_H 25 26 #ifdef FREETYPE_H 27 #error "freetype.h of FreeType 1 has been loaded!" 28 #error "Please fix the directory search order for header files" 29 #error "so that freetype.h of FreeType 2 is found first." 30 #endif 31 32 33 FT_BEGIN_HEADER 34 35 36 /************************************************************************** 37 * 38 * @section: 39 * auto_hinter 40 * 41 * @title: 42 * The auto-hinter 43 * 44 * @abstract: 45 * Controlling the auto-hinting module. 46 * 47 * @description: 48 * While FreeType's auto-hinter doesn't expose API functions by itself, 49 * it is possible to control its behaviour with @FT_Property_Set and 50 * @FT_Property_Get. The following lists the available properties 51 * together with the necessary macros and structures. 52 * 53 * Note that the auto-hinter's module name is 'autofitter' for historical 54 * reasons. 55 * 56 * Available properties are @increase-x-height, @no-stem-darkening 57 * (experimental), @darkening-parameters (experimental), @warping 58 * (experimental), @glyph-to-script-map (experimental), @fallback-script 59 * (experimental), and @default-script (experimental), as documented in 60 * the @properties section. 61 * 62 */ 63 64 65 /************************************************************************** 66 * 67 * @section: 68 * cff_driver 69 * 70 * @title: 71 * The CFF driver 72 * 73 * @abstract: 74 * Controlling the CFF driver module. 75 * 76 * @description: 77 * While FreeType's CFF driver doesn't expose API functions by itself, it 78 * is possible to control its behaviour with @FT_Property_Set and 79 * @FT_Property_Get. 80 * 81 * The CFF driver's module name is 'cff'. 82 * 83 * Available properties are @hinting-engine, @no-stem-darkening, 84 * @darkening-parameters, and @random-seed, as documented in the 85 * @properties section. 86 * 87 * 88 * **Hinting and antialiasing principles of the new engine** 89 * 90 * The rasterizer is positioning horizontal features (e.g., ascender 91 * height & x-height, or crossbars) on the pixel grid and minimizing the 92 * amount of antialiasing applied to them, while placing vertical 93 * features (vertical stems) on the pixel grid without hinting, thus 94 * representing the stem position and weight accurately. Sometimes the 95 * vertical stems may be only partially black. In this context, 96 * 'antialiasing' means that stems are not positioned exactly on pixel 97 * borders, causing a fuzzy appearance. 98 * 99 * There are two principles behind this approach. 100 * 101 * 1) No hinting in the horizontal direction: Unlike 'superhinted' 102 * TrueType, which changes glyph widths to accommodate regular 103 * inter-glyph spacing, Adobe's approach is 'faithful to the design' in 104 * representing both the glyph width and the inter-glyph spacing designed 105 * for the font. This makes the screen display as close as it can be to 106 * the result one would get with infinite resolution, while preserving 107 * what is considered the key characteristics of each glyph. Note that 108 * the distances between unhinted and grid-fitted positions at small 109 * sizes are comparable to kerning values and thus would be noticeable 110 * (and distracting) while reading if hinting were applied. 111 * 112 * One of the reasons to not hint horizontally is antialiasing for LCD 113 * screens: The pixel geometry of modern displays supplies three vertical 114 * subpixels as the eye moves horizontally across each visible pixel. On 115 * devices where we can be certain this characteristic is present a 116 * rasterizer can take advantage of the subpixels to add increments of 117 * weight. In Western writing systems this turns out to be the more 118 * critical direction anyway; the weights and spacing of vertical stems 119 * (see above) are central to Armenian, Cyrillic, Greek, and Latin type 120 * designs. Even when the rasterizer uses greyscale antialiasing instead 121 * of color (a necessary compromise when one doesn't know the screen 122 * characteristics), the unhinted vertical features preserve the design's 123 * weight and spacing much better than aliased type would. 124 * 125 * 2) Alignment in the vertical direction: Weights and spacing along the 126 * y~axis are less critical; what is much more important is the visual 127 * alignment of related features (like cap-height and x-height). The 128 * sense of alignment for these is enhanced by the sharpness of grid-fit 129 * edges, while the cruder vertical resolution (full pixels instead of 130 * 1/3 pixels) is less of a problem. 131 * 132 * On the technical side, horizontal alignment zones for ascender, 133 * x-height, and other important height values (traditionally called 134 * 'blue zones') as defined in the font are positioned independently, 135 * each being rounded to the nearest pixel edge, taking care of overshoot 136 * suppression at small sizes, stem darkening, and scaling. 137 * 138 * Hstems (this is, hint values defined in the font to help align 139 * horizontal features) that fall within a blue zone are said to be 140 * 'captured' and are aligned to that zone. Uncaptured stems are moved 141 * in one of four ways, top edge up or down, bottom edge up or down. 142 * Unless there are conflicting hstems, the smallest movement is taken to 143 * minimize distortion. 144 * 145 */ 146 147 148 /************************************************************************** 149 * 150 * @section: 151 * pcf_driver 152 * 153 * @title: 154 * The PCF driver 155 * 156 * @abstract: 157 * Controlling the PCF driver module. 158 * 159 * @description: 160 * While FreeType's PCF driver doesn't expose API functions by itself, it 161 * is possible to control its behaviour with @FT_Property_Set and 162 * @FT_Property_Get. Right now, there is a single property 163 * @no-long-family-names available if FreeType is compiled with 164 * PCF_CONFIG_OPTION_LONG_FAMILY_NAMES. 165 * 166 * The PCF driver's module name is 'pcf'. 167 * 168 */ 169 170 171 /************************************************************************** 172 * 173 * @section: 174 * t1_cid_driver 175 * 176 * @title: 177 * The Type 1 and CID drivers 178 * 179 * @abstract: 180 * Controlling the Type~1 and CID driver modules. 181 * 182 * @description: 183 * It is possible to control the behaviour of FreeType's Type~1 and 184 * Type~1 CID drivers with @FT_Property_Set and @FT_Property_Get. 185 * 186 * Behind the scenes, both drivers use the Adobe CFF engine for hinting; 187 * however, the used properties must be specified separately. 188 * 189 * The Type~1 driver's module name is 'type1'; the CID driver's module 190 * name is 't1cid'. 191 * 192 * Available properties are @hinting-engine, @no-stem-darkening, 193 * @darkening-parameters, and @random-seed, as documented in the 194 * @properties section. 195 * 196 * Please see the @cff_driver section for more details on the new hinting 197 * engine. 198 * 199 */ 200 201 202 /************************************************************************** 203 * 204 * @section: 205 * tt_driver 206 * 207 * @title: 208 * The TrueType driver 209 * 210 * @abstract: 211 * Controlling the TrueType driver module. 212 * 213 * @description: 214 * While FreeType's TrueType driver doesn't expose API functions by 215 * itself, it is possible to control its behaviour with @FT_Property_Set 216 * and @FT_Property_Get. The following lists the available properties 217 * together with the necessary macros and structures. 218 * 219 * The TrueType driver's module name is 'truetype'. 220 * 221 * A single property @interpreter-version is available, as documented in 222 * the @properties section. 223 * 224 * We start with a list of definitions, kindly provided by Greg 225 * Hitchcock. 226 * 227 * _Bi-Level Rendering_ 228 * 229 * Monochromatic rendering, exclusively used in the early days of 230 * TrueType by both Apple and Microsoft. Microsoft's GDI interface 231 * supported hinting of the right-side bearing point, such that the 232 * advance width could be non-linear. Most often this was done to 233 * achieve some level of glyph symmetry. To enable reasonable 234 * performance (e.g., not having to run hinting on all glyphs just to get 235 * the widths) there was a bit in the head table indicating if the side 236 * bearing was hinted, and additional tables, 'hdmx' and 'LTSH', to cache 237 * hinting widths across multiple sizes and device aspect ratios. 238 * 239 * _Font Smoothing_ 240 * 241 * Microsoft's GDI implementation of anti-aliasing. Not traditional 242 * anti-aliasing as the outlines were hinted before the sampling. The 243 * widths matched the bi-level rendering. 244 * 245 * _ClearType Rendering_ 246 * 247 * Technique that uses physical subpixels to improve rendering on LCD 248 * (and other) displays. Because of the higher resolution, many methods 249 * of improving symmetry in glyphs through hinting the right-side bearing 250 * were no longer necessary. This lead to what GDI calls 'natural 251 * widths' ClearType, see 252 * http://rastertragedy.com/RTRCh4.htm#Sec21. Since hinting 253 * has extra resolution, most non-linearity went away, but it is still 254 * possible for hints to change the advance widths in this mode. 255 * 256 * _ClearType Compatible Widths_ 257 * 258 * One of the earliest challenges with ClearType was allowing the 259 * implementation in GDI to be selected without requiring all UI and 260 * documents to reflow. To address this, a compatible method of 261 * rendering ClearType was added where the font hints are executed once 262 * to determine the width in bi-level rendering, and then re-run in 263 * ClearType, with the difference in widths being absorbed in the font 264 * hints for ClearType (mostly in the white space of hints); see 265 * http://rastertragedy.com/RTRCh4.htm#Sec20. Somewhat by 266 * definition, compatible width ClearType allows for non-linear widths, 267 * but only when the bi-level version has non-linear widths. 268 * 269 * _ClearType Subpixel Positioning_ 270 * 271 * One of the nice benefits of ClearType is the ability to more crisply 272 * display fractional widths; unfortunately, the GDI model of integer 273 * bitmaps did not support this. However, the WPF and Direct Write 274 * frameworks do support fractional widths. DWrite calls this 'natural 275 * mode', not to be confused with GDI's 'natural widths'. Subpixel 276 * positioning, in the current implementation of Direct Write, 277 * unfortunately does not support hinted advance widths, see 278 * http://rastertragedy.com/RTRCh4.htm#Sec22. Note that the 279 * TrueType interpreter fully allows the advance width to be adjusted in 280 * this mode, just the DWrite client will ignore those changes. 281 * 282 * _ClearType Backward Compatibility_ 283 * 284 * This is a set of exceptions made in the TrueType interpreter to 285 * minimize hinting techniques that were problematic with the extra 286 * resolution of ClearType; see 287 * http://rastertragedy.com/RTRCh4.htm#Sec1 and 288 * https://www.microsoft.com/typography/cleartype/truetypecleartype.aspx. 289 * This technique is not to be confused with ClearType compatible widths. 290 * ClearType backward compatibility has no direct impact on changing 291 * advance widths, but there might be an indirect impact on disabling 292 * some deltas. This could be worked around in backward compatibility 293 * mode. 294 * 295 * _Native ClearType Mode_ 296 * 297 * (Not to be confused with 'natural widths'.) This mode removes all the 298 * exceptions in the TrueType interpreter when running with ClearType. 299 * Any issues on widths would still apply, though. 300 * 301 */ 302 303 304 /************************************************************************** 305 * 306 * @section: 307 * properties 308 * 309 * @title: 310 * Driver properties 311 * 312 * @abstract: 313 * Controlling driver modules. 314 * 315 * @description: 316 * Driver modules can be controlled by setting and unsetting properties, 317 * using the functions @FT_Property_Set and @FT_Property_Get. This 318 * section documents the available properties, together with auxiliary 319 * macros and structures. 320 * 321 */ 322 323 324 /************************************************************************** 325 * 326 * @enum: 327 * FT_HINTING_XXX 328 * 329 * @description: 330 * A list of constants used for the @hinting-engine property to select 331 * the hinting engine for CFF, Type~1, and CID fonts. 332 * 333 * @values: 334 * FT_HINTING_FREETYPE :: 335 * Use the old FreeType hinting engine. 336 * 337 * FT_HINTING_ADOBE :: 338 * Use the hinting engine contributed by Adobe. 339 * 340 * @since: 341 * 2.9 342 * 343 */ 344 #define FT_HINTING_FREETYPE 0 345 #define FT_HINTING_ADOBE 1 346 347 /* these constants (introduced in 2.4.12) are deprecated */ 348 #define FT_CFF_HINTING_FREETYPE FT_HINTING_FREETYPE 349 #define FT_CFF_HINTING_ADOBE FT_HINTING_ADOBE 350 351 352 /************************************************************************** 353 * 354 * @property: 355 * hinting-engine 356 * 357 * @description: 358 * Thanks to Adobe, which contributed a new hinting (and parsing) engine, 359 * an application can select between 'freetype' and 'adobe' if compiled 360 * with `CFF_CONFIG_OPTION_OLD_ENGINE`. If this configuration macro 361 * isn't defined, 'hinting-engine' does nothing. 362 * 363 * The same holds for the Type~1 and CID modules if compiled with 364 * `T1_CONFIG_OPTION_OLD_ENGINE`. 365 * 366 * For the 'cff' module, the default engine is 'freetype' if 367 * `CFF_CONFIG_OPTION_OLD_ENGINE` is defined, and 'adobe' otherwise. 368 * 369 * For both the 'type1' and 't1cid' modules, the default engine is 370 * 'freetype' if `T1_CONFIG_OPTION_OLD_ENGINE` is defined, and 'adobe' 371 * otherwise. 372 * 373 * @note: 374 * This property can be used with @FT_Property_Get also. 375 * 376 * This property can be set via the `FREETYPE_PROPERTIES` environment 377 * variable (using values 'adobe' or 'freetype'). 378 * 379 * @example: 380 * The following example code demonstrates how to select Adobe's hinting 381 * engine for the 'cff' module (omitting the error handling). 382 * 383 * ``` 384 * FT_Library library; 385 * FT_UInt hinting_engine = FT_HINTING_ADOBE; 386 * 387 * 388 * FT_Init_FreeType( &library ); 389 * 390 * FT_Property_Set( library, "cff", 391 * "hinting-engine", &hinting_engine ); 392 * ``` 393 * 394 * @since: 395 * 2.4.12 (for 'cff' module) 396 * 397 * 2.9 (for 'type1' and 't1cid' modules) 398 * 399 */ 400 401 402 /************************************************************************** 403 * 404 * @property: 405 * no-stem-darkening 406 * 407 * @description: 408 * All glyphs that pass through the auto-hinter will be emboldened unless 409 * this property is set to TRUE. The same is true for the CFF, Type~1, 410 * and CID font modules if the 'Adobe' engine is selected (which is the 411 * default). 412 * 413 * Stem darkening emboldens glyphs at smaller sizes to make them more 414 * readable on common low-DPI screens when using linear alpha blending 415 * and gamma correction, see @FT_Render_Glyph. When not using linear 416 * alpha blending and gamma correction, glyphs will appear heavy and 417 * fuzzy! 418 * 419 * Gamma correction essentially lightens fonts since shades of grey are 420 * shifted to higher pixel values (=~higher brightness) to match the 421 * original intention to the reality of our screens. The side-effect is 422 * that glyphs 'thin out'. Mac OS~X and Adobe's proprietary font 423 * rendering library implement a counter-measure: stem darkening at 424 * smaller sizes where shades of gray dominate. By emboldening a glyph 425 * slightly in relation to its pixel size, individual pixels get higher 426 * coverage of filled-in outlines and are therefore 'blacker'. This 427 * counteracts the 'thinning out' of glyphs, making text remain readable 428 * at smaller sizes. 429 * 430 * By default, the Adobe engines for CFF, Type~1, and CID fonts darken 431 * stems at smaller sizes, regardless of hinting, to enhance contrast. 432 * Setting this property, stem darkening gets switched off. 433 * 434 * For the auto-hinter, stem-darkening is experimental currently and thus 435 * switched off by default (this is, `no-stem-darkening` is set to TRUE 436 * by default). Total consistency with the CFF driver is not achieved 437 * right now because the emboldening method differs and glyphs must be 438 * scaled down on the Y-axis to keep outline points inside their 439 * precomputed blue zones. The smaller the size (especially 9ppem and 440 * down), the higher the loss of emboldening versus the CFF driver. 441 * 442 * Note that stem darkening is never applied if @FT_LOAD_NO_SCALE is set. 443 * 444 * @note: 445 * This property can be used with @FT_Property_Get also. 446 * 447 * This property can be set via the `FREETYPE_PROPERTIES` environment 448 * variable (using values 1 and 0 for 'on' and 'off', respectively). It 449 * can also be set per face using @FT_Face_Properties with 450 * @FT_PARAM_TAG_STEM_DARKENING. 451 * 452 * @example: 453 * ``` 454 * FT_Library library; 455 * FT_Bool no_stem_darkening = TRUE; 456 * 457 * 458 * FT_Init_FreeType( &library ); 459 * 460 * FT_Property_Set( library, "cff", 461 * "no-stem-darkening", &no_stem_darkening ); 462 * ``` 463 * 464 * @since: 465 * 2.4.12 (for 'cff' module) 466 * 467 * 2.6.2 (for 'autofitter' module) 468 * 469 * 2.9 (for 'type1' and 't1cid' modules) 470 * 471 */ 472 473 474 /************************************************************************** 475 * 476 * @property: 477 * darkening-parameters 478 * 479 * @description: 480 * By default, the Adobe hinting engine, as used by the CFF, Type~1, and 481 * CID font drivers, darkens stems as follows (if the `no-stem-darkening` 482 * property isn't set): 483 * 484 * ``` 485 * stem width <= 0.5px: darkening amount = 0.4px 486 * stem width = 1px: darkening amount = 0.275px 487 * stem width = 1.667px: darkening amount = 0.275px 488 * stem width >= 2.333px: darkening amount = 0px 489 * ``` 490 * 491 * and piecewise linear in-between. At configuration time, these four 492 * control points can be set with the macro 493 * `CFF_CONFIG_OPTION_DARKENING_PARAMETERS`; the CFF, Type~1, and CID 494 * drivers share these values. At runtime, the control points can be 495 * changed using the `darkening-parameters` property (see the example 496 * below that demonstrates this for the Type~1 driver). 497 * 498 * The x~values give the stem width, and the y~values the darkening 499 * amount. The unit is 1000th of pixels. All coordinate values must be 500 * positive; the x~values must be monotonically increasing; the y~values 501 * must be monotonically decreasing and smaller than or equal to 500 502 * (corresponding to half a pixel); the slope of each linear piece must 503 * be shallower than -1 (e.g., -.4). 504 * 505 * The auto-hinter provides this property, too, as an experimental 506 * feature. See @no-stem-darkening for more. 507 * 508 * @note: 509 * This property can be used with @FT_Property_Get also. 510 * 511 * This property can be set via the `FREETYPE_PROPERTIES` environment 512 * variable, using eight comma-separated integers without spaces. Here 513 * the above example, using `\` to break the line for readability. 514 * 515 * ``` 516 * FREETYPE_PROPERTIES=\ 517 * type1:darkening-parameters=500,300,1000,200,1500,100,2000,0 518 * ``` 519 * 520 * @example: 521 * ``` 522 * FT_Library library; 523 * FT_Int darken_params[8] = { 500, 300, // x1, y1 524 * 1000, 200, // x2, y2 525 * 1500, 100, // x3, y3 526 * 2000, 0 }; // x4, y4 527 * 528 * 529 * FT_Init_FreeType( &library ); 530 * 531 * FT_Property_Set( library, "type1", 532 * "darkening-parameters", darken_params ); 533 * ``` 534 * 535 * @since: 536 * 2.5.1 (for 'cff' module) 537 * 538 * 2.6.2 (for 'autofitter' module) 539 * 540 * 2.9 (for 'type1' and 't1cid' modules) 541 * 542 */ 543 544 545 /************************************************************************** 546 * 547 * @property: 548 * random-seed 549 * 550 * @description: 551 * By default, the seed value for the CFF 'random' operator and the 552 * similar '0 28 callothersubr pop' command for the Type~1 and CID 553 * drivers is set to a random value. However, mainly for debugging 554 * purposes, it is often necessary to use a known value as a seed so that 555 * the pseudo-random number sequences generated by 'random' are 556 * repeatable. 557 * 558 * The `random-seed` property does that. Its argument is a signed 32bit 559 * integer; if the value is zero or negative, the seed given by the 560 * `intitialRandomSeed` private DICT operator in a CFF file gets used (or 561 * a default value if there is no such operator). If the value is 562 * positive, use it instead of `initialRandomSeed`, which is consequently 563 * ignored. 564 * 565 * @note: 566 * This property can be set via the `FREETYPE_PROPERTIES` environment 567 * variable. It can also be set per face using @FT_Face_Properties with 568 * @FT_PARAM_TAG_RANDOM_SEED. 569 * 570 * @since: 571 * 2.8 (for 'cff' module) 572 * 573 * 2.9 (for 'type1' and 't1cid' modules) 574 * 575 */ 576 577 578 /************************************************************************** 579 * 580 * @property: 581 * no-long-family-names 582 * 583 * @description: 584 * If `PCF_CONFIG_OPTION_LONG_FAMILY_NAMES` is active while compiling 585 * FreeType, the PCF driver constructs long family names. 586 * 587 * There are many PCF fonts just called 'Fixed' which look completely 588 * different, and which have nothing to do with each other. When 589 * selecting 'Fixed' in KDE or Gnome one gets results that appear rather 590 * random, the style changes often if one changes the size and one cannot 591 * select some fonts at all. The improve this situation, the PCF module 592 * prepends the foundry name (plus a space) to the family name. It also 593 * checks whether there are 'wide' characters; all put together, family 594 * names like 'Sony Fixed' or 'Misc Fixed Wide' are constructed. 595 * 596 * If `no-long-family-names` is set, this feature gets switched off. 597 * 598 * @note: 599 * This property can be used with @FT_Property_Get also. 600 * 601 * This property can be set via the `FREETYPE_PROPERTIES` environment 602 * variable (using values 1 and 0 for 'on' and 'off', respectively). 603 * 604 * @example: 605 * ``` 606 * FT_Library library; 607 * FT_Bool no_long_family_names = TRUE; 608 * 609 * 610 * FT_Init_FreeType( &library ); 611 * 612 * FT_Property_Set( library, "pcf", 613 * "no-long-family-names", 614 * &no_long_family_names ); 615 * ``` 616 * 617 * @since: 618 * 2.8 619 */ 620 621 622 /************************************************************************** 623 * 624 * @enum: 625 * TT_INTERPRETER_VERSION_XXX 626 * 627 * @description: 628 * A list of constants used for the @interpreter-version property to 629 * select the hinting engine for Truetype fonts. 630 * 631 * The numeric value in the constant names represents the version number 632 * as returned by the 'GETINFO' bytecode instruction. 633 * 634 * @values: 635 * TT_INTERPRETER_VERSION_35 :: 636 * Version~35 corresponds to MS rasterizer v.1.7 as used e.g. in 637 * Windows~98; only grayscale and B/W rasterizing is supported. 638 * 639 * TT_INTERPRETER_VERSION_38 :: 640 * Version~38 corresponds to MS rasterizer v.1.9; it is roughly 641 * equivalent to the hinting provided by DirectWrite ClearType (as can 642 * be found, for example, in the Internet Explorer~9 running on 643 * Windows~7). It is used in FreeType to select the 'Infinality' 644 * subpixel hinting code. The code may be removed in a future version. 645 * 646 * TT_INTERPRETER_VERSION_40 :: 647 * Version~40 corresponds to MS rasterizer v.2.1; it is roughly 648 * equivalent to the hinting provided by DirectWrite ClearType (as can 649 * be found, for example, in Microsoft's Edge Browser on Windows~10). 650 * It is used in FreeType to select the 'minimal' subpixel hinting 651 * code, a stripped-down and higher performance version of the 652 * 'Infinality' code. 653 * 654 * @note: 655 * This property controls the behaviour of the bytecode interpreter and 656 * thus how outlines get hinted. It does **not** control how glyph get 657 * rasterized! In particular, it does not control subpixel color 658 * filtering. 659 * 660 * If FreeType has not been compiled with the configuration option 661 * `TT_CONFIG_OPTION_SUBPIXEL_HINTING`, selecting version~38 or~40 causes 662 * an `FT_Err_Unimplemented_Feature` error. 663 * 664 * Depending on the graphics framework, Microsoft uses different bytecode 665 * and rendering engines. As a consequence, the version numbers returned 666 * by a call to the 'GETINFO' bytecode instruction are more convoluted 667 * than desired. 668 * 669 * Here are two tables that try to shed some light on the possible values 670 * for the MS rasterizer engine, together with the additional features 671 * introduced by it. 672 * 673 * ``` 674 * GETINFO framework version feature 675 * ------------------------------------------------------------------- 676 * 3 GDI (Win 3.1), v1.0 16-bit, first version 677 * TrueImage 678 * 33 GDI (Win NT 3.1), v1.5 32-bit 679 * HP Laserjet 680 * 34 GDI (Win 95) v1.6 font smoothing, 681 * new SCANTYPE opcode 682 * 35 GDI (Win 98/2000) v1.7 (UN)SCALED_COMPONENT_OFFSET 683 * bits in composite glyphs 684 * 36 MGDI (Win CE 2) v1.6+ classic ClearType 685 * 37 GDI (XP and later), v1.8 ClearType 686 * GDI+ old (before Vista) 687 * 38 GDI+ old (Vista, Win 7), v1.9 subpixel ClearType, 688 * WPF Y-direction ClearType, 689 * additional error checking 690 * 39 DWrite (before Win 8) v2.0 subpixel ClearType flags 691 * in GETINFO opcode, 692 * bug fixes 693 * 40 GDI+ (after Win 7), v2.1 Y-direction ClearType flag 694 * DWrite (Win 8) in GETINFO opcode, 695 * Gray ClearType 696 * ``` 697 * 698 * The 'version' field gives a rough orientation only, since some 699 * applications provided certain features much earlier (as an example, 700 * Microsoft Reader used subpixel and Y-direction ClearType already in 701 * Windows 2000). Similarly, updates to a given framework might include 702 * improved hinting support. 703 * 704 * ``` 705 * version sampling rendering comment 706 * x y x y 707 * -------------------------------------------------------------- 708 * v1.0 normal normal B/W B/W bi-level 709 * v1.6 high high gray gray grayscale 710 * v1.8 high normal color-filter B/W (GDI) ClearType 711 * v1.9 high high color-filter gray Color ClearType 712 * v2.1 high normal gray B/W Gray ClearType 713 * v2.1 high high gray gray Gray ClearType 714 * ``` 715 * 716 * Color and Gray ClearType are the two available variants of 717 * 'Y-direction ClearType', meaning grayscale rasterization along the 718 * Y-direction; the name used in the TrueType specification for this 719 * feature is 'symmetric smoothing'. 'Classic ClearType' is the original 720 * algorithm used before introducing a modified version in Win~XP. 721 * Another name for v1.6's grayscale rendering is 'font smoothing', and 722 * 'Color ClearType' is sometimes also called 'DWrite ClearType'. To 723 * differentiate between today's Color ClearType and the earlier 724 * ClearType variant with B/W rendering along the vertical axis, the 725 * latter is sometimes called 'GDI ClearType'. 726 * 727 * 'Normal' and 'high' sampling describe the (virtual) resolution to 728 * access the rasterized outline after the hinting process. 'Normal' 729 * means 1 sample per grid line (i.e., B/W). In the current Microsoft 730 * implementation, 'high' means an extra virtual resolution of 16x16 (or 731 * 16x1) grid lines per pixel for bytecode instructions like 'MIRP'. 732 * After hinting, these 16 grid lines are mapped to 6x5 (or 6x1) grid 733 * lines for color filtering if Color ClearType is activated. 734 * 735 * Note that 'Gray ClearType' is essentially the same as v1.6's grayscale 736 * rendering. However, the GETINFO instruction handles it differently: 737 * v1.6 returns bit~12 (hinting for grayscale), while v2.1 returns 738 * bits~13 (hinting for ClearType), 18 (symmetrical smoothing), and~19 739 * (Gray ClearType). Also, this mode respects bits 2 and~3 for the 740 * version~1 gasp table exclusively (like Color ClearType), while v1.6 741 * only respects the values of version~0 (bits 0 and~1). 742 * 743 * Keep in mind that the features of the above interpreter versions might 744 * not map exactly to FreeType features or behavior because it is a 745 * fundamentally different library with different internals. 746 * 747 */ 748 #define TT_INTERPRETER_VERSION_35 35 749 #define TT_INTERPRETER_VERSION_38 38 750 #define TT_INTERPRETER_VERSION_40 40 751 752 753 /************************************************************************** 754 * 755 * @property: 756 * interpreter-version 757 * 758 * @description: 759 * Currently, three versions are available, two representing the bytecode 760 * interpreter with subpixel hinting support (old 'Infinality' code and 761 * new stripped-down and higher performance 'minimal' code) and one 762 * without, respectively. The default is subpixel support if 763 * `TT_CONFIG_OPTION_SUBPIXEL_HINTING` is defined, and no subpixel 764 * support otherwise (since it isn't available then). 765 * 766 * If subpixel hinting is on, many TrueType bytecode instructions behave 767 * differently compared to B/W or grayscale rendering (except if 'native 768 * ClearType' is selected by the font). Microsoft's main idea is to 769 * render at a much increased horizontal resolution, then sampling down 770 * the created output to subpixel precision. However, many older fonts 771 * are not suited to this and must be specially taken care of by applying 772 * (hardcoded) tweaks in Microsoft's interpreter. 773 * 774 * Details on subpixel hinting and some of the necessary tweaks can be 775 * found in Greg Hitchcock's whitepaper at 776 * 'https://www.microsoft.com/typography/cleartype/truetypecleartype.aspx'. 777 * Note that FreeType currently doesn't really 'subpixel hint' (6x1, 6x2, 778 * or 6x5 supersampling) like discussed in the paper. Depending on the 779 * chosen interpreter, it simply ignores instructions on vertical stems 780 * to arrive at very similar results. 781 * 782 * @note: 783 * This property can be used with @FT_Property_Get also. 784 * 785 * This property can be set via the `FREETYPE_PROPERTIES` environment 786 * variable (using values '35', '38', or '40'). 787 * 788 * @example: 789 * The following example code demonstrates how to deactivate subpixel 790 * hinting (omitting the error handling). 791 * 792 * ``` 793 * FT_Library library; 794 * FT_Face face; 795 * FT_UInt interpreter_version = TT_INTERPRETER_VERSION_35; 796 * 797 * 798 * FT_Init_FreeType( &library ); 799 * 800 * FT_Property_Set( library, "truetype", 801 * "interpreter-version", 802 * &interpreter_version ); 803 * ``` 804 * 805 * @since: 806 * 2.5 807 */ 808 809 810 /************************************************************************** 811 * 812 * @property: 813 * glyph-to-script-map 814 * 815 * @description: 816 * **Experimental only** 817 * 818 * The auto-hinter provides various script modules to hint glyphs. 819 * Examples of supported scripts are Latin or CJK. Before a glyph is 820 * auto-hinted, the Unicode character map of the font gets examined, and 821 * the script is then determined based on Unicode character ranges, see 822 * below. 823 * 824 * OpenType fonts, however, often provide much more glyphs than character 825 * codes (small caps, superscripts, ligatures, swashes, etc.), to be 826 * controlled by so-called 'features'. Handling OpenType features can be 827 * quite complicated and thus needs a separate library on top of 828 * FreeType. 829 * 830 * The mapping between glyph indices and scripts (in the auto-hinter 831 * sense, see the @FT_AUTOHINTER_SCRIPT_XXX values) is stored as an array 832 * with `num_glyphs` elements, as found in the font's @FT_Face structure. 833 * The `glyph-to-script-map` property returns a pointer to this array, 834 * which can be modified as needed. Note that the modification should 835 * happen before the first glyph gets processed by the auto-hinter so 836 * that the global analysis of the font shapes actually uses the modified 837 * mapping. 838 * 839 * @example: 840 * The following example code demonstrates how to access it (omitting the 841 * error handling). 842 * 843 * ``` 844 * FT_Library library; 845 * FT_Face face; 846 * FT_Prop_GlyphToScriptMap prop; 847 * 848 * 849 * FT_Init_FreeType( &library ); 850 * FT_New_Face( library, "foo.ttf", 0, &face ); 851 * 852 * prop.face = face; 853 * 854 * FT_Property_Get( library, "autofitter", 855 * "glyph-to-script-map", &prop ); 856 * 857 * // adjust `prop.map' as needed right here 858 * 859 * FT_Load_Glyph( face, ..., FT_LOAD_FORCE_AUTOHINT ); 860 * ``` 861 * 862 * @since: 863 * 2.4.11 864 * 865 */ 866 867 868 /************************************************************************** 869 * 870 * @enum: 871 * FT_AUTOHINTER_SCRIPT_XXX 872 * 873 * @description: 874 * **Experimental only** 875 * 876 * A list of constants used for the @glyph-to-script-map property to 877 * specify the script submodule the auto-hinter should use for hinting a 878 * particular glyph. 879 * 880 * @values: 881 * FT_AUTOHINTER_SCRIPT_NONE :: 882 * Don't auto-hint this glyph. 883 * 884 * FT_AUTOHINTER_SCRIPT_LATIN :: 885 * Apply the latin auto-hinter. For the auto-hinter, 'latin' is a very 886 * broad term, including Cyrillic and Greek also since characters from 887 * those scripts share the same design constraints. 888 * 889 * By default, characters from the following Unicode ranges are 890 * assigned to this submodule. 891 * 892 * ``` 893 * U+0020 - U+007F // Basic Latin (no control characters) 894 * U+00A0 - U+00FF // Latin-1 Supplement (no control characters) 895 * U+0100 - U+017F // Latin Extended-A 896 * U+0180 - U+024F // Latin Extended-B 897 * U+0250 - U+02AF // IPA Extensions 898 * U+02B0 - U+02FF // Spacing Modifier Letters 899 * U+0300 - U+036F // Combining Diacritical Marks 900 * U+0370 - U+03FF // Greek and Coptic 901 * U+0400 - U+04FF // Cyrillic 902 * U+0500 - U+052F // Cyrillic Supplement 903 * U+1D00 - U+1D7F // Phonetic Extensions 904 * U+1D80 - U+1DBF // Phonetic Extensions Supplement 905 * U+1DC0 - U+1DFF // Combining Diacritical Marks Supplement 906 * U+1E00 - U+1EFF // Latin Extended Additional 907 * U+1F00 - U+1FFF // Greek Extended 908 * U+2000 - U+206F // General Punctuation 909 * U+2070 - U+209F // Superscripts and Subscripts 910 * U+20A0 - U+20CF // Currency Symbols 911 * U+2150 - U+218F // Number Forms 912 * U+2460 - U+24FF // Enclosed Alphanumerics 913 * U+2C60 - U+2C7F // Latin Extended-C 914 * U+2DE0 - U+2DFF // Cyrillic Extended-A 915 * U+2E00 - U+2E7F // Supplemental Punctuation 916 * U+A640 - U+A69F // Cyrillic Extended-B 917 * U+A720 - U+A7FF // Latin Extended-D 918 * U+FB00 - U+FB06 // Alphab. Present. Forms (Latin Ligatures) 919 * U+1D400 - U+1D7FF // Mathematical Alphanumeric Symbols 920 * U+1F100 - U+1F1FF // Enclosed Alphanumeric Supplement 921 * ``` 922 * 923 * FT_AUTOHINTER_SCRIPT_CJK :: 924 * Apply the CJK auto-hinter, covering Chinese, Japanese, Korean, old 925 * Vietnamese, and some other scripts. 926 * 927 * By default, characters from the following Unicode ranges are 928 * assigned to this submodule. 929 * 930 * ``` 931 * U+1100 - U+11FF // Hangul Jamo 932 * U+2E80 - U+2EFF // CJK Radicals Supplement 933 * U+2F00 - U+2FDF // Kangxi Radicals 934 * U+2FF0 - U+2FFF // Ideographic Description Characters 935 * U+3000 - U+303F // CJK Symbols and Punctuation 936 * U+3040 - U+309F // Hiragana 937 * U+30A0 - U+30FF // Katakana 938 * U+3100 - U+312F // Bopomofo 939 * U+3130 - U+318F // Hangul Compatibility Jamo 940 * U+3190 - U+319F // Kanbun 941 * U+31A0 - U+31BF // Bopomofo Extended 942 * U+31C0 - U+31EF // CJK Strokes 943 * U+31F0 - U+31FF // Katakana Phonetic Extensions 944 * U+3200 - U+32FF // Enclosed CJK Letters and Months 945 * U+3300 - U+33FF // CJK Compatibility 946 * U+3400 - U+4DBF // CJK Unified Ideographs Extension A 947 * U+4DC0 - U+4DFF // Yijing Hexagram Symbols 948 * U+4E00 - U+9FFF // CJK Unified Ideographs 949 * U+A960 - U+A97F // Hangul Jamo Extended-A 950 * U+AC00 - U+D7AF // Hangul Syllables 951 * U+D7B0 - U+D7FF // Hangul Jamo Extended-B 952 * U+F900 - U+FAFF // CJK Compatibility Ideographs 953 * U+FE10 - U+FE1F // Vertical forms 954 * U+FE30 - U+FE4F // CJK Compatibility Forms 955 * U+FF00 - U+FFEF // Halfwidth and Fullwidth Forms 956 * U+1B000 - U+1B0FF // Kana Supplement 957 * U+1D300 - U+1D35F // Tai Xuan Hing Symbols 958 * U+1F200 - U+1F2FF // Enclosed Ideographic Supplement 959 * U+20000 - U+2A6DF // CJK Unified Ideographs Extension B 960 * U+2A700 - U+2B73F // CJK Unified Ideographs Extension C 961 * U+2B740 - U+2B81F // CJK Unified Ideographs Extension D 962 * U+2F800 - U+2FA1F // CJK Compatibility Ideographs Supplement 963 * ``` 964 * 965 * FT_AUTOHINTER_SCRIPT_INDIC :: 966 * Apply the indic auto-hinter, covering all major scripts from the 967 * Indian sub-continent and some other related scripts like Thai, Lao, 968 * or Tibetan. 969 * 970 * By default, characters from the following Unicode ranges are 971 * assigned to this submodule. 972 * 973 * ``` 974 * U+0900 - U+0DFF // Indic Range 975 * U+0F00 - U+0FFF // Tibetan 976 * U+1900 - U+194F // Limbu 977 * U+1B80 - U+1BBF // Sundanese 978 * U+A800 - U+A82F // Syloti Nagri 979 * U+ABC0 - U+ABFF // Meetei Mayek 980 * U+11800 - U+118DF // Sharada 981 * ``` 982 * 983 * Note that currently Indic support is rudimentary only, missing blue 984 * zone support. 985 * 986 * @since: 987 * 2.4.11 988 * 989 */ 990 #define FT_AUTOHINTER_SCRIPT_NONE 0 991 #define FT_AUTOHINTER_SCRIPT_LATIN 1 992 #define FT_AUTOHINTER_SCRIPT_CJK 2 993 #define FT_AUTOHINTER_SCRIPT_INDIC 3 994 995 996 /************************************************************************** 997 * 998 * @struct: 999 * FT_Prop_GlyphToScriptMap 1000 * 1001 * @description: 1002 * **Experimental only** 1003 * 1004 * The data exchange structure for the @glyph-to-script-map property. 1005 * 1006 * @since: 1007 * 2.4.11 1008 * 1009 */ 1010 typedef struct FT_Prop_GlyphToScriptMap_ 1011 { 1012 FT_Face face; 1013 FT_UShort* map; 1014 1015 } FT_Prop_GlyphToScriptMap; 1016 1017 1018 /************************************************************************** 1019 * 1020 * @property: 1021 * fallback-script 1022 * 1023 * @description: 1024 * **Experimental only** 1025 * 1026 * If no auto-hinter script module can be assigned to a glyph, a fallback 1027 * script gets assigned to it (see also the @glyph-to-script-map 1028 * property). By default, this is @FT_AUTOHINTER_SCRIPT_CJK. Using the 1029 * `fallback-script` property, this fallback value can be changed. 1030 * 1031 * @note: 1032 * This property can be used with @FT_Property_Get also. 1033 * 1034 * It's important to use the right timing for changing this value: The 1035 * creation of the glyph-to-script map that eventually uses the fallback 1036 * script value gets triggered either by setting or reading a 1037 * face-specific property like @glyph-to-script-map, or by auto-hinting 1038 * any glyph from that face. In particular, if you have already created 1039 * an @FT_Face structure but not loaded any glyph (using the 1040 * auto-hinter), a change of the fallback script will affect this face. 1041 * 1042 * @example: 1043 * ``` 1044 * FT_Library library; 1045 * FT_UInt fallback_script = FT_AUTOHINTER_SCRIPT_NONE; 1046 * 1047 * 1048 * FT_Init_FreeType( &library ); 1049 * 1050 * FT_Property_Set( library, "autofitter", 1051 * "fallback-script", &fallback_script ); 1052 * ``` 1053 * 1054 * @since: 1055 * 2.4.11 1056 * 1057 */ 1058 1059 1060 /************************************************************************** 1061 * 1062 * @property: 1063 * default-script 1064 * 1065 * @description: 1066 * **Experimental only** 1067 * 1068 * If FreeType gets compiled with `FT_CONFIG_OPTION_USE_HARFBUZZ` to make 1069 * the HarfBuzz library access OpenType features for getting better glyph 1070 * coverages, this property sets the (auto-fitter) script to be used for 1071 * the default (OpenType) script data of a font's GSUB table. Features 1072 * for the default script are intended for all scripts not explicitly 1073 * handled in GSUB; an example is a 'dlig' feature, containing the 1074 * combination of the characters 'T', 'E', and 'L' to form a 'TEL' 1075 * ligature. 1076 * 1077 * By default, this is @FT_AUTOHINTER_SCRIPT_LATIN. Using the 1078 * `default-script` property, this default value can be changed. 1079 * 1080 * @note: 1081 * This property can be used with @FT_Property_Get also. 1082 * 1083 * It's important to use the right timing for changing this value: The 1084 * creation of the glyph-to-script map that eventually uses the default 1085 * script value gets triggered either by setting or reading a 1086 * face-specific property like @glyph-to-script-map, or by auto-hinting 1087 * any glyph from that face. In particular, if you have already created 1088 * an @FT_Face structure but not loaded any glyph (using the 1089 * auto-hinter), a change of the default script will affect this face. 1090 * 1091 * @example: 1092 * ``` 1093 * FT_Library library; 1094 * FT_UInt default_script = FT_AUTOHINTER_SCRIPT_NONE; 1095 * 1096 * 1097 * FT_Init_FreeType( &library ); 1098 * 1099 * FT_Property_Set( library, "autofitter", 1100 * "default-script", &default_script ); 1101 * ``` 1102 * 1103 * @since: 1104 * 2.5.3 1105 * 1106 */ 1107 1108 1109 /************************************************************************** 1110 * 1111 * @property: 1112 * increase-x-height 1113 * 1114 * @description: 1115 * For ppem values in the range 6~<= ppem <= `increase-x-height`, round 1116 * up the font's x~height much more often than normally. If the value is 1117 * set to~0, which is the default, this feature is switched off. Use 1118 * this property to improve the legibility of small font sizes if 1119 * necessary. 1120 * 1121 * @note: 1122 * This property can be used with @FT_Property_Get also. 1123 * 1124 * Set this value right after calling @FT_Set_Char_Size, but before 1125 * loading any glyph (using the auto-hinter). 1126 * 1127 * @example: 1128 * ``` 1129 * FT_Library library; 1130 * FT_Face face; 1131 * FT_Prop_IncreaseXHeight prop; 1132 * 1133 * 1134 * FT_Init_FreeType( &library ); 1135 * FT_New_Face( library, "foo.ttf", 0, &face ); 1136 * FT_Set_Char_Size( face, 10 * 64, 0, 72, 0 ); 1137 * 1138 * prop.face = face; 1139 * prop.limit = 14; 1140 * 1141 * FT_Property_Set( library, "autofitter", 1142 * "increase-x-height", &prop ); 1143 * ``` 1144 * 1145 * @since: 1146 * 2.4.11 1147 * 1148 */ 1149 1150 1151 /************************************************************************** 1152 * 1153 * @struct: 1154 * FT_Prop_IncreaseXHeight 1155 * 1156 * @description: 1157 * The data exchange structure for the @increase-x-height property. 1158 * 1159 */ 1160 typedef struct FT_Prop_IncreaseXHeight_ 1161 { 1162 FT_Face face; 1163 FT_UInt limit; 1164 1165 } FT_Prop_IncreaseXHeight; 1166 1167 1168 /************************************************************************** 1169 * 1170 * @property: 1171 * warping 1172 * 1173 * @description: 1174 * **Experimental only** 1175 * 1176 * If FreeType gets compiled with option `AF_CONFIG_OPTION_USE_WARPER` to 1177 * activate the warp hinting code in the auto-hinter, this property 1178 * switches warping on and off. 1179 * 1180 * Warping only works in 'normal' auto-hinting mode replacing it. The 1181 * idea of the code is to slightly scale and shift a glyph along the 1182 * non-hinted dimension (which is usually the horizontal axis) so that as 1183 * much of its segments are aligned (more or less) to the grid. To find 1184 * out a glyph's optimal scaling and shifting value, various parameter 1185 * combinations are tried and scored. 1186 * 1187 * By default, warping is off. 1188 * 1189 * @note: 1190 * This property can be used with @FT_Property_Get also. 1191 * 1192 * This property can be set via the `FREETYPE_PROPERTIES` environment 1193 * variable (using values 1 and 0 for 'on' and 'off', respectively). 1194 * 1195 * The warping code can also change advance widths. Have a look at the 1196 * `lsb_delta` and `rsb_delta` fields in the @FT_GlyphSlotRec structure 1197 * for details on improving inter-glyph distances while rendering. 1198 * 1199 * Since warping is a global property of the auto-hinter it is best to 1200 * change its value before rendering any face. Otherwise, you should 1201 * reload all faces that get auto-hinted in 'normal' hinting mode. 1202 * 1203 * @example: 1204 * This example shows how to switch on warping (omitting the error 1205 * handling). 1206 * 1207 * ``` 1208 * FT_Library library; 1209 * FT_Bool warping = 1; 1210 * 1211 * 1212 * FT_Init_FreeType( &library ); 1213 * 1214 * FT_Property_Set( library, "autofitter", "warping", &warping ); 1215 * ``` 1216 * 1217 * @since: 1218 * 2.6 1219 * 1220 */ 1221 1222 1223 /* */ 1224 1225 1226 FT_END_HEADER 1227 1228 1229 #endif /* FTDRIVER_H_ */ 1230 1231 1232 /* END */ 1233