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

better accuracy with new positioning method, but break text selection in Chrome

This commit is contained in:
Lu Wang 2012-08-22 23:50:56 +02:00
parent 87ae148179
commit f07fe3089c
4 changed files with 27 additions and 40 deletions

View File

@ -20,6 +20,16 @@
#pdf-main .l {
position:absolute;
white-space:pre;
font-size:0;
transform-origin:0% 100%;
-ms-transform-origin:0% 100%;
-moz-transform-origin:0% 100%;
-webkit-transform-origin:0% 100%;
-o-transform-origin:0% 100%;
}
#pdf-main span {
vertical-align: baseline;
line-height:0;
}
#pdf-main ._ {
color:transparent;

View File

@ -19,11 +19,13 @@ void BackgroundRenderer::drawChar(GfxState *state, double x, double y,
CharCode code, int nBytes, Unicode *u, int uLen)
{
auto font = state->getFont();
/*
if((font->getType() == fontType3)
|| (font->getWMode())
|| (uLen == 0)
|| (!all_of(u, u+uLen, isLegalUnicode))
)
*/
{
SplashOutputDev::drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
}

View File

@ -31,17 +31,6 @@ void HTMLRenderer::export_remote_font(long long fn_id, const string & suffix, co
allcss_fout << format(")format(\"%1%\");}.f%|2$x|{font-family:f%|2$x|;") % fontfileformat % fn_id;
double a = font->getAscent();
double d = font->getDescent();
double r = _is_positive(a-d) ? (a/(a-d)) : 1.0;
for(const string & prefix : {"", "-ms-", "-moz-", "-webkit-", "-o-"})
{
allcss_fout << prefix << "transform-origin:0% " << (r*100.0) << "%;";
}
allcss_fout << "line-height:" << (a-d) << ";";
allcss_fout << "}" << endl;
}
@ -74,17 +63,6 @@ void HTMLRenderer::export_local_font(long long fn_id, GfxFont * font, const stri
else if(font->isItalic())
allcss_fout << "font-style:italic;";
double a = font->getAscent();
double d = font->getDescent();
double r = _is_positive(a-d) ? (a/(a-d)) : 1.0;
for(const string & prefix : {"", "-ms-", "-moz-", "-webkit-", "-o-"})
{
allcss_fout << prefix << "transform-origin:0% " << (r*100.0) << "%;";
}
allcss_fout << "line-height:" << (a-d) << ";";
allcss_fout << "}" << endl;
}

View File

@ -102,7 +102,7 @@ void HTMLRenderer::check_state_change(GfxState * state)
if(!(new_fn_id == cur_fn_id))
{
new_line_status = max(new_line_status, LineStatus::DIV);
new_line_status = max(new_line_status, LineStatus::SPAN);
cur_fn_id = new_fn_id;
}
@ -166,7 +166,7 @@ void HTMLRenderer::check_state_change(GfxState * state)
if(!(_equal(new_draw_font_size, draw_font_size)))
{
new_line_status = max(new_line_status, LineStatus::DIV);
new_line_status = max(new_line_status, LineStatus::SPAN);
draw_font_size = new_draw_font_size;
cur_fs_id = install_font_size(draw_font_size);
}
@ -328,7 +328,7 @@ void HTMLRenderer::prepare_line(GfxState * state)
// horizontal position
// try to merge with the last line if possible
double target = (cur_tx - draw_tx) * draw_scale;
double target = cur_tx - draw_tx;
if(abs(target) < param->h_eps)
{
// ignore it
@ -338,7 +338,7 @@ void HTMLRenderer::prepare_line(GfxState * state)
// don't close a pending span here, keep the styling
double w;
auto wid = install_whitespace(target, 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;
}
@ -348,33 +348,30 @@ void HTMLRenderer::prepare_line(GfxState * state)
{
// have to open a new tag
if(new_line_status == LineStatus::SPAN)
{
html_fout << "<span class=\"";
}
else if (new_line_status == LineStatus::DIV)
if (new_line_status == LineStatus::DIV)
{
// TODO: recheck descent/ascent
double x,y; // in user space
state->transform(state->getCurX(), state->getCurY(), &x, &y);
html_fout << format("<div style=\"bottom:%1%px;top:%2%px;left:%3%px;\" class=\"l ")
% (y + state->getFont()->getDescent() * draw_font_size)
% (pageHeight - y - state->getFont()->getAscent() * draw_font_size)
% x;
html_fout << format("<div style=\"bottom:%1%px;left:%2%px;\" class=\"l t%|3$x|\"><em></em>")
% y % x % cur_tm_id;
html_fout << format("t%|1$x| f%|2$x| s%|3$x| ") % cur_tm_id % cur_fn_id % cur_fs_id;
}
else if(new_line_status == LineStatus::SPAN)
{
// pass
}
else
{
assert(false && "Bad value of new_line_status");
}
html_fout << format("c%|1$x| l%|2$x| w%|3$x|") % cur_color_id % cur_ls_id % cur_ws_id;
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;
html_fout << "\">";
line_status = new_line_status;
//line_status = new_line_status;
line_status = LineStatus::SPAN;
}
}