• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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 <stdint.h>
11 
12 #include <memory>
13 #include <vector>
14 
15 #include "core/fpdfapi/font/cpdf_font.h"
16 #include "core/fxcrt/fx_coordinates.h"
17 #include "core/fxcrt/fx_string.h"
18 #include "core/fxcrt/retain_ptr.h"
19 #include "core/fxcrt/unowned_ptr.h"
20 
21 enum CIDSet : uint8_t {
22   CIDSET_UNKNOWN,
23   CIDSET_GB1,
24   CIDSET_CNS1,
25   CIDSET_JAPAN1,
26   CIDSET_KOREA1,
27   CIDSET_UNICODE,
28   CIDSET_NUM_SETS
29 };
30 
31 class CFX_CTTGSUBTable;
32 class CPDF_CID2UnicodeMap;
33 class CPDF_CMap;
34 class CPDF_StreamAcc;
35 
36 class CPDF_CIDFont final : public CPDF_Font {
37  public:
38   CONSTRUCT_VIA_MAKE_RETAIN;
39   ~CPDF_CIDFont() override;
40 
41   static float CIDTransformToFloat(uint8_t ch);
42 
43   // CPDF_Font:
44   bool IsCIDFont() const override;
45   const CPDF_CIDFont* AsCIDFont() const override;
46   CPDF_CIDFont* AsCIDFont() override;
47   int GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) override;
48   int GetCharWidthF(uint32_t charcode) override;
49   FX_RECT GetCharBBox(uint32_t charcode) override;
50   uint32_t GetNextChar(ByteStringView pString, size_t* pOffset) const override;
51   size_t CountChar(ByteStringView pString) const override;
52   int AppendChar(char* str, uint32_t charcode) const override;
53   bool IsVertWriting() const override;
54   bool IsUnicodeCompatible() const override;
55   bool Load() override;
56   WideString UnicodeFromCharCode(uint32_t charcode) const override;
57   uint32_t CharCodeFromUnicode(wchar_t Unicode) const override;
58 
59   uint16_t CIDFromCharCode(uint32_t charcode) const;
60   const uint8_t* GetCIDTransform(uint16_t cid) const;
61   int16_t GetVertWidth(uint16_t cid) const;
62   CFX_Point16 GetVertOrigin(uint16_t cid) const;
63   int GetCharSize(uint32_t charcode) const;
64 
65  private:
66   enum class CIDFontType : bool {
67     kType1,    // CIDFontType0
68     kTrueType  // CIDFontType2
69   };
70 
71   CPDF_CIDFont(CPDF_Document* pDocument, RetainPtr<CPDF_Dictionary> pFontDict);
72 
73   void LoadGB2312();
74   int GetGlyphIndex(uint32_t unicodeb, bool* pVertGlyph);
75   int GetVerticalGlyph(int index, bool* pVertGlyph);
76   void LoadSubstFont();
77   wchar_t GetUnicodeFromCharCode(uint32_t charcode) const;
78 
79   RetainPtr<const CPDF_CMap> m_pCMap;
80   UnownedPtr<const CPDF_CID2UnicodeMap> m_pCID2UnicodeMap;
81   RetainPtr<CPDF_StreamAcc> m_pStreamAcc;
82   std::unique_ptr<CFX_CTTGSUBTable> m_pTTGSUBTable;
83   CIDFontType m_FontType = CIDFontType::kTrueType;
84   bool m_bCIDIsGID = false;
85   bool m_bAnsiWidthsFixed = false;
86   bool m_bAdobeCourierStd = false;
87   CIDSet m_Charset = CIDSET_UNKNOWN;
88   int16_t m_DefaultWidth = 1000;
89   int16_t m_DefaultVY = 880;
90   int16_t m_DefaultW1 = -1000;
91   std::vector<int> m_WidthList;
92   std::vector<int> m_VertMetrics;
93   FX_RECT m_CharBBox[256];
94 };
95 
96 #endif  // CORE_FPDFAPI_FONT_CPDF_CIDFONT_H_
97