mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
better asc/des handling
This commit is contained in:
parent
c99f725c72
commit
e49459d21f
30
share/unify.pe
Normal file
30
share/unify.pe
Normal file
@ -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)
|
@ -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;
|
||||
};
|
||||
|
@ -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";
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user