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

integrate negative whtiespace; restructru prepare_line

This commit is contained in:
Lu Wang 2012-08-16 20:26:09 +08:00
parent 14d2061f9e
commit 9ed6e9c325
7 changed files with 64 additions and 62 deletions

View File

@ -22,7 +22,6 @@
white-space:pre; white-space:pre;
} }
.l > ._ { .l > ._ {
display:inline-block;
color:transparent; color:transparent;
} }
::selection{ ::selection{

View File

@ -161,9 +161,14 @@ class HTMLRenderer : public OutputDev
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// state tracking // state tracking
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// check updated states, and determine new_line_stauts
// make sure this function can be called several times consecutively without problem
void check_state_change(GfxState * state); void check_state_change(GfxState * state);
void reset_state_track(); // reset all ***_changed flags
void prepare_line(); // close current span or div if necessary, according to new_line_status void reset_state_change();
// prepare the line context, (close old tags, open new tags)
// make sure the current HTML style consistent with PDF
void prepare_line(GfxState * state);
void close_line(); void close_line();

View File

@ -148,6 +148,9 @@ void HTMLRenderer::export_color (long long color_id, const GfxRGB * rgb)
void HTMLRenderer::export_whitespace (long long ws_id, double ws_width) void HTMLRenderer::export_whitespace (long long ws_id, double ws_width)
{ {
allcss_fout << format("._%|1$x|{width:%2%px;}") % ws_id % ws_width << endl; if(ws_width > 0)
allcss_fout << format("._%|1$x|{display:inline-block;width:%2%px;}") % ws_id % ws_width << endl;
else
allcss_fout << format("._%|1$x|{display:inline;margin-left:%2%px;}") % ws_id % ws_width << endl;
} }

View File

@ -182,7 +182,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state)
draw_scale = 1.0; draw_scale = 1.0;
draw_tx = draw_ty = 0; draw_tx = draw_ty = 0;
reset_state_track(); reset_state_change();
} }
void HTMLRenderer::endPage() { void HTMLRenderer::endPage() {

View File

@ -55,7 +55,8 @@ void HTMLRenderer::drawImage(GfxState * state, Object * ref, Stream * str, int w
close_line(); close_line();
double * ctm = state->getCTM(); double ctm[6];
memcpy(ctm, state->getCTM(), sizeof(ctm));
ctm[4] = ctm[5] = 0.0; ctm[4] = ctm[5] = 0.0;
html_fout << format("<img class=\"i t%2%\" style=\"left:%3%px;bottom:%4%px;width:%5%px;height:%6%px;\" src=\"i%|1$x|.png\" />") % image_count % install_transform_matrix(ctm) % state->getCurX() % state->getCurY() % width % height << endl; html_fout << format("<img class=\"i t%2%\" style=\"left:%3%px;bottom:%4%px;width:%5%px;height:%6%px;\" src=\"i%|1$x|.png\" />") % image_count % install_transform_matrix(ctm) % state->getCurX() % state->getCurY() % width % height << endl;

View File

@ -89,7 +89,7 @@ void HTMLRenderer::check_state_change(GfxState * state)
} }
// text position // text position
// we've been tracking the text position positively in update... function // we've been tracking the text position positively in the update*** functions
if(all_changed || text_pos_changed) if(all_changed || text_pos_changed)
{ {
need_recheck_position = true; need_recheck_position = true;
@ -224,9 +224,48 @@ void HTMLRenderer::check_state_change(GfxState * state)
} }
} }
prepare_line(); reset_state_change();
}
// TODO: move the following to prepare_line ?? void HTMLRenderer::reset_state_change()
{
all_changed = false;
rise_changed = false;
text_pos_changed = false;
font_changed = false;
ctm_changed = false;
text_mat_changed = false;
hori_scale_changed = false;
letter_space_changed = false;
word_space_changed = false;
color_changed = false;
}
void HTMLRenderer::prepare_line(GfxState * state)
{
// close old tags when necessary
if((line_status == LineStatus::NONE) || (new_line_status == LineStatus::NONE))
{
//pass
}
else if(new_line_status == LineStatus::DIV)
{
close_line();
}
else
{
assert(new_line_status == LineStatus::SPAN);
if(line_status == LineStatus::SPAN)
html_fout << "</span>";
else
assert(line_status == LineStatus::DIV);
// don't change line_status
}
// open new tags when necessary
if(line_status == LineStatus::NONE) if(line_status == LineStatus::NONE)
{ {
new_line_status = LineStatus::DIV; new_line_status = LineStatus::DIV;
@ -250,20 +289,10 @@ void HTMLRenderer::check_state_change(GfxState * state)
{ {
// don't close a pending span here, keep the styling // don't close a pending span here, keep the styling
if(target > param->h_eps) double w;
{ auto wid = install_whitespace(target, w);
double w; html_fout << format("<span class=\"_ _%|1$x|\">%2%</span>") % wid % (target > 0 ? " " : "");
auto wid = install_whitespace(target, w); draw_tx += w / draw_scale;
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;
}
} }
} }
@ -311,48 +340,12 @@ void HTMLRenderer::check_state_change(GfxState * state)
line_status = new_line_status; line_status = new_line_status;
} }
reset_state_track();
}
void HTMLRenderer::reset_state_track()
{
all_changed = false;
rise_changed = false;
text_pos_changed = false;
font_changed = false;
ctm_changed = false;
text_mat_changed = false;
hori_scale_changed = false;
letter_space_changed = false;
word_space_changed = false;
color_changed = false;
}
void HTMLRenderer::prepare_line()
{
if((line_status == LineStatus::NONE) || (new_line_status == LineStatus::NONE))
return;
if(new_line_status == LineStatus::DIV)
{
close_line();
}
else
{
assert(new_line_status == LineStatus::SPAN);
if(line_status == LineStatus::SPAN)
html_fout << "</span>";
else
assert(line_status == LineStatus::DIV);
// don't change line_status
}
} }
void HTMLRenderer::close_line() void HTMLRenderer::close_line()
{ {
if(line_status == LineStatus::NONE)
return;
if(line_status == LineStatus::SPAN) if(line_status == LineStatus::SPAN)
html_fout << "</span>"; html_fout << "</span>";
else else

View File

@ -155,6 +155,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
// see if the line has to be closed due to state change // see if the line has to be closed due to state change
check_state_change(state); check_state_change(state);
prepare_line(state);
// Now ready to output // Now ready to output
// get the unicodes // get the unicodes