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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 size_t valueLen = strlen(value); | 102 size_t valueLen = strlen(value); |
103 if (nameLen == 4 && !strncmp("name", name, nameLen)) { | 103 if (nameLen == 4 && !strncmp("name", name, nameLen)) { |
104 SkAutoAsciiToLC tolc(value); | 104 SkAutoAsciiToLC tolc(value); |
105 family->fNames.push_back().set(tolc.lc()); | 105 family->fNames.push_back().set(tolc.lc()); |
106 family->fIsFallbackFont = false; | 106 family->fIsFallbackFont = false; |
107 } else if (nameLen == 4 && !strncmp("lang", name, nameLen)) { | 107 } else if (nameLen == 4 && !strncmp("lang", name, nameLen)) { |
108 family->fLanguage = SkLanguage (value); | 108 family->fLanguage = SkLanguage (value); |
109 } else if (nameLen == 7 && !strncmp("variant", name, nameLen)) { | 109 } else if (nameLen == 7 && !strncmp("variant", name, nameLen)) { |
110 // Value should be either elegant or compact. | 110 // Value should be either elegant or compact. |
111 if (valueLen == 7 && !strncmp("elegant", value, valueLen)) { | 111 if (valueLen == 7 && !strncmp("elegant", value, valueLen)) { |
112 family->fVariant = kElegant_FontVariant; | 112 family->fVariant = SkPaintOptionsAndroid::kElegant_Variant; |
113 } else if (valueLen == 7 && !strncmp("compact", value, valueLen)) { | 113 } else if (valueLen == 7 && !strncmp("compact", value, valueLen)) { |
114 family->fVariant = kCompact_FontVariant; | 114 family->fVariant = SkPaintOptionsAndroid::kCompact_Variant; |
115 } | 115 } |
116 } | 116 } |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 void fontFileNameHandler(void* data, const char* s, int len) { | 120 void fontFileNameHandler(void* data, const char* s, int len) { |
121 FamilyData* familyData = (FamilyData*) data; | 121 FamilyData* familyData = (FamilyData*) data; |
122 familyData->currentFontInfo->fFileName.set(s, len); | 122 familyData->currentFontInfo->fFileName.set(s, len); |
123 } | 123 } |
124 | 124 |
| 125 void familyElementEndHandler(FontFamily* family) { |
| 126 for (int i = 0; i < family->fFonts.count(); i++) { |
| 127 family->fFonts[i].fPaintOptions.setLanguage(family->fLanguage); |
| 128 family->fFonts[i].fPaintOptions.setFontVariant(family->fVariant); |
| 129 } |
| 130 } |
| 131 |
125 void fontElementHandler(XML_Parser* parser, FontFileInfo* file, const char** att
ributes) { | 132 void fontElementHandler(XML_Parser* parser, FontFileInfo* file, const char** att
ributes) { |
126 // A <font> should have weight (integer) and style (normal, italic) attribut
es. | 133 // A <font> should have weight (integer) and style (normal, italic) attribut
es. |
127 // NOTE: we ignore the style. | 134 // NOTE: we ignore the style. |
128 // The element should contain a filename. | 135 // The element should contain a filename. |
129 for (size_t i = 0; attributes[i] != NULL && | 136 for (size_t i = 0; attributes[i] != NULL && |
130 attributes[i+1] != NULL; i += 2) { | 137 attributes[i+1] != NULL; i += 2) { |
131 const char* name = attributes[i]; | 138 const char* name = attributes[i]; |
132 const char* value = attributes[i+1]; | 139 const char* value = attributes[i+1]; |
133 size_t nameLen = strlen(name); | 140 size_t nameLen = strlen(name); |
134 if (nameLen == 6 && !strncmp("weight", name, nameLen)) { | 141 if (nameLen == 6 && !strncmp("weight", name, nameLen)) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 aliasElementHandler(familyData, attributes); | 271 aliasElementHandler(familyData, attributes); |
265 } | 272 } |
266 } | 273 } |
267 | 274 |
268 void endElementHandler(void* data, const char* tag) { | 275 void endElementHandler(void* data, const char* tag) { |
269 FamilyData* familyData = (FamilyData*) data; | 276 FamilyData* familyData = (FamilyData*) data; |
270 size_t len = strlen(tag); | 277 size_t len = strlen(tag); |
271 if (len == 9 && strncmp(tag, "familyset", len) == 0) { | 278 if (len == 9 && strncmp(tag, "familyset", len) == 0) { |
272 familysetElementEndHandler(familyData); | 279 familysetElementEndHandler(familyData); |
273 } else if (len == 6 && strncmp(tag, "family", len) == 0) { | 280 } else if (len == 6 && strncmp(tag, "family", len) == 0) { |
| 281 familyElementEndHandler(familyData->currentFamily); |
274 *familyData->families.append() = familyData->currentFamily; | 282 *familyData->families.append() = familyData->currentFamily; |
275 familyData->currentFamily = NULL; | 283 familyData->currentFamily = NULL; |
276 } else if (len == 4 && !strncmp(tag, "font", len)) { | 284 } else if (len == 4 && !strncmp(tag, "font", len)) { |
277 XML_SetCharacterDataHandler(*familyData->parser, NULL); | 285 XML_SetCharacterDataHandler(*familyData->parser, NULL); |
278 } | 286 } |
279 } | 287 } |
280 | 288 |
281 } // lmpParser | 289 } // lmpParser |
282 | 290 |
283 namespace jbParser { | 291 namespace jbParser { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 FontFileInfo& newFileInfo = familyData->currentFamily->fFonts.push_back(); | 325 FontFileInfo& newFileInfo = familyData->currentFamily->fFonts.push_back(); |
318 if (attributes) { | 326 if (attributes) { |
319 size_t currentAttributeIndex = 0; | 327 size_t currentAttributeIndex = 0; |
320 while (attributes[currentAttributeIndex] && | 328 while (attributes[currentAttributeIndex] && |
321 attributes[currentAttributeIndex + 1]) { | 329 attributes[currentAttributeIndex + 1]) { |
322 const char* attributeName = attributes[currentAttributeIndex]; | 330 const char* attributeName = attributes[currentAttributeIndex]; |
323 const char* attributeValue = attributes[currentAttributeIndex+1]; | 331 const char* attributeValue = attributes[currentAttributeIndex+1]; |
324 size_t nameLength = strlen(attributeName); | 332 size_t nameLength = strlen(attributeName); |
325 size_t valueLength = strlen(attributeValue); | 333 size_t valueLength = strlen(attributeValue); |
326 if (nameLength == 7 && strncmp(attributeName, "variant", nameLength)
== 0) { | 334 if (nameLength == 7 && strncmp(attributeName, "variant", nameLength)
== 0) { |
327 const FontVariant prevVariant = familyData->currentFamily->fVari
ant; | |
328 if (valueLength == 7 && strncmp(attributeValue, "elegant", value
Length) == 0) { | 335 if (valueLength == 7 && strncmp(attributeValue, "elegant", value
Length) == 0) { |
329 familyData->currentFamily->fVariant = kElegant_FontVariant; | 336 newFileInfo.fPaintOptions.setFontVariant(SkPaintOptionsAndro
id::kElegant_Variant); |
330 } else if (valueLength == 7 && | 337 } else if (valueLength == 7 && |
331 strncmp(attributeValue, "compact", valueLength) == 0)
{ | 338 strncmp(attributeValue, "compact", valueLength) == 0)
{ |
332 familyData->currentFamily->fVariant = kCompact_FontVariant; | 339 newFileInfo.fPaintOptions.setFontVariant(SkPaintOptionsAndro
id::kCompact_Variant); |
333 } | 340 } |
334 if (familyData->currentFamily->fFonts.count() > 1 && | |
335 familyData->currentFamily->fVariant != prevVariant) { | |
336 SkDebugf("Every font file within a family must have identica
l variants"); | |
337 sk_throw(); | |
338 } | |
339 | |
340 } else if (nameLength == 4 && strncmp(attributeName, "lang", nameLen
gth) == 0) { | 341 } else if (nameLength == 4 && strncmp(attributeName, "lang", nameLen
gth) == 0) { |
341 SkLanguage prevLang = familyData->currentFamily->fLanguage; | 342 newFileInfo.fPaintOptions.setLanguage(attributeValue); |
342 familyData->currentFamily->fLanguage = SkLanguage(attributeValue
); | |
343 if (familyData->currentFamily->fFonts.count() > 1 && | |
344 familyData->currentFamily->fLanguage != prevLang) { | |
345 SkDebugf("Every font file within a family must have identica
l languages"); | |
346 sk_throw(); | |
347 } | |
348 } else if (nameLength == 5 && strncmp(attributeName, "index", nameLe
ngth) == 0) { | 343 } else if (nameLength == 5 && strncmp(attributeName, "index", nameLe
ngth) == 0) { |
349 int value; | 344 int value; |
350 if (parseNonNegativeInteger(attributeValue, &value)) { | 345 if (parseNonNegativeInteger(attributeValue, &value)) { |
351 newFileInfo.fIndex = value; | 346 newFileInfo.fIndex = value; |
352 } else { | 347 } else { |
353 SkDebugf("---- SystemFonts index=%s (INVALID)", attributeVal
ue); | 348 SkDebugf("---- SystemFonts index=%s (INVALID)", attributeVal
ue); |
354 } | 349 } |
355 } | 350 } |
356 //each element is a pair of attributeName/attributeValue string pair
s | 351 //each element is a pair of attributeName/attributeValue string pair
s |
357 currentAttributeIndex += 2; | 352 currentAttributeIndex += 2; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 fileName.size() - fixedLen); | 506 fileName.size() - fixedLen); |
512 | 507 |
513 SkString absoluteFilename; | 508 SkString absoluteFilename; |
514 absoluteFilename.printf("%s/%s", dir, fileName.c_str()); | 509 absoluteFilename.printf("%s/%s", dir, fileName.c_str()); |
515 | 510 |
516 SkTDArray<FontFamily*> langSpecificFonts; | 511 SkTDArray<FontFamily*> langSpecificFonts; |
517 parseConfigFile(absoluteFilename.c_str(), langSpecificFonts); | 512 parseConfigFile(absoluteFilename.c_str(), langSpecificFonts); |
518 | 513 |
519 for (int i = 0; i < langSpecificFonts.count(); ++i) { | 514 for (int i = 0; i < langSpecificFonts.count(); ++i) { |
520 FontFamily* family = langSpecificFonts[i]; | 515 FontFamily* family = langSpecificFonts[i]; |
521 family->fLanguage = SkLanguage(locale); | 516 for (int j = 0; j < family->fFonts.count(); ++j) { |
| 517 family->fFonts[j].fPaintOptions.setLanguage(locale); |
| 518 } |
522 *fallbackFonts.append() = family; | 519 *fallbackFonts.append() = family; |
523 } | 520 } |
524 } | 521 } |
525 | 522 |
526 // proceed to the next entry in the directory | 523 // proceed to the next entry in the directory |
527 dirEntry = readdir(fontDirectory); | 524 dirEntry = readdir(fontDirectory); |
528 } | 525 } |
529 // cleanup the directory reference | 526 // cleanup the directory reference |
530 closedir(fontDirectory); | 527 closedir(fontDirectory); |
531 } | 528 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 if (NULL != testFallbackConfigFile) { | 586 if (NULL != testFallbackConfigFile) { |
590 parseConfigFile(testFallbackConfigFile, fallbackFonts); | 587 parseConfigFile(testFallbackConfigFile, fallbackFonts); |
591 } | 588 } |
592 | 589 |
593 // Append all fallback fonts to system fonts | 590 // Append all fallback fonts to system fonts |
594 for (int i = 0; i < fallbackFonts.count(); ++i) { | 591 for (int i = 0; i < fallbackFonts.count(); ++i) { |
595 fallbackFonts[i]->fIsFallbackFont = true; | 592 fallbackFonts[i]->fIsFallbackFont = true; |
596 *fontFamilies.append() = fallbackFonts[i]; | 593 *fontFamilies.append() = fallbackFonts[i]; |
597 } | 594 } |
598 } | 595 } |
599 | |
600 SkLanguage SkLanguage::getParent() const { | |
601 SkASSERT(!fTag.isEmpty()); | |
602 const char* tag = fTag.c_str(); | |
603 | |
604 // strip off the rightmost "-.*" | |
605 const char* parentTagEnd = strrchr(tag, '-'); | |
606 if (parentTagEnd == NULL) { | |
607 return SkLanguage(); | |
608 } | |
609 size_t parentTagLen = parentTagEnd - tag; | |
610 return SkLanguage(tag, parentTagLen); | |
611 } | |
OLD | NEW |