[poppler] poppler/TextOutputDev.cc poppler/TextOutputDev.h qt5/src qt6/src utils/pdftotext.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 29 23:27:23 UTC 2021


 poppler/TextOutputDev.cc |    6 +++---
 poppler/TextOutputDev.h  |    4 ++--
 qt5/src/poppler-page.cc  |    7 ++-----
 qt6/src/poppler-page.cc  |    7 ++-----
 utils/pdftotext.cc       |    5 ++---
 5 files changed, 11 insertions(+), 18 deletions(-)

New commits:
commit 03f80c64305157fbebff73cd57f582086e2cafdf
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sat Oct 30 01:16:10 2021 +0200

    Make makeWordList return a unique_ptr

diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc
index c0929033..26751e63 100644
--- a/poppler/TextOutputDev.cc
+++ b/poppler/TextOutputDev.cc
@@ -5557,9 +5557,9 @@ int TextPage::dumpFragment(const Unicode *text, int len, const UnicodeMap *uMap,
 }
 
 #ifdef TEXTOUT_WORD_LIST
-TextWordList *TextPage::makeWordList(bool physLayout)
+std::unique_ptr<TextWordList> TextPage::makeWordList(bool physLayout)
 {
-    return new TextWordList(this, physLayout);
+    return std::make_unique<TextWordList>(this, physLayout);
 }
 #endif
 
@@ -5933,7 +5933,7 @@ void TextOutputDev::setMergeCombining(bool merge)
 }
 
 #ifdef TEXTOUT_WORD_LIST
-TextWordList *TextOutputDev::makeWordList()
+std::unique_ptr<TextWordList> TextOutputDev::makeWordList()
 {
     return text->makeWordList(physLayout);
 }
diff --git a/poppler/TextOutputDev.h b/poppler/TextOutputDev.h
index b564e854..0d05b948 100644
--- a/poppler/TextOutputDev.h
+++ b/poppler/TextOutputDev.h
@@ -660,7 +660,7 @@ public:
     // this->rawOrder is true), physical layout order (if <physLayout>
     // is true and this->rawOrder is false), or reading order (if both
     // flags are false).
-    TextWordList *makeWordList(bool physLayout);
+    std::unique_ptr<TextWordList> makeWordList(bool physLayout);
 #endif
 
 private:
@@ -861,7 +861,7 @@ public:
     // this->rawOrder is true), physical layout order (if
     // this->physLayout is true and this->rawOrder is false), or reading
     // order (if both flags are false).
-    TextWordList *makeWordList();
+    std::unique_ptr<TextWordList> makeWordList();
 #endif
 
     // Returns the TextPage object for the last rasterized page,
diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
index b35894cf..eedc580f 100644
--- a/qt5/src/poppler-page.cc
+++ b/qt5/src/poppler-page.cc
@@ -734,10 +734,9 @@ QList<TextBox *> Page::textList(Rotation rotate, ShouldAbortQueryFunc shouldAbor
     m_page->parentDoc->doc->displayPageSlice(&output_dev, m_page->index + 1, 72, 72, rotation, false, false, false, -1, -1, -1, -1, shouldAbortExtractionCallback ? shouldAbortExtractionInternalCallback : nullAbortCallBack, &abortHelper,
                                              nullptr, nullptr, true);
 
-    TextWordList *word_list = output_dev.makeWordList();
+    std::unique_ptr<TextWordList> word_list = output_dev.makeWordList();
 
-    if (!word_list || (shouldAbortExtractionCallback && shouldAbortExtractionCallback(closure))) {
-        delete word_list;
+    if (shouldAbortExtractionCallback && shouldAbortExtractionCallback(closure)) {
         return output_list;
     }
 
@@ -771,8 +770,6 @@ QList<TextBox *> Page::textList(Rotation rotate, ShouldAbortQueryFunc shouldAbor
         text_box->m_data->nextWord = wordBoxMap.value(word->nextWord());
     }
 
-    delete word_list;
-
     return output_list;
 }
 
diff --git a/qt6/src/poppler-page.cc b/qt6/src/poppler-page.cc
index 11a60410..afdbf692 100644
--- a/qt6/src/poppler-page.cc
+++ b/qt6/src/poppler-page.cc
@@ -705,10 +705,9 @@ std::vector<std::unique_ptr<TextBox>> Page::textList(Rotation rotate, ShouldAbor
     m_page->parentDoc->doc->displayPageSlice(&output_dev, m_page->index + 1, 72, 72, rotation, false, false, false, -1, -1, -1, -1, shouldAbortExtractionCallback ? shouldAbortExtractionInternalCallback : nullAbortCallBack, &abortHelper,
                                              nullptr, nullptr, true);
 
-    TextWordList *word_list = output_dev.makeWordList();
+    std::unique_ptr<TextWordList> word_list = output_dev.makeWordList();
 
-    if (!word_list || (shouldAbortExtractionCallback && shouldAbortExtractionCallback(closure))) {
-        delete word_list;
+    if (shouldAbortExtractionCallback && shouldAbortExtractionCallback(closure)) {
         return output_list;
     }
 
@@ -742,8 +741,6 @@ std::vector<std::unique_ptr<TextBox>> Page::textList(Rotation rotate, ShouldAbor
         text_box->m_data->nextWord = wordBoxMap.value(word->nextWord());
     }
 
-    delete word_list;
-
     return output_list;
 }
 
diff --git a/utils/pdftotext.cc b/utils/pdftotext.cc
index 71ebcc29..7b45359f 100644
--- a/utils/pdftotext.cc
+++ b/utils/pdftotext.cc
@@ -16,7 +16,7 @@
 // under GPL version 2 or later
 //
 // Copyright (C) 2006 Dominic Lachowicz <cinamod at hotmail.com>
-// Copyright (C) 2007-2008, 2010, 2011, 2017-2020 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2007-2008, 2010, 2011, 2017-2021 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2009 Jan Jockusch <jan at jockusch.de>
 // Copyright (C) 2010, 2013 Hib Eris <hib at hiberis.nl>
 // Copyright (C) 2010 Kenneth Berland <ken at hero.com>
@@ -527,7 +527,7 @@ void printWordBBox(FILE *f, PDFDoc *doc, TextOutputDev *textOut, int first, int
         double hgt = useCropBox ? doc->getPageCropHeight(page) : doc->getPageMediaHeight(page);
         fprintf(f, "  <page width=\"%f\" height=\"%f\">\n", wid, hgt);
         doc->displayPage(textOut, page, resolution, resolution, 0, !useCropBox, useCropBox, false);
-        TextWordList *wordlist = textOut->makeWordList();
+        std::unique_ptr<TextWordList> wordlist = textOut->makeWordList();
         const int word_length = wordlist != nullptr ? wordlist->getLength() : 0;
         TextWord *word;
         double xMinA, yMinA, xMaxA, yMaxA;
@@ -541,7 +541,6 @@ void printWordBBox(FILE *f, PDFDoc *doc, TextOutputDev *textOut, int first, int
             fprintf(f, "    <word xMin=\"%f\" yMin=\"%f\" xMax=\"%f\" yMax=\"%f\">%s</word>\n", xMinA, yMinA, xMaxA, yMaxA, myString.c_str());
         }
         fprintf(f, "  </page>\n");
-        delete wordlist;
     }
     fprintf(f, "</doc>\n");
 }


More information about the poppler mailing list