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

Unified Diff: src/ports/SkFontConfigParser_android.cpp

Issue 1086943007: Regularize lmp::XXX_element_handler. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontConfigParser_android.cpp
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp
index 9bab84556b105f2f3dc06933a620e48aa4d2311e..3a133d976e338dfd0089b5fc0d8273daaad8bdcb 100644
--- a/src/ports/SkFontConfigParser_android.cpp
+++ b/src/ports/SkFontConfigParser_android.cpp
@@ -115,11 +115,12 @@ static bool memeq(const char* s1, const char* s2, size_t n1, size_t n2) {
namespace lmpParser {
-static void family_element_handler(FontFamily* family, const char** attributes) {
+static void family_element_handler(FamilyData* self, const char** attributes) {
// A non-fallback <family> tag must have a canonical name attribute.
// A fallback <family> tag has no name, and may have lang and variant
// attributes.
- family->fIsFallbackFont = true;
+ FontFamily& family = *self->fCurrentFamily;
+ family.fIsFallbackFont = true;
tomhudson 2015/04/20 18:11:39 Why are you making /family/ a reference instead of
bungeman-skia 2015/04/20 20:14:57 Mostly for consistency with font_element_handler,
for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
const char* name = attributes[i];
const char* value = attributes[i+1];
@@ -127,16 +128,16 @@ static void family_element_handler(FontFamily* family, const char** attributes)
size_t valueLen = strlen(value);
if (MEMEQ("name", name, nameLen)) {
SkAutoAsciiToLC tolc(value);
- family->fNames.push_back().set(tolc.lc());
- family->fIsFallbackFont = false;
+ family.fNames.push_back().set(tolc.lc());
+ family.fIsFallbackFont = false;
} else if (MEMEQ("lang", name, nameLen)) {
- family->fLanguage = SkLanguage(value, valueLen);
+ family.fLanguage = SkLanguage(value, valueLen);
} else if (MEMEQ("variant", name, nameLen)) {
// Value should be either elegant or compact.
if (MEMEQ("elegant", value, valueLen)) {
- family->fVariant = kElegant_FontVariant;
+ family.fVariant = kElegant_FontVariant;
} else if (MEMEQ("compact", value, valueLen)) {
- family->fVariant = kCompact_FontVariant;
+ family.fVariant = kCompact_FontVariant;
}
}
}
@@ -147,27 +148,28 @@ static void XMLCALL font_file_name_handler(void* data, const char* s, int len) {
self->fCurrentFontInfo->fFileName.append(s, len);
}
-static void font_element_handler(FamilyData* self, FontFileInfo* file, const char** attributes) {
+static void font_element_handler(FamilyData* self, const char** attributes) {
// A <font> should have weight (integer) and style (normal, italic) attributes.
// NOTE: we ignore the style.
// The element should contain a filename.
+ FontFileInfo& file = *self->fCurrentFontInfo;
for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
const char* name = attributes[i];
const char* value = attributes[i+1];
size_t nameLen = strlen(name);
if (MEMEQ("weight", name, nameLen)) {
- if (!parse_non_negative_integer(value, &file->fWeight)) {
+ if (!parse_non_negative_integer(value, &file.fWeight)) {
SkDebugf("---- Font weight %s (INVALID)", value);
}
} else if (MEMEQ("style", name, nameLen)) {
size_t valueLen = strlen(value);
if (MEMEQ("normal", value, valueLen)) {
- file->fStyle = FontFileInfo::Style::kNormal;
+ file.fStyle = FontFileInfo::Style::kNormal;
} else if (MEMEQ("italic", value, valueLen)) {
- file->fStyle = FontFileInfo::Style::kItalic;
+ file.fStyle = FontFileInfo::Style::kItalic;
}
} else if (MEMEQ("index", name, nameLen)) {
- if (!parse_non_negative_integer(value, &file->fIndex)) {
+ if (!parse_non_negative_integer(value, &file.fIndex)) {
SkDebugf("---- Font index %s (INVALID)", value);
}
}
@@ -240,11 +242,10 @@ static void XMLCALL start_element_handler(void* data, const char* tag, const cha
size_t len = strlen(tag);
if (MEMEQ("family", tag, len)) {
self->fCurrentFamily.reset(new FontFamily(self->fBasePath, self->fIsFallback));
- family_element_handler(self->fCurrentFamily, attributes);
+ family_element_handler(self, attributes);
} else if (MEMEQ("font", tag, len)) {
- FontFileInfo* file = &self->fCurrentFamily->fFonts.push_back();
- self->fCurrentFontInfo = file;
- font_element_handler(self, file, attributes);
+ self->fCurrentFontInfo = &self->fCurrentFamily->fFonts.push_back();
+ font_element_handler(self, attributes);
} else if (MEMEQ("alias", tag, len)) {
alias_element_handler(self, attributes);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698