tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

sile.cc (2246B)


      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 "sile.h"
      6 
      7 namespace ots {
      8 
      9 bool OpenTypeSILE::Parse(const uint8_t* data, size_t length) {
     10  Buffer table(data, length);
     11 
     12  if (!table.ReadU32(&this->version) || this->version >> 16 != 1) {
     13    return DropGraphite("Failed to read valid version");
     14  }
     15  if (!table.ReadU32(&this->checksum)) {
     16    return DropGraphite("Failed to read checksum");
     17  }
     18  if (!table.ReadU32(&this->createTime[0]) ||
     19      !table.ReadU32(&this->createTime[1])) {
     20    return DropGraphite("Failed to read createTime");
     21  }
     22  if (!table.ReadU32(&this->modifyTime[0]) ||
     23      !table.ReadU32(&this->modifyTime[1])) {
     24    return DropGraphite("Failed to read modifyTime");
     25  }
     26 
     27  if (!table.ReadU16(&this->fontNameLength)) {
     28    return DropGraphite("Failed to read fontNameLength");
     29  }
     30  //this->fontName.resize(this->fontNameLength);
     31  for (unsigned i = 0; i < this->fontNameLength; ++i) {
     32    this->fontName.emplace_back();
     33    if (!table.ReadU16(&this->fontName[i])) {
     34      return DropGraphite("Failed to read fontName[%u]", i);
     35    }
     36  }
     37 
     38  if (!table.ReadU16(&this->fontFileLength)) {
     39    return DropGraphite("Failed to read fontFileLength");
     40  }
     41  //this->baseFile.resize(this->fontFileLength);
     42  for (unsigned i = 0; i < this->fontFileLength; ++i) {
     43    this->baseFile.emplace_back();
     44    if (!table.ReadU16(&this->baseFile[i])) {
     45      return DropGraphite("Failed to read baseFile[%u]", i);
     46    }
     47  }
     48 
     49  if (table.remaining()) {
     50    return Warning("%zu bytes unparsed", table.remaining());
     51  }
     52  return true;
     53 }
     54 
     55 bool OpenTypeSILE::Serialize(OTSStream* out) {
     56  if (!out->WriteU32(this->version) ||
     57      !out->WriteU32(this->checksum) ||
     58      !out->WriteU32(this->createTime[0]) ||
     59      !out->WriteU32(this->createTime[1]) ||
     60      !out->WriteU32(this->modifyTime[0]) ||
     61      !out->WriteU32(this->modifyTime[1]) ||
     62      !out->WriteU16(this->fontNameLength) ||
     63      !SerializeParts(this->fontName, out) ||
     64      !out->WriteU16(this->fontFileLength) ||
     65      !SerializeParts(this->baseFile, out)) {
     66    return Error("Failed to write table");
     67  }
     68  return true;
     69 }
     70 
     71 }  // namespace ots