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

Side by Side Diff: src/vorg.cc

Issue 658573004: Updating to new OTS repo from https://github.com/khaledhosny/ots.git (Closed) Base URL: https://chromium.googlesource.com/external/ots@master
Patch Set: Adding Colored Emoji changes from external/git repo Created 6 years, 2 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
« .gitmodules ('K') | « src/vmtx.cc ('k') | src/woff2.cc » ('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/opentype/otspec/vorg.htm 10 // http://www.microsoft.com/typography/otspec/vorg.htm
11 11
12 #define DROP_THIS_TABLE \ 12 #define TABLE_NAME "VORG"
13 do { delete file->vorg; file->vorg = 0; } while (0) 13
14 #define DROP_THIS_TABLE(...) \
15 do { \
16 delete file->vorg; \
17 file->vorg = 0; \
18 OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \
19 OTS_FAILURE_MSG("Table discarded"); \
20 } while (0)
14 21
15 namespace ots { 22 namespace ots {
16 23
17 bool ots_vorg_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 24 bool ots_vorg_parse(OpenTypeFile *file, const uint8_t *data, size_t length) {
18 Buffer table(data, length); 25 Buffer table(data, length);
19 file->vorg = new OpenTypeVORG; 26 file->vorg = new OpenTypeVORG;
20 OpenTypeVORG * const vorg = file->vorg; 27 OpenTypeVORG * const vorg = file->vorg;
21 28
22 uint16_t num_recs; 29 uint16_t num_recs;
23 if (!table.ReadU16(&vorg->major_version) || 30 if (!table.ReadU16(&vorg->major_version) ||
24 !table.ReadU16(&vorg->minor_version) || 31 !table.ReadU16(&vorg->minor_version) ||
25 !table.ReadS16(&vorg->default_vert_origin_y) || 32 !table.ReadS16(&vorg->default_vert_origin_y) ||
26 !table.ReadU16(&num_recs)) { 33 !table.ReadU16(&num_recs)) {
27 return OTS_FAILURE(); 34 return OTS_FAILURE_MSG("Failed to read header");
28 } 35 }
29 if (vorg->major_version != 1) { 36 if (vorg->major_version != 1) {
30 OTS_WARNING("bad major version: %u", vorg->major_version); 37 DROP_THIS_TABLE("bad major version: %u", vorg->major_version);
31 DROP_THIS_TABLE;
32 return true; 38 return true;
33 } 39 }
34 if (vorg->minor_version != 0) { 40 if (vorg->minor_version != 0) {
35 OTS_WARNING("bad minor version: %u", vorg->minor_version); 41 DROP_THIS_TABLE("bad minor version: %u", vorg->minor_version);
36 DROP_THIS_TABLE;
37 return true; 42 return true;
38 } 43 }
39 44
40 // num_recs might be zero (e.g., DFHSMinchoPro5-W3-Demo.otf). 45 // num_recs might be zero (e.g., DFHSMinchoPro5-W3-Demo.otf).
41 if (!num_recs) { 46 if (!num_recs) {
42 return true; 47 return true;
43 } 48 }
44 49
45 uint16_t last_glyph_index = 0; 50 uint16_t last_glyph_index = 0;
46 vorg->metrics.reserve(num_recs); 51 vorg->metrics.reserve(num_recs);
47 for (unsigned i = 0; i < num_recs; ++i) { 52 for (unsigned i = 0; i < num_recs; ++i) {
48 OpenTypeVORGMetrics rec; 53 OpenTypeVORGMetrics rec;
49 54
50 if (!table.ReadU16(&rec.glyph_index) || 55 if (!table.ReadU16(&rec.glyph_index) ||
51 !table.ReadS16(&rec.vert_origin_y)) { 56 !table.ReadS16(&rec.vert_origin_y)) {
52 return OTS_FAILURE(); 57 return OTS_FAILURE_MSG("Failed to read record %d", i);
53 } 58 }
54 if ((i != 0) && (rec.glyph_index <= last_glyph_index)) { 59 if ((i != 0) && (rec.glyph_index <= last_glyph_index)) {
55 OTS_WARNING("the table is not sorted"); 60 DROP_THIS_TABLE("the table is not sorted");
56 DROP_THIS_TABLE;
57 return true; 61 return true;
58 } 62 }
59 last_glyph_index = rec.glyph_index; 63 last_glyph_index = rec.glyph_index;
60 64
61 vorg->metrics.push_back(rec); 65 vorg->metrics.push_back(rec);
62 } 66 }
63 67
64 return true; 68 return true;
65 } 69 }
66 70
67 bool ots_vorg_should_serialise(OpenTypeFile *file) { 71 bool ots_vorg_should_serialise(OpenTypeFile *file) {
68 if (!file->cff) return false; // this table is not for fonts with TT glyphs. 72 if (!file->cff) return false; // this table is not for fonts with TT glyphs.
69 return file->vorg != NULL; 73 return file->vorg != NULL;
70 } 74 }
71 75
72 bool ots_vorg_serialise(OTSStream *out, OpenTypeFile *file) { 76 bool ots_vorg_serialise(OTSStream *out, OpenTypeFile *file) {
73 OpenTypeVORG * const vorg = file->vorg; 77 OpenTypeVORG * const vorg = file->vorg;
74 78
75 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());
76 if (num_metrics != vorg->metrics.size() || 80 if (num_metrics != vorg->metrics.size() ||
77 !out->WriteU16(vorg->major_version) || 81 !out->WriteU16(vorg->major_version) ||
78 !out->WriteU16(vorg->minor_version) || 82 !out->WriteU16(vorg->minor_version) ||
79 !out->WriteS16(vorg->default_vert_origin_y) || 83 !out->WriteS16(vorg->default_vert_origin_y) ||
80 !out->WriteU16(num_metrics)) { 84 !out->WriteU16(num_metrics)) {
81 return OTS_FAILURE(); 85 return OTS_FAILURE_MSG("Failed to write table header");
82 } 86 }
83 87
84 for (uint16_t i = 0; i < num_metrics; ++i) { 88 for (uint16_t i = 0; i < num_metrics; ++i) {
85 const OpenTypeVORGMetrics& rec = vorg->metrics[i]; 89 const OpenTypeVORGMetrics& rec = vorg->metrics[i];
86 if (!out->WriteU16(rec.glyph_index) || 90 if (!out->WriteU16(rec.glyph_index) ||
87 !out->WriteS16(rec.vert_origin_y)) { 91 !out->WriteS16(rec.vert_origin_y)) {
88 return OTS_FAILURE(); 92 return OTS_FAILURE_MSG("Failed to write record %d", i);
89 } 93 }
90 } 94 }
91 95
92 return true; 96 return true;
93 } 97 }
94 98
95 void ots_vorg_free(OpenTypeFile *file) { 99 void ots_vorg_free(OpenTypeFile *file) {
96 delete file->vorg; 100 delete file->vorg;
97 } 101 }
98 102
99 } // namespace ots 103 } // namespace ots
104
105 #undef TABLE_NAME
106 #undef DROP_THIS_TABLE
OLDNEW
« .gitmodules ('K') | « src/vmtx.cc ('k') | src/woff2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698