diff options
author | Albert Astals Cid <aacid@kde.org> | 2020-01-05 01:20:37 +0100 |
---|---|---|
committer | Albert Astals Cid <tsdgeos@yahoo.es> | 2020-01-05 22:51:09 +0000 |
commit | c4f8555b6a8085a6a5b3c18a8a21e8aab51fe6d9 (patch) | |
tree | 8ca19b5f195be08715360bafbbcdd7570921cf35 | |
parent | 7489b99bc0e8ee22538e5c4697f43181e74044c1 (diff) |
Make getUnicodeMap param a const & instead a const *
Now you can write globalParams->getUnicodeMap("UTF-8")
which makes much more sense
-rw-r--r-- | poppler/GlobalParams.cc | 15 | ||||
-rw-r--r-- | poppler/GlobalParams.h | 6 | ||||
-rw-r--r-- | poppler/PSOutputDev.cc | 4 | ||||
-rw-r--r-- | poppler/UTF.cc | 3 | ||||
-rw-r--r-- | poppler/UnicodeMap.cc | 22 | ||||
-rw-r--r-- | poppler/UnicodeMap.h | 8 |
6 files changed, 27 insertions, 31 deletions
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc index 8b69e499..31a83e33 100644 --- a/poppler/GlobalParams.cc +++ b/poppler/GlobalParams.cc @@ -586,11 +586,11 @@ Unicode GlobalParams::mapNameToUnicodeText(const char *charName) { return nameToUnicodeText->lookup(charName); } -UnicodeMap *GlobalParams::getResidentUnicodeMap(const GooString *encodingName) { +UnicodeMap *GlobalParams::getResidentUnicodeMap(const std::string &encodingName) { UnicodeMap *map = nullptr; globalParamsLocker(); - const auto unicodeMap = residentUnicodeMaps.find(encodingName->toStr()); + const auto unicodeMap = residentUnicodeMaps.find(encodingName); if (unicodeMap != residentUnicodeMaps.end()) { map = &unicodeMap->second; } @@ -598,11 +598,11 @@ UnicodeMap *GlobalParams::getResidentUnicodeMap(const GooString *encodingName) { return map; } -FILE *GlobalParams::getUnicodeMapFile(const GooString *encodingName) { +FILE *GlobalParams::getUnicodeMapFile(const std::string &encodingName) { FILE *file = nullptr; globalParamsLocker(); - const auto unicodeMap = unicodeMaps.find(encodingName->toStr()); + const auto unicodeMap = unicodeMaps.find(encodingName); if (unicodeMap != unicodeMaps.end()) { file = openFile(unicodeMap->second.c_str(), "r"); } @@ -1135,8 +1135,7 @@ std::string GlobalParams::getTextEncodingName() const { const UnicodeMap *GlobalParams::getUtf8Map() { if (!utf8Map) { - GooString enc("UTF-8"); - utf8Map = globalParams->getUnicodeMap(&enc); + utf8Map = globalParams->getUnicodeMap("UTF-8"); } return utf8Map; @@ -1174,7 +1173,7 @@ CharCodeToUnicode *GlobalParams::getCIDToUnicode(const GooString *collection) { return ctu; } -const UnicodeMap *GlobalParams::getUnicodeMap(const GooString *encodingName) { +const UnicodeMap *GlobalParams::getUnicodeMap(const std::string &encodingName) { const UnicodeMap *map; if (!(map = getResidentUnicodeMap(encodingName))) { @@ -1191,7 +1190,7 @@ CMap *GlobalParams::getCMap(const GooString *collection, const GooString *cMapNa } const UnicodeMap *GlobalParams::getTextEncoding() { - return getUnicodeMap(textEncoding); + return getUnicodeMap(textEncoding->toStr()); } std::vector<GooString*> *GlobalParams::getEncodingNames() diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h index 3a99edf9..a5adda92 100644 --- a/poppler/GlobalParams.h +++ b/poppler/GlobalParams.h @@ -116,8 +116,8 @@ public: // lookups or text extraction with ZapfDingbats fonts. Unicode mapNameToUnicodeAll(const char *charName); - UnicodeMap *getResidentUnicodeMap(const GooString *encodingName); - FILE *getUnicodeMapFile(const GooString *encodingName); + UnicodeMap *getResidentUnicodeMap(const std::string &encodingName); + FILE *getUnicodeMapFile(const std::string &encodingName); FILE *findCMapFile(const GooString *collection, const GooString *cMapName); FILE *findToUnicodeFile(const GooString *name); GooString *findFontFile(const GooString *fontName); @@ -135,7 +135,7 @@ public: bool getErrQuiet(); CharCodeToUnicode *getCIDToUnicode(const GooString *collection); - const UnicodeMap *getUnicodeMap(const GooString *encodingName); + const UnicodeMap *getUnicodeMap(const std::string &encodingName); CMap *getCMap(const GooString *collection, const GooString *cMapName, Stream *stream = nullptr); const UnicodeMap *getTextEncoding(); diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 0a5e20d1..42c68171 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -2046,7 +2046,7 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) { sizeof(PSFont16Enc)); } font16Enc[font16EncLen].fontID = *font->getID(); - if ((uMap = globalParams->getUnicodeMap(fontLoc->encoding))) { + if ((uMap = globalParams->getUnicodeMap(fontLoc->encoding->toStr()))) { font16Enc[font16EncLen].enc = fontLoc->encoding->copy(); } else { error(errSyntaxError, -1, @@ -5099,7 +5099,7 @@ void PSOutputDev::drawString(GfxState *state, const GooString *s) { // font substitution failed, so don't output any text return; } - uMap = globalParams->getUnicodeMap(font16Enc[i].enc); + uMap = globalParams->getUnicodeMap(font16Enc[i].enc->toStr()); break; } } diff --git a/poppler/UTF.cc b/poppler/UTF.cc index cb2e6775..b5790640 100644 --- a/poppler/UTF.cc +++ b/poppler/UTF.cc @@ -423,8 +423,7 @@ char *utf16ToUtf8(const uint16_t *utf16, int *len) void unicodeToAscii7(const Unicode *in, int len, Unicode **ucs4_out, int *out_len, const int *in_idx, int **indices) { - GooString enc("ASCII7"); - const UnicodeMap *uMap = globalParams->getUnicodeMap(&enc); + const UnicodeMap *uMap = globalParams->getUnicodeMap("ASCII7"); int *idx = nullptr; if (!len) { diff --git a/poppler/UnicodeMap.cc b/poppler/UnicodeMap.cc index 8a3080e7..03d7e9d2 100644 --- a/poppler/UnicodeMap.cc +++ b/poppler/UnicodeMap.cc @@ -50,7 +50,7 @@ struct UnicodeMapExt { //------------------------------------------------------------------------ -UnicodeMap *UnicodeMap::parse(const GooString *encodingNameA) { +UnicodeMap *UnicodeMap::parse(const std::string &encodingNameA) { FILE *f; UnicodeMap *map; UnicodeMapRange *range; @@ -63,12 +63,12 @@ UnicodeMap *UnicodeMap::parse(const GooString *encodingNameA) { if (!(f = globalParams->getUnicodeMapFile(encodingNameA))) { error(errSyntaxError, -1, - "Couldn't find unicodeMap file for the '{0:t}' encoding", - encodingNameA); + "Couldn't find unicodeMap file for the '{0:s}' encoding", + encodingNameA.c_str()); return nullptr; } - map = new UnicodeMap(encodingNameA->toStr()); + map = new UnicodeMap(encodingNameA); size = 8; UnicodeMapRange *customRanges = (UnicodeMapRange *)gmallocn(size, sizeof(UnicodeMapRange)); @@ -112,13 +112,13 @@ UnicodeMap *UnicodeMap::parse(const GooString *encodingNameA) { ++map->eMapsLen; } else { error(errSyntaxError, -1, - "Bad line ({0:d}) in unicodeMap file for the '{1:t}' encoding", - line, encodingNameA); + "Bad line ({0:d}) in unicodeMap file for the '{1:s}' encoding", + line, encodingNameA.c_str()); } } else { error(errSyntaxError, -1, - "Bad line ({0:d}) in unicodeMap file for the '{1:t}' encoding", - line, encodingNameA); + "Bad line ({0:d}) in unicodeMap file for the '{1:s}' encoding", + line, encodingNameA.c_str()); } ++line; } @@ -241,8 +241,8 @@ void UnicodeMap::swap(UnicodeMap &other) noexcept swap(eMapsLen, other.eMapsLen); } -bool UnicodeMap::match(const GooString *encodingNameA) const { - return encodingName == encodingNameA->toStr(); +bool UnicodeMap::match(const std::string &encodingNameA) const { + return encodingName == encodingNameA; } int UnicodeMap::mapUnicode(Unicode u, char *buf, int bufSize) const { @@ -303,7 +303,7 @@ UnicodeMapCache::~UnicodeMapCache() { } } -const UnicodeMap *UnicodeMapCache::getUnicodeMap(const GooString *encodingName) { +const UnicodeMap *UnicodeMapCache::getUnicodeMap(const std::string &encodingName) { for (UnicodeMap *map : cache) { if (map->match(encodingName)) { return map; diff --git a/poppler/UnicodeMap.h b/poppler/UnicodeMap.h index 2de5a4ce..c9bc7aeb 100644 --- a/poppler/UnicodeMap.h +++ b/poppler/UnicodeMap.h @@ -35,8 +35,6 @@ #include <string> #include <vector> -class GooString; - //------------------------------------------------------------------------ enum UnicodeMapKind { @@ -61,7 +59,7 @@ public: // Create the UnicodeMap specified by <encodingName>. Sets the // initial reference count to 1. Returns NULL on failure. - static UnicodeMap *parse(const GooString *encodingNameA); + static UnicodeMap *parse(const std::string &encodingNameA); // Create a resident UnicodeMap. UnicodeMap(const char *encodingNameA, bool unicodeOutA, @@ -88,7 +86,7 @@ public: // Return true if this UnicodeMap matches the specified // <encodingNameA>. - bool match(const GooString *encodingNameA) const; + bool match(const std::string &encodingNameA) const; // Map Unicode to the target encoding. Fills in <buf> with the // output and returns the number of bytes used. Output will be @@ -124,7 +122,7 @@ public: UnicodeMapCache& operator=(const UnicodeMapCache &) = delete; // Get the UnicodeMap for <encodingName>. Returns NULL on failure. - const UnicodeMap *getUnicodeMap(const GooString *encodingName); + const UnicodeMap *getUnicodeMap(const std::string &encodingName); private: |