//======================================================================== // // CharCodeToUnicode.h // // Mapping from character codes to Unicode. // // Copyright 2001-2003 Glyph & Cog, LLC // //======================================================================== //======================================================================== // // Modified under the Poppler project - http://poppler.freedesktop.org // // All changes made under the Poppler project to this file are licensed // under GPL version 2 or later // // Copyright (C) 2007 Julien Rebetez // Copyright (C) 2007 Koji Otani // Copyright (C) 2008, 2011, 2012, 2018, 2019, 2021, 2022, 2024-2026 Albert Astals Cid // Copyright (C) 2017 Adrian Johnson // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, . Work sponsored by the LiMux project of the city of Munich // Copyright (C) 2018 Adam Reichold // Copyright (C) 2019 // Copyright (C) 2024, 2025 g10 Code GmbH, Author: Sune Stolborg Vuorela // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git // //======================================================================== #ifndef CHARCODETOUNICODE_H #define CHARCODETOUNICODE_H #include #include #include #include #include #include "CharTypes.h" //------------------------------------------------------------------------ class CharCodeToUnicode { friend class UnicodeToCharCode; struct PrivateTag { }; struct CharCodeToUnicodeString { CharCode c; std::vector u; }; public: // Create an identity mapping (Unicode = CharCode). static std::unique_ptr makeIdentityMapping(); // Read the CID-to-Unicode mapping for from the file // specified by . Sets the initial reference count to 1. // Returns NULL on failure. static std::unique_ptr parseCIDToUnicode(const char *fileName, const std::string &collection); // Create the CharCode-to-Unicode mapping for an 8-bit font. // is an array of 256 Unicode indexes. Sets the initial // reference count to 1. static std::unique_ptr make8BitToUnicode(Unicode *toUnicode); // Parse a ToUnicode CMap for an 8- or 16-bit font. static std::unique_ptr parseCMap(const std::string &buf, int nBits); static std::unique_ptr parseCMapFromFile(const std::string &fileName, int nBits); // Parse a ToUnicode CMap for an 8- or 16-bit font, merging it into // . void mergeCMap(const std::string &buf, int nBits); ~CharCodeToUnicode() = default; CharCodeToUnicode(const CharCodeToUnicode &) = delete; CharCodeToUnicode &operator=(const CharCodeToUnicode &) = delete; // Return true if this mapping matches the specified . bool match(const std::string &tagA); // Set the mapping for . void setMapping(CharCode c, Unicode *u, int len); // Map a CharCode to Unicode. Returns a pointer in u to internal storage // so never store the pointers it returns, just the data, otherwise // your pointed values might get changed by future calls int mapToUnicode(CharCode c, Unicode const **u) const; // Map a Unicode to CharCode. int mapToCharCode(const Unicode *u, CharCode *c, int usize) const; explicit CharCodeToUnicode(PrivateTag t = {}); explicit CharCodeToUnicode(const std::optional &tagA, PrivateTag t = {}); CharCodeToUnicode(const std::optional &tagA, std::vector &&mapA, std::vector &&sMapA, PrivateTag t = {}); private: bool parseCMap1(int (*getCharFunc)(void *), void *data, int nBits); void addMapping(CharCode code, char *uStr, int n, int offset); void addMappingInt(CharCode code, Unicode u); const std::optional tag; std::vector map; std::vector sMap; bool isIdentity; }; //------------------------------------------------------------------------ class CharCodeToUnicodeCache { public: explicit CharCodeToUnicodeCache(int sizeA); ~CharCodeToUnicodeCache(); CharCodeToUnicodeCache(const CharCodeToUnicodeCache &) = delete; CharCodeToUnicodeCache &operator=(const CharCodeToUnicodeCache &) = delete; // Get the CharCodeToUnicode object for . // Returns NULL on failure. std::shared_ptr getCharCodeToUnicode(const std::string &tag); // Insert into the cache, in the most-recently-used position. void add(std::shared_ptr ctu); private: size_t size; std::deque> cache; }; #endif