diff --git a/share/unify.pe b/share/unify.pe new file mode 100644 index 0000000..c1724a2 --- /dev/null +++ b/share/unify.pe @@ -0,0 +1,30 @@ +# script piece to unify the metrics +# by WangLu +# 2012.08.31 +wa = GetOS2Value("WinAscent") +wd = GetOS2Value("WinDescent") +ta = GetOS2Value("TypoAscent") +td = GetOS2Value("TypoDescent") +ha = GetOS2Value("HHeadAscent") +hd = GetOS2Value("HHeadDescent") +a = wa +if (ta > a) + a = ta +endif +if (ha > a) + a = ha +endif +d = wd +if (-td > d) + d = -td +endif +if (-hd > d) + d = -hd) +endif +SetOS2Value("WinAscent", a) +SetOS2Value("WinDescent", d) +SetOS2Value("HHeadAscent", a) +SetOS2Value("HHeadDescent", -d) +Print(ta-td) +Print(a) +Print(d) diff --git a/src/HTMLRenderer.h b/src/HTMLRenderer.h index 0298872..61c9892 100644 --- a/src/HTMLRenderer.h +++ b/src/HTMLRenderer.h @@ -296,6 +296,7 @@ class HTMLRenderer : public OutputDev static const std::string NECK_HTML_FILENAME; static const std::string TAIL_HTML_FILENAME; static const std::string CSS_FILENAME; + static const std::string UNIFY_SCRIPT_FILENAME; // for cross-platform purpose, use a "null" file instead of /dev/null static const std::string NULL_FILENAME; }; diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index fd322a1..45a36c3 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -242,4 +242,5 @@ const std::string HTMLRenderer::HEAD_HTML_FILENAME = "head.html"; const std::string HTMLRenderer::NECK_HTML_FILENAME = "neck.html"; const std::string HTMLRenderer::TAIL_HTML_FILENAME = "tail.html"; const std::string HTMLRenderer::CSS_FILENAME = "all.css"; +const std::string HTMLRenderer::UNIFY_SCRIPT_FILENAME = "unify.pe"; const std::string HTMLRenderer::NULL_FILENAME = "null"; diff --git a/src/HTMLRenderer/install.cc b/src/HTMLRenderer/install.cc index cc3e4de..3f5c636 100644 --- a/src/HTMLRenderer/install.cc +++ b/src/HTMLRenderer/install.cc @@ -18,6 +18,7 @@ #include "HTMLRenderer.h" #include "namespace.h" +#include "config.h" using std::all_of; using std::max; @@ -259,30 +260,13 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, * [Win|Typo|HHead][Ascent|Descent] * Firefox & Chrome interprets the values in different ways * Trying to unify them - * - * .pfa does not have such mess, convert to it and back */ - add_tmp_file(fn+"_.pfa"); - script_fout << format("Generate(%1%)") % (tmp_dir / (fn+"_.pfa")) << endl; - script_fout << "Close()" << endl; - script_fout << format("Open(%1%, 1)") % (tmp_dir / (fn+"_.pfa")) << endl; script_fout << format("Generate(%1%)") % dest << endl; script_fout << "Close()" << endl; script_fout << format("Open(%1%, 1)") % dest << endl; - - for(const string & s1 : {"Win", "Typo", "HHead"}) - { - for(const string & s2 : {"Ascent", "Descent"}) - { - script_fout << "Print(GetOS2Value(\"" << s1 << s2 << "\"))" << endl; - } - } - - script_fout << "a=GetOS2Value(\"TypoAscent\")" << endl; - script_fout << "d=GetOS2Value(\"TypoDescent\")" << endl; - script_fout << "SetOS2Value(\"TypoAscent\", 0)" << endl; - script_fout << "SetOS2Value(\"TypoDescent\", -a-d)" << endl; + script_fout << ifstream(PDF2HTMLEX_DATA_PATH / UNIFY_SCRIPT_FILENAME).rdbuf(); script_fout << format("Generate(%1%)") % dest << endl; + script_fout.close(); if(system((boost::format("fontforge -script %1% 1>%2% 2>%3%") % script_path % (tmp_dir / (fn+".info")) % (tmp_dir / NULL_FILENAME)).str().c_str()) != 0) cerr << "Warning: fontforge failed." << endl; @@ -291,21 +275,13 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, add_tmp_file(NULL_FILENAME); // read metric - int WinAsc, WinDes, TypoAsc, TypoDes, HHeadAsc, HHeadDes; - if(ifstream(tmp_dir / (fn+".info")) >> WinAsc >> WinDes >> TypoAsc >> TypoDes >> HHeadAsc >> HHeadDes) + int em, ascent, descent; + if(ifstream(tmp_dir / (fn+".info")) >> em >> ascent >> descent) { - int em = TypoAsc - TypoDes; if(em != 0) { - /* - int a = max(WinAsc, max(TypoAsc, HHeadAsc)); - int d = min(-WinDes, min(TypoDes, HHeadDes)); - */ - int a = WinAsc; - int d = -WinDes; - - info.ascent = ((double)a) / em; - info.descent = ((double)d) / em; + info.ascent = ((double)ascent) / em; + info.descent = -((double)descent) / em; } else {