Use FT_LOAD_PEDANTIC in CFX_GlyphCache::RenderGlyph(). Better detect rendering of fonts with bad bytecode hinting data. If the first call to FT_Load_Glyph() fails, retry without using the hinting data. Along the way, fix nits in/near the affected code. Bug: chromium:1063609 Change-Id: Ife86a2d4425257213b7692743e8f714de329dd38 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68870 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/cfx_glyphcache.cpp b/core/fxge/cfx_glyphcache.cpp index ec9c886..f91f8b3 100644 --- a/core/fxge/cfx_glyphcache.cpp +++ b/core/fxge/cfx_glyphcache.cpp
@@ -143,22 +143,25 @@ pFont->GetSubstFont()->m_Weight); } } + ScopedFontTransform scoped_transform(GetFace(), &ft_matrix); - int load_flags = (GetFaceRec()->face_flags & FT_FACE_FLAG_SFNT) - ? FT_LOAD_NO_BITMAP - : (FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING); + int load_flags = FT_LOAD_NO_BITMAP | FT_LOAD_PEDANTIC; + if (!(GetFaceRec()->face_flags & FT_FACE_FLAG_SFNT)) + load_flags |= FT_LOAD_NO_HINTING; int error = FT_Load_Glyph(GetFaceRec(), glyph_index, load_flags); if (error) { // if an error is returned, try to reload glyphs without hinting. - if (load_flags & FT_LOAD_NO_HINTING || load_flags & FT_LOAD_NO_SCALE) + if (load_flags & FT_LOAD_NO_HINTING) return nullptr; load_flags |= FT_LOAD_NO_HINTING; + load_flags &= ~FT_LOAD_PEDANTIC; error = FT_Load_Glyph(GetFaceRec(), glyph_index, load_flags); if (error) return nullptr; } - int weight = 0; + + int weight; if (bUseCJKSubFont) weight = pSubstFont->m_WeightCJK; else