Remove SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER.
This removes the old guarded code and enables the new api
introduced with "Update fontMgr to take list of bcp47 language tags."
c20386e3937d3d398ac9b35f9c7d997e972ade98 . Blink on Android is
already using the new code.
Review URL: https://codereview.chromium.org/705843004
diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp
index be2b11a..99cff6e 100644
--- a/gm/fontmgr.cpp
+++ b/gm/fontmgr.cpp
@@ -33,16 +33,13 @@
static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
SkScalar y, SkPaint& paint, SkFontMgr* fm,
- const char* fontName, const char* bpc47,
+ const char* fontName, const char* bcp47[], int bcp47Count,
const SkFontStyle& fontStyle) {
// find typeface containing the requested character and draw it
SkString ch;
ch.appendUnichar(character);
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
- SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle, &bpc47, 1, character);
-#else
- SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle, bpc47, character);
-#endif
+ SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle,
+ bcp47, bcp47Count, character);
SkSafeUnref(paint.setTypeface(typeface));
x = drawString(canvas, ch, x, y, paint) + 20;
@@ -60,6 +57,9 @@
return drawString(canvas, ch, x, y, paint) + 20;
}
+static const char* zh = "zh";
+static const char* ja = "ja";
+
class FontMgrGM : public skiagm::GM {
public:
FontMgrGM(SkFontMgr* fontMgr = NULL) {
@@ -113,10 +113,10 @@
x = drawString(canvas, sname, x, y, paint) + 20;
// check to see that we get different glyphs in japanese and chinese
- x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str(), "zh", fs);
- x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str(), "ja", fs);
+ x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str(), &zh, 1, fs);
+ x = drawCharacter(canvas, 0x5203, x, y, paint, fm, fName.c_str(), &ja, 1, fs);
// check that emoji characters are found
- x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, fName.c_str(), NULL, fs);
+ x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, fName.c_str(), NULL, 0, fs);
}
y += 24;
}
diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h
index 7210181..bc4e1ab 100644
--- a/include/ports/SkFontMgr.h
+++ b/include/ports/SkFontMgr.h
@@ -74,14 +74,9 @@
* most significant. If no specified bcp47 codes match, any font with the
* requested character will be matched.
*/
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
const char* bcp47[], int bcp47Count,
SkUnichar character) const;
-#else
- SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
- const char bcp47[], SkUnichar character) const;
-#endif
SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&) const;
@@ -127,14 +122,9 @@
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
const SkFontStyle&) const = 0;
// TODO: pure virtual, implement on all impls.
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
const char* bcp47[], int bcp47Count,
SkUnichar character) const
-#else
- virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
- const char bcp47[], SkUnichar character) const
-#endif
{ return NULL; }
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
const SkFontStyle&) const = 0;
diff --git a/include/ports/SkFontMgr_indirect.h b/include/ports/SkFontMgr_indirect.h
index 95a2355..573c7eb 100644
--- a/include/ports/SkFontMgr_indirect.h
+++ b/include/ports/SkFontMgr_indirect.h
@@ -39,18 +39,11 @@
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
const SkFontStyle& fontStyle) const SK_OVERRIDE;
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle&,
const char* bcp47[],
int bcp47Count,
SkUnichar character) const SK_OVERRIDE;
-#else
- virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
- const SkFontStyle&,
- const char bcp47[],
- SkUnichar character) const SK_OVERRIDE;
-#endif
virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontStyle) const SK_OVERRIDE;
diff --git a/include/ports/SkRemotableFontMgr.h b/include/ports/SkRemotableFontMgr.h
index 5a0a1bc..29ca6e8 100644
--- a/include/ports/SkRemotableFontMgr.h
+++ b/include/ports/SkRemotableFontMgr.h
@@ -134,14 +134,9 @@
* Note that bpc47 is a combination of ISO 639, 15924, and 3166-1 codes,
* so it is fine to just pass a ISO 639 here.
*/
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
virtual SkFontIdentity matchNameStyleCharacter(const char familyName[], const SkFontStyle&,
const char* bcp47[], int bcp47Count,
SkUnichar character) const=0;
-#else
- virtual SkFontIdentity matchNameStyleCharacter(const char familyName[], const SkFontStyle&,
- const char bcp47[], SkUnichar character) const=0;
-#endif
/**
* Returns the data for the given data id.
diff --git a/src/core/SkFontHost.cpp b/src/core/SkFontHost.cpp
index 14cca5a..79b7b73 100644
--- a/src/core/SkFontHost.cpp
+++ b/src/core/SkFontHost.cpp
@@ -119,18 +119,11 @@
const SkFontStyle&) const SK_OVERRIDE {
return NULL;
}
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle& style,
const char* bcp47[],
int bcp47Count,
SkUnichar character) const SK_OVERRIDE {
-#else
- virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
- const SkFontStyle& style,
- const char bcp47[],
- SkUnichar character) const SK_OVERRIDE {
-#endif
return NULL;
}
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
@@ -179,18 +172,11 @@
return this->onMatchFamilyStyle(familyName, fs);
}
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
const char* bcp47[], int bcp47Count,
SkUnichar character) const {
return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, character);
}
-#else
-SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
- const char bcp47[], SkUnichar character) const {
- return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, character);
-}
-#endif
SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face,
const SkFontStyle& fs) const {
diff --git a/src/fonts/SkFontMgr_indirect.cpp b/src/fonts/SkFontMgr_indirect.cpp
index c9d3025..39270b4 100644
--- a/src/fonts/SkFontMgr_indirect.cpp
+++ b/src/fonts/SkFontMgr_indirect.cpp
@@ -245,7 +245,6 @@
return this->createTypefaceFromFontId(id);
}
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
SkTypeface* SkFontMgr_Indirect::onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle& style,
const char* bcp47[],
@@ -255,15 +254,6 @@
bcp47Count, character);
return this->createTypefaceFromFontId(id);
}
-#else
-SkTypeface* SkFontMgr_Indirect::onMatchFamilyStyleCharacter(const char familyName[],
- const SkFontStyle& style,
- const char bcp47[],
- SkUnichar character) const {
- SkFontIdentity id = fProxy->matchNameStyleCharacter(familyName, style, bcp47, character);
- return this->createTypefaceFromFontId(id);
-}
-#endif
SkTypeface* SkFontMgr_Indirect::onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontStyle) const {
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 508ad4c..fb77b27 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -340,51 +340,42 @@
return NULL;
}
-static SkTypeface_AndroidSystem* find_family_style_character(
- const SkTDArray<NameToFamily>& fallbackNameToFamilyMap,
- const SkFontStyle& style, bool elegant,
- const SkString& langTag, SkUnichar character)
-{
- for (int i = 0; i < fallbackNameToFamilyMap.count(); ++i) {
- SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet;
- SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchStyle(style));
+ static SkTypeface_AndroidSystem* find_family_style_character(
+ const SkTDArray<NameToFamily>& fallbackNameToFamilyMap,
+ const SkFontStyle& style, bool elegant,
+ const SkString& langTag, SkUnichar character)
+ {
+ for (int i = 0; i < fallbackNameToFamilyMap.count(); ++i) {
+ SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet;
+ SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchStyle(style));
- if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c_str())) {
- continue;
+ if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c_str())) {
+ continue;
+ }
+
+ if (SkToBool(face->fVariantStyle & kElegant_FontVariant) != elegant) {
+ continue;
+ }
+
+ SkPaint paint;
+ paint.setTypeface(face);
+ paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
+
+ uint16_t glyphID;
+ paint.textToGlyphs(&character, sizeof(character), &glyphID);
+ if (glyphID != 0) {
+ return face.detach();
+ }
}
-
- if (SkToBool(face->fVariantStyle & kElegant_FontVariant) != elegant) {
- continue;
- }
-
- SkPaint paint;
- paint.setTypeface(face);
- paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
-
- uint16_t glyphID;
- paint.textToGlyphs(&character, sizeof(character), &glyphID);
- if (glyphID != 0) {
- return face.detach();
- }
+ return NULL;
}
- return NULL;
-}
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
+
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle& style,
const char* bcp47[],
int bcp47Count,
SkUnichar character) const SK_OVERRIDE
{
-#else
- virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
- const SkFontStyle& style,
- const char bcp47_val[],
- SkUnichar character) const SK_OVERRIDE
- {
- const char** bcp47 = &bcp47_val;
- int bcp47Count = bcp47_val ? 1 : 0;
-#endif
// The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascent/descent'.
// The variant 'default' means 'compact and elegant'.
// As a result, it is not possible to know the variant context from the font alone.
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 815d9f9..7b67069 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -763,22 +763,12 @@
return createTypefaceFromFcPattern(font);
}
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle& style,
const char* bcp47[],
int bcp47Count,
SkUnichar character) const SK_OVERRIDE
{
-#else
- virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
- const SkFontStyle& style,
- const char bcp47_val[],
- SkUnichar character) const SK_OVERRIDE
- {
- const char** bcp47 = &bcp47_val;
- int bcp47Count = bcp47_val ? 1 : 0;
-#endif
FCLocker lock;
SkAutoFcPattern pattern;
diff --git a/src/ports/SkRemotableFontMgr_win_dw.cpp b/src/ports/SkRemotableFontMgr_win_dw.cpp
index 498f21f..2f02e4b 100644
--- a/src/ports/SkRemotableFontMgr_win_dw.cpp
+++ b/src/ports/SkRemotableFontMgr_win_dw.cpp
@@ -408,21 +408,11 @@
SkFontIdentity fIdentity;
};
-#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
virtual SkFontIdentity matchNameStyleCharacter(const char familyName[],
const SkFontStyle& pattern,
const char* bcp47[], int bcp47Count,
SkUnichar character) const SK_OVERRIDE
{
-#else
- virtual SkFontIdentity matchNameStyleCharacter(const char familyName[],
- const SkFontStyle& pattern,
- const char bcp47_val[],
- SkUnichar character) const SK_OVERRIDE
- {
- const char** bcp47 = &bcp47_val;
- int bcp47Count = bcp47_val ? 1 : 0;
-#endif
SkFontIdentity identity = { SkFontIdentity::kInvalidDataId };
IDWriteFactory* dwFactory = sk_get_dwrite_factory();