• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_CMAP_H_
8 #define CORE_FPDFAPI_FONT_CPDF_CMAP_H_
9 
10 #include <vector>
11 
12 #include "core/fpdfapi/font/cpdf_cidfont.h"
13 #include "core/fxcrt/retain_ptr.h"
14 
15 class CPDF_CMapManager;
16 struct FXCMAP_CMap;
17 
18 enum CIDCoding : uint8_t {
19   CIDCODING_UNKNOWN = 0,
20   CIDCODING_GB,
21   CIDCODING_BIG5,
22   CIDCODING_JIS,
23   CIDCODING_KOREA,
24   CIDCODING_UCS2,
25   CIDCODING_CID,
26   CIDCODING_UTF16,
27 };
28 
29 class CPDF_CMap : public Retainable {
30  public:
31   enum CodingScheme : uint8_t {
32     OneByte,
33     TwoBytes,
34     MixedTwoBytes,
35     MixedFourBytes
36   };
37 
38   struct CodeRange {
39     size_t m_CharSize;
40     uint8_t m_Lower[4];
41     uint8_t m_Upper[4];
42   };
43 
44   struct CIDRange {
45     uint32_t m_StartCode;
46     uint32_t m_EndCode;
47     uint16_t m_StartCID;
48   };
49 
50   template <typename T, typename... Args>
51   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
52 
53   void LoadPredefined(CPDF_CMapManager* pMgr,
54                       const ByteString& name,
55                       bool bPromptCJK);
56   void LoadEmbedded(const uint8_t* pData, uint32_t dwSize);
57 
IsLoaded()58   bool IsLoaded() const { return m_bLoaded; }
IsVertWriting()59   bool IsVertWriting() const { return m_bVertical; }
60 
61   uint16_t CIDFromCharCode(uint32_t charcode) const;
62 
63   int GetCharSize(uint32_t charcode) const;
64   uint32_t GetNextChar(const char* pString, int nStrLen, int& offset) const;
65   int CountChar(const char* pString, int size) const;
66   int AppendChar(char* str, uint32_t charcode) const;
67 
SetVertical(bool vert)68   void SetVertical(bool vert) { m_bVertical = vert; }
SetCodingScheme(CodingScheme scheme)69   void SetCodingScheme(CodingScheme scheme) { m_CodingScheme = scheme; }
SetMixedFourByteLeadingRanges(std::vector<CodeRange> range)70   void SetMixedFourByteLeadingRanges(std::vector<CodeRange> range) {
71     m_MixedFourByteLeadingRanges = range;
72   }
73 
GetCoding()74   int GetCoding() const { return m_Coding; }
GetEmbedMap()75   const FXCMAP_CMap* GetEmbedMap() const { return m_pEmbedMap; }
GetCharset()76   CIDSet GetCharset() const { return m_Charset; }
SetCharset(CIDSet set)77   void SetCharset(CIDSet set) { m_Charset = set; }
78 
SetDirectCharcodeToCIDTable(size_t idx,uint16_t val)79   void SetDirectCharcodeToCIDTable(size_t idx, uint16_t val) {
80     m_DirectCharcodeToCIDTable[idx] = val;
81   }
IsDirectCharcodeToCIDTableIsEmpty()82   bool IsDirectCharcodeToCIDTableIsEmpty() const {
83     return m_DirectCharcodeToCIDTable.empty();
84   }
85 
86  private:
87   CPDF_CMap();
88   ~CPDF_CMap() override;
89 
90   ByteString m_PredefinedCMap;
91   bool m_bLoaded;
92   bool m_bVertical;
93   CIDSet m_Charset;
94   CodingScheme m_CodingScheme;
95   int m_Coding;
96   std::vector<bool> m_MixedTwoByteLeadingBytes;
97   std::vector<CodeRange> m_MixedFourByteLeadingRanges;
98   std::vector<uint16_t> m_DirectCharcodeToCIDTable;
99   std::vector<CIDRange> m_AdditionalCharcodeToCIDMappings;
100   const FXCMAP_CMap* m_pEmbedMap;
101 };
102 
103 #endif  // CORE_FPDFAPI_FONT_CPDF_CMAP_H_
104