From: Akihiro Sagawa Subject: [5/5] gdi32: Improve the synthetic bold method when using scaling factors. (try 2) Message-Id: <20151106212309.5DD7.375B48EC@gmail.com> Date: Fri, 06 Nov 2015 21:25:12 +0900 Try 2: - Avoid division by zero for `factor'. Signed-off-by: Akihiro Sagawa --- dlls/gdi32/freetype.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index b994ba8..8b15195 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -6315,27 +6315,38 @@ static inline FT_Vector normalize_vector(FT_Vector *vec) return out; } -static BOOL get_bold_glyph_outline(FT_GlyphSlot glyph, LONG ppem, FT_Glyph_Metrics *metrics) +static BOOL get_bold_glyph_outline(FT_GlyphSlot glyph, LONG ppem, + const FT_Matrix *transMat, FT_Glyph_Metrics *metrics) { const LONG EMBOLDEN_X_THRESHOLD = 50; FT_Error err; FT_Pos strength; FT_BBox bbox; + FT_Vector scaling = { 1 << 6, 0 }; + FT_Fixed factor; if(glyph->format != FT_GLYPH_FORMAT_OUTLINE) return FALSE; if(!pFT_Outline_Embolden) return FALSE; - if(pFT_Outline_EmboldenXY && ppem <= EMBOLDEN_X_THRESHOLD) { - err = pFT_Outline_EmboldenXY(&glyph->outline, 1 << 6, 0); + pFT_Vector_Transform(&scaling, transMat); + factor = pFT_Vector_Length(&scaling); + if (factor) + strength = MulDiv(1 << 6, 1 << 6, factor); + else + strength = 0; + + if(pFT_Outline_EmboldenXY && + MulDiv(ppem, factor, 1 << 6) <= EMBOLDEN_X_THRESHOLD) { + err = pFT_Outline_EmboldenXY(&glyph->outline, strength, 0); if(err) { TRACE("FT_Ouline_EmboldenXY returns %d\n", err); return FALSE; } } else { - strength = MulDiv(ppem, 1 << 6, 24); + strength = MulDiv(ppem, strength, 24); err = pFT_Outline_Embolden(&glyph->outline, strength); if(err) { TRACE("FT_Ouline_Embolden returns %d\n", err); @@ -6783,7 +6794,7 @@ static DWORD get_glyph_outline(GdiFont *incoming_font, UINT glyph, UINT format, metrics = ft_face->glyph->metrics; if(font->fake_bold) { - if (!get_bold_glyph_outline(ft_face->glyph, font->ppem, &metrics) && metrics.width) + if (!get_bold_glyph_outline(ft_face->glyph, font->ppem, &transMat, &metrics) && metrics.width) metrics.width += 1 << 6; fake_bold_adv.x = 1 << 6; }