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

Side by Side 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: Pull things together. 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The Android Open Source Project 2 * Copyright 2011 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkFontConfigParser_android.h" 8 #include "SkFontConfigParser_android.h"
9 #include "SkFontMgr_android.h" 9 #include "SkFontMgr_android.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 #define SK_FONTCONFIGPARSER_WARNING(message, ...) SkDebugf( \ 120 #define SK_FONTCONFIGPARSER_WARNING(message, ...) SkDebugf( \
121 SK_FONTCONFIGPARSER_PREFIX "%s:%d:%d: warning: " message "\n", \ 121 SK_FONTCONFIGPARSER_PREFIX "%s:%d:%d: warning: " message "\n", \
122 self->fFilename, \ 122 self->fFilename, \
123 XML_GetCurrentLineNumber(self->fParser), \ 123 XML_GetCurrentLineNumber(self->fParser), \
124 XML_GetCurrentColumnNumber(self->fParser), \ 124 XML_GetCurrentColumnNumber(self->fParser), \
125 ##__VA_ARGS__); 125 ##__VA_ARGS__);
126 126
127 namespace lmpParser { 127 namespace lmpParser {
128 128
129 static void family_element_handler(FontFamily* family, const char** attributes) { 129 static void family_element_handler(FamilyData* self, const char** attributes) {
130 // A <family> element without a 'name' (string) attribute is a fallback font . 130 // A <family> element without a 'name' (string) attribute is a fallback font .
131 // The element may have 'lang' (string) and 'variant' ("elegant", "compact") attributes. 131 // The element may have 'lang' (string) and 'variant' ("elegant", "compact") attributes.
132 // The element should contain <font> elements. 132 // The element should contain <font> elements.
133 family->fIsFallbackFont = true; 133 FontFamily* family = new FontFamily(self->fBasePath, true);
134 self->fCurrentFamily.reset(family);
134 for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) { 135 for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
135 const char* name = attributes[i]; 136 const char* name = attributes[i];
136 const char* value = attributes[i+1]; 137 const char* value = attributes[i+1];
137 size_t nameLen = strlen(name); 138 size_t nameLen = strlen(name);
138 size_t valueLen = strlen(value); 139 size_t valueLen = strlen(value);
139 if (MEMEQ("name", name, nameLen)) { 140 if (MEMEQ("name", name, nameLen)) {
140 SkAutoAsciiToLC tolc(value); 141 SkAutoAsciiToLC tolc(value);
141 family->fNames.push_back().set(tolc.lc()); 142 family->fNames.push_back().set(tolc.lc());
142 family->fIsFallbackFont = false; 143 family->fIsFallbackFont = false;
143 } else if (MEMEQ("lang", name, nameLen)) { 144 } else if (MEMEQ("lang", name, nameLen)) {
144 family->fLanguage = SkLanguage(value, valueLen); 145 family->fLanguage = SkLanguage(value, valueLen);
145 } else if (MEMEQ("variant", name, nameLen)) { 146 } else if (MEMEQ("variant", name, nameLen)) {
146 if (MEMEQ("elegant", value, valueLen)) { 147 if (MEMEQ("elegant", value, valueLen)) {
147 family->fVariant = kElegant_FontVariant; 148 family->fVariant = kElegant_FontVariant;
148 } else if (MEMEQ("compact", value, valueLen)) { 149 } else if (MEMEQ("compact", value, valueLen)) {
149 family->fVariant = kCompact_FontVariant; 150 family->fVariant = kCompact_FontVariant;
150 } 151 }
151 } 152 }
152 } 153 }
153 } 154 }
154 155
155 static void XMLCALL font_file_name_handler(void* data, const char* s, int len) { 156 static void XMLCALL font_file_name_handler(void* data, const char* s, int len) {
156 FamilyData* self = static_cast<FamilyData*>(data); 157 FamilyData* self = static_cast<FamilyData*>(data);
157 self->fCurrentFontInfo->fFileName.append(s, len); 158 self->fCurrentFontInfo->fFileName.append(s, len);
158 } 159 }
159 160
160 static void font_element_handler(FamilyData* self, FontFileInfo* file, const cha r** attributes) { 161 static void font_element_handler(FamilyData* self, const char** attributes) {
161 // A <font> element should be contained in a <family> element. 162 // A <font> element should be contained in a <family> element.
162 // The element may have 'weight' (non-negative integer), 'style' ("normal", "italic"), 163 // The element may have 'weight' (non-negative integer), 'style' ("normal", "italic"),
163 // and 'index' (non-negative integer) attributes. 164 // and 'index' (non-negative integer) attributes.
164 // The element should contain a filename. 165 // The element should contain a filename.
166 FontFileInfo& file = self->fCurrentFamily->fFonts.push_back();
167 self->fCurrentFontInfo = &file;
165 for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) { 168 for (size_t i = 0; ATTS_NON_NULL(attributes, i); i += 2) {
166 const char* name = attributes[i]; 169 const char* name = attributes[i];
167 const char* value = attributes[i+1]; 170 const char* value = attributes[i+1];
168 size_t nameLen = strlen(name); 171 size_t nameLen = strlen(name);
169 if (MEMEQ("weight", name, nameLen)) { 172 if (MEMEQ("weight", name, nameLen)) {
170 if (!parse_non_negative_integer(value, &file->fWeight)) { 173 if (!parse_non_negative_integer(value, &file.fWeight)) {
171 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid weight", value); 174 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid weight", value);
172 } 175 }
173 } else if (MEMEQ("style", name, nameLen)) { 176 } else if (MEMEQ("style", name, nameLen)) {
174 size_t valueLen = strlen(value); 177 size_t valueLen = strlen(value);
175 if (MEMEQ("normal", value, valueLen)) { 178 if (MEMEQ("normal", value, valueLen)) {
176 file->fStyle = FontFileInfo::Style::kNormal; 179 file.fStyle = FontFileInfo::Style::kNormal;
177 } else if (MEMEQ("italic", value, valueLen)) { 180 } else if (MEMEQ("italic", value, valueLen)) {
178 file->fStyle = FontFileInfo::Style::kItalic; 181 file.fStyle = FontFileInfo::Style::kItalic;
179 } 182 }
180 } else if (MEMEQ("index", name, nameLen)) { 183 } else if (MEMEQ("index", name, nameLen)) {
181 if (!parse_non_negative_integer(value, &file->fIndex)) { 184 if (!parse_non_negative_integer(value, &file.fIndex)) {
182 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid index", value); 185 SK_FONTCONFIGPARSER_WARNING("'%s' is an invalid index", value);
183 } 186 }
184 } 187 }
185 } 188 }
186 XML_SetCharacterDataHandler(self->fParser, font_file_name_handler); 189 XML_SetCharacterDataHandler(self->fParser, font_file_name_handler);
187 } 190 }
188 191
189 static FontFamily* find_family(FamilyData* self, const SkString& familyName) { 192 static FontFamily* find_family(FamilyData* self, const SkString& familyName) {
190 for (int i = 0; i < self->fFamilies.count(); i++) { 193 for (int i = 0; i < self->fFamilies.count(); i++) {
191 FontFamily* candidate = self->fFamilies[i]; 194 FontFamily* candidate = self->fFamilies[i];
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 *self->fFamilies.append() = family; 248 *self->fFamilies.append() = family;
246 } else { 249 } else {
247 targetFamily->fNames.push_back().set(aliasName); 250 targetFamily->fNames.push_back().set(aliasName);
248 } 251 }
249 } 252 }
250 253
251 static void XMLCALL start_element_handler(void* data, const char* tag, const cha r** attributes) { 254 static void XMLCALL start_element_handler(void* data, const char* tag, const cha r** attributes) {
252 FamilyData* self = static_cast<FamilyData*>(data); 255 FamilyData* self = static_cast<FamilyData*>(data);
253 size_t len = strlen(tag); 256 size_t len = strlen(tag);
254 if (MEMEQ("family", tag, len)) { 257 if (MEMEQ("family", tag, len)) {
255 self->fCurrentFamily.reset(new FontFamily(self->fBasePath, self->fIsFall back)); 258 family_element_handler(self, attributes);
256 family_element_handler(self->fCurrentFamily, attributes);
257 } else if (MEMEQ("font", tag, len)) { 259 } else if (MEMEQ("font", tag, len)) {
258 FontFileInfo* file = &self->fCurrentFamily->fFonts.push_back(); 260 font_element_handler(self, attributes);
259 self->fCurrentFontInfo = file;
260 font_element_handler(self, file, attributes);
261 } else if (MEMEQ("alias", tag, len)) { 261 } else if (MEMEQ("alias", tag, len)) {
262 alias_element_handler(self, attributes); 262 alias_element_handler(self, attributes);
263 } 263 }
264 } 264 }
265 265
266 static void XMLCALL end_element_handler(void* data, const char* tag) { 266 static void XMLCALL end_element_handler(void* data, const char* tag) {
267 FamilyData* self = static_cast<FamilyData*>(data); 267 FamilyData* self = static_cast<FamilyData*>(data);
268 size_t len = strlen(tag); 268 size_t len = strlen(tag);
269 if (MEMEQ("family", tag, len)) { 269 if (MEMEQ("family", tag, len)) {
270 *self->fFamilies.append() = self->fCurrentFamily.detach(); 270 *self->fFamilies.append() = self->fCurrentFamily.detach();
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 const char* tag = fTag.c_str(); 650 const char* tag = fTag.c_str();
651 651
652 // strip off the rightmost "-.*" 652 // strip off the rightmost "-.*"
653 const char* parentTagEnd = strrchr(tag, '-'); 653 const char* parentTagEnd = strrchr(tag, '-');
654 if (parentTagEnd == NULL) { 654 if (parentTagEnd == NULL) {
655 return SkLanguage(); 655 return SkLanguage();
656 } 656 }
657 size_t parentTagLen = parentTagEnd - tag; 657 size_t parentTagLen = parentTagEnd - tag;
658 return SkLanguage(tag, parentTagLen); 658 return SkLanguage(tag, parentTagLen);
659 } 659 }
OLDNEW
« 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