Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:53

0001 //========================================================================
0002 //
0003 // UnicodeMap.h
0004 //
0005 // Mapping from Unicode to an encoding.
0006 //
0007 // Copyright 2001-2003 Glyph & Cog, LLC
0008 //
0009 //========================================================================
0010 
0011 //========================================================================
0012 //
0013 // Modified under the Poppler project - http://poppler.freedesktop.org
0014 //
0015 // All changes made under the Poppler project to this file are licensed
0016 // under GPL version 2 or later
0017 //
0018 // Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
0019 // Copyright (C) 2018-2022 Albert Astals Cid <aacid@kde.org>
0020 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
0021 // Copyright (C) 2019 Volker Krause <vkrause@kde.org>
0022 //
0023 // To see a description of the changes please see the Changelog file that
0024 // came with your tarball or type make ChangeLog if you are building from git
0025 //
0026 //========================================================================
0027 
0028 #ifndef UNICODEMAP_H
0029 #define UNICODEMAP_H
0030 
0031 #include "poppler-config.h"
0032 #include "poppler_private_export.h"
0033 #include "CharTypes.h"
0034 
0035 #include <atomic>
0036 #include <memory>
0037 #include <string>
0038 #include <vector>
0039 
0040 //------------------------------------------------------------------------
0041 
0042 enum UnicodeMapKind
0043 {
0044     unicodeMapUser, // read from a file
0045     unicodeMapResident, // static list of ranges
0046     unicodeMapFunc // function pointer
0047 };
0048 
0049 typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
0050 
0051 struct UnicodeMapRange
0052 {
0053     Unicode start, end; // range of Unicode chars
0054     unsigned int code, nBytes; // first output code
0055 };
0056 
0057 struct UnicodeMapExt;
0058 
0059 //------------------------------------------------------------------------
0060 
0061 class POPPLER_PRIVATE_EXPORT UnicodeMap
0062 {
0063 public:
0064     // Create the UnicodeMap specified by <encodingName>.  Sets the
0065     // initial reference count to 1.  Returns NULL on failure.
0066     static std::unique_ptr<UnicodeMap> parse(const std::string &encodingNameA);
0067 
0068     // Create a resident UnicodeMap.
0069     UnicodeMap(const char *encodingNameA, bool unicodeOutA, const UnicodeMapRange *rangesA, int lenA);
0070 
0071     // Create a resident UnicodeMap that uses a function instead of a
0072     // list of ranges.
0073     UnicodeMap(const char *encodingNameA, bool unicodeOutA, UnicodeMapFunc funcA);
0074 
0075     UnicodeMap(UnicodeMap &&other) noexcept;
0076     UnicodeMap &operator=(UnicodeMap &&other) noexcept;
0077 
0078     void swap(UnicodeMap &other) noexcept;
0079 
0080     ~UnicodeMap();
0081 
0082     UnicodeMap(const UnicodeMap &) = delete;
0083     UnicodeMap &operator=(const UnicodeMap &) = delete;
0084 
0085     std::string getEncodingName() const { return encodingName; }
0086 
0087     bool isUnicode() const { return unicodeOut; }
0088 
0089     // Return true if this UnicodeMap matches the specified
0090     // <encodingNameA>.
0091     bool match(const std::string &encodingNameA) const;
0092 
0093     // Map Unicode to the target encoding.  Fills in <buf> with the
0094     // output and returns the number of bytes used.  Output will be
0095     // truncated at <bufSize> bytes.  No string terminator is written.
0096     // Returns 0 if no mapping is found.
0097     int mapUnicode(Unicode u, char *buf, int bufSize) const;
0098 
0099 private:
0100     explicit UnicodeMap(const std::string &encodingNameA);
0101 
0102     std::string encodingName;
0103     UnicodeMapKind kind;
0104     bool unicodeOut;
0105     union {
0106         const UnicodeMapRange *ranges; // (user, resident)
0107         UnicodeMapFunc func; // (func)
0108     };
0109     int len; // (user, resident)
0110     UnicodeMapExt *eMaps; // (user)
0111     int eMapsLen; // (user)
0112 };
0113 
0114 //------------------------------------------------------------------------
0115 
0116 class UnicodeMapCache
0117 {
0118 public:
0119     UnicodeMapCache();
0120 
0121     // Get the UnicodeMap for <encodingName>.  Returns NULL on failure.
0122     const UnicodeMap *getUnicodeMap(const std::string &encodingName);
0123 
0124 private:
0125     std::vector<std::unique_ptr<UnicodeMap>> cache;
0126 };
0127 
0128 #endif