1/****************************************************************************
2 *
3 * ftimage.h
4 *
5 * FreeType glyph image formats and default raster interface
6 * (specification).
7 *
8 * Copyright (C) 1996-2021 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
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 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
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 typedef enum FT_Glyph_Format_
746 {
747 FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE, 0, 0, 0, 0 ),
748
749 FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE, 'c', 'o', 'm', 'p' ),
750 FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP, 'b', 'i', 't', 's' ),
751 FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE, 'o', 'u', 't', 'l' ),
752 FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER, 'p', 'l', 'o', 't' )
753
754 } FT_Glyph_Format;
755
756
757 /* these constants are deprecated; use the corresponding */
758 /* `FT_Glyph_Format` values instead. */
759#define ft_glyph_format_none FT_GLYPH_FORMAT_NONE
760#define ft_glyph_format_composite FT_GLYPH_FORMAT_COMPOSITE
761#define ft_glyph_format_bitmap FT_GLYPH_FORMAT_BITMAP
762#define ft_glyph_format_outline FT_GLYPH_FORMAT_OUTLINE
763#define ft_glyph_format_plotter FT_GLYPH_FORMAT_PLOTTER
764
765
766 /*************************************************************************/
767 /*************************************************************************/
768 /*************************************************************************/
769 /***** *****/
770 /***** R A S T E R D E F I N I T I O N S *****/
771 /***** *****/
772 /*************************************************************************/
773 /*************************************************************************/
774 /*************************************************************************/
775
776
777
778 /**************************************************************************
779 *
780 * @section:
781 * raster
782 *
783 * @title:
784 * Scanline Converter
785 *
786 * @abstract:
787 * How vectorial outlines are converted into bitmaps and pixmaps.
788 *
789 * @description:
790 * A raster or a rasterizer is a scan converter in charge of producing a
791 * pixel coverage bitmap that can be used as an alpha channel when
792 * compositing a glyph with a background. FreeType comes with two
793 * rasterizers: bilevel `raster1` and anti-aliased `smooth` are two
794 * separate modules. They are usually called from the high-level
795 * @FT_Load_Glyph or @FT_Render_Glyph functions and produce the entire
796 * coverage bitmap at once, while staying largely invisible to users.
797 *
798 * Instead of working with complete coverage bitmaps, it is also possible
799 * to intercept consecutive pixel runs on the same scanline with the same
800 * coverage, called _spans_, and process them individually. Only the
801 * `smooth` rasterizer permits this when calling @FT_Outline_Render with
802 * @FT_Raster_Params as described below.
803 *
804 * Working with either complete bitmaps or spans it is important to think
805 * of them as colorless coverage objects suitable as alpha channels to
806 * blend arbitrary colors with a background. For best results, it is
807 * recommended to use gamma correction, too.
808 *
809 * This section also describes the public API needed to set up alternative
810 * @FT_Renderer modules.
811 *
812 * @order:
813 * FT_Span
814 * FT_SpanFunc
815 * FT_Raster_Params
816 * FT_RASTER_FLAG_XXX
817 *
818 * FT_Raster
819 * FT_Raster_NewFunc
820 * FT_Raster_DoneFunc
821 * FT_Raster_ResetFunc
822 * FT_Raster_SetModeFunc
823 * FT_Raster_RenderFunc
824 * FT_Raster_Funcs
825 *
826 */
827
828
829 /**************************************************************************
830 *
831 * @struct:
832 * FT_Span
833 *
834 * @description:
835 * A structure to model a single span of consecutive pixels when
836 * rendering an anti-aliased bitmap.
837 *
838 * @fields:
839 * x ::
840 * The span's horizontal start position.
841 *
842 * len ::
843 * The span's length in pixels.
844 *
845 * coverage ::
846 * The span color/coverage, ranging from 0 (background) to 255
847 * (foreground).
848 *
849 * @note:
850 * This structure is used by the span drawing callback type named
851 * @FT_SpanFunc that takes the y~coordinate of the span as a parameter.
852 *
853 * The anti-aliased rasterizer produces coverage values from 0 to 255,
854 * this is, from completely transparent to completely opaque.
855 */
856 typedef struct FT_Span_
857 {
858 short x;
859 unsigned short len;
860 unsigned char coverage;
861
862 } FT_Span;
863
864
865 /**************************************************************************
866 *
867 * @functype:
868 * FT_SpanFunc
869 *
870 * @description:
871 * A function used as a call-back by the anti-aliased renderer in order
872 * to let client applications draw themselves the pixel spans on each
873 * scan line.
874 *
875 * @input:
876 * y ::
877 * The scanline's upward y~coordinate.
878 *
879 * count ::
880 * The number of spans to draw on this scanline.
881 *
882 * spans ::
883 * A table of `count` spans to draw on the scanline.
884 *
885 * user ::
886 * User-supplied data that is passed to the callback.
887 *
888 * @note:
889 * This callback allows client applications to directly render the spans
890 * of the anti-aliased bitmap to any kind of surfaces.
891 *
892 * This can be used to write anti-aliased outlines directly to a given
893 * background bitmap using alpha compositing. It can also be used for
894 * oversampling and averaging.
895 */
896 typedef void
897 (*FT_SpanFunc)( int y,
898 int count,
899 const FT_Span* spans,
900 void* user );
901
902#define FT_Raster_Span_Func FT_SpanFunc
903
904
905 /**************************************************************************
906 *
907 * @functype:
908 * FT_Raster_BitTest_Func
909 *
910 * @description:
911 * Deprecated, unimplemented.
912 */
913 typedef int
914 (*FT_Raster_BitTest_Func)( int y,
915 int x,
916 void* user );
917
918
919 /**************************************************************************
920 *
921 * @functype:
922 * FT_Raster_BitSet_Func
923 *
924 * @description:
925 * Deprecated, unimplemented.
926 */
927 typedef void
928 (*FT_Raster_BitSet_Func)( int y,
929 int x,
930 void* user );
931
932
933 /**************************************************************************
934 *
935 * @enum:
936 * FT_RASTER_FLAG_XXX
937 *
938 * @description:
939 * A list of bit flag constants as used in the `flags` field of a
940 * @FT_Raster_Params structure.
941 *
942 * @values:
943 * FT_RASTER_FLAG_DEFAULT ::
944 * This value is 0.
945 *
946 * FT_RASTER_FLAG_AA ::
947 * This flag is set to indicate that an anti-aliased glyph image should
948 * be generated. Otherwise, it will be monochrome (1-bit).
949 *
950 * FT_RASTER_FLAG_DIRECT ::
951 * This flag is set to indicate direct rendering. In this mode, client
952 * applications must provide their own span callback. This lets them
953 * directly draw or compose over an existing bitmap. If this bit is
954 * _not_ set, the target pixmap's buffer _must_ be zeroed before
955 * rendering and the output will be clipped to its size.
956 *
957 * Direct rendering is only possible with anti-aliased glyphs.
958 *
959 * FT_RASTER_FLAG_CLIP ::
960 * This flag is only used in direct rendering mode. If set, the output
961 * will be clipped to a box specified in the `clip_box` field of the
962 * @FT_Raster_Params structure. Otherwise, the `clip_box` is
963 * effectively set to the bounding box and all spans are generated.
964 *
965 * FT_RASTER_FLAG_SDF ::
966 * This flag is set to indicate that a signed distance field glyph
967 * image should be generated. This is only used while rendering with
968 * the @FT_RENDER_MODE_SDF render mode.
969 */
970#define FT_RASTER_FLAG_DEFAULT 0x0
971#define FT_RASTER_FLAG_AA 0x1
972#define FT_RASTER_FLAG_DIRECT 0x2
973#define FT_RASTER_FLAG_CLIP 0x4
974#define FT_RASTER_FLAG_SDF 0x8
975
976 /* these constants are deprecated; use the corresponding */
977 /* `FT_RASTER_FLAG_XXX` values instead */
978#define ft_raster_flag_default FT_RASTER_FLAG_DEFAULT
979#define ft_raster_flag_aa FT_RASTER_FLAG_AA
980#define ft_raster_flag_direct FT_RASTER_FLAG_DIRECT
981#define ft_raster_flag_clip FT_RASTER_FLAG_CLIP
982
983
984 /**************************************************************************
985 *
986 * @struct:
987 * FT_Raster_Params
988 *
989 * @description:
990 * A structure to hold the parameters used by a raster's render function,
991 * passed as an argument to @FT_Outline_Render.
992 *
993 * @fields:
994 * target ::
995 * The target bitmap.
996 *
997 * source ::
998 * A pointer to the source glyph image (e.g., an @FT_Outline).
999 *
1000 * flags ::
1001 * The rendering flags.
1002 *
1003 * gray_spans ::
1004 * The gray span drawing callback.
1005 *
1006 * black_spans ::
1007 * Unused.
1008 *
1009 * bit_test ::
1010 * Unused.
1011 *
1012 * bit_set ::
1013 * Unused.
1014 *
1015 * user ::
1016 * User-supplied data that is passed to each drawing callback.
1017 *
1018 * clip_box ::
1019 * An optional span clipping box expressed in _integer_ pixels
1020 * (not in 26.6 fixed-point units).
1021 *
1022 * @note:
1023 * The @FT_RASTER_FLAG_AA bit flag must be set in the `flags` to
1024 * generate an anti-aliased glyph bitmap, otherwise a monochrome bitmap
1025 * is generated. The `target` should have appropriate pixel mode and its
1026 * dimensions define the clipping region.
1027 *
1028 * If both @FT_RASTER_FLAG_AA and @FT_RASTER_FLAG_DIRECT bit flags
1029 * are set in `flags`, the raster calls an @FT_SpanFunc callback
1030 * `gray_spans` with `user` data as an argument ignoring `target`. This
1031 * allows direct composition over a pre-existing user surface to perform
1032 * the span drawing and composition. To optionally clip the spans, set
1033 * the @FT_RASTER_FLAG_CLIP flag and `clip_box`. The monochrome raster
1034 * does not support the direct mode.
1035 *
1036 * The gray-level rasterizer always uses 256 gray levels. If you want
1037 * fewer gray levels, you have to use @FT_RASTER_FLAG_DIRECT and reduce
1038 * the levels in the callback function.
1039 */
1040 typedef struct FT_Raster_Params_
1041 {
1042 const FT_Bitmap* target;
1043 const void* source;
1044 int flags;
1045 FT_SpanFunc gray_spans;
1046 FT_SpanFunc black_spans; /* unused */
1047 FT_Raster_BitTest_Func bit_test; /* unused */
1048 FT_Raster_BitSet_Func bit_set; /* unused */
1049 void* user;
1050 FT_BBox clip_box;
1051
1052 } FT_Raster_Params;
1053
1054
1055 /**************************************************************************
1056 *
1057 * @type:
1058 * FT_Raster
1059 *
1060 * @description:
1061 * An opaque handle (pointer) to a raster object. Each object can be
1062 * used independently to convert an outline into a bitmap or pixmap.
1063 *
1064 * @note:
1065 * In FreeType 2, all rasters are now encapsulated within specific
1066 * @FT_Renderer modules and only used in their context.
1067 *
1068 */
1069 typedef struct FT_RasterRec_* FT_Raster;
1070
1071
1072 /**************************************************************************
1073 *
1074 * @functype:
1075 * FT_Raster_NewFunc
1076 *
1077 * @description:
1078 * A function used to create a new raster object.
1079 *
1080 * @input:
1081 * memory ::
1082 * A handle to the memory allocator.
1083 *
1084 * @output:
1085 * raster ::
1086 * A handle to the new raster object.
1087 *
1088 * @return:
1089 * Error code. 0~means success.
1090 *
1091 * @note:
1092 * The `memory` parameter is a typeless pointer in order to avoid
1093 * un-wanted dependencies on the rest of the FreeType code. In practice,
1094 * it is an @FT_Memory object, i.e., a handle to the standard FreeType
1095 * memory allocator. However, this field can be completely ignored by a
1096 * given raster implementation.
1097 */
1098 typedef int
1099 (*FT_Raster_NewFunc)( void* memory,
1100 FT_Raster* raster );
1101
1102#define FT_Raster_New_Func FT_Raster_NewFunc
1103
1104
1105 /**************************************************************************
1106 *
1107 * @functype:
1108 * FT_Raster_DoneFunc
1109 *
1110 * @description:
1111 * A function used to destroy a given raster object.
1112 *
1113 * @input:
1114 * raster ::
1115 * A handle to the raster object.
1116 */
1117 typedef void
1118 (*FT_Raster_DoneFunc)( FT_Raster raster );
1119
1120#define FT_Raster_Done_Func FT_Raster_DoneFunc
1121
1122
1123 /**************************************************************************
1124 *
1125 * @functype:
1126 * FT_Raster_ResetFunc
1127 *
1128 * @description:
1129 * FreeType used to provide an area of memory called the 'render pool'
1130 * available to all registered rasterizers. This was not thread safe,
1131 * however, and now FreeType never allocates this pool.
1132 *
1133 * This function is called after a new raster object is created.
1134 *
1135 * @input:
1136 * raster ::
1137 * A handle to the new raster object.
1138 *
1139 * pool_base ::
1140 * Previously, the address in memory of the render pool. Set this to
1141 * `NULL`.
1142 *
1143 * pool_size ::
1144 * Previously, the size in bytes of the render pool. Set this to 0.
1145 *
1146 * @note:
1147 * Rasterizers should rely on dynamic or stack allocation if they want to
1148 * (a handle to the memory allocator is passed to the rasterizer
1149 * constructor).
1150 */
1151 typedef void
1152 (*FT_Raster_ResetFunc)( FT_Raster raster,
1153 unsigned char* pool_base,
1154 unsigned long pool_size );
1155
1156#define FT_Raster_Reset_Func FT_Raster_ResetFunc
1157
1158
1159 /**************************************************************************
1160 *
1161 * @functype:
1162 * FT_Raster_SetModeFunc
1163 *
1164 * @description:
1165 * This function is a generic facility to change modes or attributes in a
1166 * given raster. This can be used for debugging purposes, or simply to
1167 * allow implementation-specific 'features' in a given raster module.
1168 *
1169 * @input:
1170 * raster ::
1171 * A handle to the new raster object.
1172 *
1173 * mode ::
1174 * A 4-byte tag used to name the mode or property.
1175 *
1176 * args ::
1177 * A pointer to the new mode/property to use.
1178 */
1179 typedef int
1180 (*FT_Raster_SetModeFunc)( FT_Raster raster,
1181 unsigned long mode,
1182 void* args );
1183
1184#define FT_Raster_Set_Mode_Func FT_Raster_SetModeFunc
1185
1186
1187 /**************************************************************************
1188 *
1189 * @functype:
1190 * FT_Raster_RenderFunc
1191 *
1192 * @description:
1193 * Invoke a given raster to scan-convert a given glyph image into a
1194 * target bitmap.
1195 *
1196 * @input:
1197 * raster ::
1198 * A handle to the raster object.
1199 *
1200 * params ::
1201 * A pointer to an @FT_Raster_Params structure used to store the
1202 * rendering parameters.
1203 *
1204 * @return:
1205 * Error code. 0~means success.
1206 *
1207 * @note:
1208 * The exact format of the source image depends on the raster's glyph
1209 * format defined in its @FT_Raster_Funcs structure. It can be an
1210 * @FT_Outline or anything else in order to support a large array of
1211 * glyph formats.
1212 *
1213 * Note also that the render function can fail and return a
1214 * `FT_Err_Unimplemented_Feature` error code if the raster used does not
1215 * support direct composition.
1216 */
1217 typedef int
1218 (*FT_Raster_RenderFunc)( FT_Raster raster,
1219 const FT_Raster_Params* params );
1220
1221#define FT_Raster_Render_Func FT_Raster_RenderFunc
1222
1223
1224 /**************************************************************************
1225 *
1226 * @struct:
1227 * FT_Raster_Funcs
1228 *
1229 * @description:
1230 * A structure used to describe a given raster class to the library.
1231 *
1232 * @fields:
1233 * glyph_format ::
1234 * The supported glyph format for this raster.
1235 *
1236 * raster_new ::
1237 * The raster constructor.
1238 *
1239 * raster_reset ::
1240 * Used to reset the render pool within the raster.
1241 *
1242 * raster_render ::
1243 * A function to render a glyph into a given bitmap.
1244 *
1245 * raster_done ::
1246 * The raster destructor.
1247 */
1248 typedef struct FT_Raster_Funcs_
1249 {
1250 FT_Glyph_Format glyph_format;
1251
1252 FT_Raster_NewFunc raster_new;
1253 FT_Raster_ResetFunc raster_reset;
1254 FT_Raster_SetModeFunc raster_set_mode;
1255 FT_Raster_RenderFunc raster_render;
1256 FT_Raster_DoneFunc raster_done;
1257
1258 } FT_Raster_Funcs;
1259
1260 /* */
1261
1262
1263FT_END_HEADER
1264
1265#endif /* FTIMAGE_H_ */
1266
1267
1268/* END */
1269
1270
1271/* Local Variables: */
1272/* coding: utf-8 */
1273/* End: */
1274