OLD | NEW |
---|---|
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 "SkTDArray.h" | 9 #include "SkTDArray.h" |
10 #include "SkTSearch.h" | 10 #include "SkTSearch.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 // for now. | 44 // for now. |
45 #define NO_TAG 0 | 45 #define NO_TAG 0 |
46 #define NAMESET_TAG 1 | 46 #define NAMESET_TAG 1 |
47 #define FILESET_TAG 2 | 47 #define FILESET_TAG 2 |
48 | 48 |
49 /** | 49 /** |
50 * The FamilyData structure is passed around by the parser so that each handler | 50 * The FamilyData structure is passed around by the parser so that each handler |
51 * can read these variables that are relevant to the current parsing. | 51 * can read these variables that are relevant to the current parsing. |
52 */ | 52 */ |
53 struct FamilyData { | 53 struct FamilyData { |
54 FamilyData(XML_Parser parserRef, SkTDArray<FontFamily*> &familiesRef) : | 54 FamilyData(XML_Parser parser, SkTDArray<FontFamily*> &families) |
mtklein
2015/01/30 23:32:09
Can it move &s and *s to the type too?
| |
55 parser(parserRef), | 55 : fParser(parser) |
56 families(familiesRef), | 56 , fFamilies(families) |
57 currentFamily(NULL), | 57 , fCurrentFamily(NULL) |
58 currentFontInfo(NULL), | 58 , fCurrentFontInfo(NULL) |
59 currentTag(NO_TAG) {}; | 59 , fCurrentTag(NO_TAG) |
60 { }; | |
60 | 61 |
61 XML_Parser parser; // The expat parser doing the work, owned by caller | 62 XML_Parser fParser; // The expat parser doing the work , owned by caller |
62 SkTDArray<FontFamily*>& families; // The array to append families, ow ned by caller | 63 SkTDArray<FontFamily*>& fFamilies; // The array to append families, o wned by caller |
63 SkAutoTDelete<FontFamily> currentFamily; // The family being created, owned by this | 64 SkAutoTDelete<FontFamily> fCurrentFamily; // The family being created, owned by this |
64 FontFileInfo* currentFontInfo; // The fontInfo being created, owne d by currentFamily | 65 FontFileInfo* fCurrentFontInfo; // The fontInfo being created, own ed by currentFamily |
65 int currentTag; // Flag to indicate when we're in n ameset/fileset tags | 66 int fCurrentTag; // Flag to indicate when we're in nameset/fileset tags |
66 }; | 67 }; |
67 | 68 |
68 /** http://www.w3.org/TR/html-markup/datatypes.html#common.data.integer.non-nega tive-def */ | 69 /** http://www.w3.org/TR/html-markup/datatypes.html#common.data.integer.non-nega tive-def */ |
69 template <typename T> static bool parseNonNegativeInteger(const char* s, T* valu e) { | 70 template <typename T> static bool parseNonNegativeInteger(const char* s, T* valu e) { |
70 SK_COMPILE_ASSERT(std::numeric_limits<T>::is_integer, T_must_be_integer); | 71 SK_COMPILE_ASSERT(std::numeric_limits<T>::is_integer, T_must_be_integer); |
71 const T nMax = std::numeric_limits<T>::max() / 10; | 72 const T nMax = std::numeric_limits<T>::max() / 10; |
72 const T dMax = std::numeric_limits<T>::max() - (nMax * 10); | 73 const T dMax = std::numeric_limits<T>::max() - (nMax * 10); |
73 T n = 0; | 74 T n = 0; |
74 for (; *s; ++s) { | 75 for (; *s; ++s) { |
75 // Check if digit | 76 // Check if digit |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 family->fVariant = kElegant_FontVariant; | 113 family->fVariant = kElegant_FontVariant; |
113 } else if (valueLen == 7 && !strncmp("compact", value, valueLen)) { | 114 } else if (valueLen == 7 && !strncmp("compact", value, valueLen)) { |
114 family->fVariant = kCompact_FontVariant; | 115 family->fVariant = kCompact_FontVariant; |
115 } | 116 } |
116 } | 117 } |
117 } | 118 } |
118 } | 119 } |
119 | 120 |
120 void fontFileNameHandler(void* data, const char* s, int len) { | 121 void fontFileNameHandler(void* data, const char* s, int len) { |
121 FamilyData* familyData = (FamilyData*) data; | 122 FamilyData* familyData = (FamilyData*) data; |
122 familyData->currentFontInfo->fFileName.set(s, len); | 123 familyData->fCurrentFontInfo->fFileName.set(s, len); |
123 } | 124 } |
124 | 125 |
125 void fontElementHandler(XML_Parser parser, FontFileInfo* file, const char** attr ibutes) { | 126 void fontElementHandler(XML_Parser parser, FontFileInfo* file, const char** attr ibutes) { |
126 // A <font> should have weight (integer) and style (normal, italic) attribut es. | 127 // A <font> should have weight (integer) and style (normal, italic) attribut es. |
127 // NOTE: we ignore the style. | 128 // NOTE: we ignore the style. |
128 // The element should contain a filename. | 129 // The element should contain a filename. |
129 for (size_t i = 0; attributes[i] != NULL && | 130 for (size_t i = 0; attributes[i] != NULL && |
130 attributes[i+1] != NULL; i += 2) { | 131 attributes[i+1] != NULL; i += 2) { |
131 const char* name = attributes[i]; | 132 const char* name = attributes[i]; |
132 const char* value = attributes[i+1]; | 133 const char* value = attributes[i+1]; |
133 size_t nameLen = strlen(name); | 134 size_t nameLen = strlen(name); |
134 if (nameLen == 6 && !strncmp("weight", name, nameLen)) { | 135 if (nameLen == 6 && !strncmp("weight", name, nameLen)) { |
135 if (!parseNonNegativeInteger(value, &file->fWeight)) { | 136 if (!parseNonNegativeInteger(value, &file->fWeight)) { |
136 SkDebugf("---- Font weight %s (INVALID)", value); | 137 SkDebugf("---- Font weight %s (INVALID)", value); |
137 file->fWeight = 0; | 138 file->fWeight = 0; |
138 } | 139 } |
139 } | 140 } |
140 } | 141 } |
141 XML_SetCharacterDataHandler(parser, fontFileNameHandler); | 142 XML_SetCharacterDataHandler(parser, fontFileNameHandler); |
142 } | 143 } |
143 | 144 |
144 FontFamily* findFamily(FamilyData* familyData, const char* familyName) { | 145 FontFamily* findFamily(FamilyData* familyData, const char* familyName) { |
145 size_t nameLen = strlen(familyName); | 146 size_t nameLen = strlen(familyName); |
146 for (int i = 0; i < familyData->families.count(); i++) { | 147 for (int i = 0; i < familyData->fFamilies.count(); i++) { |
147 FontFamily* candidate = familyData->families[i]; | 148 FontFamily* candidate = familyData->fFamilies[i]; |
148 for (int j = 0; j < candidate->fNames.count(); j++) { | 149 for (int j = 0; j < candidate->fNames.count(); j++) { |
149 if (!strncmp(candidate->fNames[j].c_str(), familyName, nameLen) && | 150 if (!strncmp(candidate->fNames[j].c_str(), familyName, nameLen) && |
150 nameLen == strlen(candidate->fNames[j].c_str())) { | 151 nameLen == strlen(candidate->fNames[j].c_str())) { |
151 return candidate; | 152 return candidate; |
152 } | 153 } |
153 } | 154 } |
154 } | 155 } |
155 | 156 |
156 return NULL; | 157 return NULL; |
157 } | 158 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 | 191 |
191 if (weight) { | 192 if (weight) { |
192 FontFamily* family = new FontFamily(); | 193 FontFamily* family = new FontFamily(); |
193 family->fNames.push_back().set(aliasName); | 194 family->fNames.push_back().set(aliasName); |
194 | 195 |
195 for (int i = 0; i < targetFamily->fFonts.count(); i++) { | 196 for (int i = 0; i < targetFamily->fFonts.count(); i++) { |
196 if (targetFamily->fFonts[i].fWeight == weight) { | 197 if (targetFamily->fFonts[i].fWeight == weight) { |
197 family->fFonts.push_back(targetFamily->fFonts[i]); | 198 family->fFonts.push_back(targetFamily->fFonts[i]); |
198 } | 199 } |
199 } | 200 } |
200 *familyData->families.append() = family; | 201 *familyData->fFamilies.append() = family; |
201 } else { | 202 } else { |
202 targetFamily->fNames.push_back().set(aliasName); | 203 targetFamily->fNames.push_back().set(aliasName); |
203 } | 204 } |
204 } | 205 } |
205 | 206 |
206 void startElementHandler(void* data, const char* tag, const char** attributes) { | 207 void startElementHandler(void* data, const char* tag, const char** attributes) { |
207 FamilyData* familyData = (FamilyData*) data; | 208 FamilyData* familyData = (FamilyData*) data; |
208 size_t len = strlen(tag); | 209 size_t len = strlen(tag); |
209 if (len == 6 && !strncmp(tag, "family", len)) { | 210 if (len == 6 && !strncmp(tag, "family", len)) { |
210 familyData->currentFamily.reset(new FontFamily()); | 211 familyData->fCurrentFamily.reset(new FontFamily()); |
211 familyElementHandler(familyData->currentFamily, attributes); | 212 familyElementHandler(familyData->fCurrentFamily, attributes); |
212 } else if (len == 4 && !strncmp(tag, "font", len)) { | 213 } else if (len == 4 && !strncmp(tag, "font", len)) { |
213 FontFileInfo* file = &familyData->currentFamily->fFonts.push_back(); | 214 FontFileInfo* file = &familyData->fCurrentFamily->fFonts.push_back(); |
214 familyData->currentFontInfo = file; | 215 familyData->fCurrentFontInfo = file; |
215 fontElementHandler(familyData->parser, file, attributes); | 216 fontElementHandler(familyData->fParser, file, attributes); |
216 } else if (len == 5 && !strncmp(tag, "alias", len)) { | 217 } else if (len == 5 && !strncmp(tag, "alias", len)) { |
217 aliasElementHandler(familyData, attributes); | 218 aliasElementHandler(familyData, attributes); |
218 } | 219 } |
219 } | 220 } |
220 | 221 |
221 void endElementHandler(void* data, const char* tag) { | 222 void endElementHandler(void* data, const char* tag) { |
222 FamilyData* familyData = (FamilyData*) data; | 223 FamilyData* familyData = (FamilyData*) data; |
223 size_t len = strlen(tag); | 224 size_t len = strlen(tag); |
224 if (len == 6 && strncmp(tag, "family", len) == 0) { | 225 if (len == 6 && strncmp(tag, "family", len) == 0) { |
225 *familyData->families.append() = familyData->currentFamily.detach(); | 226 *familyData->fFamilies.append() = familyData->fCurrentFamily.detach(); |
226 } else if (len == 4 && !strncmp(tag, "font", len)) { | 227 } else if (len == 4 && !strncmp(tag, "font", len)) { |
227 XML_SetCharacterDataHandler(familyData->parser, NULL); | 228 XML_SetCharacterDataHandler(familyData->fParser, NULL); |
228 } | 229 } |
229 } | 230 } |
230 | 231 |
231 } // lmpParser | 232 } // lmpParser |
232 | 233 |
233 namespace jbParser { | 234 namespace jbParser { |
234 | 235 |
235 /** | 236 /** |
236 * Handler for arbitrary text. This is used to parse the text inside each name | 237 * Handler for arbitrary text. This is used to parse the text inside each name |
237 * or file tag. The resulting strings are put into the fNames or FontFileInfo ar rays. | 238 * or file tag. The resulting strings are put into the fNames or FontFileInfo ar rays. |
238 */ | 239 */ |
239 static void textHandler(void* data, const char* s, int len) { | 240 static void textHandler(void* data, const char* s, int len) { |
240 FamilyData* familyData = (FamilyData*) data; | 241 FamilyData* familyData = (FamilyData*) data; |
241 // Make sure we're in the right state to store this name information | 242 // Make sure we're in the right state to store this name information |
242 if (familyData->currentFamily.get() && | 243 if (familyData->fCurrentFamily.get() && |
243 (familyData->currentTag == NAMESET_TAG || familyData->currentTag == FILESET_TAG)) { | 244 (familyData->fCurrentTag == NAMESET_TAG || familyData->fCurrentTag = = FILESET_TAG)) { |
244 switch (familyData->currentTag) { | 245 switch (familyData->fCurrentTag) { |
245 case NAMESET_TAG: { | 246 case NAMESET_TAG: { |
246 SkAutoAsciiToLC tolc(s, len); | 247 SkAutoAsciiToLC tolc(s, len); |
247 familyData->currentFamily->fNames.push_back().set(tolc.lc(), len); | 248 familyData->fCurrentFamily->fNames.push_back().set(tolc.lc(), len); |
248 break; | 249 break; |
249 } | 250 } |
250 case FILESET_TAG: | 251 case FILESET_TAG: |
251 if (familyData->currentFontInfo) { | 252 if (familyData->fCurrentFontInfo) { |
252 familyData->currentFontInfo->fFileName.set(s, len); | 253 familyData->fCurrentFontInfo->fFileName.set(s, len); |
253 } | 254 } |
254 break; | 255 break; |
255 default: | 256 default: |
256 // Noop - don't care about any text that's not in the Fonts or Names list | 257 // Noop - don't care about any text that's not in the Fonts or Names list |
257 break; | 258 break; |
258 } | 259 } |
259 } | 260 } |
260 } | 261 } |
261 | 262 |
262 /** | 263 /** |
263 * Handler for font files. This processes the attributes for language and | 264 * Handler for font files. This processes the attributes for language and |
264 * variants then lets textHandler handle the actual file name | 265 * variants then lets textHandler handle the actual file name |
265 */ | 266 */ |
266 static void fontFileElementHandler(FamilyData* familyData, const char** attribut es) { | 267 static void fontFileElementHandler(FamilyData* familyData, const char** attribut es) { |
267 FontFileInfo& newFileInfo = familyData->currentFamily->fFonts.push_back(); | 268 FontFileInfo& newFileInfo = familyData->fCurrentFamily->fFonts.push_back(); |
268 if (attributes) { | 269 if (attributes) { |
269 size_t currentAttributeIndex = 0; | 270 size_t currentAttributeIndex = 0; |
270 while (attributes[currentAttributeIndex] && | 271 while (attributes[currentAttributeIndex] && |
271 attributes[currentAttributeIndex + 1]) { | 272 attributes[currentAttributeIndex + 1]) { |
272 const char* attributeName = attributes[currentAttributeIndex]; | 273 const char* attributeName = attributes[currentAttributeIndex]; |
273 const char* attributeValue = attributes[currentAttributeIndex+1]; | 274 const char* attributeValue = attributes[currentAttributeIndex+1]; |
274 size_t nameLength = strlen(attributeName); | 275 size_t nameLength = strlen(attributeName); |
275 size_t valueLength = strlen(attributeValue); | 276 size_t valueLength = strlen(attributeValue); |
276 if (nameLength == 7 && strncmp(attributeName, "variant", nameLength) == 0) { | 277 if (nameLength == 7 && strncmp(attributeName, "variant", nameLength) == 0) { |
277 const FontVariant prevVariant = familyData->currentFamily->fVari ant; | 278 const FontVariant prevVariant = familyData->fCurrentFamily->fVar iant; |
278 if (valueLength == 7 && strncmp(attributeValue, "elegant", value Length) == 0) { | 279 if (valueLength == 7 && strncmp(attributeValue, "elegant", value Length) == 0) { |
279 familyData->currentFamily->fVariant = kElegant_FontVariant; | 280 familyData->fCurrentFamily->fVariant = kElegant_FontVariant; |
280 } else if (valueLength == 7 && | 281 } else if (valueLength == 7 && |
281 strncmp(attributeValue, "compact", valueLength) == 0) { | 282 strncmp(attributeValue, "compact", valueLength) == 0) { |
282 familyData->currentFamily->fVariant = kCompact_FontVariant; | 283 familyData->fCurrentFamily->fVariant = kCompact_FontVariant; |
283 } | 284 } |
284 if (familyData->currentFamily->fFonts.count() > 1 && | 285 if (familyData->fCurrentFamily->fFonts.count() > 1 && |
285 familyData->currentFamily->fVariant != prevVariant) { | 286 familyData->fCurrentFamily->fVariant != prevVariant) { |
286 SkDebugf("Every font file within a family must have identica l variants"); | 287 SkDebugf("Every font file within a family must have identica l variants"); |
287 sk_throw(); | 288 sk_throw(); |
288 } | 289 } |
289 | 290 |
290 } else if (nameLength == 4 && strncmp(attributeName, "lang", nameLen gth) == 0) { | 291 } else if (nameLength == 4 && strncmp(attributeName, "lang", nameLen gth) == 0) { |
291 SkLanguage prevLang = familyData->currentFamily->fLanguage; | 292 SkLanguage prevLang = familyData->fCurrentFamily->fLanguage; |
292 familyData->currentFamily->fLanguage = SkLanguage(attributeValue ); | 293 familyData->fCurrentFamily->fLanguage = SkLanguage(attributeValu e); |
293 if (familyData->currentFamily->fFonts.count() > 1 && | 294 if (familyData->fCurrentFamily->fFonts.count() > 1 && |
294 familyData->currentFamily->fLanguage != prevLang) { | 295 familyData->fCurrentFamily->fLanguage != prevLang) { |
295 SkDebugf("Every font file within a family must have identica l languages"); | 296 SkDebugf("Every font file within a family must have identica l languages"); |
296 sk_throw(); | 297 sk_throw(); |
297 } | 298 } |
298 } else if (nameLength == 5 && strncmp(attributeName, "index", nameLe ngth) == 0) { | 299 } else if (nameLength == 5 && strncmp(attributeName, "index", nameLe ngth) == 0) { |
299 int value; | 300 int value; |
300 if (parseNonNegativeInteger(attributeValue, &value)) { | 301 if (parseNonNegativeInteger(attributeValue, &value)) { |
301 newFileInfo.fIndex = value; | 302 newFileInfo.fIndex = value; |
302 } else { | 303 } else { |
303 SkDebugf("---- SystemFonts index=%s (INVALID)", attributeVal ue); | 304 SkDebugf("---- SystemFonts index=%s (INVALID)", attributeVal ue); |
304 } | 305 } |
305 } | 306 } |
306 //each element is a pair of attributeName/attributeValue string pair s | 307 //each element is a pair of attributeName/attributeValue string pair s |
307 currentAttributeIndex += 2; | 308 currentAttributeIndex += 2; |
308 } | 309 } |
309 } | 310 } |
310 familyData->currentFontInfo = &newFileInfo; | 311 familyData->fCurrentFontInfo = &newFileInfo; |
311 XML_SetCharacterDataHandler(familyData->parser, textHandler); | 312 XML_SetCharacterDataHandler(familyData->fParser, textHandler); |
312 } | 313 } |
313 | 314 |
314 /** | 315 /** |
315 * Handler for the start of a tag. The only tags we expect are familyset, family , | 316 * Handler for the start of a tag. The only tags we expect are familyset, family , |
316 * nameset, fileset, name, and file. | 317 * nameset, fileset, name, and file. |
317 */ | 318 */ |
318 static void startElementHandler(void* data, const char* tag, const char** atts) { | 319 static void startElementHandler(void* data, const char* tag, const char** atts) { |
319 FamilyData* familyData = (FamilyData*) data; | 320 FamilyData* familyData = (FamilyData*) data; |
320 size_t len = strlen(tag); | 321 size_t len = strlen(tag); |
321 if (len == 9 && strncmp(tag, "familyset", len) == 0) { | 322 if (len == 9 && strncmp(tag, "familyset", len) == 0) { |
322 // The familyset tag has an optional "version" attribute with an integer value >= 0 | 323 // The familyset tag has an optional "version" attribute with an integer value >= 0 |
323 for (size_t i = 0; atts[i] != NULL && | 324 for (size_t i = 0; atts[i] != NULL && |
324 atts[i+1] != NULL; i += 2) { | 325 atts[i+1] != NULL; i += 2) { |
325 size_t nameLen = strlen(atts[i]); | 326 size_t nameLen = strlen(atts[i]); |
326 if (nameLen == 7 && strncmp(atts[i], "version", nameLen)) continue; | 327 if (nameLen == 7 && strncmp(atts[i], "version", nameLen)) continue; |
327 const char* valueString = atts[i+1]; | 328 const char* valueString = atts[i+1]; |
328 int version; | 329 int version; |
329 if (parseNonNegativeInteger(valueString, &version) && (version >= 21 )) { | 330 if (parseNonNegativeInteger(valueString, &version) && (version >= 21 )) { |
330 XML_SetElementHandler(familyData->parser, | 331 XML_SetElementHandler(familyData->fParser, |
331 lmpParser::startElementHandler, | 332 lmpParser::startElementHandler, |
332 lmpParser::endElementHandler); | 333 lmpParser::endElementHandler); |
333 } | 334 } |
334 } | 335 } |
335 } else if (len == 6 && strncmp(tag, "family", len) == 0) { | 336 } else if (len == 6 && strncmp(tag, "family", len) == 0) { |
336 familyData->currentFamily.reset(new FontFamily()); | 337 familyData->fCurrentFamily.reset(new FontFamily()); |
337 // The Family tag has an optional "order" attribute with an integer valu e >= 0 | 338 // The Family tag has an optional "order" attribute with an integer valu e >= 0 |
338 // If this attribute does not exist, the default value is -1 | 339 // If this attribute does not exist, the default value is -1 |
339 for (size_t i = 0; atts[i] != NULL && | 340 for (size_t i = 0; atts[i] != NULL && |
340 atts[i+1] != NULL; i += 2) { | 341 atts[i+1] != NULL; i += 2) { |
341 const char* valueString = atts[i+1]; | 342 const char* valueString = atts[i+1]; |
342 int value; | 343 int value; |
343 if (parseNonNegativeInteger(valueString, &value)) { | 344 if (parseNonNegativeInteger(valueString, &value)) { |
344 familyData->currentFamily->fOrder = value; | 345 familyData->fCurrentFamily->fOrder = value; |
345 } | 346 } |
346 } | 347 } |
347 } else if (len == 7 && strncmp(tag, "nameset", len) == 0) { | 348 } else if (len == 7 && strncmp(tag, "nameset", len) == 0) { |
348 familyData->currentTag = NAMESET_TAG; | 349 familyData->fCurrentTag = NAMESET_TAG; |
349 } else if (len == 7 && strncmp(tag, "fileset", len) == 0) { | 350 } else if (len == 7 && strncmp(tag, "fileset", len) == 0) { |
350 familyData->currentTag = FILESET_TAG; | 351 familyData->fCurrentTag = FILESET_TAG; |
351 } else if (len == 4 && strncmp(tag, "name", len) == 0 && familyData->current Tag == NAMESET_TAG) { | 352 } else if (len == 4 && strncmp(tag, "name", len) == 0 && familyData->fCurren tTag == NAMESET_TAG) { |
352 // If it's a Name, parse the text inside | 353 // If it's a Name, parse the text inside |
353 XML_SetCharacterDataHandler(familyData->parser, textHandler); | 354 XML_SetCharacterDataHandler(familyData->fParser, textHandler); |
354 } else if (len == 4 && strncmp(tag, "file", len) == 0 && familyData->current Tag == FILESET_TAG) { | 355 } else if (len == 4 && strncmp(tag, "file", len) == 0 && familyData->fCurren tTag == FILESET_TAG) { |
355 // If it's a file, parse the attributes, then parse the text inside | 356 // If it's a file, parse the attributes, then parse the text inside |
356 fontFileElementHandler(familyData, atts); | 357 fontFileElementHandler(familyData, atts); |
357 } | 358 } |
358 } | 359 } |
359 | 360 |
360 /** | 361 /** |
361 * Handler for the end of tags. We only care about family, nameset, fileset, | 362 * Handler for the end of tags. We only care about family, nameset, fileset, |
362 * name, and file. | 363 * name, and file. |
363 */ | 364 */ |
364 static void endElementHandler(void* data, const char* tag) { | 365 static void endElementHandler(void* data, const char* tag) { |
365 FamilyData* familyData = (FamilyData*) data; | 366 FamilyData* familyData = (FamilyData*) data; |
366 size_t len = strlen(tag); | 367 size_t len = strlen(tag); |
367 if (len == 6 && strncmp(tag, "family", len)== 0) { | 368 if (len == 6 && strncmp(tag, "family", len)== 0) { |
368 // Done parsing a Family - store the created currentFamily in the famili es array | 369 // Done parsing a Family - store the created currentFamily in the famili es array |
369 *familyData->families.append() = familyData->currentFamily.detach(); | 370 *familyData->fFamilies.append() = familyData->fCurrentFamily.detach(); |
370 } else if (len == 7 && strncmp(tag, "nameset", len) == 0) { | 371 } else if (len == 7 && strncmp(tag, "nameset", len) == 0) { |
371 familyData->currentTag = NO_TAG; | 372 familyData->fCurrentTag = NO_TAG; |
372 } else if (len == 7 && strncmp(tag, "fileset", len) == 0) { | 373 } else if (len == 7 && strncmp(tag, "fileset", len) == 0) { |
373 familyData->currentTag = NO_TAG; | 374 familyData->fCurrentTag = NO_TAG; |
374 } else if ((len == 4 && | 375 } else if ((len == 4 && |
375 strncmp(tag, "name", len) == 0 && | 376 strncmp(tag, "name", len) == 0 && |
376 familyData->currentTag == NAMESET_TAG) || | 377 familyData->fCurrentTag == NAMESET_TAG) || |
377 (len == 4 && | 378 (len == 4 && |
378 strncmp(tag, "file", len) == 0 && | 379 strncmp(tag, "file", len) == 0 && |
379 familyData->currentTag == FILESET_TAG)) { | 380 familyData->fCurrentTag == FILESET_TAG)) { |
380 // Disable the arbitrary text handler installed to load Name data | 381 // Disable the arbitrary text handler installed to load Name data |
381 XML_SetCharacterDataHandler(familyData->parser, NULL); | 382 XML_SetCharacterDataHandler(familyData->fParser, NULL); |
382 } | 383 } |
383 } | 384 } |
384 | 385 |
385 } // namespace jbParser | 386 } // namespace jbParser |
386 | 387 |
387 /** | 388 /** |
388 * This function parses the given filename and stores the results in the given | 389 * This function parses the given filename and stores the results in the given |
389 * families array. | 390 * families array. |
390 */ | 391 */ |
391 static void parseConfigFile(const char* filename, SkTDArray<FontFamily*> &famili es) { | 392 static void parseConfigFile(const char* filename, SkTDArray<FontFamily*> &famili es) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 const char* tag = fTag.c_str(); | 553 const char* tag = fTag.c_str(); |
553 | 554 |
554 // strip off the rightmost "-.*" | 555 // strip off the rightmost "-.*" |
555 const char* parentTagEnd = strrchr(tag, '-'); | 556 const char* parentTagEnd = strrchr(tag, '-'); |
556 if (parentTagEnd == NULL) { | 557 if (parentTagEnd == NULL) { |
557 return SkLanguage(); | 558 return SkLanguage(); |
558 } | 559 } |
559 size_t parentTagLen = parentTagEnd - tag; | 560 size_t parentTagLen = parentTagEnd - tag; |
560 return SkLanguage(tag, parentTagLen); | 561 return SkLanguage(tag, parentTagLen); |
561 } | 562 } |
OLD | NEW |