• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_CMAP_H_
8 #define CORE_FPDFAPI_FONT_CPDF_CMAP_H_
9 
10 #include <stdint.h>
11 
12 #include <vector>
13 
14 #include "core/fpdfapi/font/cpdf_cidfont.h"
15 #include "core/fxcrt/fixed_zeroed_data_vector.h"
16 #include "core/fxcrt/retain_ptr.h"
17 #include "core/fxcrt/unowned_ptr.h"
18 #include "third_party/base/span.h"
19 
20 namespace fxcmap {
21 struct CMap;
22 }
23 
24 enum class CIDCoding : uint8_t {
25   kUNKNOWN = 0,
26   kGB,
27   kBIG5,
28   kJIS,
29   kKOREA,
30   kUCS2,
31   kCID,
32   kUTF16,
33 };
34 
35 class CPDF_CMap final : public Retainable {
36  public:
37   static constexpr size_t kDirectMapTableSize = 65536;
38 
39   enum CodingScheme : uint8_t {
40     OneByte,
41     TwoBytes,
42     MixedTwoBytes,
43     MixedFourBytes
44   };
45 
46   struct CodeRange {
47     size_t m_CharSize;
48     uint8_t m_Lower[4];
49     uint8_t m_Upper[4];
50   };
51 
52   struct CIDRange {
53     uint32_t m_StartCode;
54     uint32_t m_EndCode;
55     uint16_t m_StartCID;
56   };
57 
58   CONSTRUCT_VIA_MAKE_RETAIN;
59 
IsLoaded()60   bool IsLoaded() const { return m_bLoaded; }
IsVertWriting()61   bool IsVertWriting() const { return m_bVertical; }
62 
63   uint16_t CIDFromCharCode(uint32_t charcode) const;
64 
65   int GetCharSize(uint32_t charcode) const;
66   uint32_t GetNextChar(ByteStringView pString, size_t* pOffset) const;
67   size_t CountChar(ByteStringView pString) const;
68   int AppendChar(char* str, uint32_t charcode) const;
69 
SetVertical(bool vert)70   void SetVertical(bool vert) { m_bVertical = vert; }
SetCodingScheme(CodingScheme scheme)71   void SetCodingScheme(CodingScheme scheme) { m_CodingScheme = scheme; }
72   void SetAdditionalMappings(std::vector<CIDRange> mappings);
73   void SetMixedFourByteLeadingRanges(std::vector<CodeRange> ranges);
74 
GetCoding()75   CIDCoding GetCoding() const { return m_Coding; }
GetEmbedMap()76   const fxcmap::CMap* GetEmbedMap() const { return m_pEmbedMap; }
GetCharset()77   CIDSet GetCharset() const { return m_Charset; }
SetCharset(CIDSet set)78   void SetCharset(CIDSet set) { m_Charset = set; }
79 
SetDirectCharcodeToCIDTable(size_t idx,uint16_t val)80   void SetDirectCharcodeToCIDTable(size_t idx, uint16_t val) {
81     m_DirectCharcodeToCIDTable.writable_span()[idx] = val;
82   }
IsDirectCharcodeToCIDTableIsEmpty()83   bool IsDirectCharcodeToCIDTableIsEmpty() const {
84     return m_DirectCharcodeToCIDTable.empty();
85   }
86 
87  private:
88   explicit CPDF_CMap(ByteStringView bsPredefinedName);
89   explicit CPDF_CMap(pdfium::span<const uint8_t> spEmbeddedData);
90   ~CPDF_CMap() override;
91 
92   bool m_bLoaded = false;
93   bool m_bVertical = false;
94   CIDSet m_Charset = CIDSET_UNKNOWN;
95   CodingScheme m_CodingScheme = TwoBytes;
96   CIDCoding m_Coding = CIDCoding::kUNKNOWN;
97   std::vector<bool> m_MixedTwoByteLeadingBytes;
98   std::vector<CodeRange> m_MixedFourByteLeadingRanges;
99   FixedZeroedDataVector<uint16_t> m_DirectCharcodeToCIDTable;
100   std::vector<CIDRange> m_AdditionalCharcodeToCIDMappings;
101   UnownedPtr<const fxcmap::CMap> m_pEmbedMap;
102 };
103 
104 #endif  // CORE_FPDFAPI_FONT_CPDF_CMAP_H_
105