Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/ots/src/gpos.cc

Issue 1252363005: Update OTS to revision a7a3b94 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/ots/src/glyf.cc ('k') | third_party/ots/src/gsub.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpos.h" 5 #include "gpos.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <vector> 8 #include <vector>
9 9
10 #include "layout.h" 10 #include "layout.h"
(...skipping 20 matching lines...) Expand all
31 }; 31 };
32 32
33 // The size of gpos header. 33 // The size of gpos header.
34 const unsigned kGposHeaderSize = 10; 34 const unsigned kGposHeaderSize = 10;
35 // The maximum format number for anchor tables. 35 // The maximum format number for anchor tables.
36 const uint16_t kMaxAnchorFormat = 3; 36 const uint16_t kMaxAnchorFormat = 3;
37 // The maximum number of class value. 37 // The maximum number of class value.
38 const uint16_t kMaxClassDefValue = 0xFFFF; 38 const uint16_t kMaxClassDefValue = 0xFFFF;
39 39
40 // Lookup type parsers. 40 // Lookup type parsers.
41 bool ParseSingleAdjustment(const ots::OpenTypeFile *file, 41 bool ParseSingleAdjustment(const ots::Font *font,
42 const uint8_t *data, const size_t length); 42 const uint8_t *data, const size_t length);
43 bool ParsePairAdjustment(const ots::OpenTypeFile *file, 43 bool ParsePairAdjustment(const ots::Font *font,
44 const uint8_t *data, const size_t length); 44 const uint8_t *data, const size_t length);
45 bool ParseCursiveAttachment(const ots::OpenTypeFile *file, 45 bool ParseCursiveAttachment(const ots::Font *font,
46 const uint8_t *data, const size_t length); 46 const uint8_t *data, const size_t length);
47 bool ParseMarkToBaseAttachment(const ots::OpenTypeFile *file, 47 bool ParseMarkToBaseAttachment(const ots::Font *font,
48 const uint8_t *data, const size_t length); 48 const uint8_t *data, const size_t length);
49 bool ParseMarkToLigatureAttachment(const ots::OpenTypeFile *file, 49 bool ParseMarkToLigatureAttachment(const ots::Font *font,
50 const uint8_t *data, const size_t length); 50 const uint8_t *data, const size_t length);
51 bool ParseMarkToMarkAttachment(const ots::OpenTypeFile *file, 51 bool ParseMarkToMarkAttachment(const ots::Font *font,
52 const uint8_t *data, const size_t length); 52 const uint8_t *data, const size_t length);
53 bool ParseContextPositioning(const ots::OpenTypeFile *file, 53 bool ParseContextPositioning(const ots::Font *font,
54 const uint8_t *data, const size_t length); 54 const uint8_t *data, const size_t length);
55 bool ParseChainedContextPositioning(const ots::OpenTypeFile *file, 55 bool ParseChainedContextPositioning(const ots::Font *font,
56 const uint8_t *data, const size_t length); 56 const uint8_t *data, const size_t length);
57 bool ParseExtensionPositioning(const ots::OpenTypeFile *file, 57 bool ParseExtensionPositioning(const ots::Font *font,
58 const uint8_t *data, const size_t length); 58 const uint8_t *data, const size_t length);
59 59
60 const ots::LookupSubtableParser::TypeParser kGposTypeParsers[] = { 60 const ots::LookupSubtableParser::TypeParser kGposTypeParsers[] = {
61 {GPOS_TYPE_SINGLE_ADJUSTMENT, ParseSingleAdjustment}, 61 {GPOS_TYPE_SINGLE_ADJUSTMENT, ParseSingleAdjustment},
62 {GPOS_TYPE_PAIR_ADJUSTMENT, ParsePairAdjustment}, 62 {GPOS_TYPE_PAIR_ADJUSTMENT, ParsePairAdjustment},
63 {GPOS_TYPE_CURSIVE_ATTACHMENT, ParseCursiveAttachment}, 63 {GPOS_TYPE_CURSIVE_ATTACHMENT, ParseCursiveAttachment},
64 {GPOS_TYPE_MARK_TO_BASE_ATTACHMENT, ParseMarkToBaseAttachment}, 64 {GPOS_TYPE_MARK_TO_BASE_ATTACHMENT, ParseMarkToBaseAttachment},
65 {GPOS_TYPE_MARK_TO_LIGATURE_ATTACHMENT, ParseMarkToLigatureAttachment}, 65 {GPOS_TYPE_MARK_TO_LIGATURE_ATTACHMENT, ParseMarkToLigatureAttachment},
66 {GPOS_TYPE_MARK_TO_MARK_ATTACHMENT, ParseMarkToMarkAttachment}, 66 {GPOS_TYPE_MARK_TO_MARK_ATTACHMENT, ParseMarkToMarkAttachment},
67 {GPOS_TYPE_CONTEXT_POSITIONING, ParseContextPositioning}, 67 {GPOS_TYPE_CONTEXT_POSITIONING, ParseContextPositioning},
68 {GPOS_TYPE_CHAINED_CONTEXT_POSITIONING, ParseChainedContextPositioning}, 68 {GPOS_TYPE_CHAINED_CONTEXT_POSITIONING, ParseChainedContextPositioning},
69 {GPOS_TYPE_EXTENSION_POSITIONING, ParseExtensionPositioning} 69 {GPOS_TYPE_EXTENSION_POSITIONING, ParseExtensionPositioning}
70 }; 70 };
71 71
72 const ots::LookupSubtableParser kGposLookupSubtableParser = { 72 const ots::LookupSubtableParser kGposLookupSubtableParser = {
73 arraysize(kGposTypeParsers), 73 arraysize(kGposTypeParsers),
74 GPOS_TYPE_EXTENSION_POSITIONING, kGposTypeParsers 74 GPOS_TYPE_EXTENSION_POSITIONING, kGposTypeParsers
75 }; 75 };
76 76
77 // Shared Tables: ValueRecord, Anchor Table, and MarkArray 77 // Shared Tables: ValueRecord, Anchor Table, and MarkArray
78 78
79 bool ParseValueRecord(const ots::OpenTypeFile *file, 79 bool ParseValueRecord(const ots::Font *font,
80 ots::Buffer* subtable, const uint8_t *data, 80 ots::Buffer* subtable, const uint8_t *data,
81 const size_t length, const uint16_t value_format) { 81 const size_t length, const uint16_t value_format) {
82 // Check existence of adjustment fields. 82 // Check existence of adjustment fields.
83 for (unsigned i = 0; i < 4; ++i) { 83 for (unsigned i = 0; i < 4; ++i) {
84 if ((value_format >> i) & 0x1) { 84 if ((value_format >> i) & 0x1) {
85 // Just read the field since these fileds could take an arbitrary values. 85 // Just read the field since these fileds could take an arbitrary values.
86 if (!subtable->Skip(2)) { 86 if (!subtable->Skip(2)) {
87 return OTS_FAILURE_MSG("Failed to read value reacord component"); 87 return OTS_FAILURE_MSG("Failed to read value reacord component");
88 } 88 }
89 } 89 }
90 } 90 }
91 91
92 // Check existence of offsets to device table. 92 // Check existence of offsets to device table.
93 for (unsigned i = 0; i < 4; ++i) { 93 for (unsigned i = 0; i < 4; ++i) {
94 if ((value_format >> (i + 4)) & 0x1) { 94 if ((value_format >> (i + 4)) & 0x1) {
95 uint16_t offset = 0; 95 uint16_t offset = 0;
96 if (!subtable->ReadU16(&offset)) { 96 if (!subtable->ReadU16(&offset)) {
97 return OTS_FAILURE_MSG("Failed to read value record offset"); 97 return OTS_FAILURE_MSG("Failed to read value record offset");
98 } 98 }
99 if (offset) { 99 if (offset) {
100 // TODO(bashi): Is it possible that device tables locate before 100 // TODO(bashi): Is it possible that device tables locate before
101 // this record? No fonts contain such offset AKAIF. 101 // this record? No fonts contain such offset AKAIF.
102 if (offset >= length) { 102 if (offset >= length) {
103 return OTS_FAILURE_MSG("Value record offset too high %d >= %ld", offse t, length); 103 return OTS_FAILURE_MSG("Value record offset too high %d >= %ld", offse t, length);
104 } 104 }
105 if (!ots::ParseDeviceTable(file, data + offset, length - offset)) { 105 if (!ots::ParseDeviceTable(font, data + offset, length - offset)) {
106 return OTS_FAILURE_MSG("Failed to parse device table in value record") ; 106 return OTS_FAILURE_MSG("Failed to parse device table in value record") ;
107 } 107 }
108 } 108 }
109 } 109 }
110 } 110 }
111 return true; 111 return true;
112 } 112 }
113 113
114 bool ParseAnchorTable(const ots::OpenTypeFile *file, 114 bool ParseAnchorTable(const ots::Font *font,
115 const uint8_t *data, const size_t length) { 115 const uint8_t *data, const size_t length) {
116 ots::Buffer subtable(data, length); 116 ots::Buffer subtable(data, length);
117 117
118 uint16_t format = 0; 118 uint16_t format = 0;
119 // Read format and skip 2 2-byte fields that could be arbitrary values. 119 // Read format and skip 2 2-byte fields that could be arbitrary values.
120 if (!subtable.ReadU16(&format) || 120 if (!subtable.ReadU16(&format) ||
121 !subtable.Skip(4)) { 121 !subtable.Skip(4)) {
122 return OTS_FAILURE_MSG("Faled to read anchor table"); 122 return OTS_FAILURE_MSG("Faled to read anchor table");
123 } 123 }
124 124
(...skipping 14 matching lines...) Expand all
139 uint16_t offset_y_device = 0; 139 uint16_t offset_y_device = 0;
140 if (!subtable.ReadU16(&offset_x_device) || 140 if (!subtable.ReadU16(&offset_x_device) ||
141 !subtable.ReadU16(&offset_y_device)) { 141 !subtable.ReadU16(&offset_y_device)) {
142 return OTS_FAILURE_MSG("Failed to read device table offsets in format 3 an chor table"); 142 return OTS_FAILURE_MSG("Failed to read device table offsets in format 3 an chor table");
143 } 143 }
144 const unsigned format_end = static_cast<unsigned>(10); 144 const unsigned format_end = static_cast<unsigned>(10);
145 if (offset_x_device) { 145 if (offset_x_device) {
146 if (offset_x_device < format_end || offset_x_device >= length) { 146 if (offset_x_device < format_end || offset_x_device >= length) {
147 return OTS_FAILURE_MSG("Bad x device table offset %d", offset_x_device); 147 return OTS_FAILURE_MSG("Bad x device table offset %d", offset_x_device);
148 } 148 }
149 if (!ots::ParseDeviceTable(file, data + offset_x_device, 149 if (!ots::ParseDeviceTable(font, data + offset_x_device,
150 length - offset_x_device)) { 150 length - offset_x_device)) {
151 return OTS_FAILURE_MSG("Failed to parse device table in anchor table"); 151 return OTS_FAILURE_MSG("Failed to parse device table in anchor table");
152 } 152 }
153 } 153 }
154 if (offset_y_device) { 154 if (offset_y_device) {
155 if (offset_y_device < format_end || offset_y_device >= length) { 155 if (offset_y_device < format_end || offset_y_device >= length) {
156 return OTS_FAILURE_MSG("Bad y device table offset %d", offset_y_device); 156 return OTS_FAILURE_MSG("Bad y device table offset %d", offset_y_device);
157 } 157 }
158 if (!ots::ParseDeviceTable(file, data + offset_y_device, 158 if (!ots::ParseDeviceTable(font, data + offset_y_device,
159 length - offset_y_device)) { 159 length - offset_y_device)) {
160 return OTS_FAILURE_MSG("Failed to parse device table in anchor table"); 160 return OTS_FAILURE_MSG("Failed to parse device table in anchor table");
161 } 161 }
162 } 162 }
163 } 163 }
164 return true; 164 return true;
165 } 165 }
166 166
167 bool ParseMarkArrayTable(const ots::OpenTypeFile *file, 167 bool ParseMarkArrayTable(const ots::Font *font,
168 const uint8_t *data, const size_t length, 168 const uint8_t *data, const size_t length,
169 const uint16_t class_count) { 169 const uint16_t class_count) {
170 ots::Buffer subtable(data, length); 170 ots::Buffer subtable(data, length);
171 171
172 uint16_t mark_count = 0; 172 uint16_t mark_count = 0;
173 if (!subtable.ReadU16(&mark_count)) { 173 if (!subtable.ReadU16(&mark_count)) {
174 return OTS_FAILURE_MSG("Can't read mark table length"); 174 return OTS_FAILURE_MSG("Can't read mark table length");
175 } 175 }
176 176
177 // MarkRecord consists of 4-bytes. 177 // MarkRecord consists of 4-bytes.
178 const unsigned mark_records_end = 4 * static_cast<unsigned>(mark_count) + 2; 178 const unsigned mark_records_end = 4 * static_cast<unsigned>(mark_count) + 2;
179 if (mark_records_end > std::numeric_limits<uint16_t>::max()) { 179 if (mark_records_end > std::numeric_limits<uint16_t>::max()) {
180 return OTS_FAILURE_MSG("Bad mark table length"); 180 return OTS_FAILURE_MSG("Bad mark table length");
181 } 181 }
182 for (unsigned i = 0; i < mark_count; ++i) { 182 for (unsigned i = 0; i < mark_count; ++i) {
183 uint16_t class_value = 0; 183 uint16_t class_value = 0;
184 uint16_t offset_mark_anchor = 0; 184 uint16_t offset_mark_anchor = 0;
185 if (!subtable.ReadU16(&class_value) || 185 if (!subtable.ReadU16(&class_value) ||
186 !subtable.ReadU16(&offset_mark_anchor)) { 186 !subtable.ReadU16(&offset_mark_anchor)) {
187 return OTS_FAILURE_MSG("Can't read mark table %d", i); 187 return OTS_FAILURE_MSG("Can't read mark table %d", i);
188 } 188 }
189 // |class_value| may take arbitrary values including 0 here so we don't 189 // |class_value| may take arbitrary values including 0 here so we don't
190 // check the value. 190 // check the value.
191 if (offset_mark_anchor < mark_records_end || 191 if (offset_mark_anchor < mark_records_end ||
192 offset_mark_anchor >= length) { 192 offset_mark_anchor >= length) {
193 return OTS_FAILURE_MSG("Bad mark anchor offset %d for mark table %d", offs et_mark_anchor, i); 193 return OTS_FAILURE_MSG("Bad mark anchor offset %d for mark table %d", offs et_mark_anchor, i);
194 } 194 }
195 if (!ParseAnchorTable(file, data + offset_mark_anchor, 195 if (!ParseAnchorTable(font, data + offset_mark_anchor,
196 length - offset_mark_anchor)) { 196 length - offset_mark_anchor)) {
197 return OTS_FAILURE_MSG("Faled to parse anchor table for mark table %d", i) ; 197 return OTS_FAILURE_MSG("Faled to parse anchor table for mark table %d", i) ;
198 } 198 }
199 } 199 }
200 200
201 return true; 201 return true;
202 } 202 }
203 203
204 // Lookup Type 1: 204 // Lookup Type 1:
205 // Single Adjustment Positioning Subtable 205 // Single Adjustment Positioning Subtable
206 bool ParseSingleAdjustment(const ots::OpenTypeFile *file, const uint8_t *data, 206 bool ParseSingleAdjustment(const ots::Font *font, const uint8_t *data,
207 const size_t length) { 207 const size_t length) {
208 ots::Buffer subtable(data, length); 208 ots::Buffer subtable(data, length);
209 209
210 uint16_t format = 0; 210 uint16_t format = 0;
211 uint16_t offset_coverage = 0; 211 uint16_t offset_coverage = 0;
212 uint16_t value_format = 0; 212 uint16_t value_format = 0;
213 if (!subtable.ReadU16(&format) || 213 if (!subtable.ReadU16(&format) ||
214 !subtable.ReadU16(&offset_coverage) || 214 !subtable.ReadU16(&offset_coverage) ||
215 !subtable.ReadU16(&value_format)) { 215 !subtable.ReadU16(&value_format)) {
216 return OTS_FAILURE_MSG("Can't read single adjustment information"); 216 return OTS_FAILURE_MSG("Can't read single adjustment information");
217 } 217 }
218 218
219 if (format == 1) { 219 if (format == 1) {
220 // Format 1 exactly one value record. 220 // Format 1 exactly one value record.
221 if (!ParseValueRecord(file, &subtable, data, length, value_format)) { 221 if (!ParseValueRecord(font, &subtable, data, length, value_format)) {
222 return OTS_FAILURE_MSG("Failed to parse format 1 single adjustment table") ; 222 return OTS_FAILURE_MSG("Failed to parse format 1 single adjustment table") ;
223 } 223 }
224 } else if (format == 2) { 224 } else if (format == 2) {
225 uint16_t value_count = 0; 225 uint16_t value_count = 0;
226 if (!subtable.ReadU16(&value_count)) { 226 if (!subtable.ReadU16(&value_count)) {
227 return OTS_FAILURE_MSG("Failed to parse format 2 single adjustment table") ; 227 return OTS_FAILURE_MSG("Failed to parse format 2 single adjustment table") ;
228 } 228 }
229 for (unsigned i = 0; i < value_count; ++i) { 229 for (unsigned i = 0; i < value_count; ++i) {
230 if (!ParseValueRecord(file, &subtable, data, length, value_format)) { 230 if (!ParseValueRecord(font, &subtable, data, length, value_format)) {
231 return OTS_FAILURE_MSG("Failed to parse value record %d in format 2 sing le adjustment table", i); 231 return OTS_FAILURE_MSG("Failed to parse value record %d in format 2 sing le adjustment table", i);
232 } 232 }
233 } 233 }
234 } else { 234 } else {
235 return OTS_FAILURE_MSG("Bad format %d in single adjustment table", format); 235 return OTS_FAILURE_MSG("Bad format %d in single adjustment table", format);
236 } 236 }
237 237
238 if (offset_coverage < subtable.offset() || offset_coverage >= length) { 238 if (offset_coverage < subtable.offset() || offset_coverage >= length) {
239 return OTS_FAILURE_MSG("Bad coverage offset %d in single adjustment table", offset_coverage); 239 return OTS_FAILURE_MSG("Bad coverage offset %d in single adjustment table", offset_coverage);
240 } 240 }
241 241
242 if (!ots::ParseCoverageTable(file, data + offset_coverage, 242 if (!ots::ParseCoverageTable(font, data + offset_coverage,
243 length - offset_coverage, 243 length - offset_coverage,
244 file->maxp->num_glyphs)) { 244 font->maxp->num_glyphs)) {
245 return OTS_FAILURE_MSG("Failed to parse coverage table in single adjustment table"); 245 return OTS_FAILURE_MSG("Failed to parse coverage table in single adjustment table");
246 } 246 }
247 247
248 return true; 248 return true;
249 } 249 }
250 250
251 bool ParsePairSetTable(const ots::OpenTypeFile *file, 251 bool ParsePairSetTable(const ots::Font *font,
252 const uint8_t *data, const size_t length, 252 const uint8_t *data, const size_t length,
253 const uint16_t value_format1, 253 const uint16_t value_format1,
254 const uint16_t value_format2, 254 const uint16_t value_format2,
255 const uint16_t num_glyphs) { 255 const uint16_t num_glyphs) {
256 ots::Buffer subtable(data, length); 256 ots::Buffer subtable(data, length);
257 257
258 uint16_t value_count = 0; 258 uint16_t value_count = 0;
259 if (!subtable.ReadU16(&value_count)) { 259 if (!subtable.ReadU16(&value_count)) {
260 return OTS_FAILURE_MSG("Failed to read pair set table structure"); 260 return OTS_FAILURE_MSG("Failed to read pair set table structure");
261 } 261 }
262 for (unsigned i = 0; i < value_count; ++i) { 262 for (unsigned i = 0; i < value_count; ++i) {
263 // Check pair value record. 263 // Check pair value record.
264 uint16_t glyph_id = 0; 264 uint16_t glyph_id = 0;
265 if (!subtable.ReadU16(&glyph_id)) { 265 if (!subtable.ReadU16(&glyph_id)) {
266 return OTS_FAILURE_MSG("Failed to read glyph in pair value record %d", i); 266 return OTS_FAILURE_MSG("Failed to read glyph in pair value record %d", i);
267 } 267 }
268 if (glyph_id >= num_glyphs) { 268 if (glyph_id >= num_glyphs) {
269 return OTS_FAILURE_MSG("glyph id %d too high >= %d", glyph_id, num_glyphs) ; 269 return OTS_FAILURE_MSG("glyph id %d too high >= %d", glyph_id, num_glyphs) ;
270 } 270 }
271 if (!ParseValueRecord(file, &subtable, data, length, value_format1)) { 271 if (!ParseValueRecord(font, &subtable, data, length, value_format1)) {
272 return OTS_FAILURE_MSG("Failed to parse value record in format 1 pair set table"); 272 return OTS_FAILURE_MSG("Failed to parse value record in format 1 pair set table");
273 } 273 }
274 if (!ParseValueRecord(file, &subtable, data, length, value_format2)) { 274 if (!ParseValueRecord(font, &subtable, data, length, value_format2)) {
275 return OTS_FAILURE_MSG("Failed to parse value record in format 2 pair set table"); 275 return OTS_FAILURE_MSG("Failed to parse value record in format 2 pair set table");
276 } 276 }
277 } 277 }
278 return true; 278 return true;
279 } 279 }
280 280
281 bool ParsePairPosFormat1(const ots::OpenTypeFile *file, 281 bool ParsePairPosFormat1(const ots::Font *font,
282 const uint8_t *data, const size_t length, 282 const uint8_t *data, const size_t length,
283 const uint16_t value_format1, 283 const uint16_t value_format1,
284 const uint16_t value_format2, 284 const uint16_t value_format2,
285 const uint16_t num_glyphs) { 285 const uint16_t num_glyphs) {
286 ots::Buffer subtable(data, length); 286 ots::Buffer subtable(data, length);
287 287
288 // Skip 8 bytes that are already read before. 288 // Skip 8 bytes that are already read before.
289 if (!subtable.Skip(8)) { 289 if (!subtable.Skip(8)) {
290 return OTS_FAILURE_MSG("Failed to read pair pos table structure"); 290 return OTS_FAILURE_MSG("Failed to read pair pos table structure");
291 } 291 }
292 292
293 uint16_t pair_set_count = 0; 293 uint16_t pair_set_count = 0;
294 if (!subtable.ReadU16(&pair_set_count)) { 294 if (!subtable.ReadU16(&pair_set_count)) {
295 return OTS_FAILURE_MSG("Failed to read pair pos set count"); 295 return OTS_FAILURE_MSG("Failed to read pair pos set count");
296 } 296 }
297 297
298 const unsigned pair_pos_end = 2 * static_cast<unsigned>(pair_set_count) + 10; 298 const unsigned pair_pos_end = 2 * static_cast<unsigned>(pair_set_count) + 10;
299 if (pair_pos_end > std::numeric_limits<uint16_t>::max()) { 299 if (pair_pos_end > std::numeric_limits<uint16_t>::max()) {
300 return OTS_FAILURE_MSG("Bad pair set length %d", pair_pos_end); 300 return OTS_FAILURE_MSG("Bad pair set length %d", pair_pos_end);
301 } 301 }
302 for (unsigned i = 0; i < pair_set_count; ++i) { 302 for (unsigned i = 0; i < pair_set_count; ++i) {
303 uint16_t pair_set_offset = 0; 303 uint16_t pair_set_offset = 0;
304 if (!subtable.ReadU16(&pair_set_offset)) { 304 if (!subtable.ReadU16(&pair_set_offset)) {
305 return OTS_FAILURE_MSG("Failed to read pair set offset for pair set %d", i ); 305 return OTS_FAILURE_MSG("Failed to read pair set offset for pair set %d", i );
306 } 306 }
307 if (pair_set_offset < pair_pos_end || pair_set_offset >= length) { 307 if (pair_set_offset < pair_pos_end || pair_set_offset >= length) {
308 return OTS_FAILURE_MSG("Bad pair set offset %d for pair set %d", pair_set_ offset, i); 308 return OTS_FAILURE_MSG("Bad pair set offset %d for pair set %d", pair_set_ offset, i);
309 } 309 }
310 // Check pair set tables 310 // Check pair set tables
311 if (!ParsePairSetTable(file, data + pair_set_offset, length - pair_set_offse t, 311 if (!ParsePairSetTable(font, data + pair_set_offset, length - pair_set_offse t,
312 value_format1, value_format2, 312 value_format1, value_format2,
313 num_glyphs)) { 313 num_glyphs)) {
314 return OTS_FAILURE_MSG("Failed to parse pair set table %d", i); 314 return OTS_FAILURE_MSG("Failed to parse pair set table %d", i);
315 } 315 }
316 } 316 }
317 317
318 return true; 318 return true;
319 } 319 }
320 320
321 bool ParsePairPosFormat2(const ots::OpenTypeFile *file, 321 bool ParsePairPosFormat2(const ots::Font *font,
322 const uint8_t *data, const size_t length, 322 const uint8_t *data, const size_t length,
323 const uint16_t value_format1, 323 const uint16_t value_format1,
324 const uint16_t value_format2, 324 const uint16_t value_format2,
325 const uint16_t num_glyphs) { 325 const uint16_t num_glyphs) {
326 ots::Buffer subtable(data, length); 326 ots::Buffer subtable(data, length);
327 327
328 // Skip 8 bytes that are already read before. 328 // Skip 8 bytes that are already read before.
329 if (!subtable.Skip(8)) { 329 if (!subtable.Skip(8)) {
330 return OTS_FAILURE_MSG("Failed to read pair pos format 2 structure"); 330 return OTS_FAILURE_MSG("Failed to read pair pos format 2 structure");
331 } 331 }
332 332
333 uint16_t offset_class_def1 = 0; 333 uint16_t offset_class_def1 = 0;
334 uint16_t offset_class_def2 = 0; 334 uint16_t offset_class_def2 = 0;
335 uint16_t class1_count = 0; 335 uint16_t class1_count = 0;
336 uint16_t class2_count = 0; 336 uint16_t class2_count = 0;
337 if (!subtable.ReadU16(&offset_class_def1) || 337 if (!subtable.ReadU16(&offset_class_def1) ||
338 !subtable.ReadU16(&offset_class_def2) || 338 !subtable.ReadU16(&offset_class_def2) ||
339 !subtable.ReadU16(&class1_count) || 339 !subtable.ReadU16(&class1_count) ||
340 !subtable.ReadU16(&class2_count)) { 340 !subtable.ReadU16(&class2_count)) {
341 return OTS_FAILURE_MSG("Failed to read pair pos format 2 data"); 341 return OTS_FAILURE_MSG("Failed to read pair pos format 2 data");
342 } 342 }
343 343
344 // Check class 1 records. 344 // Check class 1 records.
345 for (unsigned i = 0; i < class1_count; ++i) { 345 for (unsigned i = 0; i < class1_count; ++i) {
346 // Check class 2 records. 346 // Check class 2 records.
347 for (unsigned j = 0; j < class2_count; ++j) { 347 for (unsigned j = 0; j < class2_count; ++j) {
348 if (value_format1 && !ParseValueRecord(file, &subtable, data, length, 348 if (value_format1 && !ParseValueRecord(font, &subtable, data, length,
349 value_format1)) { 349 value_format1)) {
350 return OTS_FAILURE_MSG("Failed to parse value record 1 %d and %d", j, i) ; 350 return OTS_FAILURE_MSG("Failed to parse value record 1 %d and %d", j, i) ;
351 } 351 }
352 if (value_format2 && !ParseValueRecord(file, &subtable, data, length, 352 if (value_format2 && !ParseValueRecord(font, &subtable, data, length,
353 value_format2)) { 353 value_format2)) {
354 return OTS_FAILURE_MSG("Falied to parse value record 2 %d and %d", j, i) ; 354 return OTS_FAILURE_MSG("Falied to parse value record 2 %d and %d", j, i) ;
355 } 355 }
356 } 356 }
357 } 357 }
358 358
359 // Check class definition tables. 359 // Check class definition tables.
360 if (offset_class_def1 < subtable.offset() || offset_class_def1 >= length || 360 if (offset_class_def1 < subtable.offset() || offset_class_def1 >= length ||
361 offset_class_def2 < subtable.offset() || offset_class_def2 >= length) { 361 offset_class_def2 < subtable.offset() || offset_class_def2 >= length) {
362 return OTS_FAILURE_MSG("Bad class definition table offsets %d or %d", offset _class_def1, offset_class_def2); 362 return OTS_FAILURE_MSG("Bad class definition table offsets %d or %d", offset _class_def1, offset_class_def2);
363 } 363 }
364 if (!ots::ParseClassDefTable(file, data + offset_class_def1, 364 if (!ots::ParseClassDefTable(font, data + offset_class_def1,
365 length - offset_class_def1, 365 length - offset_class_def1,
366 num_glyphs, kMaxClassDefValue)) { 366 num_glyphs, kMaxClassDefValue)) {
367 return OTS_FAILURE_MSG("Failed to parse class definition table 1"); 367 return OTS_FAILURE_MSG("Failed to parse class definition table 1");
368 } 368 }
369 if (!ots::ParseClassDefTable(file, data + offset_class_def2, 369 if (!ots::ParseClassDefTable(font, data + offset_class_def2,
370 length - offset_class_def2, 370 length - offset_class_def2,
371 num_glyphs, kMaxClassDefValue)) { 371 num_glyphs, kMaxClassDefValue)) {
372 return OTS_FAILURE_MSG("Failed to parse class definition table 2"); 372 return OTS_FAILURE_MSG("Failed to parse class definition table 2");
373 } 373 }
374 374
375 return true; 375 return true;
376 } 376 }
377 377
378 // Lookup Type 2: 378 // Lookup Type 2:
379 // Pair Adjustment Positioning Subtable 379 // Pair Adjustment Positioning Subtable
380 bool ParsePairAdjustment(const ots::OpenTypeFile *file, const uint8_t *data, 380 bool ParsePairAdjustment(const ots::Font *font, const uint8_t *data,
381 const size_t length) { 381 const size_t length) {
382 ots::Buffer subtable(data, length); 382 ots::Buffer subtable(data, length);
383 383
384 uint16_t format = 0; 384 uint16_t format = 0;
385 uint16_t offset_coverage = 0; 385 uint16_t offset_coverage = 0;
386 uint16_t value_format1 = 0; 386 uint16_t value_format1 = 0;
387 uint16_t value_format2 = 0; 387 uint16_t value_format2 = 0;
388 if (!subtable.ReadU16(&format) || 388 if (!subtable.ReadU16(&format) ||
389 !subtable.ReadU16(&offset_coverage) || 389 !subtable.ReadU16(&offset_coverage) ||
390 !subtable.ReadU16(&value_format1) || 390 !subtable.ReadU16(&value_format1) ||
391 !subtable.ReadU16(&value_format2)) { 391 !subtable.ReadU16(&value_format2)) {
392 return OTS_FAILURE_MSG("Failed to read pair adjustment structure"); 392 return OTS_FAILURE_MSG("Failed to read pair adjustment structure");
393 } 393 }
394 394
395 if (format == 1) { 395 if (format == 1) {
396 if (!ParsePairPosFormat1(file, data, length, value_format1, value_format2, 396 if (!ParsePairPosFormat1(font, data, length, value_format1, value_format2,
397 file->maxp->num_glyphs)) { 397 font->maxp->num_glyphs)) {
398 return OTS_FAILURE_MSG("Failed to parse pair pos format 1"); 398 return OTS_FAILURE_MSG("Failed to parse pair pos format 1");
399 } 399 }
400 } else if (format == 2) { 400 } else if (format == 2) {
401 if (!ParsePairPosFormat2(file, data, length, value_format1, value_format2, 401 if (!ParsePairPosFormat2(font, data, length, value_format1, value_format2,
402 file->maxp->num_glyphs)) { 402 font->maxp->num_glyphs)) {
403 return OTS_FAILURE_MSG("Failed to parse pair format 2"); 403 return OTS_FAILURE_MSG("Failed to parse pair format 2");
404 } 404 }
405 } else { 405 } else {
406 return OTS_FAILURE_MSG("Bad pos pair format %d", format); 406 return OTS_FAILURE_MSG("Bad pos pair format %d", format);
407 } 407 }
408 408
409 if (offset_coverage < subtable.offset() || offset_coverage >= length) { 409 if (offset_coverage < subtable.offset() || offset_coverage >= length) {
410 return OTS_FAILURE_MSG("Bad pair pos offset coverage %d", offset_coverage); 410 return OTS_FAILURE_MSG("Bad pair pos offset coverage %d", offset_coverage);
411 } 411 }
412 if (!ots::ParseCoverageTable(file, data + offset_coverage, 412 if (!ots::ParseCoverageTable(font, data + offset_coverage,
413 length - offset_coverage, 413 length - offset_coverage,
414 file->maxp->num_glyphs)) { 414 font->maxp->num_glyphs)) {
415 return OTS_FAILURE_MSG("Failed to parse coverage table"); 415 return OTS_FAILURE_MSG("Failed to parse coverage table");
416 } 416 }
417 417
418 return true; 418 return true;
419 } 419 }
420 420
421 // Lookup Type 3 421 // Lookup Type 3
422 // Cursive Attachment Positioning Subtable 422 // Cursive Attachment Positioning Subtable
423 bool ParseCursiveAttachment(const ots::OpenTypeFile *file, const uint8_t *data, 423 bool ParseCursiveAttachment(const ots::Font *font, const uint8_t *data,
424 const size_t length) { 424 const size_t length) {
425 ots::Buffer subtable(data, length); 425 ots::Buffer subtable(data, length);
426 426
427 uint16_t format = 0; 427 uint16_t format = 0;
428 uint16_t offset_coverage = 0; 428 uint16_t offset_coverage = 0;
429 uint16_t entry_exit_count = 0; 429 uint16_t entry_exit_count = 0;
430 if (!subtable.ReadU16(&format) || 430 if (!subtable.ReadU16(&format) ||
431 !subtable.ReadU16(&offset_coverage) || 431 !subtable.ReadU16(&offset_coverage) ||
432 !subtable.ReadU16(&entry_exit_count)) { 432 !subtable.ReadU16(&entry_exit_count)) {
433 return OTS_FAILURE_MSG("Failed to read cursive attachment structure"); 433 return OTS_FAILURE_MSG("Failed to read cursive attachment structure");
(...skipping 15 matching lines...) Expand all
449 if (!subtable.ReadU16(&offset_entry_anchor) || 449 if (!subtable.ReadU16(&offset_entry_anchor) ||
450 !subtable.ReadU16(&offset_exit_anchor)) { 450 !subtable.ReadU16(&offset_exit_anchor)) {
451 return OTS_FAILURE_MSG("Can't read entry exit record %d", i); 451 return OTS_FAILURE_MSG("Can't read entry exit record %d", i);
452 } 452 }
453 // These offsets could be NULL. 453 // These offsets could be NULL.
454 if (offset_entry_anchor) { 454 if (offset_entry_anchor) {
455 if (offset_entry_anchor < entry_exit_records_end || 455 if (offset_entry_anchor < entry_exit_records_end ||
456 offset_entry_anchor >= length) { 456 offset_entry_anchor >= length) {
457 return OTS_FAILURE_MSG("Bad entry anchor offset %d in entry exit record %d", offset_entry_anchor, i); 457 return OTS_FAILURE_MSG("Bad entry anchor offset %d in entry exit record %d", offset_entry_anchor, i);
458 } 458 }
459 if (!ParseAnchorTable(file, data + offset_entry_anchor, 459 if (!ParseAnchorTable(font, data + offset_entry_anchor,
460 length - offset_entry_anchor)) { 460 length - offset_entry_anchor)) {
461 return OTS_FAILURE_MSG("Failed to parse entry anchor table in entry exit record %d", i); 461 return OTS_FAILURE_MSG("Failed to parse entry anchor table in entry exit record %d", i);
462 } 462 }
463 } 463 }
464 if (offset_exit_anchor) { 464 if (offset_exit_anchor) {
465 if (offset_exit_anchor < entry_exit_records_end || 465 if (offset_exit_anchor < entry_exit_records_end ||
466 offset_exit_anchor >= length) { 466 offset_exit_anchor >= length) {
467 return OTS_FAILURE_MSG("Bad exit anchor offset %d in entry exit record % d", offset_exit_anchor, i); 467 return OTS_FAILURE_MSG("Bad exit anchor offset %d in entry exit record % d", offset_exit_anchor, i);
468 } 468 }
469 if (!ParseAnchorTable(file, data + offset_exit_anchor, 469 if (!ParseAnchorTable(font, data + offset_exit_anchor,
470 length - offset_exit_anchor)) { 470 length - offset_exit_anchor)) {
471 return OTS_FAILURE_MSG("Failed to parse exit anchor table in entry exit record %d", i); 471 return OTS_FAILURE_MSG("Failed to parse exit anchor table in entry exit record %d", i);
472 } 472 }
473 } 473 }
474 } 474 }
475 475
476 if (offset_coverage < subtable.offset() || offset_coverage >= length) { 476 if (offset_coverage < subtable.offset() || offset_coverage >= length) {
477 return OTS_FAILURE_MSG("Bad coverage offset in cursive attachment %d", offse t_coverage); 477 return OTS_FAILURE_MSG("Bad coverage offset in cursive attachment %d", offse t_coverage);
478 } 478 }
479 if (!ots::ParseCoverageTable(file, data + offset_coverage, 479 if (!ots::ParseCoverageTable(font, data + offset_coverage,
480 length - offset_coverage, 480 length - offset_coverage,
481 file->maxp->num_glyphs)) { 481 font->maxp->num_glyphs)) {
482 return OTS_FAILURE_MSG("Failed to parse coverage table in cursive attachment "); 482 return OTS_FAILURE_MSG("Failed to parse coverage table in cursive attachment ");
483 } 483 }
484 484
485 return true; 485 return true;
486 } 486 }
487 487
488 bool ParseAnchorArrayTable(const ots::OpenTypeFile *file, 488 bool ParseAnchorArrayTable(const ots::Font *font,
489 const uint8_t *data, const size_t length, 489 const uint8_t *data, const size_t length,
490 const uint16_t class_count) { 490 const uint16_t class_count) {
491 ots::Buffer subtable(data, length); 491 ots::Buffer subtable(data, length);
492 492
493 uint16_t record_count = 0; 493 uint16_t record_count = 0;
494 if (!subtable.ReadU16(&record_count)) { 494 if (!subtable.ReadU16(&record_count)) {
495 return OTS_FAILURE_MSG("Can't read anchor array length"); 495 return OTS_FAILURE_MSG("Can't read anchor array length");
496 } 496 }
497 497
498 const unsigned anchor_array_end = 2 * static_cast<unsigned>(record_count) * 498 const unsigned anchor_array_end = 2 * static_cast<unsigned>(record_count) *
499 static_cast<unsigned>(class_count) + 2; 499 static_cast<unsigned>(class_count) + 2;
500 if (anchor_array_end > std::numeric_limits<uint16_t>::max()) { 500 if (anchor_array_end > std::numeric_limits<uint16_t>::max()) {
501 return OTS_FAILURE_MSG("Bad end of anchor array %d", anchor_array_end); 501 return OTS_FAILURE_MSG("Bad end of anchor array %d", anchor_array_end);
502 } 502 }
503 for (unsigned i = 0; i < record_count; ++i) { 503 for (unsigned i = 0; i < record_count; ++i) {
504 for (unsigned j = 0; j < class_count; ++j) { 504 for (unsigned j = 0; j < class_count; ++j) {
505 uint16_t offset_record = 0; 505 uint16_t offset_record = 0;
506 if (!subtable.ReadU16(&offset_record)) { 506 if (!subtable.ReadU16(&offset_record)) {
507 return OTS_FAILURE_MSG("Can't read anchor array record offset for class %d and record %d", j, i); 507 return OTS_FAILURE_MSG("Can't read anchor array record offset for class %d and record %d", j, i);
508 } 508 }
509 // |offset_record| could be NULL. 509 // |offset_record| could be NULL.
510 if (offset_record) { 510 if (offset_record) {
511 if (offset_record < anchor_array_end || offset_record >= length) { 511 if (offset_record < anchor_array_end || offset_record >= length) {
512 return OTS_FAILURE_MSG("Bad record offset %d in class %d, record %d", offset_record, j, i); 512 return OTS_FAILURE_MSG("Bad record offset %d in class %d, record %d", offset_record, j, i);
513 } 513 }
514 if (!ParseAnchorTable(file, data + offset_record, 514 if (!ParseAnchorTable(font, data + offset_record,
515 length - offset_record)) { 515 length - offset_record)) {
516 return OTS_FAILURE_MSG("Failed to parse anchor table for class %d, rec ord %d", j, i); 516 return OTS_FAILURE_MSG("Failed to parse anchor table for class %d, rec ord %d", j, i);
517 } 517 }
518 } 518 }
519 } 519 }
520 } 520 }
521 return true; 521 return true;
522 } 522 }
523 523
524 bool ParseLigatureArrayTable(const ots::OpenTypeFile *file, 524 bool ParseLigatureArrayTable(const ots::Font *font,
525 const uint8_t *data, const size_t length, 525 const uint8_t *data, const size_t length,
526 const uint16_t class_count) { 526 const uint16_t class_count) {
527 ots::Buffer subtable(data, length); 527 ots::Buffer subtable(data, length);
528 528
529 uint16_t ligature_count = 0; 529 uint16_t ligature_count = 0;
530 if (!subtable.ReadU16(&ligature_count)) { 530 if (!subtable.ReadU16(&ligature_count)) {
531 return OTS_FAILURE_MSG("Failed to read ligature count"); 531 return OTS_FAILURE_MSG("Failed to read ligature count");
532 } 532 }
533 for (unsigned i = 0; i < ligature_count; ++i) { 533 for (unsigned i = 0; i < ligature_count; ++i) {
534 uint16_t offset_ligature_attach = 0; 534 uint16_t offset_ligature_attach = 0;
535 if (!subtable.ReadU16(&offset_ligature_attach)) { 535 if (!subtable.ReadU16(&offset_ligature_attach)) {
536 return OTS_FAILURE_MSG("Can't read ligature offset %d", i); 536 return OTS_FAILURE_MSG("Can't read ligature offset %d", i);
537 } 537 }
538 if (offset_ligature_attach < 2 || offset_ligature_attach >= length) { 538 if (offset_ligature_attach < 2 || offset_ligature_attach >= length) {
539 return OTS_FAILURE_MSG("Bad ligature attachment offset %d in ligature %d", offset_ligature_attach, i); 539 return OTS_FAILURE_MSG("Bad ligature attachment offset %d in ligature %d", offset_ligature_attach, i);
540 } 540 }
541 if (!ParseAnchorArrayTable(file, data + offset_ligature_attach, 541 if (!ParseAnchorArrayTable(font, data + offset_ligature_attach,
542 length - offset_ligature_attach, class_count)) { 542 length - offset_ligature_attach, class_count)) {
543 return OTS_FAILURE_MSG("Failed to parse anchor table for ligature %d", i); 543 return OTS_FAILURE_MSG("Failed to parse anchor table for ligature %d", i);
544 } 544 }
545 } 545 }
546 return true; 546 return true;
547 } 547 }
548 548
549 // Common parser for Lookup Type 4, 5 and 6. 549 // Common parser for Lookup Type 4, 5 and 6.
550 bool ParseMarkToAttachmentSubtables(const ots::OpenTypeFile *file, 550 bool ParseMarkToAttachmentSubtables(const ots::Font *font,
551 const uint8_t *data, const size_t length, 551 const uint8_t *data, const size_t length,
552 const GPOS_TYPE type) { 552 const GPOS_TYPE type) {
553 ots::Buffer subtable(data, length); 553 ots::Buffer subtable(data, length);
554 554
555 uint16_t format = 0; 555 uint16_t format = 0;
556 uint16_t offset_coverage1 = 0; 556 uint16_t offset_coverage1 = 0;
557 uint16_t offset_coverage2 = 0; 557 uint16_t offset_coverage2 = 0;
558 uint16_t class_count = 0; 558 uint16_t class_count = 0;
559 uint16_t offset_mark_array = 0; 559 uint16_t offset_mark_array = 0;
560 uint16_t offset_type_specific_array = 0; 560 uint16_t offset_type_specific_array = 0;
(...skipping 10 matching lines...) Expand all
571 return OTS_FAILURE_MSG("bad mark attachment subtable format %d", format); 571 return OTS_FAILURE_MSG("bad mark attachment subtable format %d", format);
572 } 572 }
573 573
574 const unsigned header_end = static_cast<unsigned>(subtable.offset()); 574 const unsigned header_end = static_cast<unsigned>(subtable.offset());
575 if (header_end > std::numeric_limits<uint16_t>::max()) { 575 if (header_end > std::numeric_limits<uint16_t>::max()) {
576 return OTS_FAILURE_MSG("Bad mark attachment subtable size ending at %d", hea der_end); 576 return OTS_FAILURE_MSG("Bad mark attachment subtable size ending at %d", hea der_end);
577 } 577 }
578 if (offset_coverage1 < header_end || offset_coverage1 >= length) { 578 if (offset_coverage1 < header_end || offset_coverage1 >= length) {
579 return OTS_FAILURE_MSG("Bad coverage 1 offset %d", offset_coverage1); 579 return OTS_FAILURE_MSG("Bad coverage 1 offset %d", offset_coverage1);
580 } 580 }
581 if (!ots::ParseCoverageTable(file, data + offset_coverage1, 581 if (!ots::ParseCoverageTable(font, data + offset_coverage1,
582 length - offset_coverage1, 582 length - offset_coverage1,
583 file->maxp->num_glyphs)) { 583 font->maxp->num_glyphs)) {
584 return OTS_FAILURE_MSG("Failed to parse converge 1 table"); 584 return OTS_FAILURE_MSG("Failed to parse converge 1 table");
585 } 585 }
586 if (offset_coverage2 < header_end || offset_coverage2 >= length) { 586 if (offset_coverage2 < header_end || offset_coverage2 >= length) {
587 return OTS_FAILURE_MSG("Bad coverage 2 offset %d", offset_coverage2); 587 return OTS_FAILURE_MSG("Bad coverage 2 offset %d", offset_coverage2);
588 } 588 }
589 if (!ots::ParseCoverageTable(file, data + offset_coverage2, 589 if (!ots::ParseCoverageTable(font, data + offset_coverage2,
590 length - offset_coverage2, 590 length - offset_coverage2,
591 file->maxp->num_glyphs)) { 591 font->maxp->num_glyphs)) {
592 return OTS_FAILURE_MSG("Failed to parse coverage table 2"); 592 return OTS_FAILURE_MSG("Failed to parse coverage table 2");
593 } 593 }
594 594
595 if (offset_mark_array < header_end || offset_mark_array >= length) { 595 if (offset_mark_array < header_end || offset_mark_array >= length) {
596 return OTS_FAILURE_MSG("Bad mark array offset %d", offset_mark_array); 596 return OTS_FAILURE_MSG("Bad mark array offset %d", offset_mark_array);
597 } 597 }
598 if (!ParseMarkArrayTable(file, data + offset_mark_array, 598 if (!ParseMarkArrayTable(font, data + offset_mark_array,
599 length - offset_mark_array, class_count)) { 599 length - offset_mark_array, class_count)) {
600 return OTS_FAILURE_MSG("Failed to parse mark array"); 600 return OTS_FAILURE_MSG("Failed to parse mark array");
601 } 601 }
602 602
603 if (offset_type_specific_array < header_end || 603 if (offset_type_specific_array < header_end ||
604 offset_type_specific_array >= length) { 604 offset_type_specific_array >= length) {
605 return OTS_FAILURE_MSG("Bad type specific array offset %d", offset_type_spec ific_array); 605 return OTS_FAILURE_MSG("Bad type specific array offset %d", offset_type_spec ific_array);
606 } 606 }
607 if (type == GPOS_TYPE_MARK_TO_BASE_ATTACHMENT || 607 if (type == GPOS_TYPE_MARK_TO_BASE_ATTACHMENT ||
608 type == GPOS_TYPE_MARK_TO_MARK_ATTACHMENT) { 608 type == GPOS_TYPE_MARK_TO_MARK_ATTACHMENT) {
609 if (!ParseAnchorArrayTable(file, data + offset_type_specific_array, 609 if (!ParseAnchorArrayTable(font, data + offset_type_specific_array,
610 length - offset_type_specific_array, 610 length - offset_type_specific_array,
611 class_count)) { 611 class_count)) {
612 return OTS_FAILURE_MSG("Failed to parse anchor array"); 612 return OTS_FAILURE_MSG("Failed to parse anchor array");
613 } 613 }
614 } else if (type == GPOS_TYPE_MARK_TO_LIGATURE_ATTACHMENT) { 614 } else if (type == GPOS_TYPE_MARK_TO_LIGATURE_ATTACHMENT) {
615 if (!ParseLigatureArrayTable(file, data + offset_type_specific_array, 615 if (!ParseLigatureArrayTable(font, data + offset_type_specific_array,
616 length - offset_type_specific_array, 616 length - offset_type_specific_array,
617 class_count)) { 617 class_count)) {
618 return OTS_FAILURE_MSG("Failed to parse ligature array"); 618 return OTS_FAILURE_MSG("Failed to parse ligature array");
619 } 619 }
620 } else { 620 } else {
621 return OTS_FAILURE_MSG("Bad attachment type %d", type); 621 return OTS_FAILURE_MSG("Bad attachment type %d", type);
622 } 622 }
623 623
624 return true; 624 return true;
625 } 625 }
626 626
627 // Lookup Type 4: 627 // Lookup Type 4:
628 // MarkToBase Attachment Positioning Subtable 628 // MarkToBase Attachment Positioning Subtable
629 bool ParseMarkToBaseAttachment(const ots::OpenTypeFile *file, 629 bool ParseMarkToBaseAttachment(const ots::Font *font,
630 const uint8_t *data, const size_t length) { 630 const uint8_t *data, const size_t length) {
631 return ParseMarkToAttachmentSubtables(file, data, length, 631 return ParseMarkToAttachmentSubtables(font, data, length,
632 GPOS_TYPE_MARK_TO_BASE_ATTACHMENT); 632 GPOS_TYPE_MARK_TO_BASE_ATTACHMENT);
633 } 633 }
634 634
635 // Lookup Type 5: 635 // Lookup Type 5:
636 // MarkToLigature Attachment Positioning Subtable 636 // MarkToLigature Attachment Positioning Subtable
637 bool ParseMarkToLigatureAttachment(const ots::OpenTypeFile *file, 637 bool ParseMarkToLigatureAttachment(const ots::Font *font,
638 const uint8_t *data, const size_t length) { 638 const uint8_t *data, const size_t length) {
639 return ParseMarkToAttachmentSubtables(file, data, length, 639 return ParseMarkToAttachmentSubtables(font, data, length,
640 GPOS_TYPE_MARK_TO_LIGATURE_ATTACHMENT); 640 GPOS_TYPE_MARK_TO_LIGATURE_ATTACHMENT);
641 } 641 }
642 642
643 // Lookup Type 6: 643 // Lookup Type 6:
644 // MarkToMark Attachment Positioning Subtable 644 // MarkToMark Attachment Positioning Subtable
645 bool ParseMarkToMarkAttachment(const ots::OpenTypeFile *file, 645 bool ParseMarkToMarkAttachment(const ots::Font *font,
646 const uint8_t *data, const size_t length) { 646 const uint8_t *data, const size_t length) {
647 return ParseMarkToAttachmentSubtables(file, data, length, 647 return ParseMarkToAttachmentSubtables(font, data, length,
648 GPOS_TYPE_MARK_TO_MARK_ATTACHMENT); 648 GPOS_TYPE_MARK_TO_MARK_ATTACHMENT);
649 } 649 }
650 650
651 // Lookup Type 7: 651 // Lookup Type 7:
652 // Contextual Positioning Subtables 652 // Contextual Positioning Subtables
653 bool ParseContextPositioning(const ots::OpenTypeFile *file, 653 bool ParseContextPositioning(const ots::Font *font,
654 const uint8_t *data, const size_t length) { 654 const uint8_t *data, const size_t length) {
655 return ots::ParseContextSubtable(file, data, length, file->maxp->num_glyphs, 655 return ots::ParseContextSubtable(font, data, length, font->maxp->num_glyphs,
656 file->gpos->num_lookups); 656 font->gpos->num_lookups);
657 } 657 }
658 658
659 // Lookup Type 8: 659 // Lookup Type 8:
660 // Chaining Contexual Positioning Subtable 660 // Chaining Contexual Positioning Subtable
661 bool ParseChainedContextPositioning(const ots::OpenTypeFile *file, 661 bool ParseChainedContextPositioning(const ots::Font *font,
662 const uint8_t *data, const size_t length) { 662 const uint8_t *data, const size_t length) {
663 return ots::ParseChainingContextSubtable(file, data, length, 663 return ots::ParseChainingContextSubtable(font, data, length,
664 file->maxp->num_glyphs, 664 font->maxp->num_glyphs,
665 file->gpos->num_lookups); 665 font->gpos->num_lookups);
666 } 666 }
667 667
668 // Lookup Type 9: 668 // Lookup Type 9:
669 // Extension Positioning 669 // Extension Positioning
670 bool ParseExtensionPositioning(const ots::OpenTypeFile *file, 670 bool ParseExtensionPositioning(const ots::Font *font,
671 const uint8_t *data, const size_t length) { 671 const uint8_t *data, const size_t length) {
672 return ots::ParseExtensionSubtable(file, data, length, 672 return ots::ParseExtensionSubtable(font, data, length,
673 &kGposLookupSubtableParser); 673 &kGposLookupSubtableParser);
674 } 674 }
675 675
676 } // namespace 676 } // namespace
677 677
678 #define DROP_THIS_TABLE(msg_) \ 678 #define DROP_THIS_TABLE(msg_) \
679 do { \ 679 do { \
680 OTS_FAILURE_MSG(msg_ ", table discarded"); \ 680 OTS_FAILURE_MSG(msg_ ", table discarded"); \
681 file->gpos->data = 0; \ 681 font->gpos->data = 0; \
682 file->gpos->length = 0; \ 682 font->gpos->length = 0; \
683 } while (0) 683 } while (0)
684 684
685 namespace ots { 685 namespace ots {
686 686
687 // As far as I checked, following fonts contain invalid GPOS table and 687 // As far as I checked, following fonts contain invalid GPOS table and
688 // OTS will drop their GPOS table. 688 // OTS will drop their GPOS table.
689 // 689 //
690 // # invalid delta format in device table 690 // # invalid delta format in device table
691 // samanata.ttf 691 // samanata.ttf
692 // 692 //
(...skipping 30 matching lines...) Expand all
723 // GenBasI.ttf 723 // GenBasI.ttf
724 // GenBkBasI.ttf 724 // GenBkBasI.ttf
725 // GenBkBasB.ttf 725 // GenBkBasB.ttf
726 // GenBkBasR.ttf 726 // GenBkBasR.ttf
727 // Padauk-Bold.ttf 727 // Padauk-Bold.ttf
728 // Padauk.ttf 728 // Padauk.ttf
729 // 729 //
730 // # Contour point indexes aren't sorted 730 // # Contour point indexes aren't sorted
731 // Arial Unicode.ttf 731 // Arial Unicode.ttf
732 732
733 bool ots_gpos_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 733 bool ots_gpos_parse(Font *font, const uint8_t *data, size_t length) {
734 // Parsing GPOS table requires num_glyphs which is contained in maxp table. 734 // Parsing GPOS table requires num_glyphs which is contained in maxp table.
735 if (!file->maxp) { 735 if (!font->maxp) {
736 return OTS_FAILURE_MSG("missing maxp table needed in GPOS"); 736 return OTS_FAILURE_MSG("missing maxp table needed in GPOS");
737 } 737 }
738 738
739 Buffer table(data, length); 739 Buffer table(data, length);
740 740
741 OpenTypeGPOS *gpos = new OpenTypeGPOS; 741 OpenTypeGPOS *gpos = new OpenTypeGPOS;
742 file->gpos = gpos; 742 font->gpos = gpos;
743 743
744 uint32_t version = 0; 744 uint32_t version = 0;
745 uint16_t offset_script_list = 0; 745 uint16_t offset_script_list = 0;
746 uint16_t offset_feature_list = 0; 746 uint16_t offset_feature_list = 0;
747 uint16_t offset_lookup_list = 0; 747 uint16_t offset_lookup_list = 0;
748 if (!table.ReadU32(&version) || 748 if (!table.ReadU32(&version) ||
749 !table.ReadU16(&offset_script_list) || 749 !table.ReadU16(&offset_script_list) ||
750 !table.ReadU16(&offset_feature_list) || 750 !table.ReadU16(&offset_feature_list) ||
751 !table.ReadU16(&offset_lookup_list)) { 751 !table.ReadU16(&offset_lookup_list)) {
752 DROP_THIS_TABLE("Incomplete table"); 752 DROP_THIS_TABLE("Incomplete table");
753 return true; 753 return true;
754 } 754 }
755 755
756 if (version != 0x00010000) { 756 if (version != 0x00010000) {
757 DROP_THIS_TABLE("Bad version"); 757 DROP_THIS_TABLE("Bad version");
758 return true; 758 return true;
759 } 759 }
760 760
761 if (offset_lookup_list) { 761 if (offset_lookup_list) {
762 if (offset_lookup_list < kGposHeaderSize || offset_lookup_list >= length) { 762 if (offset_lookup_list < kGposHeaderSize || offset_lookup_list >= length) {
763 DROP_THIS_TABLE("Bad lookup list offset in table header"); 763 DROP_THIS_TABLE("Bad lookup list offset in table header");
764 return true; 764 return true;
765 } 765 }
766 766
767 if (!ParseLookupListTable(file, data + offset_lookup_list, 767 if (!ParseLookupListTable(font, data + offset_lookup_list,
768 length - offset_lookup_list, 768 length - offset_lookup_list,
769 &kGposLookupSubtableParser, 769 &kGposLookupSubtableParser,
770 &gpos->num_lookups)) { 770 &gpos->num_lookups)) {
771 DROP_THIS_TABLE("Failed to parse lookup list table"); 771 DROP_THIS_TABLE("Failed to parse lookup list table");
772 return true; 772 return true;
773 } 773 }
774 } 774 }
775 775
776 uint16_t num_features = 0; 776 uint16_t num_features = 0;
777 if (offset_feature_list) { 777 if (offset_feature_list) {
778 if (offset_feature_list < kGposHeaderSize || offset_feature_list >= length) { 778 if (offset_feature_list < kGposHeaderSize || offset_feature_list >= length) {
779 DROP_THIS_TABLE("Bad feature list offset in table header"); 779 DROP_THIS_TABLE("Bad feature list offset in table header");
780 return true; 780 return true;
781 } 781 }
782 782
783 if (!ParseFeatureListTable(file, data + offset_feature_list, 783 if (!ParseFeatureListTable(font, data + offset_feature_list,
784 length - offset_feature_list, gpos->num_lookups, 784 length - offset_feature_list, gpos->num_lookups,
785 &num_features)) { 785 &num_features)) {
786 DROP_THIS_TABLE("Failed to parse feature list table"); 786 DROP_THIS_TABLE("Failed to parse feature list table");
787 return true; 787 return true;
788 } 788 }
789 } 789 }
790 790
791 if (offset_script_list) { 791 if (offset_script_list) {
792 if (offset_script_list < kGposHeaderSize || offset_script_list >= length) { 792 if (offset_script_list < kGposHeaderSize || offset_script_list >= length) {
793 DROP_THIS_TABLE("Bad script list offset in table header"); 793 DROP_THIS_TABLE("Bad script list offset in table header");
794 return true; 794 return true;
795 } 795 }
796 796
797 if (!ParseScriptListTable(file, data + offset_script_list, 797 if (!ParseScriptListTable(font, data + offset_script_list,
798 length - offset_script_list, num_features)) { 798 length - offset_script_list, num_features)) {
799 DROP_THIS_TABLE("Failed to parse script list table"); 799 DROP_THIS_TABLE("Failed to parse script list table");
800 return true; 800 return true;
801 } 801 }
802 } 802 }
803 803
804 gpos->data = data; 804 gpos->data = data;
805 gpos->length = length; 805 gpos->length = length;
806 return true; 806 return true;
807 } 807 }
808 808
809 bool ots_gpos_should_serialise(OpenTypeFile *file) { 809 bool ots_gpos_should_serialise(Font *font) {
810 return file->gpos != NULL && file->gpos->data != NULL; 810 return font->gpos != NULL && font->gpos->data != NULL;
811 } 811 }
812 812
813 bool ots_gpos_serialise(OTSStream *out, OpenTypeFile *file) { 813 bool ots_gpos_serialise(OTSStream *out, Font *font) {
814 if (!out->Write(file->gpos->data, file->gpos->length)) { 814 if (!out->Write(font->gpos->data, font->gpos->length)) {
815 return OTS_FAILURE_MSG("Failed to write GPOS table"); 815 return OTS_FAILURE_MSG("Failed to write GPOS table");
816 } 816 }
817 817
818 return true; 818 return true;
819 } 819 }
820 820
821 void ots_gpos_free(OpenTypeFile *file) { 821 void ots_gpos_reuse(Font *font, Font *other) {
822 delete file->gpos; 822 font->gpos = other->gpos;
823 font->gpos_reused = true;
824 }
825
826 void ots_gpos_free(Font *font) {
827 delete font->gpos;
823 } 828 }
824 829
825 } // namespace ots 830 } // namespace ots
826 831
827 #undef TABLE_NAME 832 #undef TABLE_NAME
828 #undef DROP_THIS_TABLE 833 #undef DROP_THIS_TABLE
OLDNEW
« no previous file with comments | « third_party/ots/src/glyf.cc ('k') | third_party/ots/src/gsub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698