tor-browser

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

glyf.h (2437B)


      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_GLYF_H_
      6 #define OTS_GLYF_H_
      7 
      8 #include <new>
      9 #include <utility>
     10 #include <vector>
     11 
     12 #include "ots.h"
     13 
     14 namespace ots {
     15 class OpenTypeLOCA;
     16 class OpenTypeMAXP;
     17 
     18 class OpenTypeGLYF : public Table {
     19 public:
     20  explicit OpenTypeGLYF(Font *font, uint32_t tag)
     21      : Table(font, tag, tag), maxp(NULL) { }
     22 
     23  ~OpenTypeGLYF() {
     24    for (auto* p : replacements) {
     25      delete[] p;
     26    }
     27  }
     28 
     29  bool Parse(const uint8_t *data, size_t length);
     30  bool Serialize(OTSStream *out);
     31 
     32 private:
     33  struct GidAtLevel {
     34    uint16_t gid;
     35    uint32_t level;
     36  };
     37 
     38  struct ComponentPointCount {
     39    ComponentPointCount() : accumulated_component_points(0) {};
     40    uint32_t accumulated_component_points;
     41    std::vector<GidAtLevel> gid_stack;
     42  };
     43 
     44  bool ParseFlagsForSimpleGlyph(Buffer &glyph,
     45                                uint32_t num_flags,
     46                                std::vector<uint8_t>& flags,
     47                                uint32_t *flag_index,
     48                                uint32_t *coordinates_length);
     49  bool ParseSimpleGlyph(Buffer &glyph,
     50                        unsigned gid,
     51                        int16_t num_contours,
     52                        int16_t xmin,
     53                        int16_t ymin,
     54                        int16_t xmax,
     55                        int16_t ymax,
     56                        bool is_tricky_font);
     57 
     58  // The skip_count outparam returns the number of bytes from the original
     59  // glyph description that are being skipped on output (normally zero).
     60  bool ParseCompositeGlyph(
     61      Buffer &glyph,
     62      unsigned glyph_id,
     63      ComponentPointCount* component_point_count,
     64      unsigned* skip_count);
     65 
     66  bool TraverseComponentsCountingPoints(
     67      Buffer& glyph,
     68      uint16_t base_glyph_id,
     69      uint32_t level,
     70      ComponentPointCount* component_point_count);
     71 
     72  Buffer GetGlyphBufferSection(
     73      const uint8_t *data,
     74      size_t length,
     75      const std::vector<uint32_t>& loca_offsets,
     76      unsigned glyph_id);
     77 
     78  OpenTypeLOCA* loca;
     79  OpenTypeMAXP* maxp;
     80 
     81  std::vector<std::pair<const uint8_t*, size_t> > iov;
     82 
     83  // Any blocks of replacement data created during parsing are stored here
     84  // to be available during serialization.
     85  std::vector<uint8_t*> replacements;
     86 };
     87 
     88 }  // namespace ots
     89 
     90 #endif  // OTS_GLYF_H_