1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-21 20:50:07 +00:00

fix glyph widths when not consistent with PDF [need more work]

This commit is contained in:
Lu Wang 2012-09-30 15:43:23 +08:00
parent 6b28049d76
commit dafc4b86dd
4 changed files with 45 additions and 17 deletions

8
TODO
View File

@ -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

View File

@ -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
{

View File

@ -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();
}

View File

@ -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];
}
}