Commit 1e098e9b authored by Jiri Jakes's avatar Jiri Jakes Committed by Albert Astals Cid

cpp: Add non_raw_non_physical layout for page::text()

parent 1ff36d64
......@@ -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());
}
/*
......
......@@ -91,7 +91,8 @@ public:
};
enum text_layout_enum {
physical_layout,
raw_order_layout
raw_order_layout,
non_raw_non_physical_layout
};
~page();
......
......@@ -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 + "'");
}
......
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