summaryrefslogtreecommitdiffstats
path: root/gfx/ots/src/loca.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/ots/src/loca.cc')
-rw-r--r--gfx/ots/src/loca.cc72
1 files changed, 28 insertions, 44 deletions
diff --git a/gfx/ots/src/loca.cc b/gfx/ots/src/loca.cc
index aae04c25a..4f322027d 100644
--- a/gfx/ots/src/loca.cc
+++ b/gfx/ots/src/loca.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.
@@ -10,84 +10,79 @@
// loca - Index to Location
// http://www.microsoft.com/typography/otspec/loca.htm
-#define TABLE_NAME "loca"
-
namespace ots {
-bool ots_loca_parse(Font *font, const uint8_t *data, size_t length) {
+bool OpenTypeLOCA::Parse(const uint8_t *data, size_t length) {
Buffer table(data, length);
// We can't do anything useful in validating this data except to ensure that
// the values are monotonically increasing.
- OpenTypeLOCA *loca = new OpenTypeLOCA;
- font->loca = loca;
-
- if (!font->maxp || !font->head) {
- return OTS_FAILURE_MSG("maxp or head tables missing from font, needed by loca");
+ OpenTypeMAXP *maxp = static_cast<OpenTypeMAXP*>(
+ GetFont()->GetTypedTable(OTS_TAG_MAXP));
+ OpenTypeHEAD *head = static_cast<OpenTypeHEAD*>(
+ GetFont()->GetTypedTable(OTS_TAG_HEAD));
+ if (!maxp || !head) {
+ return Error("Required maxp or head tables are missing");
}
- const unsigned num_glyphs = font->maxp->num_glyphs;
+ const unsigned num_glyphs = maxp->num_glyphs;
unsigned last_offset = 0;
- loca->offsets.resize(num_glyphs + 1);
+ this->offsets.resize(num_glyphs + 1);
// maxp->num_glyphs is uint16_t, thus the addition never overflows.
- if (font->head->index_to_loc_format == 0) {
+ if (head->index_to_loc_format == 0) {
// Note that the <= here (and below) is correct. There is one more offset
// than the number of glyphs in order to give the length of the final
// glyph.
for (unsigned i = 0; i <= num_glyphs; ++i) {
uint16_t offset = 0;
if (!table.ReadU16(&offset)) {
- return OTS_FAILURE_MSG("Failed to read offset for glyph %d", i);
+ return Error("Failed to read offset for glyph %d", i);
}
if (offset < last_offset) {
- return OTS_FAILURE_MSG("Out of order offset %d < %d for glyph %d", offset, last_offset, i);
+ return Error("Out of order offset %d < %d for glyph %d", offset, last_offset, i);
}
last_offset = offset;
- loca->offsets[i] = offset * 2;
+ this->offsets[i] = offset * 2;
}
} else {
for (unsigned i = 0; i <= num_glyphs; ++i) {
uint32_t offset = 0;
if (!table.ReadU32(&offset)) {
- return OTS_FAILURE_MSG("Failed to read offset for glyph %d", i);
+ return Error("Failed to read offset for glyph %d", i);
}
if (offset < last_offset) {
- return OTS_FAILURE_MSG("Out of order offset %d < %d for glyph %d", offset, last_offset, i);
+ return Error("Out of order offset %d < %d for glyph %d", offset, last_offset, i);
}
last_offset = offset;
- loca->offsets[i] = offset;
+ this->offsets[i] = offset;
}
}
return true;
}
-bool ots_loca_should_serialise(Font *font) {
- return font->loca != NULL;
-}
-
-bool ots_loca_serialise(OTSStream *out, Font *font) {
- const OpenTypeLOCA *loca = font->loca;
- const OpenTypeHEAD *head = font->head;
+bool OpenTypeLOCA::Serialize(OTSStream *out) {
+ OpenTypeHEAD *head = static_cast<OpenTypeHEAD*>(
+ GetFont()->GetTypedTable(OTS_TAG_HEAD));
if (!head) {
- return OTS_FAILURE_MSG("Missing head table in font needed by loca");
+ return Error("Required head table is missing");
}
if (head->index_to_loc_format == 0) {
- for (unsigned i = 0; i < loca->offsets.size(); ++i) {
- const uint16_t offset = static_cast<uint16_t>(loca->offsets[i] >> 1);
- if ((offset != (loca->offsets[i] >> 1)) ||
+ for (unsigned i = 0; i < this->offsets.size(); ++i) {
+ const uint16_t offset = static_cast<uint16_t>(this->offsets[i] >> 1);
+ if ((offset != (this->offsets[i] >> 1)) ||
!out->WriteU16(offset)) {
- return OTS_FAILURE_MSG("Failed to write glyph offset for glyph %d", i);
+ return Error("Failed to write glyph offset for glyph %d", i);
}
}
} else {
- for (unsigned i = 0; i < loca->offsets.size(); ++i) {
- if (!out->WriteU32(loca->offsets[i])) {
- return OTS_FAILURE_MSG("Failed to write glyph offset for glyph %d", i);
+ for (unsigned i = 0; i < this->offsets.size(); ++i) {
+ if (!out->WriteU32(this->offsets[i])) {
+ return Error("Failed to write glyph offset for glyph %d", i);
}
}
}
@@ -95,15 +90,4 @@ bool ots_loca_serialise(OTSStream *out, Font *font) {
return true;
}
-void ots_loca_reuse(Font *font, Font *other) {
- font->loca = other->loca;
- font->loca_reused = true;
-}
-
-void ots_loca_free(Font *font) {
- delete font->loca;
-}
-
} // namespace ots
-
-#undef TABLE_NAME