From 4ed1b8523f813f4b94b33fd1c6109cdd24179056 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 5 Apr 2018 14:21:43 +0200 Subject: Rework how we handle DynaLab tricky fonts in freetype. Force the face_flags to include TRICKY if we detect a DynaLab font name instead of trying to force hinting ourselves. --- include/mupdf/fitz/font.h | 1 - source/fitz/font.c | 43 ++----------------------------------------- source/pdf/pdf-font.c | 5 +++-- 3 files changed, 5 insertions(+), 44 deletions(-) diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h index d9375315..654e8146 100644 --- a/include/mupdf/fitz/font.h +++ b/include/mupdf/fitz/font.h @@ -72,7 +72,6 @@ typedef struct unsigned int fake_bold : 1; /* synthesize bold */ unsigned int fake_italic : 1; /* synthesize italic */ - unsigned int force_hinting : 1; /* force hinting for DynaLab fonts */ unsigned int has_opentype : 1; /* has opentype shaping tables */ unsigned int invalid_bbox : 1; } fz_font_flags_t; diff --git a/source/fitz/font.c b/source/fitz/font.c index e822703f..de69ff9c 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -48,7 +48,6 @@ fz_new_font(fz_context *ctx, const char *name, int use_glyph_bbox, int glyph_cou font->flags.ft_substitute = 0; font->flags.fake_bold = 0; font->flags.fake_italic = 0; - font->flags.force_hinting = 0; font->flags.has_opentype = 0; font->t3matrix = fz_identity; @@ -776,21 +775,6 @@ do_ft_render_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *trm goto retry_unhinted; } } - else if (font->flags.force_hinting) - { - /* - Enable hinting, but keep the huge char size so that - it is hinted for a character. This will in effect nullify - the effect of grid fitting. This form of hinting should - only be used for DynaLab and similar tricky TrueType fonts, - so that we get the correct outline shape. - */ - fterr = FT_Load_Glyph(face, gid, FT_LOAD_NO_BITMAP); - if (fterr) { - fz_warn(ctx, "freetype load hinted glyph (gid %d): %s", gid, ft_error_string(fterr)); - goto retry_unhinted; - } - } else { retry_unhinted: @@ -1037,7 +1021,6 @@ fz_bound_ft_glyph(fz_context *ctx, fz_font *font, int gid) FT_BBox cbox; FT_Matrix m; FT_Vector v; - int ft_flags; fz_rect *bounds = &font->bbox_table[gid]; // TODO: refactor loading into fz_load_ft_glyph @@ -1060,15 +1043,6 @@ fz_bound_ft_glyph(fz_context *ctx, fz_font *font, int gid) v.x = local_trm.e * 65536; v.y = local_trm.f * 65536; - if (font->flags.force_hinting) - { - ft_flags = FT_LOAD_NO_BITMAP; - } - else - { - ft_flags = FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING; - } - fz_lock(ctx, FZ_LOCK_FREETYPE); /* Set the char size to scale=face->units_per_EM to effectively give * us unscaled results. This avoids quantisation. We then apply the @@ -1078,7 +1052,7 @@ fz_bound_ft_glyph(fz_context *ctx, fz_font *font, int gid) fz_warn(ctx, "freetype setting character size: %s", ft_error_string(fterr)); FT_Set_Transform(face, &m, &v); - fterr = FT_Load_Glyph(face, gid, ft_flags); + fterr = FT_Load_Glyph(face, gid, FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING); if (fterr) { fz_warn(ctx, "freetype load glyph (gid %d): %s", gid, ft_error_string(fterr)); @@ -1182,7 +1156,6 @@ fz_outline_ft_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *tr FT_Face face = font->ft_face; int fterr; fz_matrix local_trm = *trm; - int ft_flags; const int scale = face->units_per_EM; const float recip = 1.0f / scale; @@ -1195,19 +1168,7 @@ fz_outline_ft_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *tr fz_lock(ctx, FZ_LOCK_FREETYPE); - if (font->flags.force_hinting) - { - ft_flags = FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM; - fterr = FT_Set_Char_Size(face, scale, scale, 72, 72); - if (fterr) - fz_warn(ctx, "freetype setting character size: %s", ft_error_string(fterr)); - } - else - { - ft_flags = FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM; - } - - fterr = FT_Load_Glyph(face, gid, ft_flags); + fterr = FT_Load_Glyph(face, gid, FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM); if (fterr) { fz_warn(ctx, "freetype load glyph (gid %d): %s", gid, ft_error_string(fterr)); diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index ae03c58b..148f4c29 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -1329,8 +1329,9 @@ pdf_load_font_descriptor(fz_context *ctx, pdf_document *doc, pdf_font_desc *font face = fontdesc->font->ft_face; if (ft_kind(face) == TRUETYPE) { - if (FT_IS_TRICKY(face) || is_dynalab(fontdesc->font->name)) - fontdesc->font->flags.force_hinting = 1; + /* FreeType's own 'tricky' font detection needs a bit of help */ + if (is_dynalab(fontdesc->font->name)) + face->face_flags |= FT_FACE_FLAG_TRICKY; if (fontdesc->ascent == 0.0f) fontdesc->ascent = 1000.0f * face->ascender / face->units_per_EM; -- cgit v1.2.3