David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 1 | /***************************************************************************/ |
| 2 | /* */ |
David Turner | 19ed8af | 2000-12-08 02:42:29 +0000 | [diff] [blame] | 3 | /* ttpload.c */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 4 | /* */ |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 5 | /* TrueType-specific tables loader (body). */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 6 | /* */ |
Werner Lemberg | 01caf4a | 2011-03-23 05:19:59 +0100 | [diff] [blame] | 7 | /* Copyright 1996-2002, 2004-2011 by */ |
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_OBJECTS_H |
| 22 | #include FT_INTERNAL_STREAM_H |
| 23 | #include FT_TRUETYPE_TAGS_H |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 24 | |
David Turner | 8d3a401 | 2001-03-20 11:14:24 +0000 | [diff] [blame] | 25 | #include "ttpload.h" |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 26 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 27 | #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT |
| 28 | #include "ttgxvar.h" |
| 29 | #endif |
| 30 | |
Werner Lemberg | 1f7f0e8 | 2001-06-06 17:30:41 +0000 | [diff] [blame] | 31 | #include "tterrors.h" |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 32 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 33 | |
| 34 | /*************************************************************************/ |
| 35 | /* */ |
| 36 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
| 37 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
| 38 | /* messages during execution. */ |
| 39 | /* */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 40 | #undef FT_COMPONENT |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 41 | #define FT_COMPONENT trace_ttpload |
| 42 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 43 | |
| 44 | /*************************************************************************/ |
| 45 | /* */ |
| 46 | /* <Function> */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 47 | /* tt_face_load_loca */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 48 | /* */ |
| 49 | /* <Description> */ |
Werner Lemberg | 5225402 | 2006-02-15 06:05:52 +0000 | [diff] [blame] | 50 | /* Load the locations table. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 51 | /* */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 52 | /* <InOut> */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 53 | /* face :: A handle to the target face object. */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 54 | /* */ |
| 55 | /* <Input> */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 56 | /* stream :: The input stream. */ |
| 57 | /* */ |
| 58 | /* <Return> */ |
Werner Lemberg | 9ca2af3 | 2000-06-21 03:03:28 +0000 | [diff] [blame] | 59 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 60 | /* */ |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 61 | FT_LOCAL_DEF( FT_Error ) |
| 62 | tt_face_load_loca( TT_Face face, |
| 63 | FT_Stream stream ) |
| 64 | { |
Werner Lemberg | f13516c | 2005-03-03 17:09:08 +0000 | [diff] [blame] | 65 | FT_Error error; |
| 66 | FT_ULong table_len; |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 67 | FT_Int shift; |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 68 | |
| 69 | |
Werner Lemberg | 5452fbe | 2005-05-05 07:44:20 +0000 | [diff] [blame] | 70 | /* we need the size of the `glyf' table for malformed `loca' tables */ |
| 71 | error = face->goto_table( face, TTAG_glyf, stream, &face->glyf_len ); |
Werner Lemberg | 1474f43 | 2008-12-09 06:51:56 +0000 | [diff] [blame] | 72 | |
| 73 | /* it is possible that a font doesn't have a glyf table at all */ |
| 74 | /* or its size is zero */ |
| 75 | if ( error == TT_Err_Table_Missing ) |
| 76 | face->glyf_len = 0; |
| 77 | else if ( error ) |
Werner Lemberg | 5452fbe | 2005-05-05 07:44:20 +0000 | [diff] [blame] | 78 | goto Exit; |
| 79 | |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 80 | FT_TRACE2(( "Locations " )); |
| 81 | error = face->goto_table( face, TTAG_loca, stream, &table_len ); |
| 82 | if ( error ) |
| 83 | { |
| 84 | error = TT_Err_Locations_Missing; |
| 85 | goto Exit; |
| 86 | } |
| 87 | |
| 88 | if ( face->header.Index_To_Loc_Format != 0 ) |
| 89 | { |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 90 | shift = 2; |
| 91 | |
Werner Lemberg | f1c2b91 | 2006-01-13 14:53:28 +0000 | [diff] [blame] | 92 | if ( table_len >= 0x40000L ) |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 93 | { |
Werner Lemberg | 858abbe | 2009-06-26 06:15:41 +0200 | [diff] [blame] | 94 | FT_TRACE2(( "table too large\n" )); |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 95 | error = TT_Err_Invalid_Table; |
| 96 | goto Exit; |
| 97 | } |
suzuki toshiya | 25dba9c | 2009-08-01 00:32:09 +0900 | [diff] [blame] | 98 | face->num_locations = table_len >> shift; |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 99 | } |
| 100 | else |
| 101 | { |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 102 | shift = 1; |
| 103 | |
Werner Lemberg | f1c2b91 | 2006-01-13 14:53:28 +0000 | [diff] [blame] | 104 | if ( table_len >= 0x20000L ) |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 105 | { |
Werner Lemberg | 858abbe | 2009-06-26 06:15:41 +0200 | [diff] [blame] | 106 | FT_TRACE2(( "table too large\n" )); |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 107 | error = TT_Err_Invalid_Table; |
| 108 | goto Exit; |
| 109 | } |
suzuki toshiya | 25dba9c | 2009-08-01 00:32:09 +0900 | [diff] [blame] | 110 | face->num_locations = table_len >> shift; |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Werner Lemberg | 01caf4a | 2011-03-23 05:19:59 +0100 | [diff] [blame] | 113 | if ( face->num_locations != (FT_ULong)face->root.num_glyphs + 1 ) |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 114 | { |
| 115 | FT_TRACE2(( "glyph count mismatch! loca: %d, maxp: %d\n", |
Werner Lemberg | 01caf4a | 2011-03-23 05:19:59 +0100 | [diff] [blame] | 116 | face->num_locations - 1, face->root.num_glyphs )); |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 117 | |
| 118 | /* we only handle the case where `maxp' gives a larger value */ |
Werner Lemberg | 01caf4a | 2011-03-23 05:19:59 +0100 | [diff] [blame] | 119 | if ( face->num_locations <= (FT_ULong)face->root.num_glyphs ) |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 120 | { |
Werner Lemberg | 01caf4a | 2011-03-23 05:19:59 +0100 | [diff] [blame] | 121 | FT_Long new_loca_len = |
| 122 | ( (FT_Long)( face->root.num_glyphs ) + 1 ) << shift; |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 123 | |
| 124 | TT_Table entry = face->dir_tables; |
| 125 | TT_Table limit = entry + face->num_tables; |
| 126 | |
| 127 | FT_Long pos = FT_Stream_Pos( stream ); |
| 128 | FT_Long dist = 0x7FFFFFFFL; |
| 129 | |
| 130 | |
| 131 | /* compute the distance to next table in font file */ |
| 132 | for ( ; entry < limit; entry++ ) |
| 133 | { |
| 134 | FT_Long diff = entry->Offset - pos; |
| 135 | |
| 136 | |
| 137 | if ( diff > 0 && diff < dist ) |
| 138 | dist = diff; |
| 139 | } |
| 140 | |
Werner Lemberg | ec4372f | 2010-11-18 20:34:22 +0100 | [diff] [blame] | 141 | if ( entry == limit ) |
| 142 | { |
| 143 | /* `loca' is the last table */ |
| 144 | dist = stream->size - pos; |
| 145 | } |
| 146 | |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 147 | if ( new_loca_len <= dist ) |
| 148 | { |
Werner Lemberg | 01caf4a | 2011-03-23 05:19:59 +0100 | [diff] [blame] | 149 | face->num_locations = face->root.num_glyphs + 1; |
Werner Lemberg | 6b19e09 | 2008-07-09 06:20:12 +0000 | [diff] [blame] | 150 | table_len = new_loca_len; |
| 151 | |
| 152 | FT_TRACE2(( "adjusting num_locations to %d\n", |
| 153 | face->num_locations )); |
| 154 | } |
| 155 | } |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 158 | /* |
| 159 | * Extract the frame. We don't need to decompress it since |
| 160 | * we are able to parse it directly. |
| 161 | */ |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 162 | if ( FT_FRAME_EXTRACT( table_len, face->glyph_locations ) ) |
| 163 | goto Exit; |
| 164 | |
| 165 | FT_TRACE2(( "loaded\n" )); |
| 166 | |
| 167 | Exit: |
| 168 | return error; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | FT_LOCAL_DEF( FT_ULong ) |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 173 | tt_face_get_location( TT_Face face, |
| 174 | FT_UInt gindex, |
| 175 | FT_UInt *asize ) |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 176 | { |
| 177 | FT_ULong pos1, pos2; |
| 178 | FT_Byte* p; |
| 179 | FT_Byte* p_limit; |
| 180 | |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 181 | |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 182 | pos1 = pos2 = 0; |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 183 | |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 184 | if ( gindex < face->num_locations ) |
| 185 | { |
| 186 | if ( face->header.Index_To_Loc_Format != 0 ) |
| 187 | { |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 188 | p = face->glyph_locations + gindex * 4; |
| 189 | p_limit = face->glyph_locations + face->num_locations * 4; |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 190 | |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 191 | pos1 = FT_NEXT_ULONG( p ); |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 192 | pos2 = pos1; |
| 193 | |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 194 | if ( p + 4 <= p_limit ) |
| 195 | pos2 = FT_NEXT_ULONG( p ); |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 196 | } |
| 197 | else |
| 198 | { |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 199 | p = face->glyph_locations + gindex * 2; |
| 200 | p_limit = face->glyph_locations + face->num_locations * 2; |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 201 | |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 202 | pos1 = FT_NEXT_USHORT( p ); |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 203 | pos2 = pos1; |
| 204 | |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 205 | if ( p + 2 <= p_limit ) |
| 206 | pos2 = FT_NEXT_USHORT( p ); |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 207 | |
| 208 | pos1 <<= 1; |
| 209 | pos2 <<= 1; |
| 210 | } |
| 211 | } |
| 212 | |
suzuki toshiya | 643d49d | 2010-09-20 01:07:57 +0900 | [diff] [blame] | 213 | /* Check broken location data */ |
| 214 | if ( pos1 >= face->glyf_len ) |
| 215 | { |
| 216 | FT_TRACE1(( "tt_face_get_location:" |
| 217 | " too large offset=0x%08lx found for gid=0x%04lx," |
| 218 | " exceeding the end of glyf table (0x%08lx)\n", |
| 219 | pos1, gindex, face->glyf_len )); |
| 220 | *asize = 0; |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | if ( pos2 >= face->glyf_len ) |
| 225 | { |
| 226 | FT_TRACE1(( "tt_face_get_location:" |
| 227 | " too large offset=0x%08lx found for gid=0x%04lx," |
| 228 | " truncate at the end of glyf table (0x%08lx)\n", |
| 229 | pos2, gindex + 1, face->glyf_len )); |
| 230 | pos2 = face->glyf_len; |
| 231 | } |
| 232 | |
Werner Lemberg | b47b97d | 2009-04-04 07:51:45 +0200 | [diff] [blame] | 233 | /* The `loca' table must be ordered; it refers to the length of */ |
| 234 | /* an entry as the difference between the current and the next */ |
| 235 | /* position. However, there do exist (malformed) fonts which */ |
| 236 | /* don't obey this rule, so we are only able to provide an */ |
| 237 | /* upper bound for the size. */ |
Werner Lemberg | 1474f43 | 2008-12-09 06:51:56 +0000 | [diff] [blame] | 238 | /* */ |
| 239 | /* We get (intentionally) a wrong, non-zero result in case the */ |
| 240 | /* `glyf' table is missing. */ |
Werner Lemberg | 43ebad4 | 2005-05-07 06:10:19 +0000 | [diff] [blame] | 241 | if ( pos2 >= pos1 ) |
Werner Lemberg | 5452fbe | 2005-05-05 07:44:20 +0000 | [diff] [blame] | 242 | *asize = (FT_UInt)( pos2 - pos1 ); |
| 243 | else |
| 244 | *asize = (FT_UInt)( face->glyf_len - pos1 ); |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 245 | |
| 246 | return pos1; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | FT_LOCAL_DEF( void ) |
| 251 | tt_face_done_loca( TT_Face face ) |
| 252 | { |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 253 | FT_Stream stream = face->root.stream; |
| 254 | |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 255 | |
| 256 | FT_FRAME_RELEASE( face->glyph_locations ); |
| 257 | face->num_locations = 0; |
| 258 | } |
| 259 | |
| 260 | |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 261 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 262 | /*************************************************************************/ |
| 263 | /* */ |
| 264 | /* <Function> */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 265 | /* tt_face_load_cvt */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 266 | /* */ |
| 267 | /* <Description> */ |
Werner Lemberg | 5225402 | 2006-02-15 06:05:52 +0000 | [diff] [blame] | 268 | /* Load the control value table into a face object. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 269 | /* */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 270 | /* <InOut> */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 271 | /* face :: A handle to the target face object. */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 272 | /* */ |
| 273 | /* <Input> */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 274 | /* stream :: A handle to the input stream. */ |
| 275 | /* */ |
| 276 | /* <Return> */ |
Werner Lemberg | 9ca2af3 | 2000-06-21 03:03:28 +0000 | [diff] [blame] | 277 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 278 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 279 | FT_LOCAL_DEF( FT_Error ) |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 280 | tt_face_load_cvt( TT_Face face, |
| 281 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 282 | { |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 283 | #ifdef TT_USE_BYTECODE_INTERPRETER |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 284 | |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 285 | FT_Error error; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 286 | FT_Memory memory = stream->memory; |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 287 | FT_ULong table_len; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 288 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 289 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 290 | FT_TRACE2(( "CVT " )); |
| 291 | |
| 292 | error = face->goto_table( face, TTAG_cvt, stream, &table_len ); |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 293 | if ( error ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 294 | { |
Werner Lemberg | 858abbe | 2009-06-26 06:15:41 +0200 | [diff] [blame] | 295 | FT_TRACE2(( "is missing\n" )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 296 | |
| 297 | face->cvt_size = 0; |
| 298 | face->cvt = NULL; |
| 299 | error = TT_Err_Ok; |
| 300 | |
| 301 | goto Exit; |
| 302 | } |
| 303 | |
| 304 | face->cvt_size = table_len / 2; |
| 305 | |
David Turner | e459d74 | 2002-03-22 13:52:37 +0000 | [diff] [blame] | 306 | if ( FT_NEW_ARRAY( face->cvt, face->cvt_size ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 307 | goto Exit; |
| 308 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 309 | if ( FT_FRAME_ENTER( face->cvt_size * 2L ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 310 | goto Exit; |
| 311 | |
| 312 | { |
David Turner | f9b8dec | 2000-06-16 19:34:52 +0000 | [diff] [blame] | 313 | FT_Short* cur = face->cvt; |
| 314 | FT_Short* limit = cur + face->cvt_size; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 315 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 316 | |
Werner Lemberg | ec4372f | 2010-11-18 20:34:22 +0100 | [diff] [blame] | 317 | for ( ; cur < limit; cur++ ) |
David Turner | a890c29 | 2002-03-22 12:55:23 +0000 | [diff] [blame] | 318 | *cur = FT_GET_SHORT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 319 | } |
| 320 | |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 321 | FT_FRAME_EXIT(); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 322 | FT_TRACE2(( "loaded\n" )); |
| 323 | |
Werner Lemberg | 44bb303 | 2004-04-25 20:15:11 +0000 | [diff] [blame] | 324 | #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT |
| 325 | if ( face->doblend ) |
| 326 | error = tt_face_vary_cvt( face, stream ); |
| 327 | #endif |
| 328 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 329 | Exit: |
| 330 | return error; |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 331 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 332 | #else /* !TT_USE_BYTECODE_INTERPRETER */ |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 333 | |
| 334 | FT_UNUSED( face ); |
| 335 | FT_UNUSED( stream ); |
| 336 | |
Werner Lemberg | c11aeb6 | 2005-03-10 15:49:45 +0000 | [diff] [blame] | 337 | return TT_Err_Ok; |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 338 | |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 339 | #endif |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | |
| 343 | /*************************************************************************/ |
| 344 | /* */ |
| 345 | /* <Function> */ |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 346 | /* tt_face_load_fpgm */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 347 | /* */ |
| 348 | /* <Description> */ |
Werner Lemberg | 5225402 | 2006-02-15 06:05:52 +0000 | [diff] [blame] | 349 | /* Load the font program. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 350 | /* */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 351 | /* <InOut> */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 352 | /* face :: A handle to the target face object. */ |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 353 | /* */ |
| 354 | /* <Input> */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 355 | /* stream :: A handle to the input stream. */ |
| 356 | /* */ |
| 357 | /* <Return> */ |
Werner Lemberg | 9ca2af3 | 2000-06-21 03:03:28 +0000 | [diff] [blame] | 358 | /* FreeType error code. 0 means success. */ |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 359 | /* */ |
David Turner | bc82f1b | 2002-03-01 02:26:22 +0000 | [diff] [blame] | 360 | FT_LOCAL_DEF( FT_Error ) |
David Turner | b08fe2d | 2002-08-27 20:20:29 +0000 | [diff] [blame] | 361 | tt_face_load_fpgm( TT_Face face, |
| 362 | FT_Stream stream ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 363 | { |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 364 | #ifdef TT_USE_BYTECODE_INTERPRETER |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 365 | |
Werner Lemberg | 5225402 | 2006-02-15 06:05:52 +0000 | [diff] [blame] | 366 | FT_Error error; |
| 367 | FT_ULong table_len; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 368 | |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 369 | |
Werner Lemberg | f697866 | 2000-01-08 20:00:54 +0000 | [diff] [blame] | 370 | FT_TRACE2(( "Font program " )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 371 | |
| 372 | /* The font program is optional */ |
| 373 | error = face->goto_table( face, TTAG_fpgm, stream, &table_len ); |
Werner Lemberg | f697866 | 2000-01-08 20:00:54 +0000 | [diff] [blame] | 374 | if ( error ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 375 | { |
| 376 | face->font_program = NULL; |
| 377 | face->font_program_size = 0; |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 378 | error = TT_Err_Ok; |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 379 | |
Werner Lemberg | 858abbe | 2009-06-26 06:15:41 +0200 | [diff] [blame] | 380 | FT_TRACE2(( "is missing\n" )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 381 | } |
| 382 | else |
| 383 | { |
| 384 | face->font_program_size = table_len; |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 385 | if ( FT_FRAME_EXTRACT( table_len, face->font_program ) ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 386 | goto Exit; |
| 387 | |
| 388 | FT_TRACE2(( "loaded, %12d bytes\n", face->font_program_size )); |
| 389 | } |
| 390 | |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 391 | Exit: |
| 392 | return error; |
| 393 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 394 | #else /* !TT_USE_BYTECODE_INTERPRETER */ |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 395 | |
| 396 | FT_UNUSED( face ); |
| 397 | FT_UNUSED( stream ); |
| 398 | |
| 399 | return TT_Err_Ok; |
| 400 | |
| 401 | #endif |
| 402 | } |
| 403 | |
| 404 | |
| 405 | /*************************************************************************/ |
| 406 | /* */ |
| 407 | /* <Function> */ |
| 408 | /* tt_face_load_prep */ |
| 409 | /* */ |
| 410 | /* <Description> */ |
Werner Lemberg | 5225402 | 2006-02-15 06:05:52 +0000 | [diff] [blame] | 411 | /* Load the cvt program. */ |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 412 | /* */ |
| 413 | /* <InOut> */ |
| 414 | /* face :: A handle to the target face object. */ |
| 415 | /* */ |
| 416 | /* <Input> */ |
| 417 | /* stream :: A handle to the input stream. */ |
| 418 | /* */ |
| 419 | /* <Return> */ |
| 420 | /* FreeType error code. 0 means success. */ |
| 421 | /* */ |
| 422 | FT_LOCAL_DEF( FT_Error ) |
| 423 | tt_face_load_prep( TT_Face face, |
| 424 | FT_Stream stream ) |
| 425 | { |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 426 | #ifdef TT_USE_BYTECODE_INTERPRETER |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 427 | |
Werner Lemberg | 5225402 | 2006-02-15 06:05:52 +0000 | [diff] [blame] | 428 | FT_Error error; |
| 429 | FT_ULong table_len; |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 430 | |
| 431 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 432 | FT_TRACE2(( "Prep program " )); |
| 433 | |
| 434 | error = face->goto_table( face, TTAG_prep, stream, &table_len ); |
Werner Lemberg | f697866 | 2000-01-08 20:00:54 +0000 | [diff] [blame] | 435 | if ( error ) |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 436 | { |
| 437 | face->cvt_program = NULL; |
| 438 | face->cvt_program_size = 0; |
Werner Lemberg | f697866 | 2000-01-08 20:00:54 +0000 | [diff] [blame] | 439 | error = TT_Err_Ok; |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 440 | |
Werner Lemberg | 858abbe | 2009-06-26 06:15:41 +0200 | [diff] [blame] | 441 | FT_TRACE2(( "is missing\n" )); |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 442 | } |
| 443 | else |
| 444 | { |
| 445 | face->cvt_program_size = table_len; |
David Turner | 7d3a264 | 2002-03-20 10:49:31 +0000 | [diff] [blame] | 446 | if ( FT_FRAME_EXTRACT( table_len, face->cvt_program ) ) |
David Turner | 2e42131 | 2000-05-26 22:13:17 +0000 | [diff] [blame] | 447 | goto Exit; |
Werner Lemberg | 78575dc | 2000-06-12 19:36:41 +0000 | [diff] [blame] | 448 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 449 | FT_TRACE2(( "loaded, %12d bytes\n", face->cvt_program_size )); |
| 450 | } |
| 451 | |
| 452 | Exit: |
| 453 | return error; |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 454 | |
David Turner | 6aa260c | 2006-08-25 22:45:13 +0000 | [diff] [blame] | 455 | #else /* !TT_USE_BYTECODE_INTERPRETER */ |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 456 | |
| 457 | FT_UNUSED( face ); |
| 458 | FT_UNUSED( stream ); |
| 459 | |
Werner Lemberg | c11aeb6 | 2005-03-10 15:49:45 +0000 | [diff] [blame] | 460 | return TT_Err_Ok; |
Werner Lemberg | e793092 | 2005-03-01 02:13:50 +0000 | [diff] [blame] | 461 | |
David Turner | e70d553 | 2005-02-22 16:53:06 +0000 | [diff] [blame] | 462 | #endif |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 466 | /*************************************************************************/ |
| 467 | /* */ |
| 468 | /* <Function> */ |
| 469 | /* tt_face_load_hdmx */ |
| 470 | /* */ |
| 471 | /* <Description> */ |
Werner Lemberg | 5225402 | 2006-02-15 06:05:52 +0000 | [diff] [blame] | 472 | /* Load the `hdmx' table into the face object. */ |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 473 | /* */ |
| 474 | /* <Input> */ |
| 475 | /* face :: A handle to the target face object. */ |
| 476 | /* */ |
| 477 | /* stream :: A handle to the input stream. */ |
| 478 | /* */ |
| 479 | /* <Return> */ |
| 480 | /* FreeType error code. 0 means success. */ |
| 481 | /* */ |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 482 | |
| 483 | FT_LOCAL_DEF( FT_Error ) |
| 484 | tt_face_load_hdmx( TT_Face face, |
| 485 | FT_Stream stream ) |
| 486 | { |
| 487 | FT_Error error; |
| 488 | FT_Memory memory = stream->memory; |
| 489 | FT_UInt version, nn, num_records; |
| 490 | FT_ULong table_size, record_size; |
| 491 | FT_Byte* p; |
| 492 | FT_Byte* limit; |
| 493 | |
| 494 | |
| 495 | /* this table is optional */ |
| 496 | error = face->goto_table( face, TTAG_hdmx, stream, &table_size ); |
| 497 | if ( error || table_size < 8 ) |
| 498 | return TT_Err_Ok; |
| 499 | |
| 500 | if ( FT_FRAME_EXTRACT( table_size, face->hdmx_table ) ) |
| 501 | goto Exit; |
| 502 | |
| 503 | p = face->hdmx_table; |
| 504 | limit = p + table_size; |
| 505 | |
| 506 | version = FT_NEXT_USHORT( p ); |
| 507 | num_records = FT_NEXT_USHORT( p ); |
| 508 | record_size = FT_NEXT_ULONG( p ); |
| 509 | |
Werner Lemberg | 36d2eab | 2006-09-05 19:24:34 +0000 | [diff] [blame] | 510 | /* The maximum number of bytes in an hdmx device record is the */ |
| 511 | /* maximum number of glyphs + 2; this is 0xFFFF + 2; this is */ |
| 512 | /* the reason why `record_size' is a long (which we read as */ |
| 513 | /* unsigned long for convenience). In practice, two bytes */ |
| 514 | /* sufficient to hold the size value. */ |
| 515 | /* */ |
| 516 | /* There are at least two fonts, HANNOM-A and HANNOM-B version */ |
| 517 | /* 2.0 (2005), which get this wrong: The upper two bytes of */ |
| 518 | /* the size value are set to 0xFF instead of 0x00. We catch */ |
| 519 | /* and fix this. */ |
| 520 | |
| 521 | if ( record_size >= 0xFFFF0000UL ) |
| 522 | record_size &= 0xFFFFU; |
| 523 | |
| 524 | /* The limit for `num_records' is a heuristic value. */ |
| 525 | |
| 526 | if ( version != 0 || num_records > 255 || record_size > 0x10001L ) |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 527 | { |
| 528 | error = TT_Err_Invalid_File_Format; |
| 529 | goto Fail; |
| 530 | } |
| 531 | |
| 532 | if ( FT_NEW_ARRAY( face->hdmx_record_sizes, num_records ) ) |
| 533 | goto Fail; |
| 534 | |
| 535 | for ( nn = 0; nn < num_records; nn++ ) |
| 536 | { |
| 537 | if ( p + record_size > limit ) |
| 538 | break; |
David Turner | da95af6 | 2006-03-20 13:32:33 +0000 | [diff] [blame] | 539 | |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 540 | face->hdmx_record_sizes[nn] = p[0]; |
| 541 | p += record_size; |
| 542 | } |
David Turner | da95af6 | 2006-03-20 13:32:33 +0000 | [diff] [blame] | 543 | |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 544 | face->hdmx_record_count = nn; |
| 545 | face->hdmx_table_size = table_size; |
Wu, Chia-I (吳佳一) | facd9af | 2006-02-22 07:59:35 +0000 | [diff] [blame] | 546 | face->hdmx_record_size = record_size; |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 547 | |
| 548 | Exit: |
| 549 | return error; |
David Turner | da95af6 | 2006-03-20 13:32:33 +0000 | [diff] [blame] | 550 | |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 551 | Fail: |
| 552 | FT_FRAME_RELEASE( face->hdmx_table ); |
| 553 | face->hdmx_table_size = 0; |
| 554 | goto Exit; |
| 555 | } |
| 556 | |
| 557 | |
| 558 | FT_LOCAL_DEF( void ) |
| 559 | tt_face_free_hdmx( TT_Face face ) |
| 560 | { |
| 561 | FT_Stream stream = face->root.stream; |
| 562 | FT_Memory memory = stream->memory; |
David Turner | da95af6 | 2006-03-20 13:32:33 +0000 | [diff] [blame] | 563 | |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 564 | |
| 565 | FT_FREE( face->hdmx_record_sizes ); |
| 566 | FT_FRAME_RELEASE( face->hdmx_table ); |
| 567 | } |
| 568 | |
Werner Lemberg | 5225402 | 2006-02-15 06:05:52 +0000 | [diff] [blame] | 569 | |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 570 | /*************************************************************************/ |
| 571 | /* */ |
Werner Lemberg | 5225402 | 2006-02-15 06:05:52 +0000 | [diff] [blame] | 572 | /* Return the advance width table for a given pixel size if it is found */ |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 573 | /* in the font's `hdmx' table (if any). */ |
| 574 | /* */ |
| 575 | FT_LOCAL_DEF( FT_Byte* ) |
| 576 | tt_face_get_device_metrics( TT_Face face, |
David Turner | da95af6 | 2006-03-20 13:32:33 +0000 | [diff] [blame] | 577 | FT_UInt ppem, |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 578 | FT_UInt gindex ) |
| 579 | { |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 580 | FT_UInt nn; |
| 581 | FT_Byte* result = NULL; |
| 582 | FT_ULong record_size = face->hdmx_record_size; |
| 583 | FT_Byte* record = face->hdmx_table + 8; |
| 584 | |
| 585 | |
| 586 | for ( nn = 0; nn < face->hdmx_record_count; nn++ ) |
| 587 | if ( face->hdmx_record_sizes[nn] == ppem ) |
| 588 | { |
| 589 | gindex += 2; |
| 590 | if ( gindex < record_size ) |
Wu, Chia-I (吳佳一) | facd9af | 2006-02-22 07:59:35 +0000 | [diff] [blame] | 591 | result = record + nn * record_size + gindex; |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 592 | break; |
| 593 | } |
| 594 | |
| 595 | return result; |
Wu, Chia-I (吳佳一) | f5aa47b | 2006-02-14 06:40:10 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | |
David Turner | d2b1f35 | 1999-12-16 23:11:37 +0000 | [diff] [blame] | 599 | /* END */ |