diff --git a/TODO b/TODO index fba441a..e891d9a 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,11 @@ +about glyph width: + - IE + - parameter for transform/trunc when width is too wide/narrow + - stretching ratio might not be correct.. + +better wrapper of ff + - need C++ class + try harder finding glyph names (using fontforge) for CID Type 0 rename single-html -> embed-font/image/css ... create a glyph for ' ', if there is not in a font diff --git a/src/HTMLRenderer/install.cc b/src/HTMLRenderer/install.cc index 0555b7a..e2bd654 100644 --- a/src/HTMLRenderer/install.cc +++ b/src/HTMLRenderer/install.cc @@ -110,24 +110,15 @@ void HTMLRenderer::install_base_font(GfxFont * font, GfxFontLoc * font_loc, Font string psname(font_loc->path->getCString()); string basename = psname.substr(0, psname.find('-')); - GfxFontLoc * localfontloc = font->locateFont(xref, gTrue); + GfxFontLoc * localfontloc = font->locateFont(xref, gFalse); if(param->embed_base_font) { if(localfontloc != nullptr) { - GooString * path = globalParams->findBase14FontFile(localfontloc->path, font); - if(path) - { - embed_font(string(path->getCString()), font, info); - export_remote_font(info, param->font_suffix, param->font_format, font); - delete localfontloc; - delete path; - return; - } - else - { - cerr << "Cannot embed base font: f" << hex << info.id << dec << ' ' << psname << endl; - } + embed_font(localfontloc->path->getCString(), font, info); + export_remote_font(info, param->font_suffix, param->font_format, font); + delete localfontloc; + return; } else { diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index 1a4b44f..9743fd0 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -189,14 +189,17 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo info.em_size = ffw_get_em_size(); if(get_metric_only) + { + ffw_metric(&info.ascent, &info.descent); + ffw_close(); return; + } used_map = preprocessor.get_code_map(hash_ref(font->getID())); /* * Step 1 - * dump the font file directly from the font descriptor and put the glyphs into the correct slots - * + * dump the font file directly from the font descriptor and put the glyphs into the correct slots * * for 8bit + nonTrueType * re-encoding the font using a PostScript encoding list (glyph id <-> glpyh name) * @@ -395,8 +398,8 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo } } - ffw_reencode_raw(cur_mapping, max_key + 1, 1); ffw_set_widths(width_list, max_key + 1); + ffw_reencode_raw(cur_mapping, max_key + 1, 1); if(ctu) ctu->decRefCnt(); @@ -458,6 +461,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo ffw_load_font(cur_tmp_fn.c_str()); ffw_metric(&info.ascent, &info.descent); ffw_save(fn.c_str()); + ffw_close(); } diff --git a/src/ffw.c b/src/ffw.c index e52e29e..99deb30 100644 --- a/src/ffw.c +++ b/src/ffw.c @@ -268,8 +268,10 @@ void ffw_metric(double * ascent, double * descent) if(a < 0) a = 0; if(d > 0) d = 0; + /* sf->ascent = min(a, em); sf->descent = em - bb.maxy; + */ info->os2_winascent = a; info->os2_typoascent = a; @@ -294,6 +296,15 @@ void ffw_metric(double * ascent, double * descent) */ void ffw_set_widths(int * width_list, int mapping_len) { + memset(cur_fv->selected, 1, cur_fv->map->enccount); + // remove kern + FVRemoveKerns(cur_fv); + FVRemoveVKerns(cur_fv); + // remove bearing + // TODO: optimize this, merge the transform matrix with width setting (below) + //FVSetWidthScript(cur_fv, wt_lbearing, 0, 0); + //FVSetWidthScript(cur_fv, wt_rbearing, 0, 0); + SplineFont * sf = cur_fv->sf; if(sf->onlybitmaps @@ -319,6 +330,20 @@ void ffw_set_widths(int * width_list, int mapping_len) SplineChar * sc = sf->glyphs[j]; if(sc == NULL) continue; + DBounds bb; + SplineCharFindBounds(sc, &bb); + + // TODO: add an option + double glyph_width = bb.maxx - bb.minx; + if(glyph_width > width_list[i]) + { + real transform[6]; + transform[0] = ((double)width_list[i]) / glyph_width; + transform[3] = 1.0; + transform[1] = transform[2] = transform[4] = transform[5] = 0; + FVTrans(cur_fv, sc, transform, NULL, fvt_alllayers | fvt_dontmovewidth); + } + sc->width = width_list[i]; } }