diff --git a/share/base.css b/share/base.css index aee1193..533a67f 100644 --- a/share/base.css +++ b/share/base.css @@ -41,7 +41,6 @@ span { } ._ { color:transparent; - font-size:1px; } ::selection{ background: rgba(127,255,255,1); diff --git a/src/HTMLRenderer/export.cc b/src/HTMLRenderer/export.cc index 4b8193f..fa5a706 100644 --- a/src/HTMLRenderer/export.cc +++ b/src/HTMLRenderer/export.cc @@ -35,7 +35,15 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff } } - css_fout << ")format(\"" << fontfileformat << "\");}.f" << info.id << "{font-family:f" << info.id << ";line-height:" << _round(info.ascent - info.descent) << ";}" << endl; + css_fout << ")format(\"" << fontfileformat << "\");}.f" << info.id << "{font-family:f" << info.id << ";line-height:" << _round(info.ascent - info.descent) << ";}"; + + // when ' ' is not vaild in the font, when we use ' ' in padding + // the browser will use the fallback font, whose metrics could be (very) different, then the layout will be affected + // so set the font-zie to avoid being affected + if(!(info.has_space)) + css_fout << ".f" << info.id << ">._{font-size:1px;}"; + + css_fout << endl; } static string general_font_family(GfxFont * font) diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index 5ad0f17..7ddc7e0 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -171,6 +171,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo *iter = tolower(*iter); info.use_tounicode = (is_truetype_suffix(suffix) || (param->tounicode > 0)); + info.has_space = false; const char * used_map = nullptr; @@ -321,6 +322,9 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo u = unicode_from_font(i, font); } + if(u == ' ') + info.has_space = true; + if(codeset.insert(u).second) { cur_mapping[k] = u; diff --git a/src/include/util.h b/src/include/util.h index d93e93a..18cd4b4 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -110,6 +110,7 @@ public: long long id; bool use_tounicode; double ascent, descent; + bool has_space; // whether space is included in the font }; // wrapper of the transform matrix double[6]