• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FONTENCODING_H_
8 #define CORE_FPDFAPI_FONT_CPDF_FONTENCODING_H_
9 
10 #include <array>
11 
12 #include "core/fxcrt/bytestring.h"
13 #include "core/fxcrt/retain_ptr.h"
14 #include "core/fxcrt/span.h"
15 #include "core/fxcrt/string_pool_template.h"
16 #include "core/fxcrt/weak_ptr.h"
17 #include "core/fxge/fx_fontencoding.h"
18 
19 enum class FontEncoding {
20   kBuiltin = 0,
21   kWinAnsi = 1,
22   kMacRoman = 2,
23   kMacExpert = 3,
24   kStandard = 4,
25   kAdobeSymbol = 5,
26   kZapfDingbats = 6,
27   kPdfDoc = 7,
28   kMsSymbol = 8,
29 };
30 
31 uint32_t CharCodeFromUnicodeForEncoding(fxge::FontEncoding encoding,
32                                         wchar_t unicode);
33 
34 wchar_t UnicodeFromAppleRomanCharCode(uint8_t charcode);
35 
36 pdfium::span<const uint16_t> UnicodesForPredefinedCharSet(
37     FontEncoding encoding);
38 const char* CharNameFromPredefinedCharSet(FontEncoding encoding,
39                                           uint8_t charcode);
40 
41 class CPDF_Object;
42 
43 class CPDF_FontEncoding {
44  public:
45   static constexpr size_t kEncodingTableSize = 256;
46 
47   explicit CPDF_FontEncoding(FontEncoding predefined_encoding);
48 
49   bool IsIdentical(const CPDF_FontEncoding* pAnother) const;
50 
UnicodeFromCharCode(uint8_t charcode)51   wchar_t UnicodeFromCharCode(uint8_t charcode) const {
52     return m_Unicodes[charcode];
53   }
54   int CharCodeFromUnicode(wchar_t unicode) const;
55 
SetUnicode(uint8_t charcode,wchar_t unicode)56   void SetUnicode(uint8_t charcode, wchar_t unicode) {
57     m_Unicodes[charcode] = unicode;
58   }
59 
60   RetainPtr<CPDF_Object> Realize(WeakPtr<ByteStringPool> pPool) const;
61 
62  private:
63   std::array<wchar_t, kEncodingTableSize> m_Unicodes = {};
64 };
65 
66 #endif  // CORE_FPDFAPI_FONT_CPDF_FONTENCODING_H_
67