OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // This is the implementation of decompression of the proposed WOFF Ultra | 5 // This is the implementation of decompression of the proposed WOFF Ultra |
6 // Condensed file format. | 6 // Condensed file format. |
7 | 7 |
8 #include <cassert> | 8 #include <cassert> |
9 #include <cstdlib> | 9 #include <cstdlib> |
10 #include <vector> | 10 #include <vector> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 TAG('k', 'e', 'r', 'n'), // 19 | 78 TAG('k', 'e', 'r', 'n'), // 19 |
79 TAG('L', 'T', 'S', 'H'), // 20 | 79 TAG('L', 'T', 'S', 'H'), // 20 |
80 TAG('P', 'C', 'L', 'T'), // 21 | 80 TAG('P', 'C', 'L', 'T'), // 21 |
81 TAG('V', 'D', 'M', 'X'), // 22 | 81 TAG('V', 'D', 'M', 'X'), // 22 |
82 TAG('v', 'h', 'e', 'a'), // 23 | 82 TAG('v', 'h', 'e', 'a'), // 23 |
83 TAG('v', 'm', 't', 'x'), // 24 | 83 TAG('v', 'm', 't', 'x'), // 24 |
84 TAG('B', 'A', 'S', 'E'), // 25 | 84 TAG('B', 'A', 'S', 'E'), // 25 |
85 TAG('G', 'D', 'E', 'F'), // 26 | 85 TAG('G', 'D', 'E', 'F'), // 26 |
86 TAG('G', 'P', 'O', 'S'), // 27 | 86 TAG('G', 'P', 'O', 'S'), // 27 |
87 TAG('G', 'S', 'U', 'B'), // 28 | 87 TAG('G', 'S', 'U', 'B'), // 28 |
| 88 TAG('E', 'B', 'S', 'C'), // 29 |
| 89 TAG('J', 'S', 'T', 'F'), // 30 |
| 90 TAG('M', 'A', 'T', 'H'), // 31 |
| 91 TAG('C', 'B', 'D', 'T'), // 32 |
| 92 TAG('C', 'B', 'L', 'C'), // 33 |
| 93 TAG('C', 'O', 'L', 'R'), // 34 |
| 94 TAG('C', 'P', 'A', 'L'), // 35 |
| 95 TAG('S', 'V', 'G', ' '), // 36 |
| 96 TAG('s', 'b', 'i', 'x'), // 37 |
| 97 TAG('a', 'c', 'n', 't'), // 38 |
| 98 TAG('a', 'v', 'a', 'r'), // 39 |
| 99 TAG('b', 'd', 'a', 't'), // 40 |
| 100 TAG('b', 'l', 'o', 'c'), // 41 |
| 101 TAG('b', 's', 'l', 'n'), // 42 |
| 102 TAG('c', 'v', 'a', 'r'), // 43 |
| 103 TAG('f', 'd', 's', 'c'), // 44 |
| 104 TAG('f', 'e', 'a', 't'), // 45 |
| 105 TAG('f', 'm', 't', 'x'), // 46 |
| 106 TAG('f', 'v', 'a', 'r'), // 47 |
| 107 TAG('g', 'v', 'a', 'r'), // 48 |
| 108 TAG('h', 's', 't', 'y'), // 49 |
| 109 TAG('j', 'u', 's', 't'), // 50 |
| 110 TAG('l', 'c', 'a', 'r'), // 51 |
| 111 TAG('m', 'o', 'r', 't'), // 52 |
| 112 TAG('m', 'o', 'r', 'x'), // 53 |
| 113 TAG('o', 'p', 'b', 'd'), // 54 |
| 114 TAG('p', 'r', 'o', 'p'), // 55 |
| 115 TAG('t', 'r', 'a', 'k'), // 56 |
| 116 TAG('Z', 'a', 'p', 'f'), // 57 |
| 117 TAG('S', 'i', 'l', 'f'), // 58 |
| 118 TAG('G', 'l', 'a', 't'), // 59 |
| 119 TAG('G', 'l', 'o', 'c'), // 60 |
| 120 TAG('F', 'e', 'a', 't'), // 61 |
| 121 TAG('S', 'i', 'l', 'l'), // 62 |
88 }; | 122 }; |
89 | 123 |
90 struct Point { | 124 struct Point { |
91 int x; | 125 int x; |
92 int y; | 126 int y; |
93 bool on_curve; | 127 bool on_curve; |
94 }; | 128 }; |
95 | 129 |
96 struct Table { | 130 struct Table { |
97 uint32_t tag; | 131 uint32_t tag; |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 | 799 |
766 bool ReadShortDirectory(ots::Buffer* file, std::vector<Table>* tables, | 800 bool ReadShortDirectory(ots::Buffer* file, std::vector<Table>* tables, |
767 size_t num_tables) { | 801 size_t num_tables) { |
768 for (size_t i = 0; i < num_tables; ++i) { | 802 for (size_t i = 0; i < num_tables; ++i) { |
769 Table* table = &tables->at(i); | 803 Table* table = &tables->at(i); |
770 uint8_t flag_byte; | 804 uint8_t flag_byte; |
771 if (!file->ReadU8(&flag_byte)) { | 805 if (!file->ReadU8(&flag_byte)) { |
772 return OTS_FAILURE(); | 806 return OTS_FAILURE(); |
773 } | 807 } |
774 uint32_t tag; | 808 uint32_t tag; |
775 if ((flag_byte & 0x1f) == 0x1f) { | 809 if ((flag_byte & 0x3f) == 0x3f) { |
776 if (!file->ReadU32(&tag)) { | 810 if (!file->ReadU32(&tag)) { |
777 return OTS_FAILURE(); | 811 return OTS_FAILURE(); |
778 } | 812 } |
779 } else { | 813 } else { |
780 if ((flag_byte & 0x1f) >= arraysize(kKnownTags)) { | 814 tag = kKnownTags[flag_byte & 0x3f]; |
781 return OTS_FAILURE(); | |
782 } | |
783 tag = kKnownTags[flag_byte & 0x1f]; | |
784 } | 815 } |
785 // Bits 5 and 6 are reserved and must be 0. | 816 // Bits 6 and 7 are reserved and must be 0. |
786 if ((flag_byte & 0x60) != 0) { | 817 if ((flag_byte & 0xc0) != 0) { |
787 return OTS_FAILURE(); | 818 return OTS_FAILURE(); |
788 } | 819 } |
789 uint32_t flags = kCompressionTypeBrotli; | 820 uint32_t flags = kCompressionTypeBrotli; |
790 if (i > 0) { | 821 if (i > 0) { |
791 flags |= kWoff2FlagsContinueStream; | 822 flags |= kWoff2FlagsContinueStream; |
792 } | 823 } |
793 if ((flag_byte & 0x80) != 0) { | 824 // Always transform the glyf and loca tables |
| 825 if (tag == TAG('g', 'l', 'y', 'f') || |
| 826 tag == TAG('l', 'o', 'c', 'a')) { |
794 flags |= kWoff2FlagsTransform; | 827 flags |= kWoff2FlagsTransform; |
795 } | 828 } |
796 uint32_t dst_length; | 829 uint32_t dst_length; |
797 if (!ReadBase128(file, &dst_length)) { | 830 if (!ReadBase128(file, &dst_length)) { |
798 return OTS_FAILURE(); | 831 return OTS_FAILURE(); |
799 } | 832 } |
800 uint32_t transform_length = dst_length; | 833 uint32_t transform_length = dst_length; |
801 if ((flags & kWoff2FlagsTransform) != 0) { | 834 if ((flags & kWoff2FlagsTransform) != 0) { |
802 if (!ReadBase128(file, &transform_length)) { | 835 if (!ReadBase128(file, &transform_length)) { |
803 return OTS_FAILURE(); | 836 return OTS_FAILURE(); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 if (transform_buf > &uncompressed_buf[0] + uncompressed_buf.size()) { | 1033 if (transform_buf > &uncompressed_buf[0] + uncompressed_buf.size()) { |
1001 return OTS_FAILURE(); | 1034 return OTS_FAILURE(); |
1002 } | 1035 } |
1003 } | 1036 } |
1004 } | 1037 } |
1005 | 1038 |
1006 return FixChecksums(tables, result); | 1039 return FixChecksums(tables, result); |
1007 } | 1040 } |
1008 | 1041 |
1009 } // namespace ots | 1042 } // namespace ots |
OLD | NEW |