Commit 3e0c57ce authored by Volker Krause's avatar Volker Krause
Browse files

Consider page rotations when retrieving text in a given page rectangle

Far from perfect, but good enough to work with basic landscape files.
parent 2065178e
......@@ -92,11 +92,31 @@ QString PdfPage::textInRect(double left, double top, double right, double bottom
PopplerGlobalParams gp;
const auto page = d->m_doc->m_popplerDoc->getPage(d->m_pageNum + 1);
const auto pageRect = page->getCropBox();
double l, t, r, b;
switch (page->getRotate()) {
case 0:
l = ratio(pageRect->x1, pageRect->x2, left);
t = ratio(pageRect->y1, pageRect->y2, top);
r = ratio(pageRect->x1, pageRect->x2, right);
b = ratio(pageRect->y1, pageRect->y2, bottom);
case 90:
l = ratio(pageRect->y1, pageRect->y2, left);
t = ratio(pageRect->x1, pageRect->x2, top);
r = ratio(pageRect->y1, pageRect->y2, right);
b = ratio(pageRect->x1, pageRect->x2, bottom);
qCWarning(Log) << "Unsupported page rotation!" << page->getRotate();
return {};
TextOutputDev device(nullptr, false, 0, false, false);
d->m_doc->m_popplerDoc->displayPageSlice(&device, d->m_pageNum + 1, 72, 72, 0, false, true, false, -1, -1, -1, -1);
const auto pageRect = d->m_doc->m_popplerDoc->getPage(d->m_pageNum + 1)->getCropBox();
std::unique_ptr<GooString> s(device.getText(ratio(pageRect->x1, pageRect->x2, left), ratio(pageRect->y1, pageRect->y2, top),
ratio(pageRect->x1, pageRect->x2, right), ratio(pageRect->y1, pageRect->y2, bottom)));
std::unique_ptr<GooString> s(device.getText(l, t, r, b));
return QString::fromUtf8(s->c_str());
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment