This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / subsys / win32k / freetype / include / freetype / ftimage.h
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ftimage.h                                                              */
4 /*                                                                         */
5 /*    FreeType glyph image formats and default raster interface            */
6 /*    (specification).                                                     */
7 /*                                                                         */
8 /*  Copyright 1996-2000 by                                                 */
9 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
10 /*                                                                         */
11 /*  This file is part of the FreeType project, and may only be used,       */
12 /*  modified, and distributed under the terms of the FreeType project      */
13 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
14 /*  this file you indicate that you have read the license and              */
15 /*  understand and accept it fully.                                        */
16 /*                                                                         */
17 /***************************************************************************/
18
19   /*************************************************************************/
20   /*                                                                       */
21   /* Note: A `raster' is simply a scan-line converter, used to render      */
22   /*       FT_Outlines into FT_Bitmaps.                                    */
23   /*                                                                       */
24   /*************************************************************************/
25
26
27 #ifndef FTIMAGE_H
28 #define FTIMAGE_H
29
30
31 #ifdef __cplusplus
32   extern "C" {
33 #endif
34
35
36   /*************************************************************************/
37   /*                                                                       */
38   /* <Type>                                                                */
39   /*    FT_Pos                                                             */
40   /*                                                                       */
41   /* <Description>                                                         */
42   /*    The type FT_Pos is a 32-bit integer used to store vectorial        */
43   /*    coordinates.  Depending on the context, these can represent        */
44   /*    distances in integer font units, or 26.6 fixed float pixel         */
45   /*    coordinates.                                                       */
46   /*                                                                       */
47   typedef signed long  FT_Pos;
48
49
50   /*************************************************************************/
51   /*                                                                       */
52   /* <Struct>                                                              */
53   /*    FT_Vector                                                          */
54   /*                                                                       */
55   /* <Description>                                                         */
56   /*    A simple structure used to store a 2D vector; coordinates are of   */
57   /*    the FT_Pos type.                                                   */
58   /*                                                                       */
59   /* <Fields>                                                              */
60   /*    x :: The horizontal coordinate.                                    */
61   /*    y :: The vertical coordinate.                                      */
62   /*                                                                       */
63   typedef struct  FT_Vector_
64   {
65     FT_Pos  x;
66     FT_Pos  y;
67
68   } FT_Vector;
69
70
71   /*************************************************************************/
72   /*                                                                       */
73   /* <Enum>                                                                */
74   /*    FT_Pixel_Mode                                                      */
75   /*                                                                       */
76   /* <Description>                                                         */
77   /*    An enumeration type used to describe the format of pixels in a     */
78   /*    given bitmap.  Note that additional formats may be added in the    */
79   /*    future.                                                            */
80   /*                                                                       */
81   /* <Fields>                                                              */
82   /*    ft_pixel_mode_mono  :: A monochrome bitmap (1 bit/pixel).          */
83   /*                                                                       */
84   /*    ft_pixel_mode_grays :: An 8-bit gray-levels bitmap.  Note that the */
85   /*                           total number of gray levels is given in the */
86   /*                           `num_grays' field of the FT_Bitmap          */
87   /*                           structure.                                  */
88   /*                                                                       */
89   /*    ft_pixel_mode_pal2  :: A 2-bit paletted bitmap.                    */
90   /*                           Currently unused by FreeType.               */
91   /*                                                                       */
92   /*    ft_pixel_mode_pal4  :: A 4-bit paletted bitmap.                    */
93   /*                           Currently unused by FreeType.               */
94   /*                                                                       */
95   /*    ft_pixel_mode_pal8  :: An 8-bit paletted bitmap.                   */
96   /*                           Currently unused by FreeType.               */
97   /*                                                                       */
98   /*    ft_pixel_mode_rgb15 :: A 15-bit RGB bitmap.  Uses 5:5:5 encoding.  */
99   /*                           Currently unused by FreeType.               */
100   /*                                                                       */
101   /*    ft_pixel_mode_rgb16 :: A 16-bit RGB bitmap.  Uses 5:6:5 encoding.  */
102   /*                           Currently unused by FreeType.               */
103   /*                                                                       */
104   /*    ft_pixel_mode_rgb24 :: A 24-bit RGB bitmap.                        */
105   /*                           Currently unused by FreeType.               */
106   /*                                                                       */
107   /*    ft_pixel_mode_rgb32 :: A 32-bit RGB bitmap.                        */
108   /*                           Currently unused by FreeType.               */
109   /*                                                                       */
110   /* <Note>                                                                */
111   /*    Some anti-aliased bitmaps might be embedded in TrueType fonts      */
112   /*    using formats pal2 or pal4, though no fonts presenting those have  */
113   /*    been found to date.                                                */
114   /*                                                                       */
115   typedef enum  FT_Pixel_Mode_
116   {
117     ft_pixel_mode_none = 0,
118     ft_pixel_mode_mono,
119     ft_pixel_mode_grays,
120     ft_pixel_mode_pal2,
121     ft_pixel_mode_pal4,
122     ft_pixel_mode_pal8,
123     ft_pixel_mode_rgb15,
124     ft_pixel_mode_rgb16,
125     ft_pixel_mode_rgb24,
126     ft_pixel_mode_rgb32,
127
128     ft_pixel_mode_max      /* do not remove */
129
130   } FT_Pixel_Mode;
131
132
133   /*************************************************************************/
134   /*                                                                       */
135   /* <Enum>                                                                */
136   /*    FT_Palette_Mode                                                    */
137   /*                                                                       */
138   /* <Description>                                                         */
139   /*    An enumeration type used to describe the format of a bitmap        */
140   /*    palette, used with ft_pixel_mode_pal4 and ft_pixel_mode_pal8.      */
141   /*                                                                       */
142   /* <Fields>                                                              */
143   /*    ft_palette_mode_rgb  :: The palette is an array of 3-bytes RGB     */
144   /*                            records.                                   */
145   /*                                                                       */
146   /*    ft_palette_mode_rgba :: The palette is an array of 4-bytes RGBA    */
147   /*                            records.                                   */
148   /*                                                                       */
149   /* <Note>                                                                */
150   /*    As ft_pixel_mode_pal2, pal4 and pal8 are currently unused by       */
151   /*    FreeType, these types are not handled by the library itself.       */
152   /*                                                                       */
153   typedef enum  FT_Palette_Mode_
154   {
155     ft_palette_mode_rgb = 0,
156     ft_palette_mode_rgba,
157
158     ft_palettte_mode_max   /* do not remove */
159
160   } FT_Palette_Mode;
161
162
163   /*************************************************************************/
164   /*                                                                       */
165   /* <Struct>                                                              */
166   /*    FT_Bitmap                                                          */
167   /*                                                                       */
168   /* <Description>                                                         */
169   /*    A structure used to describe a bitmap or pixmap to the raster.     */
170   /*    Note that we now manage pixmaps of various depths through the      */
171   /*    `pixel_mode' field.                                                */
172   /*                                                                       */
173   /* <Fields>                                                              */
174   /*    rows         :: The number of bitmap rows.                         */
175   /*                                                                       */
176   /*    width        :: The number of pixels in bitmap row.                */
177   /*                                                                       */
178   /*    pitch        :: The pitch's absolute value is the number of bytes  */
179   /*                    taken by one bitmap row, including padding.        */
180   /*                    However, the pitch is positive when the bitmap has */
181   /*                    a `down' flow, and negative when it has an `up'    */
182   /*                    flow.  In all cases, the pitch is an offset to add */
183   /*                    to a bitmap pointer in order to go down one row.   */
184   /*                                                                       */
185   /*    buffer       :: A typeless pointer to the bitmap buffer.  This     */
186   /*                    value should be aligned on 32-bit boundaries in    */
187   /*                    most cases.                                        */
188   /*                                                                       */
189   /*    num_grays    :: This field is only used with                       */
190   /*                    `ft_pixel_mode_grays'; it gives the number of gray */
191   /*                    levels used in the bitmap.                         */
192   /*                                                                       */
193   /*    pixel_mode   :: The pixel_mode, i.e., how pixel bits are stored.   */
194   /*                                                                       */
195   /*    palette_mode :: This field is only used with paletted pixel modes; */
196   /*                    it indicates how the palette is stored.            */
197   /*                                                                       */
198   /*    palette      :: A typeless pointer to the bitmap palette; only     */
199   /*                    used for paletted pixel modes.                     */
200   /*                                                                       */
201   /* <Note>                                                                */
202   /*   For now, the only pixel mode supported by FreeType are mono and     */
203   /*   grays.  However, drivers might be added in the future to support    */
204   /*   more `colorful' options.                                            */
205   /*                                                                       */
206   /*   When using pixel modes pal2, pal4 and pal8 with a void `palette'    */
207   /*   field, a gray pixmap with respectively 4, 16, and 256 levels of     */
208   /*   gray is assumed.  This, in order to be compatible with some         */
209   /*   embedded bitmap formats defined in the TrueType specification.      */
210   /*                                                                       */
211   /*   Note that no font was found presenting such embedded bitmaps, so    */
212   /*   this is currently completely unhandled by the library.              */
213   /*                                                                       */
214   typedef struct  FT_Bitmap_
215   {
216     int             rows;
217     int             width;
218     int             pitch;
219     unsigned char*  buffer;
220     short           num_grays;
221     char            pixel_mode;
222     char            palette_mode;
223     void*           palette;
224
225   } FT_Bitmap;
226
227
228   /*************************************************************************/
229   /*                                                                       */
230   /* <Struct>                                                              */
231   /*    FT_Outline                                                         */
232   /*                                                                       */
233   /* <Description>                                                         */
234   /*    This structure is used to describe an outline to the scan-line     */
235   /*    converter.                                                         */
236   /*                                                                       */
237   /* <Fields>                                                              */
238   /*    n_contours :: The number of contours in the outline.               */
239   /*                                                                       */
240   /*    n_points   :: The number of points in the outline.                 */
241   /*                                                                       */
242   /*    points     :: A pointer to an array of `n_points' FT_Vector        */
243   /*                  elements, giving the outline's point coordinates.    */
244   /*                                                                       */
245   /*    tags       :: A pointer to an array of `n_points' chars, giving    */
246   /*                  giving each outline point's type.  If bit 0 is       */
247   /*                  unset, the point is 'off' the curve, i.e. a Bezier   */
248   /*                  control point, while it is `on' when unset.          */
249   /*                                                                       */
250   /*                  Bit 1 is meaningful for `off' points only.  If set,  */
251   /*                  it indicates a third-order Bezier arc control point; */
252   /*                  and a second-order control point if unset.           */
253   /*                                                                       */
254   /*    contours   :: An array of `n_contours' shorts, giving the end      */
255   /*                  point of each contour within the outline.  For       */
256   /*                  example, the first contour is defined by the points  */
257   /*                  `0' to `contours[0]', the second one is defined by   */
258   /*                  the points `contours[0]+1' to `contours[1]', etc.    */
259   /*                                                                       */
260   /*    flags      :: A set of bit flags used to characterize the outline  */
261   /*                  and give hints to the scan-converter and hinter on   */
262   /*                  how to convert/grid-fit it.  See FT_Outline_Flags.   */
263   /*                                                                       */
264   typedef struct  FT_Outline_
265   {
266     short       n_contours;      /* number of contours in glyph        */
267     short       n_points;        /* number of points in the glyph      */
268
269     FT_Vector*  points;          /* the outline's points               */
270     char*       tags;            /* the points flags                   */
271     short*      contours;        /* the contour end points             */
272
273     int         flags;           /* outline masks                      */
274
275   } FT_Outline;
276
277
278   /*************************************************************************/
279   /*                                                                       */
280   /* <Enum>                                                                */
281   /*   FT_Outline_Flags                                                    */
282   /*                                                                       */
283   /* <Description>                                                         */
284   /*    A simple type used to enumerates the flags in an outline's         */
285   /*    `outline_flags' field.                                             */
286   /*                                                                       */
287   /* <Fields>                                                              */
288   /*    ft_outline_owner          :: If set, this flag indicates that the  */
289   /*                                 outline's field arrays (i.e.          */
290   /*                                 `points', `flags' & `contours') are   */
291   /*                                 `owned' by the outline object, and    */
292   /*                                 should thus be freed when it is       */
293   /*                                 destroyed.                            */
294   /*                                                                       */
295   /*   ft_outline_even_odd_fill   :: By default, outlines are filled using */
296   /*                                 the non-zero winding rule.  If set to */
297   /*                                 1, the outline will be filled using   */
298   /*                                 the even-odd fill rule (only works    */
299   /*                                 with the smooth raster).              */
300   /*                                                                       */
301   /*   ft_outline_reverse_fill    :: By default, outside contours of an    */
302   /*                                 outline are oriented in clock-wise    */
303   /*                                 direction, as defined in the TrueType */
304   /*                                 specification.  This flag is set if   */
305   /*                                 the outline uses the opposite         */
306   /*                                 direction (typically for Type 1       */
307   /*                                 fonts).  This flag is ignored by the  */
308   /*                                 scan-converter.  However, it is very  */
309   /*                                 important for the auto-hinter.        */
310   /*                                                                       */
311   /*   ft_outline_ignore_dropouts :: By default, the scan converter will   */
312   /*                                 try to detect drop-outs in an outline */
313   /*                                 and correct the glyph bitmap to       */
314   /*                                 ensure consistent shape continuity.   */
315   /*                                 If set, this flag hints the scan-line */
316   /*                                 converter to ignore such cases.       */
317   /*                                                                       */
318   /*   ft_outline_high_precision  :: This flag indicates that the          */
319   /*                                 scan-line converter should try to     */
320   /*                                 convert this outline to bitmaps with  */
321   /*                                 the highest possible quality.  It is  */
322   /*                                 typically set for small character     */
323   /*                                 sizes.  Note that this is only a      */
324   /*                                 hint, that might be completely        */
325   /*                                 ignored by a given scan-converter.    */
326   /*                                                                       */
327   /*   ft_outline_single_pass     :: This flag is set to force a given     */
328   /*                                 scan-converter to only use a single   */
329   /*                                 pass over the outline to render a     */
330   /*                                 bitmap glyph image.  Normally, it is  */
331   /*                                 set for very large character sizes.   */
332   /*                                 It is only a hint, that might be      */
333   /*                                 completely ignored by a given         */
334   /*                                 scan-converter.                       */
335   /*                                                                       */
336   typedef enum  FT_Outline_Flags_
337   {
338     ft_outline_none            = 0,
339     ft_outline_owner           = 1,
340     ft_outline_even_odd_fill   = 2,
341     ft_outline_reverse_fill    = 4,
342     ft_outline_ignore_dropouts = 8,
343     ft_outline_high_precision  = 256,
344     ft_outline_single_pass     = 512
345
346   } FT_Outline_Flags;
347
348
349 #define FT_CURVE_TAG( flag )  ( flag & 3 )
350
351 #define FT_Curve_Tag_On           1
352 #define FT_Curve_Tag_Conic        0
353 #define FT_Curve_Tag_Cubic        2
354
355 #define FT_Curve_Tag_Touch_X      8  /* reserved for the TrueType hinter */
356 #define FT_Curve_Tag_Touch_Y     16  /* reserved for the TrueType hinter */
357
358 #define FT_Curve_Tag_Touch_Both  ( FT_Curve_Tag_Touch_X | \
359                                    FT_Curve_Tag_Touch_Y )
360
361
362   /*************************************************************************/
363   /*                                                                       */
364   /* <FuncType>                                                            */
365   /*    FT_Outline_MoveTo_Func                                             */
366   /*                                                                       */
367   /* <Description>                                                         */
368   /*    A function pointer type used to describe the signature of a `move  */
369   /*    to' function during outline walking/decomposition.                 */
370   /*                                                                       */
371   /*    A `move to' is emitted to start a new contour in an outline.       */
372   /*                                                                       */
373   /* <Input>                                                               */
374   /*    to   :: A pointer to the target point of the `move to'.            */
375   /*                                                                       */
376   /*    user :: A typeless pointer which is passed from the caller of the  */
377   /*            decomposition function.                                    */
378   /*                                                                       */
379   /* <Return>                                                              */
380   /*    Error code.  0 means success.                                      */
381   /*                                                                       */
382   typedef int  (*FT_Outline_MoveTo_Func)( FT_Vector*  to,
383                                           void*       user );
384
385
386   /*************************************************************************/
387   /*                                                                       */
388   /* <FuncType>                                                            */
389   /*    FT_Outline_LineTo_Func                                             */
390   /*                                                                       */
391   /* <Description>                                                         */
392   /*    A function pointer type used to describe the signature of a `line  */
393   /*    to' function during outline walking/decomposition.                 */
394   /*                                                                       */
395   /*    A `line to' is emitted to indicate a segment in the outline.       */
396   /*                                                                       */
397   /* <Input>                                                               */
398   /*    to   :: A pointer to the target point of the `line to'.            */
399   /*                                                                       */
400   /*    user :: A typeless pointer which is passed from the caller of the  */
401   /*            decomposition function.                                    */
402   /*                                                                       */
403   /* <Return>                                                              */
404   /*    Error code.  0 means success.                                      */
405   /*                                                                       */
406   typedef int  (*FT_Outline_LineTo_Func)( FT_Vector*  to,
407                                           void*       user );
408
409
410   /*************************************************************************/
411   /*                                                                       */
412   /* <FuncType>                                                            */
413   /*    FT_Outline_ConicTo_Func                                            */
414   /*                                                                       */
415   /* <Description>                                                         */
416   /*    A function pointer type use to describe the signature of a `conic  */
417   /*    to' function during outline walking/decomposition.                 */
418   /*                                                                       */
419   /*    A `conic to' is emitted to indicate a second-order Bezier arc in   */
420   /*    the outline.                                                       */
421   /*                                                                       */
422   /* <Input>                                                               */
423   /*    control :: An intermediate control point between the last position */
424   /*               and the new target in `to'.                             */
425   /*                                                                       */
426   /*    to      :: A pointer to the target end point of the conic arc.     */
427   /*                                                                       */
428   /*    user    :: A typeless pointer which is passed from the caller of   */
429   /*               the decomposition function.                             */
430   /*                                                                       */
431   /* <Return>                                                              */
432   /*    Error code.  0 means success.                                      */
433   /*                                                                       */
434   typedef int  (*FT_Outline_ConicTo_Func)( FT_Vector*  control,
435                                            FT_Vector*  to,
436                                            void*       user );
437
438
439   /*************************************************************************/
440   /*                                                                       */
441   /* <FuncType>                                                            */
442   /*    FT_Outline_CubicTo_Func                                            */
443   /*                                                                       */
444   /* <Description>                                                         */
445   /*    A function pointer type used to describe the signature of a `cubic */
446   /*    to' function during outline walking/decomposition.                 */
447   /*                                                                       */
448   /*    A `cubic to' is emitted to indicate a third-order Bezier arc.      */
449   /*                                                                       */
450   /* <Input>                                                               */
451   /*    control1 :: A pointer to the first Bezier control point.           */
452   /*                                                                       */
453   /*    control2 :: A pointer to the second Bezier control point.          */
454   /*                                                                       */
455   /*    to       :: A pointer to the target end point.                     */
456   /*                                                                       */
457   /*    user     :: A typeless pointer which is passed from the caller of  */
458   /*                the decomposition function.                            */
459   /*                                                                       */
460   /* <Return>                                                              */
461   /*    Error code.  0 means success.                                      */
462   /*                                                                       */
463   typedef int  (*FT_Outline_CubicTo_Func)( FT_Vector*  control1,
464                                            FT_Vector*  control2,
465                                            FT_Vector*  to,
466                                            void*       user );
467
468
469   /*************************************************************************/
470   /*                                                                       */
471   /* <Struct>                                                              */
472   /*    FT_Outline_Funcs                                                   */
473   /*                                                                       */
474   /* <Description>                                                         */
475   /*    A structure to hold various function pointers used during outline  */
476   /*    decomposition in order to emit segments, conic, and cubic Beziers, */
477   /*    as well as `move to' and `close to' operations.                    */
478   /*                                                                       */
479   /* <Fields>                                                              */
480   /*    move_to  :: The `move to' emitter.                                 */
481   /*                                                                       */
482   /*    line_to  :: The segment emitter.                                   */
483   /*                                                                       */
484   /*    conic_to :: The second-order Bezier arc emitter.                   */
485   /*                                                                       */
486   /*    cubic_to :: The third-order Bezier arc emitter.                    */
487   /*                                                                       */
488   /*    shift    :: The shift that is applied to coordinates before they   */
489   /*                are sent to the emitter.                               */
490   /*                                                                       */
491   /*    delta    :: The delta that is applied to coordinates before they   */
492   /*                are sent to the emitter, but after the shift.          */
493   /*                                                                       */
494   /* <Note>                                                                */
495   /*    The point coordinates sent to the emitters are the transformed     */
496   /*    version of the original coordinates (this is important for high    */
497   /*    accuracy during scan-conversion).  The transformation is simple:   */
498   /*                                                                       */
499   /*      x' = (x << shift) - delta                                        */
500   /*      y' = (x << shift) - delta                                        */
501   /*                                                                       */
502   /*    Set the value of `shift' and `delta' to 0 to get the original      */
503   /*    point coordinates.                                                 */
504   /*                                                                       */
505   typedef struct  FT_Outline_Funcs_
506   {
507     FT_Outline_MoveTo_Func   move_to;
508     FT_Outline_LineTo_Func   line_to;
509     FT_Outline_ConicTo_Func  conic_to;
510     FT_Outline_CubicTo_Func  cubic_to;
511
512     int                      shift;
513     FT_Pos                   delta;
514
515   } FT_Outline_Funcs;
516
517
518   /*************************************************************************/
519   /*                                                                       */
520   /* <Macro>                                                               */
521   /*    FT_IMAGE_TAG                                                       */
522   /*                                                                       */
523   /* <Description>                                                         */
524   /*    This macro converts four letter tags into an unsigned long.        */
525   /*                                                                       */
526 #define FT_IMAGE_TAG( _x1, _x2, _x3, _x4 ) \
527           ( ( (unsigned long)_x1 << 24 ) | \
528             ( (unsigned long)_x2 << 16 ) | \
529             ( (unsigned long)_x3 << 8  ) | \
530               (unsigned long)_x4         )
531
532
533   /*************************************************************************/
534   /*                                                                       */
535   /* <Enum>                                                                */
536   /*    FT_Glyph_Format                                                    */
537   /*                                                                       */
538   /* <Description>                                                         */
539   /*    An enumeration type used to describe the format of a given glyph   */
540   /*    image.  Note that this version of FreeType only supports two image */
541   /*    formats, even though future font drivers will be able to register  */
542   /*    their own format.                                                  */
543   /*                                                                       */
544   /* <Fields>                                                              */
545   /*    ft_glyph_format_composite :: The glyph image is a composite of     */
546   /*                                 several other images.  This glyph     */
547   /*                                 format is _only_ used with the        */
548   /*                                 FT_LOAD_FLAG_NO_RECURSE flag (XXX:    */
549   /*                                 Which is currently unimplemented).    */
550   /*                                                                       */
551   /*    ft_glyph_format_bitmap    :: The glyph image is a bitmap, and can  */
552   /*                                 be described as a FT_Bitmap.          */
553   /*                                                                       */
554   /*    ft_glyph_format_outline   :: The glyph image is a vectorial image  */
555   /*                                 made of bezier control points, and    */
556   /*                                 can be described as a FT_Outline.     */
557   /*                                                                       */
558   /*    ft_glyph_format_plotter   :: The glyph image is a vectorial image  */
559   /*                                 made of plotter lines (some T1 fonts  */
560   /*                                 like Hershey contain glyph in this    */
561   /*                                 format).                              */
562   /*                                                                       */
563   typedef enum  FT_Glyph_Format_
564   {
565     ft_glyph_format_none      = 0,
566     ft_glyph_format_composite = FT_IMAGE_TAG( 'c', 'o', 'm', 'p' ),
567     ft_glyph_format_bitmap    = FT_IMAGE_TAG( 'b', 'i', 't', 's' ),
568     ft_glyph_format_outline   = FT_IMAGE_TAG( 'o', 'u', 't', 'l' ),
569     ft_glyph_format_plotter   = FT_IMAGE_TAG( 'p', 'l', 'o', 't' )
570
571   } FT_Glyph_Format;
572
573
574   /*************************************************************************/
575   /*************************************************************************/
576   /*************************************************************************/
577   /*****                                                               *****/
578   /*****            R A S T E R   D E F I N I T I O N S                *****/
579   /*****                                                               *****/
580   /*************************************************************************/
581   /*************************************************************************/
582   /*************************************************************************/
583
584
585   /*************************************************************************/
586   /*                                                                       */
587   /* A raster is a scan converter, in charge of rendering an outline into  */
588   /* a a bitmap.  This section contains the public API for rasters.        */
589   /*                                                                       */
590   /* Note that in FreeType 2, all rasters are now encapsulated within      */
591   /* specific modules called `renderers'.  See `freetype/ftrender.h' for   */
592   /* more details on renderers.                                            */
593   /*                                                                       */
594   /*************************************************************************/
595
596
597   /*************************************************************************/
598   /*                                                                       */
599   /* <Type>                                                                */
600   /*    FT_Raster                                                          */
601   /*                                                                       */
602   /* <Description>                                                         */
603   /*    A handle (pointer) to a raster object.  Each object can be used    */
604   /*    independently to convert an outline into a bitmap or pixmap.       */
605   /*                                                                       */
606   typedef struct FT_RasterRec_*  FT_Raster;
607
608
609   /*************************************************************************/
610   /*                                                                       */
611   /* <Struct>                                                              */
612   /*    FT_Span                                                            */
613   /*                                                                       */
614   /* <Description>                                                         */
615   /*    A structure used to model a single span of gray (or black) pixels  */
616   /*    when rendering a monochrome or anti-aliased bitmap.                */
617   /*                                                                       */
618   /* <Fields>                                                              */
619   /*    x        :: The span's horizontal start position.                  */
620   /*                                                                       */
621   /*    len      :: The span's length in pixels.                           */
622   /*                                                                       */
623   /*    coverage :: The span color/coverage, ranging from 0 (background)   */
624   /*                to 255 (foreground).  Only used for anti-aliased       */
625   /*                rendering.                                             */
626   /*                                                                       */
627   /* <Note>                                                                */
628   /*    This structure is used by the span drawing callback type named     */
629   /*    FT_Raster_Span_Func(), which takes the y-coordinate of the span as */
630   /*    a parameter.                                                       */
631   /*                                                                       */
632   /*    The coverage value is always between 0 and 255, even if the number */
633   /*    of gray levels have been set through FT_Set_Gray_Levels().         */
634   /*                                                                       */
635   typedef struct  FT_Span_
636   {
637     short          x;
638     unsigned short len;
639     unsigned char  coverage;
640
641   } FT_Span;
642
643
644   /*************************************************************************/
645   /*                                                                       */
646   /* <FuncType>                                                            */
647   /*    FT_Raster_Span_Func                                                */
648   /*                                                                       */
649   /* <Description>                                                         */
650   /*    A function used as a call-back by the anti-aliased renderer in     */
651   /*    order to let client applications draw themselves the gray pixel    */
652   /*    spans on each scan line.                                           */
653   /*                                                                       */
654   /* <Input>                                                               */
655   /*    y     :: The scanline's y-coordinate.                              */
656   /*                                                                       */
657   /*    count :: The number of spans to draw on this scanline.             */
658   /*                                                                       */
659   /*    spans :: A table of `count' spans to draw on the scanline.         */
660   /*                                                                       */
661   /*    user  :: User-supplied data that is passed to the callback.        */
662   /*                                                                       */
663   /* <Note>                                                                */
664   /*    This callback allows client applications to directly render the    */
665   /*    gray spans of the anti-aliased bitmap to any kind of surfaces.     */
666   /*                                                                       */
667   /*    This can be used to write anti-aliased outlines directly to a      */
668   /*    given background bitmap, and even perform translucency.            */
669   /*                                                                       */
670   /*    Note that the `count' field cannot be greater than a fixed value   */
671   /*    defined by the FT_MAX_GRAY_SPANS configuration macro in            */
672   /*    ftoption.h.  By default, this value is set to 32, which means that */
673   /*    if there are more than 32 spans on a given scanline, the callback  */
674   /*    will be called several times with the same `y' parameter in order  */
675   /*    to draw all callbacks.                                             */
676   /*                                                                       */
677   /*    Otherwise, the callback is only called once per scan-line, and     */
678   /*    only for those scanlines that do have `gray' pixels on them.       */
679   /*                                                                       */
680   typedef void  (*FT_Raster_Span_Func)( int       y,
681                                         int       count,
682                                         FT_Span*  spans,
683                                         void*     user );
684
685
686   /*************************************************************************/
687   /*                                                                       */
688   /* <FuncType>                                                            */
689   /*    FT_Raster_BitTest_Func                                             */
690   /*                                                                       */
691   /* <Description>                                                         */
692   /*    A function used as a call-back by the monochrome scan-converter    */
693   /*    to test whether a given target pixel is already set to the drawing */
694   /*    `color'.  These tests are crucial to implement drop-out control    */
695   /*    per-se the TrueType spec.                                          */
696   /*                                                                       */
697   /* <Input>                                                               */
698   /*    y     :: The pixel's y-coordinate.                                 */
699   /*                                                                       */
700   /*    x     :: The pixel's x-coordinate.                                 */
701   /*                                                                       */
702   /*    user  :: User-supplied data that is passed to the callback.        */
703   /*                                                                       */
704   /* <Return>                                                              */
705   /*   1 if the pixel is `set', 0 otherwise.                               */
706   /*                                                                       */
707   typedef int  (*FT_Raster_BitTest_Func)( int    y,
708                                           int    x,
709                                           void*  user );
710
711
712   /*************************************************************************/
713   /*                                                                       */
714   /* <FuncType>                                                            */
715   /*    FT_Raster_BitSet_Func                                              */
716   /*                                                                       */
717   /* <Description>                                                         */
718   /*    A function used as a call-back by the monochrome scan-converter    */
719   /*    to set an individual target pixel.  This is crucial to implement   */
720   /*    drop-out control according to the TrueType specification.          */
721   /*                                                                       */
722   /* <Input>                                                               */
723   /*    y     :: The pixel's y-coordinate.                                 */
724   /*                                                                       */
725   /*    x     :: The pixel's x-coordinate.                                 */
726   /*                                                                       */
727   /*    user  :: User-supplied data that is passed to the callback.        */
728   /*                                                                       */
729   /* <Return>                                                              */
730   /*    1 if the pixel is `set', 0 otherwise.                              */
731   /*                                                                       */
732   typedef void  (*FT_Raster_BitSet_Func)( int    y,
733                                           int    x,
734                                           void*  user );
735
736
737   /*************************************************************************/
738   /*                                                                       */
739   /* <Enum>                                                                */
740   /*    FT_Raster_Flag                                                     */
741   /*                                                                       */
742   /* <Description>                                                         */
743   /*    An enumeration to list the bit flags as used in the `flags' field  */
744   /*    of a FT_Raster_Params structure.                                   */
745   /*                                                                       */
746   /* <Fields>                                                              */
747   /*    ft_raster_flag_default :: This value is 0.                         */
748   /*                                                                       */
749   /*    ft_raster_flag_aa      :: Requests the rendering of an             */
750   /*                              anti-aliased glyph bitmap.  If unset, a  */
751   /*                              monchrome bitmap will be rendered.       */
752   /*                                                                       */
753   /*    ft_raster_flag_direct  :: Requests direct rendering over the       */
754   /*                              target bitmap.  Direct rendering uses    */
755   /*                              user-provided callbacks in order to      */
756   /*                              perform direct drawing or composition    */
757   /*                              over an existing bitmap.  If this bit is */
758   /*                              unset, the content of the target bitmap  */
759   /*                              *must be zeroed*!                        */
760   /*                                                                       */
761   typedef  enum
762   {
763     ft_raster_flag_default = 0,
764     ft_raster_flag_aa      = 1,
765     ft_raster_flag_direct  = 2
766
767   } FT_Raster_Flag;
768
769
770   /*************************************************************************/
771   /*                                                                       */
772   /* <Struct>                                                              */
773   /*    FT_Raster_Params                                                   */
774   /*                                                                       */
775   /* <Description>                                                         */
776   /*    A structure to hold the arguments used by a raster's render        */
777   /*    function.                                                          */
778   /*                                                                       */
779   /* <Fields>                                                              */
780   /*    target      :: The target bitmap.                                  */
781   /*                                                                       */
782   /*    source      :: A pointer to the source glyph image (e.g. an        */
783   /*                   FT_Outline).                                        */
784   /*                                                                       */
785   /*    flags       :: The rendering flags.                                */
786   /*                                                                       */
787   /*    gray_spans  :: The gray span drawing callback.                     */
788   /*                                                                       */
789   /*    black_spans :: The black span drawing callback.                    */
790   /*                                                                       */
791   /*    bit_test    :: The bit test callback.                              */
792   /*                                                                       */
793   /*    bit_set     :: The bit set callback.                               */
794   /*                                                                       */
795   /*    user        :: User-supplied data that is passed to each drawing   */
796   /*                   callback.                                           */
797   /*                                                                       */
798   /* <Note>                                                                */
799   /*    An anti-aliased glyph bitmap is drawn if the ft_raster_flag_aa bit */
800   /*    flag is set in the `flags' field, otherwise a monochrome bitmap    */
801   /*    will be generated.                                                 */
802   /*                                                                       */
803   /*    If the ft_raster_flag_direct bit flag is set in `flags', the       */
804   /*    raster will call the `gray_spans' callback to draw gray pixel      */
805   /*    spans, in the case of an aa glyph bitmap, it will call             */
806   /*    `black_spans', and `bit_test' and `bit_set' in the case of a       */
807   /*    monochrome bitmap.  This allows direct composition over a          */
808   /*    pre-existing bitmap through user-provided callbacks to perform the */
809   /*    span drawing/composition.                                          */
810   /*                                                                       */
811   /*    Note that the `bit_test' and `bit_set' callbacks are required when */
812   /*    rendering a monochrome bitmap, as they are crucial to implement    */
813   /*    correct drop-out control as defined in the TrueType specification. */
814   /*                                                                       */
815   typedef struct  FT_Raster_Params_
816   {
817     FT_Bitmap*              target;
818     void*                   source;
819     int                     flags;
820     FT_Raster_Span_Func     gray_spans;
821     FT_Raster_Span_Func     black_spans;
822     FT_Raster_BitTest_Func  bit_test;
823     FT_Raster_BitSet_Func   bit_set;
824     void*                   user;
825
826   } FT_Raster_Params;
827
828
829   /*************************************************************************/
830   /*                                                                       */
831   /* <FuncType>                                                            */
832   /*    FT_Raster_New_Func                                                 */
833   /*                                                                       */
834   /* <Description>                                                         */
835   /*    A function used to create a new raster object.                     */
836   /*                                                                       */
837   /* <Input>                                                               */
838   /*    memory :: A handle to the memory allocator.                        */
839   /*                                                                       */
840   /* <Output>                                                              */
841   /*    raster :: A handle to the new raster object.                       */
842   /*                                                                       */
843   /* <Return>                                                              */
844   /*    Error code.  0 means success.                                      */
845   /*                                                                       */
846   /* <Note>                                                                */
847   /*    The `memory' parameter is a typeless pointer in order to avoid     */
848   /*    un-wanted dependencies on the rest of the FreeType code.  In       */
849   /*    practice, it is a FT_Memory, i.e., a handle to the standard        */
850   /*    FreeType memory allocator.  However, this field can be completely  */
851   /*    ignored by a given raster implementation.                          */
852   /*                                                                       */
853   typedef int  (*FT_Raster_New_Func)( void*       memory,
854                                       FT_Raster*  raster );
855
856
857   /*************************************************************************/
858   /*                                                                       */
859   /* <FuncType>                                                            */
860   /*    FT_Raster_Done_Func                                                */
861   /*                                                                       */
862   /* <Description>                                                         */
863   /*    A function used to destroy a given raster object.                  */
864   /*                                                                       */
865   /* <Input>                                                               */
866   /*    raster :: A handle to the raster object.                           */
867   /*                                                                       */
868   typedef void  (*FT_Raster_Done_Func)( FT_Raster  raster );
869
870
871   /*************************************************************************/
872   /*                                                                       */
873   /* <FuncType>                                                            */
874   /*    FT_Raster_Reset_Func                                               */
875   /*                                                                       */
876   /* <Description>                                                         */
877   /*    FreeType provides an area of memory called the `render pool',      */
878   /*    available to all registered rasters.  This pool can be freely used */
879   /*    during a given scan-conversion but is shared by all rasters.  Its  */
880   /*    content is thus transient.                                         */
881   /*                                                                       */
882   /*    This function is called each time the render pool changes, or just */
883   /*    after a new raster object is created.                              */
884   /*                                                                       */
885   /* <Input>                                                               */
886   /*    raster    :: A handle to the new raster object.                    */
887   /*                                                                       */
888   /*    pool_base :: The address in memory of the render pool.             */
889   /*                                                                       */
890   /*    pool_size :: The size in bytes of the render pool.                 */
891   /*                                                                       */
892   /* <Note>                                                                */
893   /*    Rasters can ignore the render pool and rely on dynamic memory      */
894   /*    allocation if they want to (a handle to the memory allocator is    */
895   /*    passed to the raster constructor).  However, this is not           */
896   /*    recommended for efficiency purposes.                               */
897   /*                                                                       */
898   typedef void  (*FT_Raster_Reset_Func)( FT_Raster       raster,
899                                          unsigned char*  pool_base,
900                                          unsigned long   pool_size );
901
902
903   /*************************************************************************/
904   /*                                                                       */
905   /* <FuncType>                                                            */
906   /*    FT_Raster_Set_Mode_Func                                            */
907   /*                                                                       */
908   /* <Description>                                                         */
909   /*    This function is a generic facility to change modes or attributes  */
910   /*    in a given raster.  This can be used for debugging purposes, or    */
911   /*    simply to allow implementation-specific `features' in a given      */
912   /*    raster module.                                                     */
913   /*                                                                       */
914   /* <Input>                                                               */
915   /*    raster :: A handle to the new raster object.                       */
916   /*                                                                       */
917   /*    mode   :: A 4-byte tag used to name the mode or property.          */
918   /*                                                                       */
919   /*    args   :: A pointer to the new mode/property to use.               */
920   /*                                                                       */
921   typedef int  (*FT_Raster_Set_Mode_Func)( FT_Raster      raster,
922                                            unsigned long  mode,
923                                            void*          args );
924
925
926   /*************************************************************************/
927   /*                                                                       */
928   /* <FuncType>                                                            */
929   /*    FT_Raster_Render_Func                                              */
930   /*                                                                       */
931   /* <Description>                                                         */
932   /*   Invokes a given raster to scan-convert a given glyph image into a   */
933   /*   target bitmap.                                                      */
934   /*                                                                       */
935   /* <Input>                                                               */
936   /*    raster :: A handle to the raster object.                           */
937   /*                                                                       */
938   /*    params :: A pointer to a FT_Raster_Params structure used to store  */
939   /*              the rendering parameters.                                */
940   /*                                                                       */
941   /* <Return>                                                              */
942   /*    Error code.  0 means success.                                      */
943   /*                                                                       */
944   /* <Note>                                                                */
945   /*    The exact format of the source image depends on the raster's glyph */
946   /*    format defined in its FT_Raster_Funcs structure.  It can be an     */
947   /*    FT_Outline or anything else in order to support a large array of   */
948   /*    glyph formats.                                                     */
949   /*                                                                       */
950   /*    Note also that the render function can fail and return a           */
951   /*    FT_Err_Unimplemented_Feature error code if the raster used does    */
952   /*    not support direct composition.                                    */
953   /*                                                                       */
954   /*    XXX: For now, the standard raster doesn't support direct           */
955   /*         composition but this should change for the final release (see */
956   /*         the files demos/src/ftgrays.c and demos/src/ftgrays2.c for    */
957   /*         examples of distinct implementations which support direct     */
958   /*         composition).                                                 */
959   /*                                                                       */
960   typedef int  (*FT_Raster_Render_Func)( FT_Raster          raster,
961                                          FT_Raster_Params*  params );
962
963
964   /*************************************************************************/
965   /*                                                                       */
966   /* <Struct>                                                              */
967   /*    FT_Raster_Funcs                                                    */
968   /*                                                                       */
969   /* <Description>                                                         */
970   /*   A structure used to describe a given raster class to the library.   */
971   /*                                                                       */
972   /* <Fields>                                                              */
973   /*    glyph_format  :: The supported glyph format for this raster.       */
974   /*                                                                       */
975   /*    raster_new    :: The raster constructor.                           */
976   /*                                                                       */
977   /*    raster_reset  :: Used to reset the render pool within the raster.  */
978   /*                                                                       */
979   /*    raster_render :: A function to render a glyph into a given bitmap. */
980   /*                                                                       */
981   /*    raster_done   :: The raster destructor.                            */
982   /*                                                                       */
983   typedef struct  FT_Raster_Funcs_
984   {
985     FT_Glyph_Format          glyph_format;
986     FT_Raster_New_Func       raster_new;
987     FT_Raster_Reset_Func     raster_reset;
988     FT_Raster_Set_Mode_Func  raster_set_mode;
989     FT_Raster_Render_Func    raster_render;
990     FT_Raster_Done_Func      raster_done;
991
992   } FT_Raster_Funcs;
993
994
995 #ifdef __cplusplus
996   }
997 #endif
998
999
1000 #endif /* FTIMAGE_H */
1001
1002
1003 /* END */