mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
working on new positioning
This commit is contained in:
commit
17c44e8cb0
@ -1,8 +1,7 @@
|
||||
/*
|
||||
* HTMLRenderer.h
|
||||
*
|
||||
* Created on: Mar 15, 2011
|
||||
* Author: tian
|
||||
* by WangLu
|
||||
*/
|
||||
|
||||
#ifndef HTMLRENDERER_H_
|
||||
|
@ -7,6 +7,12 @@
|
||||
* 2012.08.14
|
||||
*/
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* use relative positioning for rise
|
||||
* negative offset of span
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "HTMLRenderer.h"
|
||||
@ -313,41 +319,12 @@ void HTMLRenderer::prepare_line(GfxState * state)
|
||||
// don't change line_status
|
||||
}
|
||||
|
||||
// open new tags when necessary
|
||||
if(line_status == LineStatus::NONE)
|
||||
{
|
||||
new_line_status = LineStatus::DIV;
|
||||
|
||||
//resync position
|
||||
draw_ty = cur_ty + cur_rise;
|
||||
draw_tx = cur_tx;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(new_line_status != LineStatus::DIV);
|
||||
|
||||
// horizontal position
|
||||
// try to merge with the last line if possible
|
||||
double target = cur_tx - draw_tx;
|
||||
if(abs(target) < param->h_eps)
|
||||
{
|
||||
// ignore it
|
||||
}
|
||||
else
|
||||
{
|
||||
// don't close a pending span here, keep the styling
|
||||
|
||||
double w;
|
||||
auto wid = install_whitespace(target * draw_scale, w);
|
||||
html_fout << format("<span class=\"_ _%|1$x|\">%2%</span>") % wid % (target > 0 ? " " : "");
|
||||
draw_tx += w / draw_scale;
|
||||
}
|
||||
}
|
||||
|
||||
if(new_line_status != LineStatus::NONE)
|
||||
{
|
||||
// have to open a new tag
|
||||
|
||||
if (new_line_status == LineStatus::DIV)
|
||||
{
|
||||
// TODO: recheck descent/ascent
|
||||
@ -357,6 +334,10 @@ void HTMLRenderer::prepare_line(GfxState * state)
|
||||
html_fout << format("<div style=\"bottom:%1%px;left:%2%px;\" class=\"l t%|3$x|\"><em></em>")
|
||||
% y % x % cur_tm_id;
|
||||
|
||||
//resync position
|
||||
draw_ty = cur_ty + cur_rise;
|
||||
draw_tx = cur_tx;
|
||||
|
||||
}
|
||||
else if(new_line_status == LineStatus::SPAN)
|
||||
{
|
||||
@ -370,10 +351,25 @@ void HTMLRenderer::prepare_line(GfxState * state)
|
||||
html_fout << format("<span class=\"f%|1$x| s%|2$x| c%|3$x| l%|4$x| w%|5$x|\">")
|
||||
% cur_fn_id % cur_fs_id % cur_color_id % cur_ls_id % cur_ws_id;
|
||||
|
||||
//line_status = new_line_status;
|
||||
line_status = LineStatus::SPAN;
|
||||
}
|
||||
|
||||
// align horizontal position
|
||||
// try to merge with the last line if possible
|
||||
double target = cur_tx - draw_tx;
|
||||
if(abs(target) < param->h_eps)
|
||||
{
|
||||
// ignore it
|
||||
}
|
||||
else
|
||||
{
|
||||
// don't close a pending span here, keep the styling
|
||||
|
||||
double w;
|
||||
auto wid = install_whitespace(target * draw_scale, w);
|
||||
html_fout << format("<span class=\"_ _%|1$x|\">%2%</span>") % wid % (target > 0 ? " " : "");
|
||||
draw_tx += w / draw_scale;
|
||||
}
|
||||
}
|
||||
void HTMLRenderer::close_line()
|
||||
{
|
||||
|
@ -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("<span class=\"_ _%|1$x|\">%2%</span>") % 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user