From 12676ccc4a9be7e2c31e8350431719888d3f4768 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Mon, 8 Oct 2012 16:26:19 +0800 Subject: [PATCH] create a glyph for ' ' when there is not one --- TODO | 2 -- src/HTMLRenderer/export.cc | 6 ------ src/HTMLRenderer/general.cc | 2 +- src/HTMLRenderer/text.cc | 20 ++++++++++++++++-- src/ffw.c | 42 ++++++++++++++++++++----------------- src/include/ffw.h | 27 ++++++++++++++++++------ src/include/util.h | 1 - 7 files changed, 63 insertions(+), 37 deletions(-) diff --git a/TODO b/TODO index 88ec458..0a60914 100644 --- a/TODO +++ b/TODO @@ -6,8 +6,6 @@ native support for draw draw non-orthogonal lines with CSS -create a glyph for ' ', if there is not in a font - position history stack (popstate) ==Wait until someone asks== diff --git a/src/HTMLRenderer/export.cc b/src/HTMLRenderer/export.cc index 62a1856..6caec63 100644 --- a/src/HTMLRenderer/export.cc +++ b/src/HTMLRenderer/export.cc @@ -41,12 +41,6 @@ void HTMLRenderer::export_remote_font(const FontInfo & info, const string & suff << ";line-height:" << _round(info.ascent - info.descent) << ";font-style:normal;font-weight:normal;}"; - // 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; } diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index b8c214f..de17caf 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -55,7 +55,7 @@ HTMLRenderer::HTMLRenderer(const Param * param) HTMLRenderer::~HTMLRenderer() { - ffw_fin(); + ffw_finalize(); clean_tmp_files(); delete [] cur_mapping; delete [] cur_mapping2; diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index 668cbc9..d6c6cfa 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -190,7 +190,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo * if parm->tounicode is 0, try the provided tounicode map first */ info.use_tounicode = (is_truetype_suffix(suffix) || (param->tounicode >= 0)); - info.has_space = false; + bool has_space = false; const char * used_map = nullptr; @@ -360,7 +360,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo } if(u == ' ') - info.has_space = true; + has_space = true; if(codeset.insert(u).second) { @@ -410,6 +410,22 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo ffw_reencode_raw(cur_mapping, max_key + 1, 1); + // we need the space chracter for offsets + if(!has_space) + { + int space_width; + if(font_8bit) + { + space_width = (int)floor(font_8bit->getWidth(' ') * info.em_size + 0.5); + } + else + { + char buf[2] = {0, ' '}; + space_width = (int)floor(font_cid->getWidth(buf, 2) * info.em_size + 0.5); + } + ffw_make_char((int)' ', space_width); + } + if(ctu) ctu->decRefCnt(); } diff --git a/src/ffw.c b/src/ffw.c index f5cdc04..d0e0858 100644 --- a/src/ffw.c +++ b/src/ffw.c @@ -77,7 +77,7 @@ void ffw_init(int debug) } } -void ffw_fin(void) +void ffw_finalize(void) { while(enc_head) { @@ -147,6 +147,26 @@ void ffw_prepare_font(void) } } +void ffw_save(const char * filename) +{ + char * _filename = strcopy(filename); + char * _ = strcopy(""); + + int r = GenerateScript(cur_fv->sf, _filename + , _, -1, -1, NULL, NULL, cur_fv->map, NULL, ly_fore); + + free(_); + free(_filename); + + if(!r) + err("Cannot save font to %s\n", filename); +} +void ffw_close(void) +{ + FontViewClose(cur_fv); + cur_fv = NULL; +} + static void ffw_do_reencode(Encoding * encoding, int force) { assert(encoding); @@ -235,25 +255,9 @@ void ffw_cidflatten(void) SFFlatten(cur_fv->sf->cidmaster); } -void ffw_save(const char * filename) +void ffw_make_char(int enc, int width) { - char * _filename = strcopy(filename); - char * _ = strcopy(""); - - int r = GenerateScript(cur_fv->sf, _filename - , _, -1, -1, NULL, NULL, cur_fv->map, NULL, ly_fore); - - free(_); - free(_filename); - - if(!r) - err("Cannot save font to %s\n", filename); -} - -void ffw_close(void) -{ - FontViewClose(cur_fv); - cur_fv = NULL; + SFMakeChar(cur_fv->sf, cur_fv->map, enc)->width = width; } int ffw_get_em_size(void) diff --git a/src/include/ffw.h b/src/include/ffw.h index 8c34870..d388677 100644 --- a/src/include/ffw.h +++ b/src/include/ffw.h @@ -19,18 +19,31 @@ extern "C" { #include #endif - +//////////////////////// +// global void ffw_init(int debug); -void ffw_fin(void); +void ffw_finalize(void); + +//////////////////////// +// load & save void ffw_load_font(const char * filename); void ffw_prepare_font(void); -void ffw_reencode_glyph_order(void); -void ffw_reencode_raw(int32_t * mapping, int mapping_len, int force); -void ffw_reencode_raw2(char ** mapping, int mapping_len, int force); -void ffw_cidflatten(void); + void ffw_save(const char * filename); void ffw_close(void); +//////////////////////// +// encoding +void ffw_reencode_glyph_order(void); +void ffw_reencode_raw(int32_t * mapping, int mapping_len, int force); +void ffw_reencode_raw2(char ** mapping, int mapping_len, int force); + +void ffw_cidflatten(void); +// get or create the char, and set the width +void ffw_make_char(int enc, int width); + +//////////////////////// +// metrics int ffw_get_em_size(void); // fix metrics and get them void ffw_metric(double * ascent, double * descent); @@ -39,6 +52,8 @@ void ffw_set_widths(int * width_list, int mapping_len, int stretch_narrow, int squeeze_wide, int remove_unused); +//////////////////////// +// others void ffw_auto_hint(void); #ifdef __cplusplus diff --git a/src/include/util.h b/src/include/util.h index ffae09e..bb09467 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -103,7 +103,6 @@ public: bool use_tounicode; int em_size; double ascent, descent; - bool has_space; // whether space is included in the font }; class Matrix_less