David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* ftglyph.c */ |
| 4 | /* */ |
Werner Lemberg | f13e633 | 2000-05-30 16:49:14 +0000 | [diff] [blame] | 5 | /* FreeType convenience functions to handle glyphs (body). */ |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 6 | /* */ |
Werner Lemberg | fa42025 | 2005-05-11 20:04:35 +0000 | [diff] [blame] | 7 | /* Copyright 1996-2001, 2002, 2003, 2004, 2005 by */ |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 | /* */ |
Werner Lemberg | 4e6dd85 | 2000-06-05 05:26:15 +0000 | [diff] [blame] | 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 */ |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 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. */ |
| 15 | /* */ |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 16 | /***************************************************************************/ |
| 17 | |
Werner Lemberg | f13e633 | 2000-05-30 16:49:14 +0000 | [diff] [blame] | 18 | /*************************************************************************/ |
| 19 | /* */ |
| 20 | /* This file contains the definition of several convenience functions */ |
| 21 | /* that can be used by client applications to easily retrieve glyph */ |
| 22 | /* bitmaps and outlines from a given face. */ |
| 23 | /* */ |
| 24 | /* These functions should be optional if you are writing a font server */ |
| 25 | /* or text layout engine on top of FreeType. However, they are pretty */ |
| 26 | /* handy for many other simple uses of the library. */ |
| 27 | /* */ |
| 28 | /*************************************************************************/ |
| 29 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 30 | |
| 31 | #include <ft2build.h> |
| 32 | #include FT_GLYPH_H |
| 33 | #include FT_OUTLINE_H |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 34 | #include FT_BITMAP_H |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 35 | #include FT_INTERNAL_OBJECTS_H |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 36 | |
Werner Lemberg | f13e633 | 2000-05-30 16:49:14 +0000 | [diff] [blame] | 37 | |
Werner Lemberg | eb81e37 | 2000-06-03 06:03:11 +0000 | [diff] [blame] | 38 | /*************************************************************************/ |
| 39 | /* */ |
| 40 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 41 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 42 | /* messages during execution. */ |
| 43 | /* */ |
| 44 | #undef FT_COMPONENT |
| 45 | #define FT_COMPONENT trace_glyph |
| 46 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 47 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 48 | /*************************************************************************/ |
| 49 | /*************************************************************************/ |
| 50 | /**** ****/ |
| 51 | /**** Convenience functions ****/ |
| 52 | /**** ****/ |
| 53 | /*************************************************************************/ |
| 54 | /*************************************************************************/ |
Werner Lemberg | eb81e37 | 2000-06-03 06:03:11 +0000 | [diff] [blame] | 55 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 56 | |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 57 | /* documentation is in ftglyph.h */ |
| 58 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 59 | FT_EXPORT_DEF( void ) |
Graham Asher | be1a8da | 2003-01-14 15:53:33 +0000 | [diff] [blame] | 60 | FT_Matrix_Multiply( const FT_Matrix* a, |
Werner Lemberg | c8c6bf5 | 2003-04-23 05:38:13 +0000 | [diff] [blame] | 61 | FT_Matrix *b ) |
David Turner | 1fb6eea | 2000-05-24 00:31:14 +0000 | [diff] [blame] | 62 | { |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 63 | FT_Fixed xx, xy, yx, yy; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 64 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 65 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 66 | if ( !a || !b ) |
| 67 | return; |
| 68 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 69 | xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx ); |
| 70 | xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy ); |
| 71 | yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx ); |
| 72 | yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy ); |
Werner Lemberg | f13e633 | 2000-05-30 16:49:14 +0000 | [diff] [blame] | 73 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 74 | b->xx = xx; b->xy = xy; |
| 75 | b->yx = yx; b->yy = yy; |
| 76 | } |
| 77 | |
| 78 | |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 79 | /* documentation is in ftglyph.h */ |
| 80 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 81 | FT_EXPORT_DEF( FT_Error ) |
| 82 | FT_Matrix_Invert( FT_Matrix* matrix ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 83 | { |
| 84 | FT_Pos delta, xx, yy; |
| 85 | |
| 86 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 87 | if ( !matrix ) |
| 88 | return FT_Err_Invalid_Argument; |
| 89 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 90 | /* compute discriminant */ |
| 91 | delta = FT_MulFix( matrix->xx, matrix->yy ) - |
| 92 | FT_MulFix( matrix->xy, matrix->yx ); |
| 93 | |
| 94 | if ( !delta ) |
| 95 | return FT_Err_Invalid_Argument; /* matrix can't be inverted */ |
| 96 | |
| 97 | matrix->xy = - FT_DivFix( matrix->xy, delta ); |
| 98 | matrix->yx = - FT_DivFix( matrix->yx, delta ); |
| 99 | |
| 100 | xx = matrix->xx; |
| 101 | yy = matrix->yy; |
| 102 | |
| 103 | matrix->xx = FT_DivFix( yy, delta ); |
| 104 | matrix->yy = FT_DivFix( xx, delta ); |
| 105 | |
| 106 | return FT_Err_Ok; |
| 107 | } |
| 108 | |
| 109 | |
| 110 | /*************************************************************************/ |
| 111 | /*************************************************************************/ |
| 112 | /**** ****/ |
| 113 | /**** FT_BitmapGlyph support ****/ |
| 114 | /**** ****/ |
| 115 | /*************************************************************************/ |
| 116 | /*************************************************************************/ |
| 117 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 118 | FT_CALLBACK_DEF( FT_Error ) |
| 119 | ft_bitmap_glyph_init( FT_Glyph bitmap_glyph, |
| 120 | FT_GlyphSlot slot ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 121 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 122 | FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; |
| 123 | FT_Error error = FT_Err_Ok; |
| 124 | FT_Library library = FT_GLYPH( glyph )->library; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 125 | |
| 126 | |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 127 | if ( slot->format != FT_GLYPH_FORMAT_BITMAP ) |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 128 | { |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 129 | error = FT_Err_Invalid_Glyph_Format; |
| 130 | goto Exit; |
| 131 | } |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 132 | |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 133 | glyph->left = slot->bitmap_left; |
| 134 | glyph->top = slot->bitmap_top; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 135 | |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 136 | /* do lazy copying whenever possible */ |
Werner Lemberg | 7a02410 | 2003-06-18 06:59:57 +0000 | [diff] [blame] | 137 | if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 138 | { |
| 139 | glyph->bitmap = slot->bitmap; |
Werner Lemberg | 7a02410 | 2003-06-18 06:59:57 +0000 | [diff] [blame] | 140 | slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 141 | } |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 142 | else |
| 143 | { |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 144 | FT_Bitmap_New( &glyph->bitmap ); |
| 145 | error = FT_Bitmap_Copy( library, &slot->bitmap, &glyph->bitmap ); |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 146 | } |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 147 | |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 148 | Exit: |
| 149 | return error; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 150 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 151 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 152 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 153 | FT_CALLBACK_DEF( FT_Error ) |
| 154 | ft_bitmap_glyph_copy( FT_Glyph bitmap_source, |
| 155 | FT_Glyph bitmap_target ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 156 | { |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 157 | FT_Library library = bitmap_source->library; |
| 158 | FT_BitmapGlyph source = (FT_BitmapGlyph)bitmap_source; |
| 159 | FT_BitmapGlyph target = (FT_BitmapGlyph)bitmap_target; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 160 | |
| 161 | |
| 162 | target->left = source->left; |
| 163 | target->top = source->top; |
| 164 | |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 165 | return FT_Bitmap_Copy( library, &source->bitmap, &target->bitmap ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 166 | } |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 167 | |
| 168 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 169 | FT_CALLBACK_DEF( void ) |
| 170 | ft_bitmap_glyph_done( FT_Glyph bitmap_glyph ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 171 | { |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 172 | FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; |
| 173 | FT_Library library = FT_GLYPH( glyph )->library; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 174 | |
| 175 | |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 176 | FT_Bitmap_Done( library, &glyph->bitmap ); |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 177 | } |
| 178 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 179 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 180 | FT_CALLBACK_DEF( void ) |
| 181 | ft_bitmap_glyph_bbox( FT_Glyph bitmap_glyph, |
| 182 | FT_BBox* cbox ) |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 183 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 184 | FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph; |
| 185 | |
| 186 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 187 | cbox->xMin = glyph->left << 6; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 188 | cbox->xMax = cbox->xMin + ( glyph->bitmap.width << 6 ); |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 189 | cbox->yMax = glyph->top << 6; |
Werner Lemberg | 5a96b07 | 2000-10-17 14:29:48 +0000 | [diff] [blame] | 190 | cbox->yMin = cbox->yMax - ( glyph->bitmap.rows << 6 ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 191 | } |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 192 | |
Werner Lemberg | f13e633 | 2000-05-30 16:49:14 +0000 | [diff] [blame] | 193 | |
Werner Lemberg | c846eac | 2004-02-19 21:39:58 +0000 | [diff] [blame] | 194 | FT_CALLBACK_TABLE_DEF |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 195 | const FT_Glyph_Class ft_bitmap_glyph_class = |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 196 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 197 | sizeof ( FT_BitmapGlyphRec ), |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 198 | FT_GLYPH_FORMAT_BITMAP, |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 199 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 200 | ft_bitmap_glyph_init, |
| 201 | ft_bitmap_glyph_done, |
| 202 | ft_bitmap_glyph_copy, |
| 203 | 0, /* FT_Glyph_TransformFunc */ |
| 204 | ft_bitmap_glyph_bbox, |
| 205 | 0 /* FT_Glyph_PrepareFunc */ |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 206 | }; |
Werner Lemberg | 2fbf7e4 | 2000-06-02 00:01:14 +0000 | [diff] [blame] | 207 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 208 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 209 | /*************************************************************************/ |
| 210 | /*************************************************************************/ |
| 211 | /**** ****/ |
| 212 | /**** FT_OutlineGlyph support ****/ |
| 213 | /**** ****/ |
| 214 | /*************************************************************************/ |
| 215 | /*************************************************************************/ |
Werner Lemberg | 2fbf7e4 | 2000-06-02 00:01:14 +0000 | [diff] [blame] | 216 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 217 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 218 | FT_CALLBACK_DEF( FT_Error ) |
| 219 | ft_outline_glyph_init( FT_Glyph outline_glyph, |
| 220 | FT_GlyphSlot slot ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 221 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 222 | FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; |
| 223 | FT_Error error = FT_Err_Ok; |
| 224 | FT_Library library = FT_GLYPH( glyph )->library; |
| 225 | FT_Outline* source = &slot->outline; |
| 226 | FT_Outline* target = &glyph->outline; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 227 | |
| 228 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 229 | /* check format in glyph slot */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 230 | if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 231 | { |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 232 | error = FT_Err_Invalid_Glyph_Format; |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 233 | goto Exit; |
| 234 | } |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 235 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 236 | /* allocate new outline */ |
| 237 | error = FT_Outline_New( library, source->n_points, source->n_contours, |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 238 | &glyph->outline ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 239 | if ( error ) |
| 240 | goto Exit; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 241 | |
Werner Lemberg | b9ee737 | 2005-05-20 21:52:19 +0000 | [diff] [blame] | 242 | FT_Outline_Copy( source, target ); |
Werner Lemberg | f13e633 | 2000-05-30 16:49:14 +0000 | [diff] [blame] | 243 | |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 244 | Exit: |
| 245 | return error; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 246 | } |
| 247 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 248 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 249 | FT_CALLBACK_DEF( void ) |
| 250 | ft_outline_glyph_done( FT_Glyph outline_glyph ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 251 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 252 | FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; |
| 253 | |
| 254 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 255 | FT_Outline_Done( FT_GLYPH( glyph )->library, &glyph->outline ); |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 256 | } |
| 257 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 258 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 259 | FT_CALLBACK_DEF( FT_Error ) |
| 260 | ft_outline_glyph_copy( FT_Glyph outline_source, |
| 261 | FT_Glyph outline_target ) |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 262 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 263 | FT_OutlineGlyph source = (FT_OutlineGlyph)outline_source; |
| 264 | FT_OutlineGlyph target = (FT_OutlineGlyph)outline_target; |
| 265 | FT_Error error; |
| 266 | FT_Library library = FT_GLYPH( source )->library; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 267 | |
| 268 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 269 | error = FT_Outline_New( library, source->outline.n_points, |
| 270 | source->outline.n_contours, &target->outline ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 271 | if ( !error ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 272 | FT_Outline_Copy( &source->outline, &target->outline ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 273 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 274 | return error; |
| 275 | } |
| 276 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 277 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 278 | FT_CALLBACK_DEF( void ) |
Werner Lemberg | fa42025 | 2005-05-11 20:04:35 +0000 | [diff] [blame] | 279 | ft_outline_glyph_transform( FT_Glyph outline_glyph, |
| 280 | const FT_Matrix* matrix, |
| 281 | const FT_Vector* delta ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 282 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 283 | FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; |
| 284 | |
| 285 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 286 | if ( matrix ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 287 | FT_Outline_Transform( &glyph->outline, matrix ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 288 | |
| 289 | if ( delta ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 290 | FT_Outline_Translate( &glyph->outline, delta->x, delta->y ); |
| 291 | } |
| 292 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 293 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 294 | FT_CALLBACK_DEF( void ) |
| 295 | ft_outline_glyph_bbox( FT_Glyph outline_glyph, |
| 296 | FT_BBox* bbox ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 297 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 298 | FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; |
| 299 | |
| 300 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 301 | FT_Outline_Get_CBox( &glyph->outline, bbox ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 302 | } |
| 303 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 304 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 305 | FT_CALLBACK_DEF( FT_Error ) |
| 306 | ft_outline_glyph_prepare( FT_Glyph outline_glyph, |
| 307 | FT_GlyphSlot slot ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 308 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 309 | FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph; |
| 310 | |
| 311 | |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 312 | slot->format = FT_GLYPH_FORMAT_OUTLINE; |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 313 | slot->outline = glyph->outline; |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 314 | slot->outline.flags &= ~FT_OUTLINE_OWNER; |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 315 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 316 | return FT_Err_Ok; |
| 317 | } |
| 318 | |
| 319 | |
Werner Lemberg | c846eac | 2004-02-19 21:39:58 +0000 | [diff] [blame] | 320 | FT_CALLBACK_TABLE_DEF |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 321 | const FT_Glyph_Class ft_outline_glyph_class = |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 322 | { |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 323 | sizeof ( FT_OutlineGlyphRec ), |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 324 | FT_GLYPH_FORMAT_OUTLINE, |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 325 | |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 326 | ft_outline_glyph_init, |
| 327 | ft_outline_glyph_done, |
| 328 | ft_outline_glyph_copy, |
| 329 | ft_outline_glyph_transform, |
| 330 | ft_outline_glyph_bbox, |
| 331 | ft_outline_glyph_prepare |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 332 | }; |
| 333 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 334 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 335 | /*************************************************************************/ |
| 336 | /*************************************************************************/ |
| 337 | /**** ****/ |
| 338 | /**** FT_Glyph class and API ****/ |
| 339 | /**** ****/ |
| 340 | /*************************************************************************/ |
| 341 | /*************************************************************************/ |
| 342 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 343 | static FT_Error |
| 344 | ft_new_glyph( FT_Library library, |
| 345 | const FT_Glyph_Class* clazz, |
| 346 | FT_Glyph* aglyph ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 347 | { |
| 348 | FT_Memory memory = library->memory; |
| 349 | FT_Error error; |
| 350 | FT_Glyph glyph; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 351 | |
| 352 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 353 | *aglyph = 0; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 354 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 355 | if ( !FT_ALLOC( glyph, clazz->glyph_size ) ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 356 | { |
| 357 | glyph->library = library; |
| 358 | glyph->clazz = clazz; |
| 359 | glyph->format = clazz->glyph_format; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 360 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 361 | *aglyph = glyph; |
| 362 | } |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 363 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 364 | return error; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 365 | } |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 366 | |
| 367 | |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 368 | /* documentation is in ftglyph.h */ |
| 369 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 370 | FT_EXPORT_DEF( FT_Error ) |
| 371 | FT_Glyph_Copy( FT_Glyph source, |
| 372 | FT_Glyph *target ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 373 | { |
| 374 | FT_Glyph copy; |
| 375 | FT_Error error; |
| 376 | const FT_Glyph_Class* clazz; |
| 377 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 378 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 379 | /* check arguments */ |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 380 | if ( !target || !source || !source->clazz ) |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 381 | { |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 382 | error = FT_Err_Invalid_Argument; |
| 383 | goto Exit; |
| 384 | } |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 385 | |
| 386 | *target = 0; |
| 387 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 388 | clazz = source->clazz; |
| 389 | error = ft_new_glyph( source->library, clazz, © ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 390 | if ( error ) |
| 391 | goto Exit; |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 392 | |
David Turner | 8fe916c | 2001-02-16 16:27:35 +0000 | [diff] [blame] | 393 | copy->advance = source->advance; |
| 394 | copy->format = source->format; |
| 395 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 396 | if ( clazz->glyph_copy ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 397 | error = clazz->glyph_copy( source, copy ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 398 | |
| 399 | if ( error ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 400 | FT_Done_Glyph( copy ); |
| 401 | else |
| 402 | *target = copy; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 403 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 404 | Exit: |
| 405 | return error; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 406 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 407 | |
Werner Lemberg | f13e633 | 2000-05-30 16:49:14 +0000 | [diff] [blame] | 408 | |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 409 | /* documentation is in ftglyph.h */ |
| 410 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 411 | FT_EXPORT_DEF( FT_Error ) |
| 412 | FT_Get_Glyph( FT_GlyphSlot slot, |
| 413 | FT_Glyph *aglyph ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 414 | { |
David Turner | c4ec973 | 2003-09-29 20:35:34 +0000 | [diff] [blame] | 415 | FT_Library library; |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 416 | FT_Error error; |
| 417 | FT_Glyph glyph; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 418 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 419 | const FT_Glyph_Class* clazz = 0; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 420 | |
| 421 | |
| 422 | if ( !slot ) |
| 423 | return FT_Err_Invalid_Slot_Handle; |
| 424 | |
David Turner | c4ec973 | 2003-09-29 20:35:34 +0000 | [diff] [blame] | 425 | library = slot->library; |
| 426 | |
Werner Lemberg | aa8c7da | 2000-07-04 03:37:18 +0000 | [diff] [blame] | 427 | if ( !aglyph ) |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 428 | return FT_Err_Invalid_Argument; |
| 429 | |
| 430 | /* if it is a bitmap, that's easy :-) */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 431 | if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 432 | clazz = &ft_bitmap_glyph_class; |
| 433 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 434 | /* it it is an outline too */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 435 | else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 436 | clazz = &ft_outline_glyph_class; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 437 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 438 | else |
| 439 | { |
| 440 | /* try to find a renderer that supports the glyph image format */ |
| 441 | FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 442 | |
| 443 | |
| 444 | if ( render ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 445 | clazz = &render->glyph_class; |
| 446 | } |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 447 | |
| 448 | if ( !clazz ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 449 | { |
| 450 | error = FT_Err_Invalid_Glyph_Format; |
| 451 | goto Exit; |
| 452 | } |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 453 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 454 | /* create FT_Glyph object */ |
| 455 | error = ft_new_glyph( library, clazz, &glyph ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 456 | if ( error ) |
| 457 | goto Exit; |
| 458 | |
| 459 | /* copy advance while converting it to 16.16 format */ |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 460 | glyph->advance.x = slot->advance.x << 10; |
| 461 | glyph->advance.y = slot->advance.y << 10; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 462 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 463 | /* now import the image from the glyph slot */ |
| 464 | error = clazz->glyph_init( glyph, slot ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 465 | |
| 466 | /* if an error occurred, destroy the glyph */ |
| 467 | if ( error ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 468 | FT_Done_Glyph( glyph ); |
| 469 | else |
| 470 | *aglyph = glyph; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 471 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 472 | Exit: |
| 473 | return error; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 474 | } |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 475 | |
| 476 | |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 477 | /* documentation is in ftglyph.h */ |
| 478 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 479 | FT_EXPORT_DEF( FT_Error ) |
| 480 | FT_Glyph_Transform( FT_Glyph glyph, |
| 481 | FT_Matrix* matrix, |
| 482 | FT_Vector* delta ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 483 | { |
| 484 | const FT_Glyph_Class* clazz; |
| 485 | FT_Error error = FT_Err_Ok; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 486 | |
| 487 | |
| 488 | if ( !glyph || !glyph->clazz ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 489 | error = FT_Err_Invalid_Argument; |
| 490 | else |
| 491 | { |
| 492 | clazz = glyph->clazz; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 493 | if ( clazz->glyph_transform ) |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 494 | { |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 495 | /* transform glyph image */ |
| 496 | clazz->glyph_transform( glyph, matrix, delta ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 497 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 498 | /* transform advance vector */ |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 499 | if ( matrix ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 500 | FT_Vector_Transform( &glyph->advance, matrix ); |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 501 | } |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 502 | else |
| 503 | error = FT_Err_Invalid_Glyph_Format; |
| 504 | } |
| 505 | return error; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 506 | } |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 507 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 508 | |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 509 | /* documentation is in ftglyph.h */ |
| 510 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 511 | FT_EXPORT_DEF( void ) |
| 512 | FT_Glyph_Get_CBox( FT_Glyph glyph, |
| 513 | FT_UInt bbox_mode, |
| 514 | FT_BBox *acbox ) |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 515 | { |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 516 | const FT_Glyph_Class* clazz; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 517 | |
| 518 | |
Werner Lemberg | cf24d51 | 2001-06-18 14:23:45 +0000 | [diff] [blame] | 519 | if ( !acbox ) |
| 520 | return; |
| 521 | |
| 522 | acbox->xMin = acbox->yMin = acbox->xMax = acbox->yMax = 0; |
| 523 | |
| 524 | if ( !glyph || !glyph->clazz ) |
| 525 | return; |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 526 | else |
| 527 | { |
| 528 | clazz = glyph->clazz; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 529 | if ( !clazz->glyph_bbox ) |
Werner Lemberg | cf24d51 | 2001-06-18 14:23:45 +0000 | [diff] [blame] | 530 | return; |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 531 | else |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 532 | { |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 533 | /* retrieve bbox in 26.6 coordinates */ |
Werner Lemberg | 4b68007 | 2000-11-07 06:30:29 +0000 | [diff] [blame] | 534 | clazz->glyph_bbox( glyph, acbox ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 535 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 536 | /* perform grid fitting if needed */ |
Werner Lemberg | 052904e | 2003-06-17 10:42:27 +0000 | [diff] [blame] | 537 | if ( bbox_mode == FT_GLYPH_BBOX_GRIDFIT || |
| 538 | bbox_mode == FT_GLYPH_BBOX_PIXELS ) |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 539 | { |
David Turner | 87c0d30 | 2003-12-24 01:10:46 +0000 | [diff] [blame] | 540 | acbox->xMin = FT_PIX_FLOOR( acbox->xMin ); |
| 541 | acbox->yMin = FT_PIX_FLOOR( acbox->yMin ); |
| 542 | acbox->xMax = FT_PIX_CEIL( acbox->xMax ); |
| 543 | acbox->yMax = FT_PIX_CEIL( acbox->yMax ); |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 544 | } |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 545 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 546 | /* convert to integer pixels if needed */ |
Werner Lemberg | 052904e | 2003-06-17 10:42:27 +0000 | [diff] [blame] | 547 | if ( bbox_mode == FT_GLYPH_BBOX_TRUNCATE || |
| 548 | bbox_mode == FT_GLYPH_BBOX_PIXELS ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 549 | { |
Werner Lemberg | 4b68007 | 2000-11-07 06:30:29 +0000 | [diff] [blame] | 550 | acbox->xMin >>= 6; |
| 551 | acbox->yMin >>= 6; |
| 552 | acbox->xMax >>= 6; |
| 553 | acbox->yMax >>= 6; |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 554 | } |
| 555 | } |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 556 | } |
| 557 | return; |
| 558 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 559 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 560 | |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 561 | /* documentation is in ftglyph.h */ |
| 562 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 563 | FT_EXPORT_DEF( FT_Error ) |
Werner Lemberg | 68e9f92 | 2002-09-27 11:09:23 +0000 | [diff] [blame] | 564 | FT_Glyph_To_Bitmap( FT_Glyph* the_glyph, |
| 565 | FT_Render_Mode render_mode, |
| 566 | FT_Vector* origin, |
| 567 | FT_Bool destroy ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 568 | { |
Werner Lemberg | 7a02410 | 2003-06-18 06:59:57 +0000 | [diff] [blame] | 569 | FT_GlyphSlotRec dummy; |
| 570 | FT_GlyphSlot_InternalRec dummy_internal; |
| 571 | FT_Error error = FT_Err_Ok; |
| 572 | FT_Glyph glyph; |
| 573 | FT_BitmapGlyph bitmap = NULL; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 574 | |
Werner Lemberg | 7a02410 | 2003-06-18 06:59:57 +0000 | [diff] [blame] | 575 | const FT_Glyph_Class* clazz; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 576 | |
| 577 | |
| 578 | /* check argument */ |
| 579 | if ( !the_glyph ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 580 | goto Bad; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 581 | |
| 582 | /* we render the glyph into a glyph bitmap using a `dummy' glyph slot */ |
| 583 | /* then calling FT_Render_Glyph_Internal() */ |
| 584 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 585 | glyph = *the_glyph; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 586 | if ( !glyph ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 587 | goto Bad; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 588 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 589 | clazz = glyph->clazz; |
David Turner | f0f1b6a | 2002-07-08 23:05:14 +0000 | [diff] [blame] | 590 | |
Werner Lemberg | 75ad4b8 | 2003-05-28 06:10:57 +0000 | [diff] [blame] | 591 | /* when called with a bitmap glyph, do nothing and return successfully */ |
David Turner | f0f1b6a | 2002-07-08 23:05:14 +0000 | [diff] [blame] | 592 | if ( clazz == &ft_bitmap_glyph_class ) |
| 593 | goto Exit; |
| 594 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 595 | if ( !clazz || !clazz->glyph_prepare ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 596 | goto Bad; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 597 | |
Werner Lemberg | b3d5e9c | 2002-07-28 05:05:24 +0000 | [diff] [blame] | 598 | FT_MEM_ZERO( &dummy, sizeof ( dummy ) ); |
Werner Lemberg | 7a02410 | 2003-06-18 06:59:57 +0000 | [diff] [blame] | 599 | FT_MEM_ZERO( &dummy_internal, sizeof ( dummy_internal ) ); |
| 600 | dummy.internal = &dummy_internal; |
| 601 | dummy.library = glyph->library; |
| 602 | dummy.format = clazz->glyph_format; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 603 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 604 | /* create result bitmap glyph */ |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 605 | error = ft_new_glyph( glyph->library, &ft_bitmap_glyph_class, |
Werner Lemberg | 92aa527 | 2005-05-23 21:33:02 +0000 | [diff] [blame] | 606 | (FT_Glyph*)(void*)&bitmap ); |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 607 | if ( error ) |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 608 | goto Exit; |
| 609 | |
Werner Lemberg | 75ad4b8 | 2003-05-28 06:10:57 +0000 | [diff] [blame] | 610 | #if 1 |
David Turner | c8ad30a | 2001-12-05 17:24:34 +0000 | [diff] [blame] | 611 | /* if `origin' is set, translate the glyph image */ |
| 612 | if ( origin ) |
| 613 | FT_Glyph_Transform( glyph, 0, origin ); |
Werner Lemberg | 5da9dd7 | 2001-12-16 08:17:33 +0000 | [diff] [blame] | 614 | #else |
| 615 | FT_UNUSED( origin ); |
David Turner | c8ad30a | 2001-12-05 17:24:34 +0000 | [diff] [blame] | 616 | #endif |
| 617 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 618 | /* prepare dummy slot for rendering */ |
David Turner | c38ddff | 2000-08-21 04:43:01 +0000 | [diff] [blame] | 619 | error = clazz->glyph_prepare( glyph, &dummy ); |
Werner Lemberg | 8728f29 | 2000-08-23 17:32:42 +0000 | [diff] [blame] | 620 | if ( !error ) |
David Turner | c38ddff | 2000-08-21 04:43:01 +0000 | [diff] [blame] | 621 | error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 622 | |
Werner Lemberg | 75ad4b8 | 2003-05-28 06:10:57 +0000 | [diff] [blame] | 623 | #if 1 |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 624 | if ( !destroy && origin ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 625 | { |
| 626 | FT_Vector v; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 627 | |
| 628 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 629 | v.x = -origin->x; |
| 630 | v.y = -origin->y; |
| 631 | FT_Glyph_Transform( glyph, 0, &v ); |
| 632 | } |
David Turner | c8ad30a | 2001-12-05 17:24:34 +0000 | [diff] [blame] | 633 | #endif |
| 634 | |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 635 | if ( error ) |
David Turner | c8ad30a | 2001-12-05 17:24:34 +0000 | [diff] [blame] | 636 | goto Exit; |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 637 | |
Werner Lemberg | 4091109 | 2000-11-03 07:57:51 +0000 | [diff] [blame] | 638 | /* in case of success, copy the bitmap to the glyph bitmap */ |
Werner Lemberg | e260d25 | 2004-05-17 09:25:04 +0000 | [diff] [blame] | 639 | error = ft_bitmap_glyph_init( (FT_Glyph)bitmap, &dummy ); |
David Turner | c8ad30a | 2001-12-05 17:24:34 +0000 | [diff] [blame] | 640 | if ( error ) |
| 641 | goto Exit; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 642 | |
David Turner | c8ad30a | 2001-12-05 17:24:34 +0000 | [diff] [blame] | 643 | /* copy advance */ |
| 644 | bitmap->root.advance = glyph->advance; |
Werner Lemberg | 4091109 | 2000-11-03 07:57:51 +0000 | [diff] [blame] | 645 | |
David Turner | c8ad30a | 2001-12-05 17:24:34 +0000 | [diff] [blame] | 646 | if ( destroy ) |
| 647 | FT_Done_Glyph( glyph ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 648 | |
David Turner | c8ad30a | 2001-12-05 17:24:34 +0000 | [diff] [blame] | 649 | *the_glyph = FT_GLYPH( bitmap ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 650 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 651 | Exit: |
Werner Lemberg | e9e130c | 2001-12-07 21:56:32 +0000 | [diff] [blame] | 652 | if ( error && bitmap ) |
| 653 | FT_Done_Glyph( FT_GLYPH( bitmap ) ); |
| 654 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 655 | return error; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 656 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 657 | Bad: |
| 658 | error = FT_Err_Invalid_Argument; |
| 659 | goto Exit; |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 660 | } |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 661 | |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 662 | |
Werner Lemberg | 90a0330 | 2000-11-07 17:21:11 +0000 | [diff] [blame] | 663 | /* documentation is in ftglyph.h */ |
| 664 | |
Werner Lemberg | f814d0f | 2001-06-27 16:18:10 +0000 | [diff] [blame] | 665 | FT_EXPORT_DEF( void ) |
| 666 | FT_Done_Glyph( FT_Glyph glyph ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 667 | { |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 668 | if ( glyph ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 669 | { |
| 670 | FT_Memory memory = glyph->library->memory; |
| 671 | const FT_Glyph_Class* clazz = glyph->clazz; |
| 672 | |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 673 | |
| 674 | if ( clazz->glyph_done ) |
David Turner | f9ca2bb | 2000-06-30 23:12:55 +0000 | [diff] [blame] | 675 | clazz->glyph_done( glyph ); |
Werner Lemberg | a8bbc26 | 2000-07-01 14:06:46 +0000 | [diff] [blame] | 676 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 677 | FT_FREE( glyph ); |
David Turner | 37379e2 | 2000-03-28 11:22:31 +0000 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
| 681 | |
Werner Lemberg | f13e633 | 2000-05-30 16:49:14 +0000 | [diff] [blame] | 682 | /* END */ |