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

Side by Side Diff: third_party/ots/src/vorg.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/vmtx.cc ('k') | third_party/ots/src/woff2.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 "vorg.h" 5 #include "vorg.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 // VORG - Vertical Origin Table 9 // VORG - Vertical Origin Table
10 // http://www.microsoft.com/typography/otspec/vorg.htm 10 // http://www.microsoft.com/typography/otspec/vorg.htm
11 11
12 #define TABLE_NAME "VORG" 12 #define TABLE_NAME "VORG"
13 13
14 #define DROP_THIS_TABLE(...) \ 14 #define DROP_THIS_TABLE(...) \
15 do { \ 15 do { \
16 OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \ 16 OTS_FAILURE_MSG_(font->file, TABLE_NAME ": " __VA_ARGS__); \
17 OTS_FAILURE_MSG("Table discarded"); \ 17 OTS_FAILURE_MSG("Table discarded"); \
18 delete file->vorg; \ 18 delete font->vorg; \
19 file->vorg = 0; \ 19 font->vorg = 0; \
20 } while (0) 20 } while (0)
21 21
22 namespace ots { 22 namespace ots {
23 23
24 bool ots_vorg_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 24 bool ots_vorg_parse(Font *font, const uint8_t *data, size_t length) {
25 Buffer table(data, length); 25 Buffer table(data, length);
26 file->vorg = new OpenTypeVORG; 26 font->vorg = new OpenTypeVORG;
27 OpenTypeVORG * const vorg = file->vorg; 27 OpenTypeVORG * const vorg = font->vorg;
28 28
29 uint16_t num_recs; 29 uint16_t num_recs;
30 if (!table.ReadU16(&vorg->major_version) || 30 if (!table.ReadU16(&vorg->major_version) ||
31 !table.ReadU16(&vorg->minor_version) || 31 !table.ReadU16(&vorg->minor_version) ||
32 !table.ReadS16(&vorg->default_vert_origin_y) || 32 !table.ReadS16(&vorg->default_vert_origin_y) ||
33 !table.ReadU16(&num_recs)) { 33 !table.ReadU16(&num_recs)) {
34 return OTS_FAILURE_MSG("Failed to read header"); 34 return OTS_FAILURE_MSG("Failed to read header");
35 } 35 }
36 if (vorg->major_version != 1) { 36 if (vorg->major_version != 1) {
37 DROP_THIS_TABLE("bad major version: %u", vorg->major_version); 37 DROP_THIS_TABLE("bad major version: %u", vorg->major_version);
(...skipping 23 matching lines...) Expand all
61 return true; 61 return true;
62 } 62 }
63 last_glyph_index = rec.glyph_index; 63 last_glyph_index = rec.glyph_index;
64 64
65 vorg->metrics.push_back(rec); 65 vorg->metrics.push_back(rec);
66 } 66 }
67 67
68 return true; 68 return true;
69 } 69 }
70 70
71 bool ots_vorg_should_serialise(OpenTypeFile *file) { 71 bool ots_vorg_should_serialise(Font *font) {
72 if (!file->cff) return false; // this table is not for fonts with TT glyphs. 72 if (!font->cff) return false; // this table is not for fonts with TT glyphs.
73 return file->vorg != NULL; 73 return font->vorg != NULL;
74 } 74 }
75 75
76 bool ots_vorg_serialise(OTSStream *out, OpenTypeFile *file) { 76 bool ots_vorg_serialise(OTSStream *out, Font *font) {
77 OpenTypeVORG * const vorg = file->vorg; 77 OpenTypeVORG * const vorg = font->vorg;
78 78
79 const uint16_t num_metrics = static_cast<uint16_t>(vorg->metrics.size()); 79 const uint16_t num_metrics = static_cast<uint16_t>(vorg->metrics.size());
80 if (num_metrics != vorg->metrics.size() || 80 if (num_metrics != vorg->metrics.size() ||
81 !out->WriteU16(vorg->major_version) || 81 !out->WriteU16(vorg->major_version) ||
82 !out->WriteU16(vorg->minor_version) || 82 !out->WriteU16(vorg->minor_version) ||
83 !out->WriteS16(vorg->default_vert_origin_y) || 83 !out->WriteS16(vorg->default_vert_origin_y) ||
84 !out->WriteU16(num_metrics)) { 84 !out->WriteU16(num_metrics)) {
85 return OTS_FAILURE_MSG("Failed to write table header"); 85 return OTS_FAILURE_MSG("Failed to write table header");
86 } 86 }
87 87
88 for (uint16_t i = 0; i < num_metrics; ++i) { 88 for (uint16_t i = 0; i < num_metrics; ++i) {
89 const OpenTypeVORGMetrics& rec = vorg->metrics[i]; 89 const OpenTypeVORGMetrics& rec = vorg->metrics[i];
90 if (!out->WriteU16(rec.glyph_index) || 90 if (!out->WriteU16(rec.glyph_index) ||
91 !out->WriteS16(rec.vert_origin_y)) { 91 !out->WriteS16(rec.vert_origin_y)) {
92 return OTS_FAILURE_MSG("Failed to write record %d", i); 92 return OTS_FAILURE_MSG("Failed to write record %d", i);
93 } 93 }
94 } 94 }
95 95
96 return true; 96 return true;
97 } 97 }
98 98
99 void ots_vorg_free(OpenTypeFile *file) { 99 void ots_vorg_reuse(Font *font, Font *other) {
100 delete file->vorg; 100 font->vorg = other->vorg;
101 font->vorg_reused = true;
102 }
103
104 void ots_vorg_free(Font *font) {
105 delete font->vorg;
101 } 106 }
102 107
103 } // namespace ots 108 } // namespace ots
104 109
105 #undef TABLE_NAME 110 #undef TABLE_NAME
106 #undef DROP_THIS_TABLE 111 #undef DROP_THIS_TABLE
OLDNEW
« no previous file with comments | « third_party/ots/src/vmtx.cc ('k') | third_party/ots/src/woff2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698