Home | History | Annotate | Download | only in font
      1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_
      8 #define CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_
      9 
     10 #include <stdint.h>
     11 
     12 #include <memory>
     13 #include <set>
     14 #include <vector>
     15 
     16 #include "core/fxge/fx_freetype.h"
     17 
     18 class CFX_CTTGSUBTable {
     19  public:
     20   CFX_CTTGSUBTable();
     21   ~CFX_CTTGSUBTable();
     22 
     23   bool LoadGSUBTable(FT_Bytes gsub);
     24   bool GetVerticalGlyph(uint32_t glyphnum, uint32_t* vglyphnum);
     25 
     26  private:
     27   struct TLangSysRecord {
     28     TLangSysRecord();
     29     ~TLangSysRecord();
     30 
     31     uint32_t LangSysTag;
     32     uint16_t LookupOrder;
     33     uint16_t ReqFeatureIndex;
     34     std::vector<uint16_t> FeatureIndices;
     35   };
     36 
     37   struct TScriptRecord {
     38     TScriptRecord();
     39     ~TScriptRecord();
     40 
     41     uint32_t ScriptTag;
     42     uint16_t DefaultLangSys;
     43     std::vector<TLangSysRecord> LangSysRecords;
     44   };
     45 
     46   struct TFeatureRecord {
     47     TFeatureRecord();
     48     ~TFeatureRecord();
     49 
     50     uint32_t FeatureTag;
     51     uint16_t FeatureParams;
     52     std::vector<uint16_t> LookupListIndices;
     53   };
     54 
     55   struct TRangeRecord {
     56     TRangeRecord();
     57 
     58     uint16_t Start;
     59     uint16_t End;
     60     uint16_t StartCoverageIndex;
     61   };
     62 
     63   struct TCoverageFormatBase {
     64     virtual ~TCoverageFormatBase() {}
     65     uint16_t CoverageFormat;
     66   };
     67 
     68   struct TCoverageFormat1 : public TCoverageFormatBase {
     69     TCoverageFormat1();
     70     ~TCoverageFormat1() override;
     71 
     72     std::vector<uint16_t> GlyphArray;
     73   };
     74 
     75   struct TCoverageFormat2 : public TCoverageFormatBase {
     76     TCoverageFormat2();
     77     ~TCoverageFormat2() override;
     78 
     79     std::vector<TRangeRecord> RangeRecords;
     80   };
     81 
     82   struct TDevice {
     83     TDevice() : StartSize(0), EndSize(0), DeltaFormat(0) {}
     84 
     85     uint16_t StartSize;
     86     uint16_t EndSize;
     87     uint16_t DeltaFormat;
     88   };
     89 
     90   struct TSubTableBase {
     91     TSubTableBase();
     92     virtual ~TSubTableBase();
     93 
     94     std::unique_ptr<TCoverageFormatBase> Coverage;
     95     uint16_t SubstFormat;
     96   };
     97 
     98   struct TSubTable1 : public TSubTableBase {
     99     TSubTable1();
    100     ~TSubTable1() override;
    101 
    102     int16_t DeltaGlyphID;
    103   };
    104 
    105   struct TSubTable2 : public TSubTableBase {
    106     TSubTable2();
    107     ~TSubTable2() override;
    108 
    109     std::vector<uint16_t> Substitutes;
    110   };
    111 
    112   struct TLookup {
    113     TLookup();
    114     ~TLookup();
    115 
    116     uint16_t LookupType;
    117     uint16_t LookupFlag;
    118     std::vector<std::unique_ptr<TSubTableBase>> SubTables;
    119   };
    120 
    121   bool Parse(FT_Bytes scriptlist, FT_Bytes featurelist, FT_Bytes lookuplist);
    122   void ParseScriptList(FT_Bytes raw);
    123   void ParseScript(FT_Bytes raw, TScriptRecord* rec);
    124   void ParseLangSys(FT_Bytes raw, TLangSysRecord* rec);
    125   void ParseFeatureList(FT_Bytes raw);
    126   void ParseFeature(FT_Bytes raw, TFeatureRecord* rec);
    127   void ParseLookupList(FT_Bytes raw);
    128   void ParseLookup(FT_Bytes raw, TLookup* rec);
    129   std::unique_ptr<TCoverageFormatBase> ParseCoverage(FT_Bytes raw);
    130   void ParseCoverageFormat1(FT_Bytes raw, TCoverageFormat1* rec);
    131   void ParseCoverageFormat2(FT_Bytes raw, TCoverageFormat2* rec);
    132   void ParseSingleSubst(FT_Bytes raw, std::unique_ptr<TSubTableBase>* rec);
    133   void ParseSingleSubstFormat1(FT_Bytes raw, TSubTable1* rec);
    134   void ParseSingleSubstFormat2(FT_Bytes raw, TSubTable2* rec);
    135 
    136   bool GetVerticalGlyphSub(uint32_t glyphnum,
    137                            uint32_t* vglyphnum,
    138                            TFeatureRecord* Feature);
    139   bool GetVerticalGlyphSub2(uint32_t glyphnum,
    140                             uint32_t* vglyphnum,
    141                             TLookup* Lookup);
    142   int GetCoverageIndex(TCoverageFormatBase* Coverage, uint32_t g) const;
    143 
    144   uint8_t GetUInt8(FT_Bytes& p) const;
    145   int16_t GetInt16(FT_Bytes& p) const;
    146   uint16_t GetUInt16(FT_Bytes& p) const;
    147   int32_t GetInt32(FT_Bytes& p) const;
    148   uint32_t GetUInt32(FT_Bytes& p) const;
    149 
    150   std::set<uint32_t> m_featureSet;
    151   bool m_bFeautureMapLoad;
    152   std::vector<TScriptRecord> ScriptList;
    153   std::vector<TFeatureRecord> FeatureList;
    154   std::vector<TLookup> LookupList;
    155 };
    156 
    157 #endif  // CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_
    158