1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-05 09:38:40 +00:00

Better solution for ascent/descent

but need more work when:
- different styles in the same line
- non-embedded fonts (that we cannot find the correct ascent/descent)
This commit is contained in:
Lu Wang 2012-08-30 20:08:42 +08:00
parent 02d5cbf244
commit 4b1aff0da5
5 changed files with 17 additions and 27 deletions

2
TODO
View File

@ -1,5 +1,7 @@
better solution for ascent/descent (cross-platform, embeded/not)
option to embed local matched fonts for non-embedded ones
fake space detection
take care of spaces (simulate by <span>)

View File

@ -20,11 +20,11 @@
position:absolute;
white-space:pre;
font-size:0;
transform-origin:0% 0%;
-ms-transform-origin:0% 0%;
-moz-transform-origin:0% 0%;
-webkit-transform-origin:0% 0%;
-o-transform-origin:0% 0%;
transform-origin:0% 190%;
-ms-transform-origin:0% 100%;
-moz-transform-origin:0% 100%;
-webkit-transform-origin:0% 100%;
-o-transform-origin:0% 100%;
}
span {
position:relative;

View File

@ -30,7 +30,7 @@ void HTMLRenderer::export_remote_font(long long fn_id, const string & suffix, co
allcss_fout << fn;
}
allcss_fout << format(")format(\"%1%\");}.f%|2$x|{font-family:f%|2$x|;}") % fontfileformat % fn_id << endl;
allcss_fout << format(")format(\"%1%\");}.f%|2$x|{font-family:f%|2$x|;line-height:%3%;}") % fontfileformat % fn_id % (font->getAscent() - font->getDescent()) << endl;
}
static string general_font_family(GfxFont * font)
@ -62,6 +62,8 @@ void HTMLRenderer::export_local_font(long long fn_id, GfxFont * font, const stri
else if(font->isItalic() || ifind_first(original_font_name, "italic"))
allcss_fout << "font-style:italic;";
allcss_fout << "line-height:" << (font->getAscent() - font->getDescent()) << ";";
allcss_fout << "}" << endl;
}

View File

@ -247,23 +247,6 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix,
if(ctu)
ctu->decRefCnt();
/*
* Fontforge cannot set the ***Ascent value for nonTTF fonts
* So save to a temp ttf file and open it again
*/
string tmpfn = fn + "_.ttf";
add_tmp_file(tmpfn);
script_fout << format("Generate(%1%)") % (tmp_dir / tmpfn) << endl;
script_fout << format("Open(%1%)") % (tmp_dir / tmpfn) << endl;
for(const string & key : {"Win", "Typo", "HHead"})
{
script_fout << format("SetOS2Value(\"%1%Ascent\", %2%)") % key % (int)round(font->getAscent() * 1000) << endl;
script_fout << format("SetOS2Value(\"%1%AscentIsOffset\", 0)") % key << endl;
script_fout << format("SetOS2Value(\"%1%Descent\", %2%)") % key % (int)round(-font->getDescent() * 1000) << endl;
script_fout << format("SetOS2Value(\"%1%DescentIsOffset\", 0)") % key << endl;
}
script_fout << format("Generate(%1%)") % ((param->single_html ? tmp_dir : dest_dir) / (fn+".ttf")) << endl;
if(param->single_html)
add_tmp_file(fn+".ttf");

View File

@ -352,11 +352,14 @@ void HTMLRenderer::prepare_line(GfxState * state)
double x,y; // in user space
state->transform(state->getCurX(), state->getCurY(), &x, &y);
html_fout << format("<div style=\"left:%1%px;top:%2%px;bottom:%3%px;\" class=\"l t%|4$x|\">")
// TODO class for height
html_fout << format("<div style=\"left:%1%px;bottom:%2%px;height:%4%px;line-height:%5%px;\" class=\"l t%|3$x|\">")
% x
% (pageHeight - y - state->getFont()->getAscent() * draw_font_size)
% (y + state->getFont()->getDescent() * draw_font_size)
% cur_tm_id;
% y
% cur_tm_id
% (state->getFont()->getAscent() * draw_font_size)
% (2*(state->getFont()->getAscent() * draw_font_size))
;
//resync position
draw_ty = cur_ty;