diff options
author | bungeman <bungeman@google.com> | 2015-04-20 13:31:46 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-20 13:31:46 -0700 |
commit | e1ddb3b190697a26154bff207fce2189c8be6d30 (patch) | |
tree | 2c41e134ef7a9d339f2cc2d0a12c43ad78c4245b /src/ports | |
parent | d1e72875d195685e8dc45d3f065a05ff49da8ce3 (diff) |
Regularize lmp::XXX_element_handler.
This makes all non-XMLCALL element_handler functions uniform by making
their signature
void XXX_element_handler(FamilyData* self, const char** attributes)
This makes the code somewhat easier to follow, as it makes explicit
which functions are actually logically methods of FamilyData (start
with 'FamilyData* self') and which are called directly by expat
(start with 'void* data').
Review URL: https://codereview.chromium.org/1086943007
Diffstat (limited to 'src/ports')
-rw-r--r-- | src/ports/SkFontConfigParser_android.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp index 2535d69e7f..e60f4e4ea3 100644 --- a/src/ports/SkFontConfigParser_android.cpp +++ b/src/ports/SkFontConfigParser_android.cpp @@ -126,11 +126,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 <family> element without a 'name' (string) attribute is a fallback font. // The element may have 'lang' (string) and 'variant' ("elegant", "compact") attributes. // The element should contain <font> elements. - family->fIsFallbackFont = true; + FontFamily* family = new FontFamily(self->fBasePath, true); + self->fCurrentFamily.reset(family); for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) { const char* name = attributes[i]; const char* value = attributes[i+1]; @@ -157,28 +158,30 @@ 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> element should be contained in a <family> element. // The element may have 'weight' (non-negative integer), 'style' ("normal", "italic"), // and 'index' (non-negative integer) attributes. // The element should contain a filename. + FontFileInfo& file = self->fCurrentFamily->fFonts.push_back(); + self->fCurrentFontInfo = &file; 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)) { SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid weight", 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)) { SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid index", value); } } @@ -252,12 +255,9 @@ static void XMLCALL start_element_handler(void* data, const char* tag, const cha FamilyData* self = static_cast<FamilyData*>(data); 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); + font_element_handler(self, attributes); } else if (MEMEQ("alias", tag, len)) { alias_element_handler(self, attributes); } |