diff --git a/src/HTMLRenderer/export.cc b/src/HTMLRenderer/export.cc
index 067762a..88a7321 100644
--- a/src/HTMLRenderer/export.cc
+++ b/src/HTMLRenderer/export.cc
@@ -21,17 +21,17 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff
{
allcss_fout << "@font-face{font-family:f" << info.id << ";src:url(";
- const char * fn = str_fmt("f%llx%s", info.id, suffix.c_str());
-
- if(param->single_html)
{
- allcss_fout << "'data:font/" << fontfileformat << ";base64," << base64stream(ifstream(tmp_dir / fn, ifstream::binary)) << "'";
+ const char * fn = str_fmt("f%llx%s", info.id, suffix.c_str());
+ if(param->single_html)
+ {
+ allcss_fout << "'data:font/" << fontfileformat << ";base64," << base64stream(ifstream(tmp_dir / fn, ifstream::binary)) << "'";
+ }
+ else
+ {
+ allcss_fout << fn;
+ }
}
- else
- {
- allcss_fout << fn;
- }
-
allcss_fout << ")format(\"" << fontfileformat << "\");}.f" << info.id << "{font-family:f" << info.id << ";line-height:" << (info.ascent - info.descent) << ";}" << endl;
}
diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc
index ce7d2c6..789d901 100644
--- a/src/HTMLRenderer/general.cc
+++ b/src/HTMLRenderer/general.cc
@@ -92,10 +92,12 @@ void HTMLRenderer::process(PDFDoc *doc)
0, true, false, false,
nullptr, nullptr, &annot_cb, nullptr);
- const char * fn = str_fmt("p%x.png", i);
- bg_renderer->getBitmap()->writeImgFile(splashFormatPng, (char*)((param->single_html ? tmp_dir : dest_dir) / fn) .c_str(), param->h_dpi, param->v_dpi);
- if(param->single_html)
- add_tmp_file(fn);
+ {
+ const char * fn = str_fmt("p%llx.png", i);
+ bg_renderer->getBitmap()->writeImgFile(splashFormatPng, (char*)((param->single_html ? tmp_dir : dest_dir) / fn) .c_str(), param->h_dpi, param->v_dpi);
+ if(param->single_html)
+ add_tmp_file(fn);
+ }
}
doc->displayPage(this, i, param->zoom * DEFAULT_DPI, param->zoom * DEFAULT_DPI,
@@ -171,15 +173,17 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state)
html_fout << "background-image:url(";
- const char * fn = str_fmt("p%x.png", pageNum);
- if(param->single_html)
{
- auto path = tmp_dir / fn;
- html_fout << "'data:image/png;base64," << base64stream(ifstream(path, ifstream::binary)) << "'";
- }
- else
- {
- html_fout << fn;
+ const char * fn = str_fmt("p%llx.png", pageNum);
+ if(param->single_html)
+ {
+ auto path = tmp_dir / fn;
+ html_fout << "'data:image/png;base64," << base64stream(ifstream(path, ifstream::binary)) << "'";
+ }
+ else
+ {
+ html_fout << fn;
+ }
}
html_fout << ");background-position:0 0;background-size:" << pageWidth << "px " << pageHeight << "px;background-repeat:no-repeat;\">";
diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc
index 7f8d9db..a228ce8 100644
--- a/src/HTMLRenderer/text.cc
+++ b/src/HTMLRenderer/text.cc
@@ -126,11 +126,13 @@ path HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id)
obj.streamReset();
- const char * fn = str_fmt("f%x%s", fn_id, suffix.c_str());
ofstream outf;
- filepath = tmp_dir / fn;
- outf.open(filepath, ofstream::binary);
- add_tmp_file(fn);
+ {
+ const char * fn = str_fmt("f%llx%s", fn_id, suffix.c_str());
+ filepath = tmp_dir / fn;
+ outf.open(filepath, ofstream::binary);
+ add_tmp_file(fn);
+ }
char buf[1024];
int len;
@@ -329,51 +331,56 @@ void HTMLRenderer::embed_font(const path & filepath, GfxFont * font, FontInfo &
}
}
- const char * fn = str_fmt("f%x%s", info.id, param->font_suffix.c_str());
- auto dest = ((param->single_html ? tmp_dir : dest_dir) / fn);
- if(param->single_html)
+ {
+ const char * fn = str_fmt("f%llx_.ttf", info.id);
+
+ /*
+ * [Win|Typo|HHead][Ascent|Descent]
+ * Firefox & Chrome interprets the values in different ways
+ * Trying to unify them
+ */
+ // Generate an intermediate ttf font in order to retrieve the metrics
+ // TODO: see if we can get the values without save/load
+
add_tmp_file(fn);
-
- /*
- * [Win|Typo|HHead][Ascent|Descent]
- * Firefox & Chrome interprets the values in different ways
- * Trying to unify them
- */
- // Generate an intermediate ttf font in order to retrieve the metrics
- // TODO: see if we can get the values without save/load
-
- fn = str_fmt("f%x_.ttf", info.id);
- add_tmp_file(fn);
- auto tmp_path = tmp_dir / fn;
- ff_save(tmp_path.c_str());
- ff_close();
- ff_load_font(tmp_path.c_str());
-
- int em = ff_get_em_size();
- int ascent = ff_get_max_ascent();
- int descent = ff_get_max_descent();
-
- ff_set_ascent(ascent);
- ff_set_descent(descent);
- ff_save(dest.c_str());
- ff_close();
-
- if(em != 0)
- {
- info.ascent = ((double)ascent) / em;
- info.descent = -((double)descent) / em;
- }
- else
- {
- info.ascent = 0;
- info.descent = 0;
+ auto tmp_path = tmp_dir / fn;
+ ff_save(tmp_path.c_str());
+ ff_close();
+ ff_load_font(tmp_path.c_str());
}
- // read metric
-
- if(param->debug)
{
- cerr << "Ascent: " << info.ascent << " Descent: " << info.descent << endl;
+ // read metrics
+ int em = ff_get_em_size();
+ int ascent = ff_get_max_ascent();
+ int descent = ff_get_max_descent();
+ if(em != 0)
+ {
+ info.ascent = ((double)ascent) / em;
+ info.descent = -((double)descent) / em;
+ }
+ else
+ {
+ info.ascent = 0;
+ info.descent = 0;
+ }
+ if(param->debug)
+ {
+ cerr << "Ascent: " << info.ascent << " Descent: " << info.descent << endl;
+ }
+
+ ff_set_ascent(ascent);
+ ff_set_descent(descent);
+ }
+
+ {
+ const char * fn = str_fmt("f%llx%s", info.id, param->font_suffix.c_str());
+ auto dest = ((param->single_html ? tmp_dir : dest_dir) / fn);
+ if(param->single_html)
+ add_tmp_file(fn);
+
+ ff_save(dest.c_str());
+ ff_close();
}
}
diff --git a/src/util.h b/src/util.h
index aa1b554..0b8ae4b 100644
--- a/src/util.h
+++ b/src/util.h
@@ -33,6 +33,7 @@ using std::endl;
using std::flush;
using std::cerr;
using std::floor;
+using std::max;
// mute gcc warning of unused function
namespace
@@ -275,9 +276,9 @@ public:
va_start(vlist, format);
int l = vsnprintf(&buf.front(), buf.capacity(), format, vlist);
va_end(vlist);
- if((l+1) > (int)buf.capacity())
+ if(l >= (int)buf.capacity())
{
- buf.reserve(l+1);
+ buf.reserve(max((long)(l+1), (long)buf.capacity() * 2));
va_start(vlist, format);
l = vsnprintf(&buf.front(), buf.capacity(), format, vlist);
va_end(vlist);