From 5892b2438a0c9d68688711202df5ce960f9ff1b9 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Thu, 23 Aug 2012 22:36:27 +0200 Subject: [PATCH] better positioning --- src/HTMLRenderer/state.cc | 4 ++++ src/HTMLRenderer/text.cc | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/HTMLRenderer/state.cc b/src/HTMLRenderer/state.cc index 623bee5..54fe7db 100644 --- a/src/HTMLRenderer/state.cc +++ b/src/HTMLRenderer/state.cc @@ -364,6 +364,10 @@ void HTMLRenderer::prepare_line(GfxState * state) % x; 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 { diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index 8f69280..34283a9 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -167,6 +167,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s) double dx = 0; double dy = 0; + double dxerr = 0; double dx1,dy1; double ox, oy; @@ -177,6 +178,11 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s) CharCode code; Unicode *u = nullptr; + double fs = state->getFontSize(); + double cs = state->getCharSpace(); + double ws = state->getWordSpace(); + double hs = state->getHorizScaling(); + while (len > 0) { 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))) { outputUnicodes(html_fout, u, uLen); - dx += dx1; - dy += dy1; } else { // should not consider hozi scaling here // will be handled by draw_ctm - double target = dx1 + state->getCharSpace(); + double target = dx1 * fs + state->getCharSpace(); if(n == 1 && *p == ' ') target += state->getWordSpace(); double w; auto wid = install_whitespace(target * draw_scale, w); html_fout << format("%2%") % wid % (target > 0 ? " " : ""); - dx += target; - dy += dy1; + + dxerr += w/draw_scale - target; } + dx += dx1; + dy += dy1; ++nChars; p += n; @@ -219,15 +225,13 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s) // horiz_scaling is merged into ctm now, // so the coordinate system is ugly - dx = (dx * state->getFontSize() - + nChars * state->getCharSpace() - + nSpaces * state->getWordSpace()) * state->getHorizScaling(); + dx = (dx * fs + nChars * cs + nSpaces * ws) * hs; - dy *= state->getFontSize(); + dy *= fs; cur_tx += dx; cur_ty += dy; - draw_tx += dx; + draw_tx += dx + dxerr * state->getFontSize() * state->getHorizScaling(); draw_ty += dy; }