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_coordinates.h"
15 #include "core/fxcrt/fx_string.h"
16 #include "core/fxcrt/fx_system.h"
17 #include "core/fxcrt/retain_ptr.h"
18 #include "core/fxcrt/unowned_ptr.h"
19 
20 enum CIDSet : uint8_t {
21   CIDSET_UNKNOWN,
22   CIDSET_GB1,
23   CIDSET_CNS1,
24   CIDSET_JAPAN1,
25   CIDSET_KOREA1,
26   CIDSET_UNICODE,
27   CIDSET_NUM_SETS
28 };
29 
30 class CFX_CTTGSUBTable;
31 class CPDF_Array;
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   CPDF_CIDFont(CPDF_Document* pDocument, CPDF_Dictionary* pFontDict);
67 
68   void LoadGB2312();
69   int GetGlyphIndex(uint32_t unicodeb, bool* pVertGlyph);
70   int GetVerticalGlyph(int index, bool* pVertGlyph);
71   void LoadSubstFont();
72   wchar_t GetUnicodeFromCharCode(uint32_t charcode) const;
73 
74   RetainPtr<const CPDF_CMap> m_pCMap;
75   UnownedPtr<const CPDF_CID2UnicodeMap> m_pCID2UnicodeMap;
76   RetainPtr<CPDF_StreamAcc> m_pStreamAcc;
77   std::unique_ptr<CFX_CTTGSUBTable> m_pTTGSUBTable;
78   bool m_bType1 = false;
79   bool m_bCIDIsGID = false;
80   bool m_bAnsiWidthsFixed = false;
81   bool m_bAdobeCourierStd = false;
82   CIDSet m_Charset = CIDSET_UNKNOWN;
83   int16_t m_DefaultWidth = 1000;
84   int16_t m_DefaultVY = 880;
85   int16_t m_DefaultW1 = -1000;
86   std::vector<int> m_WidthList;
87   std::vector<int> m_VertMetrics;
88   FX_RECT m_CharBBox[256];
89 };
90 
91 #endif  // CORE_FPDFAPI_FONT_CPDF_CIDFONT_H_
92