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