tor-browser

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

fpgm.cc (1011B)


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