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