From 4f4cae9812ea4e1f4d78ea8b90a46d8f20519883 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 13 May 2018 01:39:08 +0800 Subject: Bug 699351: Handle glyphs with uncomputable width. Previously if a glyphs units per em was 0 we'd try to divide by zero, now mupdf assumes a default value and continues. --- source/pdf/pdf-font.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index 82739ccb..72e2a971 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -295,14 +295,20 @@ static int ft_width(fz_context *ctx, pdf_font_desc *fontdesc, int cid) int gid = ft_cid_to_gid(fontdesc, cid); FT_Fixed adv; int fterr; + FT_Face face = fontdesc->font->ft_face; + FT_UShort units_per_EM; - fterr = FT_Get_Advance(fontdesc->font->ft_face, gid, mask, &adv); + fterr = FT_Get_Advance(face, gid, mask, &adv); if (fterr) { fz_warn(ctx, "freetype advance glyph (gid %d): %s", gid, ft_error_string(fterr)); return 0; } - return adv * 1000 / ((FT_Face)fontdesc->font->ft_face)->units_per_EM; + units_per_EM = face->units_per_EM; + if (units_per_EM == 0) + units_per_EM = 2048; + + return adv * 1000 / units_per_EM; } static const struct { int code; const char *name; } mre_diff_table[] = -- cgit v1.2.3