1 /***************************************************************************/
5 /* FreeType convenience functions to handle glyphs (specification). */
7 /* Copyright 1996-2000 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
19 /*************************************************************************/
21 /* This file contains the definition of several convenience functions */
22 /* that can be used by client applications to easily retrieve glyph */
23 /* bitmaps and outlines from a given face. */
25 /* These functions should be optional if you are writing a font server */
26 /* or text layout engine on top of FreeType. However, they are pretty */
27 /* handy for many other simple uses of the library. */
29 /*************************************************************************/
35 #include <freetype/freetype.h>
41 /* forward declaration to a private type */
42 typedef struct FT_Glyph_Class_ FT_Glyph_Class
;
45 /*************************************************************************/
51 /* The root glyph structure contains a given glyph image plus its */
52 /* advance width in 16.16 fixed float format. */
55 /* library :: A handle to the FreeType library object. */
57 /* clazz :: A pointer to the glyph's class. Private. */
59 /* format :: The format of the glyph's image. */
61 /* advance :: A 16.16 vector that gives the glyph's advance width. */
63 typedef struct FT_GlyphRec_
66 const FT_Glyph_Class
* clazz
;
67 FT_Glyph_Format format
;
70 } FT_GlyphRec
, *FT_Glyph
;
73 /*************************************************************************/
76 /* FT_BitmapGlyphRec */
79 /* A structure used for bitmap glyph images. This really is a */
80 /* `sub-class' of `FT_GlyphRec'. */
83 /* root :: The root FT_Glyph fields. */
85 /* left :: The left-side bearing, i.e., the horizontal distance */
86 /* from the current pen position to the left border of the */
89 /* top :: The top-side bearing, i.e., the vertical distance from */
90 /* the current pen position to the top border of the glyph */
91 /* bitmap. This distance is positive for upwards-y! */
93 /* bitmap :: A descriptor for the bitmap. */
96 /* You can typecast FT_Glyph to FT_BitmapGlyph if you have */
97 /* glyph->format == ft_glyph_format_bitmap. This lets you access */
98 /* the bitmap's contents easily. */
100 /* The corresponding pixel buffer is always owned by the BitmapGlyph */
101 /* and is thus created and destroyed with it. */
103 typedef struct FT_BitmapGlyphRec_
110 } FT_BitmapGlyphRec
, *FT_BitmapGlyph
;
113 /*************************************************************************/
116 /* FT_OutlineGlyphRec */
119 /* A structure used for outline (vectorial) glyph images. This */
120 /* really is a `sub-class' of `FT_GlyphRec'. */
123 /* root :: The root FT_Glyph fields. */
125 /* outline :: A descriptor for the outline. */
128 /* You can typecast FT_Glyph to FT_OutlineGlyph if you have */
129 /* glyph->format == ft_glyph_format_outline. This lets you access */
130 /* the outline's content easily. */
132 /* As the outline is extracted from a glyph slot, its coordinates are */
133 /* expressed normally in 26.6 pixels, unless the flag */
134 /* FT_LOAD_NO_SCALE was used in FT_Load_Glyph() or FT_Load_Char(). */
136 /* The outline's tables are always owned by the object and are */
137 /* destroyed with it. */
139 typedef struct FT_OutlineGlyphRec_
144 } FT_OutlineGlyphRec
, *FT_OutlineGlyph
;
147 /*************************************************************************/
153 /* A function used to extract a glyph image from a slot. */
156 /* slot :: A handle to the source glyph slot. */
159 /* aglyph :: A handle to the glyph object. */
162 /* FreeType error code. 0 means success. */
164 FT_EXPORT_DEF( FT_Error
) FT_Get_Glyph( FT_GlyphSlot slot
,
168 /*************************************************************************/
174 /* A function used to copy a glyph image. */
177 /* source :: A handle to the source glyph object. */
180 /* target :: A handle to the target glyph object. 0 in case of */
184 /* FreeType error code. 0 means success. */
186 FT_EXPORT_DEF( FT_Error
) FT_Glyph_Copy( FT_Glyph source
,
190 /*************************************************************************/
193 /* FT_Glyph_Transform */
196 /* Transforms a glyph image if its format is scalable. */
199 /* glyph :: A handle to the target glyph object. */
201 /* matrix :: A pointer to a 2x2 matrix to apply. */
203 /* delta :: A pointer to a 2d vector to apply. Coordinates are */
204 /* expressed in 1/64th of a pixel. */
207 /* FreeType error code (the glyph format is not scalable if it is */
211 /* The 2x2 transformation matrix is also applied to the glyph's */
212 /* advance vector. */
214 FT_EXPORT_DEF( FT_Error
) FT_Glyph_Transform( FT_Glyph glyph
,
221 ft_glyph_bbox_pixels
= 0,
222 ft_glyph_bbox_subpixels
= 1,
223 ft_glyph_bbox_gridfit
= 2
227 /*************************************************************************/
230 /* FT_Glyph_Get_CBox */
233 /* Returns the glyph image's bounding box. */
236 /* glyph :: A handle to the source glyph object. */
238 /* mode :: A set of bit flags that indicate how to interpret the */
239 /* returned bounding box values. */
242 /* box :: The glyph bounding box. Coordinates are expressed in */
243 /* 1/64th of pixels if it is grid-fitted. */
246 /* Coordinates are relative to the glyph origin, using the Y-upwards */
249 /* If `ft_glyph_bbox_subpixels' is set in `mode', the bbox */
250 /* coordinates are returned in 26.6 pixels (i.e. 1/64th of pixels). */
251 /* Otherwise, coordinates are expressed in integer pixels. */
253 /* Note that the maximum coordinates are exclusive, which means that */
254 /* one can compute the width and height of the glyph image (be it in */
255 /* integer or 26.6 pixels) as: */
257 /* width = bbox.xMax - bbox.xMin; */
258 /* height = bbox.yMax - bbox.yMin; */
260 /* Note also that for 26.6 coordinates, if the */
261 /* `ft_glyph_bbox_gridfit' flag is set in `mode;, the coordinates */
262 /* will also be grid-fitted, which corresponds to: */
264 /* bbox.xMin = FLOOR(bbox.xMin); */
265 /* bbox.yMin = FLOOR(bbox.yMin); */
266 /* bbox.xMax = CEILING(bbox.xMax); */
267 /* bbox.yMax = CEILING(bbox.yMax); */
269 /* The default value (0) for `bbox_mode' is `ft_glyph_bbox_pixels'. */
271 FT_EXPORT_DEF( void ) FT_Glyph_Get_CBox( FT_Glyph glyph
,
276 /*************************************************************************/
279 /* FT_Glyph_To_Bitmap */
282 /* Converts a given glyph object to a bitmap glyph object. */
285 /* glyph :: A pointer to a handle to the target glyph. */
288 /* render_mode :: A set of bit flags that describe how the data is */
291 /* origin :: A pointer to a vector used to translate the glyph */
292 /* image before rendering. Can be 0 (if no */
293 /* translation). The origin is expressed in */
296 /* destroy :: A boolean that indicates that the original glyph */
297 /* image should be destroyed by this function. It is */
298 /* never destroyed in case of error. */
301 /* FreeType error code. 0 means success. */
304 /* The glyph image is translated with the `origin' vector before */
305 /* rendering. In case of error, it it translated back to its */
306 /* original position and the glyph is left untouched. */
308 /* The first parameter is a pointer to a FT_Glyph handle, that will */
309 /* be replaced by this function. Typically, you would use (omitting */
310 /* error handling): */
314 /* FT_Glyph glyph; */
315 /* FT_BitmapGlyph glyph_bitmap; */
319 /* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); */
321 /* // extract glyph image */
322 /* error = FT_Get_Glyph( face->glyph, &glyph ); */
324 /* // convert to a bitmap (default render mode + destroy old) */
325 /* if ( glyph->format != ft_glyph_format_bitmap ) */
327 /* error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_default, */
329 /* if ( error ) // glyph unchanged */
333 /* // access bitmap content by typecasting */
334 /* glyph_bitmap = (FT_BitmapGlyph)glyph; */
336 /* // do funny stuff with it, like blitting/drawing */
339 /* // discard glyph image (bitmap or not) */
340 /* FT_Done_Glyph( glyph ); */
344 /* This function will always fail if the glyph's format isn't */
347 FT_EXPORT_DEF( FT_Error
) FT_Glyph_To_Bitmap( FT_Glyph
* the_glyph
,
348 FT_ULong render_mode
,
353 /*************************************************************************/
359 /* Destroys a given glyph. */
362 /* glyph :: A handle to the target glyph object. */
364 FT_EXPORT_DEF( void ) FT_Done_Glyph( FT_Glyph glyph
);
367 /* other helpful functions */
370 /*************************************************************************/
373 /* FT_Matrix_Multiply */
376 /* Performs the matrix operation `b = a*b'. */
379 /* a :: A pointer to matrix `a'. */
382 /* b :: A pointer to matrix `b'. */
388 /* The result is undefined if either `a' or `b' is zero. */
390 FT_EXPORT_DEF( void ) FT_Matrix_Multiply( FT_Matrix
* a
,
394 /*************************************************************************/
397 /* FT_Matrix_Invert */
400 /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
403 /* matrix :: A pointer to the target matrix. Remains untouched in */
407 /* FreeType error code. 0 means success. */
412 FT_EXPORT_DEF( FT_Error
) FT_Matrix_Invert( FT_Matrix
* matrix
);
419 #endif /* FTGLYPH_H */