OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "ots.h" | 5 #include "ots.h" |
6 | 6 |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <zlib.h> | 8 #include <zlib.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 201 } |
202 | 202 |
203 // entry_selector is Log2(maximum power of 2 <= numTables) | 203 // entry_selector is Log2(maximum power of 2 <= numTables) |
204 if (header->entry_selector != max_pow2) { | 204 if (header->entry_selector != max_pow2) { |
205 return OTS_FAILURE(); | 205 return OTS_FAILURE(); |
206 } | 206 } |
207 | 207 |
208 // range_shift is NumTables x 16-searchRange. We know that 16*num_tables | 208 // range_shift is NumTables x 16-searchRange. We know that 16*num_tables |
209 // doesn't over flow because we range checked it above. Also, we know that | 209 // doesn't over flow because we range checked it above. Also, we know that |
210 // it's > header->search_range by construction of search_range. | 210 // it's > header->search_range by construction of search_range. |
211 const uint32_t expected_range_shift | 211 const uint16_t expected_range_shift = |
212 = 16 * header->num_tables - header->search_range; | 212 16 * header->num_tables - header->search_range; |
213 if (header->range_shift != expected_range_shift) { | 213 if (header->range_shift != expected_range_shift) { |
214 OTS_WARNING("bad range shift"); | 214 OTS_WARNING("bad range shift"); |
215 header->range_shift = expected_range_shift; // the same as above. | 215 header->range_shift = expected_range_shift; // the same as above. |
216 } | 216 } |
217 | 217 |
218 // Next up is the list of tables. | 218 // Next up is the list of tables. |
219 std::vector<OpenTypeTable> tables; | 219 std::vector<OpenTypeTable> tables; |
220 | 220 |
221 for (unsigned i = 0; i < header->num_tables; ++i) { | 221 for (unsigned i = 0; i < header->num_tables; ++i) { |
222 OpenTypeTable table; | 222 OpenTypeTable table; |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 // mixing outline formats is not recommended | 560 // mixing outline formats is not recommended |
561 return OTS_FAILURE(); | 561 return OTS_FAILURE(); |
562 } | 562 } |
563 } else { | 563 } else { |
564 if ((!header->glyf || !header->loca) && (!header->cbdt || !header->cblc)) { | 564 if ((!header->glyf || !header->loca) && (!header->cbdt || !header->cblc)) { |
565 // No TrueType glyph or color bitmap found. | 565 // No TrueType glyph or color bitmap found. |
566 return OTS_FAILURE(); | 566 return OTS_FAILURE(); |
567 } | 567 } |
568 } | 568 } |
569 | 569 |
570 unsigned num_output_tables = 0; | 570 uint16_t num_output_tables = 0; |
571 for (unsigned i = 0; ; ++i) { | 571 for (unsigned i = 0; ; ++i) { |
572 if (table_parsers[i].parse == NULL) { | 572 if (table_parsers[i].parse == NULL) { |
573 break; | 573 break; |
574 } | 574 } |
575 | 575 |
576 if (table_parsers[i].should_serialise(header)) { | 576 if (table_parsers[i].should_serialise(header)) { |
577 num_output_tables++; | 577 num_output_tables++; |
578 } | 578 } |
579 } | 579 } |
580 | 580 |
581 unsigned max_pow2 = 0; | 581 uint16_t max_pow2 = 0; |
582 while (1u << (max_pow2 + 1) <= num_output_tables) { | 582 while (1u << (max_pow2 + 1) <= num_output_tables) { |
583 max_pow2++; | 583 max_pow2++; |
584 } | 584 } |
585 const uint16_t output_search_range = (1u << max_pow2) << 4; | 585 const uint16_t output_search_range = (1u << max_pow2) << 4; |
586 | 586 |
587 output->ResetChecksum(); | 587 output->ResetChecksum(); |
588 if (!output->WriteTag(header->version) || | 588 if (!output->WriteTag(header->version) || |
589 !output->WriteU16(num_output_tables) || | 589 !output->WriteU16(num_output_tables) || |
590 !output->WriteU16(output_search_range) || | 590 !output->WriteU16(output_search_range) || |
591 !output->WriteU16(max_pow2) || | 591 !output->WriteU16(max_pow2) || |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 va_start(va, format); | 751 va_start(va, format); |
752 std::vfprintf(stderr, format, va); | 752 std::vfprintf(stderr, format, va); |
753 va_end(va); | 753 va_end(va); |
754 std::fprintf(stderr, "\n"); | 754 std::fprintf(stderr, "\n"); |
755 std::fflush(stderr); | 755 std::fflush(stderr); |
756 } | 756 } |
757 } | 757 } |
758 #endif | 758 #endif |
759 | 759 |
760 } // namespace ots | 760 } // namespace ots |
OLD | NEW |