Backed out 3 changesets (bug 1889130) for causing xpcshell failures in test_dooh...
[gecko.git] / gfx / ots / src / ltsh.cc
blob4c40c5eb77e100c4f1b33b5432063cbc021fa7dc
1 // Copyright (c) 2009-2017 The OTS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ltsh.h"
7 #include "maxp.h"
9 // LTSH - Linear Threshold
10 // http://www.microsoft.com/typography/otspec/ltsh.htm
12 namespace ots {
14 bool OpenTypeLTSH::Parse(const uint8_t *data, size_t length) {
15 Buffer table(data, length);
17 OpenTypeMAXP *maxp = static_cast<OpenTypeMAXP*>(
18 GetFont()->GetTypedTable(OTS_TAG_MAXP));
19 if (!maxp) {
20 return Error("Required maxp table is missing");
23 uint16_t num_glyphs = 0;
24 if (!table.ReadU16(&this->version) ||
25 !table.ReadU16(&num_glyphs)) {
26 return Error("Failed to read table header");
29 if (this->version != 0) {
30 return Drop("Unsupported version: %u", this->version);
33 if (num_glyphs != maxp->num_glyphs) {
34 return Drop("Bad numGlyphs: %u", num_glyphs);
37 this->ypels.reserve(num_glyphs);
38 for (unsigned i = 0; i < num_glyphs; ++i) {
39 uint8_t pel = 0;
40 if (!table.ReadU8(&pel)) {
41 return Error("Failed to read pixels for glyph %d", i);
43 this->ypels.push_back(pel);
46 return true;
49 bool OpenTypeLTSH::Serialize(OTSStream *out) {
50 const uint16_t num_ypels = static_cast<uint16_t>(this->ypels.size());
51 if (num_ypels != this->ypels.size() ||
52 !out->WriteU16(this->version) ||
53 !out->WriteU16(num_ypels)) {
54 return Error("Failed to write table header");
56 for (uint16_t i = 0; i < num_ypels; ++i) {
57 if (!out->Write(&(this->ypels[i]), 1)) {
58 return Error("Failed to write pixel size for glyph %d", i);
62 return true;
65 bool OpenTypeLTSH::ShouldSerialize() {
66 return Table::ShouldSerialize() &&
67 // this table is not for CFF fonts.
68 GetFont()->GetTable(OTS_TAG_GLYF) != NULL;
71 } // namespace ots