1 // Copyright 2016 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_FONTENCODING_H_
8 #define CORE_FPDFAPI_FONT_CPDF_FONTENCODING_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/cfx_string_pool_template.h"
13 #include "core/fxcrt/cfx_weak_ptr.h"
14 #include "core/fxcrt/fx_string.h"
15 
16 #define PDFFONT_ENCODING_BUILTIN 0
17 #define PDFFONT_ENCODING_WINANSI 1
18 #define PDFFONT_ENCODING_MACROMAN 2
19 #define PDFFONT_ENCODING_MACEXPERT 3
20 #define PDFFONT_ENCODING_STANDARD 4
21 #define PDFFONT_ENCODING_ADOBE_SYMBOL 5
22 #define PDFFONT_ENCODING_ZAPFDINGBATS 6
23 #define PDFFONT_ENCODING_PDFDOC 7
24 #define PDFFONT_ENCODING_MS_SYMBOL 8
25 #define PDFFONT_ENCODING_UNICODE 9
26 
27 uint32_t FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode);
28 FX_WCHAR FT_UnicodeFromCharCode(int encoding, uint32_t charcode);
29 
30 FX_WCHAR PDF_UnicodeFromAdobeName(const FX_CHAR* name);
31 CFX_ByteString PDF_AdobeNameFromUnicode(FX_WCHAR unicode);
32 
33 const uint16_t* PDF_UnicodesForPredefinedCharSet(int encoding);
34 const FX_CHAR* PDF_CharNameFromPredefinedCharSet(int encoding,
35                                                  uint8_t charcode);
36 
37 class CPDF_Object;
38 
39 class CPDF_FontEncoding {
40  public:
41   CPDF_FontEncoding();
42   explicit CPDF_FontEncoding(int PredefinedEncoding);
43 
44   void LoadEncoding(CPDF_Object* pEncoding);
45 
46   bool IsIdentical(CPDF_FontEncoding* pAnother) const;
47 
UnicodeFromCharCode(uint8_t charcode)48   FX_WCHAR UnicodeFromCharCode(uint8_t charcode) const {
49     return m_Unicodes[charcode];
50   }
51   int CharCodeFromUnicode(FX_WCHAR unicode) const;
52 
SetUnicode(uint8_t charcode,FX_WCHAR unicode)53   void SetUnicode(uint8_t charcode, FX_WCHAR unicode) {
54     m_Unicodes[charcode] = unicode;
55   }
56 
57   std::unique_ptr<CPDF_Object> Realize(CFX_WeakPtr<CFX_ByteStringPool> pPool);
58 
59  public:
60   FX_WCHAR m_Unicodes[256];
61 };
62 
63 #endif  // CORE_FPDFAPI_FONT_CPDF_FONTENCODING_H_
64