| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 if (targetFamily->fFonts[i].fWeight == weight) { | 196 if (targetFamily->fFonts[i].fWeight == weight) { |
| 197 family->fFonts.push_back(targetFamily->fFonts[i]); | 197 family->fFonts.push_back(targetFamily->fFonts[i]); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 *familyData->families.append() = family; | 200 *familyData->families.append() = family; |
| 201 } else { | 201 } else { |
| 202 targetFamily->fNames.push_back().set(aliasName); | 202 targetFamily->fNames.push_back().set(aliasName); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 bool findWeight400(FontFamily* family) { | 206 void startElementHandler(void* data, const char* tag, const char** attributes) { |
| 207 for (int i = 0; i < family->fFonts.count(); i++) { | |
| 208 if (family->fFonts[i].fWeight == 400) { | |
| 209 return true; | |
| 210 } | |
| 211 } | |
| 212 return false; | |
| 213 } | |
| 214 | |
| 215 bool desiredWeight(int weight) { | |
| 216 return (weight == 400 || weight == 700); | |
| 217 } | |
| 218 | |
| 219 int countDesiredWeight(FontFamily* family) { | |
| 220 int count = 0; | |
| 221 for (int i = 0; i < family->fFonts.count(); i++) { | |
| 222 if (desiredWeight(family->fFonts[i].fWeight)) { | |
| 223 count++; | |
| 224 } | |
| 225 } | |
| 226 return count; | |
| 227 } | |
| 228 | |
| 229 // To meet Skia's expectations, any family that contains weight=400 | |
| 230 // fonts should *only* contain {400,700} | |
| 231 void purgeUndesiredWeights(FontFamily* family) { | |
| 232 int count = countDesiredWeight(family); | |
| 233 for (int i = 1, j = 0; i < family->fFonts.count(); i++) { | |
| 234 if (desiredWeight(family->fFonts[j].fWeight)) { | |
| 235 j++; | |
| 236 } | |
| 237 if ((i != j) && desiredWeight(family->fFonts[i].fWeight)) { | |
| 238 family->fFonts[j] = family->fFonts[i]; | |
| 239 } | |
| 240 } | |
| 241 family->fFonts.resize_back(count); | |
| 242 } | |
| 243 | |
| 244 void familysetElementEndHandler(FamilyData* familyData) { | |
| 245 for (int i = 0; i < familyData->families.count(); i++) { | |
| 246 if (findWeight400(familyData->families[i])) { | |
| 247 purgeUndesiredWeights(familyData->families[i]); | |
| 248 } | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 void startElementHandler(void* data, const char* tag, | |
| 253 const char** attributes) { | |
| 254 FamilyData* familyData = (FamilyData*) data; | 207 FamilyData* familyData = (FamilyData*) data; |
| 255 size_t len = strlen(tag); | 208 size_t len = strlen(tag); |
| 256 if (len == 6 && !strncmp(tag, "family", len)) { | 209 if (len == 6 && !strncmp(tag, "family", len)) { |
| 257 familyData->currentFamily = new FontFamily(); | 210 familyData->currentFamily = new FontFamily(); |
| 258 familyElementHandler(familyData->currentFamily, attributes); | 211 familyElementHandler(familyData->currentFamily, attributes); |
| 259 } else if (len == 4 && !strncmp(tag, "font", len)) { | 212 } else if (len == 4 && !strncmp(tag, "font", len)) { |
| 260 FontFileInfo* file = &familyData->currentFamily->fFonts.push_back(); | 213 FontFileInfo* file = &familyData->currentFamily->fFonts.push_back(); |
| 261 familyData->currentFontInfo = file; | 214 familyData->currentFontInfo = file; |
| 262 fontElementHandler(familyData->parser, file, attributes); | 215 fontElementHandler(familyData->parser, file, attributes); |
| 263 } else if (len == 5 && !strncmp(tag, "alias", len)) { | 216 } else if (len == 5 && !strncmp(tag, "alias", len)) { |
| 264 aliasElementHandler(familyData, attributes); | 217 aliasElementHandler(familyData, attributes); |
| 265 } | 218 } |
| 266 } | 219 } |
| 267 | 220 |
| 268 void endElementHandler(void* data, const char* tag) { | 221 void endElementHandler(void* data, const char* tag) { |
| 269 FamilyData* familyData = (FamilyData*) data; | 222 FamilyData* familyData = (FamilyData*) data; |
| 270 size_t len = strlen(tag); | 223 size_t len = strlen(tag); |
| 271 if (len == 9 && strncmp(tag, "familyset", len) == 0) { | 224 if (len == 6 && strncmp(tag, "family", len) == 0) { |
| 272 familysetElementEndHandler(familyData); | |
| 273 } else if (len == 6 && strncmp(tag, "family", len) == 0) { | |
| 274 *familyData->families.append() = familyData->currentFamily; | 225 *familyData->families.append() = familyData->currentFamily; |
| 275 familyData->currentFamily = NULL; | 226 familyData->currentFamily = NULL; |
| 276 } else if (len == 4 && !strncmp(tag, "font", len)) { | 227 } else if (len == 4 && !strncmp(tag, "font", len)) { |
| 277 XML_SetCharacterDataHandler(*familyData->parser, NULL); | 228 XML_SetCharacterDataHandler(*familyData->parser, NULL); |
| 278 } | 229 } |
| 279 } | 230 } |
| 280 | 231 |
| 281 } // lmpParser | 232 } // lmpParser |
| 282 | 233 |
| 283 namespace jbParser { | 234 namespace jbParser { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 const char* tag = fTag.c_str(); | 554 const char* tag = fTag.c_str(); |
| 604 | 555 |
| 605 // strip off the rightmost "-.*" | 556 // strip off the rightmost "-.*" |
| 606 const char* parentTagEnd = strrchr(tag, '-'); | 557 const char* parentTagEnd = strrchr(tag, '-'); |
| 607 if (parentTagEnd == NULL) { | 558 if (parentTagEnd == NULL) { |
| 608 return SkLanguage(); | 559 return SkLanguage(); |
| 609 } | 560 } |
| 610 size_t parentTagLen = parentTagEnd - tag; | 561 size_t parentTagLen = parentTagEnd - tag; |
| 611 return SkLanguage(tag, parentTagLen); | 562 return SkLanguage(tag, parentTagLen); |
| 612 } | 563 } |
| OLD | NEW |