Line | Count | Source |
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 | 1.37k | bool OpenTypeCVAR::Parse(const uint8_t* data, size_t length) { |
17 | 1.37k | Buffer table(data, length); |
18 | | |
19 | 1.37k | uint16_t majorVersion; |
20 | 1.37k | uint16_t minorVersion; |
21 | | |
22 | 1.37k | if (!table.ReadU16(&majorVersion) || |
23 | 1.36k | !table.ReadU16(&minorVersion)) { |
24 | 80 | return Drop("Failed to read table header"); |
25 | 80 | } |
26 | | |
27 | 1.29k | if (majorVersion != 1) { |
28 | 189 | return Drop("Unknown table version"); |
29 | 189 | } |
30 | | |
31 | 1.10k | OpenTypeFVAR* fvar = static_cast<OpenTypeFVAR*>( |
32 | 1.10k | GetFont()->GetTypedTable(OTS_TAG_FVAR)); |
33 | 1.10k | if (!fvar) { |
34 | 926 | return DropVariations("Required fvar table is missing"); |
35 | 926 | } |
36 | | |
37 | 183 | if (!ParseVariationData(GetFont(), data + table.offset(), length - table.offset(), |
38 | 183 | fvar->AxisCount(), 0)) { |
39 | 174 | return Drop("Failed to parse variation data"); |
40 | 174 | } |
41 | | |
42 | 9 | this->m_data = data; |
43 | 9 | this->m_length = length; |
44 | | |
45 | 9 | return true; |
46 | 183 | } |
47 | | |
48 | 7 | bool OpenTypeCVAR::Serialize(OTSStream* out) { |
49 | 7 | if (!out->Write(this->m_data, this->m_length)) { |
50 | 0 | return Error("Failed to write cvar table"); |
51 | 0 | } |
52 | | |
53 | 7 | return true; |
54 | 7 | } |
55 | | |
56 | | } // namespace ots |