[poppler] 2 commits - poppler/Annot.cc poppler/GlobalParams.cc poppler/GlobalParams.h poppler/GlobalParamsWin.cc utils/HtmlLinks.cc utils/HtmlLinks.h utils/HtmlOutputDev.cc utils/HtmlOutputDev.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 29 14:09:51 UTC 2021


 poppler/Annot.cc           |   14 +++++++-------
 poppler/GlobalParams.cc    |   28 +++++++++++-----------------
 poppler/GlobalParams.h     |    2 +-
 poppler/GlobalParamsWin.cc |    4 ++--
 utils/HtmlLinks.cc         |   23 ++++++++---------------
 utils/HtmlLinks.h          |   12 ++++++------
 utils/HtmlOutputDev.cc     |   34 +++++++++++++++-------------------
 utils/HtmlOutputDev.h      |   10 +++++-----
 8 files changed, 55 insertions(+), 72 deletions(-)

New commits:
commit 5b18fb371d41a6f551f04caf418d1140062c4870
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Oct 29 15:48:42 2021 +0200

    determineFallbackFont: Change parameter from GooString * to std::string

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 74ad0e7e..a175aa25 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -263,16 +263,16 @@ static const char *getFormAdditionalActionKey(Annot::FormAdditionalActionsType t
     return (type == Annot::actionFieldModified ? "K" : type == Annot::actionFormatField ? "F" : type == Annot::actionValidateField ? "V" : type == Annot::actionCalculateField ? "C" : nullptr);
 }
 
