mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
font embedding
This commit is contained in:
parent
5a157def7e
commit
58eaeb8f22
@ -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_ */
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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<GfxCIDFont*>(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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user