| 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 | 19 |
| 20 | 20 |
| 21 // From Android version LMP onwards, all font files collapse into | 21 // From Android version LMP onwards, all font files collapse into |
| 22 // /system/fonts/fonts.xml. Instead of trying to detect which version | 22 // /system/etc/fonts.xml. Instead of trying to detect which version |
| 23 // we're on, try to open fonts.xml; if that fails, fall back to the | 23 // we're on, try to open fonts.xml; if that fails, fall back to the |
| 24 // older filename. | 24 // older filename. |
| 25 #define LMP_SYSTEM_FONTS_FILE "/system/etc/fonts.xml" | 25 #define LMP_SYSTEM_FONTS_FILE "/system/etc/fonts.xml" |
| 26 #define OLD_SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml" | 26 #define OLD_SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml" |
| 27 #define FALLBACK_FONTS_FILE "/system/etc/fallback_fonts.xml" | 27 #define FALLBACK_FONTS_FILE "/system/etc/fallback_fonts.xml" |
| 28 #define VENDOR_FONTS_FILE "/vendor/etc/fallback_fonts.xml" | 28 #define VENDOR_FONTS_FILE "/vendor/etc/fallback_fonts.xml" |
| 29 | 29 |
| 30 #define LOCALE_FALLBACK_FONTS_SYSTEM_DIR "/system/etc" | 30 #define LOCALE_FALLBACK_FONTS_SYSTEM_DIR "/system/etc" |
| 31 #define LOCALE_FALLBACK_FONTS_VENDOR_DIR "/vendor/etc" | 31 #define LOCALE_FALLBACK_FONTS_VENDOR_DIR "/vendor/etc" |
| 32 #define LOCALE_FALLBACK_FONTS_PREFIX "fallback_fonts-" | 32 #define LOCALE_FALLBACK_FONTS_PREFIX "fallback_fonts-" |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 if (feof(file) != 0) { | 458 if (feof(file) != 0) { |
| 459 done = true; | 459 done = true; |
| 460 } | 460 } |
| 461 XML_Parse(parser, buffer, len, done); | 461 XML_Parse(parser, buffer, len, done); |
| 462 } | 462 } |
| 463 XML_ParserFree(parser); | 463 XML_ParserFree(parser); |
| 464 fclose(file); | 464 fclose(file); |
| 465 } | 465 } |
| 466 | 466 |
| 467 static void getSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { | 467 static void getSystemFontFamilies(SkTDArray<FontFamily*> &fontFamilies) { |
| 468 int initialCount = fontFamilies.count(); |
| 468 parseConfigFile(LMP_SYSTEM_FONTS_FILE, fontFamilies); | 469 parseConfigFile(LMP_SYSTEM_FONTS_FILE, fontFamilies); |
| 469 | 470 |
| 470 if (0 == fontFamilies.count()) { | 471 if (initialCount == fontFamilies.count()) { |
| 471 parseConfigFile(OLD_SYSTEM_FONTS_FILE, fontFamilies); | 472 parseConfigFile(OLD_SYSTEM_FONTS_FILE, fontFamilies); |
| 472 } | 473 } |
| 473 } | 474 } |
| 474 | 475 |
| 475 /** | 476 /** |
| 476 * In some versions of Android prior to Android 4.2 (JellyBean MR1 at API | 477 * In some versions of Android prior to Android 4.2 (JellyBean MR1 at API |
| 477 * Level 17) the fallback fonts for certain locales were encoded in their own | 478 * Level 17) the fallback fonts for certain locales were encoded in their own |
| 478 * XML files with a suffix that identified the locale. We search the provided | 479 * XML files with a suffix that identified the locale. We search the provided |
| 479 * directory for those files,add all of their entries to the fallback chain, and | 480 * directory for those files,add all of their entries to the fallback chain, and |
| 480 * include the locale as part of each entry. | 481 * include the locale as part of each entry. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 if (NULL != testFallbackConfigFile) { | 587 if (NULL != testFallbackConfigFile) { |
| 587 parseConfigFile(testFallbackConfigFile, fallbackFonts); | 588 parseConfigFile(testFallbackConfigFile, fallbackFonts); |
| 588 } | 589 } |
| 589 | 590 |
| 590 // Append all fallback fonts to system fonts | 591 // Append all fallback fonts to system fonts |
| 591 for (int i = 0; i < fallbackFonts.count(); ++i) { | 592 for (int i = 0; i < fallbackFonts.count(); ++i) { |
| 592 fallbackFonts[i]->fIsFallbackFont = true; | 593 fallbackFonts[i]->fIsFallbackFont = true; |
| 593 *fontFamilies.append() = fallbackFonts[i]; | 594 *fontFamilies.append() = fallbackFonts[i]; |
| 594 } | 595 } |
| 595 } | 596 } |
| OLD | NEW |