• 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 #include "third_party/base/span.h"
15 
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 final : 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 
IsLoaded()53   bool IsLoaded() const { return m_bLoaded; }
IsVertWriting()54   bool IsVertWriting() const { return m_bVertical; }
55 
56   uint16_t CIDFromCharCode(uint32_t charcode) const;
57 
58   int GetCharSize(uint32_t charcode) const;
59   uint32_t GetNextChar(ByteStringView pString, size_t* pOffset) const;
60   size_t CountChar(ByteStringView pString) const;
61   int AppendChar(char* str, uint32_t charcode) const;
62 
SetVertical(bool vert)63   void SetVertical(bool vert) { m_bVertical = vert; }
SetCodingScheme(CodingScheme scheme)64   void SetCodingScheme(CodingScheme scheme) { m_CodingScheme = scheme; }
65   void SetAdditionalMappings(std::vector<CIDRange> mappings);
66   void SetMixedFourByteLeadingRanges(std::vector<CodeRange> ranges);
67 
GetCoding()68   int GetCoding() const { return m_Coding; }
GetEmbedMap()69   const FXCMAP_CMap* GetEmbedMap() const { return m_pEmbedMap.Get(); }
GetCharset()70   CIDSet GetCharset() const { return m_Charset; }
SetCharset(CIDSet set)71   void SetCharset(CIDSet set) { m_Charset = set; }
72 
SetDirectCharcodeToCIDTable(size_t idx,uint16_t val)73   void SetDirectCharcodeToCIDTable(size_t idx, uint16_t val) {
74     m_DirectCharcodeToCIDTable[idx] = val;
75   }
IsDirectCharcodeToCIDTableIsEmpty()76   bool IsDirectCharcodeToCIDTableIsEmpty() const {
77     return m_DirectCharcodeToCIDTable.empty();
78   }
79 
80  private:
81   explicit CPDF_CMap(ByteStringView bsPredefinedName);
82   explicit CPDF_CMap(pdfium::span<const uint8_t> spEmbeddedData);
83   ~CPDF_CMap() override;
84 
85   bool m_bLoaded = false;
86   bool m_bVertical = false;
87   CIDSet m_Charset = CIDSET_UNKNOWN;
88   CodingScheme m_CodingScheme = TwoBytes;
89   int m_Coding = CIDCODING_UNKNOWN;
90   std::vector<bool> m_MixedTwoByteLeadingBytes;
91   std::vector<CodeRange> m_MixedFourByteLeadingRanges;
92   std::vector<uint16_t> m_DirectCharcodeToCIDTable;
93   std::vector<CIDRange> m_AdditionalCharcodeToCIDMappings;
94   UnownedPtr<const FXCMAP_CMap> m_pEmbedMap;
95 };
96 
97 #endif  // CORE_FPDFAPI_FONT_CPDF_CMAP_H_
98