From 8386aa8a3bdc682ff9daa6c559d593b9d5c4a5d1 Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Mon, 26 Jun 2017 12:47:33 -0400 Subject: [PATCH] Load FreeType glyph bitmap before emboldening. If a bitmap glyph was loaded with FT_LOAD_BITMAP_METRICS_ONLY then the glyph must be re-loaded without this flag before accessing the bitmap. BUG=chromium:725975 Change-Id: If5e5a6844e9c32238560135e141fea7f77ad7fac Reviewed-on: https://skia-review.googlesource.com/20830 Reviewed-by: Herb Derby Reviewed-by: Florin Malita Commit-Queue: Ben Wagner Cherry-Pick: c3aef18419c1bb16951370e11758c7ef131fa10b Approval: https://crbug.com/725975#c24 --- src/ports/SkFontHost_FreeType.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index b87af6f..0d61d5f 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -496,7 +496,7 @@ private: void updateGlyphIfLCD(SkGlyph* glyph); // Caller must lock gFTMutex before calling this function. // update FreeType2 glyph slot with glyph emboldened - void emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph); + void emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph, SkGlyphID gid); bool shouldSubpixelBitmap(const SkGlyph&, const SkMatrix&); }; @@ -1107,7 +1107,7 @@ bool SkScalerContext_FreeType::getCBoxForLetter(char letter, FT_BBox* bbox) { if (FT_Load_Glyph(fFace, glyph_id, fLoadGlyphFlags) != 0) { return false; } - emboldenIfNeeded(fFace, fFace->glyph); + emboldenIfNeeded(fFace, fFace->glyph, SkTo(glyph_id)); FT_Outline_Get_CBox(&fFace->glyph->outline, bbox); return true; } @@ -1159,7 +1159,7 @@ void SkScalerContext_FreeType::generateMetrics(SkGlyph* glyph) { glyph->zeroMetrics(); return; } - emboldenIfNeeded(fFace, fFace->glyph); + emboldenIfNeeded(fFace, fFace->glyph, glyph->getGlyphID()); switch ( fFace->glyph->format ) { case FT_GLYPH_FORMAT_OUTLINE: @@ -1269,7 +1269,7 @@ void SkScalerContext_FreeType::generateImage(const SkGlyph& glyph) { return; } - emboldenIfNeeded(fFace, fFace->glyph); + emboldenIfNeeded(fFace, fFace->glyph, glyph.getGlyphID()); SkMatrix* bitmapMatrix = &fMatrix22Scalar; SkMatrix subpixelBitmapMatrix; if (this->shouldSubpixelBitmap(glyph, *bitmapMatrix)) { @@ -1304,7 +1304,7 @@ void SkScalerContext_FreeType::generatePath(SkGlyphID glyphID, SkPath* path) { path->reset(); return; } - emboldenIfNeeded(fFace, fFace->glyph); + emboldenIfNeeded(fFace, fFace->glyph, glyphID); generateGlyphPath(fFace, path); @@ -1460,8 +1460,7 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* metrics /////////////////////////////////////////////////////////////////////////////// -void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph) -{ +void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph, SkGlyphID gid) { // check to see if the embolden bit is set if (0 == (fRec.fFlags & SkScalerContext::kEmbolden_Flag)) { return; @@ -1475,6 +1474,9 @@ void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph FT_Outline_Embolden(&glyph->outline, strength); break; case FT_GLYPH_FORMAT_BITMAP: + if (!fFace->glyph->bitmap.buffer) { + FT_Load_Glyph(fFace, gid, fLoadGlyphFlags); + } FT_GlyphSlot_Own_Bitmap(glyph); FT_Bitmap_Embolden(glyph->library, &glyph->bitmap, kBitmapEmboldenStrength, 0); break; -- 2.7.4