Remove ALL font fallback logic from Skia.
R=reed@google.com, bungeman@google.com, caryclark@google.com
Author: djsollen@google.com
Review URL: https://codereview.chromium.org/434623002
diff --git a/src/ports/SkFontConfigInterface_android.cpp b/src/ports/SkFontConfigInterface_android.cpp
index bdc3d50..1bdcf4c 100644
--- a/src/ports/SkFontConfigInterface_android.cpp
+++ b/src/ports/SkFontConfigInterface_android.cpp
@@ -98,14 +98,6 @@
* contains the specified chararacter. if no font is found, returns false.
*/
bool getFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* name);
- /**
- *
- */
- 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);
@@ -579,135 +571,6 @@
return fallbackFontList;
}
-SkTypeface* SkFontConfigInterfaceAndroid::nextLogicalTypeface(SkFontID currFontID,
- SkFontID origFontID,
- const SkPaintOptionsAndroid& opts) {
- // 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;
- }
-
- FallbackFontList* currentFallbackList = findFallbackFontList(opts.getLanguage());
- SkASSERT(currentFallbackList);
-
- SkTypeface::Style origStyle = SkTypeface::kNormal;
- const SkTypeface* origTypeface = SkTypefaceCache::FindByID(origFontID);
- if (NULL != origTypeface) {
- origStyle = origTypeface->style();
- }
-
- // we must convert currTypeface into a FontRecID
- FontRecID currFontRecID = INVALID_FONT_REC_ID;
- const SkTypeface* currTypeface = SkTypefaceCache::FindByID(currFontID);
- // non-system fonts are not in the font cache so if we are asked to fallback
- // for a non-system font we will start at the front of the chain.
- if (NULL != currTypeface) {
- currFontRecID = ((FontConfigTypeface*)currTypeface)->getIdentity().fID;
- SkASSERT(INVALID_FONT_REC_ID != currFontRecID);
- }
-
- FamilyRecID currFamilyRecID = INVALID_FAMILY_REC_ID;
- if (INVALID_FONT_REC_ID != currFontRecID) {
- currFamilyRecID = fFonts[currFontRecID].fFamilyRecID;
- }
-
- // lookup the index next font in the chain
- int currFallbackFontIndex = currentFallbackList->find(currFamilyRecID);
- // We add 1 to the returned index for 2 reasons: (1) if find succeeds it moves
- // our index to the next entry in the list; (2) if find() fails it returns
- // -1 and incrementing it will set our starting index to 0 (the head of the list)
- int nextFallbackFontIndex = currFallbackFontIndex + 1;
-
- if(nextFallbackFontIndex >= currentFallbackList->count()) {
- return NULL;
- }
-
- // If a rec 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* nextLogicalTypeface = 0;
- while (nextFallbackFontIndex < currentFallbackList->count()) {
- FamilyRecID familyRecID = currentFallbackList->getAt(nextFallbackFontIndex);
- if ((fFontFamilies[familyRecID].fPaintOptions.getFontVariant() & acceptedVariants) != 0) {
- FontRecID matchedFont = find_best_style(fFontFamilies[familyRecID], origStyle);
- nextLogicalTypeface = this->getTypefaceForFontRec(matchedFont);
- break;
- }
- nextFallbackFontIndex++;
- }
-
- DEBUG_FONT(("---- nextLogicalFont: currFontID=%d, origFontID=%d, currRecID=%d, "
- "lang=%s, variant=%d, nextFallbackIndex[%d,%d] => nextLogicalTypeface=%d",
- currFontID, origFontID, currFontRecID, opts.getLanguage().getTag().c_str(),
- variant, nextFallbackFontIndex, currentFallbackList->getAt(nextFallbackFontIndex),
- (nextLogicalTypeface) ? nextLogicalTypeface->uniqueID() : 0));
- return SkSafeRef(nextLogicalTypeface);
-}
-
-SkTypeface* SkFontConfigInterfaceAndroid::getTypefaceForGlyphID(uint16_t glyphID,
- const SkTypeface* origTypeface,
- const SkPaintOptionsAndroid& opts,
- int* lBounds, int* uBounds) {
- // If we aren't using fallbacks then we shouldn't be calling this
- SkASSERT(opts.isUsingFontFallbacks());
- SkASSERT(origTypeface);
-
- 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);
- } 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) {
- const FamilyRecID familyRecID = currentFallbackList->getAt(x);
- const SkPaintOptionsAndroid& familyOptions = fFontFamilies[familyRecID].fPaintOptions;
- if ((familyOptions.getFontVariant() & acceptedVariants) != 0) {
- FontRecID matchedFont = find_best_style(fFontFamilies[familyRecID], origStyle);
- currentTypeface = this->getTypefaceForFontRec(matchedFont);
- lowerBounds = upperBounds;
- upperBounds += currentTypeface->countGlyphs();
- if (glyphID < upperBounds) {
- break;
- }
- }
- }
- }
-
- if (NULL != currentTypeface) {
- if (lBounds) {
- *lBounds = lowerBounds;
- }
- if (uBounds) {
- *uBounds = upperBounds;
- }
- }
- return currentTypeface;
-}
-
///////////////////////////////////////////////////////////////////////////////
bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkString* name) {
@@ -726,18 +589,3 @@
SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s",
gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix));
}
-
-SkTypeface* SkAndroidNextLogicalTypeface(SkFontID currFontID, SkFontID origFontID,
- const SkPaintOptionsAndroid& options) {
- SkFontConfigInterfaceAndroid* fontConfig = getSingletonInterface();
- return fontConfig->nextLogicalTypeface(currFontID, origFontID, options);
-
-}
-
-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);
-}
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index e2b0fe9..ef943aa 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -1115,7 +1115,7 @@
FT_Error error;
FT_Fixed advance;
- error = FT_Get_Advance( fFace, glyph->getGlyphID(fBaseGlyphCount),
+ error = FT_Get_Advance( fFace, glyph->getGlyphID(),
fLoadGlyphFlags | FT_ADVANCE_FLAG_FAST_ONLY,
&advance );
if (0 == error) {
@@ -1217,11 +1217,11 @@
goto ERROR;
}
- err = FT_Load_Glyph( fFace, glyph->getGlyphID(fBaseGlyphCount), fLoadGlyphFlags );
+ err = FT_Load_Glyph( fFace, glyph->getGlyphID(), fLoadGlyphFlags );
if (err != 0) {
#if 0
SkDEBUGF(("SkScalerContext_FreeType::generateMetrics(%x): FT_Load_Glyph(glyph:%d flags:%x) returned 0x%x\n",
- fFaceRec->fFontID, glyph->getGlyphID(fBaseGlyphCount), fLoadGlyphFlags, err));
+ fFaceRec->fFontID, glyph->getGlyphID(), fLoadGlyphFlags, err));
#endif
ERROR:
glyph->zeroMetrics();
@@ -1305,7 +1305,7 @@
#ifdef ENABLE_GLYPH_SPEW
SkDEBUGF(("FT_Set_Char_Size(this:%p sx:%x sy:%x ", this, fScaleX, fScaleY));
- SkDEBUGF(("Metrics(glyph:%d flags:0x%x) w:%d\n", glyph->getGlyphID(fBaseGlyphCount), fLoadGlyphFlags, glyph->fWidth));
+ SkDEBUGF(("Metrics(glyph:%d flags:0x%x) w:%d\n", glyph->getGlyphID(), fLoadGlyphFlags, glyph->fWidth));
#endif
}
@@ -1319,10 +1319,10 @@
goto ERROR;
}
- err = FT_Load_Glyph( fFace, glyph.getGlyphID(fBaseGlyphCount), fLoadGlyphFlags);
+ err = FT_Load_Glyph( fFace, glyph.getGlyphID(), fLoadGlyphFlags);
if (err != 0) {
SkDEBUGF(("SkScalerContext_FreeType::generateImage: FT_Load_Glyph(glyph:%d width:%d height:%d rb:%d flags:%d) returned 0x%x\n",
- glyph.getGlyphID(fBaseGlyphCount), glyph.fWidth, glyph.fHeight, glyph.rowBytes(), fLoadGlyphFlags, err));
+ glyph.getGlyphID(), glyph.fWidth, glyph.fHeight, glyph.rowBytes(), fLoadGlyphFlags, err));
ERROR:
memset(glyph.fImage, 0, glyph.rowBytes() * glyph.fHeight);
return;
@@ -1348,11 +1348,11 @@
flags |= FT_LOAD_NO_BITMAP; // ignore embedded bitmaps so we're sure to get the outline
flags &= ~FT_LOAD_RENDER; // don't scan convert (we just want the outline)
- FT_Error err = FT_Load_Glyph( fFace, glyph.getGlyphID(fBaseGlyphCount), flags);
+ FT_Error err = FT_Load_Glyph( fFace, glyph.getGlyphID(), flags);
if (err != 0) {
SkDEBUGF(("SkScalerContext_FreeType::generatePath: FT_Load_Glyph(glyph:%d flags:%d) returned 0x%x\n",
- glyph.getGlyphID(fBaseGlyphCount), flags, err));
+ glyph.getGlyphID(), flags, err));
path->reset();
return;
}
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 2d985f9..72a3274 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -958,7 +958,7 @@
}
void SkScalerContext_Mac::generateMetrics(SkGlyph* glyph) {
- const CGGlyph cgGlyph = (CGGlyph) glyph->getGlyphID(fBaseGlyphCount);
+ const CGGlyph cgGlyph = (CGGlyph) glyph->getGlyphID();
glyph->zeroMetrics();
// The following block produces cgAdvance in CG units (pixels, y up).
@@ -1203,7 +1203,7 @@
}
void SkScalerContext_Mac::generateImage(const SkGlyph& glyph) {
- CGGlyph cgGlyph = (CGGlyph) glyph.getGlyphID(fBaseGlyphCount);
+ CGGlyph cgGlyph = (CGGlyph) glyph.getGlyphID();
// FIXME: lcd smoothed un-hinted rasterization unsupported.
bool generateA8FromLCD = fRec.getHinting() != SkPaint::kNo_Hinting;
@@ -1342,7 +1342,7 @@
font = CTFontCreateCopyWithAttributes(fCTFont, 1, &xform, NULL);
}
- CGGlyph cgGlyph = (CGGlyph)glyph.getGlyphID(fBaseGlyphCount);
+ CGGlyph cgGlyph = (CGGlyph)glyph.getGlyphID();
AutoCFRelease<CGPathRef> cgPath(CTFontCreatePathForGlyph(font, cgGlyph, NULL));
path->reset();
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index e4aab81..6f8669e 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -873,7 +873,7 @@
if (fType == SkScalerContext_GDI::kBitmap_Type || fType == SkScalerContext_GDI::kLine_Type) {
SIZE size;
- WORD glyphs = glyph->getGlyphID(0);
+ WORD glyphs = glyph->getGlyphID();
if (0 == GetTextExtentPointI(fDDC, &glyphs, 1, &size)) {
glyph->fWidth = SkToS16(fTM.tmMaxCharWidth);
} else {
@@ -911,7 +911,7 @@
return;
}
- UINT glyphId = glyph->getGlyphID(0);
+ UINT glyphId = glyph->getGlyphID();
GLYPHMETRICS gm;
sk_bzero(&gm, sizeof(gm));