Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1229)

Unified Diff: src/ports/SkFontHost_FreeType.cpp

Issue 101423004: refactor emboldenGlyph (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase to master Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_FreeType.cpp
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index f79e27b7ed06890e7d4d5a4c3bab75286c1f4f45..62c7c128a7fbb33921c1923fd7c5d48b10830089 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -1,4 +1,4 @@
-
+
/*
* Copyright 2006 The Android Open Source Project
*
@@ -216,6 +216,9 @@ private:
bool getCBoxForLetter(char letter, FT_BBox* bbox);
// Caller must lock gFTMutex before calling this function.
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);
};
///////////////////////////////////////////////////////////////////////////
@@ -1136,10 +1139,7 @@ bool SkScalerContext_FreeType::getCBoxForLetter(char letter, FT_BBox* bbox) {
return false;
if (FT_Load_Glyph(fFace, glyph_id, fLoadGlyphFlags) != 0)
return false;
- if ((fRec.fFlags & kEmbolden_Flag) &&
- !(fFace->style_flags & FT_STYLE_FLAG_BOLD)) {
- emboldenOutline(fFace, &fFace->glyph->outline);
- }
+ emboldenIfNeeded(fFace, fFace->glyph);
FT_Outline_Get_CBox(&fFace->glyph->outline, bbox);
return true;
}
@@ -1189,6 +1189,7 @@ void SkScalerContext_FreeType::generateMetrics(SkGlyph* glyph) {
glyph->zeroMetrics();
return;
}
+ emboldenIfNeeded(fFace, fFace->glyph);
switch ( fFace->glyph->format ) {
case FT_GLYPH_FORMAT_OUTLINE:
@@ -1198,10 +1199,6 @@ void SkScalerContext_FreeType::generateMetrics(SkGlyph* glyph) {
glyph->fTop = 0;
glyph->fLeft = 0;
} else {
- if (fRec.fFlags & kEmbolden_Flag && !(fFace->style_flags & FT_STYLE_FLAG_BOLD)) {
- emboldenOutline(fFace, &fFace->glyph->outline);
- }
-
FT_BBox bbox;
getBBoxForCurrentGlyph(glyph, &bbox, true);
@@ -1215,11 +1212,6 @@ void SkScalerContext_FreeType::generateMetrics(SkGlyph* glyph) {
break;
case FT_GLYPH_FORMAT_BITMAP:
- if (fRec.fFlags & kEmbolden_Flag) {
- FT_GlyphSlot_Own_Bitmap(fFace->glyph);
- FT_Bitmap_Embolden(gFTLibrary, &fFace->glyph->bitmap, kBitmapEmboldenStrength, 0);
- }
-
if (fRec.fFlags & SkScalerContext::kVertical_Flag) {
FT_Vector vector;
vector.x = fFace->glyph->metrics.vertBearingX - fFace->glyph->metrics.horiBearingX;
@@ -1298,6 +1290,7 @@ void SkScalerContext_FreeType::generateImage(const SkGlyph& glyph) {
return;
}
+ emboldenIfNeeded(fFace, fFace->glyph);
generateGlyphImage(fFace, glyph);
}
@@ -1325,6 +1318,7 @@ void SkScalerContext_FreeType::generatePath(const SkGlyph& glyph,
path->reset();
return;
}
+ emboldenIfNeeded(fFace, fFace->glyph);
generateGlyphPath(fFace, path);
@@ -1466,6 +1460,25 @@ void SkScalerContext_FreeType::generateFontMetrics(SkPaint::FontMetrics* mx,
}
}
+void SkScalerContext_FreeType::emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph)
+{
+ if (fRec.fFlags & SkScalerContext::kEmbolden_Flag) {
+ switch ( glyph->format ) {
+ case FT_GLYPH_FORMAT_OUTLINE:
+ FT_Pos strength;
+ strength = FT_MulFix(face->units_per_EM, face->size->metrics.y_scale) / 24;
+ FT_Outline_Embolden(&glyph->outline, strength);
+ break;
+ case FT_GLYPH_FORMAT_BITMAP:
+ FT_GlyphSlot_Own_Bitmap(glyph);
+ FT_Bitmap_Embolden(glyph->library, &glyph->bitmap, kBitmapEmboldenStrength, 0);
+ break;
+ default:
+ SkDEBUGFAIL("unknown glyph format");
+ }
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
#include "SkUtils.h"
« no previous file with comments | « no previous file | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698