blob: 86b2b1db904aa97eaa899374b8cd772b0916b120 [file] [log] [blame]
tomhudsonf79673b2014-08-05 06:36:11 -07001/*
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
tomhudson2ed49a42014-08-13 07:53:48 -070012int 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
tomhudsonf79673b2014-08-05 06:36:11 -070022void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies,
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,
tomhudsond3ddea22014-08-11 11:28:00 -070027 !strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(),
tomhudsonf79673b2014-08-05 06:36:11 -070028 "Roboto-Regular.ttf"));
29 REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont);
tomhudsonf79673b2014-08-05 06:36:11 -070030}
31
32void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) {
33#if SK_DEBUG_FONTS
34 for (int i = 0; i < fontFamilies.count(); ++i) {
35 SkDebugf("Family %d:\n", i);
tomhudson07544752014-08-05 13:35:00 -070036 switch(fontFamilies[i]->fVariant) {
37 case SkPaintOptionsAndroid::kElegant_Variant: SkDebugf(" elegant"); break;
38 case SkPaintOptionsAndroid::kCompact_Variant: SkDebugf(" compact"); break;
39 default: break;
40 }
41 if (!fontFamilies[i]->fLanguage.getTag().isEmpty()) {
42 SkDebugf(" language: %s", fontFamilies[i]->fLanguage.getTag().c_str());
43 }
tomhudsonf79673b2014-08-05 06:36:11 -070044 for (int j = 0; j < fontFamilies[i]->fNames.count(); ++j) {
45 SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str());
46 }
tomhudsond3ddea22014-08-11 11:28:00 -070047 for (int j = 0; j < fontFamilies[i]->fFonts.count(); ++j) {
48 const FontFileInfo& ffi = fontFamilies[i]->fFonts[j];
tomhudson07544752014-08-05 13:35:00 -070049 SkDebugf(" file (%d %s %d) %s\n",
50 ffi.fWeight,
51 ffi.fPaintOptions.getLanguage().getTag().isEmpty() ? "" :
52 ffi.fPaintOptions.getLanguage().getTag().c_str(),
53 ffi.fPaintOptions.getFontVariant(),
54 ffi.fFileName.c_str());
55 }
tomhudsonf79673b2014-08-05 06:36:11 -070056 }
57#endif // SK_DEBUG_FONTS
58}
59
60DEF_TEST(FontConfigParserAndroid, reporter) {
61
tomhudson8aed3c12014-08-07 10:20:51 -070062 bool resourcesMissing = false;
63
tomhudsonf79673b2014-08-05 06:36:11 -070064 SkTDArray<FontFamily*> preV17FontFamilies;
65 SkFontConfigParser::GetTestFontFamilies(preV17FontFamilies,
66 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(),
67 GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str());
68
tomhudson8aed3c12014-08-07 10:20:51 -070069 if (preV17FontFamilies.count() > 0) {
70 REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14);
tomhudson2ed49a42014-08-13 07:53:48 -070071 REPORTER_ASSERT(reporter, CountFallbacks(preV17FontFamilies) == 10);
tomhudsonf79673b2014-08-05 06:36:11 -070072
tomhudson8aed3c12014-08-07 10:20:51 -070073 DumpLoadedFonts(preV17FontFamilies);
74 ValidateLoadedFonts(preV17FontFamilies, reporter);
75 } else {
76 resourcesMissing = true;
77 }
tomhudsonf79673b2014-08-05 06:36:11 -070078
tomhudson07544752014-08-05 13:35:00 -070079
tomhudsonf79673b2014-08-05 06:36:11 -070080 SkTDArray<FontFamily*> v17FontFamilies;
81 SkFontConfigParser::GetTestFontFamilies(v17FontFamilies,
82 GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(),
83 GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str());
84
tomhudson8aed3c12014-08-07 10:20:51 -070085 if (v17FontFamilies.count() > 0) {
86 REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41);
tomhudson2ed49a42014-08-13 07:53:48 -070087 REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 31);
tomhudsonf79673b2014-08-05 06:36:11 -070088
tomhudson8aed3c12014-08-07 10:20:51 -070089 DumpLoadedFonts(v17FontFamilies);
90 ValidateLoadedFonts(v17FontFamilies, reporter);
91 } else {
92 resourcesMissing = true;
93 }
tomhudsonf79673b2014-08-05 06:36:11 -070094
tomhudson07544752014-08-05 13:35:00 -070095
tomhudsonf79673b2014-08-05 06:36:11 -070096 SkTDArray<FontFamily*> v22FontFamilies;
97 SkFontConfigParser::GetTestFontFamilies(v22FontFamilies,
98 GetResourcePath("android_fonts/v22/fonts.xml").c_str(),
99 NULL);
100
tomhudson8aed3c12014-08-07 10:20:51 -0700101 if (v22FontFamilies.count() > 0) {
102 REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53);
tomhudson2ed49a42014-08-13 07:53:48 -0700103 REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42);
tomhudsonf79673b2014-08-05 06:36:11 -0700104
tomhudson8aed3c12014-08-07 10:20:51 -0700105 DumpLoadedFonts(v22FontFamilies);
106 ValidateLoadedFonts(v22FontFamilies, reporter);
107 } else {
108 resourcesMissing = true;
109 }
110
111 if (resourcesMissing) {
112 SkDebugf("---- Resource files missing for FontConfigParser test\n");
113 }
tomhudsonf79673b2014-08-05 06:36:11 -0700114}
115