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 // Despite the name and location, this is portable code. | 8 // Despite the name and location, this is portable code. |
9 | 9 |
10 #include "SkFixed.h" | 10 #include "SkFixed.h" |
11 #include "SkFontMgr.h" | 11 #include "SkFontMgr.h" |
12 #include "SkFontMgr_android_parser.h" | 12 #include "SkFontMgr_android_parser.h" |
| 13 #include "SkOSFile.h" |
13 #include "SkStream.h" | 14 #include "SkStream.h" |
14 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
15 #include "SkTSearch.h" | 16 #include "SkTSearch.h" |
16 #include "SkTemplates.h" | 17 #include "SkTemplates.h" |
17 #include "SkTLogic.h" | 18 #include "SkTLogic.h" |
18 | 19 |
19 #include <dirent.h> | |
20 #include <expat.h> | 20 #include <expat.h> |
21 | 21 |
22 #include <stdlib.h> | 22 #include <stdlib.h> |
23 #include <string.h> | 23 #include <string.h> |
24 | 24 |
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 |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 * In some versions of Android prior to Android 4.2 (JellyBean MR1 at API | 669 * In some versions of Android prior to Android 4.2 (JellyBean MR1 at API |
670 * Level 17) the fallback fonts for certain locales were encoded in their own | 670 * Level 17) the fallback fonts for certain locales were encoded in their own |
671 * XML files with a suffix that identified the locale. We search the provided | 671 * XML files with a suffix that identified the locale. We search the provided |
672 * directory for those files,add all of their entries to the fallback chain, and | 672 * directory for those files,add all of their entries to the fallback chain, and |
673 * include the locale as part of each entry. | 673 * include the locale as part of each entry. |
674 */ | 674 */ |
675 static void append_fallback_font_families_for_locale(SkTDArray<FontFamily*>& fal
lbackFonts, | 675 static void append_fallback_font_families_for_locale(SkTDArray<FontFamily*>& fal
lbackFonts, |
676 const char* dir, | 676 const char* dir, |
677 const SkString& basePath) | 677 const SkString& basePath) |
678 { | 678 { |
679 SkAutoTCallIProc<DIR, closedir> fontDirectory(opendir(dir)); | 679 SkOSFile::Iter iter(dir, nullptr); |
680 if (nullptr == fontDirectory) { | 680 SkString fileName; |
681 return; | 681 while (iter.next(&fileName, false)) { |
682 } | |
683 | |
684 for (struct dirent* dirEntry; (dirEntry = readdir(fontDirectory));) { | |
685 // The size of the prefix and suffix. | 682 // The size of the prefix and suffix. |
686 static const size_t fixedLen = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1 | 683 static const size_t fixedLen = sizeof(LOCALE_FALLBACK_FONTS_PREFIX) - 1 |
687 + sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1; | 684 + sizeof(LOCALE_FALLBACK_FONTS_SUFFIX) - 1; |
688 | 685 |
689 // The size of the prefix, suffix, and a minimum valid language code | 686 // The size of the prefix, suffix, and a minimum valid language code |
690 static const size_t minSize = fixedLen + 2; | 687 static const size_t minSize = fixedLen + 2; |
691 | 688 |
692 SkString fileName(dirEntry->d_name); | |
693 if (fileName.size() < minSize || | 689 if (fileName.size() < minSize || |
694 !fileName.startsWith(LOCALE_FALLBACK_FONTS_PREFIX) || | 690 !fileName.startsWith(LOCALE_FALLBACK_FONTS_PREFIX) || |
695 !fileName.endsWith(LOCALE_FALLBACK_FONTS_SUFFIX)) | 691 !fileName.endsWith(LOCALE_FALLBACK_FONTS_SUFFIX)) |
696 { | 692 { |
697 continue; | 693 continue; |
698 } | 694 } |
699 | 695 |
700 SkString locale(fileName.c_str() + sizeof(LOCALE_FALLBACK_FONTS_PREFIX)
- 1, | 696 SkString locale(fileName.c_str() + sizeof(LOCALE_FALLBACK_FONTS_PREFIX)
- 1, |
701 fileName.size() - fixedLen); | 697 fileName.size() - fixedLen); |
702 | 698 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 const char* tag = fTag.c_str(); | 792 const char* tag = fTag.c_str(); |
797 | 793 |
798 // strip off the rightmost "-.*" | 794 // strip off the rightmost "-.*" |
799 const char* parentTagEnd = strrchr(tag, '-'); | 795 const char* parentTagEnd = strrchr(tag, '-'); |
800 if (parentTagEnd == nullptr) { | 796 if (parentTagEnd == nullptr) { |
801 return SkLanguage(); | 797 return SkLanguage(); |
802 } | 798 } |
803 size_t parentTagLen = parentTagEnd - tag; | 799 size_t parentTagLen = parentTagEnd - tag; |
804 return SkLanguage(tag, parentTagLen); | 800 return SkLanguage(tag, parentTagLen); |
805 } | 801 } |
OLD | NEW |