1 /**************************************************************************** 2 * 3 * ftimage.h 4 * 5 * FreeType glyph image formats and default raster interface 6 * (specification). 7 * 8 * Copyright (C) 1996-2020 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 /* STANDALONE_ is from ftgrays.c */ 32 #ifndef STANDALONE_ 33 #endif 34 35 36 FT_BEGIN_HEADER 37 38 39 /************************************************************************** 40 * 41 * @section: 42 * basic_types 43 * 44 */ 45 46 47 /************************************************************************** 48 * 49 * @type: 50 * FT_Pos 51 * 52 * @description: 53 * The type FT_Pos is used to store vectorial coordinates. Depending on 54 * the context, these can represent distances in integer font units, or 55 * 16.16, or 26.6 fixed-point pixel coordinates. 56 */ 57 typedef signed long FT_Pos; 58 59 60 /************************************************************************** 61 * 62 * @struct: 63 * FT_Vector 64 * 65 * @description: 66 * A simple structure used to store a 2D vector; coordinates are of the 67 * FT_Pos type. 68 * 69 * @fields: 70 * x :: 71 * The horizontal coordinate. 72 * y :: 73 * The vertical coordinate. 74 */ 75 typedef struct FT_Vector_ 76 { 77 FT_Pos x; 78 FT_Pos y; 79 80 } FT_Vector; 81 82 83 /************************************************************************** 84 * 85 * @struct: 86 * FT_BBox 87 * 88 * @description: 89 * A structure used to hold an outline's bounding box, i.e., the 90 * coordinates of its extrema in the horizontal and vertical directions. 91 * 92 * @fields: 93 * xMin :: 94 * The horizontal minimum (left-most). 95 * 96 * yMin :: 97 * The vertical minimum (bottom-most). 98 * 99 * xMax :: 100 * The horizontal maximum (right-most). 101 * 102 * yMax :: 103 * The vertical maximum (top-most). 104 * 105 * @note: 106 * The bounding box is specified with the coordinates of the lower left 107 * and the upper right corner. In PostScript, those values are often 108 * called (llx,lly) and (urx,ury), respectively. 109 * 110 * If `yMin` is negative, this value gives the glyph's descender. 111 * Otherwise, the glyph doesn't descend below the baseline. Similarly, 112 * if `ymax` is positive, this value gives the glyph's ascender. 113 * 114 * `xMin` gives the horizontal distance from the glyph's origin to the 115 * left edge of the glyph's bounding box. If `xMin` is negative, the 116 * glyph extends to the left of the origin. 117 */ 118 typedef struct FT_BBox_ 119 { 120 FT_Pos xMin, yMin; 121 FT_Pos xMax, yMax; 122 123 } FT_BBox; 124 125 126 /************************************************************************** 127 * 128 * @enum: 129 * FT_Pixel_Mode 130 * 131 * @description: 132 * An enumeration type used to describe the format of pixels in a given 133 * bitmap. Note that additional formats may be added in the future. 134 * 135 * @values: 136 * FT_PIXEL_MODE_NONE :: 137 * Value~0 is reserved. 138 * 139 * FT_PIXEL_MODE_MONO :: 140 * A monochrome bitmap, using 1~bit per pixel. Note that pixels are 141 * stored in most-significant order (MSB), which means that the 142 * left-most pixel in a byte has value 128. 143 * 144 * FT_PIXEL_MODE_GRAY :: 145 * An 8-bit bitmap, generally used to represent anti-aliased glyph 146 * images. Each pixel is stored in one byte. Note that the number of 147 * 'gray' levels is stored in the `num_grays` field of the @FT_Bitmap 148 * structure (it generally is 256). 149 * 150 * FT_PIXEL_MODE_GRAY2 :: 151 * A 2-bit per pixel bitmap, used to represent embedded anti-aliased 152 * bitmaps in font files according to the OpenType specification. We 153 * haven't found a single font using this format, however. 154 * 155 * FT_PIXEL_MODE_GRAY4 :: 156 * A 4-bit per pixel bitmap, representing embedded anti-aliased bitmaps 157 * in font files according to the OpenType specification. We haven't 158 * found a single font using this format, however. 159 * 160 * FT_PIXEL_MODE_LCD :: 161 * An 8-bit bitmap, representing RGB or BGR decimated glyph images used 162 * for display on LCD displays; the bitmap is three times wider than 163 * the original glyph image. See also @FT_RENDER_MODE_LCD. 164 * 165 * FT_PIXEL_MODE_LCD_V :: 166 * An 8-bit bitmap, representing RGB or BGR decimated glyph images used 167 * for display on rotated LCD displays; the bitmap is three times 168 * taller than the original glyph image. See also 169 * @FT_RENDER_MODE_LCD_V. 170 * 171 * FT_PIXEL_MODE_BGRA :: 172 * [Since 2.5] An image with four 8-bit channels per pixel, 173 * representing a color image (such as emoticons) with alpha channel. 174 * For each pixel, the format is BGRA, which means, the blue channel 175 * comes first in memory. The color channels are pre-multiplied and in 176 * the sRGB colorspace. For example, full red at half-translucent 177 * opacity will be represented as '00,00,80,80', not '00,00,FF,80'. 178 * See also @FT_LOAD_COLOR. 179 */ 180 typedef enum FT_Pixel_Mode_ 181 { 182 FT_PIXEL_MODE_NONE = 0, 183 FT_PIXEL_MODE_MONO, 184 FT_PIXEL_MODE_GRAY, 185 FT_PIXEL_MODE_GRAY2, 186 FT_PIXEL_MODE_GRAY4, 187 FT_PIXEL_MODE_LCD, 188 FT_PIXEL_MODE_LCD_V, 189 FT_PIXEL_MODE_BGRA, 190 191 FT_PIXEL_MODE_MAX /* do not remove */ 192 193 } FT_Pixel_Mode; 194 195 196 /* these constants are deprecated; use the corresponding `FT_Pixel_Mode` */ 197 /* values instead. */ 198 #define ft_pixel_mode_none FT_PIXEL_MODE_NONE 199 #define ft_pixel_mode_mono FT_PIXEL_MODE_MONO 200 #define ft_pixel_mode_grays FT_PIXEL_MODE_GRAY 201 #define ft_pixel_mode_pal2 FT_PIXEL_MODE_GRAY2 202 #define ft_pixel_mode_pal4 FT_PIXEL_MODE_GRAY4 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 * This flag indicates that this outline contains overlapping contrours 405 * and the anti-aliased renderer should perform oversampling to 406 * mitigate possible artifacts. This flag should _not_ be set for 407 * well designed glyphs without overlaps because it quadruples the 408 * 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 #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \ 699 value = ( ( (unsigned long)_x1 << 24 ) | \ 700 ( (unsigned long)_x2 << 16 ) | \ 701 ( (unsigned long)_x3 << 8 ) | \ 702 (unsigned long)_x4 ) 703 #endif /* FT_IMAGE_TAG */ 704 705 706 /************************************************************************** 707 * 708 * @enum: 709 * FT_Glyph_Format 710 * 711 * @description: 712 * An enumeration type used to describe the format of a given glyph 713 * image. Note that this version of FreeType only supports two image 714 * formats, even though future font drivers will be able to register 715 * their own format. 716 * 717 * @values: 718 * FT_GLYPH_FORMAT_NONE :: 719 * The value~0 is reserved. 720 * 721 * FT_GLYPH_FORMAT_COMPOSITE :: 722 * The glyph image is a composite of several other images. This format 723 * is _only_ used with @FT_LOAD_NO_RECURSE, and is used to report 724 * compound glyphs (like accented characters). 725 * 726 * FT_GLYPH_FORMAT_BITMAP :: 727 * The glyph image is a bitmap, and can be described as an @FT_Bitmap. 728 * You generally need to access the `bitmap` field of the 729 * @FT_GlyphSlotRec structure to read it. 730 * 731 * FT_GLYPH_FORMAT_OUTLINE :: 732 * The glyph image is a vectorial outline made of line segments and 733 * Bezier arcs; it can be described as an @FT_Outline; you generally 734 * want to access the `outline` field of the @FT_GlyphSlotRec structure 735 * to read it. 736 * 737 * FT_GLYPH_FORMAT_PLOTTER :: 738 * The glyph image is a vectorial path with no inside and outside 739 * contours. Some Type~1 fonts, like those in the Hershey family, 740 * contain glyphs in this format. These are described as @FT_Outline, 741 * but FreeType isn't currently capable of rendering them correctly. 742 */ 743 typedef enum FT_Glyph_Format_ 744 { 745 FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE, 0, 0, 0, 0 ), 746 747 FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE, 'c', 'o', 'm', 'p' ), 748 FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP, 'b', 'i', 't', 's' ), 749 FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE, 'o', 'u', 't', 'l' ), 750 FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER, 'p', 'l', 'o', 't' ) 751 752 } FT_Glyph_Format; 753 754 755 /* these constants are deprecated; use the corresponding */ 756 /* `FT_Glyph_Format` values instead. */ 757 #define ft_glyph_format_none FT_GLYPH_FORMAT_NONE 758 #define ft_glyph_format_composite FT_GLYPH_FORMAT_COMPOSITE 759 #define ft_glyph_format_bitmap FT_GLYPH_FORMAT_BITMAP 760 #define ft_glyph_format_outline FT_GLYPH_FORMAT_OUTLINE 761 #define ft_glyph_format_plotter FT_GLYPH_FORMAT_PLOTTER 762 763 764 /*************************************************************************/ 765 /*************************************************************************/ 766 /*************************************************************************/ 767 /***** *****/ 768 /***** R A S T E R D E F I N I T I O N S *****/ 769 /***** *****/ 770 /*************************************************************************/ 771 /*************************************************************************/ 772 /*************************************************************************/ 773 774 775 /************************************************************************** 776 * 777 * A raster is a scan converter, in charge of rendering an outline into a 778 * bitmap. This section contains the public API for rasters. 779 * 780 * Note that in FreeType 2, all rasters are now encapsulated within 781 * specific modules called 'renderers'. See `ftrender.h` for more details 782 * on renderers. 783 * 784 */ 785 786 787 /************************************************************************** 788 * 789 * @section: 790 * raster 791 * 792 * @title: 793 * Scanline Converter 794 * 795 * @abstract: 796 * How vectorial outlines are converted into bitmaps and pixmaps. 797 * 798 * @description: 799 * This section contains technical definitions. 800 * 801 * @order: 802 * FT_Raster 803 * FT_Span 804 * FT_SpanFunc 805 * 806 * FT_Raster_Params 807 * FT_RASTER_FLAG_XXX 808 * 809 * FT_Raster_NewFunc 810 * FT_Raster_DoneFunc 811 * FT_Raster_ResetFunc 812 * FT_Raster_SetModeFunc 813 * FT_Raster_RenderFunc 814 * FT_Raster_Funcs 815 * 816 */ 817 818 819 /************************************************************************** 820 * 821 * @type: 822 * FT_Raster 823 * 824 * @description: 825 * An opaque handle (pointer) to a raster object. Each object can be 826 * used independently to convert an outline into a bitmap or pixmap. 827 */ 828 typedef struct FT_RasterRec_* FT_Raster; 829 830 831 /************************************************************************** 832 * 833 * @struct: 834 * FT_Span 835 * 836 * @description: 837 * A structure used to model a single span of gray pixels when rendering 838 * an anti-aliased bitmap. 839 * 840 * @fields: 841 * x :: 842 * The span's horizontal start position. 843 * 844 * len :: 845 * The span's length in pixels. 846 * 847 * coverage :: 848 * The span color/coverage, ranging from 0 (background) to 255 849 * (foreground). 850 * 851 * @note: 852 * This structure is used by the span drawing callback type named 853 * @FT_SpanFunc that takes the y~coordinate of the span as a parameter. 854 * 855 * The coverage value is always between 0 and 255. If you want less gray 856 * values, the callback function has to reduce them. 857 */ 858 typedef struct FT_Span_ 859 { 860 short x; 861 unsigned short len; 862 unsigned char coverage; 863 864 } FT_Span; 865 866 867 /************************************************************************** 868 * 869 * @functype: 870 * FT_SpanFunc 871 * 872 * @description: 873 * A function used as a call-back by the anti-aliased renderer in order 874 * to let client applications draw themselves the gray pixel spans on 875 * each scan line. 876 * 877 * @input: 878 * y :: 879 * The scanline's upward y~coordinate. 880 * 881 * count :: 882 * The number of spans to draw on this scanline. 883 * 884 * spans :: 885 * A table of `count` spans to draw on the scanline. 886 * 887 * user :: 888 * User-supplied data that is passed to the callback. 889 * 890 * @note: 891 * This callback allows client applications to directly render the gray 892 * spans of the anti-aliased bitmap to any kind of surfaces. 893 * 894 * This can be used to write anti-aliased outlines directly to a given 895 * background bitmap, and even perform translucency. 896 */ 897 typedef void 898 (*FT_SpanFunc)( int y, 899 int count, 900 const FT_Span* spans, 901 void* user ); 902 903 #define FT_Raster_Span_Func FT_SpanFunc 904 905 906 /************************************************************************** 907 * 908 * @functype: 909 * FT_Raster_BitTest_Func 910 * 911 * @description: 912 * Deprecated, unimplemented. 913 */ 914 typedef int 915 (*FT_Raster_BitTest_Func)( int y, 916 int x, 917 void* user ); 918 919 920 /************************************************************************** 921 * 922 * @functype: 923 * FT_Raster_BitSet_Func 924 * 925 * @description: 926 * Deprecated, unimplemented. 927 */ 928 typedef void 929 (*FT_Raster_BitSet_Func)( int y, 930 int x, 931 void* user ); 932 933 934 /************************************************************************** 935 * 936 * @enum: 937 * FT_RASTER_FLAG_XXX 938 * 939 * @description: 940 * A list of bit flag constants as used in the `flags` field of a 941 * @FT_Raster_Params structure. 942 * 943 * @values: 944 * FT_RASTER_FLAG_DEFAULT :: 945 * This value is 0. 946 * 947 * FT_RASTER_FLAG_AA :: 948 * This flag is set to indicate that an anti-aliased glyph image should 949 * be generated. Otherwise, it will be monochrome (1-bit). 950 * 951 * FT_RASTER_FLAG_DIRECT :: 952 * This flag is set to indicate direct rendering. In this mode, client 953 * applications must provide their own span callback. This lets them 954 * directly draw or compose over an existing bitmap. If this bit is 955 * _not_ set, the target pixmap's buffer _must_ be zeroed before 956 * rendering and the output will be clipped to its size. 957 * 958 * Direct rendering is only possible with anti-aliased glyphs. 959 * 960 * FT_RASTER_FLAG_CLIP :: 961 * This flag is only used in direct rendering mode. If set, the output 962 * will be clipped to a box specified in the `clip_box` field of the 963 * @FT_Raster_Params structure. Otherwise, the `clip_box` is 964 * effectively set to the bounding box and all spans are generated. 965 */ 966 #define FT_RASTER_FLAG_DEFAULT 0x0 967 #define FT_RASTER_FLAG_AA 0x1 968 #define FT_RASTER_FLAG_DIRECT 0x2 969 #define FT_RASTER_FLAG_CLIP 0x4 970 971 /* these constants are deprecated; use the corresponding */ 972 /* `FT_RASTER_FLAG_XXX` values instead */ 973 #define ft_raster_flag_default FT_RASTER_FLAG_DEFAULT 974 #define ft_raster_flag_aa FT_RASTER_FLAG_AA 975 #define ft_raster_flag_direct FT_RASTER_FLAG_DIRECT 976 #define ft_raster_flag_clip FT_RASTER_FLAG_CLIP 977 978 979 /************************************************************************** 980 * 981 * @struct: 982 * FT_Raster_Params 983 * 984 * @description: 985 * A structure to hold the parameters used by a raster's render function, 986 * passed as an argument to @FT_Outline_Render. 987 * 988 * @fields: 989 * target :: 990 * The target bitmap. 991 * 992 * source :: 993 * A pointer to the source glyph image (e.g., an @FT_Outline). 994 * 995 * flags :: 996 * The rendering flags. 997 * 998 * gray_spans :: 999 * The gray span drawing callback. 1000 * 1001 * black_spans :: 1002 * Unused. 1003 * 1004 * bit_test :: 1005 * Unused. 1006 * 1007 * bit_set :: 1008 * Unused. 1009 * 1010 * user :: 1011 * User-supplied data that is passed to each drawing callback. 1012 * 1013 * clip_box :: 1014 * An optional span clipping box expressed in _integer_ pixels 1015 * (not in 26.6 fixed-point units). 1016 * 1017 * @note: 1018 * The @FT_RASTER_FLAG_AA bit flag must be set in the `flags` to 1019 * generate an anti-aliased glyph bitmap, otherwise a monochrome bitmap 1020 * is generated. The `target` should have appropriate pixel mode and its 1021 * dimensions define the clipping region. 1022 * 1023 * If both @FT_RASTER_FLAG_AA and @FT_RASTER_FLAG_DIRECT bit flags 1024 * are set in `flags`, the raster calls an @FT_SpanFunc callback 1025 * `gray_spans` with `user` data as an argument ignoring `target`. This 1026 * allows direct composition over a pre-existing user surface to perform 1027 * the span drawing and composition. To optionally clip the spans, set 1028 * the @FT_RASTER_FLAG_CLIP flag and `clip_box`. The monochrome raster 1029 * does not support the direct mode. 1030 * 1031 * The gray-level rasterizer always uses 256 gray levels. If you want 1032 * fewer gray levels, you have to use @FT_RASTER_FLAG_DIRECT and reduce 1033 * the levels in the callback function. 1034 */ 1035 typedef struct FT_Raster_Params_ 1036 { 1037 const FT_Bitmap* target; 1038 const void* source; 1039 int flags; 1040 FT_SpanFunc gray_spans; 1041 FT_SpanFunc black_spans; /* unused */ 1042 FT_Raster_BitTest_Func bit_test; /* unused */ 1043 FT_Raster_BitSet_Func bit_set; /* unused */ 1044 void* user; 1045 FT_BBox clip_box; 1046 1047 } FT_Raster_Params; 1048 1049 1050 /************************************************************************** 1051 * 1052 * @functype: 1053 * FT_Raster_NewFunc 1054 * 1055 * @description: 1056 * A function used to create a new raster object. 1057 * 1058 * @input: 1059 * memory :: 1060 * A handle to the memory allocator. 1061 * 1062 * @output: 1063 * raster :: 1064 * A handle to the new raster object. 1065 * 1066 * @return: 1067 * Error code. 0~means success. 1068 * 1069 * @note: 1070 * The `memory` parameter is a typeless pointer in order to avoid 1071 * un-wanted dependencies on the rest of the FreeType code. In practice, 1072 * it is an @FT_Memory object, i.e., a handle to the standard FreeType 1073 * memory allocator. However, this field can be completely ignored by a 1074 * given raster implementation. 1075 */ 1076 typedef int 1077 (*FT_Raster_NewFunc)( void* memory, 1078 FT_Raster* raster ); 1079 1080 #define FT_Raster_New_Func FT_Raster_NewFunc 1081 1082 1083 /************************************************************************** 1084 * 1085 * @functype: 1086 * FT_Raster_DoneFunc 1087 * 1088 * @description: 1089 * A function used to destroy a given raster object. 1090 * 1091 * @input: 1092 * raster :: 1093 * A handle to the raster object. 1094 */ 1095 typedef void 1096 (*FT_Raster_DoneFunc)( FT_Raster raster ); 1097 1098 #define FT_Raster_Done_Func FT_Raster_DoneFunc 1099 1100 1101 /************************************************************************** 1102 * 1103 * @functype: 1104 * FT_Raster_ResetFunc 1105 * 1106 * @description: 1107 * FreeType used to provide an area of memory called the 'render pool' 1108 * available to all registered rasterizers. This was not thread safe, 1109 * however, and now FreeType never allocates this pool. 1110 * 1111 * This function is called after a new raster object is created. 1112 * 1113 * @input: 1114 * raster :: 1115 * A handle to the new raster object. 1116 * 1117 * pool_base :: 1118 * Previously, the address in memory of the render pool. Set this to 1119 * `NULL`. 1120 * 1121 * pool_size :: 1122 * Previously, the size in bytes of the render pool. Set this to 0. 1123 * 1124 * @note: 1125 * Rasterizers should rely on dynamic or stack allocation if they want to 1126 * (a handle to the memory allocator is passed to the rasterizer 1127 * constructor). 1128 */ 1129 typedef void 1130 (*FT_Raster_ResetFunc)( FT_Raster raster, 1131 unsigned char* pool_base, 1132 unsigned long pool_size ); 1133 1134 #define FT_Raster_Reset_Func FT_Raster_ResetFunc 1135 1136 1137 /************************************************************************** 1138 * 1139 * @functype: 1140 * FT_Raster_SetModeFunc 1141 * 1142 * @description: 1143 * This function is a generic facility to change modes or attributes in a 1144 * given raster. This can be used for debugging purposes, or simply to 1145 * allow implementation-specific 'features' in a given raster module. 1146 * 1147 * @input: 1148 * raster :: 1149 * A handle to the new raster object. 1150 * 1151 * mode :: 1152 * A 4-byte tag used to name the mode or property. 1153 * 1154 * args :: 1155 * A pointer to the new mode/property to use. 1156 */ 1157 typedef int 1158 (*FT_Raster_SetModeFunc)( FT_Raster raster, 1159 unsigned long mode, 1160 void* args ); 1161 1162 #define FT_Raster_Set_Mode_Func FT_Raster_SetModeFunc 1163 1164 1165 /************************************************************************** 1166 * 1167 * @functype: 1168 * FT_Raster_RenderFunc 1169 * 1170 * @description: 1171 * Invoke a given raster to scan-convert a given glyph image into a 1172 * target bitmap. 1173 * 1174 * @input: 1175 * raster :: 1176 * A handle to the raster object. 1177 * 1178 * params :: 1179 * A pointer to an @FT_Raster_Params structure used to store the 1180 * rendering parameters. 1181 * 1182 * @return: 1183 * Error code. 0~means success. 1184 * 1185 * @note: 1186 * The exact format of the source image depends on the raster's glyph 1187 * format defined in its @FT_Raster_Funcs structure. It can be an 1188 * @FT_Outline or anything else in order to support a large array of 1189 * glyph formats. 1190 * 1191 * Note also that the render function can fail and return a 1192 * `FT_Err_Unimplemented_Feature` error code if the raster used does not 1193 * support direct composition. 1194 */ 1195 typedef int 1196 (*FT_Raster_RenderFunc)( FT_Raster raster, 1197 const FT_Raster_Params* params ); 1198 1199 #define FT_Raster_Render_Func FT_Raster_RenderFunc 1200 1201 1202 /************************************************************************** 1203 * 1204 * @struct: 1205 * FT_Raster_Funcs 1206 * 1207 * @description: 1208 * A structure used to describe a given raster class to the library. 1209 * 1210 * @fields: 1211 * glyph_format :: 1212 * The supported glyph format for this raster. 1213 * 1214 * raster_new :: 1215 * The raster constructor. 1216 * 1217 * raster_reset :: 1218 * Used to reset the render pool within the raster. 1219 * 1220 * raster_render :: 1221 * A function to render a glyph into a given bitmap. 1222 * 1223 * raster_done :: 1224 * The raster destructor. 1225 */ 1226 typedef struct FT_Raster_Funcs_ 1227 { 1228 FT_Glyph_Format glyph_format; 1229 1230 FT_Raster_NewFunc raster_new; 1231 FT_Raster_ResetFunc raster_reset; 1232 FT_Raster_SetModeFunc raster_set_mode; 1233 FT_Raster_RenderFunc raster_render; 1234 FT_Raster_DoneFunc raster_done; 1235 1236 } FT_Raster_Funcs; 1237 1238 /* */ 1239 1240 1241 FT_END_HEADER 1242 1243 #endif /* FTIMAGE_H_ */ 1244 1245 1246 /* END */ 1247 1248 1249 /* Local Variables: */ 1250 /* coding: utf-8 */ 1251 /* End: */ 1252