Bug 1601406 [wpt PR 20618] - Advertise DocumentPolicy & Network Err when receive...
[gecko.git] / gfx / ots / src / cvar.cc
bloba2bad7a15e022a738ccb985cf09f338d80a4ba3e
1 // Copyright (c) 2018 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 "cvar.h"
7 #include "fvar.h"
8 #include "variations.h"
10 namespace ots {
12 // -----------------------------------------------------------------------------
13 // OpenTypeCVAR
14 // -----------------------------------------------------------------------------
16 bool OpenTypeCVAR::Parse(const uint8_t* data, size_t length) {
17 Buffer table(data, length);
19 uint16_t majorVersion;
20 uint16_t minorVersion;
22 if (!table.ReadU16(&majorVersion) ||
23 !table.ReadU16(&minorVersion)) {
24 return Drop("Failed to read table header");
27 if (majorVersion != 1) {
28 return Drop("Unknown table version");
31 OpenTypeFVAR* fvar = static_cast<OpenTypeFVAR*>(
32 GetFont()->GetTypedTable(OTS_TAG_FVAR));
33 if (!fvar) {
34 return DropVariations("Required fvar table is missing");
37 if (!ParseVariationData(GetFont(), data + table.offset(), length - table.offset(),
38 fvar->AxisCount(), 0)) {
39 return Drop("Failed to parse variation data");
42 this->m_data = data;
43 this->m_length = length;
45 return true;
48 bool OpenTypeCVAR::Serialize(OTSStream* out) {
49 if (!out->Write(this->m_data, this->m_length)) {
50 return Error("Failed to write cvar table");
53 return true;
56 } // namespace ots