diff --git a/src/HTMLRenderer.h b/src/HTMLRenderer.h index be4a94f..f0f31e1 100644 --- a/src/HTMLRenderer.h +++ b/src/HTMLRenderer.h @@ -183,7 +183,12 @@ class HTMLRenderer : public OutputDev // states //////////////////////////////////////////////////// // if we have a pending opened line - bool line_opened; + enum class LineStatus + { + CLOSED, + SPAN, + DIV + } line_status; // The order is according to the appearance in check_state_change // any state changed diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index 0d2a559..7dc823a 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -19,7 +19,7 @@ using boost::filesystem::remove; using boost::filesystem::filesystem_error; HTMLRenderer::HTMLRenderer(const Param * param) - :line_opened(false) + :line_status(LineStatus::CLOSED) ,image_count(0) ,param(param) ,dest_dir(param->dest_dir) @@ -142,7 +142,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state) this->pageWidth = state->getPageWidth(); this->pageHeight = state->getPageHeight(); - assert(!line_opened); + assert(line_status == LineStatus::CLOSED); html_fout << format("
" << endl; - line_opened = false; + case LineStatus::SPAN: + html_fout << ""; + // fall through + case LineStatus::DIV: + html_fout << "
" << endl; + line_status = LineStatus::CLOSED; + break; + + case LineStatus::CLOSED: + default: + break; } draw_ty = cur_ty + cur_rise; diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index cb5f474..5506a96 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -157,11 +157,17 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s) check_state_change(state); // if the line is still open, try to merge with it - if(line_opened) + if(line_status != LineStatus::CLOSED) { double target = (cur_tx - draw_tx) * draw_scale; - if(target > -param->h_eps) + if(abs(target) < param->h_eps) { + // ignore it + } + else + { + // don't close a pending span here, keep the styling + if(target > param->h_eps) { double w; @@ -169,17 +175,16 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s) html_fout << format(" ") % wid; draw_tx += w / draw_scale; } - } - else - { - // shift left - // TODO, create a class for this - html_fout << format("") % target; - draw_tx += target / draw_scale; + else + { + // shift left + // TODO, create a class for this + html_fout << format("") % target; + draw_tx += target / draw_scale; + } } } - - if(!line_opened) + else { // have to open a new line @@ -222,7 +227,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s) html_fout << "\">"; - line_opened = true; + line_status = LineStatus::DIV; } // Now ready to output