From a6b2442e37cc00534bcdca7c83366a0fa0501157 Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Mon, 14 Mar 2022 10:56:27 +0100 Subject: Store font data in a std::vector This simplifies various method signatures, because the data array and its size do not have to be passed around separately, anymore. Also, using a std::vector makes tracking the ownership much easier. --- poppler/SplashOutputDev.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'poppler/SplashOutputDev.cc') diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc index 8f362b55..8ff7b9a4 100644 --- a/poppler/SplashOutputDev.cc +++ b/poppler/SplashOutputDev.cc @@ -1845,8 +1845,6 @@ void SplashOutputDev::doUpdateFont(GfxState *state) SplashOutFontFileID *id = nullptr; SplashFontFile *fontFile; SplashFontSrc *fontsrc = nullptr; - unsigned char *tmpBuf; - int tmpBufLen; const double *textMat; double m11, m12, m21, m22, fontSize; int faceIndex = 0; @@ -1856,7 +1854,6 @@ void SplashOutputDev::doUpdateFont(GfxState *state) needFontUpdate = false; font = nullptr; - tmpBuf = nullptr; GfxFont *const gfxFont = state->getFont().get(); if (!gfxFont) { @@ -1895,11 +1892,12 @@ reload: // embedded font std::string fileName; + std::vector tmpBuf; if (fontLoc->locType == gfxFontLocEmbedded) { // if there is an embedded font, read it to memory - tmpBuf = gfxFont->readEmbFontFile((xref) ? xref : doc->getXRef(), &tmpBufLen); - if (!tmpBuf) { + tmpBuf = gfxFont->readEmbFontFile((xref) ? xref : doc->getXRef()); + if (tmpBuf.empty()) { goto err2; } @@ -1914,7 +1912,7 @@ reload: if (!fileName.empty()) { fontsrc->setFile(fileName); } else { - fontsrc->setBuf(tmpBuf, tmpBufLen); + fontsrc->setBuf(std::move(tmpBuf)); } // load the font file @@ -1952,7 +1950,7 @@ reload: if (!fileName.empty()) { ff = FoFiTrueType::load(fileName.c_str()); } else { - ff = FoFiTrueType::make(tmpBuf, tmpBufLen); + ff = FoFiTrueType::make(fontsrc->buf.data(), fontsrc->buf.size()); } int *codeToGID; const int n = ff ? 256 : 0; @@ -2026,7 +2024,7 @@ reload: if (!fileName.empty()) { ff = FoFiTrueType::load(fileName.c_str()); } else { - ff = FoFiTrueType::make(tmpBuf, tmpBufLen); + ff = FoFiTrueType::make(fontsrc->buf.data(), fontsrc->buf.size()); } if (!ff) { error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)"); -- cgit v1.2.3