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

Albert Astals Cid aacid at kemper.freedesktop.org
Tue Aug 8 22:43:30 UTC 2017


 cpp/poppler-page.cpp       |   10 +++++++++-
 cpp/tests/poppler-dump.cpp |    3 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

New commits:
commit 09289c45b976579f5217c493f52d2a8b56870fc2
Author: Jeroen Ooms <jeroen at berkeley.edu>
Date:   Wed Aug 9 00:41:05 2017 +0200

    cpp: Fix page.text() not taking page orientation into account
    
    Bug #94517

diff --git a/cpp/poppler-page.cpp b/cpp/poppler-page.cpp
index a3f85069..68c7b30f 100644
--- a/cpp/poppler-page.cpp
+++ b/cpp/poppler-page.cpp
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
  * Copyright (C) 2017, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2017, Jeroen Ooms <jeroen at berkeley.edu>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,7 +27,9 @@
 
 #include "TextOutputDev.h"
 
+#include <algorithm>
 #include <memory>
+#include <utility>
 
 using namespace poppler;
 
@@ -270,7 +273,12 @@ ustring page::text(const rectf &r, text_layout_enum layout_mode) const
     TextOutputDev td(0, gFalse, 0, use_raw_order, gFalse);
     d->doc->doc->displayPage(&td, d->index + 1, 72, 72, 0, false, true, false);
     if (r.is_empty()) {
-        const PDFRectangle *rect = d->page->getCropBox();
+        PDFRectangle *rect = d->page->getCropBox();
+        const int rotate = d->page->getRotate();
+        if (rotate == 90 || rotate == 270) {
+            std::swap(rect->x1, rect->y1);
+            std::swap(rect->x2, rect->y2);
+        }
         s.reset(td.getText(rect->x1, rect->y1, rect->x2, rect->y2));
     } else {
         s.reset(td.getText(r.left(), r.top(), r.right(), r.bottom()));
diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index 398a5004..049d4e8f 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2009-2010, Pino Toscano <pino at kde.org>
  * Copyright (C) 2017, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2017, Jeroen Ooms <jeroen at berkeley.edu>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -315,7 +316,7 @@ static void print_page(poppler::page *p)
 static void print_page_text(poppler::page *p)
 {
     if (p) {
-        std::cout << p->text(p->page_rect(), show_text_layout) << std::endl;
+        std::cout << p->text(poppler::rectf(), show_text_layout) << std::endl;
     } else {
         std::cout << std::setw(out_width) << "Broken Page. Could not be parsed" << std::endl;
     }


More information about the poppler mailing list