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