Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //========================================================================
0002 //
0003 // CharCodeToUnicode.h
0004 //
0005 // Mapping from character codes to Unicode.
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) 2007 Julien Rebetez <julienr@svn.gnome.org>
0019 // Copyright (C) 2007 Koji Otani <sho@bbr.jp>
0020 // Copyright (C) 2008, 2011, 2012, 2018, 2019, 2021, 2022 Albert Astals Cid <aacid@kde.org>
0021 // Copyright (C) 2017 Adrian Johnson <ajohnson@redneon.com>
0022 // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
0023 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
0024 // Copyright (C) 2019 <corentinf@free.fr>
0025 //
0026 // To see a description of the changes please see the Changelog file that
0027 // came with your tarball or type make ChangeLog if you are building from git
0028 //
0029 //========================================================================
0030 
0031 #ifndef CHARCODETOUNICODE_H
0032 #define CHARCODETOUNICODE_H
0033 
0034 #include <atomic>
0035 #include <optional>
0036 
0037 #include "poppler-config.h"
0038 #include "CharTypes.h"
0039 
0040 struct CharCodeToUnicodeString;
0041 class GooString;
0042 
0043 //------------------------------------------------------------------------
0044 
0045 class CharCodeToUnicode
0046 {
0047     friend class UnicodeToCharCode;
0048 
0049 public:
0050     // Create an identity mapping (Unicode = CharCode).
0051     static CharCodeToUnicode *makeIdentityMapping();
0052 
0053     // Read the CID-to-Unicode mapping for <collection> from the file
0054     // specified by <fileName>.  Sets the initial reference count to 1.
0055     // Returns NULL on failure.
0056     static CharCodeToUnicode *parseCIDToUnicode(const char *fileName, const GooString *collection);
0057 
0058     // Create a Unicode-to-Unicode mapping from the file specified by
0059     // <fileName>.  Sets the initial reference count to 1.  Returns NULL
0060     // on failure.
0061     static CharCodeToUnicode *parseUnicodeToUnicode(const GooString *fileName);
0062 
0063     // Create the CharCode-to-Unicode mapping for an 8-bit font.
0064     // <toUnicode> is an array of 256 Unicode indexes.  Sets the initial
0065     // reference count to 1.
0066     static CharCodeToUnicode *make8BitToUnicode(Unicode *toUnicode);
0067 
0068     // Parse a ToUnicode CMap for an 8- or 16-bit font.
0069     static CharCodeToUnicode *parseCMap(const GooString *buf, int nBits);
0070     static CharCodeToUnicode *parseCMapFromFile(const GooString *fileName, int nBits);
0071 
0072     // Parse a ToUnicode CMap for an 8- or 16-bit font, merging it into
0073     // <this>.
0074     void mergeCMap(const GooString *buf, int nBits);
0075 
0076     ~CharCodeToUnicode();
0077 
0078     CharCodeToUnicode(const CharCodeToUnicode &) = delete;
0079     CharCodeToUnicode &operator=(const CharCodeToUnicode &) = delete;
0080 
0081     void incRefCnt();
0082     void decRefCnt();
0083 
0084     // Return true if this mapping matches the specified <tagA>.
0085     bool match(const GooString *tagA);
0086 
0087     // Set the mapping for <c>.
0088     void setMapping(CharCode c, Unicode *u, int len);
0089 
0090     // Map a CharCode to Unicode. Returns a pointer in u to internal storage
0091     // so never store the pointers it returns, just the data, otherwise
0092     // your pointed values might get changed by future calls
0093     int mapToUnicode(CharCode c, Unicode const **u) const;
0094 
0095     // Map a Unicode to CharCode.
0096     int mapToCharCode(const Unicode *u, CharCode *c, int usize) const;
0097 
0098     // Return the mapping's length, i.e., one more than the max char
0099     // code supported by the mapping.
0100     CharCode getLength() const { return mapLen; }
0101 
0102 private:
0103     bool parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
0104     void addMapping(CharCode code, char *uStr, int n, int offset);
0105     void addMappingInt(CharCode code, Unicode u);
0106     CharCodeToUnicode();
0107     explicit CharCodeToUnicode(const std::optional<std::string> &tagA);
0108     CharCodeToUnicode(const std::optional<std::string> &tagA, Unicode *mapA, CharCode mapLenA, bool copyMap, CharCodeToUnicodeString *sMapA, int sMapLenA, int sMapSizeA);
0109 
0110     const std::optional<std::string> tag;
0111     Unicode *map;
0112     CharCode mapLen;
0113     CharCodeToUnicodeString *sMap;
0114     int sMapLen, sMapSize;
0115     std::atomic_int refCnt;
0116     bool isIdentity;
0117 };
0118 
0119 //------------------------------------------------------------------------
0120 
0121 class CharCodeToUnicodeCache
0122 {
0123 public:
0124     explicit CharCodeToUnicodeCache(int sizeA);
0125     ~CharCodeToUnicodeCache();
0126 
0127     CharCodeToUnicodeCache(const CharCodeToUnicodeCache &) = delete;
0128     CharCodeToUnicodeCache &operator=(const CharCodeToUnicodeCache &) = delete;
0129 
0130     // Get the CharCodeToUnicode object for <tag>.  Increments its
0131     // reference count; there will be one reference for the cache plus
0132     // one for the caller of this function.  Returns NULL on failure.
0133     CharCodeToUnicode *getCharCodeToUnicode(const GooString *tag);
0134 
0135     // Insert <ctu> into the cache, in the most-recently-used position.
0136     void add(CharCodeToUnicode *ctu);
0137 
0138 private:
0139     CharCodeToUnicode **cache;
0140     int size;
0141 };
0142 
0143 #endif