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 /* Handle to an object used to model generic glyph images. It is a */
73 /* pointer to the @FT_GlyphRec structure and can contain a glyph */
74 /* bitmap or pointer. */
77 /* Glyph objects are not owned by the library. You must thus release */
78 /* them manually (through @FT_Done_Glyph) _before_ calling */
79 /* @FT_Done_FreeType. */
81 typedef struct FT_GlyphRec_* FT_Glyph;
84 /*************************************************************************/
90 /* The root glyph structure contains a given glyph image plus its */
91 /* advance width in 16.16 fixed float format. */
94 /* library :: A handle to the FreeType library object. */
96 /* clazz :: A pointer to the glyph's class. Private. */
98 /* format :: The format of the glyph's image. */
100 /* advance :: A 16.16 vector that gives the glyph's advance width. */
102 typedef struct FT_GlyphRec_
105 const FT_Glyph_Class* clazz;
106 FT_Glyph_Format format;
112 /*************************************************************************/
118 /* A handle to an object used to model a bitmap glyph image. This is */
119 /* a sub-class of @FT_Glyph, and a pointer to @FT_BitmapGlyphRec. */
121 typedef struct FT_BitmapGlyphRec_* FT_BitmapGlyph;
124 /*************************************************************************/
127 /* FT_BitmapGlyphRec */
130 /* A structure used for bitmap glyph images. This really is a */
131 /* `sub-class' of `FT_GlyphRec'. */
134 /* root :: The root FT_Glyph fields. */
136 /* left :: The left-side bearing, i.e., the horizontal distance */
137 /* from the current pen position to the left border of the */
140 /* top :: The top-side bearing, i.e., the vertical distance from */
141 /* the current pen position to the top border of the glyph */
142 /* bitmap. This distance is positive for upwards-y! */
144 /* bitmap :: A descriptor for the bitmap. */
147 /* You can typecast FT_Glyph to FT_BitmapGlyph if you have */
148 /* glyph->format == FT_GLYPH_FORMAT_BITMAP. This lets you access */
149 /* the bitmap's contents easily. */
151 /* The corresponding pixel buffer is always owned by the BitmapGlyph */
152 /* and is thus created and destroyed with it. */
154 typedef struct FT_BitmapGlyphRec_
164 /*************************************************************************/
167 /* FT_OutlineGlyph */
170 /* A handle to an object used to model an outline glyph image. This */
171 /* is a sub-class of @FT_Glyph, and a pointer to @FT_OutlineGlyphRec. */
173 typedef struct FT_OutlineGlyphRec_* FT_OutlineGlyph;
176 /*************************************************************************/
179 /* FT_OutlineGlyphRec */
182 /* A structure used for outline (vectorial) glyph images. This */
183 /* really is a `sub-class' of `FT_GlyphRec'. */
186 /* root :: The root FT_Glyph fields. */
188 /* outline :: A descriptor for the outline. */
191 /* You can typecast FT_Glyph to FT_OutlineGlyph if you have */
192 /* glyph->format == FT_GLYPH_FORMAT_OUTLINE. This lets you access */
193 /* the outline's content easily. */
195 /* As the outline is extracted from a glyph slot, its coordinates are */
196 /* expressed normally in 26.6 pixels, unless the flag */
197 /* FT_LOAD_NO_SCALE was used in FT_Load_Glyph() or FT_Load_Char(). */
199 /* The outline's tables are always owned by the object and are */
200 /* destroyed with it. */
202 typedef struct FT_OutlineGlyphRec_
207 } FT_OutlineGlyphRec;
210 /*************************************************************************/
216 /* A function used to extract a glyph image from a slot. */
219 /* slot :: A handle to the source glyph slot. */
222 /* aglyph :: A handle to the glyph object. */
225 /* FreeType error code. 0 means success. */
227 FT_EXPORT( FT_Error )
228 FT_Get_Glyph( FT_GlyphSlot slot,
232 /*************************************************************************/
238 /* A function used to copy a glyph image. */
241 /* source :: A handle to the source glyph object. */
244 /* target :: A handle to the target glyph object. 0 in case of */
248 /* FreeType error code. 0 means success. */
250 FT_EXPORT( FT_Error )
251 FT_Glyph_Copy( FT_Glyph source,
255 /*************************************************************************/
258 /* FT_Glyph_Transform */
261 /* Transforms a glyph image if its format is scalable. */
264 /* glyph :: A handle to the target glyph object. */
267 /* matrix :: A pointer to a 2x2 matrix to apply. */
269 /* delta :: A pointer to a 2d vector to apply. Coordinates are */
270 /* expressed in 1/64th of a pixel. */
273 /* FreeType error code (the glyph format is not scalable if it is */
277 /* The 2x2 transformation matrix is also applied to the glyph's */
278 /* advance vector. */
280 FT_EXPORT( FT_Error )
281 FT_Glyph_Transform( FT_Glyph glyph,
287 /*************************************************************************/
290 /* FT_Glyph_Get_CBox */
293 /* Returns a glyph's `control box'. The control box encloses all the */
294 /* outline's points, including Bezier control points. Though it */
295 /* coincides with the exact bounding box for most glyphs, it can be */
296 /* slightly larger in some situations (like when rotating an outline */
297 /* which contains Bezier outside arcs). */
299 /* Computing the control box is very fast, while getting the bounding */
300 /* box can take much more time as it needs to walk over all segments */
301 /* and arcs in the outline. To get the latter, you can use the */
302 /* `ftbbox' component which is dedicated to this single task. */
305 /* glyph :: A handle to the source glyph object. */
307 /* mode :: The mode which indicates how to interpret the returned */
308 /* bounding box values. */
311 /* acbox :: The glyph coordinate bounding box. Coordinates are */
312 /* expressed in 1/64th of pixels if it is grid-fitted. */
315 /* Coordinates are relative to the glyph origin, using the Y-upwards */
318 /* If the glyph has been loaded with FT_LOAD_NO_SCALE, `bbox_mode' */
319 /* must be set to `ft_glyph_bbox_unscaled' to get unscaled font */
322 /* If `bbox_mode' is set to `ft_glyph_bbox_subpixels' the bbox */
323 /* coordinates are returned in 26.6 pixels (i.e. 1/64th of pixels). */
325 /* Note that the maximum coordinates are exclusive, which means that */
326 /* one can compute the width and height of the glyph image (be it in */
327 /* integer or 26.6 pixels) as: */
329 /* width = bbox.xMax - bbox.xMin; */
330 /* height = bbox.yMax - bbox.yMin; */
332 /* Note also that for 26.6 coordinates, if `bbox_mode' is set to */
333 /* `ft_glyph_bbox_gridfit', the coordinates will also be grid-fitted, */
334 /* which corresponds to: */
336 /* bbox.xMin = FLOOR(bbox.xMin); */
337 /* bbox.yMin = FLOOR(bbox.yMin); */
338 /* bbox.xMax = CEILING(bbox.xMax); */
339 /* bbox.yMax = CEILING(bbox.yMax); */
341 /* To get the bbox in pixel coordinates, set `bbox_mode' to */
342 /* `ft_glyph_bbox_truncate'. */
344 /* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode' */
345 /* to `ft_glyph_bbox_pixels'. */
347 /* The default value for `bbox_mode' is `ft_glyph_bbox_pixels'. */
351 ft_glyph_bbox_unscaled = 0, /* return unscaled font units */
352 ft_glyph_bbox_subpixels = 0, /* return unfitted 26.6 coordinates */
353 ft_glyph_bbox_gridfit = 1, /* return grid-fitted 26.6 coordinates */
354 ft_glyph_bbox_truncate = 2, /* return coordinates in integer pixels */
355 ft_glyph_bbox_pixels = 3 /* return grid-fitted pixel coordinates */
360 FT_Glyph_Get_CBox( FT_Glyph glyph,
365 /*************************************************************************/
368 /* FT_Glyph_To_Bitmap */
371 /* Converts a given glyph object to a bitmap glyph object. */
374 /* the_glyph :: A pointer to a handle to the target glyph. */
377 /* render_mode :: An enumeration that describe how the data is */
380 /* origin :: A pointer to a vector used to translate the glyph */
381 /* image before rendering. Can be 0 (if no */
382 /* translation). The origin is expressed in */
385 /* destroy :: A boolean that indicates that the original glyph */
386 /* image should be destroyed by this function. It is */
387 /* never destroyed in case of error. */
390 /* FreeType error code. 0 means success. */
393 /* The glyph image is translated with the `origin' vector before */
394 /* rendering. In case of error, it it translated back to its */
395 /* original position and the glyph is left untouched. */
397 /* The first parameter is a pointer to a FT_Glyph handle, that will */
398 /* be replaced by this function. Typically, you would use (omitting */
399 /* error handling): */
403 /* FT_Glyph glyph; */
404 /* FT_BitmapGlyph glyph_bitmap; */
408 /* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); */
410 /* // extract glyph image */
411 /* error = FT_Get_Glyph( face->glyph, &glyph ); */
413 /* // convert to a bitmap (default render mode + destroy old) */
414 /* if ( glyph->format != FT_GLYPH_FORMAT_BITMAP ) */
416 /* error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_default, */
418 /* if ( error ) // glyph unchanged */
422 /* // access bitmap content by typecasting */
423 /* glyph_bitmap = (FT_BitmapGlyph)glyph; */
425 /* // do funny stuff with it, like blitting/drawing */
428 /* // discard glyph image (bitmap or not) */
429 /* FT_Done_Glyph( glyph ); */
433 /* This function will always fail if the glyph's format isn't */
436 FT_EXPORT( FT_Error )
437 FT_Glyph_To_Bitmap( FT_Glyph* the_glyph,
438 FT_Render_Mode render_mode,
443 /*************************************************************************/
449 /* Destroys a given glyph. */
452 /* glyph :: A handle to the target glyph object. */
455 FT_Done_Glyph( FT_Glyph glyph );
458 /* other helpful functions */
460 /*************************************************************************/
465 /*************************************************************************/
468 /*************************************************************************/
471 /* FT_Matrix_Multiply */
474 /* Performs the matrix operation `b = a*b'. */
477 /* a :: A pointer to matrix `a'. */
480 /* b :: A pointer to matrix `b'. */
483 /* The result is undefined if either `a' or `b' is zero. */
486 FT_Matrix_Multiply( const FT_Matrix* a,
490 /*************************************************************************/
493 /* FT_Matrix_Invert */
496 /* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
499 /* matrix :: A pointer to the target matrix. Remains untouched in */
503 /* FreeType error code. 0 means success. */
505 FT_EXPORT( FT_Error )
506 FT_Matrix_Invert( FT_Matrix* matrix );
514 #endif /* __FTGLYPH_H__ */