summaryrefslogtreecommitdiffstats
path: root/gfx/ots/src/ltsh.cc
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2019-11-14 21:08:43 -0500
committerMatt A. Tobin <email@mattatobin.com>2019-11-14 21:08:43 -0500
commit1d30f6fa8413746ddc408f93710d701493af273d (patch)
treeabe84e83d704e13c60c90db7ac4b9e363d8a81fc /gfx/ots/src/ltsh.cc
parent9308ec68e863e4c6e650680370a5d7baa9f0d1f3 (diff)
parent00573571a226a0c59dd744da67483864a22911aa (diff)
downloadUXP-1d30f6fa8413746ddc408f93710d701493af273d.tar
UXP-1d30f6fa8413746ddc408f93710d701493af273d.tar.gz
UXP-1d30f6fa8413746ddc408f93710d701493af273d.tar.lz
UXP-1d30f6fa8413746ddc408f93710d701493af273d.tar.xz
UXP-1d30f6fa8413746ddc408f93710d701493af273d.zip
Merge branch 'master' into mailnews-work
Diffstat (limited to 'gfx/ots/src/ltsh.cc')
-rw-r--r--gfx/ots/src/ltsh.cc78
1 files changed, 26 insertions, 52 deletions
diff --git a/gfx/ots/src/ltsh.cc b/gfx/ots/src/ltsh.cc
index 5b34cf4ad..4c40c5eb7 100644
--- a/gfx/ots/src/ltsh.cc
+++ b/gfx/ots/src/ltsh.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.
@@ -9,89 +9,63 @@
// LTSH - Linear Threshold
// http://www.microsoft.com/typography/otspec/ltsh.htm
-#define TABLE_NAME "LTSH"
-
-#define DROP_THIS_TABLE(...) \
- do { \
- OTS_FAILURE_MSG_(font->file, TABLE_NAME ": " __VA_ARGS__); \
- OTS_FAILURE_MSG("Table discarded"); \
- delete font->ltsh; \
- font->ltsh = 0; \
- } while (0)
-
namespace ots {
-bool ots_ltsh_parse(Font *font, const uint8_t *data, size_t length) {
+bool OpenTypeLTSH::Parse(const uint8_t *data, size_t length) {
Buffer table(data, length);
- if (!font->maxp) {
- return OTS_FAILURE_MSG("Missing maxp table from font needed by ltsh");
+ OpenTypeMAXP *maxp = static_cast<OpenTypeMAXP*>(
+ GetFont()->GetTypedTable(OTS_TAG_MAXP));
+ if (!maxp) {
+ return Error("Required maxp table is missing");
}
- OpenTypeLTSH *ltsh = new OpenTypeLTSH;
- font->ltsh = ltsh;
-
uint16_t num_glyphs = 0;
- if (!table.ReadU16(&ltsh->version) ||
+ if (!table.ReadU16(&this->version) ||
!table.ReadU16(&num_glyphs)) {
- return OTS_FAILURE_MSG("Failed to read ltsh header");
+ return Error("Failed to read table header");
}
- if (ltsh->version != 0) {
- DROP_THIS_TABLE("bad version: %u", ltsh->version);
- return true;
+ if (this->version != 0) {
+ return Drop("Unsupported version: %u", this->version);
}
- if (num_glyphs != font->maxp->num_glyphs) {
- DROP_THIS_TABLE("bad num_glyphs: %u", num_glyphs);
- return true;
+ if (num_glyphs != maxp->num_glyphs) {
+ return Drop("Bad numGlyphs: %u", num_glyphs);
}
- ltsh->ypels.reserve(num_glyphs);
+ this->ypels.reserve(num_glyphs);
for (unsigned i = 0; i < num_glyphs; ++i) {
uint8_t pel = 0;
if (!table.ReadU8(&pel)) {
- return OTS_FAILURE_MSG("Failed to read pixels for glyph %d", i);
+ return Error("Failed to read pixels for glyph %d", i);
}
- ltsh->ypels.push_back(pel);
+ this->ypels.push_back(pel);
}
return true;
}
-bool ots_ltsh_should_serialise(Font *font) {
- if (!font->glyf) return false; // this table is not for CFF fonts.
- return font->ltsh != NULL;
-}
-
-bool ots_ltsh_serialise(OTSStream *out, Font *font) {
- const OpenTypeLTSH *ltsh = font->ltsh;
-
- const uint16_t num_ypels = static_cast<uint16_t>(ltsh->ypels.size());
- if (num_ypels != ltsh->ypels.size() ||
- !out->WriteU16(ltsh->version) ||
+bool OpenTypeLTSH::Serialize(OTSStream *out) {
+ const uint16_t num_ypels = static_cast<uint16_t>(this->ypels.size());
+ if (num_ypels != this->ypels.size() ||
+ !out->WriteU16(this->version) ||
!out->WriteU16(num_ypels)) {
- return OTS_FAILURE_MSG("Failed to write pels size");
+ return Error("Failed to write table header");
}
for (uint16_t i = 0; i < num_ypels; ++i) {
- if (!out->Write(&(ltsh->ypels[i]), 1)) {
- return OTS_FAILURE_MSG("Failed to write pixel size for glyph %d", i);
+ if (!out->Write(&(this->ypels[i]), 1)) {
+ return Error("Failed to write pixel size for glyph %d", i);
}
}
return true;
}
-void ots_ltsh_reuse(Font *font, Font *other) {
- font->ltsh = other->ltsh;
- font->ltsh_reused = true;
-}
-
-void ots_ltsh_free(Font *font) {
- delete font->ltsh;
+bool OpenTypeLTSH::ShouldSerialize() {
+ return Table::ShouldSerialize() &&
+ // this table is not for CFF fonts.
+ GetFont()->GetTable(OTS_TAG_GLYF) != NULL;
}
} // namespace ots
-
-#undef TABLE_NAME
-#undef DROP_THIS_TABLE