Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: tests/FontConfigParser.cpp

Issue 694533006: Allow all font weights on Android and respect overrides. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add expectations. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkFontMgr_android.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) { 12 int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) {
13 int countOfFallbackFonts = 0; 13 int countOfFallbackFonts = 0;
14 for (int i = 0; i < fontFamilies.count(); i++) { 14 for (int i = 0; i < fontFamilies.count(); i++) {
15 if (fontFamilies[i]->fIsFallbackFont) { 15 if (fontFamilies[i]->fIsFallbackFont) {
16 countOfFallbackFonts++; 16 countOfFallbackFonts++;
17 } 17 }
18 } 18 }
19 return countOfFallbackFonts; 19 return countOfFallbackFonts;
20 } 20 }
21 21
22 void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, 22 void ValidateLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* firstE xpectedFile,
23 skiatest::Reporter* reporter) { 23 skiatest::Reporter* reporter) {
24 REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5); 24 REPORTER_ASSERT(reporter, fontFamilies[0]->fNames.count() == 5);
25 REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans- serif")); 25 REPORTER_ASSERT(reporter, !strcmp(fontFamilies[0]->fNames[0].c_str(), "sans- serif"));
26 REPORTER_ASSERT(reporter, 26 REPORTER_ASSERT(reporter,
27 !strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(), 27 !strcmp(fontFamilies[0]->fFonts[0].fFileName.c_str(), firstE xpectedFile));
28 "Roboto-Regular.ttf"));
29 REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont); 28 REPORTER_ASSERT(reporter, !fontFamilies[0]->fIsFallbackFont);
30 } 29 }
31 30
32 void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) { 31 void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies) {
33 #if SK_DEBUG_FONTS 32 #if SK_DEBUG_FONTS
34 for (int i = 0; i < fontFamilies.count(); ++i) { 33 for (int i = 0; i < fontFamilies.count(); ++i) {
35 SkDebugf("Family %d:\n", i); 34 SkDebugf("Family %d:\n", i);
36 switch(fontFamilies[i]->fVariant) { 35 switch(fontFamilies[i]->fVariant) {
37 case SkPaintOptionsAndroid::kElegant_Variant: SkDebugf(" elegant"); break; 36 case SkPaintOptionsAndroid::kElegant_Variant: SkDebugf(" elegant"); break;
38 case SkPaintOptionsAndroid::kCompact_Variant: SkDebugf(" compact"); break; 37 case SkPaintOptionsAndroid::kCompact_Variant: SkDebugf(" compact"); break;
(...skipping 25 matching lines...) Expand all
64 SkTDArray<FontFamily*> preV17FontFamilies; 63 SkTDArray<FontFamily*> preV17FontFamilies;
65 SkFontConfigParser::GetTestFontFamilies(preV17FontFamilies, 64 SkFontConfigParser::GetTestFontFamilies(preV17FontFamilies,
66 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(), 65 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(),
67 GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str()); 66 GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str());
68 67
69 if (preV17FontFamilies.count() > 0) { 68 if (preV17FontFamilies.count() > 0) {
70 REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14); 69 REPORTER_ASSERT(reporter, preV17FontFamilies.count() == 14);
71 REPORTER_ASSERT(reporter, CountFallbacks(preV17FontFamilies) == 10); 70 REPORTER_ASSERT(reporter, CountFallbacks(preV17FontFamilies) == 10);
72 71
73 DumpLoadedFonts(preV17FontFamilies); 72 DumpLoadedFonts(preV17FontFamilies);
74 ValidateLoadedFonts(preV17FontFamilies, reporter); 73 ValidateLoadedFonts(preV17FontFamilies, "Roboto-Regular.ttf", reporter);
75 } else { 74 } else {
76 resourcesMissing = true; 75 resourcesMissing = true;
77 } 76 }
78 77
79 78
80 SkTDArray<FontFamily*> v17FontFamilies; 79 SkTDArray<FontFamily*> v17FontFamilies;
81 SkFontConfigParser::GetTestFontFamilies(v17FontFamilies, 80 SkFontConfigParser::GetTestFontFamilies(v17FontFamilies,
82 GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(), 81 GetResourcePath("android_fonts/v17/system_fonts.xml").c_str(),
83 GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str()); 82 GetResourcePath("android_fonts/v17/fallback_fonts.xml").c_str());
84 83
85 if (v17FontFamilies.count() > 0) { 84 if (v17FontFamilies.count() > 0) {
86 REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41); 85 REPORTER_ASSERT(reporter, v17FontFamilies.count() == 41);
87 REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 31); 86 REPORTER_ASSERT(reporter, CountFallbacks(v17FontFamilies) == 31);
88 87
89 DumpLoadedFonts(v17FontFamilies); 88 DumpLoadedFonts(v17FontFamilies);
90 ValidateLoadedFonts(v17FontFamilies, reporter); 89 ValidateLoadedFonts(v17FontFamilies, "Roboto-Regular.ttf", reporter);
91 } else { 90 } else {
92 resourcesMissing = true; 91 resourcesMissing = true;
93 } 92 }
94 93
95 94
96 SkTDArray<FontFamily*> v22FontFamilies; 95 SkTDArray<FontFamily*> v22FontFamilies;
97 SkFontConfigParser::GetTestFontFamilies(v22FontFamilies, 96 SkFontConfigParser::GetTestFontFamilies(v22FontFamilies,
98 GetResourcePath("android_fonts/v22/fonts.xml").c_str(), 97 GetResourcePath("android_fonts/v22/fonts.xml").c_str(),
99 NULL); 98 NULL);
100 99
101 if (v22FontFamilies.count() > 0) { 100 if (v22FontFamilies.count() > 0) {
102 REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53); 101 REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53);
103 REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42); 102 REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42);
104 103
105 DumpLoadedFonts(v22FontFamilies); 104 DumpLoadedFonts(v22FontFamilies);
106 ValidateLoadedFonts(v22FontFamilies, reporter); 105 ValidateLoadedFonts(v22FontFamilies, "Roboto-Thin.ttf", reporter);
107 } else { 106 } else {
108 resourcesMissing = true; 107 resourcesMissing = true;
109 } 108 }
110 109
111 if (resourcesMissing) { 110 if (resourcesMissing) {
112 SkDebugf("---- Resource files missing for FontConfigParser test\n"); 111 SkDebugf("---- Resource files missing for FontConfigParser test\n");
113 } 112 }
114 } 113 }
115 114
OLDNEW
« no previous file with comments | « src/ports/SkFontMgr_android.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698