diff --git a/src/HTMLRenderer.h b/src/HTMLRenderer.h index f9ba245..70a6722 100644 --- a/src/HTMLRenderer.h +++ b/src/HTMLRenderer.h @@ -216,7 +216,7 @@ class HTMLRenderer : public OutputDev const Param * param; boost::filesystem::path dest_dir, tmp_dir; - boost::filesystem::ofstream html_fout, allcss_fout, fontscript_fout; + boost::filesystem::ofstream html_fout, allcss_fout; }; #endif /* HTMLRENDERER_H_ */ diff --git a/src/HTMLRenderer/export.cc b/src/HTMLRenderer/export.cc index 13c660c..f7cf8f2 100644 --- a/src/HTMLRenderer/export.cc +++ b/src/HTMLRenderer/export.cc @@ -17,20 +17,16 @@ using boost::algorithm::ifind_first; void HTMLRenderer::export_remote_font(long long fn_id, const string & suffix, const string & fontfileformat, GfxFont * font) { - - //allcss_fout << format("@font-face{font-family:f%|1$x|;src:url(f%|1$x|%2%)format(\"%3%\");}.f%|1$x|{font-family:f%|1$x|;") % fn_id % suffix % fontfileformat; - allcss_fout << format("@font-face{font-family:f%|1$x|;src:url(") % fn_id; + const std::string fn = (format("f%|1$x|%2%") % fn_id % suffix).str(); if(param->single_html) { - allcss_fout << "'data:font/" << fontfileformat << ";base64,"; - //TODO - allcss_fout << "'"; + allcss_fout << "'data:font/" << fontfileformat << ";base64," << base64_filter(ifstream(tmp_dir / fn, ifstream::binary)) << "'"; } else { - allcss_fout << format("f%|1$x|%2%") % fn_id % suffix; + allcss_fout << fn; } allcss_fout << format(")format(\"%1%\");}.f%|2$x|{font-family:f%|2$x|;") % fontfileformat % fn_id; diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index a746328..fa05ee1 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -88,7 +88,6 @@ void HTMLRenderer::pre_process() // we may output utf8 characters, so use binary html_fout.open(working_dir() / param->output_filename, ofstream::binary); allcss_fout.open(working_dir() / "all.css", ofstream::binary); - fontscript_fout.open(tmp_dir / "pdf2htmlEX.pe", ofstream::binary); if(!param->single_html) { @@ -109,7 +108,6 @@ void HTMLRenderer::post_process() html_fout.close(); allcss_fout.close(); - fontscript_fout.close(); if(param->single_html) { diff --git a/src/HTMLRenderer/install.cc b/src/HTMLRenderer/install.cc index 42f59a8..eab1546 100644 --- a/src/HTMLRenderer/install.cc +++ b/src/HTMLRenderer/install.cc @@ -119,7 +119,10 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, string fn = (format("f%|1$x|") % fn_id).str(); - fontscript_fout << format("Open(%1%, 1)") % (tmp_dir / (fn + suffix)) << endl; + path script_path = tmp_dir / "pdf2htmlEX.pe"; + ofstream script_fout(script_path, ofstream::binary); + + script_fout << format("Open(%1%, 1)") % (tmp_dir / (fn + suffix)) << endl; auto ctu = font->getToUnicode(); int * code2GID = nullptr; @@ -137,11 +140,11 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, maxcode = 0xffff; if(suffix != ".ttf") { - fontscript_fout << "CIDFlatten()" << endl; + script_fout << "CIDFlatten()" << endl; } else { - fontscript_fout << format("Reencode(\"original\")") << endl; + script_fout << format("Reencode(\"original\")") << endl; int len; // code2GID has been stored for embedded CID fonts code2GID = dynamic_cast(font)->getCodeToGIDMap(nullptr, &len); @@ -169,15 +172,17 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, const string & suffix, if(cnt > 0) { - fontscript_fout << format("LoadEncodingFile(%1%, \"%2%\")") % (tmp_dir / (fn+".encoding")) % fn << endl; - fontscript_fout << format("Reencode(\"%1%\", 1)") % fn << endl; + script_fout << format("LoadEncodingFile(%1%, \"%2%\")") % (tmp_dir / (fn+".encoding")) % fn << endl; + script_fout << format("Reencode(\"%1%\", 1)") % fn << endl; } } ctu->decRefCnt(); } - fontscript_fout << format("Generate(%1%)") % (dest_dir / (fn+".ttf")) << endl; + script_fout << format("Generate(%1%)") % (working_dir() / (fn+".ttf")) << endl; + + system((boost::format("fontforge -script %1% 2>") % script_path).str().c_str()); export_remote_font(fn_id, ".ttf", "truetype", font); }