tor-browser

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

prep.cc (1064B)


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