1 /***************************************************************************/
5 /* FreeType glyph image formats and default raster interface */
8 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */
10 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
12 /* This file is part of the FreeType project, and may only be used, */
13 /* modified, and distributed under the terms of the FreeType project */
14 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
15 /* this file you indicate that you have read the license and */
16 /* understand and accept it fully. */
18 /***************************************************************************/
20 /*************************************************************************/
22 /* Note: A `raster' is simply a scan-line converter, used to render */
23 /* FT_Outlines into FT_Bitmaps. */
25 /*************************************************************************/
32 /* _STANDALONE_ is from ftgrays.c */
41 /*************************************************************************/
46 /*************************************************************************/
49 /*************************************************************************/
55 /* The type FT_Pos is used to store vectorial coordinates. Depending */
56 /* on the context, these can represent distances in integer font */
57 /* units, or 16.16, or 26.6 fixed float pixel coordinates. */
59 typedef signed long FT_Pos
;
62 /*************************************************************************/
68 /* A simple structure used to store a 2D vector; coordinates are of */
69 /* the FT_Pos type. */
72 /* x :: The horizontal coordinate. */
73 /* y :: The vertical coordinate. */
75 typedef struct FT_Vector_
83 /*************************************************************************/
89 /* A structure used to hold an outline's bounding box, i.e., the */
90 /* coordinates of its extrema in the horizontal and vertical */
94 /* xMin :: The horizontal minimum (left-most). */
96 /* yMin :: The vertical minimum (bottom-most). */
98 /* xMax :: The horizontal maximum (right-most). */
100 /* yMax :: The vertical maximum (top-most). */
103 /* The bounding box is specified with the coordinates of the lower */
104 /* left and the upper right corner. In PostScript, those values are */
105 /* often called (llx,lly) and (urx,ury), respectively. */
107 /* If `yMin' is negative, this value gives the glyph's descender. */
108 /* Otherwise, the glyph doesn't descend below the baseline. */
109 /* Similarly, if `ymax' is positive, this value gives the glyph's */
112 /* `xMin' gives the horizontal distance from the glyph's origin to */
113 /* the left edge of the glyph's bounding box. If `xMin' is negative, */
114 /* the glyph extends to the left of the origin. */
116 typedef struct FT_BBox_
124 /*************************************************************************/
130 /* An enumeration type used to describe the format of pixels in a */
131 /* given bitmap. Note that additional formats may be added in the */
135 /* FT_PIXEL_MODE_NONE :: */
136 /* Value~0 is reserved. */
138 /* FT_PIXEL_MODE_MONO :: */
139 /* A monochrome bitmap, using 1~bit per pixel. Note that pixels */
140 /* are stored in most-significant order (MSB), which means that */
141 /* the left-most pixel in a byte has value 128. */
143 /* FT_PIXEL_MODE_GRAY :: */
144 /* An 8-bit bitmap, generally used to represent anti-aliased glyph */
145 /* images. Each pixel is stored in one byte. Note that the number */
146 /* of `gray' levels is stored in the `num_grays' field of the */
147 /* @FT_Bitmap structure (it generally is 256). */
149 /* FT_PIXEL_MODE_GRAY2 :: */
150 /* A 2-bit per pixel bitmap, used to represent embedded */
151 /* anti-aliased bitmaps in font files according to the OpenType */
152 /* specification. We haven't found a single font using this */
153 /* format, however. */
155 /* FT_PIXEL_MODE_GRAY4 :: */
156 /* A 4-bit per pixel bitmap, representing embedded anti-aliased */
157 /* bitmaps in font files according to the OpenType specification. */
158 /* We haven't found a single font using this format, however. */
160 /* FT_PIXEL_MODE_LCD :: */
161 /* An 8-bit bitmap, representing RGB or BGR decimated glyph images */
162 /* used for display on LCD displays; the bitmap is three times */
163 /* wider than the original glyph image. See also */
164 /* @FT_RENDER_MODE_LCD. */
166 /* FT_PIXEL_MODE_LCD_V :: */
167 /* An 8-bit bitmap, representing RGB or BGR decimated glyph images */
168 /* used for display on rotated LCD displays; the bitmap is three */
169 /* times taller than the original glyph image. See also */
170 /* @FT_RENDER_MODE_LCD_V. */
172 typedef enum FT_Pixel_Mode_
174 FT_PIXEL_MODE_NONE
= 0,
182 FT_PIXEL_MODE_MAX
/* do not remove */
187 /*************************************************************************/
190 /* ft_pixel_mode_xxx */
193 /* A list of deprecated constants. Use the corresponding */
194 /* @FT_Pixel_Mode values instead. */
197 /* ft_pixel_mode_none :: See @FT_PIXEL_MODE_NONE. */
198 /* ft_pixel_mode_mono :: See @FT_PIXEL_MODE_MONO. */
199 /* ft_pixel_mode_grays :: See @FT_PIXEL_MODE_GRAY. */
200 /* ft_pixel_mode_pal2 :: See @FT_PIXEL_MODE_GRAY2. */
201 /* ft_pixel_mode_pal4 :: See @FT_PIXEL_MODE_GRAY4. */
203 #define ft_pixel_mode_none FT_PIXEL_MODE_NONE
204 #define ft_pixel_mode_mono FT_PIXEL_MODE_MONO
205 #define ft_pixel_mode_grays FT_PIXEL_MODE_GRAY
206 #define ft_pixel_mode_pal2 FT_PIXEL_MODE_GRAY2
207 #define ft_pixel_mode_pal4 FT_PIXEL_MODE_GRAY4
213 /*************************************************************************/
216 /* FT_Palette_Mode */
219 /* THIS TYPE IS DEPRECATED. DO NOT USE IT! */
221 /* An enumeration type to describe the format of a bitmap palette, */
222 /* used with ft_pixel_mode_pal4 and ft_pixel_mode_pal8. */
225 /* ft_palette_mode_rgb :: The palette is an array of 3-byte RGB */
228 /* ft_palette_mode_rgba :: The palette is an array of 4-byte RGBA */
232 /* As ft_pixel_mode_pal2, pal4 and pal8 are currently unused by */
233 /* FreeType, these types are not handled by the library itself. */
235 typedef enum FT_Palette_Mode_
237 ft_palette_mode_rgb
= 0,
238 ft_palette_mode_rgba
,
240 ft_palette_mode_max
/* do not remove */
249 /*************************************************************************/
255 /* A structure used to describe a bitmap or pixmap to the raster. */
256 /* Note that we now manage pixmaps of various depths through the */
257 /* `pixel_mode' field. */
260 /* rows :: The number of bitmap rows. */
262 /* width :: The number of pixels in bitmap row. */
264 /* pitch :: The pitch's absolute value is the number of bytes */
265 /* taken by one bitmap row, including padding. */
266 /* However, the pitch is positive when the bitmap has */
267 /* a `down' flow, and negative when it has an `up' */
268 /* flow. In all cases, the pitch is an offset to add */
269 /* to a bitmap pointer in order to go down one row. */
271 /* For the B/W rasterizer, `pitch' is always an even */
274 /* buffer :: A typeless pointer to the bitmap buffer. This */
275 /* value should be aligned on 32-bit boundaries in */
278 /* num_grays :: This field is only used with */
279 /* @FT_PIXEL_MODE_GRAY; it gives the number of gray */
280 /* levels used in the bitmap. */
282 /* pixel_mode :: The pixel mode, i.e., how pixel bits are stored. */
283 /* See @FT_Pixel_Mode for possible values. */
285 /* palette_mode :: This field is intended for paletted pixel modes; */
286 /* it indicates how the palette is stored. Not */
287 /* used currently. */
289 /* palette :: A typeless pointer to the bitmap palette; this */
290 /* field is intended for paletted pixel modes. Not */
291 /* used currently. */
294 /* For now, the only pixel modes supported by FreeType are mono and */
295 /* grays. However, drivers might be added in the future to support */
296 /* more `colorful' options. */
298 typedef struct FT_Bitmap_
303 unsigned char* buffer
;
312 /*************************************************************************/
315 /* outline_processing */
317 /*************************************************************************/
320 /*************************************************************************/
326 /* This structure is used to describe an outline to the scan-line */
330 /* n_contours :: The number of contours in the outline. */
332 /* n_points :: The number of points in the outline. */
334 /* points :: A pointer to an array of `n_points' @FT_Vector */
335 /* elements, giving the outline's point coordinates. */
337 /* tags :: A pointer to an array of `n_points' chars, giving */
338 /* each outline point's type. */
340 /* If bit~0 is unset, the point is `off' the curve, */
341 /* i.e., a Bézier control point, while it is `on' if */
344 /* Bit~1 is meaningful for `off' points only. If set, */
345 /* it indicates a third-order Bézier arc control point; */
346 /* and a second-order control point if unset. */
348 /* If bit~2 is set, bits 5-7 contain the drop-out mode */
349 /* (as defined in the OpenType specification; the value */
350 /* is the same as the argument to the SCANMODE */
353 /* Bits 3 and~4 are reserved for internal purposes. */
355 /* contours :: An array of `n_contours' shorts, giving the end */
356 /* point of each contour within the outline. For */
357 /* example, the first contour is defined by the points */
358 /* `0' to `contours[0]', the second one is defined by */
359 /* the points `contours[0]+1' to `contours[1]', etc. */
361 /* flags :: A set of bit flags used to characterize the outline */
362 /* and give hints to the scan-converter and hinter on */
363 /* how to convert/grid-fit it. See @FT_OUTLINE_FLAGS. */
366 /* The B/W rasterizer only checks bit~2 in the `tags' array for the */
367 /* first point of each contour. The drop-out mode as given with */
368 /* @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, and */
369 /* @FT_OUTLINE_INCLUDE_STUBS in `flags' is then overridden. */
371 typedef struct FT_Outline_
373 short n_contours
; /* number of contours in glyph */
374 short n_points
; /* number of points in the glyph */
376 FT_Vector
* points
; /* the outline's points */
377 char* tags
; /* the points flags */
378 short* contours
; /* the contour end points */
380 int flags
; /* outline masks */
384 /* Following limits must be consistent with */
385 /* FT_Outline.{n_contours,n_points} */
386 #define FT_OUTLINE_CONTOURS_MAX SHRT_MAX
387 #define FT_OUTLINE_POINTS_MAX SHRT_MAX
390 /*************************************************************************/
393 /* FT_OUTLINE_FLAGS */
396 /* A list of bit-field constants use for the flags in an outline's */
400 /* FT_OUTLINE_NONE :: */
401 /* Value~0 is reserved. */
403 /* FT_OUTLINE_OWNER :: */
404 /* If set, this flag indicates that the outline's field arrays */
405 /* (i.e., `points', `flags', and `contours') are `owned' by the */
406 /* outline object, and should thus be freed when it is destroyed. */
408 /* FT_OUTLINE_EVEN_ODD_FILL :: */
409 /* By default, outlines are filled using the non-zero winding rule. */
410 /* If set to 1, the outline will be filled using the even-odd fill */
411 /* rule (only works with the smooth rasterizer). */
413 /* FT_OUTLINE_REVERSE_FILL :: */
414 /* By default, outside contours of an outline are oriented in */
415 /* clock-wise direction, as defined in the TrueType specification. */
416 /* This flag is set if the outline uses the opposite direction */
417 /* (typically for Type~1 fonts). This flag is ignored by the scan */
420 /* FT_OUTLINE_IGNORE_DROPOUTS :: */
421 /* By default, the scan converter will try to detect drop-outs in */
422 /* an outline and correct the glyph bitmap to ensure consistent */
423 /* shape continuity. If set, this flag hints the scan-line */
424 /* converter to ignore such cases. See below for more information. */
426 /* FT_OUTLINE_SMART_DROPOUTS :: */
427 /* Select smart dropout control. If unset, use simple dropout */
428 /* control. Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See */
429 /* below for more information. */
431 /* FT_OUTLINE_INCLUDE_STUBS :: */
432 /* If set, turn pixels on for `stubs', otherwise exclude them. */
433 /* Ignored if @FT_OUTLINE_IGNORE_DROPOUTS is set. See below for */
434 /* more information. */
436 /* FT_OUTLINE_HIGH_PRECISION :: */
437 /* This flag indicates that the scan-line converter should try to */
438 /* convert this outline to bitmaps with the highest possible */
439 /* quality. It is typically set for small character sizes. Note */
440 /* that this is only a hint that might be completely ignored by a */
441 /* given scan-converter. */
443 /* FT_OUTLINE_SINGLE_PASS :: */
444 /* This flag is set to force a given scan-converter to only use a */
445 /* single pass over the outline to render a bitmap glyph image. */
446 /* Normally, it is set for very large character sizes. It is only */
447 /* a hint that might be completely ignored by a given */
448 /* scan-converter. */
451 /* The flags @FT_OUTLINE_IGNORE_DROPOUTS, @FT_OUTLINE_SMART_DROPOUTS, */
452 /* and @FT_OUTLINE_INCLUDE_STUBS are ignored by the smooth */
455 /* There exists a second mechanism to pass the drop-out mode to the */
456 /* B/W rasterizer; see the `tags' field in @FT_Outline. */
458 /* Please refer to the description of the `SCANTYPE' instruction in */
459 /* the OpenType specification (in file `ttinst1.doc') how simple */
460 /* drop-outs, smart drop-outs, and stubs are defined. */
462 #define FT_OUTLINE_NONE 0x0
463 #define FT_OUTLINE_OWNER 0x1
464 #define FT_OUTLINE_EVEN_ODD_FILL 0x2
465 #define FT_OUTLINE_REVERSE_FILL 0x4
466 #define FT_OUTLINE_IGNORE_DROPOUTS 0x8
467 #define FT_OUTLINE_SMART_DROPOUTS 0x10
468 #define FT_OUTLINE_INCLUDE_STUBS 0x20
470 #define FT_OUTLINE_HIGH_PRECISION 0x100
471 #define FT_OUTLINE_SINGLE_PASS 0x200
474 /*************************************************************************
480 * These constants are deprecated. Please use the corresponding
481 * @FT_OUTLINE_FLAGS values.
484 * ft_outline_none :: See @FT_OUTLINE_NONE.
485 * ft_outline_owner :: See @FT_OUTLINE_OWNER.
486 * ft_outline_even_odd_fill :: See @FT_OUTLINE_EVEN_ODD_FILL.
487 * ft_outline_reverse_fill :: See @FT_OUTLINE_REVERSE_FILL.
488 * ft_outline_ignore_dropouts :: See @FT_OUTLINE_IGNORE_DROPOUTS.
489 * ft_outline_high_precision :: See @FT_OUTLINE_HIGH_PRECISION.
490 * ft_outline_single_pass :: See @FT_OUTLINE_SINGLE_PASS.
492 #define ft_outline_none FT_OUTLINE_NONE
493 #define ft_outline_owner FT_OUTLINE_OWNER
494 #define ft_outline_even_odd_fill FT_OUTLINE_EVEN_ODD_FILL
495 #define ft_outline_reverse_fill FT_OUTLINE_REVERSE_FILL
496 #define ft_outline_ignore_dropouts FT_OUTLINE_IGNORE_DROPOUTS
497 #define ft_outline_high_precision FT_OUTLINE_HIGH_PRECISION
498 #define ft_outline_single_pass FT_OUTLINE_SINGLE_PASS
502 #define FT_CURVE_TAG( flag ) ( flag & 3 )
504 #define FT_CURVE_TAG_ON 1
505 #define FT_CURVE_TAG_CONIC 0
506 #define FT_CURVE_TAG_CUBIC 2
508 #define FT_CURVE_TAG_HAS_SCANMODE 4
510 #define FT_CURVE_TAG_TOUCH_X 8 /* reserved for the TrueType hinter */
511 #define FT_CURVE_TAG_TOUCH_Y 16 /* reserved for the TrueType hinter */
513 #define FT_CURVE_TAG_TOUCH_BOTH ( FT_CURVE_TAG_TOUCH_X | \
514 FT_CURVE_TAG_TOUCH_Y )
516 #define FT_Curve_Tag_On FT_CURVE_TAG_ON
517 #define FT_Curve_Tag_Conic FT_CURVE_TAG_CONIC
518 #define FT_Curve_Tag_Cubic FT_CURVE_TAG_CUBIC
519 #define FT_Curve_Tag_Touch_X FT_CURVE_TAG_TOUCH_X
520 #define FT_Curve_Tag_Touch_Y FT_CURVE_TAG_TOUCH_Y
523 /*************************************************************************/
526 /* FT_Outline_MoveToFunc */
529 /* A function pointer type used to describe the signature of a `move */
530 /* to' function during outline walking/decomposition. */
532 /* A `move to' is emitted to start a new contour in an outline. */
535 /* to :: A pointer to the target point of the `move to'. */
537 /* user :: A typeless pointer which is passed from the caller of the */
538 /* decomposition function. */
541 /* Error code. 0~means success. */
544 (*FT_Outline_MoveToFunc
)( const FT_Vector
* to
,
547 #define FT_Outline_MoveTo_Func FT_Outline_MoveToFunc
550 /*************************************************************************/
553 /* FT_Outline_LineToFunc */
556 /* A function pointer type used to describe the signature of a `line */
557 /* to' function during outline walking/decomposition. */
559 /* A `line to' is emitted to indicate a segment in the outline. */
562 /* to :: A pointer to the target point of the `line to'. */
564 /* user :: A typeless pointer which is passed from the caller of the */
565 /* decomposition function. */
568 /* Error code. 0~means success. */
571 (*FT_Outline_LineToFunc
)( const FT_Vector
* to
,
574 #define FT_Outline_LineTo_Func FT_Outline_LineToFunc
577 /*************************************************************************/
580 /* FT_Outline_ConicToFunc */
583 /* A function pointer type used to describe the signature of a `conic */
584 /* to' function during outline walking or decomposition. */
586 /* A `conic to' is emitted to indicate a second-order Bézier arc in */
590 /* control :: An intermediate control point between the last position */
591 /* and the new target in `to'. */
593 /* to :: A pointer to the target end point of the conic arc. */
595 /* user :: A typeless pointer which is passed from the caller of */
596 /* the decomposition function. */
599 /* Error code. 0~means success. */
602 (*FT_Outline_ConicToFunc
)( const FT_Vector
* control
,
606 #define FT_Outline_ConicTo_Func FT_Outline_ConicToFunc
609 /*************************************************************************/
612 /* FT_Outline_CubicToFunc */
615 /* A function pointer type used to describe the signature of a `cubic */
616 /* to' function during outline walking or decomposition. */
618 /* A `cubic to' is emitted to indicate a third-order Bézier arc. */
621 /* control1 :: A pointer to the first Bézier control point. */
623 /* control2 :: A pointer to the second Bézier control point. */
625 /* to :: A pointer to the target end point. */
627 /* user :: A typeless pointer which is passed from the caller of */
628 /* the decomposition function. */
631 /* Error code. 0~means success. */
634 (*FT_Outline_CubicToFunc
)( const FT_Vector
* control1
,
635 const FT_Vector
* control2
,
639 #define FT_Outline_CubicTo_Func FT_Outline_CubicToFunc
642 /*************************************************************************/
645 /* FT_Outline_Funcs */
648 /* A structure to hold various function pointers used during outline */
649 /* decomposition in order to emit segments, conic, and cubic Béziers. */
652 /* move_to :: The `move to' emitter. */
654 /* line_to :: The segment emitter. */
656 /* conic_to :: The second-order Bézier arc emitter. */
658 /* cubic_to :: The third-order Bézier arc emitter. */
660 /* shift :: The shift that is applied to coordinates before they */
661 /* are sent to the emitter. */
663 /* delta :: The delta that is applied to coordinates before they */
664 /* are sent to the emitter, but after the shift. */
667 /* The point coordinates sent to the emitters are the transformed */
668 /* version of the original coordinates (this is important for high */
669 /* accuracy during scan-conversion). The transformation is simple: */
672 /* x' = (x << shift) - delta */
673 /* y' = (x << shift) - delta */
676 /* Set the values of `shift' and `delta' to~0 to get the original */
677 /* point coordinates. */
679 typedef struct FT_Outline_Funcs_
681 FT_Outline_MoveToFunc move_to
;
682 FT_Outline_LineToFunc line_to
;
683 FT_Outline_ConicToFunc conic_to
;
684 FT_Outline_CubicToFunc cubic_to
;
692 /*************************************************************************/
697 /*************************************************************************/
700 /*************************************************************************/
706 /* This macro converts four-letter tags to an unsigned long type. */
709 /* Since many 16-bit compilers don't like 32-bit enumerations, you */
710 /* should redefine this macro in case of problems to something like */
714 /* #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) value */
717 /* to get a simple enumeration without assigning special numbers. */
720 #define FT_IMAGE_TAG( value, _x1, _x2, _x3, _x4 ) \
721 value = ( ( (unsigned long)_x1 << 24 ) | \
722 ( (unsigned long)_x2 << 16 ) | \
723 ( (unsigned long)_x3 << 8 ) | \
725 #endif /* FT_IMAGE_TAG */
728 /*************************************************************************/
731 /* FT_Glyph_Format */
734 /* An enumeration type used to describe the format of a given glyph */
735 /* image. Note that this version of FreeType only supports two image */
736 /* formats, even though future font drivers will be able to register */
737 /* their own format. */
740 /* FT_GLYPH_FORMAT_NONE :: */
741 /* The value~0 is reserved. */
743 /* FT_GLYPH_FORMAT_COMPOSITE :: */
744 /* The glyph image is a composite of several other images. This */
745 /* format is _only_ used with @FT_LOAD_NO_RECURSE, and is used to */
746 /* report compound glyphs (like accented characters). */
748 /* FT_GLYPH_FORMAT_BITMAP :: */
749 /* The glyph image is a bitmap, and can be described as an */
750 /* @FT_Bitmap. You generally need to access the `bitmap' field of */
751 /* the @FT_GlyphSlotRec structure to read it. */
753 /* FT_GLYPH_FORMAT_OUTLINE :: */
754 /* The glyph image is a vectorial outline made of line segments */
755 /* and Bézier arcs; it can be described as an @FT_Outline; you */
756 /* generally want to access the `outline' field of the */
757 /* @FT_GlyphSlotRec structure to read it. */
759 /* FT_GLYPH_FORMAT_PLOTTER :: */
760 /* The glyph image is a vectorial path with no inside and outside */
761 /* contours. Some Type~1 fonts, like those in the Hershey family, */
762 /* contain glyphs in this format. These are described as */
763 /* @FT_Outline, but FreeType isn't currently capable of rendering */
764 /* them correctly. */
766 typedef enum FT_Glyph_Format_
768 FT_IMAGE_TAG( FT_GLYPH_FORMAT_NONE
, 0, 0, 0, 0 ),
770 FT_IMAGE_TAG( FT_GLYPH_FORMAT_COMPOSITE
, 'c', 'o', 'm', 'p' ),
771 FT_IMAGE_TAG( FT_GLYPH_FORMAT_BITMAP
, 'b', 'i', 't', 's' ),
772 FT_IMAGE_TAG( FT_GLYPH_FORMAT_OUTLINE
, 'o', 'u', 't', 'l' ),
773 FT_IMAGE_TAG( FT_GLYPH_FORMAT_PLOTTER
, 'p', 'l', 'o', 't' )
778 /*************************************************************************/
781 /* ft_glyph_format_xxx */
784 /* A list of deprecated constants. Use the corresponding */
785 /* @FT_Glyph_Format values instead. */
788 /* ft_glyph_format_none :: See @FT_GLYPH_FORMAT_NONE. */
789 /* ft_glyph_format_composite :: See @FT_GLYPH_FORMAT_COMPOSITE. */
790 /* ft_glyph_format_bitmap :: See @FT_GLYPH_FORMAT_BITMAP. */
791 /* ft_glyph_format_outline :: See @FT_GLYPH_FORMAT_OUTLINE. */
792 /* ft_glyph_format_plotter :: See @FT_GLYPH_FORMAT_PLOTTER. */
794 #define ft_glyph_format_none FT_GLYPH_FORMAT_NONE
795 #define ft_glyph_format_composite FT_GLYPH_FORMAT_COMPOSITE
796 #define ft_glyph_format_bitmap FT_GLYPH_FORMAT_BITMAP
797 #define ft_glyph_format_outline FT_GLYPH_FORMAT_OUTLINE
798 #define ft_glyph_format_plotter FT_GLYPH_FORMAT_PLOTTER
801 /*************************************************************************/
802 /*************************************************************************/
803 /*************************************************************************/
805 /***** R A S T E R D E F I N I T I O N S *****/
807 /*************************************************************************/
808 /*************************************************************************/
809 /*************************************************************************/
812 /*************************************************************************/
814 /* A raster is a scan converter, in charge of rendering an outline into */
815 /* a a bitmap. This section contains the public API for rasters. */
817 /* Note that in FreeType 2, all rasters are now encapsulated within */
818 /* specific modules called `renderers'. See `freetype/ftrender.h' for */
819 /* more details on renderers. */
821 /*************************************************************************/
824 /*************************************************************************/
830 /* Scanline Converter */
833 /* How vectorial outlines are converted into bitmaps and pixmaps. */
836 /* This section contains technical definitions. */
838 /*************************************************************************/
841 /*************************************************************************/
847 /* A handle (pointer) to a raster object. Each object can be used */
848 /* independently to convert an outline into a bitmap or pixmap. */
850 typedef struct FT_RasterRec_
* FT_Raster
;
853 /*************************************************************************/
859 /* A structure used to model a single span of gray (or black) pixels */
860 /* when rendering a monochrome or anti-aliased bitmap. */
863 /* x :: The span's horizontal start position. */
865 /* len :: The span's length in pixels. */
867 /* coverage :: The span color/coverage, ranging from 0 (background) */
868 /* to 255 (foreground). Only used for anti-aliased */
872 /* This structure is used by the span drawing callback type named */
873 /* @FT_SpanFunc which takes the y~coordinate of the span as a */
876 /* The coverage value is always between 0 and 255. If you want less */
877 /* gray values, the callback function has to reduce them. */
879 typedef struct FT_Span_
883 unsigned char coverage
;
888 /*************************************************************************/
894 /* A function used as a call-back by the anti-aliased renderer in */
895 /* order to let client applications draw themselves the gray pixel */
896 /* spans on each scan line. */
899 /* y :: The scanline's y~coordinate. */
901 /* count :: The number of spans to draw on this scanline. */
903 /* spans :: A table of `count' spans to draw on the scanline. */
905 /* user :: User-supplied data that is passed to the callback. */
908 /* This callback allows client applications to directly render the */
909 /* gray spans of the anti-aliased bitmap to any kind of surfaces. */
911 /* This can be used to write anti-aliased outlines directly to a */
912 /* given background bitmap, and even perform translucency. */
914 /* Note that the `count' field cannot be greater than a fixed value */
915 /* defined by the `FT_MAX_GRAY_SPANS' configuration macro in */
916 /* `ftoption.h'. By default, this value is set to~32, which means */
917 /* that if there are more than 32~spans on a given scanline, the */
918 /* callback is called several times with the same `y' parameter in */
919 /* order to draw all callbacks. */
921 /* Otherwise, the callback is only called once per scan-line, and */
922 /* only for those scanlines that do have `gray' pixels on them. */
925 (*FT_SpanFunc
)( int y
,
927 const FT_Span
* spans
,
930 #define FT_Raster_Span_Func FT_SpanFunc
933 /*************************************************************************/
936 /* FT_Raster_BitTest_Func */
939 /* THIS TYPE IS DEPRECATED. DO NOT USE IT. */
941 /* A function used as a call-back by the monochrome scan-converter */
942 /* to test whether a given target pixel is already set to the drawing */
943 /* `color'. These tests are crucial to implement drop-out control */
944 /* per-se the TrueType spec. */
947 /* y :: The pixel's y~coordinate. */
949 /* x :: The pixel's x~coordinate. */
951 /* user :: User-supplied data that is passed to the callback. */
954 /* 1~if the pixel is `set', 0~otherwise. */
957 (*FT_Raster_BitTest_Func
)( int y
,
962 /*************************************************************************/
965 /* FT_Raster_BitSet_Func */
968 /* THIS TYPE IS DEPRECATED. DO NOT USE IT. */
970 /* A function used as a call-back by the monochrome scan-converter */
971 /* to set an individual target pixel. This is crucial to implement */
972 /* drop-out control according to the TrueType specification. */
975 /* y :: The pixel's y~coordinate. */
977 /* x :: The pixel's x~coordinate. */
979 /* user :: User-supplied data that is passed to the callback. */
982 /* 1~if the pixel is `set', 0~otherwise. */
985 (*FT_Raster_BitSet_Func
)( int y
,
990 /*************************************************************************/
993 /* FT_RASTER_FLAG_XXX */
996 /* A list of bit flag constants as used in the `flags' field of a */
997 /* @FT_Raster_Params structure. */
1000 /* FT_RASTER_FLAG_DEFAULT :: This value is 0. */
1002 /* FT_RASTER_FLAG_AA :: This flag is set to indicate that an */
1003 /* anti-aliased glyph image should be */
1004 /* generated. Otherwise, it will be */
1005 /* monochrome (1-bit). */
1007 /* FT_RASTER_FLAG_DIRECT :: This flag is set to indicate direct */
1008 /* rendering. In this mode, client */
1009 /* applications must provide their own span */
1010 /* callback. This lets them directly */
1011 /* draw or compose over an existing bitmap. */
1012 /* If this bit is not set, the target */
1013 /* pixmap's buffer _must_ be zeroed before */
1016 /* Note that for now, direct rendering is */
1017 /* only possible with anti-aliased glyphs. */
1019 /* FT_RASTER_FLAG_CLIP :: This flag is only used in direct */
1020 /* rendering mode. If set, the output will */
1021 /* be clipped to a box specified in the */
1022 /* `clip_box' field of the */
1023 /* @FT_Raster_Params structure. */
1025 /* Note that by default, the glyph bitmap */
1026 /* is clipped to the target pixmap, except */
1027 /* in direct rendering mode where all spans */
1028 /* are generated if no clipping box is set. */
1030 #define FT_RASTER_FLAG_DEFAULT 0x0
1031 #define FT_RASTER_FLAG_AA 0x1
1032 #define FT_RASTER_FLAG_DIRECT 0x2
1033 #define FT_RASTER_FLAG_CLIP 0x4
1036 #define ft_raster_flag_default FT_RASTER_FLAG_DEFAULT
1037 #define ft_raster_flag_aa FT_RASTER_FLAG_AA
1038 #define ft_raster_flag_direct FT_RASTER_FLAG_DIRECT
1039 #define ft_raster_flag_clip FT_RASTER_FLAG_CLIP
1042 /*************************************************************************/
1045 /* FT_Raster_Params */
1048 /* A structure to hold the arguments used by a raster's render */
1052 /* target :: The target bitmap. */
1054 /* source :: A pointer to the source glyph image (e.g., an */
1057 /* flags :: The rendering flags. */
1059 /* gray_spans :: The gray span drawing callback. */
1061 /* black_spans :: The black span drawing callback. UNIMPLEMENTED! */
1063 /* bit_test :: The bit test callback. UNIMPLEMENTED! */
1065 /* bit_set :: The bit set callback. UNIMPLEMENTED! */
1067 /* user :: User-supplied data that is passed to each drawing */
1070 /* clip_box :: An optional clipping box. It is only used in */
1071 /* direct rendering mode. Note that coordinates here */
1072 /* should be expressed in _integer_ pixels (and not in */
1073 /* 26.6 fixed-point units). */
1076 /* An anti-aliased glyph bitmap is drawn if the @FT_RASTER_FLAG_AA */
1077 /* bit flag is set in the `flags' field, otherwise a monochrome */
1078 /* bitmap is generated. */
1080 /* If the @FT_RASTER_FLAG_DIRECT bit flag is set in `flags', the */
1081 /* raster will call the `gray_spans' callback to draw gray pixel */
1082 /* spans, in the case of an aa glyph bitmap, it will call */
1083 /* `black_spans', and `bit_test' and `bit_set' in the case of a */
1084 /* monochrome bitmap. This allows direct composition over a */
1085 /* pre-existing bitmap through user-provided callbacks to perform the */
1086 /* span drawing/composition. */
1088 /* Note that the `bit_test' and `bit_set' callbacks are required when */
1089 /* rendering a monochrome bitmap, as they are crucial to implement */
1090 /* correct drop-out control as defined in the TrueType specification. */
1092 typedef struct FT_Raster_Params_
1094 const FT_Bitmap
* target
;
1097 FT_SpanFunc gray_spans
;
1098 FT_SpanFunc black_spans
; /* doesn't work! */
1099 FT_Raster_BitTest_Func bit_test
; /* doesn't work! */
1100 FT_Raster_BitSet_Func bit_set
; /* doesn't work! */
1107 /*************************************************************************/
1110 /* FT_Raster_NewFunc */
1113 /* A function used to create a new raster object. */
1116 /* memory :: A handle to the memory allocator. */
1119 /* raster :: A handle to the new raster object. */
1122 /* Error code. 0~means success. */
1125 /* The `memory' parameter is a typeless pointer in order to avoid */
1126 /* un-wanted dependencies on the rest of the FreeType code. In */
1127 /* practice, it is an @FT_Memory object, i.e., a handle to the */
1128 /* standard FreeType memory allocator. However, this field can be */
1129 /* completely ignored by a given raster implementation. */
1132 (*FT_Raster_NewFunc
)( void* memory
,
1133 FT_Raster
* raster
);
1135 #define FT_Raster_New_Func FT_Raster_NewFunc
1138 /*************************************************************************/
1141 /* FT_Raster_DoneFunc */
1144 /* A function used to destroy a given raster object. */
1147 /* raster :: A handle to the raster object. */
1150 (*FT_Raster_DoneFunc
)( FT_Raster raster
);
1152 #define FT_Raster_Done_Func FT_Raster_DoneFunc
1155 /*************************************************************************/
1158 /* FT_Raster_ResetFunc */
1161 /* FreeType provides an area of memory called the `render pool', */
1162 /* available to all registered rasters. This pool can be freely used */
1163 /* during a given scan-conversion but is shared by all rasters. Its */
1164 /* content is thus transient. */
1166 /* This function is called each time the render pool changes, or just */
1167 /* after a new raster object is created. */
1170 /* raster :: A handle to the new raster object. */
1172 /* pool_base :: The address in memory of the render pool. */
1174 /* pool_size :: The size in bytes of the render pool. */
1177 /* Rasters can ignore the render pool and rely on dynamic memory */
1178 /* allocation if they want to (a handle to the memory allocator is */
1179 /* passed to the raster constructor). However, this is not */
1180 /* recommended for efficiency purposes. */
1183 (*FT_Raster_ResetFunc
)( FT_Raster raster
,
1184 unsigned char* pool_base
,
1185 unsigned long pool_size
);
1187 #define FT_Raster_Reset_Func FT_Raster_ResetFunc
1190 /*************************************************************************/
1193 /* FT_Raster_SetModeFunc */
1196 /* This function is a generic facility to change modes or attributes */
1197 /* in a given raster. This can be used for debugging purposes, or */
1198 /* simply to allow implementation-specific `features' in a given */
1199 /* raster module. */
1202 /* raster :: A handle to the new raster object. */
1204 /* mode :: A 4-byte tag used to name the mode or property. */
1206 /* args :: A pointer to the new mode/property to use. */
1209 (*FT_Raster_SetModeFunc
)( FT_Raster raster
,
1213 #define FT_Raster_Set_Mode_Func FT_Raster_SetModeFunc
1216 /*************************************************************************/
1219 /* FT_Raster_RenderFunc */
1222 /* Invoke a given raster to scan-convert a given glyph image into a */
1223 /* target bitmap. */
1226 /* raster :: A handle to the raster object. */
1228 /* params :: A pointer to an @FT_Raster_Params structure used to */
1229 /* store the rendering parameters. */
1232 /* Error code. 0~means success. */
1235 /* The exact format of the source image depends on the raster's glyph */
1236 /* format defined in its @FT_Raster_Funcs structure. It can be an */
1237 /* @FT_Outline or anything else in order to support a large array of */
1238 /* glyph formats. */
1240 /* Note also that the render function can fail and return a */
1241 /* `FT_Err_Unimplemented_Feature' error code if the raster used does */
1242 /* not support direct composition. */
1244 /* XXX: For now, the standard raster doesn't support direct */
1245 /* composition but this should change for the final release (see */
1246 /* the files `demos/src/ftgrays.c' and `demos/src/ftgrays2.c' */
1247 /* for examples of distinct implementations which support direct */
1251 (*FT_Raster_RenderFunc
)( FT_Raster raster
,
1252 const FT_Raster_Params
* params
);
1254 #define FT_Raster_Render_Func FT_Raster_RenderFunc
1257 /*************************************************************************/
1260 /* FT_Raster_Funcs */
1263 /* A structure used to describe a given raster class to the library. */
1266 /* glyph_format :: The supported glyph format for this raster. */
1268 /* raster_new :: The raster constructor. */
1270 /* raster_reset :: Used to reset the render pool within the raster. */
1272 /* raster_render :: A function to render a glyph into a given bitmap. */
1274 /* raster_done :: The raster destructor. */
1276 typedef struct FT_Raster_Funcs_
1278 FT_Glyph_Format glyph_format
;
1279 FT_Raster_NewFunc raster_new
;
1280 FT_Raster_ResetFunc raster_reset
;
1281 FT_Raster_SetModeFunc raster_set_mode
;
1282 FT_Raster_RenderFunc raster_render
;
1283 FT_Raster_DoneFunc raster_done
;
1293 #endif /* __FTIMAGE_H__ */
1299 /* Local Variables: */