1 /***************************************************************************/
5 /* FreeType convenience functions to handle glyphs (specification). */
7 /* Copyright 1996-2001 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 /*************************************************************************/
37 #include FT_FREETYPE_H
43 /*************************************************************************/
46 /* glyph_management */
49 /* Glyph Management */
52 /* Generic interface to manage individual glyph data. */
55 /* This section contains definitions used to manage glyph data */
56 /* through generic FT_Glyph objects. Each of them can contain a */
57 /* bitmap, a vector outline, or even images in other formats. */
59 /*************************************************************************/
62 /* forward declaration to a private type */
63 typedef struct FT_Glyph_Class_ FT_Glyph_Class;
66 /*************************************************************************/
72 /* The root glyph structure contains a given glyph image plus its */
73 /* advance width in 16.16 fixed float format. */
76 /* library :: A handle to the FreeType library object. */
78 /* clazz :: A pointer to the glyph's class. Private. */
80 /* format :: The format of the glyph's image. */
82 /* advance :: A 16.16 vector that gives the glyph's advance width. */
84 typedef struct FT_GlyphRec_
87 const FT_Glyph_Class* clazz;
88 FT_Glyph_Format format;
91 } FT_GlyphRec, *FT_Glyph;
94 /*************************************************************************/
97 /* FT_BitmapGlyphRec */
100 /* A structure used for bitmap glyph images. This really is a */
101 /* `sub-class' of `FT_GlyphRec'. */
104 /* root :: The root FT_Glyph fields. */
106 /* left :: The left-side bearing, i.e., the horizontal distance */
107 /* from the current pen position to the left border of the */
110 /* top :: The top-side bearing, i.e., the vertical distance from */
111 /* the current pen position to the top border of the glyph */
112 /* bitmap. This distance is positive for upwards-y! */
114 /* bitmap :: A descriptor for the bitmap. */
117 /* You can typecast FT_Glyph to FT_BitmapGlyph if you have */
118 /* glyph->format == ft_glyph_format_bitmap. This lets you access */
119 /* the bitmap's contents easily. */
121 /* The corresponding pixel buffer is always owned by the BitmapGlyph */
122 /* and is thus created and destroyed with it. */
124 typedef struct FT_BitmapGlyphRec_
131 } FT_BitmapGlyphRec, *FT_BitmapGlyph;
134 /*************************************************************************/
137 /* FT_OutlineGlyphRec */
140 /* A structure used for outline (vectorial) glyph images. This */
141 /* really is a `sub-class' of `FT_GlyphRec'. */
144 /* root :: The root FT_Glyph fields. */
146 /* outline :: A descriptor for the outline. */
149 /* You can typecast FT_Glyph to FT_OutlineGlyph if you have */
150 /* glyph->format == ft_glyph_format_outline. This lets you access */
151 /* the outline's content easily. */
153 /* As the outline is extracted from a glyph slot, its coordinates are */
154 /* expressed normally in 26.6 pixels, unless the flag */
155 /* FT_LOAD_NO_SCALE was used in FT_Load_Glyph() or FT_Load_Char(). */
157 /* The outline's tables are always owned by the object and are */
158 /* destroyed with it. */
160 typedef struct FT_OutlineGlyphRec_
165 } FT_OutlineGlyphRec, *FT_OutlineGlyph;
168 /*************************************************************************/
174 /* A function used to extract a glyph image from a slot. */
177 /* slot :: A handle to the source glyph slot. */
180 /* aglyph :: A handle to the glyph object. */
183 /* FreeType error code. 0 means success. */
185 FT_EXPORT( FT_Error )
186 FT_Get_Glyph( FT_GlyphSlot slot,
190 /*************************************************************************/
196 /* A function used to copy a glyph image. */
199 /* source :: A handle to the source glyph object. */
202 /* target :: A handle to the target glyph object. 0 in case of */
206 /* FreeType error code. 0 means success. */
208 FT_EXPORT( FT_Error )
209 FT_Glyph_Copy( FT_Glyph source,
213 /*************************************************************************/
216 /* FT_Glyph_Transform */
219 /* Transforms a glyph image if its format is scalable. */
222 /* glyph :: A handle to the target glyph object. */
225 /* matrix :: A pointer to a 2x2 matrix to apply. */
227 /* delta :: A pointer to a 2d vector to apply. Coordinates are */
228 /* expressed in 1/64th of a pixel. */
231 /* FreeType error code (the glyph format is not scalable if it is */
235 /* The 2x2 transformation matrix is also applied to the glyph's */
236 /* advance vector. */
238 FT_EXPORT( FT_Error )
239 FT_Glyph_Transform( FT_Glyph glyph,
245 /*************************************************************************/
248 /* FT_Glyph_Get_CBox */
251 /* Returns a glyph's `control box'. The control box encloses all the */
252 /* outline's points, including Bezier control points. Though it */
253 /* coincides with the exact bounding box for most glyphs, it can be */
254 /* slightly larger in some situations (like when rotating an outline */
255 /* which contains Bezier outside arcs). */
257 /* Computing the control box is very fast, while getting the bounding */
258 /* box can take much more time as it needs to walk over all segments */
259 /* and arcs in the outline. To get the latter, you can use the */
260 /* `ftbbox' component which is dedicated to this single task. */
263 /* glyph :: A handle to the source glyph object. */
265 /* mode :: The mode which indicates how to interpret the returned */
266 /* bounding box values. */
269 /* acbox :: The glyph coordinate bounding box. Coordinates are */
270 /* expressed in 1/64th of pixels if it is grid-fitted. */
273 /* Coordinates are relative to the glyph origin, using the Y-upwards */
276 /* If the glyph has been loaded with FT_LOAD_NO_SCALE, `bbox_mode' */
277 /* must be set to `ft_glyph_bbox_unscaled' to get unscaled font */
280 /* If `bbox_mode' is set to `ft_glyph_bbox_subpixels' the bbox */
281 /* coordinates are returned in 26.6 pixels (i.e. 1/64th of pixels). */
283 /* Note that the maximum coordinates are exclusive, which means that */
284 /* one can compute the width and height of the glyph image (be it in */
285 /* integer or 26.6 pixels) as: */
287 /* width = bbox.xMax - bbox.xMin; */
288 /* height = bbox.yMax - bbox.yMin; */
290 /* Note also that for 26.6 coordinates, if `bbox_mode' is set to */
291 /* `ft_glyph_bbox_gridfit', the coordinates will also be grid-fitted, */
292 /* which corresponds to: */
294 /* bbox.xMin = FLOOR(bbox.xMin); */
295 /* bbox.yMin = FLOOR(bbox.yMin); */
296 /* bbox.xMax = CEILING(bbox.xMax); */
297 /* bbox.yMax = CEILING(bbox.yMax); */
299 /* To get the bbox in pixel coordinates, set `bbox_mode' to */
300 /* `ft_glyph_bbox_truncate'. */
302 /* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode' */
303 /* to `ft_glyph_bbox_pixels'. */
305 /* The default value for `bbox_mode' is `ft_glyph_bbox_pixels'. */
309 ft_glyph_bbox_unscaled = 0, /* return unscaled font units */
310 ft_glyph_bbox_subpixels = 0, /* return unfitted 26.6 coordinates */
311 ft_glyph_bbox_gridfit = 1, /* return grid-fitted 26.6 coordinates */
312 ft_glyph_bbox_truncate = 2, /* return coordinates in integer pixels */
313 ft_glyph_bbox_pixels = 3 /* return grid-fitted pixel coordinates */
318 FT_Glyph_Get_CBox( FT_Glyph glyph,
323 /*************************************************************************/
326 /* FT_Glyph_To_Bitmap */
329 /* Converts a given glyph object to a bitmap glyph object. */
332 /* the_glyph :: A pointer to a handle to the target glyph. */
335 /* render_mode :: A set of bit flags that describe how the data is */
338 /* origin :: A pointer to a vector used to translate the glyph */
339 /* image before rendering. Can be 0 (if no */
340 /* translation). The origin is expressed in */
343 /* destroy :: A boolean that indicates that the original glyph */
344 /* image should be destroyed by this function. It is */
345 /* never destroyed in case of error. */
348 /* FreeType error code. 0 means success. */
351 /* The glyph image is translated with the `origin' vector before */
352 /* rendering. In case of error, it it translated back to its */
353 /* original position and the glyph is left untouched. */
355 /* The first parameter is a pointer to a FT_Glyph handle, that will */
356 /* be replaced by this function. Typically, you would use (omitting */
357 /* error handling): */
361 /* FT_Glyph glyph; */
362 /* FT_BitmapGlyph glyph_bitmap; */
366 /* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); */
368 /* // extract glyph image */
369 /* error = FT_Get_Glyph( face->glyph, &glyph ); */
371 /* // convert to a bitmap (default render mode + destroy old) */
372 /* if ( glyph->format != ft_glyph_format_bitmap ) */
374 /* error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_default, */
376 /* if ( error ) // glyph unchanged */
380 /* // access bitmap content by typecasting */
381 /* glyph_bitmap = (FT_BitmapGlyph)glyph; */
383 /* // do funny stuff with it, like blitting/drawing */
386 /* // discard glyph image (bitmap or not) */
387 /* FT_Done_Glyph( glyph ); */
391 /* This function will always fail if the glyph's format isn't */
394 FT_EXPORT( FT_Error )
395 FT_Glyph_To_Bitmap( FT_Glyph* the_glyph,
396 FT_ULong render_mode,
401 /*************************************************************************/
407 /* Destroys a given glyph. */
410 /* glyph :: A handle to the target glyph object. */
413 FT_Done_Glyph( FT_Glyph glyph );
416 /* other helpful functions */
418 /*************************************************************************/
423 /*************************************************************************/
426 /*************************************************************************/
429 /* FT_Matrix_Multiply */
432 /* Performs the matrix operation `b = a*b'. */
435 /* a :: A pointer to matrix `a'. */
438 /* b :: A pointer to matrix `b'. */
441 /* The result is undefined if either `a' or `b' is zero. */
444 FT_Matrix_Multiply( FT_Matrix* a,
448 /*************************************************************************/
451 /* FT_Matrix_Invert */
454 /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
457 /* matrix :: A pointer to the target matrix. Remains untouched in */
461 /* FreeType error code. 0 means success. */
463 FT_EXPORT( FT_Error )
464 FT_Matrix_Invert( FT_Matrix* matrix );
472 #endif /* __FTGLYPH_H__ */