tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Resources.h" |
| 9 | #include "SkFontConfigParser_android.h" |
| 10 | #include "Test.h" |
| 11 | |
tomhudson | 2ed49a4 | 2014-08-13 07:53:48 -0700 | [diff] [blame] | 12 | int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) { |
| 13 | int countOfFallbackFonts = 0; |
| 14 | for (int i = 0; i < fontFamilies.count(); i++) { |
| 15 | if (fontFamilies[i]->fIsFallbackFont) { |
| 16 | countOfFallbackFonts++; |
| 17 | } |
| 18 | } |
| 19 | return countOfFallbackFonts; |
| 20 | } |
| 21 | |
bungeman | 4b86bac | 2014-11-04 10:54:31 -0800 | [diff] [blame] | 22 | void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstExpectedFile, |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 23 | skiatest::Reporter* reporter) { |
| 24 | REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5); |
| 25 | REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans-serif")); |
| 26 | REPORTER_ASSERT(reporter, |
bungeman | 4b86bac | 2014-11-04 10:54:31 -0800 | [diff] [blame] | 27 | !strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(), firstExpectedFile)); |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 28 | REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont); |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) { |
| 32 | #if SK_DEBUG_FONTS |
| 33 | for (int i = 0; i < fontFamilies.count(); ++i) { |
| 34 | SkDebugf("Family %d:\n", i); |
tomhudson | 0754475 | 2014-08-05 13:35:00 -0700 | [diff] [blame] | 35 | switch(fontFamilies[i]->fVariant) { |
| 36 | case SkPaintOptionsAndroid::kElegant_Variant: SkDebugf(" elegant"); break; |
| 37 | case SkPaintOptionsAndroid::kCompact_Variant: SkDebugf(" compact"); break; |
| 38 | default: break; |
| 39 | } |
| 40 | if (!fontFamilies[i]->fLanguage.getTag().isEmpty()) { |
| 41 | SkDebugf(" language: %s", fontFamilies[i]->fLanguage.getTag().c_str()); |
| 42 | } |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 43 | for (int j = 0; j < fontFamilies[i]->fNames.count(); ++j) { |
| 44 | SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str()); |
| 45 | } |
tomhudson | d3ddea2 | 2014-08-11 11:28:00 -0700 | [diff] [blame] | 46 | for (int j = 0; j < fontFamilies[i]->fFonts.count(); ++j) { |
| 47 | const FontFileInfo& ffi = fontFamilies[i]->fFonts[j]; |
tomhudson | 0754475 | 2014-08-05 13:35:00 -0700 | [diff] [blame] | 48 | SkDebugf(" file (%d %s %d) %s\n", |
| 49 | ffi.fWeight, |
| 50 | ffi.fPaintOptions.getLanguage().getTag().isEmpty() ? "" : |
| 51 | ffi.fPaintOptions.getLanguage().getTag().c_str(), |
| 52 | ffi.fPaintOptions.getFontVariant(), |
| 53 | ffi.fFileName.c_str()); |
| 54 | } |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 55 | } |
| 56 | #endif // SK_DEBUG_FONTS |
| 57 | } |
| 58 | |
| 59 | DEF_TEST(FontConfigParserAndroid, reporter) { |
| 60 | |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 61 | bool resourcesMissing = false; |
| 62 | |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 63 | SkTDArray<FontFamily*> preV17FontFamilies; |
| 64 | SkFontConfigParser::GetTestFontFamilies(preV17FontFamilies, |
| 65 | GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(), |
| 66 | GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str()); |
| 67 | |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 68 | if (preV17FontFamilies.count() > 0) { |
| 69 | REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14); |
tomhudson | 2ed49a4 | 2014-08-13 07:53:48 -0700 | [diff] [blame] | 70 | REPORTER_ASSERT(reporter, CountFallbacks(preV17FontFamilies) == 10); |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 71 | |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 72 | DumpLoadedFonts(preV17FontFamilies); |
bungeman | 4b86bac | 2014-11-04 10:54:31 -0800 | [diff] [blame] | 73 | ValidateLoadedFonts(preV17FontFamilies, "Roboto-Regular.ttf", reporter); |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 74 | } else { |
| 75 | resourcesMissing = true; |
| 76 | } |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 77 | |
tomhudson | 0754475 | 2014-08-05 13:35:00 -0700 | [diff] [blame] | 78 | |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 79 | SkTDArray<FontFamily*> v17FontFamilies; |
| 80 | SkFontConfigParser::GetTestFontFamilies(v17FontFamilies, |
| 81 | GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(), |
| 82 | GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str()); |
| 83 | |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 84 | if (v17FontFamilies.count() > 0) { |
| 85 | REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41); |
tomhudson | 2ed49a4 | 2014-08-13 07:53:48 -0700 | [diff] [blame] | 86 | REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 31); |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 87 | |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 88 | DumpLoadedFonts(v17FontFamilies); |
bungeman | 4b86bac | 2014-11-04 10:54:31 -0800 | [diff] [blame] | 89 | ValidateLoadedFonts(v17FontFamilies, "Roboto-Regular.ttf", reporter); |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 90 | } else { |
| 91 | resourcesMissing = true; |
| 92 | } |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 93 | |
tomhudson | 0754475 | 2014-08-05 13:35:00 -0700 | [diff] [blame] | 94 | |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 95 | SkTDArray<FontFamily*> v22FontFamilies; |
| 96 | SkFontConfigParser::GetTestFontFamilies(v22FontFamilies, |
| 97 | GetResourcePath("android_fonts/v22/fonts.xml").c_str(), |
| 98 | NULL); |
| 99 | |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 100 | if (v22FontFamilies.count() > 0) { |
| 101 | REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53); |
tomhudson | 2ed49a4 | 2014-08-13 07:53:48 -0700 | [diff] [blame] | 102 | REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42); |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 103 | |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 104 | DumpLoadedFonts(v22FontFamilies); |
bungeman | 4b86bac | 2014-11-04 10:54:31 -0800 | [diff] [blame] | 105 | ValidateLoadedFonts(v22FontFamilies, "Roboto-Thin.ttf", reporter); |
tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 106 | } else { |
| 107 | resourcesMissing = true; |
| 108 | } |
| 109 | |
| 110 | if (resourcesMissing) { |
| 111 | SkDebugf("---- Resource files missing for FontConfigParser test\n"); |
| 112 | } |
tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 113 | } |
| 114 | |