1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-06-26 06:09:21 +00:00

working on external font hint tool

This commit is contained in:
Lu Wang 2012-09-23 20:25:22 +08:00
parent 201fecb18e
commit 9e7f34bd5a
4 changed files with 37 additions and 14 deletions

View File

@ -121,6 +121,11 @@ If it's empty, the file name will be determined automatically.
.B --font-suffix <suffix> (Default: ".ttf"), --font-format <format> (Default: "truetype")
Specify the suffix and format of fonts extracted from the PDF file. They should be consistent.
.TP
.B --external-hint-tool <tool> (Default: "")
If specified, the tool will be called in order to enhanced hinting for fonts.
The tool will be called as '<tool> <in.suffix> <out.suffix>', where suffix will be the same as specified for --font-suffix.
.TP
.B --debug <0|1> (Default: 0)
Show debug information.
.TP

View File

@ -393,23 +393,38 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
*
* Generate the font as desired
*
*/
string tmp_fn = (char*)str_fmt("%s/__font%s", param->tmp_dir.c_str(), param->font_suffix.c_str());
add_tmp_file(tmp_fn);
string fn = (char*)str_fmt("%s/f%llx%s",
(param->single_html ? param->tmp_dir : param->dest_dir).c_str(),
info.id, param->font_suffix.c_str());
if(param->single_html)
add_tmp_file(fn);
ffw_save(fn.c_str());
ffw_close();
/*
* Step 4
* Reload to retrieve accurate ascent/descent <-- TODO: remove this
*/
rename(fn.c_str(), tmp_fn.c_str());
ffw_load_font(tmp_fn.c_str());
ffw_metric(&info.ascent, &info.descent, &info.em_size);
ffw_save(fn.c_str());
ffw_close();
/*
* Step 5 (keeping the scope)
* Call external hinting program
*/
if(param->external_hint_tool != "")
{
auto fn = str_fmt("%s/f%llx%s",
(param->single_html ? param->tmp_dir : param->dest_dir).c_str(),
info.id, param->font_suffix.c_str());
if(param->single_html)
add_tmp_file((char*)fn);
ffw_save((char*)fn);
ffw_close();
ffw_load_font((char*)fn);
ffw_metric(&info.ascent, &info.descent, &info.em_size);
ffw_save((char*)fn);
ffw_close();
rename(fn.c_str(), tmp_fn.c_str());
system((char*)str_fmt("%s %s %s", param->external_hint_tool.c_str(), tmp_fn.c_str(), fn.c_str()));
}
}

View File

@ -46,6 +46,8 @@ struct Param
std::string css_filename;
std::string font_suffix, font_format;
std::string external_hint_tool;
int debug;
int clean_tmp;
};

View File

@ -81,6 +81,7 @@ void parse_options (int argc, char **argv)
.add("css-filename", &param.css_filename, "", "Specify the file name of the generated css file")
.add("font-suffix", &param.font_suffix, ".ttf", "suffix for extracted font files")
.add("font-format", &param.font_format, "opentype", "format for extracted font files")
.add("external-hint-tool", &param.external_hint_tool, "", "external tool for hintting fonts")
.add("debug", &param.debug, 0, "output debug information")
.add("clean-tmp", &param.clean_tmp, 1, "clean temporary files after processing")