From 6f87affd82a1bf9294d0c0b1107adea03fee593a Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Thu, 30 Aug 2012 01:01:45 +0800 Subject: [PATCH] corrected vertical position of LaTeX Math fonts, but this may hurt the font? just wait for bugs --- TODO | 12 +++++------- share/all.css | 32 ++++++++++++++++---------------- src/BackgroundRenderer.cc | 2 +- src/HTMLRenderer.h | 1 + src/HTMLRenderer/export.cc | 6 ++---- src/HTMLRenderer/general.cc | 2 +- src/HTMLRenderer/install.cc | 14 ++++++++++++++ src/HTMLRenderer/state.cc | 4 ++-- 8 files changed, 42 insertions(+), 31 deletions(-) diff --git a/TODO b/TODO index 9e42a9b..155e12b 100644 --- a/TODO +++ b/TODO @@ -1,19 +1,17 @@ z-index for space span -fake space detection +fake space detection -> Unicode U+200B manpage +disable selection if we know unicode is wrong + +compress div/span + option to break ligatures check if we can add information to the font, and let browsers show ligatures automatically use absolute positioning for long whitespace solution/workaround for latex math fonts -wiki page -- why the html looks ugly : use a modern web browser, use Linux/Mac, (enabling ClearType for Windows XP) -- why got incorrect text after copy&paste : try ligature or always-apply-unicode -- why text are so small : set --zoom or zoom in the page -- why images are blurred : set higher dpi - ==Future== custom html/css native support for image diff --git a/share/all.css b/share/all.css index 7bf8eba..1ec0c4f 100644 --- a/share/all.css +++ b/share/all.css @@ -1,5 +1,4 @@ #pdf-main { - font-family: sans-serif; position:absolute; top:0; left:0; @@ -10,37 +9,38 @@ /* for Chrome & Safari */ -webkit-text-stroke-width:0.13px; } -#pdf-main .p { +.p { position:relative; margin:13px auto; background-color:white; overflow:hidden; display:none; } -#pdf-main .l { +.l { position:absolute; white-space:pre; - font-size:1px; - 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 { - position:relative; line-height:0; + height:0; + 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%; +} +span { + position:relative; vertical-align: baseline; } -#pdf-main ._ { +._ { color:transparent; } -#pdf-main ::selection{ +::selection{ background: rgba(127,255,255,1); } -#pdf-main ::-moz-selection{ +::-moz-selection{ background: rgba(127,255,255,1); } -#pdf-main .i { +.i { position:absolute; } diff --git a/src/BackgroundRenderer.cc b/src/BackgroundRenderer.cc index 2a6dd3f..aad7f99 100644 --- a/src/BackgroundRenderer.cc +++ b/src/BackgroundRenderer.cc @@ -18,6 +18,6 @@ void BackgroundRenderer::drawChar(GfxState *state, double x, double y, double originX, double originY, CharCode code, int nBytes, Unicode *u, int uLen) { -// SplashOutputDev::drawChar(state,x,y,dx,dy,originX,originY,code, nBytes, u, uLen); + SplashOutputDev::drawChar(state,x,y,dx,dy,originX,originY,code, nBytes, u, uLen); } diff --git a/src/HTMLRenderer.h b/src/HTMLRenderer.h index 117af8c..e159d48 100644 --- a/src/HTMLRenderer.h +++ b/src/HTMLRenderer.h @@ -152,6 +152,7 @@ class HTMLRenderer : public OutputDev void export_remote_font(long long fn_id, const std::string & suffix, const std::string & fontfileformat, GfxFont * font); void export_remote_default_font(long long fn_id); void export_local_font(long long fn_id, GfxFont * font, const std::string & original_font_name, const std::string & cssfont); + void export_font_size(long long fs_id, double font_size); void export_transform_matrix(long long tm_id, const double * tm); void export_letter_space(long long ls_id, double letter_space); diff --git a/src/HTMLRenderer/export.cc b/src/HTMLRenderer/export.cc index 0161824..55b6cbb 100644 --- a/src/HTMLRenderer/export.cc +++ b/src/HTMLRenderer/export.cc @@ -12,6 +12,7 @@ #include "HTMLRenderer.h" #include "namespace.h" +#include "config.h" using boost::algorithm::ifind_first; @@ -29,9 +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; - - allcss_fout << "}" << endl; + allcss_fout << format(")format(\"%1%\");}.f%|2$x|{font-family:f%|2$x|;}") % fontfileformat % fn_id << endl; } static string general_font_family(GfxFont * font) @@ -66,7 +65,6 @@ void HTMLRenderer::export_local_font(long long fn_id, GfxFont * font, const stri allcss_fout << "}" << endl; } - void HTMLRenderer::export_font_size (long long fs_id, double font_size) { allcss_fout << format(".s%|1$x|{font-size:%2%px;}") % fs_id % font_size << endl; diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index 5e307e1..fd322a1 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -109,7 +109,7 @@ void HTMLRenderer::pre_process() html_fout << fixed; allcss_fout << fixed; - allcss_fout << ifstream(PDF2HTMLEX_DATA_PATH / CSS_FILENAME, ifstream::binary).rdbuf(); + allcss_fout << ifstream(PDF2HTMLEX_DATA_PATH / CSS_FILENAME, ifstream::binary).rdbuf(); } void HTMLRenderer::post_process() diff --git a/src/HTMLRenderer/install.cc b/src/HTMLRenderer/install.cc index 9a7256a..8036577 100644 --- a/src/HTMLRenderer/install.cc +++ b/src/HTMLRenderer/install.cc @@ -245,6 +245,20 @@ 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 << "SetOS2Value(\"" << key << "Ascent\", 0)" << 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"); diff --git a/src/HTMLRenderer/state.cc b/src/HTMLRenderer/state.cc index 06c918d..3623b3c 100644 --- a/src/HTMLRenderer/state.cc +++ b/src/HTMLRenderer/state.cc @@ -352,8 +352,8 @@ void HTMLRenderer::prepare_line(GfxState * state) double x,y; // in user space state->transform(state->getCurX(), state->getCurY(), &x, &y); - html_fout << format("
") - % x % y % cur_tm_id; + html_fout << format("
") + % x % (pageHeight-y) % cur_tm_id; //resync position draw_ty = cur_ty;