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