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. 4 5 #include "cvt.h" 6 7 // cvt - Control Value Table 8 // http://www.microsoft.com/typography/otspec/cvt.htm 9 10 namespace ots { 11 Parse(const uint8_t * data,size_t length)12bool OpenTypeCVT::Parse(const uint8_t *data, size_t length) { 13 Buffer table(data, length); 14 15 if (length >= 128 * 1024u) { 16 return Error("Length (%d) > 120K"); // almost all cvt tables are less than 4k bytes. 17 } 18 19 if (length % 2 != 0) { 20 return Error("Uneven table length (%d)", length); 21 } 22 23 if (!table.Skip(length)) { 24 return Error("Table length too high"); 25 } 26 27 this->data = data; 28 this->length = length; 29 return true; 30 } 31 Serialize(OTSStream * out)32bool OpenTypeCVT::Serialize(OTSStream *out) { 33 if (!out->Write(this->data, this->length)) { 34 return Error("Failed to write cvt table"); 35 } 36 37 return true; 38 } 39 ShouldSerialize()40bool OpenTypeCVT::ShouldSerialize() { 41 return Table::ShouldSerialize() && 42 // this table is not for CFF fonts. 43 GetFont()->GetTable(OTS_TAG_GLYF) != NULL; 44 } 45 46 } // namespace ots 47