| OLD | NEW |
| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 bool ReadTrueTypeCollection(Buffer* file, const uint8_t* data, size_t len, | 134 bool ReadTrueTypeCollection(Buffer* file, const uint8_t* data, size_t len, |
| 135 FontCollection* font_collection) { | 135 FontCollection* font_collection) { |
| 136 uint32_t num_fonts; | 136 uint32_t num_fonts; |
| 137 | 137 |
| 138 if (!file->ReadU32(&font_collection->header_version) || | 138 if (!file->ReadU32(&font_collection->header_version) || |
| 139 !file->ReadU32(&num_fonts)) { | 139 !file->ReadU32(&num_fonts)) { |
| 140 return FONT_COMPRESSION_FAILURE(); | 140 return FONT_COMPRESSION_FAILURE(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 std::vector<uint32_t> offsets; | 143 std::vector<uint32_t> offsets; |
| 144 for (auto i = 0; i < num_fonts; i++) { | 144 for (size_t i = 0; i < num_fonts; i++) { |
| 145 uint32_t offset; | 145 uint32_t offset; |
| 146 if (!file->ReadU32(&offset)) { | 146 if (!file->ReadU32(&offset)) { |
| 147 return FONT_COMPRESSION_FAILURE(); | 147 return FONT_COMPRESSION_FAILURE(); |
| 148 } | 148 } |
| 149 offsets.push_back(offset); | 149 offsets.push_back(offset); |
| 150 } | 150 } |
| 151 | 151 |
| 152 font_collection->fonts.resize(offsets.size()); | 152 font_collection->fonts.resize(offsets.size()); |
| 153 std::vector<Font>::iterator font_it = font_collection->fonts.begin(); | 153 std::vector<Font>::iterator font_it = font_collection->fonts.begin(); |
| 154 | 154 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return WriteFont(font_collection.fonts[0], &offset, dst, dst_size); | 290 return WriteFont(font_collection.fonts[0], &offset, dst, dst_size); |
| 291 } | 291 } |
| 292 | 292 |
| 293 // Write TTC header | 293 // Write TTC header |
| 294 StoreU32(kTtcFontFlavor, &offset, dst); | 294 StoreU32(kTtcFontFlavor, &offset, dst); |
| 295 StoreU32(font_collection.header_version, &offset, dst); | 295 StoreU32(font_collection.header_version, &offset, dst); |
| 296 StoreU32(font_collection.fonts.size(), &offset, dst); | 296 StoreU32(font_collection.fonts.size(), &offset, dst); |
| 297 | 297 |
| 298 // Offset Table, zeroed for now | 298 // Offset Table, zeroed for now |
| 299 size_t offset_table = offset; // where to write offsets later | 299 size_t offset_table = offset; // where to write offsets later |
| 300 for (int i = 0; i < font_collection.fonts.size(); i++) { | 300 for (size_t i = 0; i < font_collection.fonts.size(); i++) { |
| 301 StoreU32(0, &offset, dst); | 301 StoreU32(0, &offset, dst); |
| 302 } | 302 } |
| 303 | 303 |
| 304 if (font_collection.header_version == 0x00020000) { | 304 if (font_collection.header_version == 0x00020000) { |
| 305 StoreU32(0, &offset, dst); // ulDsigTag | 305 StoreU32(0, &offset, dst); // ulDsigTag |
| 306 StoreU32(0, &offset, dst); // ulDsigLength | 306 StoreU32(0, &offset, dst); // ulDsigLength |
| 307 StoreU32(0, &offset, dst); // ulDsigOffset | 307 StoreU32(0, &offset, dst); // ulDsigOffset |
| 308 } | 308 } |
| 309 | 309 |
| 310 // Write fonts and their offsets. | 310 // Write fonts and their offsets. |
| 311 for (int i = 0; i < font_collection.fonts.size(); i++) { | 311 for (size_t i = 0; i < font_collection.fonts.size(); i++) { |
| 312 const auto& font = font_collection.fonts[i]; | 312 const auto& font = font_collection.fonts[i]; |
| 313 StoreU32(offset, &offset_table, dst); | 313 StoreU32(offset, &offset_table, dst); |
| 314 if (!WriteFont(font, &offset, dst, dst_size)) { | 314 if (!WriteFont(font, &offset, dst, dst_size)) { |
| 315 return false; | 315 return false; |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 return true; | 319 return true; |
| 320 } | 320 } |
| 321 | 321 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 std::map<uint32_t, Font::Table>::iterator it = | 388 std::map<uint32_t, Font::Table>::iterator it = |
| 389 font->tables.find(kDsigTableTag); | 389 font->tables.find(kDsigTableTag); |
| 390 if (it != font->tables.end()) { | 390 if (it != font->tables.end()) { |
| 391 font->tables.erase(it); | 391 font->tables.erase(it); |
| 392 font->num_tables = font->tables.size(); | 392 font->num_tables = font->tables.size(); |
| 393 } | 393 } |
| 394 return true; | 394 return true; |
| 395 } | 395 } |
| 396 | 396 |
| 397 } // namespace woff2 | 397 } // namespace woff2 |
| OLD | NEW |