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.
9 bool OpenTypeSILE::Parse(const uint8_t* data
, size_t length
) {
10 if (GetFont()->dropped_graphite
) {
11 return Drop("Skipping Graphite table");
13 Buffer
table(data
, length
);
15 if (!table
.ReadU32(&this->version
) || this->version
>> 16 != 1) {
16 return DropGraphite("Failed to read valid version");
18 if (!table
.ReadU32(&this->checksum
)) {
19 return DropGraphite("Failed to read checksum");
21 if (!table
.ReadU32(&this->createTime
[0]) ||
22 !table
.ReadU32(&this->createTime
[1])) {
23 return DropGraphite("Failed to read createTime");
25 if (!table
.ReadU32(&this->modifyTime
[0]) ||
26 !table
.ReadU32(&this->modifyTime
[1])) {
27 return DropGraphite("Failed to read modifyTime");
30 if (!table
.ReadU16(&this->fontNameLength
)) {
31 return DropGraphite("Failed to read fontNameLength");
33 //this->fontName.resize(this->fontNameLength);
34 for (unsigned i
= 0; i
< this->fontNameLength
; ++i
) {
35 this->fontName
.emplace_back();
36 if (!table
.ReadU16(&this->fontName
[i
])) {
37 return DropGraphite("Failed to read fontName[%u]", i
);
41 if (!table
.ReadU16(&this->fontFileLength
)) {
42 return DropGraphite("Failed to read fontFileLength");
44 //this->baseFile.resize(this->fontFileLength);
45 for (unsigned i
= 0; i
< this->fontFileLength
; ++i
) {
46 this->baseFile
.emplace_back();
47 if (!table
.ReadU16(&this->baseFile
[i
])) {
48 return DropGraphite("Failed to read baseFile[%u]", i
);
52 if (table
.remaining()) {
53 return Warning("%zu bytes unparsed", table
.remaining());
58 bool OpenTypeSILE::Serialize(OTSStream
* out
) {
59 if (!out
->WriteU32(this->version
) ||
60 !out
->WriteU32(this->checksum
) ||
61 !out
->WriteU32(this->createTime
[0]) ||
62 !out
->WriteU32(this->createTime
[1]) ||
63 !out
->WriteU32(this->modifyTime
[0]) ||
64 !out
->WriteU32(this->modifyTime
[1]) ||
65 !out
->WriteU16(this->fontNameLength
) ||
66 !SerializeParts(this->fontName
, out
) ||
67 !out
->WriteU16(this->fontFileLength
) ||
68 !SerializeParts(this->baseFile
, out
)) {
69 return Error("Failed to write table");