summaryrefslogtreecommitdiffstats
path: root/gfx/ots/src/gasp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/ots/src/gasp.cc')
-rw-r--r--gfx/ots/src/gasp.cc85
1 files changed, 25 insertions, 60 deletions
diff --git a/gfx/ots/src/gasp.cc b/gfx/ots/src/gasp.cc
index 5ebf5d84b..2a03c831f 100644
--- a/gfx/ots/src/gasp.cc
+++ b/gfx/ots/src/gasp.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009-2017 The OTS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,113 +7,78 @@
// gasp - Grid-fitting And Scan-conversion Procedure
// http://www.microsoft.com/typography/otspec/gasp.htm
-#define TABLE_NAME "gasp"
-
-#define DROP_THIS_TABLE(...) \
- do { \
- OTS_FAILURE_MSG_(font->file, TABLE_NAME ": " __VA_ARGS__); \
- OTS_FAILURE_MSG("Table discarded"); \
- delete font->gasp; \
- font->gasp = 0; \
- } while (0)
-
namespace ots {
-bool ots_gasp_parse(Font *font, const uint8_t *data, size_t length) {
+bool OpenTypeGASP::Parse(const uint8_t *data, size_t length) {
Buffer table(data, length);
- OpenTypeGASP *gasp = new OpenTypeGASP;
- font->gasp = gasp;
-
uint16_t num_ranges = 0;
- if (!table.ReadU16(&gasp->version) ||
+ if (!table.ReadU16(&this->version) ||
!table.ReadU16(&num_ranges)) {
- return OTS_FAILURE_MSG("Failed to read table header");
+ return Error("Failed to read table header");
}
- if (gasp->version > 1) {
+ if (this->version > 1) {
// Lots of Linux fonts have bad version numbers...
- DROP_THIS_TABLE("bad version: %u", gasp->version);
- return true;
+ return Drop("Unsupported version: %u", this->version);
}
if (num_ranges == 0) {
- DROP_THIS_TABLE("num_ranges is zero");
- return true;
+ return Drop("numRanges is zero");
}
- gasp->gasp_ranges.reserve(num_ranges);
+ this->gasp_ranges.reserve(num_ranges);
for (unsigned i = 0; i < num_ranges; ++i) {
uint16_t max_ppem = 0;
uint16_t behavior = 0;
if (!table.ReadU16(&max_ppem) ||
!table.ReadU16(&behavior)) {
- return OTS_FAILURE_MSG("Failed to read subrange %d", i);
+ return Error("Failed to read GASPRANGE %d", i);
}
- if ((i > 0) && (gasp->gasp_ranges[i - 1].first >= max_ppem)) {
+ if ((i > 0) && (this->gasp_ranges[i - 1].first >= max_ppem)) {
// The records in the gaspRange[] array must be sorted in order of
// increasing rangeMaxPPEM value.
- DROP_THIS_TABLE("ranges are not sorted");
- return true;
+ return Drop("Ranges are not sorted");
}
if ((i == num_ranges - 1u) && // never underflow.
(max_ppem != 0xffffu)) {
- DROP_THIS_TABLE("The last record should be 0xFFFF as a sentinel value "
+ return Drop("The last record should be 0xFFFF as a sentinel value "
"for rangeMaxPPEM");
- return true;
}
if (behavior >> 8) {
- OTS_WARNING("undefined bits are used: %x", behavior);
+ Warning("Undefined bits are used: %x", behavior);
// mask undefined bits.
behavior &= 0x000fu;
}
- if (gasp->version == 0 && (behavior >> 2) != 0) {
- OTS_WARNING("changed the version number to 1");
- gasp->version = 1;
+ if (this->version == 0 && (behavior >> 2) != 0) {
+ Warning("Changed the version number to 1");
+ this->version = 1;
}
- gasp->gasp_ranges.push_back(std::make_pair(max_ppem, behavior));
+ this->gasp_ranges.push_back(std::make_pair(max_ppem, behavior));
}
return true;
}
-bool ots_gasp_should_serialise(Font *font) {
- return font->gasp != NULL;
-}
-
-bool ots_gasp_serialise(OTSStream *out, Font *font) {
- const OpenTypeGASP *gasp = font->gasp;
-
- const uint16_t num_ranges = static_cast<uint16_t>(gasp->gasp_ranges.size());
- if (num_ranges != gasp->gasp_ranges.size() ||
- !out->WriteU16(gasp->version) ||
+bool OpenTypeGASP::Serialize(OTSStream *out) {
+ const uint16_t num_ranges = static_cast<uint16_t>(this->gasp_ranges.size());
+ if (num_ranges != this->gasp_ranges.size() ||
+ !out->WriteU16(this->version) ||
!out->WriteU16(num_ranges)) {
- return OTS_FAILURE_MSG("failed to write gasp header");
+ return Error("Failed to write table header");
}
for (uint16_t i = 0; i < num_ranges; ++i) {
- if (!out->WriteU16(gasp->gasp_ranges[i].first) ||
- !out->WriteU16(gasp->gasp_ranges[i].second)) {
- return OTS_FAILURE_MSG("Failed to write gasp subtable %d", i);
+ if (!out->WriteU16(this->gasp_ranges[i].first) ||
+ !out->WriteU16(this->gasp_ranges[i].second)) {
+ return Error("Failed to write GASPRANGE %d", i);
}
}
return true;
}
-void ots_gasp_reuse(Font *font, Font *other) {
- font->gasp = other->gasp;
- font->gasp_reused = true;
-}
-
-void ots_gasp_free(Font *font) {
- delete font->gasp;
-}
-
} // namespace ots
-
-#undef TABLE_NAME
-#undef DROP_THIS_TABLE