1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

cosmetic changes

This commit is contained in:
John Hewson 2013-01-29 18:13:48 +00:00
parent b2d28e2490
commit b9763d1072

View File

@ -18,62 +18,67 @@
namespace pdf2htmlEX {
void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suffix, GfxFont * font)
void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suffix, GfxFont * font)
{
string mime_type, format;
if(suffix == ".ttf")
{
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(";
{
auto fn = str_fmt("f%llx%s", info.id, suffix.c_str());
if(param->single_html)
{
auto path = param->tmp_dir + "/" + (char*)fn;
ifstream fin(path, ifstream::binary);
if(!fin)
throw "Cannot locate font file: " + path;
f_css.fs << "'data:font/" + mime_type + ";base64," << base64stream(fin) << "'";
}
else
{
f_css.fs << (char*)fn;
}
}
f_css.fs << ")"
<< "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;
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(";
{
auto fn = str_fmt("f%llx%s", info.id, suffix.c_str());
if(param->single_html)
{
auto path = param->tmp_dir + "/" + (char*)fn;
ifstream fin(path, ifstream::binary);
if(!fin)
throw "Cannot locate font file: " + path;
f_css.fs << "'data:font/" + mime_type + ";base64," << base64stream(fin) << "'";
}
else
{
f_css.fs << (char*)fn;
}
}
f_css.fs << ")"
<< "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)
{