OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
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 "Resources.h" | 8 #include "Resources.h" |
9 #include "SkFontConfigParser_android.h" | 9 #include "SkFontConfigParser_android.h" |
10 #include "Test.h" | 10 #include "Test.h" |
11 | 11 |
12 void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, | 12 void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, |
13 skiatest::Reporter* reporter) { | 13 skiatest::Reporter* reporter) { |
14 REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5); | 14 REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5); |
15 REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans- serif")); | 15 REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans- serif")); |
16 REPORTER_ASSERT(reporter, | 16 REPORTER_ASSERT(reporter, |
17 !strcmp(fontFamilies[0]->fFontFiles[0].fFileName.c_str(), | 17 !strcmp(fontFamilies[0]->fFontFiles[0].fFileName.c_str(), |
18 "Roboto-Regular.ttf")); | 18 "Roboto-Regular.ttf")); |
19 REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont); | 19 REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont); |
20 | 20 |
21 } | 21 } |
22 | 22 |
23 void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) { | 23 void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) { |
24 #if SK_DEBUG_FONTS | 24 #if SK_DEBUG_FONTS |
25 for (int i = 0; i < fontFamilies.count(); ++i) { | 25 for (int i = 0; i < fontFamilies.count(); ++i) { |
26 SkDebugf("Family %d:\n", i); | 26 SkDebugf("Family %d:\n", i); |
27 switch(fontFamilies[i]->variant) { | |
28 case SkPaintOptionsAndroid::kElegant_Variant: SkDebugf(" elegant"); break; | |
29 case SkPaintOptionsAndroid::kCompact_Variant: SkDebugf(" compact"); break; | |
30 default: break; | |
31 } | |
32 if (!fontFamilies[i]->language.isEmpty()) { | |
33 SkDebugf(" language: %s", fontFamilies[i]->language.c_str()); | |
34 } | |
27 for (int j = 0; j < fontFamilies[i]->fNames.count(); ++j) { | 35 for (int j = 0; j < fontFamilies[i]->fNames.count(); ++j) { |
28 SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str()); | 36 SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str()); |
29 } | 37 } |
38 for (int j = 0; j < fontFamilies[i]->fFontFiles.count(); ++j) { | |
39 const FontFileInfo& ffi = fontFamilies[i]->fFontFiles[j]; | |
40 SkDebugf(" file (%d %s %d) %s\n", | |
41 ffi.weight, | |
42 ffi.fPaintOptions.getLanguage().getTag().isEmpty() ? "" : | |
43 ffi.fPaintOptions.getLanguage().getTag().c_str(), | |
44 ffi.fPaintOptions.getFontVariant(), | |
45 ffi.fFileName.c_str()); | |
46 } | |
30 } | 47 } |
31 #endif // SK_DEBUG_FONTS | 48 #endif // SK_DEBUG_FONTS |
32 } | 49 } |
33 | 50 |
34 DEF_TEST(FontConfigParserAndroid, reporter) { | 51 DEF_TEST(FontConfigParserAndroid, reporter) { |
35 | 52 |
36 SkTDArray<FontFamily*> preV17FontFamilies; | 53 SkTDArray<FontFamily*> preV17FontFamilies; |
37 SkFontConfigParser::GetTestFontFamilies(preV17FontFamilies, | 54 SkFontConfigParser::GetTestFontFamilies(preV17FontFamilies, |
38 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(), | 55 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(), |
39 GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str()); | 56 GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str()); |
40 | 57 |
41 REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14); | 58 REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14); |
42 | 59 |
43 DumpLoadedFonts(preV17FontFamilies); | 60 DumpLoadedFonts(preV17FontFamilies); |
44 ValidateLoadedFonts(preV17FontFamilies, reporter); | 61 ValidateLoadedFonts(preV17FontFamilies, reporter); |
45 | 62 |
63 | |
djsollen
2014/08/05 19:44:08
extra space? If you were trying to provide separat
| |
46 SkTDArray<FontFamily*> v17FontFamilies; | 64 SkTDArray<FontFamily*> v17FontFamilies; |
47 SkFontConfigParser::GetTestFontFamilies(v17FontFamilies, | 65 SkFontConfigParser::GetTestFontFamilies(v17FontFamilies, |
48 GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(), | 66 GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(), |
49 GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str()); | 67 GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str()); |
50 | 68 |
51 | |
52 REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41); | 69 REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41); |
53 | 70 |
54 DumpLoadedFonts(v17FontFamilies); | 71 DumpLoadedFonts(v17FontFamilies); |
55 ValidateLoadedFonts(v17FontFamilies, reporter); | 72 ValidateLoadedFonts(v17FontFamilies, reporter); |
56 | 73 |
74 | |
djsollen
2014/08/05 19:44:08
same here.
| |
57 SkTDArray<FontFamily*> v22FontFamilies; | 75 SkTDArray<FontFamily*> v22FontFamilies; |
58 SkFontConfigParser::GetTestFontFamilies(v22FontFamilies, | 76 SkFontConfigParser::GetTestFontFamilies(v22FontFamilies, |
59 GetResourcePath("android_fonts/v22/fonts.xml").c_str(), | 77 GetResourcePath("android_fonts/v22/fonts.xml").c_str(), |
60 NULL); | 78 NULL); |
61 | 79 |
62 //REPORTER_ASSERT(reporter, v22FontFamilies.count() > 0); | 80 REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53); |
63 if (v22FontFamilies.count() > 0) { | |
64 REPORTER_ASSERT(reporter, v22FontFamilies[0]->fNames.count() > 0); | |
65 } | |
66 | 81 |
67 //ValidateLoadedFonts(v22FontFamilies, reporter); | 82 DumpLoadedFonts(v22FontFamilies); |
83 ValidateLoadedFonts(v22FontFamilies, reporter); | |
68 } | 84 } |
69 | 85 |
OLD | NEW |