OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "metrics.h" | 5 #include "metrics.h" |
6 | 6 |
7 #include "head.h" | 7 #include "head.h" |
8 #include "maxp.h" | 8 #include "maxp.h" |
9 | 9 |
10 // OpenType horizontal and vertical common header format | 10 // OpenType horizontal and vertical common header format |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 const unsigned num_sbs = num_glyphs - num_metrics; | 119 const unsigned num_sbs = num_glyphs - num_metrics; |
120 | 120 |
121 metrics->entries.reserve(num_metrics); | 121 metrics->entries.reserve(num_metrics); |
122 for (unsigned i = 0; i < num_metrics; ++i) { | 122 for (unsigned i = 0; i < num_metrics; ++i) { |
123 uint16_t adv = 0; | 123 uint16_t adv = 0; |
124 int16_t sb = 0; | 124 int16_t sb = 0; |
125 if (!table->ReadU16(&adv) || !table->ReadS16(&sb)) { | 125 if (!table->ReadU16(&adv) || !table->ReadS16(&sb)) { |
126 return OTS_FAILURE_MSG("Failed to read metric %d", i); | 126 return OTS_FAILURE_MSG("Failed to read metric %d", i); |
127 } | 127 } |
128 | |
129 // This check is bogus, see https://github.com/khaledhosny/ots/issues/36 | |
130 #if 0 | |
131 // Since so many fonts don't have proper value on |adv| and |sb|, | |
132 // we should not call ots_failure() here. For example, about 20% of fonts | |
133 // in http://www.princexml.com/fonts/ (200+ fonts) fails these tests. | |
134 if (adv > header->adv_width_max) { | |
135 OTS_WARNING("bad adv: %u > %u", adv, header->adv_width_max); | |
136 adv = header->adv_width_max; | |
137 } | |
138 | |
139 if (sb < header->min_sb1) { | |
140 OTS_WARNING("bad sb: %d < %d", sb, header->min_sb1); | |
141 sb = header->min_sb1; | |
142 } | |
143 #endif | |
144 | |
145 metrics->entries.push_back(std::make_pair(adv, sb)); | 128 metrics->entries.push_back(std::make_pair(adv, sb)); |
146 } | 129 } |
147 | 130 |
148 metrics->sbs.reserve(num_sbs); | 131 metrics->sbs.reserve(num_sbs); |
149 for (unsigned i = 0; i < num_sbs; ++i) { | 132 for (unsigned i = 0; i < num_sbs; ++i) { |
150 int16_t sb; | 133 int16_t sb; |
151 if (!table->ReadS16(&sb)) { | 134 if (!table->ReadS16(&sb)) { |
152 // Some Japanese fonts (e.g., mona.ttf) fail this test. | 135 // Some Japanese fonts (e.g., mona.ttf) fail this test. |
153 return OTS_FAILURE_MSG("Failed to read side bearing %d", i + num_metrics); | 136 return OTS_FAILURE_MSG("Failed to read side bearing %d", i + num_metrics); |
154 } | 137 } |
155 | |
156 // This check is bogus, see https://github.com/khaledhosny/ots/issues/36 | |
157 #if 0 | |
158 if (sb < header->min_sb1) { | |
159 // The same as above. Three fonts in http://www.fontsquirrel.com/fontface | |
160 // (e.g., Notice2Std.otf) have weird lsb values. | |
161 OTS_WARNING("bad lsb: %d < %d", sb, header->min_sb1); | |
162 sb = header->min_sb1; | |
163 } | |
164 #endif | |
165 | |
166 metrics->sbs.push_back(sb); | 138 metrics->sbs.push_back(sb); |
167 } | 139 } |
168 | 140 |
169 return true; | 141 return true; |
170 } | 142 } |
171 | 143 |
172 bool SerialiseMetricsTable(const ots::Font *font, | 144 bool SerialiseMetricsTable(const ots::Font *font, |
173 OTSStream *out, | 145 OTSStream *out, |
174 const OpenTypeMetricsTable *metrics) { | 146 const OpenTypeMetricsTable *metrics) { |
175 for (unsigned i = 0; i < metrics->entries.size(); ++i) { | 147 for (unsigned i = 0; i < metrics->entries.size(); ++i) { |
176 if (!out->WriteU16(metrics->entries[i].first) || | 148 if (!out->WriteU16(metrics->entries[i].first) || |
177 !out->WriteS16(metrics->entries[i].second)) { | 149 !out->WriteS16(metrics->entries[i].second)) { |
178 return OTS_FAILURE_MSG("Failed to write metric %d", i); | 150 return OTS_FAILURE_MSG("Failed to write metric %d", i); |
179 } | 151 } |
180 } | 152 } |
181 | 153 |
182 for (unsigned i = 0; i < metrics->sbs.size(); ++i) { | 154 for (unsigned i = 0; i < metrics->sbs.size(); ++i) { |
183 if (!out->WriteS16(metrics->sbs[i])) { | 155 if (!out->WriteS16(metrics->sbs[i])) { |
184 return OTS_FAILURE_MSG("Failed to write side bearing %ld", i + metrics->en
tries.size()); | 156 return OTS_FAILURE_MSG("Failed to write side bearing %ld", i + metrics->en
tries.size()); |
185 } | 157 } |
186 } | 158 } |
187 | 159 |
188 return true; | 160 return true; |
189 } | 161 } |
190 | 162 |
191 } // namespace ots | 163 } // namespace ots |
192 | 164 |
193 #undef TABLE_NAME | 165 #undef TABLE_NAME |
OLD | NEW |