diff options
author | Raph Levien <raph@google.com> | 2014-06-06 17:56:41 -0700 |
---|---|---|
committer | Raph Levien <raph@google.com> | 2014-06-10 11:59:29 -0700 |
commit | 9a5f713add8cfb91ac2c9ed5c917309053201ab6 (patch) | |
tree | 7d6be261f3a7d30b0d7f14a66b2ff5e290e1bc4f /libs/minikin/FontFamily.cpp | |
parent | 89566f0ada1cafe673efa064cde38467990235d4 (diff) | |
download | android_frameworks_minikin-9a5f713add8cfb91ac2c9ed5c917309053201ab6.tar.gz android_frameworks_minikin-9a5f713add8cfb91ac2c9ed5c917309053201ab6.tar.bz2 android_frameworks_minikin-9a5f713add8cfb91ac2c9ed5c917309053201ab6.zip |
Support for fake bold and italics
This patch adds support for computing when fake bold and fake italics
are needed (because the styles are requested but not provided by the
matching FontFamily), and providing them as part of the layout result.
Part of the fix for bug 15436379 Fake bold doesn't fully work (Minikin)
Change-Id: I180c034b559837943673b5c272c8e890178dff0d
Diffstat (limited to 'libs/minikin/FontFamily.cpp')
-rw-r--r-- | libs/minikin/FontFamily.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/libs/minikin/FontFamily.cpp b/libs/minikin/FontFamily.cpp index 0fb98ae..9106f63 100644 --- a/libs/minikin/FontFamily.cpp +++ b/libs/minikin/FontFamily.cpp @@ -109,7 +109,7 @@ void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { type } // Compute a matching metric between two styles - 0 is an exact match -int computeMatch(FontStyle style1, FontStyle style2) { +static int computeMatch(FontStyle style1, FontStyle style2) { if (style1 == style2) return 0; int score = abs(style1.getWeight() - style2.getWeight()); if (style1.getItalic() != style2.getItalic()) { @@ -118,7 +118,15 @@ int computeMatch(FontStyle style1, FontStyle style2) { return score; } -MinikinFont* FontFamily::getClosestMatch(FontStyle style) const { +static FontFakery computeFakery(FontStyle wanted, FontStyle actual) { + // If desired weight is 2 or more grades higher than actual + // (for example, medium 500 -> bold 700), then select fake bold. + bool isFakeBold = (wanted.getWeight() - actual.getWeight()) >= 2; + bool isFakeItalic = wanted.getItalic() && !actual.getItalic(); + return FontFakery(isFakeBold, isFakeItalic); +} + +FakedFont FontFamily::getClosestMatch(FontStyle style) const { const Font* bestFont = NULL; int bestMatch = 0; for (size_t i = 0; i < mFonts.size(); i++) { @@ -129,7 +137,14 @@ MinikinFont* FontFamily::getClosestMatch(FontStyle style) const { bestMatch = match; } } - return bestFont == NULL ? NULL : bestFont->typeface; + FakedFont result; + if (bestFont == NULL) { + result.font = NULL; + } else { + result.font = bestFont->typeface; + result.fakery = computeFakery(style, bestFont->style); + } + return result; } size_t FontFamily::getNumFonts() const { |