[poppler] poppler/PSOutputDev.cc poppler/PSOutputDev.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Apr 3 21:22:46 UTC 2023
poppler/PSOutputDev.cc | 41 +++++++++++++++++------------------------
poppler/PSOutputDev.h | 2 +-
2 files changed, 18 insertions(+), 25 deletions(-)
New commits:
commit 8354c73ea0516a9d4a4bdf68da5c5392498b286d
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date: Sun Apr 2 14:38:53 2023 +0200
Make filterPSName return std::string
Rather than a pointer to GooString. This saves one memory allocation.
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 23e3dcf0..80212e37 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -2772,32 +2772,27 @@ void PSOutputDev::setupType3Font(GfxFont *font, GooString *psName, Dict *parentR
// font object, and an object ID (font file object for
GooString *PSOutputDev::makePSFontName(GfxFont *font, const Ref *id)
{
- GooString *psName;
const GooString *s;
if ((s = font->getEmbeddedFontName())) {
- psName = filterPSName(s->toStr());
- if (fontNames.emplace(psName->toStr()).second) {
- return psName;
+ std::string psName = filterPSName(s->toStr());
+ if (fontNames.emplace(psName).second) {
+ return new GooString(std::move(psName));
}
- delete psName;
}
if (font->getName()) {
- psName = filterPSName(*font->getName());
- if (fontNames.emplace(psName->toStr()).second) {
- return psName;
+ std::string psName = filterPSName(*font->getName());
+ if (fontNames.emplace(psName).second) {
+ return new GooString(std::move(psName));
}
- delete psName;
}
- psName = GooString::format("FF{0:d}_{1:d}", id->num, id->gen).release();
+ GooString *psName = GooString::format("FF{0:d}_{1:d}", id->num, id->gen).release();
if ((s = font->getEmbeddedFontName())) {
- s = filterPSName(s->toStr());
- psName->append('_')->append(s);
- delete s;
+ std::string filteredName = filterPSName(s->toStr());
+ psName->append('_')->append(filteredName);
} else if (font->getName()) {
- s = filterPSName(*font->getName());
- psName->append('_')->append(s);
- delete s;
+ std::string filteredName = filterPSName(*font->getName());
+ psName->append('_')->append(filteredName);
}
fontNames.emplace(psName->toStr());
return psName;
@@ -7415,27 +7410,25 @@ void PSOutputDev::writePSName(const char *s)
}
}
-GooString *PSOutputDev::filterPSName(const std::string &name)
+std::string PSOutputDev::filterPSName(const std::string &name)
{
- GooString *name2;
- char buf[8];
-
- name2 = new GooString();
+ std::string name2;
// ghostscript chokes on names that begin with out-of-limits
// numbers, e.g., 1e4foo is handled correctly (as a name), but
// 1e999foo generates a limitcheck error
const char c0 = name[0];
if (c0 >= '0' && c0 <= '9') {
- name2->append('f');
+ name2 += 'f';
}
for (const char c : name) {
if (c <= (char)0x20 || c >= (char)0x7f || c == '(' || c == ')' || c == '<' || c == '>' || c == '[' || c == ']' || c == '{' || c == '}' || c == '/' || c == '%') {
+ char buf[8];
sprintf(buf, "#%02x", c & 0xff);
- name2->append(buf);
+ name2.append(buf);
} else {
- name2->append(c);
+ name2 += c;
}
}
return name2;
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index dad0a384..1b6257c9 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -401,7 +401,7 @@ private:
void opiTransform(GfxState *state, double x0, double y0, double *x1, double *y1);
#endif
void cvtFunction(const Function *func, bool invertPSFunction = false);
- GooString *filterPSName(const std::string &name);
+ static std::string filterPSName(const std::string &name);
// Write the document-level setup.
void writeDocSetup(Catalog *catalog, const std::vector<int> &pageList, bool duplexA);
More information about the poppler
mailing list