diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /gfx/ots/src/ltsh.cc | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/ots/src/ltsh.cc')
-rw-r--r-- | gfx/ots/src/ltsh.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/gfx/ots/src/ltsh.cc b/gfx/ots/src/ltsh.cc new file mode 100644 index 0000000000..4c40c5eb77 --- /dev/null +++ b/gfx/ots/src/ltsh.cc @@ -0,0 +1,71 @@ +// 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. + +#include "ltsh.h" + +#include "maxp.h" + +// LTSH - Linear Threshold +// http://www.microsoft.com/typography/otspec/ltsh.htm + +namespace ots { + +bool OpenTypeLTSH::Parse(const uint8_t *data, size_t length) { + Buffer table(data, length); + + OpenTypeMAXP *maxp = static_cast<OpenTypeMAXP*>( + GetFont()->GetTypedTable(OTS_TAG_MAXP)); + if (!maxp) { + return Error("Required maxp table is missing"); + } + + uint16_t num_glyphs = 0; + if (!table.ReadU16(&this->version) || + !table.ReadU16(&num_glyphs)) { + return Error("Failed to read table header"); + } + + if (this->version != 0) { + return Drop("Unsupported version: %u", this->version); + } + + if (num_glyphs != maxp->num_glyphs) { + return Drop("Bad numGlyphs: %u", num_glyphs); + } + + this->ypels.reserve(num_glyphs); + for (unsigned i = 0; i < num_glyphs; ++i) { + uint8_t pel = 0; + if (!table.ReadU8(&pel)) { + return Error("Failed to read pixels for glyph %d", i); + } + this->ypels.push_back(pel); + } + + return true; +} + +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 Error("Failed to write table header"); + } + for (uint16_t i = 0; i < num_ypels; ++i) { + if (!out->Write(&(this->ypels[i]), 1)) { + return Error("Failed to write pixel size for glyph %d", i); + } + } + + return true; +} + +bool OpenTypeLTSH::ShouldSerialize() { + return Table::ShouldSerialize() && + // this table is not for CFF fonts. + GetFont()->GetTable(OTS_TAG_GLYF) != NULL; +} + +} // namespace ots |