diff --git a/src/HTMLRenderer/TextLineBuffer.cc b/src/HTMLRenderer/TextLineBuffer.cc
index a04e1e1..3c52dc0 100644
--- a/src/HTMLRenderer/TextLineBuffer.cc
+++ b/src/HTMLRenderer/TextLineBuffer.cc
@@ -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 << "" << (target > (threshold - EPS) ? " " : "") << "";
+ out << "" << (target > (threshold - EPS) ? " " : "") << "";
- dx = target - w;
+ }
+ }
}
-
+ dx = target - actual_offset;
++ cur_offset_iter;
}
diff --git a/src/HTMLRenderer/state.cc b/src/HTMLRenderer/state.cc
index 2fff0d1..c4f7e32 100644
--- a/src/HTMLRenderer/state.cc
+++ b/src/HTMLRenderer/state.cc
@@ -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