OLD | NEW |
1 // Copyright 2014 Google Inc. All Rights Reserved. | 1 // Copyright 2014 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, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 // | 14 // |
15 // Library for converting TTF format font files to their WOFF2 versions. | 15 // Library for converting TTF format font files to their WOFF2 versions. |
16 | 16 |
17 #include "./woff2_enc.h" | 17 #include "./woff2_enc.h" |
18 | 18 |
19 #include <stdlib.h> | 19 #include <stdlib.h> |
20 #include <complex> | 20 #include <complex> |
21 #include <cstring> | 21 #include <cstring> |
22 #include <limits> | 22 #include <limits> |
23 #include <string> | 23 #include <string> |
24 #include <vector> | 24 #include <vector> |
25 | 25 |
26 #include "./encode.h" | 26 #include "./compressor.h" |
27 #include "./buffer.h" | 27 #include "./buffer.h" |
28 #include "./font.h" | 28 #include "./font.h" |
29 #include "./normalize.h" | 29 #include "./normalize.h" |
30 #include "./round.h" | 30 #include "./round.h" |
31 #include "./store_bytes.h" | 31 #include "./store_bytes.h" |
32 #include "./table_tags.h" | 32 #include "./table_tags.h" |
33 #include "./transform.h" | 33 #include "./transform.h" |
34 #include "./variable_length.h" | 34 #include "./variable_length.h" |
35 #include "./woff2_common.h" | 35 #include "./woff2_common.h" |
36 | 36 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 141 } |
142 | 142 |
143 // compressed data | 143 // compressed data |
144 size += compressed_data_length; | 144 size += compressed_data_length; |
145 size = Round4(size); | 145 size = Round4(size); |
146 | 146 |
147 size += extended_metadata_length; | 147 size += extended_metadata_length; |
148 return size; | 148 return size; |
149 } | 149 } |
150 | 150 |
151 size_t ComputeTTFLength(const std::vector<Table>& tables) { | |
152 size_t size = 12 + 16 * tables.size(); // sfnt header | |
153 for (const auto& table : tables) { | |
154 size += Round4(table.src_length); | |
155 } | |
156 return size; | |
157 } | |
158 | |
159 size_t ComputeUncompressedLength(const Font& font) { | 151 size_t ComputeUncompressedLength(const Font& font) { |
160 // sfnt header + offset table | 152 // sfnt header + offset table |
161 size_t size = 12 + 16 * font.num_tables; | 153 size_t size = 12 + 16 * font.num_tables; |
162 for (const auto& entry : font.tables) { | 154 for (const auto& entry : font.tables) { |
163 const Font::Table& table = entry.second; | 155 const Font::Table& table = entry.second; |
164 if (table.tag & 0x80808080) continue; // xform tables don't stay | 156 if (table.tag & 0x80808080) continue; // xform tables don't stay |
165 if (table.IsReused()) continue; // don't have to pay twice | 157 if (table.IsReused()) continue; // don't have to pay twice |
166 size += Round4(table.length); | 158 size += Round4(table.length); |
167 } | 159 } |
168 return size; | 160 return size; |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 #ifdef FONT_COMPRESSION_BIN | 461 #ifdef FONT_COMPRESSION_BIN |
470 fprintf(stderr, "Mismatch between computed and actual length " | 462 fprintf(stderr, "Mismatch between computed and actual length " |
471 "(%zd vs %zd)\n", *result_length, offset); | 463 "(%zd vs %zd)\n", *result_length, offset); |
472 #endif | 464 #endif |
473 return FONT_COMPRESSION_FAILURE(); | 465 return FONT_COMPRESSION_FAILURE(); |
474 } | 466 } |
475 return true; | 467 return true; |
476 } | 468 } |
477 | 469 |
478 } // namespace woff2 | 470 } // namespace woff2 |
OLD | NEW |