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" |
11 #include "SkTypeface.h" | 11 #include "SkTypeface.h" |
12 | 12 |
13 #include <expat.h> | 13 #include <expat.h> |
14 #include <dirent.h> | 14 #include <dirent.h> |
15 #include <stdio.h> | 15 #include <stdio.h> |
16 | 16 |
17 #include <limits> | 17 #include <limits> |
18 | 18 |
19 #define SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml" | 19 |
20 | |
21 // From Android version LMP onwards, all font files collapse into | |
22 // /system/fonts/fonts.xml. Instead of trying to detect which version | |
djsollen
2014/08/13 13:31:53
too late, but update this in a future CL to reflec
| |
23 // we're on, try to open fonts.xml; if that fails, fall back to the | |
24 // older filename. | |
25 #define LMP_SYSTEM_FONTS_FILE "/system/etc/fonts.xml" | |
26 #define OLD_SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml" | |
20 #define FALLBACK_FONTS_FILE "/system/etc/fallback_fonts.xml" | 27 #define FALLBACK_FONTS_FILE "/system/etc/fallback_fonts.xml" |
21 #define VENDOR_FONTS_FILE "/vendor/etc/fallback_fonts.xml" | 28 #define VENDOR_FONTS_FILE "/vendor/etc/fallback_fonts.xml" |
22 | 29 |
23 #define LOCALE_FALLBACK_FONTS_SYSTEM_DIR "/system/etc" | 30 #define LOCALE_FALLBACK_FONTS_SYSTEM_DIR "/system/etc" |
24 #define LOCALE_FALLBACK_FONTS_VENDOR_DIR "/vendor/etc" | 31 #define LOCALE_FALLBACK_FONTS_VENDOR_DIR "/vendor/etc" |
25 #define LOCALE_FALLBACK_FONTS_PREFIX "fallback_fonts-" | 32 #define LOCALE_FALLBACK_FONTS_PREFIX "fallback_fonts-" |
26 #define LOCALE_FALLBACK_FONTS_SUFFIX ".xml" | 33 #define LOCALE_FALLBACK_FONTS_SUFFIX ".xml" |
27 | 34 |
28 /** | 35 /** |
29 * This file contains TWO parsers: one for JB and earlier (system_fonts.xml / | 36 * This file contains TWO parsers: one for JB and earlier (system_fonts.xml / |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 if (feof(file) != 0) { | 455 if (feof(file) != 0) { |
449 done = true; | 456 done = true; |
450 } | 457 } |
451 XML_Parse(parser, buffer, len, done); | 458 XML_Parse(parser, buffer, len, done); |
452 } | 459 } |
453 XML_ParserFree(parser); | 460 XML_ParserFree(parser); |
454 fclose(file); | 461 fclose(file); |
455 } | 462 } |
456 | 463 |
457 static void getSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { | 464 static void getSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { |
458 parseConfigFile(SYSTEM_FONTS_FILE, fontFamilies); | 465 parseConfigFile(LMP_SYSTEM_FONTS_FILE, fontFamilies); |
466 | |
467 if (0 == fontFamilies.count()) { | |
djsollen
2014/08/13 13:31:52
seems potentially wrong to trigger on that in case
| |
468 parseConfigFile(OLD_SYSTEM_FONTS_FILE, fontFamilies); | |
469 } | |
459 } | 470 } |
460 | 471 |
461 /** | 472 /** |
462 * In some versions of Android prior to Android 4.2 (JellyBean MR1 at API | 473 * In some versions of Android prior to Android 4.2 (JellyBean MR1 at API |
463 * Level 17) the fallback fonts for certain locales were encoded in their own | 474 * Level 17) the fallback fonts for certain locales were encoded in their own |
464 * XML files with a suffix that identified the locale. We search the provided | 475 * XML files with a suffix that identified the locale. We search the provided |
465 * directory for those files,add all of their entries to the fallback chain, and | 476 * directory for those files,add all of their entries to the fallback chain, and |
466 * include the locale as part of each entry. | 477 * include the locale as part of each entry. |
467 */ | 478 */ |
468 static void getFallbackFontFamiliesForLocale(SkTDArray<FontFamily*> &fallbackFon ts, const char* dir) { | 479 static void getFallbackFontFamiliesForLocale(SkTDArray<FontFamily*> &fallbackFon ts, const char* dir) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 if (NULL != testFallbackConfigFile) { | 583 if (NULL != testFallbackConfigFile) { |
573 parseConfigFile(testFallbackConfigFile, fallbackFonts); | 584 parseConfigFile(testFallbackConfigFile, fallbackFonts); |
574 } | 585 } |
575 | 586 |
576 // Append all fallback fonts to system fonts | 587 // Append all fallback fonts to system fonts |
577 for (int i = 0; i < fallbackFonts.count(); ++i) { | 588 for (int i = 0; i < fallbackFonts.count(); ++i) { |
578 fallbackFonts[i]->fIsFallbackFont = true; | 589 fallbackFonts[i]->fIsFallbackFont = true; |
579 *fontFamilies.append() = fallbackFonts[i]; | 590 *fontFamilies.append() = fallbackFonts[i]; |
580 } | 591 } |
581 } | 592 } |
OLD | NEW |