Chromium Code Reviews| Index: src/ports/SkFontConfigInterface_android.cpp |
| diff --git a/src/ports/SkFontConfigInterface_android.cpp b/src/ports/SkFontConfigInterface_android.cpp |
| index 3a4c02e539d2f0fbd4d8f90bde28c2daa7d5f952..7885faee9a51d35da0696209a3622d6ff3b5a514 100644 |
| --- a/src/ports/SkFontConfigInterface_android.cpp |
| +++ b/src/ports/SkFontConfigInterface_android.cpp |
| @@ -103,6 +103,9 @@ public: |
| SkPaintOptionsAndroid::FontVariant fontVariant); |
| SkTypeface* nextLogicalTypeface(SkFontID currFontID, SkFontID origFontID, |
| const SkPaintOptionsAndroid& options); |
| + SkTypeface* getTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origTypeface, |
| + const SkPaintOptionsAndroid& options, |
| + int* lowerBounds, int* upperBounds); |
| private: |
| void addFallbackFamily(FamilyRecID fontRecID); |
| @@ -670,6 +673,64 @@ SkTypeface* SkFontConfigInterfaceAndroid::nextLogicalTypeface(SkFontID currFontI |
| return SkSafeRef(nextLogicalTypeface); |
| } |
| +SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForGlyphID(uint16_t glyphID, |
| + const SkTypeface* origTypeface, |
| + const SkPaintOptionsAndroid& opts, |
| + int* lBounds, int* uBounds) { |
| + // Skia does not support font fallback by default. This enables clients such |
| + // as WebKit to customize their font selection. In any case, clients can use |
| + // GetFallbackFamilyNameForChar() to get the fallback font for individual |
| + // characters. |
| + if (!opts.isUsingFontFallbacks()) { |
| + return NULL; |
| + } |
| + |
| + SkTypeface* currentTypeface = NULL; |
| + int lowerBounds = 0; //inclusive |
| + int upperBounds = origTypeface->countGlyphs(); //exclusive |
| + |
| + // check to see if the glyph is in the bounds of the origTypeface |
| + if (glyphID < upperBounds) { |
| + currentTypeface = const_cast<SkTypeface*>(origTypeface); |
|
scroggo
2013/10/01 21:00:14
It appears you do not modify currentTypeface. It s
djsollen
2013/10/02 16:16:41
But I do return that value and I can't return a co
|
| + } else { |
| + FallbackFontList* currentFallbackList = findFallbackFontList(opts.getLanguage()); |
| + SkASSERT(currentFallbackList); |
| + |
| + // If an object is set to prefer "kDefault_Variant" it means they have no preference |
| + // In this case, we set the value to "kCompact_Variant" |
| + SkPaintOptionsAndroid::FontVariant variant = opts.getFontVariant(); |
| + if (variant == SkPaintOptionsAndroid::kDefault_Variant) { |
| + variant = SkPaintOptionsAndroid::kCompact_Variant; |
| + } |
| + |
| + int32_t acceptedVariants = SkPaintOptionsAndroid::kDefault_Variant | variant; |
| + SkTypeface::Style origStyle = origTypeface->style(); |
| + |
| + for (int x = 0; x < currentFallbackList->count(); ++x) { |
| + FamilyRecID familyRecID = currentFallbackList->getAt(x); |
| + if ((fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & acceptedVariants) != 0) { |
|
scroggo
2013/10/01 21:00:14
100 chars
|
| + FontRecID matchedFont = find_best_style(fFontFamilies[familyRecID], origStyle); |
| + currentTypeface = this->getTypefaceForFontRec(matchedFont); |
| + lowerBounds = upperBounds; |
| + upperBounds += currentTypeface->countGlyphs(); |
| + if (glyphID < upperBounds) { |
| + break; |
| + } |
| + } |
| + } |
| + } |
| + |
| + if (currentTypeface) { |
|
scroggo
2013/10/01 21:00:14
nit: explicit NULL check.
|
| + if (lBounds) { |
| + *lBounds = lowerBounds; |
| + } |
| + if (uBounds) { |
| + *uBounds = upperBounds; |
| + } |
| + } |
| + return SkSafeRef(currentTypeface); |
|
scroggo
2013/10/01 21:00:14
Why not return SkRef(currentTypeface) inside the i
|
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) { |
| @@ -702,6 +763,14 @@ SkTypeface* SkAndroidNextLogicalTypeface(SkFontID currFontID, SkFontID origFontI |
| } |
| +SkTypeface* SkGetTypefaceForGlyphID(uint16_t glyphID, const SkTypeface* origTypeface, |
| + const SkPaintOptionsAndroid& options, |
| + int* lowerBounds, int* upperBounds) { |
| + SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface(); |
| + return fontConfig->getTypefaceForGlyphID(glyphID, origTypeface, options, |
| + lowerBounds, upperBounds); |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |