[poppler] cpp/poppler-page.cpp cpp/tests
Albert Astals Cid
aacid at kemper.freedesktop.org
Wed Aug 9 12:26:53 UTC 2017
Rebased ref, commits from common ancestor:
commit d7b800933e1b57c180247708991f5c3a282f8305
Author: Jason Alan Palmer <jalanpalmer at gmail.com>
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..97a4dbb0 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, Jason Alan Palmer <jalanpalmer at gmail.com>
*
* 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..f9c8b6e4 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, Jason Alan Palmer <jalanpalmer at gmail.com>
*
* 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