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

Side by Side Diff: third_party/woff2/src/font.cc

Issue 2736873002: Update woff2 to cbea7b9 (Closed)
Patch Set: Created 3 years, 9 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/woff2/src/font.h ('k') | third_party/woff2/src/glyph.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 2013 Google Inc. All Rights Reserved. 1 // Copyright 2013 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 // Check that tables are non-overlapping. 99 // Check that tables are non-overlapping.
100 uint32_t last_offset = 12UL + 16UL * font->num_tables; 100 uint32_t last_offset = 12UL + 16UL * font->num_tables;
101 for (const auto& i : intervals) { 101 for (const auto& i : intervals) {
102 if (i.first < last_offset || i.first + i.second < i.first) { 102 if (i.first < last_offset || i.first + i.second < i.first) {
103 return FONT_COMPRESSION_FAILURE(); 103 return FONT_COMPRESSION_FAILURE();
104 } 104 }
105 last_offset = i.first + i.second; 105 last_offset = i.first + i.second;
106 } 106 }
107 107
108 // Sanity check key tables
109 const Font::Table* head_table = font->FindTable(kHeadTableTag);
110 if (head_table != NULL && head_table->length < 52) {
111 return FONT_COMPRESSION_FAILURE();
112 }
113
108 return true; 114 return true;
109 } 115 }
110 116
111 bool ReadCollectionFont(Buffer* file, const uint8_t* data, size_t len, 117 bool ReadCollectionFont(Buffer* file, const uint8_t* data, size_t len,
112 Font* font, 118 Font* font,
113 std::map<uint32_t, Font::Table*>* all_tables) { 119 std::map<uint32_t, Font::Table*>* all_tables) {
114 if (!file->ReadU32(&font->flavor)) { 120 if (!file->ReadU32(&font->flavor)) {
115 return FONT_COMPRESSION_FAILURE(); 121 return FONT_COMPRESSION_FAILURE();
116 } 122 }
117 if (!ReadTrueTypeFont(file, data, len, font)) { 123 if (!ReadTrueTypeFont(file, data, len, font)) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (font->flavor == kTtcFontFlavor) { 180 if (font->flavor == kTtcFontFlavor) {
175 return FONT_COMPRESSION_FAILURE(); 181 return FONT_COMPRESSION_FAILURE();
176 } 182 }
177 return ReadTrueTypeFont(&file, data, len, font); 183 return ReadTrueTypeFont(&file, data, len, font);
178 } 184 }
179 185
180 bool ReadFontCollection(const uint8_t* data, size_t len, 186 bool ReadFontCollection(const uint8_t* data, size_t len,
181 FontCollection* font_collection) { 187 FontCollection* font_collection) {
182 Buffer file(data, len); 188 Buffer file(data, len);
183 189
184 uint32_t flavor; 190 if (!file.ReadU32(&font_collection->flavor)) {
185 if (!file.ReadU32(&flavor)) {
186 return FONT_COMPRESSION_FAILURE(); 191 return FONT_COMPRESSION_FAILURE();
187 } 192 }
188 193
189 if (flavor != kTtcFontFlavor) { 194 if (font_collection->flavor != kTtcFontFlavor) {
190 font_collection->fonts.resize(1); 195 font_collection->fonts.resize(1);
191 Font& font = font_collection->fonts[0]; 196 Font& font = font_collection->fonts[0];
192 font.flavor = flavor; 197 font.flavor = font_collection->flavor;
193 return ReadTrueTypeFont(&file, data, len, &font); 198 return ReadTrueTypeFont(&file, data, len, &font);
194 } 199 }
195 return ReadTrueTypeCollection(&file, data, len, font_collection); 200 return ReadTrueTypeCollection(&file, data, len, font_collection);
196 } 201 }
197 202
198 size_t FontFileSize(const Font& font) { 203 size_t FontFileSize(const Font& font) {
199 size_t max_offset = 12ULL + 16ULL * font.num_tables; 204 size_t max_offset = 12ULL + 16ULL * font.num_tables;
200 for (const auto& i : font.tables) { 205 for (const auto& i : font.tables) {
201 const Font::Table& table = i.second; 206 const Font::Table& table = i.second;
202 size_t padding_size = (4 - (table.length & 3)) & 3; 207 size_t padding_size = (4 - (table.length & 3)) & 3;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 284 }
280 285
281 return true; 286 return true;
282 } 287 }
283 288
284 bool WriteFontCollection(const FontCollection& font_collection, uint8_t* dst, 289 bool WriteFontCollection(const FontCollection& font_collection, uint8_t* dst,
285 size_t dst_size) { 290 size_t dst_size) {
286 size_t offset = 0; 291 size_t offset = 0;
287 292
288 // It's simpler if this just a simple sfnt 293 // It's simpler if this just a simple sfnt
289 if (font_collection.fonts.size() == 1) { 294 if (font_collection.flavor != kTtcFontFlavor) {
290 return WriteFont(font_collection.fonts[0], &offset, dst, dst_size); 295 return WriteFont(font_collection.fonts[0], &offset, dst, dst_size);
291 } 296 }
292 297
293 // Write TTC header 298 // Write TTC header
294 StoreU32(kTtcFontFlavor, &offset, dst); 299 StoreU32(kTtcFontFlavor, &offset, dst);
295 StoreU32(font_collection.header_version, &offset, dst); 300 StoreU32(font_collection.header_version, &offset, dst);
296 StoreU32(font_collection.fonts.size(), &offset, dst); 301 StoreU32(font_collection.fonts.size(), &offset, dst);
297 302
298 // Offset Table, zeroed for now 303 // Offset Table, zeroed for now
299 size_t offset_table = offset; // where to write offsets later 304 size_t offset_table = offset; // where to write offsets later
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 std::map<uint32_t, Font::Table>::iterator it = 393 std::map<uint32_t, Font::Table>::iterator it =
389 font->tables.find(kDsigTableTag); 394 font->tables.find(kDsigTableTag);
390 if (it != font->tables.end()) { 395 if (it != font->tables.end()) {
391 font->tables.erase(it); 396 font->tables.erase(it);
392 font->num_tables = font->tables.size(); 397 font->num_tables = font->tables.size();
393 } 398 }
394 return true; 399 return true;
395 } 400 }
396 401
397 } // namespace woff2 402 } // namespace woff2
OLDNEW
« no previous file with comments | « third_party/woff2/src/font.h ('k') | third_party/woff2/src/glyph.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698