mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
fix line merging
This commit is contained in:
parent
19a86e98bf
commit
9531a3d8c2
@ -156,36 +156,43 @@ void HTMLRenderer::TextLineBuffer::flush(void)
|
||||
if(cur_text_idx >= cur_offset_iter->start_idx)
|
||||
{
|
||||
double target = cur_offset_iter->width + dx;
|
||||
double actual_offset = 0;
|
||||
|
||||
if(equal(target, 0))
|
||||
if(abs(target) <= renderer->param->h_eps)
|
||||
{
|
||||
dx = 0;
|
||||
}
|
||||
else if(equal(target, stack.back()->single_space_offset()))
|
||||
{
|
||||
Unicode u = ' ';
|
||||
outputUnicodes(out, &u, 1);
|
||||
dx = 0;
|
||||
actual_offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto & wm = renderer->whitespace_manager;
|
||||
wm.install(target);
|
||||
auto wid = wm.get_id();
|
||||
double w = wm.get_actual_value();
|
||||
double space_off = stack.back()->single_space_offset();
|
||||
if(abs(target - space_off) <= renderer->param->h_eps)
|
||||
{
|
||||
Unicode u = ' ';
|
||||
outputUnicodes(out, &u, 1);
|
||||
actual_offset = space_off;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto & wm = renderer->whitespace_manager;
|
||||
wm.install(target);
|
||||
auto wid = wm.get_id();
|
||||
actual_offset = wm.get_actual_value();
|
||||
|
||||
if(w < 0)
|
||||
last_text_pos_with_negative_offset = cur_text_idx;
|
||||
if(!equal(actual_offset, 0))
|
||||
{
|
||||
if(is_positive(-actual_offset))
|
||||
last_text_pos_with_negative_offset = cur_text_idx;
|
||||
|
||||
auto * p = stack.back();
|
||||
double threshold = p->draw_font_size * (p->font_info->ascent - p->font_info->descent) * (renderer->param->space_threshold);
|
||||
auto * p = stack.back();
|
||||
double threshold = p->draw_font_size * (p->font_info->ascent - p->font_info->descent) * (renderer->param->space_threshold);
|
||||
|
||||
out << "<span class=\"" << CSS::WHITESPACE_CN
|
||||
<< ' ' << CSS::WHITESPACE_CN << wid << "\">" << (target > (threshold - EPS) ? " " : "") << "</span>";
|
||||
out << "<span class=\"" << CSS::WHITESPACE_CN
|
||||
<< ' ' << CSS::WHITESPACE_CN << wid << "\">" << (target > (threshold - EPS) ? " " : "") << "</span>";
|
||||
|
||||
dx = target - w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dx = target - actual_offset;
|
||||
++ cur_offset_iter;
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ void HTMLRenderer::check_state_change(GfxState * state)
|
||||
|
||||
// see if the new line is compatible with the current line with proper position shift
|
||||
// depends: rise & text position & transformation
|
||||
if(need_recheck_position)
|
||||
if(need_recheck_position && (new_line_state < NLS_DIV))
|
||||
{
|
||||
// try to transform the old origin under the new TM
|
||||
/*
|
||||
@ -295,20 +295,18 @@ void HTMLRenderer::check_state_change(GfxState * state)
|
||||
if(tm_equal(old_tm, cur_text_tm, 4))
|
||||
{
|
||||
double lhs1 = cur_text_tm[4] - old_tm[4] - old_tm[2] * (draw_ty - cur_ty) - old_tm[0] * (draw_tx - cur_tx);
|
||||
double lhs2 = cur_text_tm[5] - old_tm[5] - old_tm[3] * (draw_ty - cur_ty) - old_tm[0] * (draw_tx - cur_tx);
|
||||
double lhs2 = cur_text_tm[5] - old_tm[5] - old_tm[3] * (draw_ty - cur_ty) - old_tm[1] * (draw_tx - cur_tx);
|
||||
|
||||
if(equal(old_tm[0] * lhs2, old_tm[1] * lhs1))
|
||||
{
|
||||
if(!equal(old_tm[0], 0))
|
||||
{
|
||||
dx = lhs1 / old_tm[0];
|
||||
draw_tx += dx;
|
||||
merged = true;
|
||||
}
|
||||
else if (!equal(old_tm[1], 0))
|
||||
{
|
||||
dx = lhs2 / old_tm[1];
|
||||
draw_tx += dx;
|
||||
merged = true;
|
||||
}
|
||||
else
|
||||
@ -317,7 +315,6 @@ void HTMLRenderer::check_state_change(GfxState * state)
|
||||
{
|
||||
// free
|
||||
dx = 0;
|
||||
draw_tx = cur_tx;
|
||||
merged = true;
|
||||
}
|
||||
// else fail
|
||||
@ -330,6 +327,7 @@ void HTMLRenderer::check_state_change(GfxState * state)
|
||||
if(merged)
|
||||
{
|
||||
text_line_buf->append_offset(dx * draw_text_scale);
|
||||
draw_tx = cur_tx;
|
||||
draw_ty = cur_ty;
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user