From 6670ea1b5743c996f2bd636c21bed4c80aec23ae Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Tue, 7 Aug 2012 09:59:10 +0800 Subject: [PATCH] moving to drawString --- CMakeLists.txt | 2 +- src/Consts.h | 79 ++++++++++++++++++++++++++++++++++++++ src/HTMLRenderer.cc | 92 +++++++++------------------------------------ src/HTMLRenderer.h | 2 +- 4 files changed, 98 insertions(+), 77 deletions(-) create mode 100644 src/Consts.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a64c7c..60e47f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb") -add_executable(pdftohtmlEX src/pdftohtmlEX.cc src/HTMLRenderer.cc src/HTMLRenderer.h src/BackgroundRenderer.cc src/BackgroundRenderer.h) +add_executable(pdftohtmlEX src/pdftohtmlEX.cc src/HTMLRenderer.cc src/HTMLRenderer.h src/BackgroundRenderer.cc src/BackgroundRenderer.h src/Consts.h) target_link_libraries(pdftohtmlEX poppler boost_program_options) diff --git a/src/Consts.h b/src/Consts.h new file mode 100644 index 0000000..7c8b677 --- /dev/null +++ b/src/Consts.h @@ -0,0 +1,79 @@ +/* + * Constants + * + * by WangLu + * 2012.08.07 + */ + +#ifndef CONSTS_H__ +#define CONSTS_H__ +#include +#include + +const char * HTML_HEAD = "\n\ +\ +\ +\ +\ +
"; + +const char * HTML_TAIL = "
"; + +const std::map BASE_14_FONT_CSS_FONT_MAP({\ + { "Courier", "Courier,monospace" },\ + { "Helvetica", "Helvetica,Arial,\"Nimbus Sans L\",sans-serif" },\ + { "Times", "Times,\"Time New Roman\",\"Nimbus Roman No9 L\",serif" },\ + { "Symbol", "Symbol,\"Standard Symbols L\"" },\ + { "ZapfDingbats", "ZapfDingbats,\"Dingbats\"" },\ +}); + +const double id_matrix[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0}; + +#endif //CONSTS_H__ diff --git a/src/HTMLRenderer.cc b/src/HTMLRenderer.cc index f203ec8..fdef4ff 100644 --- a/src/HTMLRenderer.cc +++ b/src/HTMLRenderer.cc @@ -25,6 +25,7 @@ #include "HTMLRenderer.h" #include "BackgroundRenderer.h" +#include "Consts.h" /* * CSS classes @@ -41,74 +42,9 @@ * w - White space * t - Transform matrix * c - Color + * */ -const char * HTML_HEAD = "\n\ -\ -\ -\ -\ -
"; - -const char * HTML_TAIL = "
"; - -const std::map BASE_14_FONT_CSS_FONT_MAP({\ - { "Courier", "Courier,monospace" },\ - { "Helvetica", "Helvetica,Arial,\"Nimbus Sans L\",sans-serif" },\ - { "Times", "Times,\"Time New Roman\",\"Nimbus Roman No9 L\",serif" },\ - { "Symbol", "Symbol" },\ - { "ZapfDingbats", "ZapfDingbats" },\ -}); - -const double id_matrix[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0}; - TextString::TextString(GfxState *state) :unicodes() ,x(state->getCurX()) @@ -242,7 +178,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state) cur_fn_id = cur_fs_id = cur_tm_id = cur_color_id = 0; cur_line_x_offset = 0; - cur_line_y = 0; + cur_tx = cur_ty = 0; cur_font_size = 0; memcpy(draw_ctm, id_matrix, sizeof(draw_ctm)); @@ -380,9 +316,9 @@ void HTMLRenderer::endString(GfxState *state) { if(at_same_line(cur_line, cur_string)) { // TODO: this is not correct - double x1 = cur_line->getX() + cur_line->getWidth(); - double x2 = cur_string->getX(); - double target = (x2-x1-cur_line_x_offset); + double x1 = cur_line->getState()->getLineX() + cur_line->getWidth(); + double x2 = cur_string->getState()->getLineX(); + double target = (x2-x1-cur_line_x_offset) * draw_scale; if(target > -param->h_eps) { @@ -439,7 +375,8 @@ void HTMLRenderer::endString(GfxState *state) { html_fout << "\""; double x,y; cur_state->transform(cur_state->getCurX(), cur_state->getCurY(), &x, &y); - html_fout << boost::format(" data-scale=\"%4%\" data-x=\"%1%\" data-y=\"%2%\" data-hs=\"%3%")%x%y%(cur_state->getHorizScaling())%draw_scale; + html_fout << boost::format("data-lx=\"%5%\" data-ly=\"%6%\" data-scale=\"%4%\" data-x=\"%1%\" data-y=\"%2%\" data-hs=\"%3%") + %x%y%(cur_state->getHorizScaling())%draw_scale%cur_state->getLineX()%cur_state->getLineY(); } html_fout << "\">"; @@ -471,11 +408,16 @@ void HTMLRenderer::drawChar(GfxState *state, double x, double y, // TODO void HTMLRenderer::drawString(GfxState * state, GooString * s) { + check_state_change(state); + auto font = state->getFont(); if(font->getWMode()) - std::cerr << "TODO: writing mode" << std::endl; + { + //TODO + return; + } - // stolen from poppler + // from poppler double dx = 0; double dy = 0; double dx2, dy2; @@ -983,10 +925,10 @@ void HTMLRenderer::check_state_change(GfxState * state) { if(pos_changed) { - if(!_equal(state->getLineY(), cur_line_y)) + if(!_equal(state->getLineY(), cur_ty)) { close_cur_line(); - cur_line_y = state->getLineY(); + cur_ty = state->getLineY(); } } diff --git a/src/HTMLRenderer.h b/src/HTMLRenderer.h index dd1fe54..523d24e 100644 --- a/src/HTMLRenderer.h +++ b/src/HTMLRenderer.h @@ -199,7 +199,7 @@ class HTMLRenderer : public OutputDev double cur_line_x_offset; // current position - double cur_line_y; + double cur_tx, cur_ty; // in text coords bool pos_changed; long long cur_fn_id;