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."
c20386e393
. Blink on Android is
already using the new code.
Review URL: https://codereview.chromium.org/705843004
This commit is contained in:
parent
b61e206138
commit
c9232dcda0
@ -33,16 +33,13 @@ static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x,
|
||||
|
||||
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 @@ static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
|
||||
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 @@ protected:
|
||||
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;
|
||||
}
|
||||
|
@ -74,14 +74,9 @@ public:
|
||||
* 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 @@ protected:
|
||||
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;
|
||||
|
@ -39,18 +39,11 @@ protected:
|
||||
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;
|
||||
|
@ -134,14 +134,9 @@ public:
|
||||
* 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.
|
||||
|
@ -119,18 +119,11 @@ protected:
|
||||
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 @@ SkTypeface* SkFontMgr::matchFamilyStyle(const char familyName[],
|
||||
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 {
|
||||
|
@ -245,7 +245,6 @@ SkTypeface* SkFontMgr_Indirect::onMatchFamilyStyle(const char familyName[],
|
||||
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 @@ SkTypeface* SkFontMgr_Indirect::onMatchFamilyStyleCharacter(const char familyNam
|
||||
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 {
|
||||
|
@ -340,51 +340,42 @@ protected:
|
||||
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 (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 (!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();
|
||||
}
|
||||
}
|
||||
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.
|
||||
|
@ -763,22 +763,12 @@ protected:
|
||||
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;
|
||||
|
@ -408,21 +408,11 @@ public:
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user