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

Side by Side Diff: third_party/ots/src/gasp.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/fpgm.cc ('k') | third_party/ots/src/gdef.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 "gasp.h" 5 #include "gasp.h"
6 6
7 // gasp - Grid-fitting And Scan-conversion Procedure 7 // gasp - Grid-fitting And Scan-conversion Procedure
8 // http://www.microsoft.com/typography/otspec/gasp.htm 8 // http://www.microsoft.com/typography/otspec/gasp.htm
9 9
10 #define TABLE_NAME "gasp" 10 #define TABLE_NAME "gasp"
11 11
12 #define DROP_THIS_TABLE(...) \ 12 #define DROP_THIS_TABLE(...) \
13 do { \ 13 do { \
14 OTS_FAILURE_MSG_(file, TABLE_NAME ": " __VA_ARGS__); \ 14 OTS_FAILURE_MSG_(font->file, TABLE_NAME ": " __VA_ARGS__); \
15 OTS_FAILURE_MSG("Table discarded"); \ 15 OTS_FAILURE_MSG("Table discarded"); \
16 delete file->gasp; \ 16 delete font->gasp; \
17 file->gasp = 0; \ 17 font->gasp = 0; \
18 } while (0) 18 } while (0)
19 19
20 namespace ots { 20 namespace ots {
21 21
22 bool ots_gasp_parse(OpenTypeFile *file, const uint8_t *data, size_t length) { 22 bool ots_gasp_parse(Font *font, const uint8_t *data, size_t length) {
23 Buffer table(data, length); 23 Buffer table(data, length);
24 24
25 OpenTypeGASP *gasp = new OpenTypeGASP; 25 OpenTypeGASP *gasp = new OpenTypeGASP;
26 file->gasp = gasp; 26 font->gasp = gasp;
27 27
28 uint16_t num_ranges = 0; 28 uint16_t num_ranges = 0;
29 if (!table.ReadU16(&gasp->version) || 29 if (!table.ReadU16(&gasp->version) ||
30 !table.ReadU16(&num_ranges)) { 30 !table.ReadU16(&num_ranges)) {
31 return OTS_FAILURE_MSG("Failed to read table header"); 31 return OTS_FAILURE_MSG("Failed to read table header");
32 } 32 }
33 33
34 if (gasp->version > 1) { 34 if (gasp->version > 1) {
35 // Lots of Linux fonts have bad version numbers... 35 // Lots of Linux fonts have bad version numbers...
36 DROP_THIS_TABLE("bad version: %u", gasp->version); 36 DROP_THIS_TABLE("bad version: %u", gasp->version);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 OTS_WARNING("changed the version number to 1"); 73 OTS_WARNING("changed the version number to 1");
74 gasp->version = 1; 74 gasp->version = 1;
75 } 75 }
76 76
77 gasp->gasp_ranges.push_back(std::make_pair(max_ppem, behavior)); 77 gasp->gasp_ranges.push_back(std::make_pair(max_ppem, behavior));
78 } 78 }
79 79
80 return true; 80 return true;
81 } 81 }
82 82
83 bool ots_gasp_should_serialise(OpenTypeFile *file) { 83 bool ots_gasp_should_serialise(Font *font) {
84 return file->gasp != NULL; 84 return font->gasp != NULL;
85 } 85 }
86 86
87 bool ots_gasp_serialise(OTSStream *out, OpenTypeFile *file) { 87 bool ots_gasp_serialise(OTSStream *out, Font *font) {
88 const OpenTypeGASP *gasp = file->gasp; 88 const OpenTypeGASP *gasp = font->gasp;
89 89
90 const uint16_t num_ranges = static_cast<uint16_t>(gasp->gasp_ranges.size()); 90 const uint16_t num_ranges = static_cast<uint16_t>(gasp->gasp_ranges.size());
91 if (num_ranges != gasp->gasp_ranges.size() || 91 if (num_ranges != gasp->gasp_ranges.size() ||
92 !out->WriteU16(gasp->version) || 92 !out->WriteU16(gasp->version) ||
93 !out->WriteU16(num_ranges)) { 93 !out->WriteU16(num_ranges)) {
94 return OTS_FAILURE_MSG("failed to write gasp header"); 94 return OTS_FAILURE_MSG("failed to write gasp header");
95 } 95 }
96 96
97 for (uint16_t i = 0; i < num_ranges; ++i) { 97 for (uint16_t i = 0; i < num_ranges; ++i) {
98 if (!out->WriteU16(gasp->gasp_ranges[i].first) || 98 if (!out->WriteU16(gasp->gasp_ranges[i].first) ||
99 !out->WriteU16(gasp->gasp_ranges[i].second)) { 99 !out->WriteU16(gasp->gasp_ranges[i].second)) {
100 return OTS_FAILURE_MSG("Failed to write gasp subtable %d", i); 100 return OTS_FAILURE_MSG("Failed to write gasp subtable %d", i);
101 } 101 }
102 } 102 }
103 103
104 return true; 104 return true;
105 } 105 }
106 106
107 void ots_gasp_free(OpenTypeFile *file) { 107 void ots_gasp_reuse(Font *font, Font *other) {
108 delete file->gasp; 108 font->gasp = other->gasp;
109 font->gasp_reused = true;
110 }
111
112 void ots_gasp_free(Font *font) {
113 delete font->gasp;
109 } 114 }
110 115
111 } // namespace ots 116 } // namespace ots
112 117
113 #undef TABLE_NAME 118 #undef TABLE_NAME
114 #undef DROP_THIS_TABLE 119 #undef DROP_THIS_TABLE
OLDNEW
« no previous file with comments | « third_party/ots/src/fpgm.cc ('k') | third_party/ots/src/gdef.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698