-static const char *determineFallbackFont(GooString *tok, const char *defaultFallback)
+static const char *determineFallbackFont(const std::string &tok, const char *defaultFallback)
 {
     // TODO: adjust these based on other example PDFs.
-    if (!tok->cmp("/ZaDb")) {
+    if (tok == "/ZaDb") {
         return "ZapfDingbats";
-    } else if (!tok->cmp("/Cour")) {
+    } else if (tok == "/Cour") {
         return "Courier";
-    } else if (!tok->cmp("/TiRo")) {
+    } else if (tok == "/TiRo") {
         return "TimesNewRoman";
-    } else if (!tok->cmp("/Helvetica-Bold")) {
+    } else if (tok == "/Helvetica-Bold") {
         return "Helvetica-Bold";
     }
     return defaultFallback;
@@ -4218,7 +4218,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
         if (tok->getLength() >= 1 && tok->getChar(0) == '/') {
             if (!resources || !(font = resources->lookupFont(tok->c_str() + 1))) {
                 if (xref != nullptr && resourcesDict != nullptr) {
-                    const char *fallback = determineFallbackFont(tok, defaultFallback);
+                    const char *fallback = determineFallbackFont(tok->toStr(), defaultFallback);
                     fontToFree = createAnnotDrawFont(xref, resourcesDict, tok->c_str() + 1, fallback);
                     font = fontToFree;
                 } else {
@@ -4593,7 +4593,7 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
         if (tok->getLength() >= 1 && tok->getChar(0) == '/') {
             if (!resources || !(font = resources->lookupFont(tok->c_str() + 1))) {
                 if (xref != nullptr && resourcesDict != nullptr) {
-                    const char *fallback = determineFallbackFont(tok, "Helvetica");
+                    const char *fallback = determineFallbackFont(tok->toStr(), "Helvetica");
                     fontToFree = createAnnotDrawFont(xref, resourcesDict, tok->c_str() + 1, fallback);
                     font = fontToFree;
                 } else {
commit f897e21bc6e6823ed2912d8a496469eed41ca1da
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Oct 29 15:39:39 2021 +0200

    Change some std::vector * to std::vector
    
    If we always new and always delete them, no need to have a pointer

diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 01975901..47aa85a2 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -15,7 +15,7 @@
 //
 // Copyright (C) 2005 Martin Kretzschmar <martink at gnome.org>
 // Copyright (C) 2005, 2006 Kristian Høgsberg <krh at redhat.com>
-// Copyright (C) 2005, 2007-2010, 2012, 2015, 2017-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2007-2010, 2012, 2015, 2017-2021 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2005 Jonathan Blandford <jrb at redhat.com>
 // Copyright (C) 2006, 2007 Jeff Muizelaar <jeff at infidigm.net>
 // Copyright (C) 2006 Takashi Iwai <tiwai at suse.de>
@@ -230,27 +230,23 @@ public:
     void scanWindowsFonts(GooString *winFontDir);
 #endif
 #ifdef WITH_FONTCONFIGURATION_FONTCONFIG
-    void addFcFont(SysFontInfo *si) { fonts->push_back(si); }
+    void addFcFont(SysFontInfo *si) { fonts.push_back(si); }
 #endif
 private:
 #ifdef _WIN32
     SysFontInfo *makeWindowsFont(const char *name, int fontNum, const char *path);
 #endif
 
-    std::vector<SysFontInfo *> *fonts;
+    std::vector<SysFontInfo *> fonts;
 };
 
-SysFontList::SysFontList()
-{
-    fonts = new std::vector<SysFontInfo *>();
-}
+SysFontList::SysFontList() { }
 
 SysFontList::~SysFontList()
 {
-    for (auto entry : *fonts) {
+    for (auto entry : fonts) {
         delete entry;
     }
-    delete fonts;
 }
 
 const SysFontInfo *SysFontList::find(const GooString *name, bool fixedWidth, bool exact)
@@ -334,7 +330,7 @@ const SysFontInfo *SysFontList::find(const GooString *name, bool fixedWidth, boo
 
     // search for the font
     const SysFontInfo *fi = nullptr;
-    for (const SysFontInfo *f : *fonts) {
+    for (const SysFontInfo *f : fonts) {
         fi = f;
         if (fi->match(name2, bold, italic, oblique, fixedWidth)) {
             break;
@@ -343,7 +339,7 @@ const SysFontInfo *SysFontList::find(const GooString *name, bool fixedWidth, boo
     }
     if (!fi && !exact && bold) {
         // try ignoring the bold flag
-        for (const SysFontInfo *f : *fonts) {
+        for (const SysFontInfo *f : fonts) {
             fi = f;
             if (fi->match(name2, false, italic)) {
                 break;
@@ -353,7 +349,7 @@ const SysFontInfo *SysFontList::find(const GooString *name, bool fixedWidth, boo
     }
     if (!fi && !exact && (bold || italic)) {
         // try ignoring the bold and italic flags
-        for (const SysFontInfo *f : *fonts) {
+        for (const SysFontInfo *f : fonts) {
             fi = f;
             if (fi->match(name2, false, false)) {
                 break;
@@ -387,7 +383,6 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir) : popplerDataDir(cu
 
     nameToUnicodeZapfDingbats = new NameToCharCode();
     nameToUnicodeText = new NameToCharCode();
-    toUnicodeDirs = new std::vector<GooString *>();
     sysFonts = new SysFontList();
     psExpandSmaller = false;
     psShrinkLarger = true;
@@ -473,7 +468,7 @@ void GlobalParams::scanEncodingDirs()
     dir = new GDir(dataPathBuffer, false);
     while (entry = dir->getNextEntry(), entry != nullptr) {
         addCMapDir(entry->getName(), entry->getFullPath());
-        toUnicodeDirs->push_back(entry->getFullPath()->copy());
+        toUnicodeDirs.push_back(entry->getFullPath()->copy());
         delete entry;
     }
     delete dir;
@@ -542,10 +537,9 @@ GlobalParams::~GlobalParams()
 
     delete nameToUnicodeZapfDingbats;
     delete nameToUnicodeText;
-    for (auto entry : *toUnicodeDirs) {
+    for (auto entry : toUnicodeDirs) {
         delete entry;
     }
-    delete toUnicodeDirs;
     delete sysFonts;
     delete textEncoding;
 
@@ -631,7 +625,7 @@ FILE *GlobalParams::findToUnicodeFile(const GooString *name)
     FILE *f;
 
     globalParamsLocker();
-    for (const GooString *dir : *toUnicodeDirs) {
+    for (const GooString *dir : toUnicodeDirs) {
         fileName = appendToPath(dir->copy(), name->c_str());
         f = openFile(fileName->c_str(), "r");
         delete fileName;
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index b98d33e0..44875ed1 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -170,7 +170,7 @@ private:
     std::unordered_map<std::string, std::string> unicodeMaps;
     // list of CMap dirs, indexed by collection
     std::unordered_multimap<std::string, std::string> cMapDirs;
-    std::vector<GooString *> *toUnicodeDirs; // list of ToUnicode CMap dirs
+    std::vector<GooString *> toUnicodeDirs; // list of ToUnicode CMap dirs
     bool baseFontsInitialized;
 #ifdef _WIN32
     // windows font substitutes (for CID fonts)
diff --git a/poppler/GlobalParamsWin.cc b/poppler/GlobalParamsWin.cc
index d4eb5871..0d44f736 100644
--- a/poppler/GlobalParamsWin.cc
+++ b/poppler/GlobalParamsWin.cc
@@ -9,7 +9,7 @@
    // Copyright (C) 2013, 2018, 2019 Adam Reichold <adamreichold at myopera.com>
    // Copyright (C) 2013 Dmytro Morgun <lztoad at gmail.com>
    // Copyright (C) 2017 Christoph Cullmann <cullmann at kde.org>
-   // Copyright (C) 2017, 2018, 2020 Albert Astals Cid <aacid at kde.org>
+   // Copyright (C) 2017, 2018, 2020, 2021 Albert Astals Cid <aacid at kde.org>
    // Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>. Work sponsored by the LiMux project of the city of Munich
    // Copyright (C) 2019 Christian Persch <chpe at src.gnome.org>
    // Copyright (C) 2019 Oliver Sander <oliver.sander at tu-dresden.de>
@@ -260,7 +260,7 @@ void SysFontList::scanWindowsFonts(GooString *winFontDir)
                         } else {
                             p1 = p0 + strlen(p0);
                         }
-                        fonts->push_back(makeWindowsFont(p0, fontNum, fontPath->c_str()));
+                        fonts.push_back(makeWindowsFont(p0, fontNum, fontPath->c_str()));
                         p0 = p1;
                         ++fontNum;
                     }
diff --git a/utils/HtmlLinks.cc b/utils/HtmlLinks.cc
index b505e37c..8b48499b 100644
--- a/utils/HtmlLinks.cc
+++ b/utils/HtmlLinks.cc
@@ -18,7 +18,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2008 Boris Toloknov <tlknv at yandex.ru>
-// Copyright (C) 2010 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2010, 2021 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2013 Julien Nabet <serval2412 at yahoo.fr>
 //
 // To see a description of the changes please see the Changelog file that
@@ -111,7 +111,7 @@ static GooString *EscapeSpecialChars(GooString *s)
     return tmp ? tmp : s;
 }
 
-GooString *HtmlLink::getLinkStart()
+GooString *HtmlLink::getLinkStart() const
 {
     GooString *res = new GooString("<a href=\"");
     GooString *d = xml ? EscapeSpecialChars(dest) : dest;
@@ -133,30 +133,23 @@ GooString *HtmlLink::getLinkStart()
   return tmp;
   }*/
 
-HtmlLinks::HtmlLinks()
-{
-    accu = new std::vector<HtmlLink>();
-}
+HtmlLinks::HtmlLinks() { }
 
-HtmlLinks::~HtmlLinks()
-{
-    delete accu;
-    accu = nullptr;
-}
+HtmlLinks::~HtmlLinks() { }
 
 bool HtmlLinks::inLink(double xmin, double ymin, double xmax, double ymax, int &p) const
 {
 
-    for (std::vector<HtmlLink>::iterator i = accu->begin(); i != accu->end(); ++i) {
+    for (std::vector<HtmlLink>::const_iterator i = accu.begin(); i != accu.end(); ++i) {
         if (i->inLink(xmin, ymin, xmax, ymax)) {
-            p = (i - accu->begin());
+            p = (i - accu.begin());
             return true;
         }
     }
     return false;
 }
 
-HtmlLink *HtmlLinks::getLink(int i) const
+const HtmlLink *HtmlLinks::getLink(int i) const
 {
-    return &(*accu)[i];
+    return &accu[i];
 }
diff --git a/utils/HtmlLinks.h b/utils/HtmlLinks.h
index fa4fb2a3..7bb8cc39 100644
--- a/utils/HtmlLinks.h
+++ b/utils/HtmlLinks.h
@@ -17,7 +17,7 @@
 // All changes made under the Poppler project to this file are licensed
 // under GPL version 2 or later
 //
-// Copyright (C) 2010, 2018 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2010, 2018, 2021 Albert Astals Cid <aacid at kde.org>
 //
 // 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
@@ -48,29 +48,29 @@ public:
     ~HtmlLink();
     HtmlLink &operator=(const HtmlLink &) = delete;
     bool isEqualDest(const HtmlLink &x) const;
-    GooString *getDest() { return new GooString(dest); }
+    GooString *getDest() const { return new GooString(dest); }
     double getX1() const { return Xmin; }
     double getX2() const { return Xmax; }
     double getY1() const { return Ymin; }
     double getY2() const { return Ymax; }
     bool inLink(double xmin, double ymin, double xmax, double ymax) const;
     // GooString *Link(GooString *content);
-    GooString *getLinkStart();
+    GooString *getLinkStart() const;
 };
 
 class HtmlLinks
 {
 private:
-    std::vector<HtmlLink> *accu;
+    std::vector<HtmlLink> accu;
 
 public:
     HtmlLinks();
     ~HtmlLinks();
     HtmlLinks(const HtmlLinks &) = delete;
     HtmlLinks &operator=(const HtmlLinks &) = delete;
-    void AddLink(const HtmlLink &x) { accu->push_back(x); }
+    void AddLink(const HtmlLink &x) { accu.push_back(x); }
     bool inLink(double xmin, double ymin, double xmax, double ymax, int &p) const;
-    HtmlLink *getLink(int i) const;
+    const HtmlLink *getLink(int i) const;
 };
 
 #endif
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index bd55ac7d..35d6776d 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -285,7 +285,6 @@ HtmlPage::HtmlPage(bool rawOrderA)
     yxCur1 = yxCur2 = nullptr;
     fonts = new HtmlFontAccu();
     links = new HtmlLinks();
-    imgList = new std::vector<HtmlImage *>();
     pageWidth = 0;
     pageHeight = 0;
     fontsPageMarker = 0;
@@ -299,10 +298,9 @@ HtmlPage::~HtmlPage()
     delete DocName;
     delete fonts;
     delete links;
-    for (auto entry : *imgList) {
+    for (auto entry : imgList) {
         delete entry;
     }
-    delete imgList;
 }
 
 void HtmlPage::updateFont(GfxState *state)
@@ -630,8 +628,8 @@ void HtmlPage::coalesce()
             }
 
             /* fix <i>, <b> if str1 and str2 differ and handle switch of links */
-            HtmlLink *hlink1 = str1->getLink();
-            HtmlLink *hlink2 = str2->getLink();
+            const HtmlLink *hlink1 = str1->getLink();
+            const HtmlLink *hlink2 = str2->getLink();
             bool switch_links = !hlink1 || !hlink2 || !hlink1->isEqualDest(*hlink2);
             bool finish_a = switch_links && hlink1 != nullptr;
             bool finish_italic = hfont1->isItalic() && (!hfont2->isItalic() || finish_a);
@@ -713,7 +711,7 @@ void HtmlPage::dumpAsXML(FILE *f, int page)
         delete fontCSStyle;
     }
 
-    for (auto ptr : *imgList) {
+    for (auto ptr : imgList) {
         auto img = static_cast<HtmlImage *>(ptr);
         if (!noRoundedCoordinates) {
             fprintf(f, "<image top=\"%d\" left=\"%d\" ", xoutRound(img->yMin), xoutRound(img->xMin));
@@ -725,7 +723,7 @@ void HtmlPage::dumpAsXML(FILE *f, int page)
         fprintf(f, "src=\"%s\"/>\n", img->fName->c_str());
         delete img;
     }
-    imgList->clear();
+    imgList.clear();
 
     for (HtmlString *tmp = yxStrings; tmp; tmp = tmp->yxNext) {
         if (tmp->htext) {
@@ -910,7 +908,7 @@ void HtmlPage::dump(FILE *f, int pageNum, const std::vector<std::string> &backgr
     } else {
         fprintf(f, "<a name=%d></a>", pageNum);
         // Loop over the list of image names on this page
-        for (auto ptr : *imgList) {
+        for (auto ptr : imgList) {
             auto img = static_cast<HtmlImage *>(ptr);
 
             // see printCSS() for class names
@@ -924,7 +922,7 @@ void HtmlPage::dump(FILE *f, int pageNum, const std::vector<std::string> &backgr
             fprintf(f, "<img%s src=\"%s\"/><br/>\n", styles[style_index], img->fName->c_str());
             delete img;
         }
-        imgList->clear();
+        imgList.clear();
 
         GooString *str;
         for (HtmlString *tmp = yxStrings; tmp; tmp = tmp->yxNext) {
@@ -975,7 +973,7 @@ void HtmlPage::setDocName(const char *fname)
 void HtmlPage::addImage(GooString *fname, GfxState *state)
 {
     HtmlImage *img = new HtmlImage(fname, state);
-    imgList->push_back(img);
+    imgList.push_back(img);
 }
 
 //------------------------------------------------------------------------
@@ -1073,16 +1071,15 @@ HtmlOutputDev::HtmlOutputDev(Catalog *catalogA, const char *fileName, const char
     needClose = false;
     pages = new HtmlPage(rawOrder);
 
-    glMetaVars = new std::vector<HtmlMetaVar *>();
-    glMetaVars->push_back(new HtmlMetaVar("generator", "pdftohtml 0.36"));
+    glMetaVars.push_back(new HtmlMetaVar("generator", "pdftohtml 0.36"));
     if (author)
-        glMetaVars->push_back(new HtmlMetaVar("author", author));
+        glMetaVars.push_back(new HtmlMetaVar("author", author));
     if (keywords)
-        glMetaVars->push_back(new HtmlMetaVar("keywords", keywords));
+        glMetaVars.push_back(new HtmlMetaVar("keywords", keywords));
     if (date)
-        glMetaVars->push_back(new HtmlMetaVar("date", date));
+        glMetaVars.push_back(new HtmlMetaVar("date", date));
     if (subject)
-        glMetaVars->push_back(new HtmlMetaVar("subject", subject));
+        glMetaVars.push_back(new HtmlMetaVar("subject", subject));
 
     maxPageWidth = 0;
     maxPageHeight = 0;
@@ -1170,10 +1167,9 @@ HtmlOutputDev::~HtmlOutputDev()
     delete Docname;
     delete docTitle;
 
-    for (auto entry : *glMetaVars) {
+    for (auto entry : glMetaVars) {
         delete entry;
     }
-    delete glMetaVars;
 
     if (fContentsFrame) {
         fputs("</body>\n</html>\n", fContentsFrame);
@@ -1612,7 +1608,7 @@ void HtmlOutputDev::dumpMetaVars(FILE *file)
 {
     GooString *var;
 
-    for (const HtmlMetaVar *t : *glMetaVars) {
+    for (const HtmlMetaVar *t : glMetaVars) {
         var = t->toString();
         fprintf(file, "%s\n", var->c_str());
         delete var;
diff --git a/utils/HtmlOutputDev.h b/utils/HtmlOutputDev.h
index 6159c955..c95a05f4 100644
--- a/utils/HtmlOutputDev.h
+++ b/utils/HtmlOutputDev.h
@@ -80,13 +80,13 @@ public:
 
     // Add a character to the string.
     void addChar(GfxState *state, double x, double y, double dx, double dy, Unicode u);
-    HtmlLink *getLink() { return link; }
+    const HtmlLink *getLink() const { return link; }
     const HtmlFont &getFont() const { return *fonts->Get(fontpos); }
     void endString(); // postprocessing
 
 private:
     // aender die text variable
-    HtmlLink *link;
+    const HtmlLink *link;
     double xMin, xMax; // bounding box x coordinates
     double yMin, yMax; // bounding box y coordinates
     int col; // starting column
@@ -147,7 +147,7 @@ public:
     void addImage(GooString *fname, GfxState *state);
 
     // number of images on the current page
-    int getNumImages() { return imgList->size(); }
+    int getNumImages() { return imgList.size(); }
 
     void dump(FILE *f, int pageNum, const std::vector<std::string> &backgroundImages);
 
@@ -177,7 +177,7 @@ private:
     int fontsPageMarker;
     HtmlFontAccu *fonts;
     HtmlLinks *links;
-    std::vector<HtmlImage *> *imgList;
+    std::vector<HtmlImage *> imgList;
 
     GooString *DocName;
     int pageWidth;
@@ -311,7 +311,7 @@ private:
     int maxPageHeight;
     GooString *Docname;
     GooString *docTitle;
-    std::vector<HtmlMetaVar *> *glMetaVars;
+    std::vector<HtmlMetaVar *> glMetaVars;
     Catalog *catalog;
     Page *docPage;
     std::vector<std::string> backgroundImages;


More information about the poppler mailing list