Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(903)

Unified Diff: src/ports/SkFontConfigParser_android.cpp

Issue 447873003: Remove SkPaintOptionsAndroid (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: typo Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/ports/SkFontConfigParser_android.cpp
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp
index e9c912f4b012e0e9608eab2cf5d7713d6cc48d49..bc4bca21594966718666f3709606c4ff5ac56d66 100644
--- a/src/ports/SkFontConfigParser_android.cpp
+++ b/src/ports/SkFontConfigParser_android.cpp
@@ -109,9 +109,9 @@ void familyElementHandler(FontFamily* family, const char** attributes) {
} else if (nameLen == 7 && !strncmp("variant", name, nameLen)) {
// Value should be either elegant or compact.
if (valueLen == 7 && !strncmp("elegant", value, valueLen)) {
- family->fVariant = SkPaintOptionsAndroid::kElegant_Variant;
+ family->fVariant = kElegant_FontVariant;
} else if (valueLen == 7 && !strncmp("compact", value, valueLen)) {
- family->fVariant = SkPaintOptionsAndroid::kCompact_Variant;
+ family->fVariant = kCompact_FontVariant;
}
}
}
@@ -122,13 +122,6 @@ void fontFileNameHandler(void* data, const char* s, int len) {
familyData->currentFontInfo->fFileName.set(s, len);
}
-void familyElementEndHandler(FontFamily* family) {
- for (int i = 0; i < family->fFonts.count(); i++) {
- family->fFonts[i].fPaintOptions.setLanguage(family->fLanguage);
- family->fFonts[i].fPaintOptions.setFontVariant(family->fVariant);
- }
-}
-
void fontElementHandler(XML_Parser* parser, FontFileInfo* file, const char** attributes) {
// A <font> should have weight (integer) and style (normal, italic) attributes.
// NOTE: we ignore the style.
@@ -278,7 +271,6 @@ void endElementHandler(void* data, const char* tag) {
if (len == 9 && strncmp(tag, "familyset", len) == 0) {
familysetElementEndHandler(familyData);
} else if (len == 6 && strncmp(tag, "family", len) == 0) {
- familyElementEndHandler(familyData->currentFamily);
*familyData->families.append() = familyData->currentFamily;
familyData->currentFamily = NULL;
} else if (len == 4 && !strncmp(tag, "font", len)) {
@@ -332,14 +324,27 @@ static void fontFileElementHandler(FamilyData* familyData, const char** attribut
size_t nameLength = strlen(attributeName);
size_t valueLength = strlen(attributeValue);
if (nameLength == 7 && strncmp(attributeName, "variant", nameLength) == 0) {
+ const FontVariant prevVariant = familyData->currentFamily->fVariant;
if (valueLength == 7 && strncmp(attributeValue, "elegant", valueLength) == 0) {
- newFileInfo.fPaintOptions.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant);
+ familyData->currentFamily->fVariant = kElegant_FontVariant;
} else if (valueLength == 7 &&
strncmp(attributeValue, "compact", valueLength) == 0) {
- newFileInfo.fPaintOptions.setFontVariant(SkPaintOptionsAndroid::kCompact_Variant);
+ familyData->currentFamily->fVariant = kCompact_FontVariant;
+ }
+ if (familyData->currentFamily->fFonts.count() > 1 &&
+ familyData->currentFamily->fVariant != prevVariant) {
+ SkDebugf("Every font file within a family must have identical variants");
+ sk_throw();
}
+
} else if (nameLength == 4 && strncmp(attributeName, "lang", nameLength) == 0) {
- newFileInfo.fPaintOptions.setLanguage(attributeValue);
+ SkLanguage prevLang = familyData->currentFamily->fLanguage;
+ familyData->currentFamily->fLanguage = SkLanguage(attributeValue);
+ if (familyData->currentFamily->fFonts.count() > 1 &&
+ familyData->currentFamily->fLanguage != prevLang) {
+ SkDebugf("Every font file within a family must have identical languages");
+ sk_throw();
+ }
} else if (nameLength == 5 && strncmp(attributeName, "index", nameLength) == 0) {
int value;
if (parseNonNegativeInteger(attributeValue, &value)) {
@@ -513,9 +518,7 @@ static void getFallbackFontFamiliesForLocale(SkTDArray<FontFamily*> &fallbackFon
for (int i = 0; i < langSpecificFonts.count(); ++i) {
FontFamily* family = langSpecificFonts[i];
- for (int j = 0; j < family->fFonts.count(); ++j) {
- family->fFonts[j].fPaintOptions.setLanguage(locale);
- }
+ family->fLanguage = SkLanguage(locale);
*fallbackFonts.append() = family;
}
}
@@ -593,3 +596,16 @@ void SkFontConfigParser::GetTestFontFamilies(SkTDArray<FontFamily*> &fontFamilie
*fontFamilies.append() = fallbackFonts[i];
}
}
+
+SkLanguage SkLanguage::getParent() const {
+ SkASSERT(!fTag.isEmpty());
+ const char* tag = fTag.c_str();
+
+ // strip off the rightmost "-.*"
+ const char* parentTagEnd = strrchr(tag, '-');
+ if (parentTagEnd == NULL) {
+ return SkLanguage();
+ }
+ size_t parentTagLen = parentTagEnd - tag;
+ return SkLanguage(tag, parentTagLen);
+}

Powered by Google App Engine
This is Rietveld 408576698