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_TOUNICODEMAP_H_ 8 #define CORE_FPDFAPI_FONT_CPDF_TOUNICODEMAP_H_ 9 10 #include <map> 11 #include <set> 12 #include <vector> 13 14 #include "core/fxcrt/fx_string.h" 15 #include "core/fxcrt/retain_ptr.h" 16 #include "core/fxcrt/unowned_ptr.h" 17 #include "third_party/abseil-cpp/absl/types/optional.h" 18 19 class CPDF_CID2UnicodeMap; 20 class CPDF_SimpleParser; 21 class CPDF_Stream; 22 23 class CPDF_ToUnicodeMap { 24 public: 25 explicit CPDF_ToUnicodeMap(RetainPtr<const CPDF_Stream> pStream); 26 ~CPDF_ToUnicodeMap(); 27 28 WideString Lookup(uint32_t charcode) const; 29 uint32_t ReverseLookup(wchar_t unicode) const; 30 31 size_t GetUnicodeCountByCharcodeForTesting(uint32_t charcode) const; 32 33 private: 34 friend class cpdf_tounicodemap_StringToCode_Test; 35 friend class cpdf_tounicodemap_StringToWideString_Test; 36 37 static absl::optional<uint32_t> StringToCode(ByteStringView input); 38 static WideString StringToWideString(ByteStringView str); 39 40 void Load(RetainPtr<const CPDF_Stream> pStream); 41 void HandleBeginBFChar(CPDF_SimpleParser* pParser); 42 void HandleBeginBFRange(CPDF_SimpleParser* pParser); 43 uint32_t GetMultiCharIndexIndicator() const; 44 void SetCode(uint32_t srccode, WideString destcode); 45 46 // Inserts a new entry which hasn't not been inserted into `m_Multimap` 47 // before. 48 void InsertIntoMultimap(uint32_t code, uint32_t destcode); 49 50 std::map<uint32_t, std::set<uint32_t>> m_Multimap; 51 UnownedPtr<const CPDF_CID2UnicodeMap> m_pBaseMap; 52 std::vector<WideString> m_MultiCharVec; 53 }; 54 55 #endif // CORE_FPDFAPI_FONT_CPDF_TOUNICODEMAP_H_ 56