Allow all font weights on Android and respect overrides.
This removes the code which forces 400 and 700 weights only, and also overrides the font weight with the configured weight. Review URL: https://codereview.chromium.org/694533006
This commit is contained in:
parent
47eda52e8f
commit
4b86bacb04
@ -6209,7 +6209,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
17276962213970077366
|
||||
15535368433031718847
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -6218,7 +6218,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
8694218356938189525
|
||||
17714223495513615914
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
|
@ -6209,7 +6209,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
17276962213970077366
|
||||
15535368433031718847
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -6218,7 +6218,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
8694218356938189525
|
||||
17714223495513615914
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
|
@ -4853,7 +4853,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
5363798543478698363
|
||||
17992956605548700079
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -4862,7 +4862,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
8694218356938189525
|
||||
17714223495513615914
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
|
@ -4853,7 +4853,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
5363798543478698363
|
||||
17992956605548700079
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -4862,7 +4862,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
8694218356938189525
|
||||
17714223495513615914
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
|
@ -4647,7 +4647,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
17276962213970077366
|
||||
15535368433031718847
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -4656,7 +4656,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
8694218356938189525
|
||||
17714223495513615914
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
|
@ -4647,7 +4647,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
17276962213970077366
|
||||
15535368433031718847
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -4656,7 +4656,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
8694218356938189525
|
||||
17714223495513615914
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
|
@ -4687,7 +4687,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
1821325695757397620
|
||||
6653149078790784803
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -4696,7 +4696,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
13605807214433697
|
||||
7308045438196578573
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -4705,7 +4705,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
13605807214433697
|
||||
7308045438196578573
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
|
@ -4687,7 +4687,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
1821325695757397620
|
||||
6653149078790784803
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -4696,7 +4696,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
13605807214433697
|
||||
7308045438196578573
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
@ -4705,7 +4705,7 @@
|
||||
"allowed-digests": [
|
||||
[
|
||||
"bitmap-64bitMD5",
|
||||
13605807214433697
|
||||
7308045438196578573
|
||||
]
|
||||
],
|
||||
"reviewed-by-human": true
|
||||
|
@ -203,54 +203,7 @@ void aliasElementHandler(FamilyData* familyData, const char** attributes) {
|
||||
}
|
||||
}
|
||||
|
||||
bool findWeight400(FontFamily* family) {
|
||||
for (int i = 0; i < family->fFonts.count(); i++) {
|
||||
if (family->fFonts[i].fWeight == 400) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool desiredWeight(int weight) {
|
||||
return (weight == 400 || weight == 700);
|
||||
}
|
||||
|
||||
int countDesiredWeight(FontFamily* family) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < family->fFonts.count(); i++) {
|
||||
if (desiredWeight(family->fFonts[i].fWeight)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// To meet Skia's expectations, any family that contains weight=400
|
||||
// fonts should *only* contain {400,700}
|
||||
void purgeUndesiredWeights(FontFamily* family) {
|
||||
int count = countDesiredWeight(family);
|
||||
for (int i = 1, j = 0; i < family->fFonts.count(); i++) {
|
||||
if (desiredWeight(family->fFonts[j].fWeight)) {
|
||||
j++;
|
||||
}
|
||||
if ((i != j) && desiredWeight(family->fFonts[i].fWeight)) {
|
||||
family->fFonts[j] = family->fFonts[i];
|
||||
}
|
||||
}
|
||||
family->fFonts.resize_back(count);
|
||||
}
|
||||
|
||||
void familysetElementEndHandler(FamilyData* familyData) {
|
||||
for (int i = 0; i < familyData->families.count(); i++) {
|
||||
if (findWeight400(familyData->families[i])) {
|
||||
purgeUndesiredWeights(familyData->families[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void startElementHandler(void* data, const char* tag,
|
||||
const char** attributes) {
|
||||
void startElementHandler(void* data, const char* tag, const char** attributes) {
|
||||
FamilyData* familyData = (FamilyData*) data;
|
||||
size_t len = strlen(tag);
|
||||
if (len == 6 && !strncmp(tag, "family", len)) {
|
||||
@ -268,9 +221,7 @@ void startElementHandler(void* data, const char* tag,
|
||||
void endElementHandler(void* data, const char* tag) {
|
||||
FamilyData* familyData = (FamilyData*) data;
|
||||
size_t len = strlen(tag);
|
||||
if (len == 9 && strncmp(tag, "familyset", len) == 0) {
|
||||
familysetElementEndHandler(familyData);
|
||||
} else if (len == 6 && strncmp(tag, "family", len) == 0) {
|
||||
if (len == 6 && strncmp(tag, "family", len) == 0) {
|
||||
*familyData->families.append() = familyData->currentFamily;
|
||||
familyData->currentFamily = NULL;
|
||||
} else if (len == 4 && !strncmp(tag, "font", len)) {
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
SkTypeface_Android(int index,
|
||||
const SkFontStyle& style,
|
||||
bool isFixedPitch,
|
||||
const SkString familyName)
|
||||
const SkString& familyName)
|
||||
: INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
|
||||
, fIndex(index)
|
||||
, fFamilyName(familyName) { }
|
||||
@ -63,11 +63,11 @@ private:
|
||||
|
||||
class SkTypeface_AndroidSystem : public SkTypeface_Android {
|
||||
public:
|
||||
SkTypeface_AndroidSystem(const SkString pathName,
|
||||
SkTypeface_AndroidSystem(const SkString& pathName,
|
||||
int index,
|
||||
const SkFontStyle& style,
|
||||
bool isFixedPitch,
|
||||
const SkString familyName,
|
||||
const SkString& familyName,
|
||||
const SkLanguage& lang,
|
||||
FontVariant variantStyle)
|
||||
: INHERITED(index, style, isFixedPitch, familyName)
|
||||
@ -102,7 +102,7 @@ public:
|
||||
int index,
|
||||
const SkFontStyle& style,
|
||||
bool isFixedPitch,
|
||||
const SkString familyName)
|
||||
const SkString& familyName)
|
||||
: INHERITED(index, style, isFixedPitch, familyName)
|
||||
, fStream(SkRef(stream)) { }
|
||||
|
||||
@ -167,6 +167,10 @@ public:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fontFile.fWeight != 0) {
|
||||
style = SkFontStyle(fontFile.fWeight, style.width(), style.slant());
|
||||
}
|
||||
|
||||
const SkLanguage& lang = family.fLanguage;
|
||||
uint32_t variant = family.fVariant;
|
||||
if (kDefault_FontVariant == variant) {
|
||||
@ -231,16 +235,7 @@ public:
|
||||
|
||||
private:
|
||||
SkFontStyle style(int index) {
|
||||
return SkFontStyle(this->weight(index), SkFontStyle::kNormal_Width,
|
||||
this->slant(index));
|
||||
}
|
||||
SkFontStyle::Weight weight(int index) {
|
||||
if (fStyles[index]->isBold()) return SkFontStyle::kBold_Weight;
|
||||
return SkFontStyle::kNormal_Weight;
|
||||
}
|
||||
SkFontStyle::Slant slant(int index) {
|
||||
if (fStyles[index]->isItalic()) return SkFontStyle::kItalic_Slant;
|
||||
return SkFontStyle::kUpright_Slant;
|
||||
return fStyles[index]->fontStyle();
|
||||
}
|
||||
static int match_score(const SkFontStyle& pattern, const SkFontStyle& candidate) {
|
||||
int score = 0;
|
||||
|
@ -19,13 +19,12 @@ int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) {
|
||||
return countOfFallbackFonts;
|
||||
}
|
||||
|
||||
void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies,
|
||||
void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstExpectedFile,
|
||||
skiatest::Reporter* reporter) {
|
||||
REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5);
|
||||
REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans-serif"));
|
||||
REPORTER_ASSERT(reporter,
|
||||
!strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(),
|
||||
"Roboto-Regular.ttf"));
|
||||
!strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(), firstExpectedFile));
|
||||
REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont);
|
||||
}
|
||||
|
||||
@ -71,7 +70,7 @@ DEF_TEST(FontConfigParserAndroid, reporter) {
|
||||
REPORTER_ASSERT(reporter, CountFallbacks(preV17FontFamilies) == 10);
|
||||
|
||||
DumpLoadedFonts(preV17FontFamilies);
|
||||
ValidateLoadedFonts(preV17FontFamilies, reporter);
|
||||
ValidateLoadedFonts(preV17FontFamilies, "Roboto-Regular.ttf", reporter);
|
||||
} else {
|
||||
resourcesMissing = true;
|
||||
}
|
||||
@ -87,7 +86,7 @@ DEF_TEST(FontConfigParserAndroid, reporter) {
|
||||
REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 31);
|
||||
|
||||
DumpLoadedFonts(v17FontFamilies);
|
||||
ValidateLoadedFonts(v17FontFamilies, reporter);
|
||||
ValidateLoadedFonts(v17FontFamilies, "Roboto-Regular.ttf", reporter);
|
||||
} else {
|
||||
resourcesMissing = true;
|
||||
}
|
||||
@ -103,7 +102,7 @@ DEF_TEST(FontConfigParserAndroid, reporter) {
|
||||
REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42);
|
||||
|
||||
DumpLoadedFonts(v22FontFamilies);
|
||||
ValidateLoadedFonts(v22FontFamilies, reporter);
|
||||
ValidateLoadedFonts(v22FontFamilies, "Roboto-Thin.ttf", reporter);
|
||||
} else {
|
||||
resourcesMissing = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user