summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Sander <oliver.sander@tu-dresden.de>2021-12-31 11:32:20 +0100
committerAlbert Astals Cid <tsdgeos@yahoo.es>2022-01-05 13:45:07 +0000
commit9451ca15dc63b908786e93f86f84862b11fc45dd (patch)
tree5f1c995b5c1fedfc6d3647cf0d26468ab9726c09
parentf5e53b3c81b7adf41457436dd924fc849b14ddd6 (diff)
Store 'path' as std::string in GfxFontLoc
...instead of as GooString*. This avoids some heap allocations. To simplify interaction with the rest of the code, the GfxFontLoc class gets two new methods 'setPath' and 'pathAsGooString'. These methods are intended to be temporary. Avoiding them now would mean having to change too much calling code.
-rwxr-xr-xpoppler/CairoFontEngine.cc5
-rw-r--r--poppler/GfxFont.cc36
-rw-r--r--poppler/GfxFont.h13
-rw-r--r--poppler/PSOutputDev.cc8
-rw-r--r--poppler/SplashOutputDev.cc6
-rw-r--r--qt5/src/QPainterOutputDev.cc12
-rw-r--r--qt6/src/QPainterOutputDev.cc12
7 files changed, 50 insertions, 42 deletions
diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index e4885443..b9a1ad60 100755
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -342,7 +342,6 @@ CairoFreeTypeFont::~CairoFreeTypeFont() { }
CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Library lib, bool useCIDs)
{
- GooString *fileName;
const char *fileNameC;
char *font_data;
int font_data_len;
@@ -364,7 +363,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
codeToGIDLen = 0;
font_data = nullptr;
font_data_len = 0;
- fileName = nullptr;
+ const GooString *fileName = nullptr;
fileNameC = nullptr;
bool substitute = false;
@@ -385,7 +384,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
// external font
} else { // gfxFontLocExternal
- fileName = fontLoc->path;
+ fileName = fontLoc->pathAsGooString();
fontType = fontLoc->fontType;
substitute = true;
}
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 5155a9c9..3abde7a4 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -172,16 +172,21 @@ static int readFromStream(void *data)
GfxFontLoc::GfxFontLoc()
{
- path = nullptr;
fontNum = 0;
substIdx = -1;
}
-GfxFontLoc::~GfxFontLoc()
+GfxFontLoc::~GfxFontLoc() = default;
+
+void GfxFontLoc::setPath(GooString *pathA)
{
- if (path) {
- delete path;
- }
+ path = pathA->toStr();
+ delete pathA;
+}
+
+const GooString *GfxFontLoc::pathAsGooString() const
+{
+ return (const GooString *)(&path);
}
//------------------------------------------------------------------------
@@ -618,7 +623,7 @@ GfxFontLoc *GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
{
GfxFontLoc *fontLoc;
SysFontType sysFontType;
- GooString *path, *base14Name, *substName;
+ GooString *path, *base14Name;
int substIdx, fontNum;
bool embed;
@@ -674,7 +679,7 @@ GfxFontLoc *GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
fontLoc = new GfxFontLoc();
fontLoc->locType = gfxFontLocResident;
fontLoc->fontType = fontType1;
- fontLoc->path = name->copy();
+ fontLoc->setPath(name->copy());
return fontLoc;
}
@@ -683,7 +688,7 @@ GfxFontLoc *GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
fontLoc = new GfxFontLoc();
fontLoc->locType = gfxFontLocResident;
fontLoc->fontType = fontType1;
- fontLoc->path = new GooString(((Gfx8BitFont *)this)->base14->base14Name);
+ fontLoc->path = ((Gfx8BitFont *)this)->base14->base14Name;
return fontLoc;
}
@@ -713,7 +718,7 @@ GfxFontLoc *GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
fontLoc = new GfxFontLoc();
fontLoc->locType = gfxFontLocExternal;
fontLoc->fontType = fontCIDType2;
- fontLoc->path = path;
+ fontLoc->setPath(path);
fontLoc->fontNum = fontNum;
return fontLoc;
}
@@ -722,13 +727,13 @@ GfxFontLoc *GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
fontLoc = new GfxFontLoc();
fontLoc->locType = gfxFontLocExternal;
fontLoc->fontType = fontTrueType;
- fontLoc->path = path;
+ fontLoc->setPath(path);
return fontLoc;
} else if (sysFontType == sysFontPFA || sysFontType == sysFontPFB) {
fontLoc = new GfxFontLoc();
fontLoc->locType = gfxFontLocExternal;
fontLoc->fontType = fontType1;
- fontLoc->path = path;
+ fontLoc->setPath(path);
fontLoc->fontNum = fontNum;
return fontLoc;
}
@@ -752,18 +757,17 @@ GfxFontLoc *GfxFont::locateFont(XRef *xref, PSOutputDev *ps)
if (isItalic()) {
substIdx += 1;
}
- substName = new GooString(base14SubstFonts[substIdx]);
+ GooString substName(base14SubstFonts[substIdx]);
if (ps) {
error(errSyntaxWarning, -1, "Substituting font '{0:s}' for '{1:s}'", base14SubstFonts[substIdx], name ? name->c_str() : "null");
fontLoc = new GfxFontLoc();
fontLoc->locType = gfxFontLocResident;
fontLoc->fontType = fontType1;
- fontLoc->path = substName;
+ fontLoc->path = substName.toStr();
fontLoc->substIdx = substIdx;
return fontLoc;
} else {
- path = globalParams->findFontFile(substName);
- delete substName;
+ path = globalParams->findFontFile(&substName);
if (path) {
if ((fontLoc = getExternalFont(path, false))) {
error(errSyntaxWarning, -1, "Substituting font '{0:s}' for '{1:s}'", base14SubstFonts[substIdx], name ? name->c_str() : "");
@@ -834,7 +838,7 @@ GfxFontLoc *GfxFont::getExternalFont(GooString *path, bool cid)
fontLoc = new GfxFontLoc();
fontLoc->locType = gfxFontLocExternal;
fontLoc->fontType = fontType;
- fontLoc->path = path;
+ fontLoc->setPath(path);
return fontLoc;
}
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index f9263a59..0510acb1 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -121,14 +121,19 @@ public:
GfxFontLoc(const GfxFontLoc &) = delete;
GfxFontLoc &operator=(const GfxFontLoc &) = delete;
+ // Set the 'path' string from a GooString on the heap.
+ // Ownership of the object is taken.
+ void setPath(GooString *pathA);
+ const GooString *pathAsGooString() const;
+
GfxFontLocType locType;
GfxFontType fontType;
Ref embFontID; // embedded stream obj ID
// (if locType == gfxFontLocEmbedded)
- GooString *path; // font file path
- // (if locType == gfxFontLocExternal)
- // PS font name
- // (if locType == gfxFontLocResident)
+ std::string path; // font file path
+ // (if locType == gfxFontLocExternal)
+ // PS font name
+ // (if locType == gfxFontLocResident)
int fontNum; // for TrueType collections
// (if locType == gfxFontLocExternal)
int substIdx; // substitute font index
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 6c58daa3..743a223e 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -2031,25 +2031,25 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict)
//~ this won't work -- the PS font name won't match
psName = makePSFontName(font, font->getID());
}
- setupExternalType1Font(fontLoc->path, psName);
+ setupExternalType1Font(fontLoc->pathAsGooString(), psName);
break;
case fontTrueType:
case fontTrueTypeOT:
psName = makePSFontName(font, font->getID());
- setupExternalTrueTypeFont(font, fontLoc->path, psName);
+ setupExternalTrueTypeFont(font, fontLoc->pathAsGooString(), psName);
break;
case fontCIDType2:
case fontCIDType2OT:
psName = makePSFontName(font, font->getID());
//~ should check to see if font actually uses vertical mode
- setupExternalCIDTrueTypeFont(font, fontLoc->path, psName, true);
+ setupExternalCIDTrueTypeFont(font, fontLoc->pathAsGooString(), psName, true);
break;
default:
break;
}
break;
case gfxFontLocResident:
- psName = fontLoc->path->copy();
+ psName = new GooString(fontLoc->path);
break;
}
}
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index 02c6bd34..cbfb209d 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -1830,7 +1830,6 @@ void SplashOutputDev::doUpdateFont(GfxState *state)
SplashFontFile *fontFile;
SplashFontSrc *fontsrc = nullptr;
FoFiTrueType *ff;
- GooString *fileName;
char *tmpBuf;
int tmpBufLen;
const double *textMat;
@@ -1842,7 +1841,6 @@ void SplashOutputDev::doUpdateFont(GfxState *state)
needFontUpdate = false;
font = nullptr;
- fileName = nullptr;
tmpBuf = nullptr;
fontLoc = nullptr;
@@ -1882,6 +1880,8 @@ reload:
}
// embedded font
+ const GooString *fileName = nullptr;
+
if (fontLoc->locType == gfxFontLocEmbedded) {
// if there is an embedded font, read it to memory
tmpBuf = gfxFont->readEmbFontFile((xref) ? xref : doc->getXRef(), &tmpBufLen);
@@ -1890,7 +1890,7 @@ reload:
// external font
} else { // gfxFontLocExternal
- fileName = fontLoc->path;
+ fileName = fontLoc->pathAsGooString();
fontType = fontLoc->fontType;
doAdjustFontMatrix = true;
}
diff --git a/qt5/src/QPainterOutputDev.cc b/qt5/src/QPainterOutputDev.cc
index f67e65fc..ab7ac045 100644
--- a/qt5/src/QPainterOutputDev.cc
+++ b/qt5/src/QPainterOutputDev.cc
@@ -473,7 +473,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
break;
}
case gfxFontLocExternal: { // font is in an external font file
- QString fontFile(fontLoc->path->c_str());
+ QString fontFile(fontLoc->path.c_str());
m_rawFont = new QRawFont(fontFile, fontSize, m_hintingPreference);
m_rawFontCache.insert(std::make_pair(fontID, std::unique_ptr<QRawFont>(m_rawFont)));
break;
@@ -554,7 +554,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
FT_Face freeTypeFace;
if (fontLoc->locType != gfxFontLocEmbedded) {
- if (FT_New_Face(m_ftLibrary, fontLoc->path->c_str(), faceIndex, &freeTypeFace)) {
+ if (FT_New_Face(m_ftLibrary, fontLoc->path.c_str(), faceIndex, &freeTypeFace)) {
error(errSyntaxError, -1, "Couldn't create a FreeType face for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)");
return;
}
@@ -589,7 +589,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
}
case fontTrueType:
case fontTrueTypeOT: {
- auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path->c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
+ auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
m_codeToGIDCache[id] = (ff) ? ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff.get()) : nullptr;
@@ -602,7 +602,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
// check for a CFF font
if (!m_useCIDs) {
- auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path->c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(tmpBuf.get(), tmpBufLen));
+ auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(tmpBuf.get(), tmpBufLen));
cidToGIDMap = (ff) ? ff->getCIDToGIDMap(&nCIDs) : nullptr;
}
@@ -624,7 +624,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
int nCIDs = 0;
if (!codeToGID && !m_useCIDs) {
- auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path->c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
+ auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
if (ff && ff->isOpenTypeCFF()) {
cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
@@ -646,7 +646,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(), codeToGIDLen * sizeof(int));
}
} else {
- auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path->c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
+ auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
if (!ff) {
return;
}
diff --git a/qt6/src/QPainterOutputDev.cc b/qt6/src/QPainterOutputDev.cc
index f67e65fc..ab7ac045 100644
--- a/qt6/src/QPainterOutputDev.cc
+++ b/qt6/src/QPainterOutputDev.cc
@@ -473,7 +473,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
break;
}
case gfxFontLocExternal: { // font is in an external font file
- QString fontFile(fontLoc->path->c_str());
+ QString fontFile(fontLoc->path.c_str());
m_rawFont = new QRawFont(fontFile, fontSize, m_hintingPreference);
m_rawFontCache.insert(std::make_pair(fontID, std::unique_ptr<QRawFont>(m_rawFont)));
break;
@@ -554,7 +554,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
FT_Face freeTypeFace;
if (fontLoc->locType != gfxFontLocEmbedded) {
- if (FT_New_Face(m_ftLibrary, fontLoc->path->c_str(), faceIndex, &freeTypeFace)) {
+ if (FT_New_Face(m_ftLibrary, fontLoc->path.c_str(), faceIndex, &freeTypeFace)) {
error(errSyntaxError, -1, "Couldn't create a FreeType face for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)");
return;
}
@@ -589,7 +589,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
}
case fontTrueType:
case fontTrueTypeOT: {
- auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path->c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
+ auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
m_codeToGIDCache[id] = (ff) ? ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff.get()) : nullptr;
@@ -602,7 +602,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
// check for a CFF font
if (!m_useCIDs) {
- auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path->c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(tmpBuf.get(), tmpBufLen));
+ auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(tmpBuf.get(), tmpBufLen));
cidToGIDMap = (ff) ? ff->getCIDToGIDMap(&nCIDs) : nullptr;
}
@@ -624,7 +624,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
int nCIDs = 0;
if (!codeToGID && !m_useCIDs) {
- auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path->c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
+ auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
if (ff && ff->isOpenTypeCFF()) {
cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
@@ -646,7 +646,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(), codeToGIDLen * sizeof(int));
}
} else {
- auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path->c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
+ auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiTrueType>(FoFiTrueType::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiTrueType>(FoFiTrueType::make(tmpBuf.get(), tmpBufLen));
if (!ff) {
return;
}