tor-browser

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

cff.h (2231B)


      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 #ifndef OTS_CFF_H_
      6 #define OTS_CFF_H_
      7 
      8 #include "ots.h"
      9 
     10 #include <map>
     11 #include <string>
     12 #include <vector>
     13 
     14 #undef major // glibc defines major!
     15 
     16 namespace ots {
     17 
     18 struct CFFIndex {
     19  CFFIndex()
     20      : count(0), off_size(0), offset_to_next(0) {}
     21  uint32_t count;
     22  uint8_t off_size;
     23  std::vector<uint32_t> offsets;
     24  uint32_t offset_to_next;
     25 };
     26 
     27 typedef std::map<uint32_t, uint16_t> CFFFDSelect;
     28 
     29 class OpenTypeCFF : public Table {
     30 public:
     31  explicit OpenTypeCFF(Font *font, uint32_t tag)
     32      : Table(font, tag, tag),
     33        major(0),
     34        font_dict_length(0),
     35        charstrings_index(NULL),
     36        local_subrs(NULL),
     37        m_data(NULL),
     38        m_length(0) {
     39  }
     40 
     41  ~OpenTypeCFF();
     42 
     43  bool Parse(const uint8_t *data, size_t length);
     44  bool Serialize(OTSStream *out);
     45 
     46  // Major version number.
     47  uint8_t major;
     48 
     49  // Name INDEX. This name is used in name.cc as a postscript font name.
     50  std::string name;
     51 
     52  // The number of fonts the file has.
     53  size_t font_dict_length;
     54  // A map from glyph # to font #.
     55  CFFFDSelect fd_select;
     56 
     57  // A list of char strings.
     58  CFFIndex* charstrings_index;
     59  // A list of Local Subrs associated with FDArrays. Can be empty.
     60  std::vector<CFFIndex *> local_subrs_per_font;
     61  // A Local Subrs associated with Top DICT. Can be NULL.
     62  CFFIndex *local_subrs;
     63 
     64  // CFF2 VariationStore regionIndexCount.
     65  std::vector<uint16_t> region_index_count;
     66 
     67  // CFF2 vsindex: per FontDICT->PrivateDICT
     68  // default of 0 is stored for each font if not
     69  // explicitly set in Font's PrivateDICT.
     70  std::vector<int32_t> vsindex_per_font;
     71 
     72 protected:
     73  bool ValidateFDSelect(uint16_t num_glyphs);
     74 
     75 private:
     76  const uint8_t *m_data;
     77  size_t m_length;
     78 };
     79 
     80 class OpenTypeCFF2 : public OpenTypeCFF {
     81 public:
     82  explicit OpenTypeCFF2(Font *font, uint32_t tag)
     83      : OpenTypeCFF(font, tag),
     84        m_data(NULL),
     85        m_length(0) {
     86  }
     87 
     88  bool Parse(const uint8_t *data, size_t length);
     89  bool Serialize(OTSStream *out);
     90 
     91 private:
     92  const uint8_t *m_data;
     93  size_t m_length;
     94 };
     95 
     96 }  // namespace ots
     97 
     98 #endif  // OTS_CFF_H_