1 /****************************************************************************
5 * FreeType glyph image formats and default raster interface
8 * Copyright (C) 1996-2023 by
9 * David Turner, Robert Wilhelm, and Werner Lemberg.
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.
19 /**************************************************************************
21 * Note: A 'raster' is simply a scan-line converter, used to render
22 * `FT_Outline`s into `FT_Bitmap`s.
34 /**************************************************************************
42 /**************************************************************************
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.
52 typedef signed long FT_Pos;
55 /**************************************************************************
61 * A simple structure used to store a 2D vector; coordinates are of the
66 * The horizontal coordinate.
68 * The vertical coordinate.
70 typedef struct FT_Vector_
78 /**************************************************************************
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.
89 * The horizontal minimum (left-most).
92 * The vertical minimum (bottom-most).
95 * The horizontal maximum (right-most).
98 * The vertical maximum (top-most).
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.
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.
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.
113 typedef struct FT_BBox_
121 /**************************************************************************
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.
131 * FT_PIXEL_MODE_NONE ::
132 * Value~0 is reserved.
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.
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).
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.
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.
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.
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.
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.
175 typedef enum FT_Pixel_Mode_
177 FT_PIXEL_MODE_NONE = 0,
186 FT_PIXEL_MODE_MAX /* do not remove */
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
201 /* For debugging, the @FT_Pixel_Mode enumeration must stay in sync */
202 /* with the `pixel_modes` array in file `ftobjs.c`. */
205 /**************************************************************************
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`
217 * The number of bitmap rows.
220 * The number of pixels in bitmap row.
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.
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.
233 * For the B/W rasterizer, `pitch` is always an even number.
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.
241 * A typeless pointer to the bitmap buffer. This value should be
242 * aligned on 32-bit boundaries in most cases.
245 * This field is only used with @FT_PIXEL_MODE_GRAY; it gives the
246 * number of gray levels used in the bitmap.
249 * The pixel mode, i.e., how pixel bits are stored. See @FT_Pixel_Mode
250 * for possible values.
253 * This field is intended for paletted pixel modes; it indicates how
254 * the palette is stored. Not used currently.
257 * A typeless pointer to the bitmap palette; this field is intended for
258 * paletted pixel modes. Not used currently.
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
266 typedef struct FT_Bitmap_
271 unsigned char* buffer;
272 unsigned short num_grays;
273 unsigned char pixel_mode;
274 unsigned char palette_mode;
280 /**************************************************************************
288 /**************************************************************************
294 * This structure is used to describe an outline to the scan-line
299 * The number of contours in the outline.
302 * The number of points in the outline.
305 * A pointer to an array of `n_points` @FT_Vector elements, giving the
306 * outline's point coordinates.
309 * A pointer to an array of `n_points` chars, giving each outline
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.
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
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).
323 * Bits 3 and~4 are reserved for internal purposes.
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.
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
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.
342 typedef struct FT_Outline_
344 short n_contours; /* number of contours in glyph */
345 short n_points; /* number of points in the glyph */
347 FT_Vector* points; /* the outline's points */
348 char* tags; /* the points flags */
349 short* contours; /* the contour end points */
351 int flags; /* outline masks */
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
363 /**************************************************************************
369 * A list of bit-field constants used for the flags in an outline's
374 * Value~0 is reserved.
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.
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).
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
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.
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
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
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.
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
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.
430 * The flags @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and
431 * @FT_OUTLINE_INCLUDE_STUBS are ignored by the smooth rasterizer.
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.
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.
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
449 #define FT_OUTLINE_HIGH_PRECISION 0x100
450 #define FT_OUTLINE_SINGLE_PASS 0x200
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
465 #define FT_CURVE_TAG( flag ) ( flag & 0x03 )
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
472 #define FT_CURVE_TAG_HAS_SCANMODE 0x04
474 #define FT_CURVE_TAG_TOUCH_X 0x08 /* reserved for TrueType hinter */
475 #define FT_CURVE_TAG_TOUCH_Y 0x10 /* reserved for TrueType hinter */
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 */
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
491 /**************************************************************************
494 * FT_Outline_MoveToFunc
497 * A function pointer type used to describe the signature of a 'move to'
498 * function during outline walking/decomposition.
500 * A 'move to' is emitted to start a new contour in an outline.
504 * A pointer to the target point of the 'move to'.
507 * A typeless pointer, which is passed from the caller of the
508 * decomposition function.
511 * Error code. 0~means success.
514 (*FT_Outline_MoveToFunc)( const FT_Vector* to,
517 #define FT_Outline_MoveTo_Func FT_Outline_MoveToFunc
520 /**************************************************************************
523 * FT_Outline_LineToFunc
526 * A function pointer type used to describe the signature of a 'line to'
527 * function during outline walking/decomposition.
529 * A 'line to' is emitted to indicate a segment in the outline.
533 * A pointer to the target point of the 'line to'.
536 * A typeless pointer, which is passed from the caller of the
537 * decomposition function.
540 * Error code. 0~means success.
543 (*FT_Outline_LineToFunc)( const FT_Vector* to,
546 #define FT_Outline_LineTo_Func FT_Outline_LineToFunc
549 /**************************************************************************
552 * FT_Outline_ConicToFunc
555 * A function pointer type used to describe the signature of a 'conic to'
556 * function during outline walking or decomposition.
558 * A 'conic to' is emitted to indicate a second-order Bezier arc in the
563 * An intermediate control point between the last position and the new
567 * A pointer to the target end point of the conic arc.
570 * A typeless pointer, which is passed from the caller of the
571 * decomposition function.
574 * Error code. 0~means success.
577 (*FT_Outline_ConicToFunc)( const FT_Vector* control,
581 #define FT_Outline_ConicTo_Func FT_Outline_ConicToFunc
584 /**************************************************************************
587 * FT_Outline_CubicToFunc
590 * A function pointer type used to describe the signature of a 'cubic to'
591 * function during outline walking or decomposition.
593 * A 'cubic to' is emitted to indicate a third-order Bezier arc.
597 * A pointer to the first Bezier control point.
600 * A pointer to the second Bezier control point.
603 * A pointer to the target end point.
606 * A typeless pointer, which is passed from the caller of the
607 * decomposition function.
610 * Error code. 0~means success.
613 (*FT_Outline_CubicToFunc)( const FT_Vector* control1,
614 const FT_Vector* control2,
618 #define FT_Outline_CubicTo_Func FT_Outline_CubicToFunc
621 /**************************************************************************
627 * A structure to hold various function pointers used during outline
628 * decomposition in order to emit segments, conic, and cubic Beziers.
632 * The 'move to' emitter.
635 * The segment emitter.
638 * The second-order Bezier arc emitter.
641 * The third-order Bezier arc emitter.
644 * The shift that is applied to coordinates before they are sent to the
648 * The delta that is applied to coordinates before they are sent to the
649 * emitter, but after the shift.
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:
657 * x' = (x << shift) - delta
658 * y' = (y << shift) - delta
661 * Set the values of `shift` and `delta` to~0 to get the original point
664 typedef struct FT_Outline_Funcs_
666 FT_Outline_MoveToFunc move_to;
667 FT_Outline_LineToFunc line_to;
668 FT_Outline_ConicToFunc conic_to;
669 FT_Outline_CubicToFunc cubic_to;
677 /**************************************************************************
685 /**************************************************************************
691 * This macro converts four-letter tags to an unsigned long type.
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:
698 * #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value
701 * to get a simple enumeration without assigning special numbers.
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 ) )
711 #endif /* FT_IMAGE_TAG */
714 /**************************************************************************
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
726 * FT_GLYPH_FORMAT_NONE ::
727 * The value~0 is reserved.
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).
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.
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
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.
751 * FT_GLYPH_FORMAT_SVG ::
752 * [Since 2.12] The glyph is represented by an SVG document in the
755 typedef enum FT_Glyph_Format_
757 FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE, 0, 0, 0, 0 ),
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', ' ' )
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
777 /*************************************************************************/
778 /*************************************************************************/
779 /*************************************************************************/
781 /***** R A S T E R D E F I N I T I O N S *****/
783 /*************************************************************************/
784 /*************************************************************************/
785 /*************************************************************************/
789 /**************************************************************************
798 * How vectorial outlines are converted into bitmaps and pixmaps.
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.
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.
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.
820 * This section also describes the public API needed to set up alternative
821 * @FT_Renderer modules.
832 * FT_Raster_ResetFunc
833 * FT_Raster_SetModeFunc
834 * FT_Raster_RenderFunc
840 /**************************************************************************
846 * A structure to model a single span of consecutive pixels when
847 * rendering an anti-aliased bitmap.
851 * The span's horizontal start position.
854 * The span's length in pixels.
857 * The span color/coverage, ranging from 0 (background) to 255
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.
864 * The anti-aliased rasterizer produces coverage values from 0 to 255,
865 * that is, from completely transparent to completely opaque.
867 typedef struct FT_Span_
871 unsigned char coverage;
876 /**************************************************************************
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
888 * The scanline's upward y~coordinate.
891 * The number of spans to draw on this scanline.
894 * A table of `count` spans to draw on the scanline.
897 * User-supplied data that is passed to the callback.
900 * This callback allows client applications to directly render the spans
901 * of the anti-aliased bitmap to any kind of surfaces.
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.
908 (*FT_SpanFunc)( int y,
910 const FT_Span* spans,
913 #define FT_Raster_Span_Func FT_SpanFunc
916 /**************************************************************************
919 * FT_Raster_BitTest_Func
922 * Deprecated, unimplemented.
925 (*FT_Raster_BitTest_Func)( int y,
930 /**************************************************************************
933 * FT_Raster_BitSet_Func
936 * Deprecated, unimplemented.
939 (*FT_Raster_BitSet_Func)( int y,
944 /**************************************************************************
950 * A list of bit flag constants as used in the `flags` field of a
951 * @FT_Raster_Params structure.
954 * FT_RASTER_FLAG_DEFAULT ::
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).
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.
968 * Direct rendering is only possible with anti-aliased glyphs.
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.
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.
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
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
995 /**************************************************************************
1001 * A structure to hold the parameters used by a raster's render function,
1002 * passed as an argument to @FT_Outline_Render.
1006 * The target bitmap.
1009 * A pointer to the source glyph image (e.g., an @FT_Outline).
1012 * The rendering flags.
1015 * The gray span drawing callback.
1027 * User-supplied data that is passed to each drawing callback.
1030 * An optional span clipping box expressed in _integer_ pixels
1031 * (not in 26.6 fixed-point units).
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.
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.
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.
1051 typedef struct FT_Raster_Params_
1053 const FT_Bitmap* target;
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 */
1066 /**************************************************************************
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.
1076 * In FreeType 2, all rasters are now encapsulated within specific
1077 * @FT_Renderer modules and only used in their context.
1080 typedef struct FT_RasterRec_* FT_Raster;
1083 /**************************************************************************
1089 * A function used to create a new raster object.
1093 * A handle to the memory allocator.
1097 * A handle to the new raster object.
1100 * Error code. 0~means success.
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.
1110 (*FT_Raster_NewFunc)( void* memory,
1111 FT_Raster* raster );
1113 #define FT_Raster_New_Func FT_Raster_NewFunc
1116 /**************************************************************************
1119 * FT_Raster_DoneFunc
1122 * A function used to destroy a given raster object.
1126 * A handle to the raster object.
1129 (*FT_Raster_DoneFunc)( FT_Raster raster );
1131 #define FT_Raster_Done_Func FT_Raster_DoneFunc
1134 /**************************************************************************
1137 * FT_Raster_ResetFunc
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.
1144 * This function is called after a new raster object is created.
1148 * A handle to the new raster object.
1151 * Previously, the address in memory of the render pool. Set this to
1155 * Previously, the size in bytes of the render pool. Set this to 0.
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
1163 (*FT_Raster_ResetFunc)( FT_Raster raster,
1164 unsigned char* pool_base,
1165 unsigned long pool_size );
1167 #define FT_Raster_Reset_Func FT_Raster_ResetFunc
1170 /**************************************************************************
1173 * FT_Raster_SetModeFunc
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.
1182 * A handle to the new raster object.
1185 * A 4-byte tag used to name the mode or property.
1188 * A pointer to the new mode/property to use.
1191 (*FT_Raster_SetModeFunc)( FT_Raster raster,
1195 #define FT_Raster_Set_Mode_Func FT_Raster_SetModeFunc
1198 /**************************************************************************
1201 * FT_Raster_RenderFunc
1204 * Invoke a given raster to scan-convert a given glyph image into a
1209 * A handle to the raster object.
1212 * A pointer to an @FT_Raster_Params structure used to store the
1213 * rendering parameters.
1216 * Error code. 0~means success.
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
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.
1229 (*FT_Raster_RenderFunc)( FT_Raster raster,
1230 const FT_Raster_Params* params );
1232 #define FT_Raster_Render_Func FT_Raster_RenderFunc
1235 /**************************************************************************
1241 * A structure used to describe a given raster class to the library.
1245 * The supported glyph format for this raster.
1248 * The raster constructor.
1251 * Used to reset the render pool within the raster.
1254 * A function to render a glyph into a given bitmap.
1257 * The raster destructor.
1259 typedef struct FT_Raster_Funcs_
1261 FT_Glyph_Format glyph_format;
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;
1276 #endif /* FTIMAGE_H_ */
1282 /* Local Variables: */