summaryrefslogtreecommitdiff
path: root/fitz/res_font.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-04-24 21:40:53 +0200
committerTor Andersson <tor@ghostscript.com>2010-04-24 21:40:53 +0200
commit00bf23444ca93b9b6f6b8c9a3a6f10b535698acf (patch)
tree417d73d893de83b4a06cb128d16fa0fb485e2054 /fitz/res_font.c
parenteac58058a2ff46fda09fd9e28f9ad908b79d2031 (diff)
downloadmupdf-00bf23444ca93b9b6f6b8c9a3a6f10b535698acf.tar.xz
Add font width scaling for rendering substituted fonts.
Diffstat (limited to 'fitz/res_font.c')
-rw-r--r--fitz/res_font.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/fitz/res_font.c b/fitz/res_font.c
index f7b29773..90321523 100644
--- a/fitz/res_font.c
+++ b/fitz/res_font.c
@@ -30,6 +30,9 @@ fz_newfont(void)
font->bbox.x1 = 1000;
font->bbox.y1 = 1000;
+ font->widthcount = 0;
+ font->widthtable = nil;
+
return font;
}
@@ -67,6 +70,9 @@ fz_dropfont(fz_font *font)
fz_finalizefreetype();
}
+ if (font->widthtable)
+ fz_free(font->widthtable);
+
fz_free(font);
}
}
@@ -215,37 +221,32 @@ fz_renderftglyph(fz_font *font, int gid, fz_matrix trm)
fz_pixmap *glyph;
int y;
-#if 0
- /* We lost this feature in refactoring.
- * We can't access pdf_fontdesc metrics from fz_font.
- * The pdf_fontdesc metrics are character based (cid),
- * where the glyph being rendered is given by glyph (gid).
- */
- if (font->ftsubstitute && font->wmode == 0)
+ /* Fudge the font matrix to stretch the glyph if we've substituted the font. */
+ if (font->ftsubstitute && gid < font->widthcount)
{
- fz_hmtx subw;
+ int subw;
int realw;
float scale;
+ /* TODO: use FT_Get_Advance */
fterr = FT_Set_Char_Size(face, 1000, 1000, 72, 72);
if (fterr)
- return fz_warn("freetype setting character size: %s", ft_errorstring(fterr));
+ fz_warn("freetype setting character size: %s", ft_errorstring(fterr));
fterr = FT_Load_Glyph(font->ftface, gid,
FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM);
if (fterr)
- return fz_throw("freetype failed to load glyph: %s", ft_errorstring(fterr));
+ fz_warn("freetype failed to load glyph: %s", ft_errorstring(fterr));
realw = ((FT_Face)font->ftface)->glyph->advance.x;
- subw = fz_gethmtx(font, cid); // <-- this is the offender
+ subw = font->widthtable[gid];
if (realw)
- scale = (float) subw.w / realw;
+ scale = (float) subw / realw;
else
scale = 1.0;
trm = fz_concat(fz_scale(scale, 1.0), trm);
}
-#endif
/* freetype mutilates complex glyphs if they are loaded
* with FT_Set_Char_Size 1.0. it rounds the coordinates