mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-10-05 19:41:40 +00:00
automatically infer @font-face src format
This commit is contained in:
parent
2f1c8170bf
commit
6fda07bec3
@ -109,8 +109,8 @@ If this switch is on, local matched font will be used and embedded; otherwise on
|
|||||||
Similar as above but for non-base fonts.
|
Similar as above but for non-base fonts.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B --font-suffix <suffix> (Default: .ttf), --font-format <format> (Default: truetype)
|
.B --font-suffix <suffix> (Default: .ttf)
|
||||||
Specify the suffix and format of fonts extracted from the PDF file. They should be consistent.
|
Specify the suffix of fonts extracted from the PDF file.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B --decompose-ligature <0|1> (Default: 0)
|
.B --decompose-ligature <0|1> (Default: 0)
|
||||||
|
@ -248,7 +248,7 @@ class HTMLRenderer : public OutputDev
|
|||||||
* remote font: to be retrieved from the web server
|
* remote font: to be retrieved from the web server
|
||||||
* local font: to be substituted with a local (client side) font
|
* local font: to be substituted with a local (client side) font
|
||||||
*/
|
*/
|
||||||
void export_remote_font(const FontInfo & info, const std::string & suffix, const std::string & fontfileformat, GfxFont * font);
|
void export_remote_font(const FontInfo & info, const std::string & suffix, GfxFont * font);
|
||||||
void export_remote_default_font(long long fn_id);
|
void export_remote_default_font(long long fn_id);
|
||||||
void export_local_font(const FontInfo & info, GfxFont * font, const std::string & original_font_name, const std::string & cssfont);
|
void export_local_font(const FontInfo & info, GfxFont * font, const std::string & original_font_name, const std::string & cssfont);
|
||||||
|
|
||||||
|
@ -18,8 +18,30 @@
|
|||||||
|
|
||||||
namespace pdf2htmlEX {
|
namespace pdf2htmlEX {
|
||||||
|
|
||||||
void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suffix, const string & fontfileformat, GfxFont * font)
|
void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suffix, GfxFont * font)
|
||||||
{
|
{
|
||||||
|
string mime_type, format;
|
||||||
|
if (suffix == ".ttf") {
|
||||||
|
format = "truetype";
|
||||||
|
mime_type = "application/x-font-ttf";
|
||||||
|
}
|
||||||
|
else if (suffix == ".otf") {
|
||||||
|
format = "opentype";
|
||||||
|
mime_type = "application/x-font-otf";
|
||||||
|
}
|
||||||
|
else if (suffix == ".woff") {
|
||||||
|
format = "woff";
|
||||||
|
mime_type = "application/font-woff";
|
||||||
|
}
|
||||||
|
else if (suffix == ".eot") {
|
||||||
|
format = "embedded-opentype";
|
||||||
|
mime_type = "application/vnd.ms-fontobject";
|
||||||
|
}
|
||||||
|
else if (suffix == ".svg") {
|
||||||
|
format = "svg";
|
||||||
|
mime_type = "image/svg+xml";
|
||||||
|
}
|
||||||
|
|
||||||
f_css.fs << "@font-face{"
|
f_css.fs << "@font-face{"
|
||||||
<< "font-family:f" << info.id << ";"
|
<< "font-family:f" << info.id << ";"
|
||||||
<< "src:url(";
|
<< "src:url(";
|
||||||
@ -32,7 +54,7 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff
|
|||||||
ifstream fin(path, ifstream::binary);
|
ifstream fin(path, ifstream::binary);
|
||||||
if(!fin)
|
if(!fin)
|
||||||
throw "Cannot locate font file: " + path;
|
throw "Cannot locate font file: " + path;
|
||||||
f_css.fs << "'data:font/" + fontfileformat + ";base64," << base64stream(fin) << "'";
|
f_css.fs << "'data:font/" + mime_type + ";base64," << base64stream(fin) << "'";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -41,7 +63,7 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff
|
|||||||
}
|
}
|
||||||
|
|
||||||
f_css.fs << ")"
|
f_css.fs << ")"
|
||||||
<< "format(\"" << fontfileformat << "\");"
|
<< "format(\"" << format << "\");"
|
||||||
<< "}" // end of @font-face
|
<< "}" // end of @font-face
|
||||||
<< ".f" << info.id << "{"
|
<< ".f" << info.id << "{"
|
||||||
<< "font-family:f" << info.id << ";"
|
<< "font-family:f" << info.id << ";"
|
||||||
@ -51,7 +73,7 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff
|
|||||||
<< "visibility:visible;"
|
<< "visibility:visible;"
|
||||||
<< "}" // end of .f
|
<< "}" // end of .f
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string general_font_family(GfxFont * font)
|
static string general_font_family(GfxFont * font)
|
||||||
{
|
{
|
||||||
|
@ -110,7 +110,7 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, FontInfo & info)
|
|||||||
if(path != "")
|
if(path != "")
|
||||||
{
|
{
|
||||||
embed_font(path, font, info);
|
embed_font(path, font, info);
|
||||||
export_remote_font(info, param->font_suffix, param->font_format, font);
|
export_remote_font(info, param->font_suffix, font);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -129,7 +129,7 @@ void HTMLRenderer::install_base_font(GfxFont * font, GfxFontLoc * font_loc, Font
|
|||||||
if(localfontloc != nullptr)
|
if(localfontloc != nullptr)
|
||||||
{
|
{
|
||||||
embed_font(localfontloc->path->getCString(), font, info);
|
embed_font(localfontloc->path->getCString(), font, info);
|
||||||
export_remote_font(info, param->font_suffix, param->font_format, font);
|
export_remote_font(info, param->font_suffix, font);
|
||||||
delete localfontloc;
|
delete localfontloc;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ void HTMLRenderer::install_external_font(GfxFont * font, FontInfo & info)
|
|||||||
if(localfontloc != nullptr)
|
if(localfontloc != nullptr)
|
||||||
{
|
{
|
||||||
embed_font(string(localfontloc->path->getCString()), font, info);
|
embed_font(string(localfontloc->path->getCString()), font, info);
|
||||||
export_remote_font(info, param->font_suffix, param->font_format, font);
|
export_remote_font(info, param->font_suffix, font);
|
||||||
delete localfontloc;
|
delete localfontloc;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ struct Param
|
|||||||
// fonts
|
// fonts
|
||||||
int embed_base_font;
|
int embed_base_font;
|
||||||
int embed_external_font;
|
int embed_external_font;
|
||||||
std::string font_suffix, font_format;
|
std::string font_suffix;
|
||||||
int decompose_ligature;
|
int decompose_ligature;
|
||||||
int remove_unused_glyph;
|
int remove_unused_glyph;
|
||||||
int auto_hint;
|
int auto_hint;
|
||||||
|
@ -53,6 +53,8 @@ void show_version_and_exit(const char * dummy = nullptr)
|
|||||||
|
|
||||||
void parse_options (int argc, char **argv)
|
void parse_options (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
string deprecated_string;
|
||||||
|
|
||||||
argparser
|
argparser
|
||||||
// pages
|
// pages
|
||||||
.add("first-page,f", ¶m.first_page, 1, "first page to convert")
|
.add("first-page,f", ¶m.first_page, 1, "first page to convert")
|
||||||
@ -77,7 +79,6 @@ void parse_options (int argc, char **argv)
|
|||||||
.add("embed-base-font", ¶m.embed_base_font, 0, "embed local match for standard 14 fonts")
|
.add("embed-base-font", ¶m.embed_base_font, 0, "embed local match for standard 14 fonts")
|
||||||
.add("embed-external-font", ¶m.embed_external_font, 0, "embed local match for external fonts")
|
.add("embed-external-font", ¶m.embed_external_font, 0, "embed local match for external fonts")
|
||||||
.add("font-suffix", ¶m.font_suffix, ".ttf", "suffix for embedded font files (.ttf,.otf,.woff,.svg)")
|
.add("font-suffix", ¶m.font_suffix, ".ttf", "suffix for embedded font files (.ttf,.otf,.woff,.svg)")
|
||||||
.add("font-format", ¶m.font_format, "opentype", "CSS @font-face format for embedded fonts")
|
|
||||||
.add("decompose-ligature", ¶m.decompose_ligature, 0, "decompose ligatures, such as \uFB01 -> fi")
|
.add("decompose-ligature", ¶m.decompose_ligature, 0, "decompose ligatures, such as \uFB01 -> fi")
|
||||||
.add("remove-unused-glyph", ¶m.remove_unused_glyph, 1, "remove unused glyphs in embedded fonts")
|
.add("remove-unused-glyph", ¶m.remove_unused_glyph, 1, "remove unused glyphs in embedded fonts")
|
||||||
.add("auto-hint", ¶m.auto_hint, 0, "use fontforge autohint on fonts without hints")
|
.add("auto-hint", ¶m.auto_hint, 0, "use fontforge autohint on fonts without hints")
|
||||||
@ -111,6 +112,11 @@ void parse_options (int argc, char **argv)
|
|||||||
|
|
||||||
.add("", ¶m.input_filename, "", "")
|
.add("", ¶m.input_filename, "", "")
|
||||||
.add("", ¶m.output_filename, "", "")
|
.add("", ¶m.output_filename, "", "")
|
||||||
|
|
||||||
|
// deprecated
|
||||||
|
.add("font-format", &deprecated_string, "", "", [] (const char*) {
|
||||||
|
cerr << "warning: --font-format is deprecated, @font-face format is inferred from --font-suffix" << endl;
|
||||||
|
})
|
||||||
;
|
;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
Loading…
Reference in New Issue
Block a user