OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007,2008,2009 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009 Red Hat, Inc. |
| 3 * Copyright © 2012 Google, Inc. |
3 * | 4 * |
4 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
5 * | 6 * |
6 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
7 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
8 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
9 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
10 * all copies of this software. | 11 * all copies of this software. |
11 * | 12 * |
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR | 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES | 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN | 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
16 * DAMAGE. | 17 * DAMAGE. |
17 * | 18 * |
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, | 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS | 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO | 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
23 * | 24 * |
24 * Red Hat Author(s): Behdad Esfahbod | 25 * Red Hat Author(s): Behdad Esfahbod |
| 26 * Google Author(s): Behdad Esfahbod |
25 */ | 27 */ |
26 | 28 |
27 #ifndef HB_OPEN_FILE_PRIVATE_HH | 29 #ifndef HB_OPEN_FILE_PRIVATE_HH |
28 #define HB_OPEN_FILE_PRIVATE_HH | 30 #define HB_OPEN_FILE_PRIVATE_HH |
29 | 31 |
30 #include "hb-open-type-private.hh" | 32 #include "hb-open-type-private.hh" |
31 | 33 |
32 | 34 |
33 | 35 |
34 /* | 36 /* |
35 * | 37 * |
36 * The OpenType Font File | 38 * The OpenType Font File |
37 * | 39 * |
38 */ | 40 */ |
39 | 41 |
40 | 42 |
41 /* | 43 /* |
42 * Organization of an OpenType Font | 44 * Organization of an OpenType Font |
43 */ | 45 */ |
44 | 46 |
45 struct OpenTypeFontFile; | 47 struct OpenTypeFontFile; |
46 struct OffsetTable; | 48 struct OffsetTable; |
47 struct TTCHeader; | 49 struct TTCHeader; |
48 | 50 |
49 | 51 |
50 typedef struct TableRecord | 52 typedef struct TableRecord |
51 { | 53 { |
52 inline bool sanitize (hb_sanitize_context_t *c) { | 54 inline bool sanitize (hb_sanitize_context_t *c) { |
53 TRACE_SANITIZE (); | 55 TRACE_SANITIZE (); |
54 return c->check_struct (this); | 56 return TRACE_RETURN (c->check_struct (this)); |
55 } | 57 } |
56 | 58 |
57 Tag tag; /* 4-byte identifier. */ | 59 Tag tag; /* 4-byte identifier. */ |
58 CheckSum checkSum; /* CheckSum for this table. */ | 60 CheckSum checkSum; /* CheckSum for this table. */ |
59 ULONG offset; /* Offset from beginning of TrueType font | 61 ULONG offset; /* Offset from beginning of TrueType font |
60 * file. */ | 62 * file. */ |
61 ULONG length; /* Length of this table. */ | 63 ULONG length; /* Length of this table. */ |
62 public: | 64 public: |
63 DEFINE_SIZE_STATIC (16); | 65 DEFINE_SIZE_STATIC (16); |
64 } OpenTypeTable; | 66 } OpenTypeTable; |
(...skipping 28 matching lines...) Expand all Loading... |
93 inline const TableRecord& get_table_by_tag (hb_tag_t tag) const | 95 inline const TableRecord& get_table_by_tag (hb_tag_t tag) const |
94 { | 96 { |
95 unsigned int table_index; | 97 unsigned int table_index; |
96 find_table_index (tag, &table_index); | 98 find_table_index (tag, &table_index); |
97 return get_table (table_index); | 99 return get_table (table_index); |
98 } | 100 } |
99 | 101 |
100 public: | 102 public: |
101 inline bool sanitize (hb_sanitize_context_t *c) { | 103 inline bool sanitize (hb_sanitize_context_t *c) { |
102 TRACE_SANITIZE (); | 104 TRACE_SANITIZE (); |
103 return c->check_struct (this) | 105 return TRACE_RETURN (c->check_struct (this) && c->check_array (tables, Table
Record::static_size, numTables)); |
104 » && c->check_array (tables, TableRecord::static_size, numTables); | |
105 } | 106 } |
106 | 107 |
107 private: | 108 private: |
108 Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */ | 109 Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */ |
109 USHORT numTables; /* Number of tables. */ | 110 USHORT numTables; /* Number of tables. */ |
110 USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */ | 111 USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */ |
111 USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */ | 112 USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */ |
112 USHORT rangeShift; /* NumTables x 16-searchRange. */ | 113 USHORT rangeShift; /* NumTables x 16-searchRange. */ |
113 TableRecord tables[VAR]; /* TableRecord entries. numTables items */ | 114 TableRecord tables[VAR]; /* TableRecord entries. numTables items */ |
114 public: | 115 public: |
115 DEFINE_SIZE_ARRAY (12, tables); | 116 DEFINE_SIZE_ARRAY (12, tables); |
116 } OpenTypeFontFace; | 117 } OpenTypeFontFace; |
117 | 118 |
118 | 119 |
119 /* | 120 /* |
120 * TrueType Collections | 121 * TrueType Collections |
121 */ | 122 */ |
122 | 123 |
123 struct TTCHeaderVersion1 | 124 struct TTCHeaderVersion1 |
124 { | 125 { |
125 friend struct TTCHeader; | 126 friend struct TTCHeader; |
126 | 127 |
127 inline unsigned int get_face_count (void) const { return table.len; } | 128 inline unsigned int get_face_count (void) const { return table.len; } |
128 inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+t
able[i]; } | 129 inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+t
able[i]; } |
129 | 130 |
130 inline bool sanitize (hb_sanitize_context_t *c) { | 131 inline bool sanitize (hb_sanitize_context_t *c) { |
131 TRACE_SANITIZE (); | 132 TRACE_SANITIZE (); |
132 return table.sanitize (c, this); | 133 return TRACE_RETURN (table.sanitize (c, this)); |
133 } | 134 } |
134 | 135 |
135 private: | 136 private: |
136 Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */ | 137 Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */ |
137 FixedVersion version; /* Version of the TTC Header (1.0), | 138 FixedVersion version; /* Version of the TTC Header (1.0), |
138 * 0x00010000 */ | 139 * 0x00010000 */ |
139 LongOffsetLongArrayOf<OffsetTable> | 140 LongOffsetLongArrayOf<OffsetTable> |
140 table; /* Array of offsets to the OffsetTable for each
font | 141 table; /* Array of offsets to the OffsetTable for each
font |
141 * from the beginning of the file */ | 142 * from the beginning of the file */ |
142 public: | 143 public: |
(...skipping 18 matching lines...) Expand all Loading... |
161 { | 162 { |
162 switch (u.header.version.major) { | 163 switch (u.header.version.major) { |
163 case 2: /* version 2 is compatible with version 1 */ | 164 case 2: /* version 2 is compatible with version 1 */ |
164 case 1: return u.version1.get_face (i); | 165 case 1: return u.version1.get_face (i); |
165 default:return Null(OpenTypeFontFace); | 166 default:return Null(OpenTypeFontFace); |
166 } | 167 } |
167 } | 168 } |
168 | 169 |
169 inline bool sanitize (hb_sanitize_context_t *c) { | 170 inline bool sanitize (hb_sanitize_context_t *c) { |
170 TRACE_SANITIZE (); | 171 TRACE_SANITIZE (); |
171 if (unlikely (!u.header.version.sanitize (c))) return false; | 172 if (unlikely (!u.header.version.sanitize (c))) return TRACE_RETURN (false); |
172 switch (u.header.version.major) { | 173 switch (u.header.version.major) { |
173 case 2: /* version 2 is compatible with version 1 */ | 174 case 2: /* version 2 is compatible with version 1 */ |
174 case 1: return u.version1.sanitize (c); | 175 case 1: return TRACE_RETURN (u.version1.sanitize (c)); |
175 default:return true; | 176 default:return TRACE_RETURN (true); |
176 } | 177 } |
177 } | 178 } |
178 | 179 |
179 private: | 180 private: |
180 union { | 181 union { |
181 struct { | 182 struct { |
182 Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */ | 183 Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */ |
183 FixedVersion version; /* Version of the TTC Header (1.0 or 2.0), | 184 FixedVersion version; /* Version of the TTC Header (1.0 or 2.0), |
184 * 0x00010000 or 0x00020000 */ | 185 * 0x00010000 or 0x00020000 */ |
185 } header; | 186 } header; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 case TrueTag: | 224 case TrueTag: |
224 case Typ1Tag: | 225 case Typ1Tag: |
225 case TrueTypeTag: return u.fontFace; | 226 case TrueTypeTag: return u.fontFace; |
226 case TTCTag: return u.ttcHeader.get_face (i); | 227 case TTCTag: return u.ttcHeader.get_face (i); |
227 default: return Null(OpenTypeFontFace); | 228 default: return Null(OpenTypeFontFace); |
228 } | 229 } |
229 } | 230 } |
230 | 231 |
231 inline bool sanitize (hb_sanitize_context_t *c) { | 232 inline bool sanitize (hb_sanitize_context_t *c) { |
232 TRACE_SANITIZE (); | 233 TRACE_SANITIZE (); |
233 if (unlikely (!u.tag.sanitize (c))) return false; | 234 if (unlikely (!u.tag.sanitize (c))) return TRACE_RETURN (false); |
234 switch (u.tag) { | 235 switch (u.tag) { |
235 case CFFTag: /* All the non-collection tags */ | 236 case CFFTag: /* All the non-collection tags */ |
236 case TrueTag: | 237 case TrueTag: |
237 case Typ1Tag: | 238 case Typ1Tag: |
238 case TrueTypeTag:» return u.fontFace.sanitize (c); | 239 case TrueTypeTag:» return TRACE_RETURN (u.fontFace.sanitize (c)); |
239 case TTCTag:» return u.ttcHeader.sanitize (c); | 240 case TTCTag:» return TRACE_RETURN (u.ttcHeader.sanitize (c)); |
240 default:» » return true; | 241 default:» » return TRACE_RETURN (true); |
241 } | 242 } |
242 } | 243 } |
243 | 244 |
244 private: | 245 private: |
245 union { | 246 union { |
246 Tag tag; /* 4-byte identifier. */ | 247 Tag tag; /* 4-byte identifier. */ |
247 OpenTypeFontFace fontFace; | 248 OpenTypeFontFace fontFace; |
248 TTCHeader ttcHeader; | 249 TTCHeader ttcHeader; |
249 } u; | 250 } u; |
250 public: | 251 public: |
251 DEFINE_SIZE_UNION (4, tag); | 252 DEFINE_SIZE_UNION (4, tag); |
252 }; | 253 }; |
253 | 254 |
254 | 255 |
255 | 256 |
256 #endif /* HB_OPEN_FILE_PRIVATE_HH */ | 257 #endif /* HB_OPEN_FILE_PRIVATE_HH */ |
OLD | NEW |