tor-browser

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

hvar.cc (2502B)


      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 "hvar.h"
      6 
      7 #include "variations.h"
      8 
      9 namespace ots {
     10 
     11 // -----------------------------------------------------------------------------
     12 // OpenTypeHVAR
     13 // -----------------------------------------------------------------------------
     14 
     15 bool OpenTypeHVAR::Parse(const uint8_t* data, size_t length) {
     16  Buffer table(data, length);
     17 
     18  uint16_t majorVersion;
     19  uint16_t minorVersion;
     20  uint32_t itemVariationStoreOffset;
     21  uint32_t advanceWidthMappingOffset;
     22  uint32_t lsbMappingOffset;
     23  uint32_t rsbMappingOffset;
     24 
     25  if (!table.ReadU16(&majorVersion) ||
     26      !table.ReadU16(&minorVersion) ||
     27      !table.ReadU32(&itemVariationStoreOffset) ||
     28      !table.ReadU32(&advanceWidthMappingOffset) ||
     29      !table.ReadU32(&lsbMappingOffset) ||
     30      !table.ReadU32(&rsbMappingOffset)) {
     31    return DropVariations("Failed to read table header");
     32  }
     33 
     34  if (majorVersion != 1) {
     35    return DropVariations("Unknown table version");
     36  }
     37 
     38  if (itemVariationStoreOffset > length ||
     39      advanceWidthMappingOffset > length ||
     40      lsbMappingOffset > length ||
     41      rsbMappingOffset > length) {
     42    return DropVariations("Invalid subtable offset");
     43  }
     44 
     45  if (!ParseItemVariationStore(GetFont(), data + itemVariationStoreOffset,
     46                               length - itemVariationStoreOffset)) {
     47    return DropVariations("Failed to parse item variation store");
     48  }
     49 
     50  if (advanceWidthMappingOffset) {
     51    if (!ParseDeltaSetIndexMap(GetFont(), data + advanceWidthMappingOffset,
     52                               length - advanceWidthMappingOffset)) {
     53      return DropVariations("Failed to parse advance width mappings");
     54    }
     55  }
     56 
     57  if (lsbMappingOffset) {
     58    if (!ParseDeltaSetIndexMap(GetFont(), data + lsbMappingOffset,
     59                               length - lsbMappingOffset)) {
     60      return DropVariations("Failed to parse LSB mappings");
     61    }
     62  }
     63 
     64  if (rsbMappingOffset) {
     65    if (!ParseDeltaSetIndexMap(GetFont(), data + rsbMappingOffset,
     66                               length - rsbMappingOffset)) {
     67      return DropVariations("Failed to parse RSB mappings");
     68    }
     69  }
     70 
     71  this->m_data = data;
     72  this->m_length = length;
     73 
     74  return true;
     75 }
     76 
     77 bool OpenTypeHVAR::Serialize(OTSStream* out) {
     78  if (!out->Write(this->m_data, this->m_length)) {
     79    return Error("Failed to write HVAR table");
     80  }
     81 
     82  return true;
     83 }
     84 
     85 }  // namespace ots