diff --git a/pdf2htmlEX.1.in b/pdf2htmlEX.1.in
index 9df3065..71b8033 100644
--- a/pdf2htmlEX.1.in
+++ b/pdf2htmlEX.1.in
@@ -102,8 +102,8 @@ If this switch is on, local matched font will be used and embedded; otherwise on
Similar as above but for non-base fonts.
.TP
-.B --font-suffix (Default: .ttf), --font-format (Default: truetype)
-Specify the suffix and format of fonts extracted from the PDF file. They should be consistent.
+.B --font-suffix (Default: .ttf)
+Specify the suffix of fonts extracted from the PDF file.
.TP
.B --decompose-ligature <0|1> (Default: 0)
diff --git a/src/HTMLRenderer/HTMLRenderer.h b/src/HTMLRenderer/HTMLRenderer.h
index 532eedb..f94e013 100644
--- a/src/HTMLRenderer/HTMLRenderer.h
+++ b/src/HTMLRenderer/HTMLRenderer.h
@@ -248,7 +248,7 @@ class HTMLRenderer : public OutputDev
* remote font: to be retrieved from the web server
* 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_local_font(const FontInfo & info, GfxFont * font, const std::string & original_font_name, const std::string & cssfont);
diff --git a/src/HTMLRenderer/export.cc b/src/HTMLRenderer/export.cc
index 148f741..c9e1516 100644
--- a/src/HTMLRenderer/export.cc
+++ b/src/HTMLRenderer/export.cc
@@ -18,11 +18,38 @@
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{"
- << "font-family:f" << info.id << ";"
- << "src:url(";
+ << "font-family:f" << info.id << ";"
+ << "src:url(";
{
auto fn = str_fmt("f%llx%s", info.id, suffix.c_str());
@@ -32,7 +59,7 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff
ifstream fin(path, ifstream::binary);
if(!fin)
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
{
@@ -41,23 +68,23 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff
}
f_css.fs << ")"
- << "format(\"" << fontfileformat << "\");"
- << "}" // end of @font-face
- << ".f" << info.id << "{"
- << "font-family:f" << info.id << ";"
- << "line-height:" << round(info.ascent - info.descent) << ";"
- << "font-style:normal;"
- << "font-weight:normal;"
- << "visibility:visible;"
- << "}" // end of .f
- << endl;
+ << "format(\"" << format << "\");"
+ << "}" // end of @font-face
+ << ".f" << info.id << "{"
+ << "font-family:f" << info.id << ";"
+ << "line-height:" << round(info.ascent - info.descent) << ";"
+ << "font-style:normal;"
+ << "font-weight:normal;"
+ << "visibility:visible;"
+ << "}" // end of .f
+ << endl;
}
static string general_font_family(GfxFont * font)
{
- if(font -> isFixedWidth())
+ if(font->isFixedWidth())
return "monospace";
- else if (font -> isSerif())
+ else if (font->isSerif())
return "serif";
else
return "sans-serif";
diff --git a/src/HTMLRenderer/install.cc b/src/HTMLRenderer/install.cc
index 4dac8d2..1ec80ca 100644
--- a/src/HTMLRenderer/install.cc
+++ b/src/HTMLRenderer/install.cc
@@ -110,7 +110,7 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, FontInfo & info)
if(path != "")
{
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
{
@@ -129,7 +129,7 @@ void HTMLRenderer::install_base_font(GfxFont * font, GfxFontLoc * font_loc, Font
if(localfontloc != nullptr)
{
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;
return;
}
@@ -186,7 +186,7 @@ void HTMLRenderer::install_external_font(GfxFont * font, FontInfo & info)
if(localfontloc != nullptr)
{
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;
return;
}
diff --git a/src/Param.h b/src/Param.h
index fdabc8c..e8d6b90 100644
--- a/src/Param.h
+++ b/src/Param.h
@@ -34,7 +34,7 @@ struct Param
// fonts
int embed_base_font;
int embed_external_font;
- std::string font_suffix, font_format;
+ std::string font_suffix;
int decompose_ligature;
int remove_unused_glyph;
int auto_hint;
diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc
index 1bfe6cb..bee540d 100644
--- a/src/pdf2htmlEX.cc
+++ b/src/pdf2htmlEX.cc
@@ -54,6 +54,8 @@ void show_version_and_exit(const char * dummy = nullptr)
void parse_options (int argc, char **argv)
{
+ string deprecated_string;
+
argparser
// pages
.add("first-page,f", ¶m.first_page, 1, "first page to convert")
@@ -78,7 +80,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-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-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("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")
@@ -112,6 +113,11 @@ void parse_options (int argc, char **argv)
.add("", ¶m.input_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