1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-05 09:38:40 +00:00

prepare sytle changing withint a line using <span>

This commit is contained in:
Lu Wang 2012-08-16 16:20:16 +08:00
parent b68136c428
commit ad6d6a31a0
4 changed files with 37 additions and 18 deletions

View File

@ -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

View File

@ -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("<div id=\"p%|1$x|\" class=\"p\" style=\"width:%2%px;height:%3%px;") % pageNum % pageWidth % pageHeight;

View File

@ -244,10 +244,19 @@ void HTMLRenderer::reset_state_track()
}
void HTMLRenderer::close_cur_line()
{
if(line_opened)
switch(line_status)
{
html_fout << "</div>" << endl;
line_opened = false;
case LineStatus::SPAN:
html_fout << "</span>";
// fall through
case LineStatus::DIV:
html_fout << "</div>" << endl;
line_status = LineStatus::CLOSED;
break;
case LineStatus::CLOSED:
default:
break;
}
draw_ty = cur_ty + cur_rise;

View File

@ -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("<span class=\"_ _%|1$x|\"> </span>") % wid;
draw_tx += w / draw_scale;
}
}
else
{
// shift left
// TODO, create a class for this
html_fout << format("<span style=\"margin-left:%1%px\"></span>") % target;
draw_tx += target / draw_scale;
else
{
// shift left
// TODO, create a class for this
html_fout << format("<span style=\"margin-left:%1%px\"></span>") % 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