| 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 | |
| 12 | void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, |
| 13 | skiatest::Reporter* reporter) { |
| 14 | REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5); |
| 15 | REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans-serif")); |
| 16 | REPORTER_ASSERT(reporter, |
| 17 | !strcmp(fontFamilies[0]->fFontFiles[0].fFileName.c_str(), |
| 18 | "Roboto-Regular.ttf")); |
| 19 | REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont); |
| 20 | |
| 21 | } |
| 22 | |
| 23 | void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) { |
| 24 | #if SK_DEBUG_FONTS |
| 25 | for (int i = 0; i < fontFamilies.count(); ++i) { |
| 26 | SkDebugf("Family %d:\n", i); |
| tomhudson | 0754475 | 2014-08-05 13:35:00 -0700 | [diff] [blame] | 27 | switch(fontFamilies[i]->fVariant) { |
| 28 | case SkPaintOptionsAndroid::kElegant_Variant: SkDebugf(" elegant"); break; |
| 29 | case SkPaintOptionsAndroid::kCompact_Variant: SkDebugf(" compact"); break; |
| 30 | default: break; |
| 31 | } |
| 32 | if (!fontFamilies[i]->fLanguage.getTag().isEmpty()) { |
| 33 | SkDebugf(" language: %s", fontFamilies[i]->fLanguage.getTag().c_str()); |
| 34 | } |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 35 | for (int j = 0; j < fontFamilies[i]->fNames.count(); ++j) { |
| 36 | SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str()); |
| 37 | } |
| tomhudson | 0754475 | 2014-08-05 13:35:00 -0700 | [diff] [blame] | 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.fWeight, |
| 42 | ffi.fPaintOptions.getLanguage().getTag().isEmpty() ? "" : |
| 43 | ffi.fPaintOptions.getLanguage().getTag().c_str(), |
| 44 | ffi.fPaintOptions.getFontVariant(), |
| 45 | ffi.fFileName.c_str()); |
| 46 | } |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 47 | } |
| 48 | #endif // SK_DEBUG_FONTS |
| 49 | } |
| 50 | |
| 51 | DEF_TEST(FontConfigParserAndroid, reporter) { |
| 52 | |
| tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 53 | bool resourcesMissing = false; |
| 54 | |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 55 | SkTDArray<FontFamily*> preV17FontFamilies; |
| 56 | SkFontConfigParser::GetTestFontFamilies(preV17FontFamilies, |
| 57 | GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(), |
| 58 | GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str()); |
| 59 | |
| tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 60 | if (preV17FontFamilies.count() > 0) { |
| 61 | REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14); |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 62 | |
| tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 63 | DumpLoadedFonts(preV17FontFamilies); |
| 64 | ValidateLoadedFonts(preV17FontFamilies, reporter); |
| 65 | } else { |
| 66 | resourcesMissing = true; |
| 67 | } |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 68 | |
| tomhudson | 0754475 | 2014-08-05 13:35:00 -0700 | [diff] [blame] | 69 | |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 70 | SkTDArray<FontFamily*> v17FontFamilies; |
| 71 | SkFontConfigParser::GetTestFontFamilies(v17FontFamilies, |
| 72 | GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(), |
| 73 | GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str()); |
| 74 | |
| tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 75 | if (v17FontFamilies.count() > 0) { |
| 76 | REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41); |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 77 | |
| tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 78 | DumpLoadedFonts(v17FontFamilies); |
| 79 | ValidateLoadedFonts(v17FontFamilies, reporter); |
| 80 | } else { |
| 81 | resourcesMissing = true; |
| 82 | } |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 83 | |
| tomhudson | 0754475 | 2014-08-05 13:35:00 -0700 | [diff] [blame] | 84 | |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 85 | SkTDArray<FontFamily*> v22FontFamilies; |
| 86 | SkFontConfigParser::GetTestFontFamilies(v22FontFamilies, |
| 87 | GetResourcePath("android_fonts/v22/fonts.xml").c_str(), |
| 88 | NULL); |
| 89 | |
| tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 90 | if (v22FontFamilies.count() > 0) { |
| 91 | REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53); |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 92 | |
| tomhudson | 8aed3c1 | 2014-08-07 10:20:51 -0700 | [diff] [blame] | 93 | DumpLoadedFonts(v22FontFamilies); |
| 94 | ValidateLoadedFonts(v22FontFamilies, reporter); |
| 95 | } else { |
| 96 | resourcesMissing = true; |
| 97 | } |
| 98 | |
| 99 | if (resourcesMissing) { |
| 100 | SkDebugf("---- Resource files missing for FontConfigParser test\n"); |
| 101 | } |
| tomhudson | f79673b | 2014-08-05 06:36:11 -0700 | [diff] [blame] | 102 | } |
| 103 | |