1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

better positioning

This commit is contained in:
Lu Wang 2012-08-23 22:36:27 +02:00
parent ec87a51a75
commit 5892b2438a
2 changed files with 18 additions and 10 deletions

View File

@ -364,6 +364,10 @@ void HTMLRenderer::prepare_line(GfxState * state)
% x; % x;
html_fout << format("t%|1$x| f%|2$x| s%|3$x| ") % cur_tm_id % cur_fn_id % cur_fs_id; html_fout << format("t%|1$x| f%|2$x| s%|3$x| ") % cur_tm_id % cur_fn_id % cur_fs_id;
//resync position
draw_ty = cur_ty + cur_rise;
draw_tx = cur_tx;
} }
else else
{ {

View File

@ -167,6 +167,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
double dx = 0; double dx = 0;
double dy = 0; double dy = 0;
double dxerr = 0;
double dx1,dy1; double dx1,dy1;
double ox, oy; double ox, oy;
@ -177,6 +178,11 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
CharCode code; CharCode code;
Unicode *u = nullptr; Unicode *u = nullptr;
double fs = state->getFontSize();
double cs = state->getCharSpace();
double ws = state->getWordSpace();
double hs = state->getHorizScaling();
while (len > 0) { while (len > 0) {
auto n = font->getNextChar(p, len, &code, &u, &uLen, &dx1, &dy1, &ox, &oy); auto n = font->getNextChar(p, len, &code, &u, &uLen, &dx1, &dy1, &ox, &oy);
@ -193,24 +199,24 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
if((uLen > 0) && (all_of(u, u+uLen, isLegalUnicode))) if((uLen > 0) && (all_of(u, u+uLen, isLegalUnicode)))
{ {
outputUnicodes(html_fout, u, uLen); outputUnicodes(html_fout, u, uLen);
dx += dx1;
dy += dy1;
} }
else else
{ {
// should not consider hozi scaling here // should not consider hozi scaling here
// will be handled by draw_ctm // will be handled by draw_ctm
double target = dx1 + state->getCharSpace(); double target = dx1 * fs + state->getCharSpace();
if(n == 1 && *p == ' ') if(n == 1 && *p == ' ')
target += state->getWordSpace(); target += state->getWordSpace();
double w; double w;
auto wid = install_whitespace(target * draw_scale, w); auto wid = install_whitespace(target * draw_scale, w);
html_fout << format("<span class=\"_ _%|1$x|\">%2%</span>") % wid % (target > 0 ? " " : ""); html_fout << format("<span class=\"_ _%|1$x|\">%2%</span>") % wid % (target > 0 ? " " : "");
dx += target;
dy += dy1; dxerr += w/draw_scale - target;
} }
dx += dx1;
dy += dy1;
++nChars; ++nChars;
p += n; p += n;
@ -219,15 +225,13 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
// horiz_scaling is merged into ctm now, // horiz_scaling is merged into ctm now,
// so the coordinate system is ugly // so the coordinate system is ugly
dx = (dx * state->getFontSize() dx = (dx * fs + nChars * cs + nSpaces * ws) * hs;
+ nChars * state->getCharSpace()
+ nSpaces * state->getWordSpace()) * state->getHorizScaling();
dy *= state->getFontSize(); dy *= fs;
cur_tx += dx; cur_tx += dx;
cur_ty += dy; cur_ty += dy;
draw_tx += dx; draw_tx += dx + dxerr * state->getFontSize() * state->getHorizScaling();
draw_ty += dy; draw_ty += dy;
} }