1 /***************************************************************************/
5 /* FreeType glyph image formats and default raster interface */
8 /* Copyright 1996-2015 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. */
17 /***************************************************************************/
19 /*************************************************************************/
21 /* Note: A `raster' is simply a scan-line converter, used to render */
22 /* FT_Outlines into FT_Bitmaps. */
24 /*************************************************************************/
31 /* _STANDALONE_ is from ftgrays.c */
40 /*************************************************************************/
45 /*************************************************************************/
48 /*************************************************************************/
54 /* The type FT_Pos is used to store vectorial coordinates. Depending */
55 /* on the context, these can represent distances in integer font */
56 /* units, or 16.16, or 26.6 fixed-point pixel coordinates. */
58 typedef signed long FT_Pos
;
61 /*************************************************************************/
67 /* A simple structure used to store a 2D vector; coordinates are of */
68 /* the FT_Pos type. */
71 /* x :: The horizontal coordinate. */
72 /* y :: The vertical coordinate. */
74 typedef struct FT_Vector_
82 /*************************************************************************/
88 /* A structure used to hold an outline's bounding box, i.e., the */
89 /* coordinates of its extrema in the horizontal and vertical */
93 /* xMin :: The horizontal minimum (left-most). */
95 /* yMin :: The vertical minimum (bottom-most). */
97 /* xMax :: The horizontal maximum (right-most). */
99 /* yMax :: The vertical maximum (top-most). */
102 /* The bounding box is specified with the coordinates of the lower */
103 /* left and the upper right corner. In PostScript, those values are */
104 /* often called (llx,lly) and (urx,ury), respectively. */
106 /* If `yMin' is negative, this value gives the glyph's descender. */
107 /* Otherwise, the glyph doesn't descend below the baseline. */
108 /* Similarly, if `ymax' is positive, this value gives the glyph's */
111 /* `xMin' gives the horizontal distance from the glyph's origin to */
112 /* the left edge of the glyph's bounding box. If `xMin' is negative, */
113 /* the glyph extends to the left of the origin. */
115 typedef struct FT_BBox_
123 /*************************************************************************/
129 /* An enumeration type used to describe the format of pixels in a */
130 /* given bitmap. Note that additional formats may be added in the */
134 /* FT_PIXEL_MODE_NONE :: */
135 /* Value~0 is reserved. */
137 /* FT_PIXEL_MODE_MONO :: */
138 /* A monochrome bitmap, using 1~bit per pixel. Note that pixels */
139 /* are stored in most-significant order (MSB), which means that */
140 /* the left-most pixel in a byte has value 128. */
142 /* FT_PIXEL_MODE_GRAY :: */
143 /* An 8-bit bitmap, generally used to represent anti-aliased glyph */
144 /* images. Each pixel is stored in one byte. Note that the number */
145 /* of `gray' levels is stored in the `num_grays' field of the */
146 /* @FT_Bitmap structure (it generally is 256). */
148 /* FT_PIXEL_MODE_GRAY2 :: */
149 /* A 2-bit per pixel bitmap, used to represent embedded */
150 /* anti-aliased bitmaps in font files according to the OpenType */
151 /* specification. We haven't found a single font using this */
152 /* format, however. */
154 /* FT_PIXEL_MODE_GRAY4 :: */
155 /* A 4-bit per pixel bitmap, representing embedded anti-aliased */
156 /* bitmaps in font files according to the OpenType specification. */
157 /* We haven't found a single font using this format, however. */
159 /* FT_PIXEL_MODE_LCD :: */
160 /* An 8-bit bitmap, representing RGB or BGR decimated glyph images */
161 /* used for display on LCD displays; the bitmap is three times */
162 /* wider than the original glyph image. See also */
163 /* @FT_RENDER_MODE_LCD. */
165 /* FT_PIXEL_MODE_LCD_V :: */
166 /* An 8-bit bitmap, representing RGB or BGR decimated glyph images */
167 /* used for display on rotated LCD displays; the bitmap is three */
168 /* times taller than the original glyph image. See also */
169 /* @FT_RENDER_MODE_LCD_V. */
171 /* FT_PIXEL_MODE_BGRA :: */
172 /* An image with four 8-bit channels per pixel, representing a */
173 /* color image (such as emoticons) with alpha channel. For each */
174 /* pixel, the format is BGRA, which means, the blue channel comes */
175 /* 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. */
180 typedef enum FT_Pixel_Mode_
182 FT_PIXEL_MODE_NONE
= 0,
191 FT_PIXEL_MODE_MAX
/* do not remove */
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
205 /*************************************************************************/
211 /* A structure used to describe a bitmap or pixmap to the raster. */
212 /* Note that we now manage pixmaps of various depths through the */
213 /* `pixel_mode' field. */
216 /* rows :: The number of bitmap rows. */
218 /* width :: The number of pixels in bitmap row. */
220 /* pitch :: The pitch's absolute value is the number of bytes */
221 /* taken by one bitmap row, including padding. */
222 /* However, the pitch is positive when the bitmap has */
223 /* a `down' flow, and negative when it has an `up' */
224 /* flow. In all cases, the pitch is an offset to add */
225 /* to a bitmap pointer in order to go down one row. */
227 /* Note that `padding' means the alignment of a */
228 /* bitmap to a byte border, and FreeType functions */
229 /* normally align to the smallest possible integer */
232 /* For the B/W rasterizer, `pitch' is always an even */
235 /* To change the pitch of a bitmap (say, to make it a */
236 /* multiple of 4), use @FT_Bitmap_Convert. */
237 /* Alternatively, you might use callback functions to */
238 /* directly render to the application's surface; see */
239 /* the file `example2.cpp' in the tutorial for a */
242 /* buffer :: A typeless pointer to the bitmap buffer. This */
243 /* value should be aligned on 32-bit boundaries in */
246 /* num_grays :: This field is only used with */
247 /* @FT_PIXEL_MODE_GRAY; it gives the number of gray */
248 /* levels used in the bitmap. */
250 /* pixel_mode :: The pixel mode, i.e., how pixel bits are stored. */
251 /* See @FT_Pixel_Mode for possible values. */
253 /* palette_mode :: This field is intended for paletted pixel modes; */
254 /* it indicates how the palette is stored. Not */
255 /* used currently. */
257 /* palette :: A typeless pointer to the bitmap palette; this */
258 /* field is intended for paletted pixel modes. Not */
259 /* used currently. */
261 typedef struct FT_Bitmap_
266 unsigned char* buffer
;
267 unsigned short num_grays
;
268 unsigned char pixel_mode
;
269 unsigned char palette_mode
;
275 /*************************************************************************/
278 /* outline_processing */
280 /*************************************************************************/
283 /*************************************************************************/
289 /* This structure is used to describe an outline to the scan-line */
293 /* n_contours :: The number of contours in the outline. */
295 /* n_points :: The number of points in the outline. */
297 /* points :: A pointer to an array of `n_points' @FT_Vector */
298 /* elements, giving the outline's point coordinates. */
300 /* tags :: A pointer to an array of `n_points' chars, giving */
301 /* each outline point's type. */
303 /* If bit~0 is unset, the point is `off' the curve, */
304 /* i.e., a Bézier control point, while it is `on' if */
307 /* Bit~1 is meaningful for `off' points only. If set, */
308 /* it indicates a third-order Bézier arc control point; */
309 /* and a second-order control point if unset. */
311 /* If bit~2 is set, bits 5-7 contain the drop-out mode */
312 /* (as defined in the OpenType specification; the value */
313 /* is the same as the argument to the SCANMODE */
316 /* Bits 3 and~4 are reserved for internal purposes. */
318 /* contours :: An array of `n_contours' shorts, giving the end */
319 /* point of each contour within the outline. For */
320 /* example, the first contour is defined by the points */
321 /* `0' to `contours[0]', the second one is defined by */
322 /* the points `contours[0]+1' to `contours[1]', etc. */
324 /* flags :: A set of bit flags used to characterize the outline */
325 /* and give hints to the scan-converter and hinter on */
326 /* how to convert/grid-fit it. See @FT_OUTLINE_XXX. */
329 /* The B/W rasterizer only checks bit~2 in the `tags' array for the */
330 /* first point of each contour. The drop-out mode as given with */
331 /* @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and */
332 /* @FT_OUTLINE_INCLUDE_STUBS in `flags' is then overridden. */
334 typedef struct FT_Outline_
336 short n_contours
; /* number of contours in glyph */
337 short n_points
; /* number of points in the glyph */
339 FT_Vector
* points
; /* the outline's points */
340 char* tags
; /* the points flags */
341 short* contours
; /* the contour end points */
343 int flags
; /* outline masks */
349 /* Following limits must be consistent with */
350 /* FT_Outline.{n_contours,n_points} */
351 #define FT_OUTLINE_CONTOURS_MAX SHRT_MAX
352 #define FT_OUTLINE_POINTS_MAX SHRT_MAX
355 /*************************************************************************/
361 /* A list of bit-field constants use for the flags in an outline's */
365 /* FT_OUTLINE_NONE :: */
366 /* Value~0 is reserved. */
368 /* FT_OUTLINE_OWNER :: */
369 /* If set, this flag indicates that the outline's field arrays */
370 /* (i.e., `points', `flags', and `contours') are `owned' by the */
371 /* outline object, and should thus be freed when it is destroyed. */
373 /* FT_OUTLINE_EVEN_ODD_FILL :: */
374 /* By default, outlines are filled using the non-zero winding rule. */
375 /* If set to 1, the outline will be filled using the even-odd fill */
376 /* rule (only works with the smooth rasterizer). */
378 /* FT_OUTLINE_REVERSE_FILL :: */
379 /* By default, outside contours of an outline are oriented in */
380 /* clock-wise direction, as defined in the TrueType specification. */
381 /* This flag is set if the outline uses the opposite direction */
382 /* (typically for Type~1 fonts). This flag is ignored by the scan */
385 /* FT_OUTLINE_IGNORE_DROPOUTS :: */
386 /* By default, the scan converter will try to detect drop-outs in */
387 /* an outline and correct the glyph bitmap to ensure consistent */
388 /* shape continuity. If set, this flag hints the scan-line */
389 /* converter to ignore such cases. See below for more information. */
391 /* FT_OUTLINE_SMART_DROPOUTS :: */
392 /* Select smart dropout control. If unset, use simple dropout */
393 /* control. Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See */
394 /* below for more information. */
396 /* FT_OUTLINE_INCLUDE_STUBS :: */
397 /* If set, turn pixels on for `stubs', otherwise exclude them. */
398 /* Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See below for */
399 /* more information. */
401 /* FT_OUTLINE_HIGH_PRECISION :: */
402 /* This flag indicates that the scan-line converter should try to */
403 /* convert this outline to bitmaps with the highest possible */
404 /* quality. It is typically set for small character sizes. Note */
405 /* that this is only a hint that might be completely ignored by a */
406 /* given scan-converter. */
408 /* FT_OUTLINE_SINGLE_PASS :: */
409 /* This flag is set to force a given scan-converter to only use a */
410 /* single pass over the outline to render a bitmap glyph image. */
411 /* Normally, it is set for very large character sizes. It is only */
412 /* a hint that might be completely ignored by a given */
413 /* scan-converter. */
416 /* The flags @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, */
417 /* and @FT_OUTLINE_INCLUDE_STUBS are ignored by the smooth */
420 /* There exists a second mechanism to pass the drop-out mode to the */
421 /* B/W rasterizer; see the `tags' field in @FT_Outline. */
423 /* Please refer to the description of the `SCANTYPE' instruction in */
424 /* the OpenType specification (in file `ttinst1.doc') how simple */
425 /* drop-outs, smart drop-outs, and stubs are defined. */
427 #define FT_OUTLINE_NONE 0x0
428 #define FT_OUTLINE_OWNER 0x1
429 #define FT_OUTLINE_EVEN_ODD_FILL 0x2
430 #define FT_OUTLINE_REVERSE_FILL 0x4
431 #define FT_OUTLINE_IGNORE_DROPOUTS 0x8
432 #define FT_OUTLINE_SMART_DROPOUTS 0x10
433 #define FT_OUTLINE_INCLUDE_STUBS 0x20
435 #define FT_OUTLINE_HIGH_PRECISION 0x100
436 #define FT_OUTLINE_SINGLE_PASS 0x200
439 /* these constants are deprecated; use the corresponding */
440 /* `FT_OUTLINE_XXX' values instead */
441 #define ft_outline_none FT_OUTLINE_NONE
442 #define ft_outline_owner FT_OUTLINE_OWNER
443 #define ft_outline_even_odd_fill FT_OUTLINE_EVEN_ODD_FILL
444 #define ft_outline_reverse_fill FT_OUTLINE_REVERSE_FILL
445 #define ft_outline_ignore_dropouts FT_OUTLINE_IGNORE_DROPOUTS
446 #define ft_outline_high_precision FT_OUTLINE_HIGH_PRECISION
447 #define ft_outline_single_pass FT_OUTLINE_SINGLE_PASS
451 #define FT_CURVE_TAG( flag ) ( flag & 3 )
453 #define FT_CURVE_TAG_ON 1
454 #define FT_CURVE_TAG_CONIC 0
455 #define FT_CURVE_TAG_CUBIC 2
457 #define FT_CURVE_TAG_HAS_SCANMODE 4
459 #define FT_CURVE_TAG_TOUCH_X 8 /* reserved for the TrueType hinter */
460 #define FT_CURVE_TAG_TOUCH_Y 16 /* reserved for the TrueType hinter */
462 #define FT_CURVE_TAG_TOUCH_BOTH ( FT_CURVE_TAG_TOUCH_X | \
463 FT_CURVE_TAG_TOUCH_Y )
465 #define FT_Curve_Tag_On FT_CURVE_TAG_ON
466 #define FT_Curve_Tag_Conic FT_CURVE_TAG_CONIC
467 #define FT_Curve_Tag_Cubic FT_CURVE_TAG_CUBIC
468 #define FT_Curve_Tag_Touch_X FT_CURVE_TAG_TOUCH_X
469 #define FT_Curve_Tag_Touch_Y FT_CURVE_TAG_TOUCH_Y
472 /*************************************************************************/
475 /* FT_Outline_MoveToFunc */
478 /* A function pointer type used to describe the signature of a `move */
479 /* to' function during outline walking/decomposition. */
481 /* A `move to' is emitted to start a new contour in an outline. */
484 /* to :: A pointer to the target point of the `move to'. */
486 /* user :: A typeless pointer, which is passed from the caller of the */
487 /* decomposition function. */
490 /* Error code. 0~means success. */
493 (*FT_Outline_MoveToFunc
)( const FT_Vector
* to
,
496 #define FT_Outline_MoveTo_Func FT_Outline_MoveToFunc
499 /*************************************************************************/
502 /* FT_Outline_LineToFunc */
505 /* A function pointer type used to describe the signature of a `line */
506 /* to' function during outline walking/decomposition. */
508 /* A `line to' is emitted to indicate a segment in the outline. */
511 /* to :: A pointer to the target point of the `line to'. */
513 /* user :: A typeless pointer, which is passed from the caller of the */
514 /* decomposition function. */
517 /* Error code. 0~means success. */
520 (*FT_Outline_LineToFunc
)( const FT_Vector
* to
,
523 #define FT_Outline_LineTo_Func FT_Outline_LineToFunc
526 /*************************************************************************/
529 /* FT_Outline_ConicToFunc */
532 /* A function pointer type used to describe the signature of a `conic */
533 /* to' function during outline walking or decomposition. */
535 /* A `conic to' is emitted to indicate a second-order Bézier arc in */
539 /* control :: An intermediate control point between the last position */
540 /* and the new target in `to'. */
542 /* to :: A pointer to the target end point of the conic arc. */
544 /* user :: A typeless pointer, which is passed from the caller of */
545 /* the decomposition function. */
548 /* Error code. 0~means success. */
551 (*FT_Outline_ConicToFunc
)( const FT_Vector
* control
,
555 #define FT_Outline_ConicTo_Func FT_Outline_ConicToFunc
558 /*************************************************************************/
561 /* FT_Outline_CubicToFunc */
564 /* A function pointer type used to describe the signature of a `cubic */
565 /* to' function during outline walking or decomposition. */
567 /* A `cubic to' is emitted to indicate a third-order Bézier arc. */
570 /* control1 :: A pointer to the first Bézier control point. */
572 /* control2 :: A pointer to the second Bézier control point. */
574 /* to :: A pointer to the target end point. */
576 /* user :: A typeless pointer, which is passed from the caller of */
577 /* the decomposition function. */
580 /* Error code. 0~means success. */
583 (*FT_Outline_CubicToFunc
)( const FT_Vector
* control1
,
584 const FT_Vector
* control2
,
588 #define FT_Outline_CubicTo_Func FT_Outline_CubicToFunc
591 /*************************************************************************/
594 /* FT_Outline_Funcs */
597 /* A structure to hold various function pointers used during outline */
598 /* decomposition in order to emit segments, conic, and cubic Béziers. */
601 /* move_to :: The `move to' emitter. */
603 /* line_to :: The segment emitter. */
605 /* conic_to :: The second-order Bézier arc emitter. */
607 /* cubic_to :: The third-order Bézier arc emitter. */
609 /* shift :: The shift that is applied to coordinates before they */
610 /* are sent to the emitter. */
612 /* delta :: The delta that is applied to coordinates before they */
613 /* are sent to the emitter, but after the shift. */
616 /* The point coordinates sent to the emitters are the transformed */
617 /* version of the original coordinates (this is important for high */
618 /* accuracy during scan-conversion). The transformation is simple: */
621 /* x' = (x << shift) - delta */
622 /* y' = (x << shift) - delta */
625 /* Set the values of `shift' and `delta' to~0 to get the original */
626 /* point coordinates. */
628 typedef struct FT_Outline_Funcs_
630 FT_Outline_MoveToFunc move_to
;
631 FT_Outline_LineToFunc line_to
;
632 FT_Outline_ConicToFunc conic_to
;
633 FT_Outline_CubicToFunc cubic_to
;
641 /*************************************************************************/
646 /*************************************************************************/
649 /*************************************************************************/
655 /* This macro converts four-letter tags to an unsigned long type. */
658 /* Since many 16-bit compilers don't like 32-bit enumerations, you */
659 /* should redefine this macro in case of problems to something like */
663 /* #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value */
666 /* to get a simple enumeration without assigning special numbers. */
669 #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \
670 value = ( ( (unsigned long)_x1 << 24 ) | \
671 ( (unsigned long)_x2 << 16 ) | \
672 ( (unsigned long)_x3 << 8 ) | \
674 #endif /* FT_IMAGE_TAG */
677 /*************************************************************************/
680 /* FT_Glyph_Format */
683 /* An enumeration type used to describe the format of a given glyph */
684 /* image. Note that this version of FreeType only supports two image */
685 /* formats, even though future font drivers will be able to register */
686 /* their own format. */
689 /* FT_GLYPH_FORMAT_NONE :: */
690 /* The value~0 is reserved. */
692 /* FT_GLYPH_FORMAT_COMPOSITE :: */
693 /* The glyph image is a composite of several other images. This */
694 /* format is _only_ used with @FT_LOAD_NO_RECURSE, and is used to */
695 /* report compound glyphs (like accented characters). */
697 /* FT_GLYPH_FORMAT_BITMAP :: */
698 /* The glyph image is a bitmap, and can be described as an */
699 /* @FT_Bitmap. You generally need to access the `bitmap' field of */
700 /* the @FT_GlyphSlotRec structure to read it. */
702 /* FT_GLYPH_FORMAT_OUTLINE :: */
703 /* The glyph image is a vectorial outline made of line segments */
704 /* and Bézier arcs; it can be described as an @FT_Outline; you */
705 /* generally want to access the `outline' field of the */
706 /* @FT_GlyphSlotRec structure to read it. */
708 /* FT_GLYPH_FORMAT_PLOTTER :: */
709 /* The glyph image is a vectorial path with no inside and outside */
710 /* contours. Some Type~1 fonts, like those in the Hershey family, */
711 /* contain glyphs in this format. These are described as */
712 /* @FT_Outline, but FreeType isn't currently capable of rendering */
713 /* them correctly. */
715 typedef enum FT_Glyph_Format_
717 FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE
, 0, 0, 0, 0 ),
719 FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE
, 'c', 'o', 'm', 'p' ),
720 FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP
, 'b', 'i', 't', 's' ),
721 FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE
, 'o', 'u', 't', 'l' ),
722 FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER
, 'p', 'l', 'o', 't' )
727 /* these constants are deprecated; use the corresponding */
728 /* `FT_Glyph_Format' values instead. */
729 #define ft_glyph_format_none FT_GLYPH_FORMAT_NONE
730 #define ft_glyph_format_composite FT_GLYPH_FORMAT_COMPOSITE
731 #define ft_glyph_format_bitmap FT_GLYPH_FORMAT_BITMAP
732 #define ft_glyph_format_outline FT_GLYPH_FORMAT_OUTLINE
733 #define ft_glyph_format_plotter FT_GLYPH_FORMAT_PLOTTER
736 /*************************************************************************/
737 /*************************************************************************/
738 /*************************************************************************/
740 /***** R A S T E R D E F I N I T I O N S *****/
742 /*************************************************************************/
743 /*************************************************************************/
744 /*************************************************************************/
747 /*************************************************************************/
749 /* A raster is a scan converter, in charge of rendering an outline into */
750 /* a a bitmap. This section contains the public API for rasters. */
752 /* Note that in FreeType 2, all rasters are now encapsulated within */
753 /* specific modules called `renderers'. See `ftrender.h' for more */
754 /* details on renderers. */
756 /*************************************************************************/
759 /*************************************************************************/
765 /* Scanline Converter */
768 /* How vectorial outlines are converted into bitmaps and pixmaps. */
771 /* This section contains technical definitions. */
778 /* FT_Raster_Params */
779 /* FT_RASTER_FLAG_XXX */
781 /* FT_Raster_NewFunc */
782 /* FT_Raster_DoneFunc */
783 /* FT_Raster_ResetFunc */
784 /* FT_Raster_SetModeFunc */
785 /* FT_Raster_RenderFunc */
786 /* FT_Raster_Funcs */
788 /*************************************************************************/
791 /*************************************************************************/
797 /* An opaque handle (pointer) to a raster object. Each object can be */
798 /* used independently to convert an outline into a bitmap or pixmap. */
800 typedef struct FT_RasterRec_
* FT_Raster
;
803 /*************************************************************************/
809 /* A structure used to model a single span of gray pixels when */
810 /* rendering an anti-aliased bitmap. */
813 /* x :: The span's horizontal start position. */
815 /* len :: The span's length in pixels. */
817 /* coverage :: The span color/coverage, ranging from 0 (background) */
818 /* to 255 (foreground). */
821 /* This structure is used by the span drawing callback type named */
822 /* @FT_SpanFunc that takes the y~coordinate of the span as a */
825 /* The coverage value is always between 0 and 255. If you want less */
826 /* gray values, the callback function has to reduce them. */
828 typedef struct FT_Span_
832 unsigned char coverage
;
837 /*************************************************************************/
843 /* A function used as a call-back by the anti-aliased renderer in */
844 /* order to let client applications draw themselves the gray pixel */
845 /* spans on each scan line. */
848 /* y :: The scanline's y~coordinate. */
850 /* count :: The number of spans to draw on this scanline. */
852 /* spans :: A table of `count' spans to draw on the scanline. */
854 /* user :: User-supplied data that is passed to the callback. */
857 /* This callback allows client applications to directly render the */
858 /* gray spans of the anti-aliased bitmap to any kind of surfaces. */
860 /* This can be used to write anti-aliased outlines directly to a */
861 /* given background bitmap, and even perform translucency. */
863 /* Note that the `count' field cannot be greater than a fixed value */
864 /* defined by the `FT_MAX_GRAY_SPANS' configuration macro in */
865 /* `ftoption.h'. By default, this value is set to~32, which means */
866 /* that if there are more than 32~spans on a given scanline, the */
867 /* callback is called several times with the same `y' parameter in */
868 /* order to draw all callbacks. */
870 /* Otherwise, the callback is only called once per scan-line, and */
871 /* only for those scanlines that do have `gray' pixels on them. */
874 (*FT_SpanFunc
)( int y
,
876 const FT_Span
* spans
,
879 #define FT_Raster_Span_Func FT_SpanFunc
882 /*************************************************************************/
885 /* FT_Raster_BitTest_Func */
888 /* Deprecated, unimplemented. */
891 (*FT_Raster_BitTest_Func
)( int y
,
896 /*************************************************************************/
899 /* FT_Raster_BitSet_Func */
902 /* Deprecated, unimplemented. */
905 (*FT_Raster_BitSet_Func
)( int y
,
910 /*************************************************************************/
913 /* FT_RASTER_FLAG_XXX */
916 /* A list of bit flag constants as used in the `flags' field of a */
917 /* @FT_Raster_Params structure. */
920 /* FT_RASTER_FLAG_DEFAULT :: This value is 0. */
922 /* FT_RASTER_FLAG_AA :: This flag is set to indicate that an */
923 /* anti-aliased glyph image should be */
924 /* generated. Otherwise, it will be */
925 /* monochrome (1-bit). */
927 /* FT_RASTER_FLAG_DIRECT :: This flag is set to indicate direct */
928 /* rendering. In this mode, client */
929 /* applications must provide their own span */
930 /* callback. This lets them directly */
931 /* draw or compose over an existing bitmap. */
932 /* If this bit is not set, the target */
933 /* pixmap's buffer _must_ be zeroed before */
936 /* Direct rendering is only possible with */
937 /* anti-aliased glyphs. */
939 /* FT_RASTER_FLAG_CLIP :: This flag is only used in direct */
940 /* rendering mode. If set, the output will */
941 /* be clipped to a box specified in the */
942 /* `clip_box' field of the */
943 /* @FT_Raster_Params structure. */
945 /* Note that by default, the glyph bitmap */
946 /* is clipped to the target pixmap, except */
947 /* in direct rendering mode where all spans */
948 /* are generated if no clipping box is set. */
950 #define FT_RASTER_FLAG_DEFAULT 0x0
951 #define FT_RASTER_FLAG_AA 0x1
952 #define FT_RASTER_FLAG_DIRECT 0x2
953 #define FT_RASTER_FLAG_CLIP 0x4
955 /* these constants are deprecated; use the corresponding */
956 /* `FT_RASTER_FLAG_XXX' values instead */
957 #define ft_raster_flag_default FT_RASTER_FLAG_DEFAULT
958 #define ft_raster_flag_aa FT_RASTER_FLAG_AA
959 #define ft_raster_flag_direct FT_RASTER_FLAG_DIRECT
960 #define ft_raster_flag_clip FT_RASTER_FLAG_CLIP
963 /*************************************************************************/
966 /* FT_Raster_Params */
969 /* A structure to hold the arguments used by a raster's render */
973 /* target :: The target bitmap. */
975 /* source :: A pointer to the source glyph image (e.g., an */
978 /* flags :: The rendering flags. */
980 /* gray_spans :: The gray span drawing callback. */
982 /* black_spans :: Unused. */
984 /* bit_test :: Unused. */
986 /* bit_set :: Unused. */
988 /* user :: User-supplied data that is passed to each drawing */
991 /* clip_box :: An optional clipping box. It is only used in */
992 /* direct rendering mode. Note that coordinates here */
993 /* should be expressed in _integer_ pixels (and not in */
994 /* 26.6 fixed-point units). */
997 /* An anti-aliased glyph bitmap is drawn if the @FT_RASTER_FLAG_AA */
998 /* bit flag is set in the `flags' field, otherwise a monochrome */
999 /* bitmap is generated. */
1001 /* If the @FT_RASTER_FLAG_DIRECT bit flag is set in `flags', the */
1002 /* raster will call the `gray_spans' callback to draw gray pixel */
1003 /* spans. This allows direct composition over a pre-existing bitmap */
1004 /* through user-provided callbacks to perform the span drawing and */
1005 /* composition. Not supported by the monochrome rasterizer. */
1007 typedef struct FT_Raster_Params_
1009 const FT_Bitmap
* target
;
1012 FT_SpanFunc gray_spans
;
1013 FT_SpanFunc black_spans
; /* unused */
1014 FT_Raster_BitTest_Func bit_test
; /* unused */
1015 FT_Raster_BitSet_Func bit_set
; /* unused */
1022 /*************************************************************************/
1025 /* FT_Raster_NewFunc */
1028 /* A function used to create a new raster object. */
1031 /* memory :: A handle to the memory allocator. */
1034 /* raster :: A handle to the new raster object. */
1037 /* Error code. 0~means success. */
1040 /* The `memory' parameter is a typeless pointer in order to avoid */
1041 /* un-wanted dependencies on the rest of the FreeType code. In */
1042 /* practice, it is an @FT_Memory object, i.e., a handle to the */
1043 /* standard FreeType memory allocator. However, this field can be */
1044 /* completely ignored by a given raster implementation. */
1047 (*FT_Raster_NewFunc
)( void* memory
,
1048 FT_Raster
* raster
);
1050 #define FT_Raster_New_Func FT_Raster_NewFunc
1053 /*************************************************************************/
1056 /* FT_Raster_DoneFunc */
1059 /* A function used to destroy a given raster object. */
1062 /* raster :: A handle to the raster object. */
1065 (*FT_Raster_DoneFunc
)( FT_Raster raster
);
1067 #define FT_Raster_Done_Func FT_Raster_DoneFunc
1070 /*************************************************************************/
1073 /* FT_Raster_ResetFunc */
1076 /* FreeType used to provide an area of memory called the `render */
1077 /* pool' available to all registered rasters. This was not thread */
1078 /* safe however and now FreeType never allocates this pool. NULL */
1079 /* is always passed in as pool_base. */
1081 /* This function is called each time the render pool changes, or just */
1082 /* after a new raster object is created. */
1085 /* raster :: A handle to the new raster object. */
1087 /* pool_base :: The address in memory of the render pool. */
1089 /* pool_size :: The size in bytes of the render pool. */
1092 /* Rasters should ignore the render pool and rely on dynamic or stack */
1093 /* allocation if they want to (a handle to the memory allocator is */
1094 /* passed to the raster constructor). */
1097 (*FT_Raster_ResetFunc
)( FT_Raster raster
,
1098 unsigned char* pool_base
,
1099 unsigned long pool_size
);
1101 #define FT_Raster_Reset_Func FT_Raster_ResetFunc
1104 /*************************************************************************/
1107 /* FT_Raster_SetModeFunc */
1110 /* This function is a generic facility to change modes or attributes */
1111 /* in a given raster. This can be used for debugging purposes, or */
1112 /* simply to allow implementation-specific `features' in a given */
1113 /* raster module. */
1116 /* raster :: A handle to the new raster object. */
1118 /* mode :: A 4-byte tag used to name the mode or property. */
1120 /* args :: A pointer to the new mode/property to use. */
1123 (*FT_Raster_SetModeFunc
)( FT_Raster raster
,
1127 #define FT_Raster_Set_Mode_Func FT_Raster_SetModeFunc
1130 /*************************************************************************/
1133 /* FT_Raster_RenderFunc */
1136 /* Invoke a given raster to scan-convert a given glyph image into a */
1137 /* target bitmap. */
1140 /* raster :: A handle to the raster object. */
1142 /* params :: A pointer to an @FT_Raster_Params structure used to */
1143 /* store the rendering parameters. */
1146 /* Error code. 0~means success. */
1149 /* The exact format of the source image depends on the raster's glyph */
1150 /* format defined in its @FT_Raster_Funcs structure. It can be an */
1151 /* @FT_Outline or anything else in order to support a large array of */
1152 /* glyph formats. */
1154 /* Note also that the render function can fail and return a */
1155 /* `FT_Err_Unimplemented_Feature' error code if the raster used does */
1156 /* not support direct composition. */
1158 /* XXX: For now, the standard raster doesn't support direct */
1159 /* composition but this should change for the final release (see */
1160 /* the files `demos/src/ftgrays.c' and `demos/src/ftgrays2.c' */
1161 /* for examples of distinct implementations that support direct */
1165 (*FT_Raster_RenderFunc
)( FT_Raster raster
,
1166 const FT_Raster_Params
* params
);
1168 #define FT_Raster_Render_Func FT_Raster_RenderFunc
1171 /*************************************************************************/
1174 /* FT_Raster_Funcs */
1177 /* A structure used to describe a given raster class to the library. */
1180 /* glyph_format :: The supported glyph format for this raster. */
1182 /* raster_new :: The raster constructor. */
1184 /* raster_reset :: Used to reset the render pool within the raster. */
1186 /* raster_render :: A function to render a glyph into a given bitmap. */
1188 /* raster_done :: The raster destructor. */
1190 typedef struct FT_Raster_Funcs_
1192 FT_Glyph_Format glyph_format
;
1193 FT_Raster_NewFunc raster_new
;
1194 FT_Raster_ResetFunc raster_reset
;
1195 FT_Raster_SetModeFunc raster_set_mode
;
1196 FT_Raster_RenderFunc raster_render
;
1197 FT_Raster_DoneFunc raster_done
;
1206 #endif /* __FTIMAGE_H__ */
1212 /* Local Variables: */