cvar.cc (1402B)
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. 4 5 #include "cvar.h" 6 7 #include "fvar.h" 8 #include "variations.h" 9 10 namespace ots { 11 12 // ----------------------------------------------------------------------------- 13 // OpenTypeCVAR 14 // ----------------------------------------------------------------------------- 15 16 bool OpenTypeCVAR::Parse(const uint8_t* data, size_t length) { 17 Buffer table(data, length); 18 19 uint16_t majorVersion; 20 uint16_t minorVersion; 21 22 if (!table.ReadU16(&majorVersion) || 23 !table.ReadU16(&minorVersion)) { 24 return Drop("Failed to read table header"); 25 } 26 27 if (majorVersion != 1) { 28 return Drop("Unknown table version"); 29 } 30 31 OpenTypeFVAR* fvar = static_cast<OpenTypeFVAR*>( 32 GetFont()->GetTypedTable(OTS_TAG_FVAR)); 33 if (!fvar) { 34 return DropVariations("Required fvar table is missing"); 35 } 36 37 if (!ParseVariationData(GetFont(), data + table.offset(), length - table.offset(), 38 fvar->AxisCount(), 0)) { 39 return Drop("Failed to parse variation data"); 40 } 41 42 this->m_data = data; 43 this->m_length = length; 44 45 return true; 46 } 47 48 bool OpenTypeCVAR::Serialize(OTSStream* out) { 49 if (!out->Write(this->m_data, this->m_length)) { 50 return Error("Failed to write cvar table"); 51 } 52 53 return true; 54 } 55 56 } // namespace ots