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

Side by Side Diff: tests/FontConfigParser.cpp

Issue 1027373002: Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Android and tests. Created 5 years, 7 months 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
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 "SkCommandLineFlags.h" 9 #include "SkCommandLineFlags.h"
10 #include "SkFontConfigParser_android.h" 10 #include "SkFontConfigParser_android.h"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 #include <cmath>
14 #include <cstdio>
15
13 DECLARE_bool(verboseFontMgr); 16 DECLARE_bool(verboseFontMgr);
14 17
15 int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) { 18 int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) {
16 int countOfFallbackFonts = 0; 19 int countOfFallbackFonts = 0;
17 for (int i = 0; i < fontFamilies.count(); i++) { 20 for (int i = 0; i < fontFamilies.count(); i++) {
18 if (fontFamilies[i]->fIsFallbackFont) { 21 if (fontFamilies[i]->fIsFallbackFont) {
19 countOfFallbackFonts++; 22 countOfFallbackFonts++;
20 } 23 }
21 } 24 }
22 return countOfFallbackFonts; 25 return countOfFallbackFonts;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str()); 87 SkDebugf(" name %s\n", fontFamilies[i]->fNames[j].c_str());
85 } 88 }
86 for (int j = 0; j < fontFamilies[i]->fFonts.count(); ++j) { 89 for (int j = 0; j < fontFamilies[i]->fFonts.count(); ++j) {
87 const FontFileInfo& ffi = fontFamilies[i]->fFonts[j]; 90 const FontFileInfo& ffi = fontFamilies[i]->fFonts[j];
88 SkDebugf(" file (%d) %s#%d\n", ffi.fWeight, ffi.fFileName.c_str(), ffi.fIndex); 91 SkDebugf(" file (%d) %s#%d\n", ffi.fWeight, ffi.fFileName.c_str(), ffi.fIndex);
89 } 92 }
90 } 93 }
91 SkDebugf("\n\n"); 94 SkDebugf("\n\n");
92 } 95 }
93 96
97 template <int N, typename T> static void test_parse_fixed_r(skiatest::Reporter* reporter,
98 double low, double h igh, double inc)
99 {
100 double SK_FixedMax_double = nextafter(1 << (sizeof(T) * CHAR_BIT - N - 1), 0 .0);
101 double SK_FixedEpsilon_double = (1.0 / (1 << N));
102 //double maxError = 0;
103 char buffer[64];
104 for (double f = low; f < high; f += inc) {
105 SkString s;
106 // 'sprintf' formatting as expected depends on the current locale being "C".
107 // This test currently only runs on Android, which always runs in the "C " locale.
108 sprintf(buffer, "%.20f", f);
109 T fix;
110 bool b = parse_fixed<N>(buffer, &fix);
111 if (b) {
112 double f2 = fix * SK_FixedEpsilon_double;
113 REPORTER_ASSERT(reporter, fabs(f - f2) <= SK_FixedEpsilon_double);
114 //maxError = SkTMax(maxError, fabs(f - f2));
115 } else {
116 REPORTER_ASSERT(reporter, SK_FixedMax_double < f || f < -SK_FixedMax _double);
117 }
118 }
119
120 //SkDebugf("maxError: %.20f\n", maxError);
121 }
122
123 static void test_parse_fixed(skiatest::Reporter* reporter) {
124 test_parse_fixed_r<27, int32_t>(reporter, -17.1, -16.9, 0.000001);
125 test_parse_fixed_r<27, int32_t>(reporter, -8.1, -7.9, 0.000001);
126 test_parse_fixed_r<27, int32_t>(reporter, -0.1, 0.1, 0.000001);
127 test_parse_fixed_r<27, int32_t>(reporter, 7.9, 8.1, 0.000001);
128 test_parse_fixed_r<27, int32_t>(reporter, 16.9, 17.1, 0.000001);
129 test_parse_fixed_r<16, int32_t>(reporter, -0.125, 0.125, 1.0 / (1 << 19));
130 test_parse_fixed_r<16, int32_t>(reporter, -32768.125, -32766.875, 1.0 / (1 < < 17));
131 test_parse_fixed_r<16, int32_t>(reporter, 32766.875, 32768.125, 1.0 / (1 << 17));
132 test_parse_fixed_r<16, int32_t>(reporter, -1.1, 1.1, 0.0001);
133
134 SkFixed fix;
135 REPORTER_ASSERT(reporter, !parse_fixed<16>("", &fix));
136 REPORTER_ASSERT(reporter, !parse_fixed<16>(".", &fix));
137 REPORTER_ASSERT(reporter, !parse_fixed<16>("123.", &fix));
138 REPORTER_ASSERT(reporter, !parse_fixed<16>("a", &fix));
139 REPORTER_ASSERT(reporter, !parse_fixed<16>(".123a", &fix));
140 }
141
94 DEF_TEST(FontConfigParserAndroid, reporter) { 142 DEF_TEST(FontConfigParserAndroid, reporter) {
143 test_parse_fixed(reporter);
95 144
96 bool resourcesMissing = false; 145 bool resourcesMissing = false;
97 146
98 SkTDArray<FontFamily*> preV17FontFamilies; 147 SkTDArray<FontFamily*> preV17FontFamilies;
99 SkFontConfigParser::GetCustomFontFamilies(preV17FontFamilies, 148 SkFontConfigParser::GetCustomFontFamilies(preV17FontFamilies,
100 SkString("/custom/font/path/"), 149 SkString("/custom/font/path/"),
101 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(), 150 GetResourcePath("android_fonts/pre_v17/system_fonts.xml").c_str(),
102 GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str()); 151 GetResourcePath("android_fonts/pre_v17/fallback_fonts.xml").c_str());
103 152
104 if (preV17FontFamilies.count() > 0) { 153 if (preV17FontFamilies.count() > 0) {
(...skipping 25 matching lines...) Expand all
130 } 179 }
131 180
132 181
133 SkTDArray<FontFamily*> v22FontFamilies; 182 SkTDArray<FontFamily*> v22FontFamilies;
134 SkFontConfigParser::GetCustomFontFamilies(v22FontFamilies, 183 SkFontConfigParser::GetCustomFontFamilies(v22FontFamilies,
135 SkString("/custom/font/path/"), 184 SkString("/custom/font/path/"),
136 GetResourcePath("android_fonts/v22/fonts.xml").c_str(), 185 GetResourcePath("android_fonts/v22/fonts.xml").c_str(),
137 NULL); 186 NULL);
138 187
139 if (v22FontFamilies.count() > 0) { 188 if (v22FontFamilies.count() > 0) {
140 REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53); 189 REPORTER_ASSERT(reporter, v22FontFamilies.count() == 54);
141 REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42); 190 REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42);
142 191
143 DumpLoadedFonts(v22FontFamilies, "version 22"); 192 DumpLoadedFonts(v22FontFamilies, "version 22");
144 ValidateLoadedFonts(v22FontFamilies, "Roboto-Thin.ttf", reporter); 193 ValidateLoadedFonts(v22FontFamilies, "Roboto-Thin.ttf", reporter);
145 } else { 194 } else {
146 resourcesMissing = true; 195 resourcesMissing = true;
147 } 196 }
148 197
149 if (resourcesMissing) { 198 if (resourcesMissing) {
150 SkDebugf("---- Resource files missing for FontConfigParser test\n"); 199 SkDebugf("---- Resource files missing for FontConfigParser test\n");
151 } 200 }
152 } 201 }
153 202
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698