mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
better line merging
This commit is contained in:
parent
6ee3d2b949
commit
3cdde4bce7
@ -182,73 +182,52 @@ void HTMLRenderer::check_state_change(GfxState * state)
|
|||||||
// depends: rise & text position & transformation
|
// depends: rise & text position & transformation
|
||||||
if(need_recheck_position)
|
if(need_recheck_position)
|
||||||
{
|
{
|
||||||
bool hope = true;
|
// try to transform the old origin under the new TM
|
||||||
// do not bother with draw_ctm
|
/*
|
||||||
if(_tm_equal(cur_ctm, old_ctm)) {
|
* OldTM * (draw_tx, draw_ty, 1)^T = CurTM * (draw_tx + dx, draw_ty + dy, 1)^T
|
||||||
// nothing to do
|
*
|
||||||
}
|
* OldTM[4] = CurTM[0] * dx + CurTM[2] * dy + CurTM[4]
|
||||||
else if (_tm_equal(cur_ctm, old_ctm, 4))
|
* OldTM[5] = CurTM[1] * dx + CurTM[3] * dy + CurTM[5]
|
||||||
|
*
|
||||||
|
* We just care if we can map the origin y to the same new y
|
||||||
|
* So just let dy = cur_y - old_y, and try to solve dx
|
||||||
|
*
|
||||||
|
* TODO, writing mode, set dx and solve dy
|
||||||
|
*/
|
||||||
|
|
||||||
|
double dy = cur_ty + cur_rise - draw_ty;
|
||||||
|
draw_ty += dy;
|
||||||
|
|
||||||
|
double tdx = old_ctm[4] - cur_ctm[4] - cur_ctm[2] * dy;
|
||||||
|
double tdy = old_ctm[5] - cur_ctm[5] - cur_ctm[3] * dy;
|
||||||
|
|
||||||
|
if(_equal(cur_ctm[0] * tdy, cur_ctm[1] * tdx))
|
||||||
{
|
{
|
||||||
// try harder,
|
if(abs(cur_ctm[0]) > EPS)
|
||||||
// try to transform the old origin under the new TM
|
draw_tx += tdx / cur_ctm[0];
|
||||||
/*
|
else if (abs(cur_ctm[1]) > EPS)
|
||||||
* OldTM * (draw_tx, draw_ty, 1)^T = CurTM * (draw_tx + dx, draw_ty + dy, 1)^T
|
draw_tx += tdy / cur_ctm[1];
|
||||||
*
|
|
||||||
* OldTM[4] = CurTM[0] * dx + CurTM[2] * dy + CurTM[4]
|
|
||||||
* OldTM[5] = CurTM[1] * dx + CurTM[3] * dy + CurTM[5]
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
double tdx = old_ctm[4] - cur_ctm[4];
|
|
||||||
double tdy = old_ctm[5] - cur_ctm[5];
|
|
||||||
|
|
||||||
double deter = cur_ctm[0] * cur_ctm[3] - cur_ctm[1] * cur_ctm[2];
|
|
||||||
|
|
||||||
if(abs(deter) > EPS)
|
|
||||||
{
|
|
||||||
//ok, only one solution
|
|
||||||
draw_tx += (cur_ctm[3]*tdx - cur_ctm[2]*tdy) / deter;
|
|
||||||
draw_ty += (-cur_ctm[1]*tdx + cur_ctm[0]*tdy) / deter;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO, writing mode?
|
if((abs(tdx) < EPS) && (abs(tdy) < EPS))
|
||||||
//prefer the same line, so dy = 0
|
|
||||||
if(_equal(cur_ctm[0] * old_ctm[5], cur_ctm[1] * old_ctm[4]))
|
|
||||||
{
|
{
|
||||||
// just compute dx
|
// free
|
||||||
if(abs(cur_ctm[0]) > EPS)
|
draw_tx = cur_tx;
|
||||||
draw_tx += old_ctm[4] / cur_ctm[0];
|
}
|
||||||
else if (abs(cur_ctm[1]) > EPS)
|
|
||||||
draw_tx += old_ctm[5] / cur_ctm[1];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// wo cur_ctm[0] == cur_ctm[1] == 0
|
|
||||||
// while the first 4 elements of cur/old_ctm are the same, but the last 2 are not
|
|
||||||
// so give up
|
|
||||||
hope = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hope = false;
|
// fail
|
||||||
|
new_line_status = max(new_line_status, LineStatus::DIV);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// ok, have to start a new line
|
// no solution
|
||||||
hope = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// should use the draw_scale here
|
|
||||||
if(!(hope && (abs((cur_ty + cur_rise) - draw_ty) * draw_scale < param->v_eps)))
|
|
||||||
{
|
|
||||||
new_line_status = max(new_line_status, LineStatus::DIV);
|
new_line_status = max(new_line_status, LineStatus::DIV);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// letter space
|
// letter space
|
||||||
// depends: draw_scale
|
// depends: draw_scale
|
||||||
if(all_changed || letter_space_changed)
|
if(all_changed || letter_space_changed)
|
||||||
|
Loading…
Reference in New Issue
Block a user