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,
|
static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
|
||||||
SkScalar y, SkPaint& paint, SkFontMgr* fm,
|
SkScalar y, SkPaint& paint, SkFontMgr* fm,
|
||||||
const char* fontName, const char* bpc47,
|
const char* fontName, const char* bcp47[], int bcp47Count,
|
||||||
const SkFontStyle& fontStyle) {
|
const SkFontStyle& fontStyle) {
|
||||||
// find typeface containing the requested character and draw it
|
// find typeface containing the requested character and draw it
|
||||||
SkString ch;
|
SkString ch;
|
||||||
ch.appendUnichar(character);
|
ch.appendUnichar(character);
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle,
|
||||||
SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle, &bpc47, 1, character);
|
bcp47, bcp47Count, character);
|
||||||
#else
|
|
||||||
SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle, bpc47, character);
|
|
||||||
#endif
|
|
||||||
SkSafeUnref(paint.setTypeface(typeface));
|
SkSafeUnref(paint.setTypeface(typeface));
|
||||||
x = drawString(canvas, ch, x, y, paint) + 20;
|
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;
|
return drawString(canvas, ch, x, y, paint) + 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* zh = "zh";
|
||||||
|
static const char* ja = "ja";
|
||||||
|
|
||||||
class FontMgrGM : public skiagm::GM {
|
class FontMgrGM : public skiagm::GM {
|
||||||
public:
|
public:
|
||||||
FontMgrGM(SkFontMgr* fontMgr = NULL) {
|
FontMgrGM(SkFontMgr* fontMgr = NULL) {
|
||||||
@ -113,10 +113,10 @@ protected:
|
|||||||
x = drawString(canvas, sname, x, y, paint) + 20;
|
x = drawString(canvas, sname, x, y, paint) + 20;
|
||||||
|
|
||||||
// check to see that we get different glyphs in japanese and chinese
|
// 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(), &zh, 1, 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(), &ja, 1, fs);
|
||||||
// check that emoji characters are found
|
// 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;
|
y += 24;
|
||||||
}
|
}
|
||||||
|
@ -74,14 +74,9 @@ public:
|
|||||||
* most significant. If no specified bcp47 codes match, any font with the
|
* most significant. If no specified bcp47 codes match, any font with the
|
||||||
* requested character will be matched.
|
* requested character will be matched.
|
||||||
*/
|
*/
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
|
||||||
SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
|
SkTypeface* matchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
|
||||||
const char* bcp47[], int bcp47Count,
|
const char* bcp47[], int bcp47Count,
|
||||||
SkUnichar character) const;
|
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;
|
SkTypeface* matchFaceStyle(const SkTypeface*, const SkFontStyle&) const;
|
||||||
|
|
||||||
@ -127,14 +122,9 @@ protected:
|
|||||||
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
|
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
|
||||||
const SkFontStyle&) const = 0;
|
const SkFontStyle&) const = 0;
|
||||||
// TODO: pure virtual, implement on all impls.
|
// TODO: pure virtual, implement on all impls.
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
|
||||||
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
|
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
|
||||||
const char* bcp47[], int bcp47Count,
|
const char* bcp47[], int bcp47Count,
|
||||||
SkUnichar character) const
|
SkUnichar character) const
|
||||||
#else
|
|
||||||
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[], const SkFontStyle&,
|
|
||||||
const char bcp47[], SkUnichar character) const
|
|
||||||
#endif
|
|
||||||
{ return NULL; }
|
{ return NULL; }
|
||||||
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
|
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
|
||||||
const SkFontStyle&) const = 0;
|
const SkFontStyle&) const = 0;
|
||||||
|
@ -39,18 +39,11 @@ protected:
|
|||||||
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
|
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
|
||||||
const SkFontStyle& fontStyle) const SK_OVERRIDE;
|
const SkFontStyle& fontStyle) const SK_OVERRIDE;
|
||||||
|
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
|
||||||
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
||||||
const SkFontStyle&,
|
const SkFontStyle&,
|
||||||
const char* bcp47[],
|
const char* bcp47[],
|
||||||
int bcp47Count,
|
int bcp47Count,
|
||||||
SkUnichar character) const SK_OVERRIDE;
|
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,
|
virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
|
||||||
const SkFontStyle& fontStyle) const SK_OVERRIDE;
|
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,
|
* 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.
|
* 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&,
|
virtual SkFontIdentity matchNameStyleCharacter(const char familyName[], const SkFontStyle&,
|
||||||
const char* bcp47[], int bcp47Count,
|
const char* bcp47[], int bcp47Count,
|
||||||
SkUnichar character) const=0;
|
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.
|
* Returns the data for the given data id.
|
||||||
|
@ -119,18 +119,11 @@ protected:
|
|||||||
const SkFontStyle&) const SK_OVERRIDE {
|
const SkFontStyle&) const SK_OVERRIDE {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
|
||||||
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
||||||
const SkFontStyle& style,
|
const SkFontStyle& style,
|
||||||
const char* bcp47[],
|
const char* bcp47[],
|
||||||
int bcp47Count,
|
int bcp47Count,
|
||||||
SkUnichar character) const SK_OVERRIDE {
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
|
virtual SkTypeface* onMatchFaceStyle(const SkTypeface*,
|
||||||
@ -179,18 +172,11 @@ SkTypeface* SkFontMgr::matchFamilyStyle(const char familyName[],
|
|||||||
return this->onMatchFamilyStyle(familyName, fs);
|
return this->onMatchFamilyStyle(familyName, fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
|
||||||
SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
|
SkTypeface* SkFontMgr::matchFamilyStyleCharacter(const char familyName[], const SkFontStyle& style,
|
||||||
const char* bcp47[], int bcp47Count,
|
const char* bcp47[], int bcp47Count,
|
||||||
SkUnichar character) const {
|
SkUnichar character) const {
|
||||||
return this->onMatchFamilyStyleCharacter(familyName, style, bcp47, bcp47Count, character);
|
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,
|
SkTypeface* SkFontMgr::matchFaceStyle(const SkTypeface* face,
|
||||||
const SkFontStyle& fs) const {
|
const SkFontStyle& fs) const {
|
||||||
|
@ -245,7 +245,6 @@ SkTypeface* SkFontMgr_Indirect::onMatchFamilyStyle(const char familyName[],
|
|||||||
return this->createTypefaceFromFontId(id);
|
return this->createTypefaceFromFontId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
|
||||||
SkTypeface* SkFontMgr_Indirect::onMatchFamilyStyleCharacter(const char familyName[],
|
SkTypeface* SkFontMgr_Indirect::onMatchFamilyStyleCharacter(const char familyName[],
|
||||||
const SkFontStyle& style,
|
const SkFontStyle& style,
|
||||||
const char* bcp47[],
|
const char* bcp47[],
|
||||||
@ -255,15 +254,6 @@ SkTypeface* SkFontMgr_Indirect::onMatchFamilyStyleCharacter(const char familyNam
|
|||||||
bcp47Count, character);
|
bcp47Count, character);
|
||||||
return this->createTypefaceFromFontId(id);
|
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,
|
SkTypeface* SkFontMgr_Indirect::onMatchFaceStyle(const SkTypeface* familyMember,
|
||||||
const SkFontStyle& fontStyle) const {
|
const SkFontStyle& fontStyle) const {
|
||||||
|
@ -340,51 +340,42 @@ protected:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkTypeface_AndroidSystem* find_family_style_character(
|
static SkTypeface_AndroidSystem* find_family_style_character(
|
||||||
const SkTDArray<NameToFamily>& fallbackNameToFamilyMap,
|
const SkTDArray<NameToFamily>& fallbackNameToFamilyMap,
|
||||||
const SkFontStyle& style, bool elegant,
|
const SkFontStyle& style, bool elegant,
|
||||||
const SkString& langTag, SkUnichar character)
|
const SkString& langTag, SkUnichar character)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < fallbackNameToFamilyMap.count(); ++i) {
|
for (int i = 0; i < fallbackNameToFamilyMap.count(); ++i) {
|
||||||
SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet;
|
SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet;
|
||||||
SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchStyle(style));
|
SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchStyle(style));
|
||||||
|
|
||||||
if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c_str())) {
|
if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c_str())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SkToBool(face->fVariantStyle & kElegant_FontVariant) != elegant) {
|
if (SkToBool(face->fVariantStyle & kElegant_FontVariant) != elegant) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
paint.setTypeface(face);
|
paint.setTypeface(face);
|
||||||
paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
|
paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
|
||||||
|
|
||||||
uint16_t glyphID;
|
uint16_t glyphID;
|
||||||
paint.textToGlyphs(&character, sizeof(character), &glyphID);
|
paint.textToGlyphs(&character, sizeof(character), &glyphID);
|
||||||
if (glyphID != 0) {
|
if (glyphID != 0) {
|
||||||
return face.detach();
|
return face.detach();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
|
||||||
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
||||||
const SkFontStyle& style,
|
const SkFontStyle& style,
|
||||||
const char* bcp47[],
|
const char* bcp47[],
|
||||||
int bcp47Count,
|
int bcp47Count,
|
||||||
SkUnichar character) const SK_OVERRIDE
|
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 'elegant' is 'not squashed', 'compact' is 'stays in ascent/descent'.
|
||||||
// The variant 'default' means 'compact and elegant'.
|
// The variant 'default' means 'compact and elegant'.
|
||||||
// As a result, it is not possible to know the variant context from the font alone.
|
// As a result, it is not possible to know the variant context from the font alone.
|
||||||
|
@ -763,22 +763,12 @@ protected:
|
|||||||
return createTypefaceFromFcPattern(font);
|
return createTypefaceFromFcPattern(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
|
||||||
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
|
||||||
const SkFontStyle& style,
|
const SkFontStyle& style,
|
||||||
const char* bcp47[],
|
const char* bcp47[],
|
||||||
int bcp47Count,
|
int bcp47Count,
|
||||||
SkUnichar character) const SK_OVERRIDE
|
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;
|
FCLocker lock;
|
||||||
|
|
||||||
SkAutoFcPattern pattern;
|
SkAutoFcPattern pattern;
|
||||||
|
@ -408,21 +408,11 @@ public:
|
|||||||
SkFontIdentity fIdentity;
|
SkFontIdentity fIdentity;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef SK_FM_NEW_MATCH_FAMILY_STYLE_CHARACTER
|
|
||||||
virtual SkFontIdentity matchNameStyleCharacter(const char familyName[],
|
virtual SkFontIdentity matchNameStyleCharacter(const char familyName[],
|
||||||
const SkFontStyle& pattern,
|
const SkFontStyle& pattern,
|
||||||
const char* bcp47[], int bcp47Count,
|
const char* bcp47[], int bcp47Count,
|
||||||
SkUnichar character) const SK_OVERRIDE
|
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 };
|
SkFontIdentity identity = { SkFontIdentity::kInvalidDataId };
|
||||||
|
|
||||||
IDWriteFactory* dwFactory = sk_get_dwrite_factory();
|
IDWriteFactory* dwFactory = sk_get_dwrite_factory();
|
||||||
|
Loading…
Reference in New Issue
Block a user