David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
| 3 | /* ttgload.c */ |
| 4 | /* */ |
| 5 | /* TrueType Glyph Loader (body). */ |
| 6 | /* */ |
Werner Lemberg | 91a9716 | 2011-01-30 20:12:54 +0100 | [diff] [blame] | 7 | /* Copyright 1996-2011 */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 | /* */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +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 | d2b1f35 | 1999-12-16 23:11:37 +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 | /* */ |
| 16 | /***************************************************************************/ |
| 17 | |
Werner Lemberg | cc069be | 2000-12-08 16:17:16 +0000 | [diff] [blame] | 18 | |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 19 | #include <ft2build.h> |
| 20 | #include FT_INTERNAL_DEBUG_H |
| 21 | #include FT_INTERNAL_CALC_H |
| 22 | #include FT_INTERNAL_STREAM_H |
| 23 | #include FT_INTERNAL_SFNT_H |
| 24 | #include FT_TRUETYPE_TAGS_H |
| 25 | #include FT_OUTLINE_H |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 26 | |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 27 | #include "ttgload.h" |
Werner Lemberg | f13516c | 2005-03-03 17:09:08 +0000 | [diff] [blame] | 28 | #include "ttpload.h" |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 29 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 30 | #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT |
| 31 | #include "ttgxvar.h" |
| 32 | #endif |
| 33 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 34 | #include "tterrors.h" |
| 35 | |
David Turner | a90663f | 2000-07-08 00:41:13 +0000 | [diff] [blame] | 36 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +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 | /* */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 43 | #undef FT_COMPONENT |
| 44 | #define FT_COMPONENT trace_ttgload |
| 45 | |
| 46 | |
| 47 | /*************************************************************************/ |
| 48 | /* */ |
Werner Lemberg | 6e3fee0 | 2011-03-21 09:28:52 +0100 | [diff] [blame] | 49 | /* Composite glyph flags. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 50 | /* */ |
Werner Lemberg | eed446d | 2002-08-16 12:46:52 +0000 | [diff] [blame] | 51 | #define ARGS_ARE_WORDS 0x0001 |
| 52 | #define ARGS_ARE_XY_VALUES 0x0002 |
| 53 | #define ROUND_XY_TO_GRID 0x0004 |
| 54 | #define WE_HAVE_A_SCALE 0x0008 |
| 55 | /* reserved 0x0010 */ |
| 56 | #define MORE_COMPONENTS 0x0020 |
| 57 | #define WE_HAVE_AN_XY_SCALE 0x0040 |
| 58 | #define WE_HAVE_A_2X2 0x0080 |
| 59 | #define WE_HAVE_INSTR 0x0100 |
| 60 | #define USE_MY_METRICS 0x0200 |
| 61 | #define OVERLAP_COMPOUND 0x0400 |
| 62 | #define SCALED_COMPONENT_OFFSET 0x0800 |
| 63 | #define UNSCALED_COMPONENT_OFFSET 0x1000 |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 64 | |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 65 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 66 | /*************************************************************************/ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 67 | /* */ |
Behdad Esfahbod | 8c82ec5 | 2011-04-21 08:21:37 +0200 | [diff] [blame] | 68 | /* Return the horizontal metrics in font units for a given glyph. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 69 | /* */ |
Werner Lemberg | ac0d52d | 2009-11-02 08:35:24 +0100 | [diff] [blame] | 70 | FT_LOCAL_DEF( void ) |
David Turner | 28534d6 | 2008-09-01 21:35:21 +0000 | [diff] [blame] | 71 | TT_Get_HMetrics( TT_Face face, |
| 72 | FT_UInt idx, |
David Turner | 28534d6 | 2008-09-01 21:35:21 +0000 | [diff] [blame] | 73 | FT_Short* lsb, |
| 74 | FT_UShort* aw ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 75 | { |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 76 | ( (SFNT_Service)face->sfnt )->get_metrics( face, 0, idx, lsb, aw ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 77 | |
Werner Lemberg | c4b2214 | 2009-11-15 10:10:00 +0100 | [diff] [blame] | 78 | FT_TRACE5(( " advance width (font units): %d\n", *aw )); |
| 79 | FT_TRACE5(( " left side bearing (font units): %d\n", *lsb )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
| 83 | /*************************************************************************/ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 84 | /* */ |
Behdad Esfahbod | 8c82ec5 | 2011-04-21 08:21:37 +0200 | [diff] [blame] | 85 | /* Return the vertical metrics in font units for a given glyph. */ |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 86 | /* Greg Hitchcock from Microsoft told us that if there were no `vmtx' */ |
| 87 | /* table, typoAscender/Descender from the `OS/2' table would be used */ |
| 88 | /* instead, and if there were no `OS/2' table, use ascender/descender */ |
| 89 | /* from the `hhea' table. But that is not what Microsoft's rasterizer */ |
| 90 | /* apparently does: It uses the ppem value as the advance height, and */ |
| 91 | /* sets the top side bearing to be zero. */ |
| 92 | /* */ |
Werner Lemberg | ac0d52d | 2009-11-02 08:35:24 +0100 | [diff] [blame] | 93 | FT_LOCAL_DEF( void ) |
David Turner | 28534d6 | 2008-09-01 21:35:21 +0000 | [diff] [blame] | 94 | TT_Get_VMetrics( TT_Face face, |
| 95 | FT_UInt idx, |
David Turner | 28534d6 | 2008-09-01 21:35:21 +0000 | [diff] [blame] | 96 | FT_Short* tsb, |
| 97 | FT_UShort* ah ) |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 98 | { |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 99 | if ( face->vertical_info ) |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 100 | ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, idx, tsb, ah ); |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 101 | |
Werner Lemberg | 4b2e83d | 2007-02-01 07:58:02 +0000 | [diff] [blame] | 102 | #if 1 /* Empirically determined, at variance with what MS said */ |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 103 | |
| 104 | else |
| 105 | { |
| 106 | *tsb = 0; |
| 107 | *ah = face->root.units_per_EM; |
| 108 | } |
| 109 | |
| 110 | #else /* This is what MS said to do. It isn't what they do, however. */ |
| 111 | |
| 112 | else if ( face->os2.version != 0xFFFFU ) |
| 113 | { |
| 114 | *tsb = face->os2.sTypoAscender; |
| 115 | *ah = face->os2.sTypoAscender - face->os2.sTypoDescender; |
| 116 | } |
David Turner | 2f0fdb9 | 2004-06-21 21:16:56 +0000 | [diff] [blame] | 117 | else |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 118 | { |
| 119 | *tsb = face->horizontal.Ascender; |
| 120 | *ah = face->horizontal.Ascender - face->horizontal.Descender; |
| 121 | } |
| 122 | |
| 123 | #endif |
| 124 | |
Werner Lemberg | c4b2214 | 2009-11-15 10:10:00 +0100 | [diff] [blame] | 125 | FT_TRACE5(( " advance height (font units): %d\n", *ah )); |
| 126 | FT_TRACE5(( " top side bearing (font units): %d\n", *tsb )); |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 130 | static void |
| 131 | tt_get_metrics( TT_Loader loader, |
| 132 | FT_UInt glyph_index ) |
| 133 | { |
| 134 | TT_Face face = (TT_Face)loader->face; |
| 135 | |
| 136 | FT_Short left_bearing = 0, top_bearing = 0; |
| 137 | FT_UShort advance_width = 0, advance_height = 0; |
| 138 | |
| 139 | |
| 140 | TT_Get_HMetrics( face, glyph_index, |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 141 | &left_bearing, |
| 142 | &advance_width ); |
| 143 | TT_Get_VMetrics( face, glyph_index, |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 144 | &top_bearing, |
| 145 | &advance_height ); |
| 146 | |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 147 | loader->left_bearing = left_bearing; |
| 148 | loader->advance = advance_width; |
| 149 | loader->top_bearing = top_bearing; |
| 150 | loader->vadvance = advance_height; |
| 151 | |
| 152 | if ( !loader->linear_def ) |
| 153 | { |
| 154 | loader->linear_def = 1; |
| 155 | loader->linear = advance_width; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 160 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
| 161 | |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 162 | static void |
| 163 | tt_get_metrics_incr_overrides( TT_Loader loader, |
| 164 | FT_UInt glyph_index ) |
| 165 | { |
| 166 | TT_Face face = (TT_Face)loader->face; |
| 167 | |
| 168 | FT_Short left_bearing = 0, top_bearing = 0; |
| 169 | FT_UShort advance_width = 0, advance_height = 0; |
| 170 | |
| 171 | |
Ken Sharp | 980b76e | 2010-02-10 07:02:43 +0100 | [diff] [blame] | 172 | /* If this is an incrementally loaded font check whether there are */ |
| 173 | /* overriding metrics for this glyph. */ |
| 174 | if ( face->root.internal->incremental_interface && |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 175 | face->root.internal->incremental_interface->funcs->get_glyph_metrics ) |
| 176 | { |
| 177 | FT_Incremental_MetricsRec metrics; |
| 178 | FT_Error error; |
| 179 | |
| 180 | |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 181 | metrics.bearing_x = loader->left_bearing; |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 182 | metrics.bearing_y = 0; |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 183 | metrics.advance = loader->advance; |
Ken Sharp | 980b76e | 2010-02-10 07:02:43 +0100 | [diff] [blame] | 184 | metrics.advance_v = 0; |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 185 | |
| 186 | error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( |
| 187 | face->root.internal->incremental_interface->object, |
| 188 | glyph_index, FALSE, &metrics ); |
| 189 | if ( error ) |
| 190 | goto Exit; |
| 191 | |
| 192 | left_bearing = (FT_Short)metrics.bearing_x; |
| 193 | advance_width = (FT_UShort)metrics.advance; |
| 194 | |
| 195 | #if 0 |
| 196 | |
| 197 | /* GWW: Do I do the same for vertical metrics? */ |
| 198 | metrics.bearing_x = 0; |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 199 | metrics.bearing_y = loader->top_bearing; |
| 200 | metrics.advance = loader->vadvance; |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 201 | |
| 202 | error = face->root.internal->incremental_interface->funcs->get_glyph_metrics( |
| 203 | face->root.internal->incremental_interface->object, |
| 204 | glyph_index, TRUE, &metrics ); |
| 205 | if ( error ) |
| 206 | goto Exit; |
| 207 | |
| 208 | top_bearing = (FT_Short)metrics.bearing_y; |
| 209 | advance_height = (FT_UShort)metrics.advance; |
| 210 | |
| 211 | #endif /* 0 */ |
| 212 | |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 213 | loader->left_bearing = left_bearing; |
| 214 | loader->advance = advance_width; |
| 215 | loader->top_bearing = top_bearing; |
| 216 | loader->vadvance = advance_height; |
| 217 | |
| 218 | if ( !loader->linear_def ) |
| 219 | { |
| 220 | loader->linear_def = 1; |
| 221 | loader->linear = advance_width; |
| 222 | } |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 223 | } |
| 224 | |
Werner Lemberg | 9045f5b | 2009-12-03 05:57:30 +0100 | [diff] [blame] | 225 | Exit: |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 226 | return; |
| 227 | } |
Werner Lemberg | 9045f5b | 2009-12-03 05:57:30 +0100 | [diff] [blame] | 228 | |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 229 | #endif /* FT_CONFIG_OPTION_INCREMENTAL */ |
| 230 | |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 231 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 232 | /*************************************************************************/ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 233 | /* */ |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 234 | /* Translates an array of coordinates. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 235 | /* */ |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 236 | static void |
| 237 | translate_array( FT_UInt n, |
| 238 | FT_Vector* coords, |
| 239 | FT_Pos delta_x, |
| 240 | FT_Pos delta_y ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 241 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 242 | FT_UInt k; |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 243 | |
Werner Lemberg | 5811c7c | 2000-07-02 13:53:16 +0000 | [diff] [blame] | 244 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 245 | if ( delta_x ) |
| 246 | for ( k = 0; k < n; k++ ) |
| 247 | coords[k].x += delta_x; |
| 248 | |
| 249 | if ( delta_y ) |
| 250 | for ( k = 0; k < n; k++ ) |
| 251 | coords[k].y += delta_y; |
| 252 | } |
| 253 | |
| 254 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 255 | #undef IS_HINTED |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 256 | #define IS_HINTED( flags ) ( ( flags & FT_LOAD_NO_HINTING ) == 0 ) |
| 257 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 258 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 259 | /*************************************************************************/ |
| 260 | /* */ |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 261 | /* The following functions are used by default with TrueType fonts. */ |
| 262 | /* However, they can be replaced by alternatives if we need to support */ |
| 263 | /* TrueType-compressed formats (like MicroType) in the future. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 264 | /* */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 265 | /*************************************************************************/ |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 266 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 267 | FT_CALLBACK_DEF( FT_Error ) |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 268 | TT_Access_Glyph_Frame( TT_Loader loader, |
| 269 | FT_UInt glyph_index, |
| 270 | FT_ULong offset, |
| 271 | FT_UInt byte_count ) |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 272 | { |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 273 | FT_Error error; |
| 274 | FT_Stream stream = loader->stream; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 275 | |
Werner Lemberg | 353dfea | 2000-08-29 18:58:41 +0000 | [diff] [blame] | 276 | /* for non-debug mode */ |
| 277 | FT_UNUSED( glyph_index ); |
| 278 | |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 279 | |
Werner Lemberg | ae425e5 | 2010-06-29 12:31:08 +0200 | [diff] [blame] | 280 | FT_TRACE4(( "Glyph %ld\n", glyph_index )); |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 281 | |
| 282 | /* the following line sets the `error' variable through macros! */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 283 | if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( byte_count ) ) |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 284 | return error; |
| 285 | |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 286 | loader->cursor = stream->cursor; |
| 287 | loader->limit = stream->limit; |
| 288 | |
Werner Lemberg | e72c9fe | 2000-07-31 18:59:02 +0000 | [diff] [blame] | 289 | return TT_Err_Ok; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 290 | } |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 291 | |
| 292 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 293 | FT_CALLBACK_DEF( void ) |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 294 | TT_Forget_Glyph_Frame( TT_Loader loader ) |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 295 | { |
| 296 | FT_Stream stream = loader->stream; |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 297 | |
| 298 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 299 | FT_FRAME_EXIT(); |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 300 | } |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 301 | |
| 302 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 303 | FT_CALLBACK_DEF( FT_Error ) |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 304 | TT_Load_Glyph_Header( TT_Loader loader ) |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 305 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 306 | FT_Byte* p = loader->cursor; |
| 307 | FT_Byte* limit = loader->limit; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 308 | |
Werner Lemberg | ac81295 | 2002-01-06 16:42:44 +0000 | [diff] [blame] | 309 | |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 310 | if ( p + 10 > limit ) |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 311 | return TT_Err_Invalid_Outline; |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 312 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 313 | loader->n_contours = FT_NEXT_SHORT( p ); |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 314 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 315 | loader->bbox.xMin = FT_NEXT_SHORT( p ); |
| 316 | loader->bbox.yMin = FT_NEXT_SHORT( p ); |
| 317 | loader->bbox.xMax = FT_NEXT_SHORT( p ); |
| 318 | loader->bbox.yMax = FT_NEXT_SHORT( p ); |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 319 | |
| 320 | FT_TRACE5(( " # of contours: %d\n", loader->n_contours )); |
| 321 | FT_TRACE5(( " xMin: %4d xMax: %4d\n", loader->bbox.xMin, |
| 322 | loader->bbox.xMax )); |
| 323 | FT_TRACE5(( " yMin: %4d yMax: %4d\n", loader->bbox.yMin, |
| 324 | loader->bbox.yMax )); |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 325 | loader->cursor = p; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 326 | |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 327 | return TT_Err_Ok; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 328 | } |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 329 | |
| 330 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 331 | FT_CALLBACK_DEF( FT_Error ) |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 332 | TT_Load_Simple_Glyph( TT_Loader load ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 333 | { |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 334 | FT_Error error; |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 335 | FT_Byte* p = load->cursor; |
| 336 | FT_Byte* limit = load->limit; |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 337 | FT_GlyphLoader gloader = load->gloader; |
| 338 | FT_Int n_contours = load->n_contours; |
| 339 | FT_Outline* outline; |
| 340 | TT_Face face = (TT_Face)load->face; |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 341 | FT_UShort n_ins; |
David Turner | 7fa30ee | 2007-06-11 00:55:23 +0000 | [diff] [blame] | 342 | FT_Int n_points; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 343 | |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 344 | FT_Byte *flag, *flag_limit; |
| 345 | FT_Byte c, count; |
| 346 | FT_Vector *vec, *vec_limit; |
| 347 | FT_Pos x; |
David Turner | 815911a | 2007-06-16 17:07:20 +0000 | [diff] [blame] | 348 | FT_Short *cont, *cont_limit, prev_cont; |
David Turner | 5f5e544 | 2007-06-11 00:18:00 +0000 | [diff] [blame] | 349 | FT_Int xy_size = 0; |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 350 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 351 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 352 | /* check that we can add the contours to the glyph */ |
David Turner | 9fbd2ab | 2005-10-28 16:14:14 +0000 | [diff] [blame] | 353 | error = FT_GLYPHLOADER_CHECK_POINTS( gloader, 0, n_contours ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 354 | if ( error ) |
| 355 | goto Fail; |
| 356 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 357 | /* reading the contours' endpoints & number of points */ |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 358 | cont = gloader->current.outline.contours; |
| 359 | cont_limit = cont + n_contours; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 360 | |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 361 | /* check space for contours array + instructions count */ |
Werner Lemberg | e12ed56 | 2007-06-17 05:31:23 +0000 | [diff] [blame] | 362 | if ( n_contours >= 0xFFF || p + ( n_contours + 1 ) * 2 > limit ) |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 363 | goto Invalid_Outline; |
Werner Lemberg | ac81295 | 2002-01-06 16:42:44 +0000 | [diff] [blame] | 364 | |
Werner Lemberg | 89d64fa | 2008-05-17 20:06:13 +0000 | [diff] [blame] | 365 | prev_cont = FT_NEXT_USHORT( p ); |
| 366 | |
| 367 | if ( n_contours > 0 ) |
| 368 | cont[0] = prev_cont; |
| 369 | |
David Turner | 815911a | 2007-06-16 17:07:20 +0000 | [diff] [blame] | 370 | for ( cont++; cont < cont_limit; cont++ ) |
| 371 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 372 | cont[0] = FT_NEXT_USHORT( p ); |
David Turner | 8f626b0 | 2007-06-22 22:22:38 +0000 | [diff] [blame] | 373 | if ( cont[0] <= prev_cont ) |
David Turner | 815911a | 2007-06-16 17:07:20 +0000 | [diff] [blame] | 374 | { |
Werner Lemberg | e12ed56 | 2007-06-17 05:31:23 +0000 | [diff] [blame] | 375 | /* unordered contours: this is invalid */ |
Werner Lemberg | f765e44 | 2010-06-24 10:34:29 +0200 | [diff] [blame] | 376 | error = TT_Err_Invalid_Table; |
David Turner | 815911a | 2007-06-16 17:07:20 +0000 | [diff] [blame] | 377 | goto Fail; |
| 378 | } |
| 379 | prev_cont = cont[0]; |
| 380 | } |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 381 | |
| 382 | n_points = 0; |
| 383 | if ( n_contours > 0 ) |
Werner Lemberg | d069246 | 2007-05-16 15:48:02 +0000 | [diff] [blame] | 384 | { |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 385 | n_points = cont[-1] + 1; |
Werner Lemberg | d069246 | 2007-05-16 15:48:02 +0000 | [diff] [blame] | 386 | if ( n_points < 0 ) |
| 387 | goto Invalid_Outline; |
| 388 | } |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 389 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 390 | /* note that we will add four phantom points later */ |
David Turner | 9fbd2ab | 2005-10-28 16:14:14 +0000 | [diff] [blame] | 391 | error = FT_GLYPHLOADER_CHECK_POINTS( gloader, n_points + 4, 0 ); |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 392 | if ( error ) |
| 393 | goto Fail; |
| 394 | |
| 395 | /* we'd better check the contours table right now */ |
| 396 | outline = &gloader->current.outline; |
| 397 | |
| 398 | for ( cont = outline->contours + 1; cont < cont_limit; cont++ ) |
| 399 | if ( cont[-1] >= cont[0] ) |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 400 | goto Invalid_Outline; |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 401 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 402 | /* reading the bytecode instructions */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 403 | load->glyph->control_len = 0; |
| 404 | load->glyph->control_data = 0; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 405 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 406 | if ( p + 2 > limit ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 407 | goto Invalid_Outline; |
| 408 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 409 | n_ins = FT_NEXT_USHORT( p ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 410 | |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 411 | FT_TRACE5(( " Instructions size: %u\n", n_ins )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 412 | |
| 413 | if ( n_ins > face->max_profile.maxSizeOfInstructions ) |
| 414 | { |
Werner Lemberg | 858abbe | 2009-06-26 06:15:41 +0200 | [diff] [blame] | 415 | FT_TRACE0(( "TT_Load_Simple_Glyph: too many instructions (%d)\n", |
Werner Lemberg | 6e2f9d5 | 2007-06-05 06:58:48 +0000 | [diff] [blame] | 416 | n_ins )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 417 | error = TT_Err_Too_Many_Hints; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 418 | goto Fail; |
| 419 | } |
| 420 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 421 | if ( ( limit - p ) < n_ins ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 422 | { |
Werner Lemberg | 858abbe | 2009-06-26 06:15:41 +0200 | [diff] [blame] | 423 | FT_TRACE0(( "TT_Load_Simple_Glyph: instruction count mismatch\n" )); |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 424 | error = TT_Err_Too_Many_Hints; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 425 | goto Fail; |
| 426 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 427 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 428 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 429 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 430 | if ( IS_HINTED( load->load_flags ) ) |
David Turner | 08fdac9 | 2000-02-21 16:01:33 +0000 | [diff] [blame] | 431 | { |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 432 | load->glyph->control_len = n_ins; |
| 433 | load->glyph->control_data = load->exec->glyphIns; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 434 | |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 435 | FT_MEM_COPY( load->exec->glyphIns, p, (FT_Long)n_ins ); |
David Turner | 08fdac9 | 2000-02-21 16:01:33 +0000 | [diff] [blame] | 436 | } |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 437 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 438 | #endif /* TT_USE_BYTECODE_INTERPRETER */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 439 | |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 440 | p += n_ins; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 441 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 442 | /* reading the point tags */ |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 443 | flag = (FT_Byte*)outline->tags; |
| 444 | flag_limit = flag + n_points; |
| 445 | |
Werner Lemberg | 685dd4f | 2004-10-13 05:15:44 +0000 | [diff] [blame] | 446 | FT_ASSERT( flag != NULL ); |
| 447 | |
Werner Lemberg | f946fc6 | 2003-12-31 08:48:21 +0000 | [diff] [blame] | 448 | while ( flag < flag_limit ) |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 449 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 450 | if ( p + 1 > limit ) |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 451 | goto Invalid_Outline; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 452 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 453 | *flag++ = c = FT_NEXT_BYTE( p ); |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 454 | if ( c & 8 ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 455 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 456 | if ( p + 1 > limit ) |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 457 | goto Invalid_Outline; |
| 458 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 459 | count = FT_NEXT_BYTE( p ); |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 460 | if ( flag + (FT_Int)count > flag_limit ) |
| 461 | goto Invalid_Outline; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 462 | |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 463 | for ( ; count > 0; count-- ) |
| 464 | *flag++ = c; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 468 | /* reading the X coordinates */ |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 469 | |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 470 | vec = outline->points; |
| 471 | vec_limit = vec + n_points; |
| 472 | flag = (FT_Byte*)outline->tags; |
| 473 | x = 0; |
| 474 | |
David Turner | 5f5e544 | 2007-06-11 00:18:00 +0000 | [diff] [blame] | 475 | if ( p + xy_size > limit ) |
| 476 | goto Invalid_Outline; |
| 477 | |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 478 | for ( ; vec < vec_limit; vec++, flag++ ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 479 | { |
Werner Lemberg | 35ae574 | 2008-10-02 10:40:52 +0000 | [diff] [blame] | 480 | FT_Pos y = 0; |
| 481 | FT_Byte f = *flag; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 482 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 483 | |
David Turner | 5f5e544 | 2007-06-11 00:18:00 +0000 | [diff] [blame] | 484 | if ( f & 2 ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 485 | { |
Werner Lemberg | f6c120f | 2007-06-11 04:55:58 +0000 | [diff] [blame] | 486 | if ( p + 1 > limit ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 487 | goto Invalid_Outline; |
| 488 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 489 | y = (FT_Pos)FT_NEXT_BYTE( p ); |
David Turner | 5f5e544 | 2007-06-11 00:18:00 +0000 | [diff] [blame] | 490 | if ( ( f & 16 ) == 0 ) |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 491 | y = -y; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 492 | } |
David Turner | 5f5e544 | 2007-06-11 00:18:00 +0000 | [diff] [blame] | 493 | else if ( ( f & 16 ) == 0 ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 494 | { |
Werner Lemberg | f6c120f | 2007-06-11 04:55:58 +0000 | [diff] [blame] | 495 | if ( p + 2 > limit ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 496 | goto Invalid_Outline; |
| 497 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 498 | y = (FT_Pos)FT_NEXT_SHORT( p ); |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 499 | } |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 500 | |
| 501 | x += y; |
| 502 | vec->x = x; |
Werner Lemberg | 35ae574 | 2008-10-02 10:40:52 +0000 | [diff] [blame] | 503 | /* the cast is for stupid compilers */ |
| 504 | *flag = (FT_Byte)( f & ~( 2 | 16 ) ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 507 | /* reading the Y coordinates */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 508 | |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 509 | vec = gloader->current.outline.points; |
| 510 | vec_limit = vec + n_points; |
| 511 | flag = (FT_Byte*)outline->tags; |
| 512 | x = 0; |
| 513 | |
| 514 | for ( ; vec < vec_limit; vec++, flag++ ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 515 | { |
Werner Lemberg | 35ae574 | 2008-10-02 10:40:52 +0000 | [diff] [blame] | 516 | FT_Pos y = 0; |
| 517 | FT_Byte f = *flag; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 518 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 519 | |
David Turner | 5f5e544 | 2007-06-11 00:18:00 +0000 | [diff] [blame] | 520 | if ( f & 4 ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 521 | { |
Werner Lemberg | f6c120f | 2007-06-11 04:55:58 +0000 | [diff] [blame] | 522 | if ( p + 1 > limit ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 523 | goto Invalid_Outline; |
| 524 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 525 | y = (FT_Pos)FT_NEXT_BYTE( p ); |
David Turner | 5f5e544 | 2007-06-11 00:18:00 +0000 | [diff] [blame] | 526 | if ( ( f & 32 ) == 0 ) |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 527 | y = -y; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 528 | } |
David Turner | 5f5e544 | 2007-06-11 00:18:00 +0000 | [diff] [blame] | 529 | else if ( ( f & 32 ) == 0 ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 530 | { |
Werner Lemberg | f6c120f | 2007-06-11 04:55:58 +0000 | [diff] [blame] | 531 | if ( p + 2 > limit ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 532 | goto Invalid_Outline; |
| 533 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 534 | y = (FT_Pos)FT_NEXT_SHORT( p ); |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 535 | } |
Werner Lemberg | 0240d29 | 2003-06-09 15:54:18 +0000 | [diff] [blame] | 536 | |
| 537 | x += y; |
| 538 | vec->y = x; |
Werner Lemberg | 35ae574 | 2008-10-02 10:40:52 +0000 | [diff] [blame] | 539 | /* the cast is for stupid compilers */ |
| 540 | *flag = (FT_Byte)( f & FT_CURVE_TAG_ON ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 541 | } |
| 542 | |
David Turner | 8edbcab | 2001-06-19 08:28:24 +0000 | [diff] [blame] | 543 | outline->n_points = (FT_UShort)n_points; |
| 544 | outline->n_contours = (FT_Short) n_contours; |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 545 | |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 546 | load->cursor = p; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 547 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 548 | Fail: |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 549 | return error; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 550 | |
| 551 | Invalid_Outline: |
| 552 | error = TT_Err_Invalid_Outline; |
| 553 | goto Fail; |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 557 | FT_CALLBACK_DEF( FT_Error ) |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 558 | TT_Load_Composite_Glyph( TT_Loader loader ) |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 559 | { |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 560 | FT_Error error; |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 561 | FT_Byte* p = loader->cursor; |
| 562 | FT_Byte* limit = loader->limit; |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 563 | FT_GlyphLoader gloader = loader->gloader; |
David Turner | eba5ad4 | 2002-03-14 12:56:35 +0000 | [diff] [blame] | 564 | FT_SubGlyph subglyph; |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 565 | FT_UInt num_subglyphs; |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 566 | |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 567 | |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 568 | num_subglyphs = 0; |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 569 | |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 570 | do |
| 571 | { |
| 572 | FT_Fixed xx, xy, yy, yx; |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 573 | FT_UInt count; |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 574 | |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 575 | |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 576 | /* check that we can load a new subglyph */ |
David Turner | eba5ad4 | 2002-03-14 12:56:35 +0000 | [diff] [blame] | 577 | error = FT_GlyphLoader_CheckSubGlyphs( gloader, num_subglyphs + 1 ); |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 578 | if ( error ) |
| 579 | goto Fail; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 580 | |
Werner Lemberg | ac81295 | 2002-01-06 16:42:44 +0000 | [diff] [blame] | 581 | /* check space */ |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 582 | if ( p + 4 > limit ) |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 583 | goto Invalid_Composite; |
| 584 | |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 585 | subglyph = gloader->current.subglyphs + num_subglyphs; |
| 586 | |
| 587 | subglyph->arg1 = subglyph->arg2 = 0; |
| 588 | |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 589 | subglyph->flags = FT_NEXT_USHORT( p ); |
| 590 | subglyph->index = FT_NEXT_USHORT( p ); |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 591 | |
Werner Lemberg | ac81295 | 2002-01-06 16:42:44 +0000 | [diff] [blame] | 592 | /* check space */ |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 593 | count = 2; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 594 | if ( subglyph->flags & ARGS_ARE_WORDS ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 595 | count += 2; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 596 | if ( subglyph->flags & WE_HAVE_A_SCALE ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 597 | count += 2; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 598 | else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 599 | count += 4; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 600 | else if ( subglyph->flags & WE_HAVE_A_2X2 ) |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 601 | count += 8; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 602 | |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 603 | if ( p + count > limit ) |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 604 | goto Invalid_Composite; |
| 605 | |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 606 | /* read arguments */ |
| 607 | if ( subglyph->flags & ARGS_ARE_WORDS ) |
| 608 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 609 | subglyph->arg1 = FT_NEXT_SHORT( p ); |
| 610 | subglyph->arg2 = FT_NEXT_SHORT( p ); |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 611 | } |
| 612 | else |
| 613 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 614 | subglyph->arg1 = FT_NEXT_CHAR( p ); |
| 615 | subglyph->arg2 = FT_NEXT_CHAR( p ); |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* read transform */ |
| 619 | xx = yy = 0x10000L; |
| 620 | xy = yx = 0; |
| 621 | |
| 622 | if ( subglyph->flags & WE_HAVE_A_SCALE ) |
| 623 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 624 | xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2; |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 625 | yy = xx; |
| 626 | } |
| 627 | else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE ) |
| 628 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 629 | xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2; |
| 630 | yy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2; |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 631 | } |
| 632 | else if ( subglyph->flags & WE_HAVE_A_2X2 ) |
| 633 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 634 | xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2; |
| 635 | yx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2; |
| 636 | xy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2; |
| 637 | yy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2; |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | subglyph->transform.xx = xx; |
| 641 | subglyph->transform.xy = xy; |
| 642 | subglyph->transform.yx = yx; |
| 643 | subglyph->transform.yy = yy; |
| 644 | |
| 645 | num_subglyphs++; |
Werner Lemberg | 5811c7c | 2000-07-02 13:53:16 +0000 | [diff] [blame] | 646 | |
Werner Lemberg | dcd2e14 | 2000-06-25 07:43:15 +0000 | [diff] [blame] | 647 | } while ( subglyph->flags & MORE_COMPONENTS ); |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 648 | |
| 649 | gloader->current.num_subglyphs = num_subglyphs; |
| 650 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 651 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 652 | |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 653 | { |
Werner Lemberg | 545c4e5 | 2006-05-17 22:55:04 +0000 | [diff] [blame] | 654 | FT_Stream stream = loader->stream; |
| 655 | |
| 656 | |
Werner Lemberg | 5df5dbb | 2008-06-22 13:40:08 +0000 | [diff] [blame] | 657 | /* we must undo the FT_FRAME_ENTER in order to point */ |
| 658 | /* to the composite instructions, if we find some. */ |
| 659 | /* We will process them later. */ |
| 660 | /* */ |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 661 | loader->ins_pos = (FT_ULong)( FT_STREAM_POS() + |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 662 | p - limit ); |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 663 | } |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 664 | |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 665 | #endif |
| 666 | |
David Turner | 281679d | 2006-05-17 13:34:21 +0000 | [diff] [blame] | 667 | loader->cursor = p; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 668 | |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 669 | Fail: |
| 670 | return error; |
David Turner | f7f82d7 | 2002-01-06 10:13:40 +0000 | [diff] [blame] | 671 | |
| 672 | Invalid_Composite: |
| 673 | error = TT_Err_Invalid_Composite; |
| 674 | goto Fail; |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 675 | } |
| 676 | |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 677 | |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 678 | FT_LOCAL_DEF( void ) |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 679 | TT_Init_Glyph_Loading( TT_Face face ) |
David Turner | 994d774 | 2000-06-25 04:49:19 +0000 | [diff] [blame] | 680 | { |
| 681 | face->access_glyph_frame = TT_Access_Glyph_Frame; |
| 682 | face->read_glyph_header = TT_Load_Glyph_Header; |
| 683 | face->read_simple_glyph = TT_Load_Simple_Glyph; |
| 684 | face->read_composite_glyph = TT_Load_Composite_Glyph; |
| 685 | face->forget_glyph_frame = TT_Forget_Glyph_Frame; |
| 686 | } |
| 687 | |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 688 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 689 | static void |
| 690 | tt_prepare_zone( TT_GlyphZone zone, |
| 691 | FT_GlyphLoad load, |
| 692 | FT_UInt start_point, |
| 693 | FT_UInt start_contour ) |
| 694 | { |
Werner Lemberg | e12ed56 | 2007-06-17 05:31:23 +0000 | [diff] [blame] | 695 | zone->n_points = (FT_UShort)( load->outline.n_points - start_point ); |
| 696 | zone->n_contours = (FT_Short) ( load->outline.n_contours - |
| 697 | start_contour ); |
| 698 | zone->org = load->extra_points + start_point; |
| 699 | zone->cur = load->outline.points + start_point; |
| 700 | zone->orus = load->extra_points2 + start_point; |
| 701 | zone->tags = (FT_Byte*)load->outline.tags + start_point; |
| 702 | zone->contours = (FT_UShort*)load->outline.contours + start_contour; |
David Turner | 9fbfc6a | 2006-08-16 09:11:31 +0000 | [diff] [blame] | 703 | zone->first_point = (FT_UShort)start_point; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | |
| 707 | /*************************************************************************/ |
| 708 | /* */ |
| 709 | /* <Function> */ |
| 710 | /* TT_Hint_Glyph */ |
| 711 | /* */ |
| 712 | /* <Description> */ |
| 713 | /* Hint the glyph using the zone prepared by the caller. Note that */ |
| 714 | /* the zone is supposed to include four phantom points. */ |
| 715 | /* */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 716 | static FT_Error |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 717 | TT_Hint_Glyph( TT_Loader loader, |
| 718 | FT_Bool is_composite ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 719 | { |
| 720 | TT_GlyphZone zone = &loader->zone; |
| 721 | FT_Pos origin; |
| 722 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 723 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 724 | FT_UInt n_ins; |
| 725 | #else |
| 726 | FT_UNUSED( is_composite ); |
| 727 | #endif |
| 728 | |
David Turner | 18e4443 | 2005-09-23 13:22:10 +0000 | [diff] [blame] | 729 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 730 | #ifdef TT_USE_BYTECODE_INTERPRETER |
suzuki toshiya | 1b6f1d2 | 2009-08-01 00:32:16 +0900 | [diff] [blame] | 731 | if ( loader->glyph->control_len > 0xFFFFL ) |
| 732 | { |
| 733 | FT_TRACE1(( "TT_Hint_Glyph: too long instructions " )); |
| 734 | FT_TRACE1(( "(0x%lx byte) is truncated\n", |
| 735 | loader->glyph->control_len )); |
| 736 | } |
| 737 | n_ins = (FT_UInt)( loader->glyph->control_len ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 738 | #endif |
| 739 | |
| 740 | origin = zone->cur[zone->n_points - 4].x; |
| 741 | origin = FT_PIX_ROUND( origin ) - origin; |
| 742 | if ( origin ) |
| 743 | translate_array( zone->n_points, zone->cur, origin, 0 ); |
| 744 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 745 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Werner Lemberg | 6e87ed9 | 2007-01-26 22:18:56 +0000 | [diff] [blame] | 746 | /* save original point position in org */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 747 | if ( n_ins > 0 ) |
Werner Lemberg | 1234299 | 2006-08-19 11:18:09 +0000 | [diff] [blame] | 748 | FT_ARRAY_COPY( zone->org, zone->cur, zone->n_points ); |
Werner Lemberg | ffa4965 | 2008-05-25 12:43:57 +0000 | [diff] [blame] | 749 | |
| 750 | /* Reset graphics state. */ |
| 751 | loader->exec->GS = ((TT_Size)loader->size)->GS; |
| 752 | |
| 753 | /* XXX: UNDOCUMENTED! Hinting instructions of a composite glyph */ |
| 754 | /* completely refer to the (already) hinted subglyphs. */ |
| 755 | if ( is_composite ) |
| 756 | { |
| 757 | loader->exec->metrics.x_scale = 1 << 16; |
| 758 | loader->exec->metrics.y_scale = 1 << 16; |
| 759 | |
| 760 | FT_ARRAY_COPY( zone->orus, zone->cur, zone->n_points ); |
| 761 | } |
| 762 | else |
| 763 | { |
Werner Lemberg | 0c52faa | 2008-05-25 20:04:56 +0000 | [diff] [blame] | 764 | loader->exec->metrics.x_scale = |
| 765 | ((TT_Size)loader->size)->metrics.x_scale; |
| 766 | loader->exec->metrics.y_scale = |
| 767 | ((TT_Size)loader->size)->metrics.y_scale; |
Werner Lemberg | ffa4965 | 2008-05-25 12:43:57 +0000 | [diff] [blame] | 768 | } |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 769 | #endif |
| 770 | |
| 771 | /* round pp2 and pp4 */ |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 772 | zone->cur[zone->n_points - 3].x = |
| 773 | FT_PIX_ROUND( zone->cur[zone->n_points - 3].x ); |
| 774 | zone->cur[zone->n_points - 1].y = |
| 775 | FT_PIX_ROUND( zone->cur[zone->n_points - 1].y ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 776 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 777 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 778 | |
| 779 | if ( n_ins > 0 ) |
| 780 | { |
| 781 | FT_Bool debug; |
| 782 | FT_Error error; |
| 783 | |
Werner Lemberg | 7227114 | 2009-06-18 15:42:52 +0200 | [diff] [blame] | 784 | FT_GlyphLoader gloader = loader->gloader; |
| 785 | FT_Outline current_outline = gloader->current.outline; |
| 786 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 787 | |
| 788 | error = TT_Set_CodeRange( loader->exec, tt_coderange_glyph, |
| 789 | loader->exec->glyphIns, n_ins ); |
| 790 | if ( error ) |
| 791 | return error; |
| 792 | |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 793 | loader->exec->is_composite = is_composite; |
| 794 | loader->exec->pts = *zone; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 795 | |
David Turner | 115b442 | 2006-12-22 11:37:05 +0000 | [diff] [blame] | 796 | debug = FT_BOOL( !( loader->load_flags & FT_LOAD_NO_SCALE ) && |
Werner Lemberg | 6b87e6f | 2007-01-02 19:20:08 +0000 | [diff] [blame] | 797 | ((TT_Size)loader->size)->debug ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 798 | |
| 799 | error = TT_Run_Context( loader->exec, debug ); |
| 800 | if ( error && loader->exec->pedantic_hinting ) |
| 801 | return error; |
Werner Lemberg | 7227114 | 2009-06-18 15:42:52 +0200 | [diff] [blame] | 802 | |
| 803 | /* store drop-out mode in bits 5-7; set bit 2 also as a marker */ |
| 804 | current_outline.tags[0] |= |
| 805 | ( loader->exec->GS.scan_type << 5 ) | FT_CURVE_TAG_HAS_SCANMODE; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | #endif |
| 809 | |
| 810 | /* save glyph phantom points */ |
| 811 | if ( !loader->preserve_pps ) |
| 812 | { |
| 813 | loader->pp1 = zone->cur[zone->n_points - 4]; |
| 814 | loader->pp2 = zone->cur[zone->n_points - 3]; |
| 815 | loader->pp3 = zone->cur[zone->n_points - 2]; |
| 816 | loader->pp4 = zone->cur[zone->n_points - 1]; |
| 817 | } |
| 818 | |
| 819 | return TT_Err_Ok; |
| 820 | } |
| 821 | |
| 822 | |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 823 | /*************************************************************************/ |
| 824 | /* */ |
| 825 | /* <Function> */ |
| 826 | /* TT_Process_Simple_Glyph */ |
| 827 | /* */ |
| 828 | /* <Description> */ |
| 829 | /* Once a simple glyph has been loaded, it needs to be processed. */ |
| 830 | /* Usually, this means scaling and hinting through bytecode */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 831 | /* interpretation. */ |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 832 | /* */ |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 833 | static FT_Error |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 834 | TT_Process_Simple_Glyph( TT_Loader loader ) |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 835 | { |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 836 | FT_GlyphLoader gloader = loader->gloader; |
| 837 | FT_Error error = TT_Err_Ok; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 838 | FT_Outline* outline; |
Werner Lemberg | d21fe6e | 2007-07-10 23:10:39 +0000 | [diff] [blame] | 839 | FT_Int n_points; |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 840 | |
Werner Lemberg | e4b32a5 | 2000-10-31 20:42:18 +0000 | [diff] [blame] | 841 | |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 842 | outline = &gloader->current.outline; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 843 | n_points = outline->n_points; |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 844 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 845 | /* set phantom points */ |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 846 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 847 | outline->points[n_points ] = loader->pp1; |
| 848 | outline->points[n_points + 1] = loader->pp2; |
| 849 | outline->points[n_points + 2] = loader->pp3; |
| 850 | outline->points[n_points + 3] = loader->pp4; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 851 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 852 | outline->tags[n_points ] = 0; |
| 853 | outline->tags[n_points + 1] = 0; |
| 854 | outline->tags[n_points + 2] = 0; |
| 855 | outline->tags[n_points + 3] = 0; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 856 | |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 857 | n_points += 4; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 858 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 859 | #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT |
| 860 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 861 | if ( ((TT_Face)loader->face)->doblend ) |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 862 | { |
| 863 | /* Deltas apply to the unscaled data. */ |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 864 | FT_Vector* deltas; |
| 865 | FT_Memory memory = loader->face->memory; |
Werner Lemberg | d21fe6e | 2007-07-10 23:10:39 +0000 | [diff] [blame] | 866 | FT_Int i; |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 867 | |
| 868 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 869 | error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(loader->face), |
| 870 | loader->glyph_index, |
Werner Lemberg | 2b54eba | 2004-05-07 07:08:14 +0000 | [diff] [blame] | 871 | &deltas, |
| 872 | n_points ); |
Werner Lemberg | 2b54eba | 2004-05-07 07:08:14 +0000 | [diff] [blame] | 873 | if ( error ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 874 | return error; |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 875 | |
| 876 | for ( i = 0; i < n_points; ++i ) |
| 877 | { |
| 878 | outline->points[i].x += deltas[i].x; |
| 879 | outline->points[i].y += deltas[i].y; |
| 880 | } |
| 881 | |
| 882 | FT_FREE( deltas ); |
| 883 | } |
| 884 | |
| 885 | #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ |
| 886 | |
David Turner | 33f5f24 | 2006-08-16 16:50:55 +0000 | [diff] [blame] | 887 | if ( IS_HINTED( loader->load_flags ) ) |
| 888 | { |
| 889 | tt_prepare_zone( &loader->zone, &gloader->current, 0, 0 ); |
| 890 | |
| 891 | FT_ARRAY_COPY( loader->zone.orus, loader->zone.cur, |
| 892 | loader->zone.n_points + 4 ); |
| 893 | } |
| 894 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 895 | /* scale the glyph */ |
| 896 | if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 897 | { |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 898 | FT_Vector* vec = outline->points; |
| 899 | FT_Vector* limit = outline->points + n_points; |
| 900 | FT_Fixed x_scale = ((TT_Size)loader->size)->metrics.x_scale; |
| 901 | FT_Fixed y_scale = ((TT_Size)loader->size)->metrics.y_scale; |
Werner Lemberg | 5811c7c | 2000-07-02 13:53:16 +0000 | [diff] [blame] | 902 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 903 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 904 | for ( ; vec < limit; vec++ ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 905 | { |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 906 | vec->x = FT_MulFix( vec->x, x_scale ); |
| 907 | vec->y = FT_MulFix( vec->y, y_scale ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 908 | } |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 909 | |
| 910 | loader->pp1 = outline->points[n_points - 4]; |
| 911 | loader->pp2 = outline->points[n_points - 3]; |
| 912 | loader->pp3 = outline->points[n_points - 2]; |
| 913 | loader->pp4 = outline->points[n_points - 1]; |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 914 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 915 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 916 | if ( IS_HINTED( loader->load_flags ) ) |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 917 | { |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 918 | loader->zone.n_points += 4; |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 919 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 920 | error = TT_Hint_Glyph( loader, 0 ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 921 | } |
| 922 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 923 | return error; |
| 924 | } |
| 925 | |
| 926 | |
| 927 | /*************************************************************************/ |
| 928 | /* */ |
| 929 | /* <Function> */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 930 | /* TT_Process_Composite_Component */ |
| 931 | /* */ |
| 932 | /* <Description> */ |
| 933 | /* Once a composite component has been loaded, it needs to be */ |
| 934 | /* processed. Usually, this means transforming and translating. */ |
| 935 | /* */ |
| 936 | static FT_Error |
| 937 | TT_Process_Composite_Component( TT_Loader loader, |
| 938 | FT_SubGlyph subglyph, |
| 939 | FT_UInt start_point, |
| 940 | FT_UInt num_base_points ) |
| 941 | { |
| 942 | FT_GlyphLoader gloader = loader->gloader; |
| 943 | FT_Vector* base_vec = gloader->base.outline.points; |
| 944 | FT_UInt num_points = gloader->base.outline.n_points; |
| 945 | FT_Bool have_scale; |
| 946 | FT_Pos x, y; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 947 | |
David Turner | 18e4443 | 2005-09-23 13:22:10 +0000 | [diff] [blame] | 948 | |
| 949 | have_scale = FT_BOOL( subglyph->flags & ( WE_HAVE_A_SCALE | |
| 950 | WE_HAVE_AN_XY_SCALE | |
| 951 | WE_HAVE_A_2X2 ) ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 952 | |
| 953 | /* perform the transform required for this subglyph */ |
| 954 | if ( have_scale ) |
| 955 | { |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 956 | FT_UInt i; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 957 | |
| 958 | |
| 959 | for ( i = num_base_points; i < num_points; i++ ) |
| 960 | FT_Vector_Transform( base_vec + i, &subglyph->transform ); |
| 961 | } |
| 962 | |
| 963 | /* get offset */ |
| 964 | if ( !( subglyph->flags & ARGS_ARE_XY_VALUES ) ) |
| 965 | { |
| 966 | FT_UInt k = subglyph->arg1; |
| 967 | FT_UInt l = subglyph->arg2; |
| 968 | FT_Vector* p1; |
| 969 | FT_Vector* p2; |
| 970 | |
| 971 | |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 972 | /* match l-th point of the newly loaded component to the k-th point */ |
| 973 | /* of the previously loaded components. */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 974 | |
| 975 | /* change to the point numbers used by our outline */ |
| 976 | k += start_point; |
| 977 | l += num_base_points; |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 978 | if ( k >= num_base_points || |
| 979 | l >= num_points ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 980 | return TT_Err_Invalid_Composite; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 981 | |
| 982 | p1 = gloader->base.outline.points + k; |
| 983 | p2 = gloader->base.outline.points + l; |
| 984 | |
| 985 | x = p1->x - p2->x; |
| 986 | y = p1->y - p2->y; |
| 987 | } |
| 988 | else |
| 989 | { |
| 990 | x = subglyph->arg1; |
| 991 | y = subglyph->arg2; |
| 992 | |
| 993 | if ( !x && !y ) |
| 994 | return TT_Err_Ok; |
| 995 | |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 996 | /* Use a default value dependent on */ |
| 997 | /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old TT */ |
| 998 | /* fonts which don't set the xxx_COMPONENT_OFFSET bit. */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 999 | |
| 1000 | if ( have_scale && |
| 1001 | #ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED |
| 1002 | !( subglyph->flags & UNSCALED_COMPONENT_OFFSET ) ) |
| 1003 | #else |
| 1004 | ( subglyph->flags & SCALED_COMPONENT_OFFSET ) ) |
| 1005 | #endif |
| 1006 | { |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 1007 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1008 | #if 0 |
| 1009 | |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1010 | /*************************************************************************/ |
| 1011 | /* */ |
| 1012 | /* This algorithm is what Apple documents. But it doesn't work. */ |
| 1013 | /* */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1014 | int a = subglyph->transform.xx > 0 ? subglyph->transform.xx |
| 1015 | : -subglyph->transform.xx; |
| 1016 | int b = subglyph->transform.yx > 0 ? subglyph->transform.yx |
| 1017 | : -subglyph->transform.yx; |
| 1018 | int c = subglyph->transform.xy > 0 ? subglyph->transform.xy |
| 1019 | : -subglyph->transform.xy; |
| 1020 | int d = subglyph->transform.yy > 0 ? subglyph->transform.yy |
| 1021 | : -subglyph->transform.yy; |
| 1022 | int m = a > b ? a : b; |
| 1023 | int n = c > d ? c : d; |
| 1024 | |
| 1025 | |
| 1026 | if ( a - b <= 33 && a - b >= -33 ) |
| 1027 | m *= 2; |
| 1028 | if ( c - d <= 33 && c - d >= -33 ) |
| 1029 | n *= 2; |
| 1030 | x = FT_MulFix( x, m ); |
| 1031 | y = FT_MulFix( y, n ); |
| 1032 | |
| 1033 | #else /* 0 */ |
| 1034 | |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1035 | /*************************************************************************/ |
| 1036 | /* */ |
| 1037 | /* This algorithm is a guess and works much better than the above. */ |
| 1038 | /* */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1039 | FT_Fixed mac_xscale = FT_SqrtFixed( |
suzuki toshiya | 9fc4094 | 2009-08-01 00:32:14 +0900 | [diff] [blame] | 1040 | (FT_Int32)FT_MulFix( subglyph->transform.xx, |
| 1041 | subglyph->transform.xx ) + |
| 1042 | (FT_Int32)FT_MulFix( subglyph->transform.xy, |
| 1043 | subglyph->transform.xy ) ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1044 | FT_Fixed mac_yscale = FT_SqrtFixed( |
suzuki toshiya | 9fc4094 | 2009-08-01 00:32:14 +0900 | [diff] [blame] | 1045 | (FT_Int32)FT_MulFix( subglyph->transform.yy, |
| 1046 | subglyph->transform.yy ) + |
| 1047 | (FT_Int32)FT_MulFix( subglyph->transform.yx, |
| 1048 | subglyph->transform.yx ) ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1049 | |
| 1050 | |
| 1051 | x = FT_MulFix( x, mac_xscale ); |
| 1052 | y = FT_MulFix( y, mac_yscale ); |
| 1053 | |
| 1054 | #endif /* 0 */ |
| 1055 | |
| 1056 | } |
| 1057 | |
| 1058 | if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) |
| 1059 | { |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1060 | FT_Fixed x_scale = ((TT_Size)loader->size)->metrics.x_scale; |
| 1061 | FT_Fixed y_scale = ((TT_Size)loader->size)->metrics.y_scale; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1062 | |
| 1063 | |
| 1064 | x = FT_MulFix( x, x_scale ); |
| 1065 | y = FT_MulFix( y, y_scale ); |
| 1066 | |
| 1067 | if ( subglyph->flags & ROUND_XY_TO_GRID ) |
| 1068 | { |
| 1069 | x = FT_PIX_ROUND( x ); |
| 1070 | y = FT_PIX_ROUND( y ); |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | if ( x || y ) |
| 1076 | translate_array( num_points - num_base_points, |
| 1077 | base_vec + num_base_points, |
| 1078 | x, y ); |
| 1079 | |
| 1080 | return TT_Err_Ok; |
| 1081 | } |
| 1082 | |
| 1083 | |
| 1084 | /*************************************************************************/ |
| 1085 | /* */ |
| 1086 | /* <Function> */ |
| 1087 | /* TT_Process_Composite_Glyph */ |
| 1088 | /* */ |
| 1089 | /* <Description> */ |
| 1090 | /* This is slightly different from TT_Process_Simple_Glyph, in that */ |
Werner Lemberg | 4b2e83d | 2007-02-01 07:58:02 +0000 | [diff] [blame] | 1091 | /* its sole purpose is to hint the glyph. Thus this function is */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1092 | /* only available when bytecode interpreter is enabled. */ |
| 1093 | /* */ |
| 1094 | static FT_Error |
| 1095 | TT_Process_Composite_Glyph( TT_Loader loader, |
| 1096 | FT_UInt start_point, |
| 1097 | FT_UInt start_contour ) |
| 1098 | { |
| 1099 | FT_Error error; |
| 1100 | FT_Outline* outline; |
Werner Lemberg | a2da05c | 2006-06-25 06:27:27 +0000 | [diff] [blame] | 1101 | FT_UInt i; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1102 | |
| 1103 | |
| 1104 | outline = &loader->gloader->base.outline; |
| 1105 | |
| 1106 | /* make room for phantom points */ |
David Turner | 9fbd2ab | 2005-10-28 16:14:14 +0000 | [diff] [blame] | 1107 | error = FT_GLYPHLOADER_CHECK_POINTS( loader->gloader, |
| 1108 | outline->n_points + 4, |
| 1109 | 0 ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1110 | if ( error ) |
| 1111 | return error; |
| 1112 | |
| 1113 | outline->points[outline->n_points ] = loader->pp1; |
| 1114 | outline->points[outline->n_points + 1] = loader->pp2; |
| 1115 | outline->points[outline->n_points + 2] = loader->pp3; |
| 1116 | outline->points[outline->n_points + 3] = loader->pp4; |
| 1117 | |
| 1118 | outline->tags[outline->n_points ] = 0; |
| 1119 | outline->tags[outline->n_points + 1] = 0; |
| 1120 | outline->tags[outline->n_points + 2] = 0; |
| 1121 | outline->tags[outline->n_points + 3] = 0; |
| 1122 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 1123 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1124 | |
| 1125 | { |
| 1126 | FT_Stream stream = loader->stream; |
Werner Lemberg | 6da023d | 2010-05-20 15:38:00 +0200 | [diff] [blame] | 1127 | FT_UShort n_ins, max_ins; |
| 1128 | FT_ULong tmp; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1129 | |
| 1130 | |
| 1131 | /* TT_Load_Composite_Glyph only gives us the offset of instructions */ |
Werner Lemberg | 7c25946 | 2005-09-28 07:34:45 +0000 | [diff] [blame] | 1132 | /* so we read them here */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1133 | if ( FT_STREAM_SEEK( loader->ins_pos ) || |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1134 | FT_READ_USHORT( n_ins ) ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1135 | return error; |
| 1136 | |
| 1137 | FT_TRACE5(( " Instructions size = %d\n", n_ins )); |
| 1138 | |
| 1139 | /* check it */ |
Werner Lemberg | 6da023d | 2010-05-20 15:38:00 +0200 | [diff] [blame] | 1140 | max_ins = ((TT_Face)loader->face)->max_profile.maxSizeOfInstructions; |
| 1141 | if ( n_ins > max_ins ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1142 | { |
Werner Lemberg | 6da023d | 2010-05-20 15:38:00 +0200 | [diff] [blame] | 1143 | /* acroread ignores this field, so we only do a rough safety check */ |
| 1144 | if ( (FT_Int)n_ins > loader->byte_len ) |
| 1145 | { |
| 1146 | FT_TRACE1(( "TT_Process_Composite_Glyph: " |
Werner Lemberg | ae425e5 | 2010-06-29 12:31:08 +0200 | [diff] [blame] | 1147 | "too many instructions (%d) for glyph with length %d\n", |
Werner Lemberg | 6da023d | 2010-05-20 15:38:00 +0200 | [diff] [blame] | 1148 | n_ins, loader->byte_len )); |
| 1149 | return TT_Err_Too_Many_Hints; |
| 1150 | } |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1151 | |
Werner Lemberg | 6da023d | 2010-05-20 15:38:00 +0200 | [diff] [blame] | 1152 | tmp = loader->exec->glyphSize; |
| 1153 | error = Update_Max( loader->exec->memory, |
| 1154 | &tmp, |
| 1155 | sizeof ( FT_Byte ), |
| 1156 | (void*)&loader->exec->glyphIns, |
| 1157 | n_ins ); |
| 1158 | loader->exec->glyphSize = (FT_UShort)tmp; |
| 1159 | if ( error ) |
| 1160 | return error; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1161 | } |
| 1162 | else if ( n_ins == 0 ) |
| 1163 | return TT_Err_Ok; |
| 1164 | |
| 1165 | if ( FT_STREAM_READ( loader->exec->glyphIns, n_ins ) ) |
| 1166 | return error; |
| 1167 | |
| 1168 | loader->glyph->control_data = loader->exec->glyphIns; |
| 1169 | loader->glyph->control_len = n_ins; |
| 1170 | } |
| 1171 | |
| 1172 | #endif |
| 1173 | |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1174 | tt_prepare_zone( &loader->zone, &loader->gloader->base, |
| 1175 | start_point, start_contour ); |
Werner Lemberg | a2da05c | 2006-06-25 06:27:27 +0000 | [diff] [blame] | 1176 | |
| 1177 | /* Some points are likely touched during execution of */ |
| 1178 | /* instructions on components. So let's untouch them. */ |
| 1179 | for ( i = start_point; i < loader->zone.n_points; i++ ) |
Werner Lemberg | 780d7e0 | 2009-06-17 06:45:20 +0200 | [diff] [blame] | 1180 | loader->zone.tags[i] &= ~FT_CURVE_TAG_TOUCH_BOTH; |
Werner Lemberg | a2da05c | 2006-06-25 06:27:27 +0000 | [diff] [blame] | 1181 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1182 | loader->zone.n_points += 4; |
| 1183 | |
| 1184 | return TT_Hint_Glyph( loader, 1 ); |
| 1185 | } |
| 1186 | |
| 1187 | |
| 1188 | /* Calculate the four phantom points. */ |
| 1189 | /* The first two stand for horizontal origin and advance. */ |
| 1190 | /* The last two stand for vertical origin and advance. */ |
| 1191 | #define TT_LOADER_SET_PP( loader ) \ |
| 1192 | do { \ |
| 1193 | (loader)->pp1.x = (loader)->bbox.xMin - (loader)->left_bearing; \ |
| 1194 | (loader)->pp1.y = 0; \ |
| 1195 | (loader)->pp2.x = (loader)->pp1.x + (loader)->advance; \ |
| 1196 | (loader)->pp2.y = 0; \ |
| 1197 | (loader)->pp3.x = 0; \ |
| 1198 | (loader)->pp3.y = (loader)->top_bearing + (loader)->bbox.yMax; \ |
| 1199 | (loader)->pp4.x = 0; \ |
| 1200 | (loader)->pp4.y = (loader)->pp3.y - (loader)->vadvance; \ |
| 1201 | } while ( 0 ) |
| 1202 | |
| 1203 | |
| 1204 | /*************************************************************************/ |
| 1205 | /* */ |
| 1206 | /* <Function> */ |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1207 | /* load_truetype_glyph */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1208 | /* */ |
| 1209 | /* <Description> */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1210 | /* Loads a given truetype glyph. Handles composites and uses a */ |
| 1211 | /* TT_Loader object. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1212 | /* */ |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 1213 | static FT_Error |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 1214 | load_truetype_glyph( TT_Loader loader, |
David Turner | 77b68b8 | 2003-01-08 09:59:17 +0000 | [diff] [blame] | 1215 | FT_UInt glyph_index, |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1216 | FT_UInt recurse_count, |
| 1217 | FT_Bool header_only ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1218 | { |
Werner Lemberg | c0aeef4 | 2009-11-08 07:58:05 +0100 | [diff] [blame] | 1219 | FT_Error error = TT_Err_Ok; |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 1220 | FT_Fixed x_scale, y_scale; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1221 | FT_ULong offset; |
| 1222 | TT_Face face = (TT_Face)loader->face; |
| 1223 | FT_GlyphLoader gloader = loader->gloader; |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 1224 | FT_Bool opened_frame = 0; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1225 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1226 | #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1227 | FT_Vector* deltas = NULL; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1228 | #endif |
| 1229 | |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1230 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
Werner Lemberg | 2b54eba | 2004-05-07 07:08:14 +0000 | [diff] [blame] | 1231 | FT_StreamRec inc_stream; |
| 1232 | FT_Data glyph_data; |
| 1233 | FT_Bool glyph_data_loaded = 0; |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 1234 | #endif |
| 1235 | |
Werner Lemberg | 6ab5624 | 2003-06-04 07:59:58 +0000 | [diff] [blame] | 1236 | |
Werner Lemberg | 0f6f367 | 2007-07-04 19:57:45 +0000 | [diff] [blame] | 1237 | /* some fonts have an incorrect value of `maxComponentDepth', */ |
| 1238 | /* thus we allow depth 1 to catch the majority of them */ |
| 1239 | if ( recurse_count > 1 && |
| 1240 | recurse_count > face->max_profile.maxComponentDepth ) |
David Turner | 77b68b8 | 2003-01-08 09:59:17 +0000 | [diff] [blame] | 1241 | { |
| 1242 | error = TT_Err_Invalid_Composite; |
| 1243 | goto Exit; |
| 1244 | } |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 1245 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1246 | /* check glyph index */ |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1247 | if ( glyph_index >= (FT_UInt)face->root.num_glyphs ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1248 | { |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1249 | error = TT_Err_Invalid_Glyph_Index; |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 1250 | goto Exit; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
David Turner | 861ba62 | 2000-02-15 12:54:51 +0000 | [diff] [blame] | 1253 | loader->glyph_index = glyph_index; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1254 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1255 | if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1256 | { |
David Turner | 2f0fdb9 | 2004-06-21 21:16:56 +0000 | [diff] [blame] | 1257 | x_scale = ((TT_Size)loader->size)->metrics.x_scale; |
| 1258 | y_scale = ((TT_Size)loader->size)->metrics.y_scale; |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1259 | } |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1260 | else |
| 1261 | { |
| 1262 | x_scale = 0x10000L; |
| 1263 | y_scale = 0x10000L; |
| 1264 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1265 | |
Werner Lemberg | 422210b | 2009-11-03 08:11:02 +0100 | [diff] [blame] | 1266 | tt_get_metrics( loader, glyph_index ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1267 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1268 | /* Set `offset' to the start of the glyph relative to the start of */ |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1269 | /* the `glyf' table, and `byte_len' to the length of the glyph in */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1270 | /* bytes. */ |
| 1271 | |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1272 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1273 | |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 1274 | /* If we are loading glyph data via the incremental interface, set */ |
| 1275 | /* the loader stream to a memory stream reading the data returned */ |
| 1276 | /* by the interface. */ |
Graham Asher | ce12182 | 2002-08-01 15:29:17 +0000 | [diff] [blame] | 1277 | if ( face->root.internal->incremental_interface ) |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1278 | { |
Graham Asher | ce12182 | 2002-08-01 15:29:17 +0000 | [diff] [blame] | 1279 | error = face->root.internal->incremental_interface->funcs->get_glyph_data( |
| 1280 | face->root.internal->incremental_interface->object, |
| 1281 | glyph_index, &glyph_data ); |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 1282 | if ( error ) |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1283 | goto Exit; |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 1284 | |
Graham Asher | ce12182 | 2002-08-01 15:29:17 +0000 | [diff] [blame] | 1285 | glyph_data_loaded = 1; |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1286 | offset = 0; |
Wu, Chia-I (吳佳一) | 9a2b3b6 | 2006-02-14 08:37:03 +0000 | [diff] [blame] | 1287 | loader->byte_len = glyph_data.length; |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1288 | |
Werner Lemberg | b3d5e9c | 2002-07-28 05:05:24 +0000 | [diff] [blame] | 1289 | FT_MEM_ZERO( &inc_stream, sizeof ( inc_stream ) ); |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1290 | FT_Stream_OpenMemory( &inc_stream, |
| 1291 | glyph_data.pointer, glyph_data.length ); |
| 1292 | |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1293 | loader->stream = &inc_stream; |
| 1294 | } |
| 1295 | else |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 1296 | |
| 1297 | #endif /* FT_CONFIG_OPTION_INCREMENTAL */ |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1298 | |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1299 | offset = tt_face_get_location( face, glyph_index, |
| 1300 | (FT_UInt*)&loader->byte_len ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1301 | |
Werner Lemberg | bf391cb | 2008-01-10 08:47:08 +0000 | [diff] [blame] | 1302 | if ( loader->byte_len > 0 ) |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1303 | { |
Werner Lemberg | fe6da50 | 2010-01-05 10:10:15 +0100 | [diff] [blame] | 1304 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
Werner Lemberg | 3445e4f | 2010-01-04 15:53:27 +0100 | [diff] [blame] | 1305 | /* for the incremental interface, `glyf_offset' is always zero */ |
| 1306 | if ( !loader->glyf_offset && |
| 1307 | !face->root.internal->incremental_interface ) |
Werner Lemberg | fe6da50 | 2010-01-05 10:10:15 +0100 | [diff] [blame] | 1308 | #else |
| 1309 | if ( !loader->glyf_offset ) |
| 1310 | #endif /* FT_CONFIG_OPTION_INCREMENTAL */ |
Werner Lemberg | 1474f43 | 2008-12-09 06:51:56 +0000 | [diff] [blame] | 1311 | { |
Werner Lemberg | 858abbe | 2009-06-26 06:15:41 +0200 | [diff] [blame] | 1312 | FT_TRACE2(( "no `glyf' table but non-zero `loca' entry\n" )); |
Werner Lemberg | 1474f43 | 2008-12-09 06:51:56 +0000 | [diff] [blame] | 1313 | error = TT_Err_Invalid_Table; |
| 1314 | goto Exit; |
| 1315 | } |
| 1316 | |
Werner Lemberg | bf391cb | 2008-01-10 08:47:08 +0000 | [diff] [blame] | 1317 | error = face->access_glyph_frame( loader, glyph_index, |
| 1318 | loader->glyf_offset + offset, |
| 1319 | loader->byte_len ); |
| 1320 | if ( error ) |
| 1321 | goto Exit; |
| 1322 | |
| 1323 | opened_frame = 1; |
| 1324 | |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1325 | /* read glyph header first */ |
Werner Lemberg | bf391cb | 2008-01-10 08:47:08 +0000 | [diff] [blame] | 1326 | error = face->read_glyph_header( loader ); |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1327 | if ( error || header_only ) |
Werner Lemberg | bf391cb | 2008-01-10 08:47:08 +0000 | [diff] [blame] | 1328 | goto Exit; |
| 1329 | } |
| 1330 | |
| 1331 | if ( loader->byte_len == 0 || loader->n_contours == 0 ) |
| 1332 | { |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1333 | loader->bbox.xMin = 0; |
| 1334 | loader->bbox.xMax = 0; |
| 1335 | loader->bbox.yMin = 0; |
| 1336 | loader->bbox.yMax = 0; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1337 | |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1338 | if ( header_only ) |
| 1339 | goto Exit; |
| 1340 | |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 1341 | /* must initialize points before (possibly) overriding */ |
| 1342 | /* glyph metrics from the incremental interface */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1343 | TT_LOADER_SET_PP( loader ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1344 | |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 1345 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
| 1346 | tt_get_metrics_incr_overrides( loader, glyph_index ); |
| 1347 | #endif |
| 1348 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 1349 | #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1350 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 1351 | if ( ((TT_Face)(loader->face))->doblend ) |
| 1352 | { |
| 1353 | /* this must be done before scaling */ |
| 1354 | FT_Memory memory = loader->face->memory; |
| 1355 | |
| 1356 | |
Werner Lemberg | 5afaa67 | 2004-06-28 14:19:15 +0000 | [diff] [blame] | 1357 | error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(loader->face), |
| 1358 | glyph_index, &deltas, 4 ); |
David Turner | c28b8c1 | 2004-06-24 20:18:24 +0000 | [diff] [blame] | 1359 | if ( error ) |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 1360 | goto Exit; |
| 1361 | |
| 1362 | loader->pp1.x += deltas[0].x; loader->pp1.y += deltas[0].y; |
| 1363 | loader->pp2.x += deltas[1].x; loader->pp2.y += deltas[1].y; |
| 1364 | loader->pp3.x += deltas[2].x; loader->pp3.y += deltas[2].y; |
| 1365 | loader->pp4.x += deltas[3].x; loader->pp4.y += deltas[3].y; |
| 1366 | |
| 1367 | FT_FREE( deltas ); |
| 1368 | } |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1369 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 1370 | #endif |
| 1371 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1372 | if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 1373 | { |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1374 | loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1375 | loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1376 | loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 1377 | loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); |
| 1378 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1379 | |
Werner Lemberg | 1429db6 | 2001-04-02 23:54:01 +0000 | [diff] [blame] | 1380 | error = TT_Err_Ok; |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 1381 | goto Exit; |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1382 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1383 | |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 1384 | /* must initialize points before (possibly) overriding */ |
| 1385 | /* glyph metrics from the incremental interface */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1386 | TT_LOADER_SET_PP( loader ); |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 1387 | |
Chris Liddell | 10cf388 | 2010-02-18 17:09:30 +0100 | [diff] [blame] | 1388 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
| 1389 | tt_get_metrics_incr_overrides( loader, glyph_index ); |
| 1390 | #endif |
| 1391 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1392 | /***********************************************************************/ |
| 1393 | /***********************************************************************/ |
| 1394 | /***********************************************************************/ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1395 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1396 | /* if it is a simple glyph, load it */ |
| 1397 | |
Werner Lemberg | bf391cb | 2008-01-10 08:47:08 +0000 | [diff] [blame] | 1398 | if ( loader->n_contours > 0 ) |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1399 | { |
David Turner | 994d774 | 2000-06-25 04:49:19 +0000 | [diff] [blame] | 1400 | error = face->read_simple_glyph( loader ); |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1401 | if ( error ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1402 | goto Exit; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 1403 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1404 | /* all data have been read */ |
| 1405 | face->forget_glyph_frame( loader ); |
| 1406 | opened_frame = 0; |
Werner Lemberg | 5811c7c | 2000-07-02 13:53:16 +0000 | [diff] [blame] | 1407 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1408 | error = TT_Process_Simple_Glyph( loader ); |
Werner Lemberg | dcd2e14 | 2000-06-25 07:43:15 +0000 | [diff] [blame] | 1409 | if ( error ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1410 | goto Exit; |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 1411 | |
| 1412 | FT_GlyphLoader_Add( gloader ); |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1413 | } |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1414 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1415 | /***********************************************************************/ |
| 1416 | /***********************************************************************/ |
| 1417 | /***********************************************************************/ |
| 1418 | |
| 1419 | /* otherwise, load a composite! */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1420 | else if ( loader->n_contours == -1 ) |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1421 | { |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 1422 | FT_UInt start_point; |
| 1423 | FT_UInt start_contour; |
| 1424 | FT_ULong ins_pos; /* position of composite instructions, if any */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1425 | |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 1426 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1427 | start_point = gloader->base.outline.n_points; |
| 1428 | start_contour = gloader->base.outline.n_contours; |
| 1429 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1430 | /* for each subglyph, read composite header */ |
David Turner | 994d774 | 2000-06-25 04:49:19 +0000 | [diff] [blame] | 1431 | error = face->read_composite_glyph( loader ); |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1432 | if ( error ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1433 | goto Exit; |
David Turner | ed7f62a | 2000-03-28 11:19:28 +0000 | [diff] [blame] | 1434 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1435 | /* store the offset of instructions */ |
David Turner | c6a9220 | 2000-07-04 18:12:13 +0000 | [diff] [blame] | 1436 | ins_pos = loader->ins_pos; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1437 | |
| 1438 | /* all data we need are read */ |
David Turner | 994d774 | 2000-06-25 04:49:19 +0000 | [diff] [blame] | 1439 | face->forget_glyph_frame( loader ); |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 1440 | opened_frame = 0; |
| 1441 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 1442 | #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT |
| 1443 | |
| 1444 | if ( face->doblend ) |
| 1445 | { |
| 1446 | FT_Int i, limit; |
| 1447 | FT_SubGlyph subglyph; |
| 1448 | FT_Memory memory = face->root.memory; |
| 1449 | |
| 1450 | |
| 1451 | /* this provides additional offsets */ |
| 1452 | /* for each component's translation */ |
| 1453 | |
Werner Lemberg | e12ed56 | 2007-06-17 05:31:23 +0000 | [diff] [blame] | 1454 | if ( ( error = TT_Vary_Get_Glyph_Deltas( |
| 1455 | face, |
| 1456 | glyph_index, |
| 1457 | &deltas, |
| 1458 | gloader->current.num_subglyphs + 4 )) != 0 ) |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 1459 | goto Exit; |
| 1460 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 1461 | subglyph = gloader->current.subglyphs + gloader->base.num_subglyphs; |
| 1462 | limit = gloader->current.num_subglyphs; |
| 1463 | |
| 1464 | for ( i = 0; i < limit; ++i, ++subglyph ) |
| 1465 | { |
| 1466 | if ( subglyph->flags & ARGS_ARE_XY_VALUES ) |
| 1467 | { |
suzuki toshiya | 9206eba | 2009-08-01 00:32:17 +0900 | [diff] [blame] | 1468 | /* XXX: overflow check for subglyph->{arg1,arg2}. */ |
| 1469 | /* deltas[i].{x,y} must be within signed 16-bit, */ |
| 1470 | /* but the restriction of summed delta is not clear */ |
| 1471 | subglyph->arg1 += (FT_Int16)deltas[i].x; |
| 1472 | subglyph->arg2 += (FT_Int16)deltas[i].y; |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | loader->pp1.x += deltas[i + 0].x; loader->pp1.y += deltas[i + 0].y; |
| 1477 | loader->pp2.x += deltas[i + 1].x; loader->pp2.y += deltas[i + 1].y; |
| 1478 | loader->pp3.x += deltas[i + 2].x; loader->pp3.y += deltas[i + 2].y; |
| 1479 | loader->pp4.x += deltas[i + 3].x; loader->pp4.y += deltas[i + 3].y; |
| 1480 | |
| 1481 | FT_FREE( deltas ); |
| 1482 | } |
| 1483 | |
| 1484 | #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ |
| 1485 | |
| 1486 | if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) |
| 1487 | { |
| 1488 | loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale ); |
| 1489 | loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale ); |
| 1490 | loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale ); |
| 1491 | loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale ); |
| 1492 | } |
| 1493 | |
David Turner | ed7f62a | 2000-03-28 11:19:28 +0000 | [diff] [blame] | 1494 | /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1495 | /* `as is' in the glyph slot (the client application will be */ |
Werner Lemberg | eed446d | 2002-08-16 12:46:52 +0000 | [diff] [blame] | 1496 | /* responsible for interpreting these data)... */ |
David Turner | ed7f62a | 2000-03-28 11:19:28 +0000 | [diff] [blame] | 1497 | if ( loader->load_flags & FT_LOAD_NO_RECURSE ) |
| 1498 | { |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 1499 | FT_GlyphLoader_Add( gloader ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1500 | loader->glyph->format = FT_GLYPH_FORMAT_COMPOSITE; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 1501 | |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 1502 | goto Exit; |
David Turner | ed7f62a | 2000-03-28 11:19:28 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1505 | /*********************************************************************/ |
Werner Lemberg | dcd2e14 | 2000-06-25 07:43:15 +0000 | [diff] [blame] | 1506 | /*********************************************************************/ |
| 1507 | /*********************************************************************/ |
| 1508 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1509 | { |
Werner Lemberg | 57a94c4 | 2008-05-25 16:49:29 +0000 | [diff] [blame] | 1510 | FT_UInt n, num_base_points; |
| 1511 | FT_SubGlyph subglyph = 0; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 1512 | |
Werner Lemberg | 57a94c4 | 2008-05-25 16:49:29 +0000 | [diff] [blame] | 1513 | FT_UInt num_points = start_point; |
| 1514 | FT_UInt num_subglyphs = gloader->current.num_subglyphs; |
| 1515 | FT_UInt num_base_subgs = gloader->base.num_subglyphs; |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 1516 | |
Werner Lemberg | 57a94c4 | 2008-05-25 16:49:29 +0000 | [diff] [blame] | 1517 | FT_Stream old_stream = loader->stream; |
Werner Lemberg | 6da023d | 2010-05-20 15:38:00 +0200 | [diff] [blame] | 1518 | FT_Int old_byte_len = loader->byte_len; |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 1519 | |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 1520 | |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 1521 | FT_GlyphLoader_Add( gloader ); |
Werner Lemberg | bd5ae40 | 2000-07-05 04:32:02 +0000 | [diff] [blame] | 1522 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1523 | /* read each subglyph independently */ |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1524 | for ( n = 0; n < num_subglyphs; n++ ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1525 | { |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1526 | FT_Vector pp[4]; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1527 | |
Werner Lemberg | dcd2e14 | 2000-06-25 07:43:15 +0000 | [diff] [blame] | 1528 | |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1529 | /* Each time we call load_truetype_glyph in this loop, the */ |
| 1530 | /* value of `gloader.base.subglyphs' can change due to table */ |
| 1531 | /* reallocations. We thus need to recompute the subglyph */ |
| 1532 | /* pointer on each iteration. */ |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 1533 | subglyph = gloader->base.subglyphs + num_base_subgs + n; |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1534 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1535 | pp[0] = loader->pp1; |
| 1536 | pp[1] = loader->pp2; |
| 1537 | pp[2] = loader->pp3; |
| 1538 | pp[3] = loader->pp4; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1539 | |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 1540 | num_base_points = gloader->base.outline.n_points; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1541 | |
David Turner | 77b68b8 | 2003-01-08 09:59:17 +0000 | [diff] [blame] | 1542 | error = load_truetype_glyph( loader, subglyph->index, |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1543 | recurse_count + 1, FALSE ); |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1544 | if ( error ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1545 | goto Exit; |
David Turner | 3475e7f | 2000-05-17 20:56:01 +0000 | [diff] [blame] | 1546 | |
David Turner | 61d6b2b | 2001-05-16 17:49:07 +0000 | [diff] [blame] | 1547 | /* restore subglyph pointer */ |
David Turner | f0df85b | 2000-06-22 00:17:42 +0000 | [diff] [blame] | 1548 | subglyph = gloader->base.subglyphs + num_base_subgs + n; |
| 1549 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1550 | if ( !( subglyph->flags & USE_MY_METRICS ) ) |
David Turner | 7bb7fed | 2000-02-28 11:23:36 +0000 | [diff] [blame] | 1551 | { |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1552 | loader->pp1 = pp[0]; |
| 1553 | loader->pp2 = pp[1]; |
| 1554 | loader->pp3 = pp[2]; |
| 1555 | loader->pp4 = pp[3]; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1556 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1557 | |
Werner Lemberg | dcd2e14 | 2000-06-25 07:43:15 +0000 | [diff] [blame] | 1558 | num_points = gloader->base.outline.n_points; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1559 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1560 | if ( num_points == num_base_points ) |
| 1561 | continue; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1562 | |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 1563 | /* gloader->base.outline consists of three parts: */ |
| 1564 | /* 0 -(1)-> start_point -(2)-> num_base_points -(3)-> n_points. */ |
| 1565 | /* */ |
| 1566 | /* (1): exists from the beginning */ |
| 1567 | /* (2): components that have been loaded so far */ |
| 1568 | /* (3): the newly loaded component */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1569 | TT_Process_Composite_Component( loader, subglyph, start_point, |
| 1570 | num_base_points ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1571 | } |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1572 | |
Werner Lemberg | 6da023d | 2010-05-20 15:38:00 +0200 | [diff] [blame] | 1573 | loader->stream = old_stream; |
| 1574 | loader->byte_len = old_byte_len; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1575 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1576 | /* process the glyph */ |
| 1577 | loader->ins_pos = ins_pos; |
| 1578 | if ( IS_HINTED( loader->load_flags ) && |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1579 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 1580 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1581 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1582 | subglyph->flags & WE_HAVE_INSTR && |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1583 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1584 | #endif |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1585 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1586 | num_points > start_point ) |
| 1587 | TT_Process_Composite_Glyph( loader, start_point, start_contour ); |
Werner Lemberg | dcd2e14 | 2000-06-25 07:43:15 +0000 | [diff] [blame] | 1588 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1589 | } |
| 1590 | } |
David Turner | 77b68b8 | 2003-01-08 09:59:17 +0000 | [diff] [blame] | 1591 | else |
| 1592 | { |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 1593 | /* invalid composite count (negative but not -1) */ |
David Turner | 77b68b8 | 2003-01-08 09:59:17 +0000 | [diff] [blame] | 1594 | error = TT_Err_Invalid_Outline; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1595 | goto Exit; |
David Turner | 77b68b8 | 2003-01-08 09:59:17 +0000 | [diff] [blame] | 1596 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1597 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1598 | /***********************************************************************/ |
| 1599 | /***********************************************************************/ |
| 1600 | /***********************************************************************/ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1601 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1602 | Exit: |
| 1603 | |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1604 | if ( opened_frame ) |
David Turner | 994d774 | 2000-06-25 04:49:19 +0000 | [diff] [blame] | 1605 | face->forget_glyph_frame( loader ); |
David Turner | 90f68b7 | 2000-06-23 12:26:14 +0000 | [diff] [blame] | 1606 | |
Graham Asher | ce12182 | 2002-08-01 15:29:17 +0000 | [diff] [blame] | 1607 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1608 | |
Werner Lemberg | 3c403e4 | 2002-08-06 21:47:40 +0000 | [diff] [blame] | 1609 | if ( glyph_data_loaded ) |
| 1610 | face->root.internal->incremental_interface->funcs->free_glyph_data( |
| 1611 | face->root.internal->incremental_interface->object, |
| 1612 | &glyph_data ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1613 | |
Graham Asher | ce12182 | 2002-08-01 15:29:17 +0000 | [diff] [blame] | 1614 | #endif |
| 1615 | |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1616 | return error; |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1620 | static FT_Error |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 1621 | compute_glyph_metrics( TT_Loader loader, |
| 1622 | FT_UInt glyph_index ) |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1623 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 1624 | FT_BBox bbox; |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 1625 | TT_Face face = (TT_Face)loader->face; |
Werner Lemberg | cf24d51 | 2001-06-18 14:23:45 +0000 | [diff] [blame] | 1626 | FT_Fixed y_scale; |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1627 | TT_GlyphSlot glyph = loader->glyph; |
David Turner | c312861 | 2000-06-23 05:02:13 +0000 | [diff] [blame] | 1628 | TT_Size size = (TT_Size)loader->size; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1629 | |
Werner Lemberg | dcd2e14 | 2000-06-25 07:43:15 +0000 | [diff] [blame] | 1630 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1631 | y_scale = 0x10000L; |
| 1632 | if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 ) |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1633 | y_scale = size->root.metrics.y_scale; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1634 | |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 1635 | if ( glyph->format != FT_GLYPH_FORMAT_COMPOSITE ) |
David Turner | ed7f62a | 2000-03-28 11:19:28 +0000 | [diff] [blame] | 1636 | FT_Outline_Get_CBox( &glyph->outline, &bbox ); |
David Turner | ed7f62a | 2000-03-28 11:19:28 +0000 | [diff] [blame] | 1637 | else |
| 1638 | bbox = loader->bbox; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1639 | |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 1640 | /* get the device-independent horizontal advance; it is scaled later */ |
| 1641 | /* by the base layer. */ |
Behdad Esfahbod | 8c82ec5 | 2011-04-21 08:21:37 +0200 | [diff] [blame] | 1642 | glyph->linearHoriAdvance = loader->linear; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1643 | |
| 1644 | glyph->metrics.horiBearingX = bbox.xMin; |
| 1645 | glyph->metrics.horiBearingY = bbox.yMax; |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1646 | glyph->metrics.horiAdvance = loader->pp2.x - loader->pp1.x; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1647 | |
Bram Tassyns | 4694ea2 | 2009-09-02 13:06:33 +0200 | [diff] [blame] | 1648 | /* adjust advance width to the value contained in the hdmx table */ |
| 1649 | if ( !face->postscript.isFixedPitch && |
| 1650 | IS_HINTED( loader->load_flags ) ) |
| 1651 | { |
| 1652 | FT_Byte* widthp; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1653 | |
Bram Tassyns | 4694ea2 | 2009-09-02 13:06:33 +0200 | [diff] [blame] | 1654 | |
| 1655 | widthp = tt_face_get_device_metrics( face, |
| 1656 | size->root.metrics.x_ppem, |
| 1657 | glyph_index ); |
| 1658 | |
| 1659 | if ( widthp ) |
| 1660 | glyph->metrics.horiAdvance = *widthp << 6; |
| 1661 | } |
| 1662 | |
| 1663 | /* set glyph dimensions */ |
| 1664 | glyph->metrics.width = bbox.xMax - bbox.xMin; |
| 1665 | glyph->metrics.height = bbox.yMax - bbox.yMin; |
| 1666 | |
| 1667 | /* Now take care of vertical metrics. In the case where there is */ |
| 1668 | /* no vertical information within the font (relatively common), */ |
| 1669 | /* create some metrics manually */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1670 | { |
Werner Lemberg | 1723dcc | 2006-01-15 07:30:32 +0000 | [diff] [blame] | 1671 | FT_Pos top; /* scaled vertical top side bearing */ |
| 1672 | FT_Pos advance; /* scaled vertical advance height */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1673 | |
Werner Lemberg | 56a4d87 | 2004-06-03 07:56:21 +0000 | [diff] [blame] | 1674 | |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1675 | /* Get the unscaled top bearing and advance height. */ |
Werner Lemberg | d30062d | 2009-09-08 07:06:54 +0200 | [diff] [blame] | 1676 | if ( face->vertical_info && |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1677 | face->vertical.number_Of_VMetrics > 0 ) |
| 1678 | { |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1679 | top = (FT_Short)FT_DivFix( loader->pp3.y - bbox.yMax, |
| 1680 | y_scale ); |
Werner Lemberg | 49f4d34 | 2005-06-16 19:07:08 +0000 | [diff] [blame] | 1681 | |
| 1682 | if ( loader->pp3.y <= loader->pp4.y ) |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1683 | advance = 0; |
Werner Lemberg | 49f4d34 | 2005-06-16 19:07:08 +0000 | [diff] [blame] | 1684 | else |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1685 | advance = (FT_UShort)FT_DivFix( loader->pp3.y - loader->pp4.y, |
| 1686 | y_scale ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1687 | } |
| 1688 | else |
| 1689 | { |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1690 | FT_Pos height; |
Werner Lemberg | 49f4d34 | 2005-06-16 19:07:08 +0000 | [diff] [blame] | 1691 | |
| 1692 | |
| 1693 | /* XXX Compute top side bearing and advance height in */ |
| 1694 | /* Get_VMetrics instead of here. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1695 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1696 | /* NOTE: The OS/2 values are the only `portable' ones, */ |
| 1697 | /* which is why we use them, if there is an OS/2 */ |
| 1698 | /* table in the font. Otherwise, we use the */ |
| 1699 | /* values defined in the horizontal header. */ |
Werner Lemberg | 49f4d34 | 2005-06-16 19:07:08 +0000 | [diff] [blame] | 1700 | |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1701 | height = (FT_Short)FT_DivFix( bbox.yMax - bbox.yMin, |
| 1702 | y_scale ); |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 1703 | if ( face->os2.version != 0xFFFFU ) |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1704 | advance = (FT_Pos)( face->os2.sTypoAscender - |
| 1705 | face->os2.sTypoDescender ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1706 | else |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1707 | advance = (FT_Pos)( face->horizontal.Ascender - |
| 1708 | face->horizontal.Descender ); |
Werner Lemberg | 49f4d34 | 2005-06-16 19:07:08 +0000 | [diff] [blame] | 1709 | |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1710 | top = ( advance - height ) / 2; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
Graham Asher | 46960df | 2003-02-13 17:49:27 +0000 | [diff] [blame] | 1713 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
Graham Asher | 46960df | 2003-02-13 17:49:27 +0000 | [diff] [blame] | 1714 | { |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1715 | FT_Incremental_InterfaceRec* incr; |
| 1716 | FT_Incremental_MetricsRec metrics; |
| 1717 | FT_Error error; |
Graham Asher | 46960df | 2003-02-13 17:49:27 +0000 | [diff] [blame] | 1718 | |
Werner Lemberg | b442ca1 | 2003-04-23 15:50:27 +0000 | [diff] [blame] | 1719 | |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1720 | incr = face->root.internal->incremental_interface; |
Graham Asher | 46960df | 2003-02-13 17:49:27 +0000 | [diff] [blame] | 1721 | |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1722 | /* If this is an incrementally loaded font see if there are */ |
| 1723 | /* overriding metrics for this glyph. */ |
| 1724 | if ( incr && incr->funcs->get_glyph_metrics ) |
| 1725 | { |
| 1726 | metrics.bearing_x = 0; |
| 1727 | metrics.bearing_y = top; |
| 1728 | metrics.advance = advance; |
Werner Lemberg | 1723dcc | 2006-01-15 07:30:32 +0000 | [diff] [blame] | 1729 | |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1730 | error = incr->funcs->get_glyph_metrics( incr->object, |
| 1731 | glyph_index, |
| 1732 | TRUE, |
| 1733 | &metrics ); |
| 1734 | if ( error ) |
| 1735 | return error; |
Graham Asher | 46960df | 2003-02-13 17:49:27 +0000 | [diff] [blame] | 1736 | |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1737 | top = metrics.bearing_y; |
| 1738 | advance = metrics.advance; |
| 1739 | } |
Graham Asher | 46960df | 2003-02-13 17:49:27 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
Werner Lemberg | 8bb07e6 | 2004-03-27 08:43:17 +0000 | [diff] [blame] | 1742 | /* GWW: Do vertical metrics get loaded incrementally too? */ |
| 1743 | |
Graham Asher | 46960df | 2003-02-13 17:49:27 +0000 | [diff] [blame] | 1744 | #endif /* FT_CONFIG_OPTION_INCREMENTAL */ |
| 1745 | |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1746 | glyph->linearVertAdvance = advance; |
| 1747 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1748 | /* scale the metrics */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1749 | if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1750 | { |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1751 | top = FT_MulFix( top, y_scale ); |
Wu, Chia-I (吳佳一) | 212aee0 | 2006-01-15 06:24:53 +0000 | [diff] [blame] | 1752 | advance = FT_MulFix( advance, y_scale ); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1753 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1754 | |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1755 | /* XXX: for now, we have no better algorithm for the lsb, but it */ |
| 1756 | /* should work fine. */ |
| 1757 | /* */ |
Bram Tassyns | 4694ea2 | 2009-09-02 13:06:33 +0200 | [diff] [blame] | 1758 | glyph->metrics.vertBearingX = glyph->metrics.horiBearingX - |
| 1759 | glyph->metrics.horiAdvance / 2; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1760 | glyph->metrics.vertBearingY = top; |
| 1761 | glyph->metrics.vertAdvance = advance; |
| 1762 | } |
| 1763 | |
Graham Asher | 13217f2 | 2002-07-18 15:59:23 +0000 | [diff] [blame] | 1764 | return 0; |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1765 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1766 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1767 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1768 | #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1769 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1770 | static FT_Error |
| 1771 | load_sbit_image( TT_Size size, |
| 1772 | TT_GlyphSlot glyph, |
| 1773 | FT_UInt glyph_index, |
| 1774 | FT_Int32 load_flags ) |
| 1775 | { |
| 1776 | TT_Face face; |
| 1777 | SFNT_Service sfnt; |
| 1778 | FT_Stream stream; |
| 1779 | FT_Error error; |
| 1780 | TT_SBit_MetricsRec metrics; |
| 1781 | |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1782 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1783 | face = (TT_Face)glyph->face; |
| 1784 | sfnt = (SFNT_Service)face->sfnt; |
| 1785 | stream = face->root.stream; |
| 1786 | |
| 1787 | error = sfnt->load_sbit_image( face, |
Wu, Chia-I (吳佳一) | fa7d6ab | 2006-01-13 12:21:31 +0000 | [diff] [blame] | 1788 | size->strike_index, |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1789 | glyph_index, |
| 1790 | (FT_Int)load_flags, |
| 1791 | stream, |
| 1792 | &glyph->bitmap, |
| 1793 | &metrics ); |
| 1794 | if ( !error ) |
| 1795 | { |
| 1796 | glyph->outline.n_points = 0; |
| 1797 | glyph->outline.n_contours = 0; |
| 1798 | |
| 1799 | glyph->metrics.width = (FT_Pos)metrics.width << 6; |
| 1800 | glyph->metrics.height = (FT_Pos)metrics.height << 6; |
| 1801 | |
| 1802 | glyph->metrics.horiBearingX = (FT_Pos)metrics.horiBearingX << 6; |
| 1803 | glyph->metrics.horiBearingY = (FT_Pos)metrics.horiBearingY << 6; |
| 1804 | glyph->metrics.horiAdvance = (FT_Pos)metrics.horiAdvance << 6; |
| 1805 | |
| 1806 | glyph->metrics.vertBearingX = (FT_Pos)metrics.vertBearingX << 6; |
| 1807 | glyph->metrics.vertBearingY = (FT_Pos)metrics.vertBearingY << 6; |
| 1808 | glyph->metrics.vertAdvance = (FT_Pos)metrics.vertAdvance << 6; |
| 1809 | |
| 1810 | glyph->format = FT_GLYPH_FORMAT_BITMAP; |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1811 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1812 | if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) |
| 1813 | { |
| 1814 | glyph->bitmap_left = metrics.vertBearingX; |
| 1815 | glyph->bitmap_top = metrics.vertBearingY; |
| 1816 | } |
| 1817 | else |
| 1818 | { |
| 1819 | glyph->bitmap_left = metrics.horiBearingX; |
| 1820 | glyph->bitmap_top = metrics.horiBearingY; |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | return error; |
| 1825 | } |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1826 | |
| 1827 | #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1828 | |
| 1829 | |
| 1830 | static FT_Error |
| 1831 | tt_loader_init( TT_Loader loader, |
| 1832 | TT_Size size, |
| 1833 | TT_GlyphSlot glyph, |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1834 | FT_Int32 load_flags, |
| 1835 | FT_Bool glyf_table_only ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1836 | { |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1837 | TT_Face face; |
| 1838 | FT_Stream stream; |
Werner Lemberg | 18931a5 | 2011-02-01 07:08:43 +0100 | [diff] [blame] | 1839 | FT_Bool pedantic = FT_BOOL( load_flags & FT_LOAD_PEDANTIC ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1840 | |
| 1841 | |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1842 | face = (TT_Face)glyph->face; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1843 | stream = face->root.stream; |
| 1844 | |
| 1845 | FT_MEM_ZERO( loader, sizeof ( TT_LoaderRec ) ); |
| 1846 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 1847 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1848 | |
| 1849 | /* load execution context */ |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1850 | if ( IS_HINTED( load_flags ) && !glyf_table_only ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1851 | { |
| 1852 | TT_ExecContext exec; |
Werner Lemberg | 91959bf | 2006-11-22 10:36:55 +0000 | [diff] [blame] | 1853 | FT_Bool grayscale; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1854 | |
| 1855 | |
David Turner | 384be23 | 2007-01-05 15:32:01 +0000 | [diff] [blame] | 1856 | if ( !size->cvt_ready ) |
| 1857 | { |
Werner Lemberg | 18931a5 | 2011-02-01 07:08:43 +0100 | [diff] [blame] | 1858 | FT_Error error = tt_size_ready_bytecode( size, pedantic ); |
Werner Lemberg | 91a9716 | 2011-01-30 20:12:54 +0100 | [diff] [blame] | 1859 | |
| 1860 | |
David Turner | 384be23 | 2007-01-05 15:32:01 +0000 | [diff] [blame] | 1861 | if ( error ) |
| 1862 | return error; |
| 1863 | } |
| 1864 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1865 | /* query new execution context */ |
| 1866 | exec = size->debug ? size->context |
| 1867 | : ( (TT_Driver)FT_FACE_DRIVER( face ) )->context; |
| 1868 | if ( !exec ) |
| 1869 | return TT_Err_Could_Not_Find_Context; |
| 1870 | |
Werner Lemberg | 91959bf | 2006-11-22 10:36:55 +0000 | [diff] [blame] | 1871 | grayscale = |
| 1872 | FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != FT_RENDER_MODE_MONO ); |
| 1873 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1874 | TT_Load_Context( exec, face, size ); |
| 1875 | |
Werner Lemberg | 91959bf | 2006-11-22 10:36:55 +0000 | [diff] [blame] | 1876 | /* a change from mono to grayscale rendering (and vice versa) */ |
| 1877 | /* requires a re-execution of the CVT program */ |
| 1878 | if ( grayscale != exec->grayscale ) |
| 1879 | { |
| 1880 | FT_UInt i; |
| 1881 | |
| 1882 | |
Werner Lemberg | 6abb923 | 2010-09-14 09:02:10 +0200 | [diff] [blame] | 1883 | FT_TRACE4(( "tt_loader_init: grayscale change," |
| 1884 | " re-executing `prep' table\n" )); |
| 1885 | |
Werner Lemberg | 91959bf | 2006-11-22 10:36:55 +0000 | [diff] [blame] | 1886 | exec->grayscale = grayscale; |
| 1887 | |
| 1888 | for ( i = 0; i < size->cvt_size; i++ ) |
| 1889 | size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale ); |
Werner Lemberg | 18931a5 | 2011-02-01 07:08:43 +0100 | [diff] [blame] | 1890 | tt_size_run_prep( size, pedantic ); |
Werner Lemberg | 91959bf | 2006-11-22 10:36:55 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 1893 | /* see whether the cvt program has disabled hinting */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1894 | if ( exec->GS.instruct_control & 1 ) |
| 1895 | load_flags |= FT_LOAD_NO_HINTING; |
| 1896 | |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 1897 | /* load default graphics state -- if needed */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1898 | if ( exec->GS.instruct_control & 2 ) |
| 1899 | exec->GS = tt_default_graphics_state; |
| 1900 | |
| 1901 | exec->pedantic_hinting = FT_BOOL( load_flags & FT_LOAD_PEDANTIC ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1902 | loader->exec = exec; |
| 1903 | loader->instructions = exec->glyphIns; |
| 1904 | } |
| 1905 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 1906 | #endif /* TT_USE_BYTECODE_INTERPRETER */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1907 | |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 1908 | /* seek to the beginning of the glyph table -- for Type 42 fonts */ |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1909 | /* the table might be accessed from a Postscript stream or something */ |
| 1910 | /* else... */ |
| 1911 | |
| 1912 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
| 1913 | |
| 1914 | if ( face->root.internal->incremental_interface ) |
| 1915 | loader->glyf_offset = 0; |
| 1916 | else |
| 1917 | |
| 1918 | #endif |
| 1919 | |
| 1920 | { |
| 1921 | FT_Error error = face->goto_table( face, TTAG_glyf, stream, 0 ); |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1922 | |
| 1923 | |
Werner Lemberg | 1474f43 | 2008-12-09 06:51:56 +0000 | [diff] [blame] | 1924 | if ( error == TT_Err_Table_Missing ) |
| 1925 | loader->glyf_offset = 0; |
| 1926 | else if ( error ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1927 | { |
Werner Lemberg | 858abbe | 2009-06-26 06:15:41 +0200 | [diff] [blame] | 1928 | FT_ERROR(( "tt_loader_init: could not access glyph table\n" )); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1929 | return error; |
| 1930 | } |
Werner Lemberg | 1474f43 | 2008-12-09 06:51:56 +0000 | [diff] [blame] | 1931 | else |
| 1932 | loader->glyf_offset = FT_STREAM_POS(); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /* get face's glyph loader */ |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 1936 | if ( !glyf_table_only ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1937 | { |
| 1938 | FT_GlyphLoader gloader = glyph->internal->loader; |
| 1939 | |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 1940 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1941 | FT_GlyphLoader_Rewind( gloader ); |
| 1942 | loader->gloader = gloader; |
| 1943 | } |
| 1944 | |
Werner Lemberg | 1474f43 | 2008-12-09 06:51:56 +0000 | [diff] [blame] | 1945 | loader->load_flags = load_flags; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 1946 | |
| 1947 | loader->face = (FT_Face)face; |
| 1948 | loader->size = (FT_Size)size; |
| 1949 | loader->glyph = (FT_GlyphSlot)glyph; |
| 1950 | loader->stream = stream; |
| 1951 | |
| 1952 | return TT_Err_Ok; |
| 1953 | } |
| 1954 | |
| 1955 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1956 | /*************************************************************************/ |
| 1957 | /* */ |
| 1958 | /* <Function> */ |
| 1959 | /* TT_Load_Glyph */ |
| 1960 | /* */ |
| 1961 | /* <Description> */ |
| 1962 | /* A function used to load a single glyph within a given glyph slot, */ |
| 1963 | /* for a given size. */ |
| 1964 | /* */ |
| 1965 | /* <Input> */ |
| 1966 | /* glyph :: A handle to a target slot object where the glyph */ |
| 1967 | /* will be loaded. */ |
| 1968 | /* */ |
| 1969 | /* size :: A handle to the source face size at which the glyph */ |
| 1970 | /* must be scaled/loaded. */ |
| 1971 | /* */ |
| 1972 | /* glyph_index :: The index of the glyph in the font file. */ |
| 1973 | /* */ |
| 1974 | /* load_flags :: A flag indicating what to load for this glyph. The */ |
| 1975 | /* FT_LOAD_XXX constants can be used to control the */ |
| 1976 | /* glyph loading process (e.g., whether the outline */ |
| 1977 | /* should be scaled, whether to load bitmaps or not, */ |
| 1978 | /* whether to hint the outline, etc). */ |
| 1979 | /* */ |
| 1980 | /* <Return> */ |
Werner Lemberg | a929ba9 | 2000-06-25 06:47:11 +0000 | [diff] [blame] | 1981 | /* FreeType error code. 0 means success. */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1982 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 1983 | FT_LOCAL_DEF( FT_Error ) |
Werner Lemberg | 4a2305c | 2001-06-28 07:17:51 +0000 | [diff] [blame] | 1984 | TT_Load_Glyph( TT_Size size, |
| 1985 | TT_GlyphSlot glyph, |
Werner Lemberg | c3dc56b | 2004-04-19 06:13:50 +0000 | [diff] [blame] | 1986 | FT_UInt glyph_index, |
Werner Lemberg | e59dc91 | 2002-09-21 18:43:10 +0000 | [diff] [blame] | 1987 | FT_Int32 load_flags ) |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1988 | { |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 1989 | TT_Face face; |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 1990 | FT_Error error; |
| 1991 | TT_LoaderRec loader; |
David Turner | e49ab25 | 2000-05-16 23:44:38 +0000 | [diff] [blame] | 1992 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 1993 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1994 | face = (TT_Face)glyph->face; |
Werner Lemberg | 3ab770b | 2005-03-08 20:24:56 +0000 | [diff] [blame] | 1995 | error = TT_Err_Ok; |
David Turner | ed7f62a | 2000-03-28 11:19:28 +0000 | [diff] [blame] | 1996 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 1997 | #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS |
Werner Lemberg | 4b68007 | 2000-11-07 06:30:29 +0000 | [diff] [blame] | 1998 | |
| 1999 | /* try to load embedded bitmap if any */ |
| 2000 | /* */ |
| 2001 | /* XXX: The convention should be emphasized in */ |
| 2002 | /* the documents because it can be confusing. */ |
Werner Lemberg | f1c2b91 | 2006-01-13 14:53:28 +0000 | [diff] [blame] | 2003 | if ( size->strike_index != 0xFFFFFFFFUL && |
David Turner | f96594f | 2000-11-06 23:07:51 +0000 | [diff] [blame] | 2004 | ( load_flags & FT_LOAD_NO_BITMAP ) == 0 ) |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 2005 | { |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 2006 | error = load_sbit_image( size, glyph, glyph_index, load_flags ); |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 2007 | if ( !error ) |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 2008 | { |
| 2009 | FT_Face root = &face->root; |
| 2010 | |
| 2011 | |
| 2012 | if ( FT_IS_SCALABLE( root ) ) |
| 2013 | { |
| 2014 | /* for the bbox we need the header only */ |
| 2015 | (void)tt_loader_init( &loader, size, glyph, load_flags, TRUE ); |
| 2016 | (void)load_truetype_glyph( &loader, glyph_index, 0, TRUE ); |
| 2017 | glyph->linearHoriAdvance = loader.linear; |
| 2018 | glyph->linearVertAdvance = loader.top_bearing + loader.bbox.yMax - |
| 2019 | loader.vadvance; |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 2020 | } |
| 2021 | |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 2022 | return TT_Err_Ok; |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 2023 | } |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 2024 | } |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 2025 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 2026 | #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ |
| 2027 | |
Werner Lemberg | 560d5fe | 2005-10-21 09:08:28 +0000 | [diff] [blame] | 2028 | /* if FT_LOAD_NO_SCALE is not set, `ttmetrics' must be valid */ |
Wu, Chia-I (吳佳一) | 2293bb1 | 2005-10-19 08:07:38 +0000 | [diff] [blame] | 2029 | if ( !( load_flags & FT_LOAD_NO_SCALE ) && !size->ttmetrics.valid ) |
Wu, Chia-I (吳佳一) | 15c1f5d | 2005-08-20 08:17:44 +0000 | [diff] [blame] | 2030 | return TT_Err_Invalid_Size_Handle; |
| 2031 | |
David Turner | 4937a3e | 2001-12-19 21:09:16 +0000 | [diff] [blame] | 2032 | if ( load_flags & FT_LOAD_SBITS_ONLY ) |
Werner Lemberg | 779afe4 | 2003-06-22 15:33:53 +0000 | [diff] [blame] | 2033 | return TT_Err_Invalid_Argument; |
David Turner | 4937a3e | 2001-12-19 21:09:16 +0000 | [diff] [blame] | 2034 | |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 2035 | error = tt_loader_init( &loader, size, glyph, load_flags, FALSE ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 2036 | if ( error ) |
| 2037 | return error; |
Werner Lemberg | 7f74a52 | 2002-07-26 09:09:10 +0000 | [diff] [blame] | 2038 | |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 2039 | glyph->format = FT_GLYPH_FORMAT_OUTLINE; |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 2040 | glyph->num_subglyphs = 0; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 2041 | glyph->outline.flags = 0; |
Werner Lemberg | 91db04c | 2002-04-01 14:25:28 +0000 | [diff] [blame] | 2042 | |
Werner Lemberg | 6f99c88 | 2007-05-19 07:01:49 +0000 | [diff] [blame] | 2043 | /* main loading loop */ |
Werner Lemberg | f186ba6 | 2009-11-03 15:46:35 +0100 | [diff] [blame] | 2044 | error = load_truetype_glyph( &loader, glyph_index, 0, FALSE ); |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 2045 | if ( !error ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 2046 | { |
| 2047 | if ( glyph->format == FT_GLYPH_FORMAT_COMPOSITE ) |
| 2048 | { |
| 2049 | glyph->num_subglyphs = loader.gloader->base.num_subglyphs; |
| 2050 | glyph->subglyphs = loader.gloader->base.subglyphs; |
| 2051 | } |
| 2052 | else |
| 2053 | { |
Werner Lemberg | ffa033b | 2005-08-19 08:56:29 +0000 | [diff] [blame] | 2054 | glyph->outline = loader.gloader->base.outline; |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 2055 | glyph->outline.flags &= ~FT_OUTLINE_SINGLE_PASS; |
| 2056 | |
John Tytgat | 8c4cce5 | 2010-04-05 08:22:22 +0200 | [diff] [blame] | 2057 | /* Translate array so that (0,0) is the glyph's origin. Note */ |
| 2058 | /* that this behaviour is independent on the value of bit 1 of */ |
| 2059 | /* the `flags' field in the `head' table -- at least major */ |
| 2060 | /* applications like Acroread indicate that. */ |
| 2061 | if ( loader.pp1.x ) |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 2062 | FT_Outline_Translate( &glyph->outline, -loader.pp1.x, 0 ); |
| 2063 | } |
| 2064 | |
Werner Lemberg | 5df5dbb | 2008-06-22 13:40:08 +0000 | [diff] [blame] | 2065 | #ifdef TT_USE_BYTECODE_INTERPRETER |
| 2066 | |
Werner Lemberg | 745a4f4 | 2008-06-22 22:41:24 +0000 | [diff] [blame] | 2067 | if ( IS_HINTED( load_flags ) ) |
Werner Lemberg | 5df5dbb | 2008-06-22 13:40:08 +0000 | [diff] [blame] | 2068 | { |
Werner Lemberg | 745a4f4 | 2008-06-22 22:41:24 +0000 | [diff] [blame] | 2069 | if ( loader.exec->GS.scan_control ) |
Werner Lemberg | 5df5dbb | 2008-06-22 13:40:08 +0000 | [diff] [blame] | 2070 | { |
Werner Lemberg | 745a4f4 | 2008-06-22 22:41:24 +0000 | [diff] [blame] | 2071 | /* convert scan conversion mode to FT_OUTLINE_XXX flags */ |
| 2072 | switch ( loader.exec->GS.scan_type ) |
| 2073 | { |
| 2074 | case 0: /* simple drop-outs including stubs */ |
| 2075 | glyph->outline.flags |= FT_OUTLINE_INCLUDE_STUBS; |
| 2076 | break; |
| 2077 | case 1: /* simple drop-outs excluding stubs */ |
| 2078 | /* nothing; it's the default rendering mode */ |
| 2079 | break; |
| 2080 | case 4: /* smart drop-outs including stubs */ |
| 2081 | glyph->outline.flags |= FT_OUTLINE_SMART_DROPOUTS | |
| 2082 | FT_OUTLINE_INCLUDE_STUBS; |
| 2083 | break; |
| 2084 | case 5: /* smart drop-outs excluding stubs */ |
| 2085 | glyph->outline.flags |= FT_OUTLINE_SMART_DROPOUTS; |
| 2086 | break; |
Werner Lemberg | 5df5dbb | 2008-06-22 13:40:08 +0000 | [diff] [blame] | 2087 | |
Werner Lemberg | 745a4f4 | 2008-06-22 22:41:24 +0000 | [diff] [blame] | 2088 | default: /* no drop-out control */ |
| 2089 | glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS; |
| 2090 | break; |
| 2091 | } |
Werner Lemberg | 5df5dbb | 2008-06-22 13:40:08 +0000 | [diff] [blame] | 2092 | } |
Bram Tassyns | 4694ea2 | 2009-09-02 13:06:33 +0200 | [diff] [blame] | 2093 | else |
Werner Lemberg | 745a4f4 | 2008-06-22 22:41:24 +0000 | [diff] [blame] | 2094 | glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS; |
Werner Lemberg | 5df5dbb | 2008-06-22 13:40:08 +0000 | [diff] [blame] | 2095 | } |
Werner Lemberg | 5df5dbb | 2008-06-22 13:40:08 +0000 | [diff] [blame] | 2096 | |
| 2097 | #endif /* TT_USE_BYTECODE_INTERPRETER */ |
| 2098 | |
David Turner | 8f43c71 | 2000-02-02 12:16:19 +0000 | [diff] [blame] | 2099 | compute_glyph_metrics( &loader, glyph_index ); |
Wu, Chia-I (吳佳一) | 0142e6a | 2005-08-16 01:54:59 +0000 | [diff] [blame] | 2100 | } |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 2101 | |
Werner Lemberg | 26aca02 | 2002-05-05 07:40:16 +0000 | [diff] [blame] | 2102 | /* Set the `high precision' bit flag. */ |
| 2103 | /* This is _critical_ to get correct output for monochrome */ |
| 2104 | /* TrueType glyphs at all sizes using the bytecode interpreter. */ |
| 2105 | /* */ |
Werner Lemberg | 560d5fe | 2005-10-21 09:08:28 +0000 | [diff] [blame] | 2106 | if ( !( load_flags & FT_LOAD_NO_SCALE ) && |
| 2107 | size->root.metrics.y_ppem < 24 ) |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 2108 | glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION; |
David Turner | 8cd8907 | 2002-05-04 18:02:59 +0000 | [diff] [blame] | 2109 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 2110 | return error; |
| 2111 | } |
| 2112 | |
| 2113 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 2114 | /* END */ |