From 5223541c1f530706b7ceb8aaa025b571d6a51d4c Mon Sep 17 00:00:00 2001 From: Simon Chenard Date: Mon, 11 Aug 2014 16:36:35 +0200 Subject: [PATCH] working but ugly code --- CMakeLists.txt | 1 + src/HTMLRenderer/HTMLRenderer.h | 6 ++ src/HTMLRenderer/form.cc | 103 ++++++++++++++++++++++++++++++++ src/HTMLRenderer/general.cc | 4 ++ src/Param.h | 3 + src/pdf2htmlEX.cc | 3 + 6 files changed, 120 insertions(+) create mode 100644 src/HTMLRenderer/form.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f0aad4..017b43f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,7 @@ set(PDF2HTMLEX_SRC ${PDF2HTMLEX_SRC} src/HTMLRenderer/general.cc src/HTMLRenderer/image.cc src/HTMLRenderer/font.cc + src/HTMLRenderer/form.cc src/HTMLRenderer/link.cc src/HTMLRenderer/outline.cc src/HTMLRenderer/state.cc diff --git a/src/HTMLRenderer/HTMLRenderer.h b/src/HTMLRenderer/HTMLRenderer.h index 80ef25d..6335d6e 100644 --- a/src/HTMLRenderer/HTMLRenderer.h +++ b/src/HTMLRenderer/HTMLRenderer.h @@ -20,6 +20,10 @@ #include #include +// for form.cc +#include +#include + #include "pdf2htmlEX-config.h" #include "Param.h" @@ -165,6 +169,8 @@ protected: void process_outline(void); void process_outline_items(GooList * items); + void process_form(std::ostream & out); + void set_stream_flags (std::ostream & out); void dump_css(void); diff --git a/src/HTMLRenderer/form.cc b/src/HTMLRenderer/form.cc new file mode 100644 index 0000000..d2870a9 --- /dev/null +++ b/src/HTMLRenderer/form.cc @@ -0,0 +1,103 @@ +/* + * form.cc + * + * Handling Forms + * + * by Simon Chenard + * 2014.07.25 + */ + +#include +#include +#include + +#include "HTMLRenderer.h" +#include "util/namespace.h" +#include "util/misc.h" + +namespace pdf2htmlEX { + +using std::ostream; +using std::cerr; + +void HTMLRenderer::process_form(ostream & out) +{ + FormPageWidgets * widgets = cur_catalog->getPage(pageNum)->getFormWidgets(); + int num = widgets->getNumWidgets(); + std::ostringstream derp; + + for(int i = 0; i < num; i++) + { + FormWidget * w = widgets->getWidget(i); + double x1, y1, x2, y2; + int width, height, font_size; + + w->getRect(&x1, &y1, &x2, &y2); + x1 = x1 * param.zoom; + x2 = x2 * param.zoom; + y1 = y1 * param.zoom; + y2 = y2 * param.zoom; + + width = x2 - x1; + height = y2 - y1; + + if(w->getType() == formText) + { + font_size = height / 2; + + out << "" << endl; + } + + if(w->getType() == formButton) + { + out << "
X
" << endl; + + } + } + + //output, at the end, the necessary css + if(num > 0) { + //this is usable by the whole document and as such should be in dump_css + out << "" << endl; + + //this is currently page specific + out << "" << endl; + + } +} + +} diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index a7d4e4e..b614a38 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -252,6 +252,10 @@ void HTMLRenderer::endPage() { html_text_page.dump_css(f_css.fs); html_text_page.clear(); + // process form + if(param.include_forms) + process_form(*f_curpage); + // process links before the page is closed cur_doc->processLinks(this, pageNum); diff --git a/src/Param.h b/src/Param.h index b2330ed..9491d42 100644 --- a/src/Param.h +++ b/src/Param.h @@ -62,6 +62,9 @@ struct Param int tounicode; int optimize_text; + // adobe form + int include_forms; + // background image std::string bg_format; int svg_node_count_limit; diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 3d4972a..845b5bf 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -189,6 +189,9 @@ void parse_options (int argc, char **argv) .add("optimize-text", ¶m.optimize_text, 0, "try to reduce the number of HTML elements used for text") .add("correct-text-visibility", ¶m.correct_text_visibility, 0, "try to detect texts covered by other graphics and properly arrange them") + // adobe forms + .add("include-forms", ¶m.include_forms, 0, "include text fields and such") + // background image .add("bg-format", ¶m.bg_format, "png", "specify background image format") .add("svg-node-count-limit", ¶m.svg_node_count_limit, -1, "if node count in a svg background image exceeds this limit,"