summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Sander <oliver.sander@tu-dresden.de>2021-09-15 15:12:24 +0200
committerAlbert Astals Cid <tsdgeos@yahoo.es>2021-09-16 10:09:59 +0000
commit609992087a1e9ba85e24e76f59235b06149c7354 (patch)
tree956d1698665356c18bf0761e9e4c8d8929aafa46
parenta646ed9b0a544b87d4998a7209b340970db6a53d (diff)
Store GfxFont::encodingName by value, in a std::string
Storing by value saves various heap allocations. Using std::string instead of GooString brings the code closer to standard C++.
-rw-r--r--glib/poppler-document.cc9
-rw-r--r--poppler/FontInfo.cc7
-rw-r--r--poppler/FontInfo.h6
-rw-r--r--poppler/GfxFont.cc25
-rw-r--r--poppler/GfxFont.h5
-rw-r--r--utils/pdffonts.cc4
6 files changed, 26 insertions, 30 deletions
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 25cc39b4..fd080510 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -4,7 +4,7 @@
* Copyright (C) 2016 Jakub Alba <jakubalba@gmail.com>
* Copyright (C) 2018-2019 Marek Kasik <mkasik@redhat.com>
* Copyright (C) 2019 Masamichi Hosoda <trueroad@trueroad.jp>
- * Copyright (C) 2019, Oliver Sander <oliver.sander@tu-dresden.de>
+ * Copyright (C) 2019, 2021 Oliver Sander <oliver.sander@tu-dresden.de>
* Copyright (C) 2020 Albert Astals Cid <aacid@kde.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -2712,14 +2712,13 @@ PopplerFontType poppler_fonts_iter_get_font_type(PopplerFontsIter *iter)
*/
const char *poppler_fonts_iter_get_encoding(PopplerFontsIter *iter)
{
- const GooString *encoding;
FontInfo *info;
info = iter->items[iter->index];
- encoding = info->getEncoding();
- if (encoding != nullptr) {
- return encoding->c_str();
+ const std::string &encoding = info->getEncoding();
+ if (!encoding.empty()) {
+ return encoding.c_str();
} else {
return nullptr;
}
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index c1c11204..53c9bf2d 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -14,7 +14,7 @@
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
// 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
// Copyright (C) 2018, 2019 Adam Reichold <adam.reichold@t-online.de>
-// Copyright (C) 2019 Oliver Sander <oliver.sander@tu-dresden.de>
+// Copyright (C) 2019, 2021 Oliver Sander <oliver.sander@tu-dresden.de>
//
// 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
@@ -194,7 +194,7 @@ FontInfo::FontInfo(GfxFont *font, XRef *xref)
if (substituteNameAux.getLength() > 0)
substituteName = substituteNameAux.copy();
}
- encoding = font->getEncodingName()->copy();
+ encoding = font->getEncodingName();
// look for a ToUnicode map
hasToUnicode = false;
@@ -212,7 +212,7 @@ FontInfo::FontInfo(const FontInfo &f)
{
name = f.name ? f.name->copy() : nullptr;
file = f.file ? f.file->copy() : nullptr;
- encoding = f.encoding ? f.encoding->copy() : nullptr;
+ encoding = f.encoding;
substituteName = f.substituteName ? f.substituteName->copy() : nullptr;
type = f.type;
emb = f.emb;
@@ -226,7 +226,6 @@ FontInfo::~FontInfo()
{
delete name;
delete file;
- delete encoding;
if (substituteName)
delete substituteName;
}
diff --git a/poppler/FontInfo.h b/poppler/FontInfo.h
index 50f2a6b7..a798c5d2 100644
--- a/poppler/FontInfo.h
+++ b/poppler/FontInfo.h
@@ -8,7 +8,7 @@
// Copyright (C) 2009 Pino Toscano <pino@kde.org>
// Copyright (C) 2012 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
-// Copyright (C) 2019 Oliver Sander <oliver.sander@tu-dresden.de>
+// Copyright (C) 2019, 2021 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2019 Adam Reichold <adam.reichold@t-online.de>
//
// To see a description of the changes please see the Changelog file that
@@ -66,7 +66,7 @@ public:
const GooString *getName() const { return name; };
const GooString *getSubstituteName() const { return substituteName; };
const GooString *getFile() const { return file; };
- const GooString *getEncoding() const { return encoding; };
+ const std::string &getEncoding() const { return encoding; };
Type getType() const { return type; };
bool getEmbedded() const { return emb; };
bool getSubset() const { return subset; };
@@ -78,7 +78,7 @@ private:
GooString *name;
GooString *substituteName;
GooString *file;
- GooString *encoding;
+ std::string encoding;
Type type;
bool emb;
bool subset;
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index ccd4366a..d3cff8aa 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -35,6 +35,7 @@
// 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
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
// Copyright (C) 2019 LE GARREC Vincent <legarrec.vincent@gmail.com>
+// Copyright (C) 2021 Oliver Sander <oliver.sander@tu-dresden.de>
//
// 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
@@ -232,7 +233,6 @@ GfxFont::GfxFont(const char *tagA, Ref idA, const GooString *nameA, GfxFontType
stretch = StretchNotDefined;
weight = WeightNotDefined;
refCnt = 1;
- encodingName = new GooString("");
hasToUnicode = false;
}
@@ -246,9 +246,6 @@ GfxFont::~GfxFont()
if (embFontName) {
delete embFontName;
}
- if (encodingName) {
- delete encodingName;
- }
}
void GfxFont::incRefCnt()
@@ -1198,19 +1195,19 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
}
if (baseEncFromFontFile) {
- encodingName->Set("Builtin");
+ encodingName = "Builtin";
} else if (baseEnc == winAnsiEncoding) {
- encodingName->Set("WinAnsi");
+ encodingName = "WinAnsi";
} else if (baseEnc == macRomanEncoding) {
- encodingName->Set("MacRoman");
+ encodingName = "MacRoman";
} else if (baseEnc == macExpertEncoding) {
- encodingName->Set("MacExpert");
+ encodingName = "MacExpert";
} else if (baseEnc == symbolEncoding) {
- encodingName->Set("Symbol");
+ encodingName = "Symbol";
} else if (baseEnc == zapfDingbatsEncoding) {
- encodingName->Set("ZapfDingbats");
+ encodingName = "ZapfDingbats";
} else {
- encodingName->Set("Standard");
+ encodingName = "Standard";
}
// copy the base encoding
@@ -1238,7 +1235,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
if (obj1.isDict()) {
Object obj2 = obj1.dictLookup("Differences");
if (obj2.isArray()) {
- encodingName->Set("Custom");
+ encodingName = "Custom";
hasEncoding = true;
int code = 0;
for (i = 0; i < obj2.arrayGetLength(); ++i) {
@@ -1830,9 +1827,9 @@ GfxCIDFont::GfxCIDFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA,
return;
}
if (cMap->getCMapName()) {
- encodingName->Set(cMap->getCMapName()->c_str());
+ encodingName = cMap->getCMapName()->toStr();
} else {
- encodingName->Set("Custom");
+ encodingName = "Custom";
}
// CIDToGIDMap (for embedded TrueType fonts)
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 16f062e9..398f4dea 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -24,6 +24,7 @@
// Copyright (C) 2015, 2018 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2015 Thomas Freitag <Thomas.Freitag@alfa.de>
// 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
+// Copyright (C) 2021 Oliver Sander <oliver.sander@tu-dresden.de>
//
// 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
@@ -291,7 +292,7 @@ public:
bool hasToUnicodeCMap() const { return hasToUnicode; }
// Return the name of the encoding
- GooString *getEncodingName() const { return encodingName; }
+ const std::string &getEncodingName() const { return encodingName; }
// Return AGLFN names of ligatures in the Standard and Expert encodings
// for use with fonts that are not compatible with the Standard 14 fonts.
@@ -326,7 +327,7 @@ protected:
int refCnt;
bool ok;
bool hasToUnicode;
- GooString *encodingName;
+ std::string encodingName;
};
//------------------------------------------------------------------------
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index 09a09d5b..3dcf5d92 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -19,7 +19,7 @@
// Copyright (C) 2012, 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2013 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
-// Copyright (C) 2019 Oliver Sander <oliver.sander@tu-dresden.de>
+// Copyright (C) 2019, 2021 Oliver Sander <oliver.sander@tu-dresden.de>
//
// 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
@@ -148,7 +148,7 @@ int main(int argc, char *argv[])
printf("name type encoding emb sub uni object ID\n");
printf("------------------------------------ ----------------- ---------------- --- --- --- ---------\n");
for (const FontInfo *font : fonts) {
- printf("%-36s %-17s %-16s %-3s %-3s %-3s", font->getName() ? font->getName()->c_str() : "[none]", fontTypeNames[font->getType()], font->getEncoding()->c_str(), font->getEmbedded() ? "yes" : "no",
+ printf("%-36s %-17s %-16s %-3s %-3s %-3s", font->getName() ? font->getName()->c_str() : "[none]", fontTypeNames[font->getType()], font->getEncoding().c_str(), font->getEmbedded() ? "yes" : "no",
font->getSubset() ? "yes" : "no", font->getToUnicode() ? "yes" : "no");
const Ref fontRef = font->getRef();
if (fontRef.gen >= 100000) {