1 /**************************************************************************** 2 * 3 * ftimage.h 4 * 5 * FreeType glyph image formats and default raster interface 6 * (specification). 7 * 8 * Copyright (C) 1996-2023 by 9 * David Turner, Robert Wilhelm, and Werner Lemberg. 10 * 11 * This file is part of the FreeType project, and may only be used, 12 * modified, and distributed under the terms of the FreeType project 13 * license, LICENSE.TXT. By continuing to use, modify, or distribute 14 * this file you indicate that you have read the license and 15 * understand and accept it fully. 16 * 17 */ 18 19 /************************************************************************** 20 * 21 * Note: A 'raster' is simply a scan-line converter, used to render 22 * FT_Outlines into FT_Bitmaps. 23 * 24 */ 25 26 27 #ifndef FTIMAGE_H_ 28 #define FTIMAGE_H_ 29 30 31 FT_BEGIN_HEADER 32 33 34 /************************************************************************** 35 * 36 * @section: 37 * basic_types 38 * 39 */ 40 41 42 /************************************************************************** 43 * 44 * @type: 45 * FT_Pos 46 * 47 * @description: 48 * The type FT_Pos is used to store vectorial coordinates. Depending on 49 * the context, these can represent distances in integer font units, or 50 * 16.16, or 26.6 fixed-point pixel coordinates. 51 */ 52 typedef signed long FT_Pos; 53 54 55 /************************************************************************** 56 * 57 * @struct: 58 * FT_Vector 59 * 60 * @description: 61 * A simple structure used to store a 2D vector; coordinates are of the 62 * FT_Pos type. 63 * 64 * @fields: 65 * x :: 66 * The horizontal coordinate. 67 * y :: 68 * The vertical coordinate. 69 */ 70 typedef struct FT_Vector_ 71 { 72 FT_Pos x; 73 FT_Pos y; 74 75 } FT_Vector; 76 77 78 /************************************************************************** 79 * 80 * @struct: 81 * FT_BBox 82 * 83 * @description: 84 * A structure used to hold an outline's bounding box, i.e., the 85 * coordinates of its extrema in the horizontal and vertical directions. 86 * 87 * @fields: 88 * xMin :: 89 * The horizontal minimum (left-most). 90 * 91 * yMin :: 92 * The vertical minimum (bottom-most). 93 * 94 * xMax :: 95 * The horizontal maximum (right-most). 96 * 97 * yMax :: 98 * The vertical maximum (top-most). 99 * 100 * @note: 101 * The bounding box is specified with the coordinates of the lower left 102 * and the upper right corner. In PostScript, those values are often 103 * called (llx,lly) and (urx,ury), respectively. 104 * 105 * If `yMin` is negative, this value gives the glyph's descender. 106 * Otherwise, the glyph doesn't descend below the baseline. Similarly, 107 * if `ymax` is positive, this value gives the glyph's ascender. 108 * 109 * `xMin` gives the horizontal distance from the glyph's origin to the 110 * left edge of the glyph's bounding box. If `xMin` is negative, the 111 * glyph extends to the left of the origin. 112 */ 113 typedef struct FT_BBox_ 114 { 115 FT_Pos xMin, yMin; 116 FT_Pos xMax, yMax; 117 118 } FT_BBox; 119 120 121 /************************************************************************** 122 * 123 * @enum: 124 * FT_Pixel_Mode 125 * 126 * @description: 127 * An enumeration type used to describe the format of pixels in a given 128 * bitmap. Note that additional formats may be added in the future. 129 * 130 * @values: 131 * FT_PIXEL_MODE_NONE :: 132 * Value~0 is reserved. 133 * 134 * FT_PIXEL_MODE_MONO :: 135 * A monochrome bitmap, using 1~bit per pixel. Note that pixels are 136 * stored in most-significant order (MSB), which means that the 137 * left-most pixel in a byte has value 128. 138 * 139 * FT_PIXEL_MODE_GRAY :: 140 * An 8-bit bitmap, generally used to represent anti-aliased glyph 141 * images. Each pixel is stored in one byte. Note that the number of 142 * 'gray' levels is stored in the `num_grays` field of the @FT_Bitmap 143 * structure (it generally is 256). 144 * 145 * FT_PIXEL_MODE_GRAY2 :: 146 * A 2-bit per pixel bitmap, used to represent embedded anti-aliased 147 * bitmaps in font files according to the OpenType specification. We 148 * haven't found a single font using this format, however. 149 * 150 * FT_PIXEL_MODE_GRAY4 :: 151 * A 4-bit per pixel bitmap, representing embedded anti-aliased bitmaps 152 * in font files according to the OpenType specification. We haven't 153 * found a single font using this format, however. 154 * 155 * FT_PIXEL_MODE_LCD :: 156 * An 8-bit bitmap, representing RGB or BGR decimated glyph images used 157 * for display on LCD displays; the bitmap is three times wider than 158 * the original glyph image. See also @FT_RENDER_MODE_LCD. 159 * 160 * FT_PIXEL_MODE_LCD_V :: 161 * An 8-bit bitmap, representing RGB or BGR decimated glyph images used 162 * for display on rotated LCD displays; the bitmap is three times 163 * taller than the original glyph image. See also 164 * @FT_RENDER_MODE_LCD_V. 165 * 166 * FT_PIXEL_MODE_BGRA :: 167 * [Since 2.5] An image with four 8-bit channels per pixel, 168 * representing a color image (such as emoticons) with alpha channel. 169 * For each pixel, the format is BGRA, which means, the blue channel 170 * comes first in memory. The color channels are pre-multiplied and in 171 * the sRGB colorspace. For example, full red at half-translucent 172 * opacity will be represented as '00,00,80,80', not '00,00,FF,80'. 173 * See also @FT_LOAD_COLOR. 174 */ 175 typedef enum FT_Pixel_Mode_ 176 { 177 FT_PIXEL_MODE_NONE = 0, 178 FT_PIXEL_MODE_MONO, 179 FT_PIXEL_MODE_GRAY, 180 FT_PIXEL_MODE_GRAY2, 181 FT_PIXEL_MODE_GRAY4, 182 FT_PIXEL_MODE_LCD, 183 FT_PIXEL_MODE_LCD_V, 184 FT_PIXEL_MODE_BGRA, 185 186 FT_PIXEL_MODE_MAX /* do not remove */ 187 188 } FT_Pixel_Mode; 189 190 191 /* these constants are deprecated; use the corresponding `FT_Pixel_Mode` */ 192 /* values instead. */ 193 #define ft_pixel_mode_none FT_PIXEL_MODE_NONE 194 #define ft_pixel_mode_mono FT_PIXEL_MODE_MONO 195 #define ft_pixel_mode_grays FT_PIXEL_MODE_GRAY 196 #define ft_pixel_mode_pal2 FT_PIXEL_MODE_GRAY2 197 #define ft_pixel_mode_pal4 FT_PIXEL_MODE_GRAY4 198 199 /* */ 200 201 /* For debugging, the @FT_Pixel_Mode enumeration must stay in sync */ 202 /* with the `pixel_modes` array in file `ftobjs.c`. */ 203 204 205 /************************************************************************** 206 * 207 * @struct: 208 * FT_Bitmap 209 * 210 * @description: 211 * A structure used to describe a bitmap or pixmap to the raster. Note 212 * that we now manage pixmaps of various depths through the `pixel_mode` 213 * field. 214 * 215 * @fields: 216 * rows :: 217 * The number of bitmap rows. 218 * 219 * width :: 220 * The number of pixels in bitmap row. 221 * 222 * pitch :: 223 * The pitch's absolute value is the number of bytes taken by one 224 * bitmap row, including padding. However, the pitch is positive when 225 * the bitmap has a 'down' flow, and negative when it has an 'up' flow. 226 * In all cases, the pitch is an offset to add to a bitmap pointer in 227 * order to go down one row. 228 * 229 * Note that 'padding' means the alignment of a bitmap to a byte 230 * border, and FreeType functions normally align to the smallest 231 * possible integer value. 232 * 233 * For the B/W rasterizer, `pitch` is always an even number. 234 * 235 * To change the pitch of a bitmap (say, to make it a multiple of 4), 236 * use @FT_Bitmap_Convert. Alternatively, you might use callback 237 * functions to directly render to the application's surface; see the 238 * file `example2.cpp` in the tutorial for a demonstration. 239 * 240 * buffer :: 241 * A typeless pointer to the bitmap buffer. This value should be 242 * aligned on 32-bit boundaries in most cases. 243 * 244 * num_grays :: 245 * This field is only used with @FT_PIXEL_MODE_GRAY; it gives the 246 * number of gray levels used in the bitmap. 247 * 248 * pixel_mode :: 249 * The pixel mode, i.e., how pixel bits are stored. See @FT_Pixel_Mode 250 * for possible values. 251 * 252 * palette_mode :: 253 * This field is intended for paletted pixel modes; it indicates how 254 * the palette is stored. Not used currently. 255 * 256 * palette :: 257 * A typeless pointer to the bitmap palette; this field is intended for 258 * paletted pixel modes. Not used currently. 259 */ 260 typedef struct FT_Bitmap_ 261 { 262 unsigned int rows; 263 unsigned int width; 264 int pitch; 265 unsigned char* buffer; 266 unsigned short num_grays; 267 unsigned char pixel_mode; 268 unsigned char palette_mode; 269 void* palette; 270 271 } FT_Bitmap; 272 273 274 /************************************************************************** 275 * 276 * @section: 277 * outline_processing 278 * 279 */ 280 281 282 /************************************************************************** 283 * 284 * @struct: 285 * FT_Outline 286 * 287 * @description: 288 * This structure is used to describe an outline to the scan-line 289 * converter. 290 * 291 * @fields: 292 * n_contours :: 293 * The number of contours in the outline. 294 * 295 * n_points :: 296 * The number of points in the outline. 297 * 298 * points :: 299 * A pointer to an array of `n_points` @FT_Vector elements, giving the 300 * outline's point coordinates. 301 * 302 * tags :: 303 * A pointer to an array of `n_points` chars, giving each outline 304 * point's type. 305 * 306 * If bit~0 is unset, the point is 'off' the curve, i.e., a Bezier 307 * control point, while it is 'on' if set. 308 * 309 * Bit~1 is meaningful for 'off' points only. If set, it indicates a 310 * third-order Bezier arc control point; and a second-order control 311 * point if unset. 312 * 313 * If bit~2 is set, bits 5-7 contain the drop-out mode (as defined in 314 * the OpenType specification; the value is the same as the argument to 315 * the 'SCANMODE' instruction). 316 * 317 * Bits 3 and~4 are reserved for internal purposes. 318 * 319 * contours :: 320 * An array of `n_contours` shorts, giving the end point of each 321 * contour within the outline. For example, the first contour is 322 * defined by the points '0' to `contours[0]`, the second one is 323 * defined by the points `contours[0]+1` to `contours[1]`, etc. 324 * 325 * flags :: 326 * A set of bit flags used to characterize the outline and give hints 327 * to the scan-converter and hinter on how to convert/grid-fit it. See 328 * @FT_OUTLINE_XXX. 329 * 330 * @note: 331 * The B/W rasterizer only checks bit~2 in the `tags` array for the first 332 * point of each contour. The drop-out mode as given with 333 * @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and 334 * @FT_OUTLINE_INCLUDE_STUBS in `flags` is then overridden. 335 */ 336 typedef struct FT_Outline_ 337 { 338 short n_contours; /* number of contours in glyph */ 339 short n_points; /* number of points in the glyph */ 340 341 FT_Vector* points; /* the outline's points */ 342 char* tags; /* the points flags */ 343 short* contours; /* the contour end points */ 344 345 int flags; /* outline masks */ 346 347 } FT_Outline; 348 349 /* */ 350 351 /* Following limits must be consistent with */ 352 /* FT_Outline.{n_contours,n_points} */ 353 #define FT_OUTLINE_CONTOURS_MAX SHRT_MAX 354 #define FT_OUTLINE_POINTS_MAX SHRT_MAX 355 356 357 /************************************************************************** 358 * 359 * @enum: 360 * FT_OUTLINE_XXX 361 * 362 * @description: 363 * A list of bit-field constants used for the flags in an outline's 364 * `flags` field. 365 * 366 * @values: 367 * FT_OUTLINE_NONE :: 368 * Value~0 is reserved. 369 * 370 * FT_OUTLINE_OWNER :: 371 * If set, this flag indicates that the outline's field arrays (i.e., 372 * `points`, `flags`, and `contours`) are 'owned' by the outline 373 * object, and should thus be freed when it is destroyed. 374 * 375 * FT_OUTLINE_EVEN_ODD_FILL :: 376 * By default, outlines are filled using the non-zero winding rule. If 377 * set to 1, the outline will be filled using the even-odd fill rule 378 * (only works with the smooth rasterizer). 379 * 380 * FT_OUTLINE_REVERSE_FILL :: 381 * By default, outside contours of an outline are oriented in 382 * clock-wise direction, as defined in the TrueType specification. 383 * This flag is set if the outline uses the opposite direction 384 * (typically for Type~1 fonts). This flag is ignored by the scan 385 * converter. 386 * 387 * FT_OUTLINE_IGNORE_DROPOUTS :: 388 * By default, the scan converter will try to detect drop-outs in an 389 * outline and correct the glyph bitmap to ensure consistent shape 390 * continuity. If set, this flag hints the scan-line converter to 391 * ignore such cases. See below for more information. 392 * 393 * FT_OUTLINE_SMART_DROPOUTS :: 394 * Select smart dropout control. If unset, use simple dropout control. 395 * Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See below for more 396 * information. 397 * 398 * FT_OUTLINE_INCLUDE_STUBS :: 399 * If set, turn pixels on for 'stubs', otherwise exclude them. Ignored 400 * if @FT_OUTLINE_IGNORE_DROPOUTS is set. See below for more 401 * information. 402 * 403 * FT_OUTLINE_OVERLAP :: 404 * [Since 2.10.3] This flag indicates that this outline contains 405 * overlapping contours and the anti-aliased renderer should perform 406 * oversampling to mitigate possible artifacts. This flag should _not_ 407 * be set for well designed glyphs without overlaps because it quadruples 408 * the rendering time. 409 * 410 * FT_OUTLINE_HIGH_PRECISION :: 411 * This flag indicates that the scan-line converter should try to 412 * convert this outline to bitmaps with the highest possible quality. 413 * It is typically set for small character sizes. Note that this is 414 * only a hint that might be completely ignored by a given 415 * scan-converter. 416 * 417 * FT_OUTLINE_SINGLE_PASS :: 418 * This flag is set to force a given scan-converter to only use a 419 * single pass over the outline to render a bitmap glyph image. 420 * Normally, it is set for very large character sizes. It is only a 421 * hint that might be completely ignored by a given scan-converter. 422 * 423 * @note: 424 * The flags @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and 425 * @FT_OUTLINE_INCLUDE_STUBS are ignored by the smooth rasterizer. 426 * 427 * There exists a second mechanism to pass the drop-out mode to the B/W 428 * rasterizer; see the `tags` field in @FT_Outline. 429 * 430 * Please refer to the description of the 'SCANTYPE' instruction in the 431 * OpenType specification (in file `ttinst1.doc`) how simple drop-outs, 432 * smart drop-outs, and stubs are defined. 433 */ 434 #define FT_OUTLINE_NONE 0x0 435 #define FT_OUTLINE_OWNER 0x1 436 #define FT_OUTLINE_EVEN_ODD_FILL 0x2 437 #define FT_OUTLINE_REVERSE_FILL 0x4 438 #define FT_OUTLINE_IGNORE_DROPOUTS 0x8 439 #define FT_OUTLINE_SMART_DROPOUTS 0x10 440 #define FT_OUTLINE_INCLUDE_STUBS 0x20 441 #define FT_OUTLINE_OVERLAP 0x40 442 443 #define FT_OUTLINE_HIGH_PRECISION 0x100 444 #define FT_OUTLINE_SINGLE_PASS 0x200 445 446 447 /* these constants are deprecated; use the corresponding */ 448 /* `FT_OUTLINE_XXX` values instead */ 449 #define ft_outline_none FT_OUTLINE_NONE 450 #define ft_outline_owner FT_OUTLINE_OWNER 451 #define ft_outline_even_odd_fill FT_OUTLINE_EVEN_ODD_FILL 452 #define ft_outline_reverse_fill FT_OUTLINE_REVERSE_FILL 453 #define ft_outline_ignore_dropouts FT_OUTLINE_IGNORE_DROPOUTS 454 #define ft_outline_high_precision FT_OUTLINE_HIGH_PRECISION 455 #define ft_outline_single_pass FT_OUTLINE_SINGLE_PASS 456 457 /* */ 458 459 #define FT_CURVE_TAG( flag ) ( flag & 0x03 ) 460 461 /* see the `tags` field in `FT_Outline` for a description of the values */ 462 #define FT_CURVE_TAG_ON 0x01 463 #define FT_CURVE_TAG_CONIC 0x00 464 #define FT_CURVE_TAG_CUBIC 0x02 465 466 #define FT_CURVE_TAG_HAS_SCANMODE 0x04 467 468 #define FT_CURVE_TAG_TOUCH_X 0x08 /* reserved for TrueType hinter */ 469 #define FT_CURVE_TAG_TOUCH_Y 0x10 /* reserved for TrueType hinter */ 470 471 #define FT_CURVE_TAG_TOUCH_BOTH ( FT_CURVE_TAG_TOUCH_X | \ 472 FT_CURVE_TAG_TOUCH_Y ) 473 /* values 0x20, 0x40, and 0x80 are reserved */ 474 475 476 /* these constants are deprecated; use the corresponding */ 477 /* `FT_CURVE_TAG_XXX` values instead */ 478 #define FT_Curve_Tag_On FT_CURVE_TAG_ON 479 #define FT_Curve_Tag_Conic FT_CURVE_TAG_CONIC 480 #define FT_Curve_Tag_Cubic FT_CURVE_TAG_CUBIC 481 #define FT_Curve_Tag_Touch_X FT_CURVE_TAG_TOUCH_X 482 #define FT_Curve_Tag_Touch_Y FT_CURVE_TAG_TOUCH_Y 483 484 485 /************************************************************************** 486 * 487 * @functype: 488 * FT_Outline_MoveToFunc 489 * 490 * @description: 491 * A function pointer type used to describe the signature of a 'move to' 492 * function during outline walking/decomposition. 493 * 494 * A 'move to' is emitted to start a new contour in an outline. 495 * 496 * @input: 497 * to :: 498 * A pointer to the target point of the 'move to'. 499 * 500 * user :: 501 * A typeless pointer, which is passed from the caller of the 502 * decomposition function. 503 * 504 * @return: 505 * Error code. 0~means success. 506 */ 507 typedef int 508 (*FT_Outline_MoveToFunc)( const FT_Vector* to, 509 void* user ); 510 511 #define FT_Outline_MoveTo_Func FT_Outline_MoveToFunc 512 513 514 /************************************************************************** 515 * 516 * @functype: 517 * FT_Outline_LineToFunc 518 * 519 * @description: 520 * A function pointer type used to describe the signature of a 'line to' 521 * function during outline walking/decomposition. 522 * 523 * A 'line to' is emitted to indicate a segment in the outline. 524 * 525 * @input: 526 * to :: 527 * A pointer to the target point of the 'line to'. 528 * 529 * user :: 530 * A typeless pointer, which is passed from the caller of the 531 * decomposition function. 532 * 533 * @return: 534 * Error code. 0~means success. 535 */ 536 typedef int 537 (*FT_Outline_LineToFunc)( const FT_Vector* to, 538 void* user ); 539 540 #define FT_Outline_LineTo_Func FT_Outline_LineToFunc 541 542 543 /************************************************************************** 544 * 545 * @functype: 546 * FT_Outline_ConicToFunc 547 * 548 * @description: 549 * A function pointer type used to describe the signature of a 'conic to' 550 * function during outline walking or decomposition. 551 * 552 * A 'conic to' is emitted to indicate a second-order Bezier arc in the 553 * outline. 554 * 555 * @input: 556 * control :: 557 * An intermediate control point between the last position and the new 558 * target in `to`. 559 * 560 * to :: 561 * A pointer to the target end point of the conic arc. 562 * 563 * user :: 564 * A typeless pointer, which is passed from the caller of the 565 * decomposition function. 566 * 567 * @return: 568 * Error code. 0~means success. 569 */ 570 typedef int 571 (*FT_Outline_ConicToFunc)( const FT_Vector* control, 572 const FT_Vector* to, 573 void* user ); 574 575 #define FT_Outline_ConicTo_Func FT_Outline_ConicToFunc 576 577 578 /************************************************************************** 579 * 580 * @functype: 581 * FT_Outline_CubicToFunc 582 * 583 * @description: 584 * A function pointer type used to describe the signature of a 'cubic to' 585 * function during outline walking or decomposition. 586 * 587 * A 'cubic to' is emitted to indicate a third-order Bezier arc. 588 * 589 * @input: 590 * control1 :: 591 * A pointer to the first Bezier control point. 592 * 593 * control2 :: 594 * A pointer to the second Bezier control point. 595 * 596 * to :: 597 * A pointer to the target end point. 598 * 599 * user :: 600 * A typeless pointer, which is passed from the caller of the 601 * decomposition function. 602 * 603 * @return: 604 * Error code. 0~means success. 605 */ 606 typedef int 607 (*FT_Outline_CubicToFunc)( const FT_Vector* control1, 608 const FT_Vector* control2, 609 const FT_Vector* to, 610 void* user ); 611 612 #define FT_Outline_CubicTo_Func FT_Outline_CubicToFunc 613 614 615 /************************************************************************** 616 * 617 * @struct: 618 * FT_Outline_Funcs 619 * 620 * @description: 621 * A structure to hold various function pointers used during outline 622 * decomposition in order to emit segments, conic, and cubic Beziers. 623 * 624 * @fields: 625 * move_to :: 626 * The 'move to' emitter. 627 * 628 * line_to :: 629 * The segment emitter. 630 * 631 * conic_to :: 632 * The second-order Bezier arc emitter. 633 * 634 * cubic_to :: 635 * The third-order Bezier arc emitter. 636 * 637 * shift :: 638 * The shift that is applied to coordinates before they are sent to the 639 * emitter. 640 * 641 * delta :: 642 * The delta that is applied to coordinates before they are sent to the 643 * emitter, but after the shift. 644 * 645 * @note: 646 * The point coordinates sent to the emitters are the transformed version 647 * of the original coordinates (this is important for high accuracy 648 * during scan-conversion). The transformation is simple: 649 * 650 * ``` 651 * x' = (x << shift) - delta 652 * y' = (y << shift) - delta 653 * ``` 654 * 655 * Set the values of `shift` and `delta` to~0 to get the original point 656 * coordinates. 657 */ 658 typedef struct FT_Outline_Funcs_ 659 { 660 FT_Outline_MoveToFunc move_to; 661 FT_Outline_LineToFunc line_to; 662 FT_Outline_ConicToFunc conic_to; 663 FT_Outline_CubicToFunc cubic_to; 664 665 int shift; 666 FT_Pos delta; 667 668 } FT_Outline_Funcs; 669 670 671 /************************************************************************** 672 * 673 * @section: 674 * basic_types 675 * 676 */ 677 678 679 /************************************************************************** 680 * 681 * @macro: 682 * FT_IMAGE_TAG 683 * 684 * @description: 685 * This macro converts four-letter tags to an unsigned long type. 686 * 687 * @note: 688 * Since many 16-bit compilers don't like 32-bit enumerations, you should 689 * redefine this macro in case of problems to something like this: 690 * 691 * ``` 692 * #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value 693 * ``` 694 * 695 * to get a simple enumeration without assigning special numbers. 696 */ 697 #ifndef FT_IMAGE_TAG 698 699 #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \ 700 value = ( ( FT_STATIC_BYTE_CAST( unsigned long, _x1 ) << 24 ) | \ 701 ( FT_STATIC_BYTE_CAST( unsigned long, _x2 ) << 16 ) | \ 702 ( FT_STATIC_BYTE_CAST( unsigned long, _x3 ) << 8 ) | \ 703 FT_STATIC_BYTE_CAST( unsigned long, _x4 ) ) 704 705 #endif /* FT_IMAGE_TAG */ 706 707 708 /************************************************************************** 709 * 710 * @enum: 711 * FT_Glyph_Format 712 * 713 * @description: 714 * An enumeration type used to describe the format of a given glyph 715 * image. Note that this version of FreeType only supports two image 716 * formats, even though future font drivers will be able to register 717 * their own format. 718 * 719 * @values: 720 * FT_GLYPH_FORMAT_NONE :: 721 * The value~0 is reserved. 722 * 723 * FT_GLYPH_FORMAT_COMPOSITE :: 724 * The glyph image is a composite of several other images. This format 725 * is _only_ used with @FT_LOAD_NO_RECURSE, and is used to report 726 * compound glyphs (like accented characters). 727 * 728 * FT_GLYPH_FORMAT_BITMAP :: 729 * The glyph image is a bitmap, and can be described as an @FT_Bitmap. 730 * You generally need to access the `bitmap` field of the 731 * @FT_GlyphSlotRec structure to read it. 732 * 733 * FT_GLYPH_FORMAT_OUTLINE :: 734 * The glyph image is a vectorial outline made of line segments and 735 * Bezier arcs; it can be described as an @FT_Outline; you generally 736 * want to access the `outline` field of the @FT_GlyphSlotRec structure 737 * to read it. 738 * 739 * FT_GLYPH_FORMAT_PLOTTER :: 740 * The glyph image is a vectorial path with no inside and outside 741 * contours. Some Type~1 fonts, like those in the Hershey family, 742 * contain glyphs in this format. These are described as @FT_Outline, 743 * but FreeType isn't currently capable of rendering them correctly. 744 * 745 * FT_GLYPH_FORMAT_SVG :: 746 * [Since 2.12] The glyph is represented by an SVG document in the 747 * 'SVG~' table. 748 */ 749 typedef enum FT_Glyph_Format_ 750 { 751 FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE, 0, 0, 0, 0 ), 752 753 FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE, 'c', 'o', 'm', 'p' ), 754 FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP, 'b', 'i', 't', 's' ), 755 FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE, 'o', 'u', 't', 'l' ), 756 FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER, 'p', 'l', 'o', 't' ), 757 FT_IMAGE_TAG( FT_GLYPH_FORMAT_SVG, 'S', 'V', 'G', ' ' ) 758 759 } FT_Glyph_Format; 760 761 762 /* these constants are deprecated; use the corresponding */ 763 /* `FT_Glyph_Format` values instead. */ 764 #define ft_glyph_format_none FT_GLYPH_FORMAT_NONE 765 #define ft_glyph_format_composite FT_GLYPH_FORMAT_COMPOSITE 766 #define ft_glyph_format_bitmap FT_GLYPH_FORMAT_BITMAP 767 #define ft_glyph_format_outline FT_GLYPH_FORMAT_OUTLINE 768 #define ft_glyph_format_plotter FT_GLYPH_FORMAT_PLOTTER 769 770 771 /*************************************************************************/ 772 /*************************************************************************/ 773 /*************************************************************************/ 774 /***** *****/ 775 /***** R A S T E R D E F I N I T I O N S *****/ 776 /***** *****/ 777 /*************************************************************************/ 778 /*************************************************************************/ 779 /*************************************************************************/ 780 781 782 783 /************************************************************************** 784 * 785 * @section: 786 * raster 787 * 788 * @title: 789 * Scanline Converter 790 * 791 * @abstract: 792 * How vectorial outlines are converted into bitmaps and pixmaps. 793 * 794 * @description: 795 * A raster or a rasterizer is a scan converter in charge of producing a 796 * pixel coverage bitmap that can be used as an alpha channel when 797 * compositing a glyph with a background. FreeType comes with two 798 * rasterizers: bilevel `raster1` and anti-aliased `smooth` are two 799 * separate modules. They are usually called from the high-level 800 * @FT_Load_Glyph or @FT_Render_Glyph functions and produce the entire 801 * coverage bitmap at once, while staying largely invisible to users. 802 * 803 * Instead of working with complete coverage bitmaps, it is also possible 804 * to intercept consecutive pixel runs on the same scanline with the same 805 * coverage, called _spans_, and process them individually. Only the 806 * `smooth` rasterizer permits this when calling @FT_Outline_Render with 807 * @FT_Raster_Params as described below. 808 * 809 * Working with either complete bitmaps or spans it is important to think 810 * of them as colorless coverage objects suitable as alpha channels to 811 * blend arbitrary colors with a background. For best results, it is 812 * recommended to use gamma correction, too. 813 * 814 * This section also describes the public API needed to set up alternative 815 * @FT_Renderer modules. 816 * 817 * @order: 818 * FT_Span 819 * FT_SpanFunc 820 * FT_Raster_Params 821 * FT_RASTER_FLAG_XXX 822 * 823 * FT_Raster 824 * FT_Raster_NewFunc 825 * FT_Raster_DoneFunc 826 * FT_Raster_ResetFunc 827 * FT_Raster_SetModeFunc 828 * FT_Raster_RenderFunc 829 * FT_Raster_Funcs 830 * 831 */ 832 833 834 /************************************************************************** 835 * 836 * @struct: 837 * FT_Span 838 * 839 * @description: 840 * A structure to model a single span of consecutive pixels when 841 * rendering an anti-aliased bitmap. 842 * 843 * @fields: 844 * x :: 845 * The span's horizontal start position. 846 * 847 * len :: 848 * The span's length in pixels. 849 * 850 * coverage :: 851 * The span color/coverage, ranging from 0 (background) to 255 852 * (foreground). 853 * 854 * @note: 855 * This structure is used by the span drawing callback type named 856 * @FT_SpanFunc that takes the y~coordinate of the span as a parameter. 857 * 858 * The anti-aliased rasterizer produces coverage values from 0 to 255, 859 * this is, from completely transparent to completely opaque. 860 */ 861 typedef struct FT_Span_ 862 { 863 short x; 864 unsigned short len; 865 unsigned char coverage; 866 867 } FT_Span; 868 869 870 /************************************************************************** 871 * 872 * @functype: 873 * FT_SpanFunc 874 * 875 * @description: 876 * A function used as a call-back by the anti-aliased renderer in order 877 * to let client applications draw themselves the pixel spans on each 878 * scan line. 879 * 880 * @input: 881 * y :: 882 * The scanline's upward y~coordinate. 883 * 884 * count :: 885 * The number of spans to draw on this scanline. 886 * 887 * spans :: 888 * A table of `count` spans to draw on the scanline. 889 * 890 * user :: 891 * User-supplied data that is passed to the callback. 892 * 893 * @note: 894 * This callback allows client applications to directly render the spans 895 * of the anti-aliased bitmap to any kind of surfaces. 896 * 897 * This can be used to write anti-aliased outlines directly to a given 898 * background bitmap using alpha compositing. It can also be used for 899 * oversampling and averaging. 900 */ 901 typedef void 902 (*FT_SpanFunc)( int y, 903 int count, 904 const FT_Span* spans, 905 void* user ); 906 907 #define FT_Raster_Span_Func FT_SpanFunc 908 909 910 /************************************************************************** 911 * 912 * @functype: 913 * FT_Raster_BitTest_Func 914 * 915 * @description: 916 * Deprecated, unimplemented. 917 */ 918 typedef int 919 (*FT_Raster_BitTest_Func)( int y, 920 int x, 921 void* user ); 922 923 924 /************************************************************************** 925 * 926 * @functype: 927 * FT_Raster_BitSet_Func 928 * 929 * @description: 930 * Deprecated, unimplemented. 931 */ 932 typedef void 933 (*FT_Raster_BitSet_Func)( int y, 934 int x, 935 void* user ); 936 937 938 /************************************************************************** 939 * 940 * @enum: 941 * FT_RASTER_FLAG_XXX 942 * 943 * @description: 944 * A list of bit flag constants as used in the `flags` field of a 945 * @FT_Raster_Params structure. 946 * 947 * @values: 948 * FT_RASTER_FLAG_DEFAULT :: 949 * This value is 0. 950 * 951 * FT_RASTER_FLAG_AA :: 952 * This flag is set to indicate that an anti-aliased glyph image should 953 * be generated. Otherwise, it will be monochrome (1-bit). 954 * 955 * FT_RASTER_FLAG_DIRECT :: 956 * This flag is set to indicate direct rendering. In this mode, client 957 * applications must provide their own span callback. This lets them 958 * directly draw or compose over an existing bitmap. If this bit is 959 * _not_ set, the target pixmap's buffer _must_ be zeroed before 960 * rendering and the output will be clipped to its size. 961 * 962 * Direct rendering is only possible with anti-aliased glyphs. 963 * 964 * FT_RASTER_FLAG_CLIP :: 965 * This flag is only used in direct rendering mode. If set, the output 966 * will be clipped to a box specified in the `clip_box` field of the 967 * @FT_Raster_Params structure. Otherwise, the `clip_box` is 968 * effectively set to the bounding box and all spans are generated. 969 * 970 * FT_RASTER_FLAG_SDF :: 971 * This flag is set to indicate that a signed distance field glyph 972 * image should be generated. This is only used while rendering with 973 * the @FT_RENDER_MODE_SDF render mode. 974 */ 975 #define FT_RASTER_FLAG_DEFAULT 0x0 976 #define FT_RASTER_FLAG_AA 0x1 977 #define FT_RASTER_FLAG_DIRECT 0x2 978 #define FT_RASTER_FLAG_CLIP 0x4 979 #define FT_RASTER_FLAG_SDF 0x8 980 981 /* these constants are deprecated; use the corresponding */ 982 /* `FT_RASTER_FLAG_XXX` values instead */ 983 #define ft_raster_flag_default FT_RASTER_FLAG_DEFAULT 984 #define ft_raster_flag_aa FT_RASTER_FLAG_AA 985 #define ft_raster_flag_direct FT_RASTER_FLAG_DIRECT 986 #define ft_raster_flag_clip FT_RASTER_FLAG_CLIP 987 988 989 /************************************************************************** 990 * 991 * @struct: 992 * FT_Raster_Params 993 * 994 * @description: 995 * A structure to hold the parameters used by a raster's render function, 996 * passed as an argument to @FT_Outline_Render. 997 * 998 * @fields: 999 * target :: 1000 * The target bitmap. 1001 * 1002 * source :: 1003 * A pointer to the source glyph image (e.g., an @FT_Outline). 1004 * 1005 * flags :: 1006 * The rendering flags. 1007 * 1008 * gray_spans :: 1009 * The gray span drawing callback. 1010 * 1011 * black_spans :: 1012 * Unused. 1013 * 1014 * bit_test :: 1015 * Unused. 1016 * 1017 * bit_set :: 1018 * Unused. 1019 * 1020 * user :: 1021 * User-supplied data that is passed to each drawing callback. 1022 * 1023 * clip_box :: 1024 * An optional span clipping box expressed in _integer_ pixels 1025 * (not in 26.6 fixed-point units). 1026 * 1027 * @note: 1028 * The @FT_RASTER_FLAG_AA bit flag must be set in the `flags` to 1029 * generate an anti-aliased glyph bitmap, otherwise a monochrome bitmap 1030 * is generated. The `target` should have appropriate pixel mode and its 1031 * dimensions define the clipping region. 1032 * 1033 * If both @FT_RASTER_FLAG_AA and @FT_RASTER_FLAG_DIRECT bit flags 1034 * are set in `flags`, the raster calls an @FT_SpanFunc callback 1035 * `gray_spans` with `user` data as an argument ignoring `target`. This 1036 * allows direct composition over a pre-existing user surface to perform 1037 * the span drawing and composition. To optionally clip the spans, set 1038 * the @FT_RASTER_FLAG_CLIP flag and `clip_box`. The monochrome raster 1039 * does not support the direct mode. 1040 * 1041 * The gray-level rasterizer always uses 256 gray levels. If you want 1042 * fewer gray levels, you have to use @FT_RASTER_FLAG_DIRECT and reduce 1043 * the levels in the callback function. 1044 */ 1045 typedef struct FT_Raster_Params_ 1046 { 1047 const FT_Bitmap* target; 1048 const void* source; 1049 int flags; 1050 FT_SpanFunc gray_spans; 1051 FT_SpanFunc black_spans; /* unused */ 1052 FT_Raster_BitTest_Func bit_test; /* unused */ 1053 FT_Raster_BitSet_Func bit_set; /* unused */ 1054 void* user; 1055 FT_BBox clip_box; 1056 1057 } FT_Raster_Params; 1058 1059 1060 /************************************************************************** 1061 * 1062 * @type: 1063 * FT_Raster 1064 * 1065 * @description: 1066 * An opaque handle (pointer) to a raster object. Each object can be 1067 * used independently to convert an outline into a bitmap or pixmap. 1068 * 1069 * @note: 1070 * In FreeType 2, all rasters are now encapsulated within specific 1071 * @FT_Renderer modules and only used in their context. 1072 * 1073 */ 1074 typedef struct FT_RasterRec_* FT_Raster; 1075 1076 1077 /************************************************************************** 1078 * 1079 * @functype: 1080 * FT_Raster_NewFunc 1081 * 1082 * @description: 1083 * A function used to create a new raster object. 1084 * 1085 * @input: 1086 * memory :: 1087 * A handle to the memory allocator. 1088 * 1089 * @output: 1090 * raster :: 1091 * A handle to the new raster object. 1092 * 1093 * @return: 1094 * Error code. 0~means success. 1095 * 1096 * @note: 1097 * The `memory` parameter is a typeless pointer in order to avoid 1098 * un-wanted dependencies on the rest of the FreeType code. In practice, 1099 * it is an @FT_Memory object, i.e., a handle to the standard FreeType 1100 * memory allocator. However, this field can be completely ignored by a 1101 * given raster implementation. 1102 */ 1103 typedef int 1104 (*FT_Raster_NewFunc)( void* memory, 1105 FT_Raster* raster ); 1106 1107 #define FT_Raster_New_Func FT_Raster_NewFunc 1108 1109 1110 /************************************************************************** 1111 * 1112 * @functype: 1113 * FT_Raster_DoneFunc 1114 * 1115 * @description: 1116 * A function used to destroy a given raster object. 1117 * 1118 * @input: 1119 * raster :: 1120 * A handle to the raster object. 1121 */ 1122 typedef void 1123 (*FT_Raster_DoneFunc)( FT_Raster raster ); 1124 1125 #define FT_Raster_Done_Func FT_Raster_DoneFunc 1126 1127 1128 /************************************************************************** 1129 * 1130 * @functype: 1131 * FT_Raster_ResetFunc 1132 * 1133 * @description: 1134 * FreeType used to provide an area of memory called the 'render pool' 1135 * available to all registered rasterizers. This was not thread safe, 1136 * however, and now FreeType never allocates this pool. 1137 * 1138 * This function is called after a new raster object is created. 1139 * 1140 * @input: 1141 * raster :: 1142 * A handle to the new raster object. 1143 * 1144 * pool_base :: 1145 * Previously, the address in memory of the render pool. Set this to 1146 * `NULL`. 1147 * 1148 * pool_size :: 1149 * Previously, the size in bytes of the render pool. Set this to 0. 1150 * 1151 * @note: 1152 * Rasterizers should rely on dynamic or stack allocation if they want to 1153 * (a handle to the memory allocator is passed to the rasterizer 1154 * constructor). 1155 */ 1156 typedef void 1157 (*FT_Raster_ResetFunc)( FT_Raster raster, 1158 unsigned char* pool_base, 1159 unsigned long pool_size ); 1160 1161 #define FT_Raster_Reset_Func FT_Raster_ResetFunc 1162 1163 1164 /************************************************************************** 1165 * 1166 * @functype: 1167 * FT_Raster_SetModeFunc 1168 * 1169 * @description: 1170 * This function is a generic facility to change modes or attributes in a 1171 * given raster. This can be used for debugging purposes, or simply to 1172 * allow implementation-specific 'features' in a given raster module. 1173 * 1174 * @input: 1175 * raster :: 1176 * A handle to the new raster object. 1177 * 1178 * mode :: 1179 * A 4-byte tag used to name the mode or property. 1180 * 1181 * args :: 1182 * A pointer to the new mode/property to use. 1183 */ 1184 typedef int 1185 (*FT_Raster_SetModeFunc)( FT_Raster raster, 1186 unsigned long mode, 1187 void* args ); 1188 1189 #define FT_Raster_Set_Mode_Func FT_Raster_SetModeFunc 1190 1191 1192 /************************************************************************** 1193 * 1194 * @functype: 1195 * FT_Raster_RenderFunc 1196 * 1197 * @description: 1198 * Invoke a given raster to scan-convert a given glyph image into a 1199 * target bitmap. 1200 * 1201 * @input: 1202 * raster :: 1203 * A handle to the raster object. 1204 * 1205 * params :: 1206 * A pointer to an @FT_Raster_Params structure used to store the 1207 * rendering parameters. 1208 * 1209 * @return: 1210 * Error code. 0~means success. 1211 * 1212 * @note: 1213 * The exact format of the source image depends on the raster's glyph 1214 * format defined in its @FT_Raster_Funcs structure. It can be an 1215 * @FT_Outline or anything else in order to support a large array of 1216 * glyph formats. 1217 * 1218 * Note also that the render function can fail and return a 1219 * `FT_Err_Unimplemented_Feature` error code if the raster used does not 1220 * support direct composition. 1221 */ 1222 typedef int 1223 (*FT_Raster_RenderFunc)( FT_Raster raster, 1224 const FT_Raster_Params* params ); 1225 1226 #define FT_Raster_Render_Func FT_Raster_RenderFunc 1227 1228 1229 /************************************************************************** 1230 * 1231 * @struct: 1232 * FT_Raster_Funcs 1233 * 1234 * @description: 1235 * A structure used to describe a given raster class to the library. 1236 * 1237 * @fields: 1238 * glyph_format :: 1239 * The supported glyph format for this raster. 1240 * 1241 * raster_new :: 1242 * The raster constructor. 1243 * 1244 * raster_reset :: 1245 * Used to reset the render pool within the raster. 1246 * 1247 * raster_render :: 1248 * A function to render a glyph into a given bitmap. 1249 * 1250 * raster_done :: 1251 * The raster destructor. 1252 */ 1253 typedef struct FT_Raster_Funcs_ 1254 { 1255 FT_Glyph_Format glyph_format; 1256 1257 FT_Raster_NewFunc raster_new; 1258 FT_Raster_ResetFunc raster_reset; 1259 FT_Raster_SetModeFunc raster_set_mode; 1260 FT_Raster_RenderFunc raster_render; 1261 FT_Raster_DoneFunc raster_done; 1262 1263 } FT_Raster_Funcs; 1264 1265 /* */ 1266 1267 1268 FT_END_HEADER 1269 1270 #endif /* FTIMAGE_H_ */ 1271 1272 1273 /* END */ 1274 1275 1276 /* Local Variables: */ 1277 /* coding: utf-8 */ 1278 /* End: */ 1279