[poppler] cpp/poppler-page.cpp cpp/poppler-page.h cpp/tests
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Mar 31 21:38:26 UTC 2020
cpp/poppler-page.cpp | 25 ++++++++++++-------------
cpp/poppler-page.h | 3 ++-
cpp/tests/poppler-dump.cpp | 4 +++-
3 files changed, 17 insertions(+), 15 deletions(-)
New commits:
commit 1e098e9b272d57478a3f23a9a6b6bb1542740aaf
Author: Jiri Jakes <freedesktop at jirijakes.eu>
Date: Tue Mar 31 21:38:23 2020 +0000
cpp: Add non_raw_non_physical layout for page::text()
diff --git a/cpp/poppler-page.cpp b/cpp/poppler-page.cpp
index f9cba3e5..d9533cfe 100644
--- a/cpp/poppler-page.cpp
+++ b/cpp/poppler-page.cpp
@@ -262,6 +262,10 @@ ustring page::text(const rectf &r) const
return text(r, physical_layout);
}
+static void appendToGooString(void *stream, const char *text, int len) {
+ ((GooString *) stream)->append(text, len);
+}
+
/**
Returns the text in the page.
@@ -275,22 +279,17 @@ ustring page::text(const rectf &r) const
*/
ustring page::text(const rectf &r, text_layout_enum layout_mode) const
{
- std::unique_ptr<GooString> s;
- const bool use_raw_order = (layout_mode == raw_order_layout);
- TextOutputDev td(nullptr, false, 0, use_raw_order, false);
- d->doc->doc->displayPage(&td, d->index + 1, 72, 72, 0, false, true, false);
+ std::unique_ptr<GooString> out(new GooString());
+ const bool use_raw_order = (layout_mode == raw_order_layout);
+ const bool use_physical_layout = (layout_mode == physical_layout);
+ TextOutputDev td(&appendToGooString, out.get(), use_physical_layout, 0, use_raw_order, false);
if (r.is_empty()) {
- 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));
+ d->doc->doc->displayPage(&td, d->index + 1, 72, 72, 0, false, true, false);
} else {
- s.reset(td.getText(r.left(), r.top(), r.right(), r.bottom()));
+ d->doc->doc->displayPageSlice(&td, d->index + 1, 72, 72, 0, false, true, false,
+ r.left(), r.top(), r.width(), r.height());
}
- return ustring::from_utf8(s->c_str());
+ return ustring::from_utf8(out->c_str());
}
/*
diff --git a/cpp/poppler-page.h b/cpp/poppler-page.h
index bd7f1fcf..28cfaa95 100644
--- a/cpp/poppler-page.h
+++ b/cpp/poppler-page.h
@@ -91,7 +91,8 @@ public:
};
enum text_layout_enum {
physical_layout,
- raw_order_layout
+ raw_order_layout,
+ non_raw_non_physical_layout
};
~page();
diff --git a/cpp/tests/poppler-dump.cpp b/cpp/tests/poppler-dump.cpp
index 857bb6cc..470327ef 100644
--- a/cpp/tests/poppler-dump.cpp
+++ b/cpp/tests/poppler-dump.cpp
@@ -81,7 +81,7 @@ static const ArgDesc the_args[] = {
{ "--show-destinations", argFlag, &show_destinations, 0,
"show named destinations" },
{ "--show-text", argString, &show_text, sizeof(show_text),
- "show text (physical|raw) extracted from all pages" },
+ "show text (physical|raw|none) extracted from all pages" },
{ "--show-text-list", argFlag, &show_text_list, 0,
"show text list (experimental)" },
{ "-h", argFlag, &show_help, 0,
@@ -451,6 +451,8 @@ int main(int argc, char *argv[])
show_text_layout = poppler::page::physical_layout;
} else if (!memcmp(show_text, "raw", 4)) {
show_text_layout = poppler::page::raw_order_layout;
+ } else if (!memcmp(show_text, "none", 5)) {
+ show_text_layout = poppler::page::non_raw_non_physical_layout;
} else {
error(std::string("unrecognized text mode: '") + show_text + "'");
}
More information about the poppler
mailing list