Home | History | Annotate | Download | only in font
      1 // Copyright 2016 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_CPDF_CIDFONT_H_
      8 #define CORE_FPDFAPI_FONT_CPDF_CIDFONT_H_
      9 
     10 #include <memory>
     11 #include <vector>
     12 
     13 #include "core/fpdfapi/font/cpdf_font.h"
     14 #include "core/fxcrt/fx_string.h"
     15 #include "core/fxcrt/fx_system.h"
     16 #include "core/fxcrt/retain_ptr.h"
     17 #include "core/fxcrt/unowned_ptr.h"
     18 
     19 enum CIDSet : uint8_t {
     20   CIDSET_UNKNOWN,
     21   CIDSET_GB1,
     22   CIDSET_CNS1,
     23   CIDSET_JAPAN1,
     24   CIDSET_KOREA1,
     25   CIDSET_UNICODE,
     26   CIDSET_NUM_SETS
     27 };
     28 
     29 class CFX_CTTGSUBTable;
     30 class CPDF_Array;
     31 class CPDF_CID2UnicodeMap;
     32 class CPDF_CMap;
     33 class CPDF_StreamAcc;
     34 
     35 class CPDF_CIDFont : public CPDF_Font {
     36  public:
     37   CPDF_CIDFont();
     38   ~CPDF_CIDFont() override;
     39 
     40   static float CIDTransformToFloat(uint8_t ch);
     41 
     42   // CPDF_Font:
     43   bool IsCIDFont() const override;
     44   const CPDF_CIDFont* AsCIDFont() const override;
     45   CPDF_CIDFont* AsCIDFont() override;
     46   int GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) override;
     47   int GetCharWidthF(uint32_t charcode) override;
     48   FX_RECT GetCharBBox(uint32_t charcode) override;
     49   uint32_t GetNextChar(const char* pString,
     50                        int nStrLen,
     51                        int& offset) const override;
     52   int CountChar(const char* pString, int size) const override;
     53   int AppendChar(char* str, uint32_t charcode) const override;
     54   bool IsVertWriting() const override;
     55   bool IsUnicodeCompatible() const override;
     56   bool Load() override;
     57   WideString UnicodeFromCharCode(uint32_t charcode) const override;
     58   uint32_t CharCodeFromUnicode(wchar_t Unicode) const override;
     59 
     60   uint16_t CIDFromCharCode(uint32_t charcode) const;
     61   const uint8_t* GetCIDTransform(uint16_t CID) const;
     62   short GetVertWidth(uint16_t CID) const;
     63   void GetVertOrigin(uint16_t CID, short& vx, short& vy) const;
     64   int GetCharSize(uint32_t charcode) const;
     65 
     66  protected:
     67   void LoadGB2312();
     68   int GetGlyphIndex(uint32_t unicodeb, bool* pVertGlyph);
     69   int GetVerticalGlyph(int index, bool* pVertGlyph);
     70   void LoadMetricsArray(CPDF_Array* pArray,
     71                         std::vector<uint32_t>* result,
     72                         int nElements);
     73   void LoadSubstFont();
     74   wchar_t GetUnicodeFromCharCode(uint32_t charcode) const;
     75 
     76   RetainPtr<CPDF_CMap> m_pCMap;
     77   UnownedPtr<CPDF_CID2UnicodeMap> m_pCID2UnicodeMap;
     78   CIDSet m_Charset;
     79   bool m_bType1;
     80   bool m_bCIDIsGID;
     81   uint16_t m_DefaultWidth;
     82   RetainPtr<CPDF_StreamAcc> m_pStreamAcc;
     83   bool m_bAnsiWidthsFixed;
     84   FX_RECT m_CharBBox[256];
     85   std::vector<uint32_t> m_WidthList;
     86   short m_DefaultVY;
     87   short m_DefaultW1;
     88   std::vector<uint32_t> m_VertMetrics;
     89   bool m_bAdobeCourierStd;
     90   std::unique_ptr<CFX_CTTGSUBTable> m_pTTGSUBTable;
     91 };
     92 
     93 #endif  // CORE_FPDFAPI_FONT_CPDF_CIDFONT_H_
     94