Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: third_party/ots/src/os2.cc

Issue 1252363005: Update OTS to revision a7a3b94 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/ots/src/name.cc ('k') | third_party/ots/src/ots.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "os2.h" 7 #include "os2.h"
8 #include "head.h" 8 #include "head.h"
9 9
10 // OS/2 - OS/2 and Windows Metrics 10 // OS/2 - OS/2 and Windows Metrics
11 // http://www.microsoft.com/typography/otspec/os2.htm 11 // http://www.microsoft.com/typography/otspec/os2.htm
12 12
13 #define TABLE_NAME "OS/2" 13 #define TABLE_NAME "OS/2"
14 14
15 namespace ots { 15 namespace ots {
16 16
17 bool ots_os2_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 17 bool ots_os2_parse(Font *font, const uint8_t *data, size_t length) {
18 Buffer table(data, length); 18 Buffer table(data, length);
19 19
20 OpenTypeOS2 *os2 = new OpenTypeOS2; 20 OpenTypeOS2 *os2 = new OpenTypeOS2;
21 file->os2 = os2; 21 font->os2 = os2;
22 22
23 if (!table.ReadU16(&os2->version) || 23 if (!table.ReadU16(&os2->version) ||
24 !table.ReadS16(&os2->avg_char_width) || 24 !table.ReadS16(&os2->avg_char_width) ||
25 !table.ReadU16(&os2->weight_class) || 25 !table.ReadU16(&os2->weight_class) ||
26 !table.ReadU16(&os2->width_class) || 26 !table.ReadU16(&os2->width_class) ||
27 !table.ReadU16(&os2->type) || 27 !table.ReadU16(&os2->type) ||
28 !table.ReadS16(&os2->subscript_x_size) || 28 !table.ReadS16(&os2->subscript_x_size) ||
29 !table.ReadS16(&os2->subscript_y_size) || 29 !table.ReadS16(&os2->subscript_y_size) ||
30 !table.ReadS16(&os2->subscript_x_offset) || 30 !table.ReadS16(&os2->subscript_x_offset) ||
31 !table.ReadS16(&os2->subscript_y_offset) || 31 !table.ReadS16(&os2->subscript_y_offset) ||
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return OTS_FAILURE_MSG("Error reading more basic table fields"); 124 return OTS_FAILURE_MSG("Error reading more basic table fields");
125 } 125 }
126 126
127 // If bit 6 is set, then bits 0 and 5 must be clear. 127 // If bit 6 is set, then bits 0 and 5 must be clear.
128 if (os2->selection & 0x40) { 128 if (os2->selection & 0x40) {
129 os2->selection &= 0xffdeu; 129 os2->selection &= 0xffdeu;
130 } 130 }
131 131
132 // the settings of bits 0 and 1 must be reflected in the macStyle bits 132 // the settings of bits 0 and 1 must be reflected in the macStyle bits
133 // in the 'head' table. 133 // in the 'head' table.
134 if (!file->head) { 134 if (!font->head) {
135 return OTS_FAILURE_MSG("Needed head table is missing from the font"); 135 return OTS_FAILURE_MSG("Needed head table is missing from the font");
136 } 136 }
137 if ((os2->selection & 0x1) && 137 if ((os2->selection & 0x1) &&
138 !(file->head->mac_style & 0x2)) { 138 !(font->head->mac_style & 0x2)) {
139 OTS_WARNING("adjusting Mac style (italic)"); 139 OTS_WARNING("adjusting Mac style (italic)");
140 file->head->mac_style |= 0x2; 140 font->head->mac_style |= 0x2;
141 } 141 }
142 if ((os2->selection & 0x2) && 142 if ((os2->selection & 0x2) &&
143 !(file->head->mac_style & 0x4)) { 143 !(font->head->mac_style & 0x4)) {
144 OTS_WARNING("adjusting Mac style (underscore)"); 144 OTS_WARNING("adjusting Mac style (underscore)");
145 file->head->mac_style |= 0x4; 145 font->head->mac_style |= 0x4;
146 } 146 }
147 147
148 // While bit 6 on implies that bits 0 and 1 of macStyle are clear, 148 // While bit 6 on implies that bits 0 and 1 of macStyle are clear,
149 // the reverse is not true. 149 // the reverse is not true.
150 if ((os2->selection & 0x40) && 150 if ((os2->selection & 0x40) &&
151 (file->head->mac_style & 0x3)) { 151 (font->head->mac_style & 0x3)) {
152 OTS_WARNING("adjusting Mac style (regular)"); 152 OTS_WARNING("adjusting Mac style (regular)");
153 file->head->mac_style &= 0xfffcu; 153 font->head->mac_style &= 0xfffcu;
154 } 154 }
155 155
156 if ((os2->version < 4) && 156 if ((os2->version < 4) &&
157 (os2->selection & 0x300)) { 157 (os2->selection & 0x300)) {
158 // bit 8 and 9 must be unset in OS/2 table versions less than 4. 158 // bit 8 and 9 must be unset in OS/2 table versions less than 4.
159 return OTS_FAILURE_MSG("Version %d incompatible with selection %d", os2->ver sion, os2->selection); 159 return OTS_FAILURE_MSG("Version %d incompatible with selection %d", os2->ver sion, os2->selection);
160 } 160 }
161 161
162 // mask reserved bits. use only 0..9 bits. 162 // mask reserved bits. use only 0..9 bits.
163 os2->selection &= 0x3ff; 163 os2->selection &= 0x3ff;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 234 }
235 235
236 if (os2->upper_optical_pointsize < 2) { 236 if (os2->upper_optical_pointsize < 2) {
237 OTS_WARNING("'usUpperOpticalPointSize' is lower than 2: %d", os2->upper_opti cal_pointsize); 237 OTS_WARNING("'usUpperOpticalPointSize' is lower than 2: %d", os2->upper_opti cal_pointsize);
238 os2->upper_optical_pointsize = 2; 238 os2->upper_optical_pointsize = 2;
239 } 239 }
240 240
241 return true; 241 return true;
242 } 242 }
243 243
244 bool ots_os2_should_serialise(OpenTypeFile *file) { 244 bool ots_os2_should_serialise(Font *font) {
245 return file->os2 != NULL; 245 return font->os2 != NULL;
246 } 246 }
247 247
248 bool ots_os2_serialise(OTSStream *out, OpenTypeFile *file) { 248 bool ots_os2_serialise(OTSStream *out, Font *font) {
249 const OpenTypeOS2 *os2 = file->os2; 249 const OpenTypeOS2 *os2 = font->os2;
250 250
251 if (!out->WriteU16(os2->version) || 251 if (!out->WriteU16(os2->version) ||
252 !out->WriteS16(os2->avg_char_width) || 252 !out->WriteS16(os2->avg_char_width) ||
253 !out->WriteU16(os2->weight_class) || 253 !out->WriteU16(os2->weight_class) ||
254 !out->WriteU16(os2->width_class) || 254 !out->WriteU16(os2->width_class) ||
255 !out->WriteU16(os2->type) || 255 !out->WriteU16(os2->type) ||
256 !out->WriteS16(os2->subscript_x_size) || 256 !out->WriteS16(os2->subscript_x_size) ||
257 !out->WriteS16(os2->subscript_y_size) || 257 !out->WriteS16(os2->subscript_y_size) ||
258 !out->WriteS16(os2->subscript_x_offset) || 258 !out->WriteS16(os2->subscript_x_offset) ||
259 !out->WriteS16(os2->subscript_y_offset) || 259 !out->WriteS16(os2->subscript_y_offset) ||
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 315 }
316 316
317 if (!out->WriteU16(os2->lower_optical_pointsize) || 317 if (!out->WriteU16(os2->lower_optical_pointsize) ||
318 !out->WriteU16(os2->upper_optical_pointsize)) { 318 !out->WriteU16(os2->upper_optical_pointsize)) {
319 return OTS_FAILURE_MSG("Failed to write version 5-specific fields"); 319 return OTS_FAILURE_MSG("Failed to write version 5-specific fields");
320 } 320 }
321 321
322 return true; 322 return true;
323 } 323 }
324 324
325 void ots_os2_free(OpenTypeFile *file) { 325 void ots_os2_reuse(Font *font, Font *other) {
326 delete file->os2; 326 font->os2 = other->os2;
327 font->os2_reused = true;
328 }
329
330 void ots_os2_free(Font *font) {
331 delete font->os2;
327 } 332 }
328 333
329 } // namespace ots 334 } // namespace ots
330 335
331 #undef TABLE_NAME 336 #undef TABLE_NAME
OLDNEW
« no previous file with comments | « third_party/ots/src/name.cc ('k') | third_party/ots/src/ots.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698