[poppler] cpp/poppler-document.cpp cpp/tests

Albert Astals Cid aacid at kemper.freedesktop.org
Wed May 10 09:22:12 UTC 2017


 cpp/poppler-document.cpp   |   13 ++++++++++++-
 cpp/tests/poppler-dump.cpp |   18 +++++++++++++-----
 2 files changed, 25 insertions(+), 6 deletions(-)

New commits:
commit 96ff78d63d2173671d07f62910b1d85c5fc509ff
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed May 10 11:20:56 2017 +0200

    cpp: Return nullptr if the page at index can't be fethed
    
    That is the same of what the glib/qt frontends do.
    
    Bug #100981

diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index 35bbfa2a..998a836d 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -25,6 +25,7 @@
 
 #include "poppler-document-private.h"
 #include "poppler-embedded-file-private.h"
+#include "poppler-page-private.h"
 #include "poppler-private.h"
 #include "poppler-toc-private.h"
 
@@ -916,7 +917,17 @@ page* document::create_page(const ustring &label) const
  */
 page* document::create_page(int index) const
 {
-    return index >= 0 && index < d->doc->getNumPages() ? new page(d, index) : 0;
+    if (index >= 0 && index < d->doc->getNumPages()) {
+        page *p = new page(d, index);
+        if (p->d->page) {
+            return p;
+        } else {
+            delete p;
+            return nullptr;
+        }
+    } else {
+        return nullptr;
+    }
 }
 
 /**
diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index 1185971b..398a5004 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -301,16 +301,24 @@ static void print_embedded_files(poppler::document *doc)
 
 static void print_page(poppler::page *p)
 {
-    std::cout << std::setw(out_width) << "Rect" << ": " << p->page_rect() << std::endl;
-    std::cout << std::setw(out_width) << "Label" << ": " << p->label() << std::endl;
-    std::cout << std::setw(out_width) << "Duration" << ": " << p->duration() << std::endl;
-    std::cout << std::setw(out_width) << "Orientation" << ": " << out_page_orientation(p->orientation()) << std::endl;
+    if (p) {
+        std::cout << std::setw(out_width) << "Rect" << ": " << p->page_rect() << std::endl;
+        std::cout << std::setw(out_width) << "Label" << ": " << p->label() << std::endl;
+        std::cout << std::setw(out_width) << "Duration" << ": " << p->duration() << std::endl;
+        std::cout << std::setw(out_width) << "Orientation" << ": " << out_page_orientation(p->orientation()) << std::endl;
+    } else {
+        std::cout << std::setw(out_width) << "Broken Page. Could not be parsed" << std::endl;
+    }
     std::cout << std::endl;
 }
 
 static void print_page_text(poppler::page *p)
 {
-    std::cout << p->text(p->page_rect(), show_text_layout) << std::endl;
+    if (p) {
+        std::cout << p->text(p->page_rect(), show_text_layout) << std::endl;
+    } else {
+        std::cout << std::setw(out_width) << "Broken Page. Could not be parsed" << std::endl;
+    }
     std::cout << std::endl;
 }
 


More information about the poppler mailing list