blob: f63920b7fa2f67eec2e5dc44f44b9ac16bd75a5e [file] [log] [blame]
reed@google.com83165a52013-04-11 18:31:25 +00001/*
2 * Copyright 2013 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkFont.h"
9#include "include/core/SkFontMgr.h"
10#include "include/core/SkPaint.h"
11#include "include/core/SkStream.h"
12#include "include/core/SkTypeface.h"
13#include "src/core/SkAdvancedTypefaceMetrics.h"
14#include "tests/Test.h"
15#include "tools/flags/CommandLineFlags.h"
reed@google.com83165a52013-04-11 18:31:25 +000016
bungeman147ea2f2015-11-12 09:50:08 -080017#include <initializer_list>
18#include <limits>
19#include <vector>
20
reed@google.com43c27582014-04-08 15:04:29 +000021static void test_font(skiatest::Reporter* reporter) {
Mike Reed5f50f572018-11-12 13:19:37 -050022 SkFont font(nullptr, 24);
skia.committer@gmail.come1d94432014-04-09 03:04:11 +000023
Herb Derby087fad72019-01-22 14:45:16 -050024 //REPORTER_ASSERT(reporter, SkTypeface::GetDefaultTypeface() == font.getTypeface());
Mike Reedfe4fc142018-10-22 14:24:07 -040025 REPORTER_ASSERT(reporter, 24 == font.getSize());
26 REPORTER_ASSERT(reporter, 1 == font.getScaleX());
27 REPORTER_ASSERT(reporter, 0 == font.getSkewX());
reed@google.com43c27582014-04-08 15:04:29 +000028
29 uint16_t glyphs[5];
30 sk_bzero(glyphs, sizeof(glyphs));
31
Florin Malitad6db27c2018-11-02 12:08:31 -040032 // Check that no glyphs are copied with insufficient storage.
Ben Wagner51e15a62019-05-07 15:38:46 -040033 int count = font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, 2);
reed@google.com43c27582014-04-08 15:04:29 +000034 REPORTER_ASSERT(reporter, 5 == count);
Florin Malitad6db27c2018-11-02 12:08:31 -040035 for (const auto glyph : glyphs) { REPORTER_ASSERT(reporter, glyph == 0); }
36
Ben Wagner51e15a62019-05-07 15:38:46 -040037 SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs,
Florin Malitad6db27c2018-11-02 12:08:31 -040038 SK_ARRAY_COUNT(glyphs)) == count);
39
reed@google.com43c27582014-04-08 15:04:29 +000040 for (int i = 0; i < count; ++i) {
41 REPORTER_ASSERT(reporter, 0 != glyphs[i]);
42 }
43 REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
44 REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
skia.committer@gmail.come1d94432014-04-09 03:04:11 +000045
Mike Reedfe4fc142018-10-22 14:24:07 -040046 const SkFont newFont(font.makeWithSize(36));
Herb Derby087fad72019-01-22 14:45:16 -050047 REPORTER_ASSERT(reporter, font.getTypefaceOrDefault() == newFont.getTypefaceOrDefault());
Mike Reedfe4fc142018-10-22 14:24:07 -040048 REPORTER_ASSERT(reporter, 36 == newFont.getSize()); // double check we haven't changed
49 REPORTER_ASSERT(reporter, 24 == font.getSize()); // double check we haven't changed
reed@google.com43c27582014-04-08 15:04:29 +000050}
51
reed@google.comd44d9882013-09-18 20:32:25 +000052/*
53 * If the font backend is going to "alias" some font names to other fonts
54 * (e.g. sans -> Arial) then we want to at least get the same typeface back
55 * if we request the alias name multiple times.
56 */
reed@google.comc1a81eb2013-09-19 18:06:03 +000057static void test_alias_names(skiatest::Reporter* reporter) {
58 const char* inNames[] = {
59 "sans", "sans-serif", "serif", "monospace", "times", "helvetica"
60 };
skia.committer@gmail.comf91e3d42013-09-20 07:01:33 +000061
reed@google.comc1a81eb2013-09-19 18:06:03 +000062 for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) {
mbocee6a9912016-05-31 11:42:36 -070063 sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkFontStyle()));
halcanary96fcdcc2015-08-27 07:41:13 -070064 if (nullptr == first.get()) {
reed@google.comc1a81eb2013-09-19 18:06:03 +000065 continue;
66 }
67 for (int j = 0; j < 10; ++j) {
mbocee6a9912016-05-31 11:42:36 -070068 sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkFontStyle()));
reed@google.comc1a81eb2013-09-19 18:06:03 +000069 #if 0
70 SkString name;
71 face->getFamilyName(&name);
72 printf("request %s, received %s, first id %x received %x\n",
73 inNames[i], name.c_str(), first->uniqueID(), face->uniqueID());
74 #endif
75 REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID());
76 }
reed@google.comd44d9882013-09-18 20:32:25 +000077 }
78}
79
reed@google.com83165a52013-04-11 18:31:25 +000080static void test_fontiter(skiatest::Reporter* reporter, bool verbose) {
Hal Canary342b7ac2016-11-04 11:49:42 -040081 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
reed@google.com83165a52013-04-11 18:31:25 +000082 int count = fm->countFamilies();
83
84 for (int i = 0; i < count; ++i) {
85 SkString fname;
86 fm->getFamilyName(i, &fname);
reed@google.com83165a52013-04-11 18:31:25 +000087
Hal Canary342b7ac2016-11-04 11:49:42 -040088 sk_sp<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str()));
89 sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
bungeman@google.com71033442013-05-01 14:21:20 +000090 REPORTER_ASSERT(reporter, fnset->count() == set->count());
reed@google.com83165a52013-04-11 18:31:25 +000091
92 if (verbose) {
93 SkDebugf("[%2d] %s\n", i, fname.c_str());
94 }
95
96 for (int j = 0; j < set->count(); ++j) {
97 SkString sname;
98 SkFontStyle fs;
99 set->getStyle(j, &fs, &sname);
reed@google.comeb029572013-04-25 14:59:32 +0000100// REPORTER_ASSERT(reporter, sname.size() > 0);
reed@google.com83165a52013-04-11 18:31:25 +0000101
Hal Canary342b7ac2016-11-04 11:49:42 -0400102 sk_sp<SkTypeface> face(set->createTypeface(j));
reed@google.comc1ccda32013-04-19 14:28:54 +0000103// REPORTER_ASSERT(reporter, face.get());
reed@google.com83165a52013-04-11 18:31:25 +0000104
105 if (verbose) {
106 SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(),
bungemanb4bb7d82016-04-27 10:21:04 -0700107 fs.weight(), fs.width(), fs.slant());
reed@google.com83165a52013-04-11 18:31:25 +0000108 }
109 }
110 }
111}
112
bungeman7575bb12017-05-01 13:02:42 -0400113static void test_match(skiatest::Reporter* reporter) {
114 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
115 sk_sp<SkFontStyleSet> styleSet(fm->matchFamily(nullptr));
116 REPORTER_ASSERT(reporter, styleSet);
117}
118
bungeman147ea2f2015-11-12 09:50:08 -0800119static void test_matchStyleCSS3(skiatest::Reporter* reporter) {
bungeman147ea2f2015-11-12 09:50:08 -0800120 static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
121
122 class TestTypeface : public SkTypeface {
123 public:
bungemane3aea102016-07-13 05:16:58 -0700124 TestTypeface(const SkFontStyle& fontStyle) : SkTypeface(fontStyle, false){}
bungeman147ea2f2015-11-12 09:50:08 -0800125 protected:
Ben Wagner4212a7d2019-02-25 14:27:46 -0500126 std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
Bruce Wang536ad2c2018-06-25 11:37:25 -0400127 sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
128 return sk_ref_sp(this);
129 }
reeda9322c22016-04-12 06:47:05 -0700130 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
131 const SkDescriptor*) const override {
bungeman147ea2f2015-11-12 09:50:08 -0800132 return nullptr;
133 }
134 void onFilterRec(SkScalerContextRec*) const override { }
Hal Canary209e4b12017-05-04 14:23:55 -0400135 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
136 return nullptr;
137 }
bungeman147ea2f2015-11-12 09:50:08 -0800138 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
Mike Reed64670cb2019-04-16 11:37:38 -0700139 void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override {
140 sk_bzero(glyphs, count * sizeof(glyphs[0]));
bungeman147ea2f2015-11-12 09:50:08 -0800141 }
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400142 int onCountGlyphs() const override { return 0; }
Ben Wagner2c2240f2019-04-17 16:04:30 -0400143 void getPostScriptGlyphNames(SkString*) const override {}
144 void getGlyphToUnicodeMap(SkUnichar*) const override {}
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400145 int onGetUPEM() const override { return 0; }
bungeman147ea2f2015-11-12 09:50:08 -0800146 class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
147 public:
148 bool next(SkTypeface::LocalizedString*) override { return false; }
149 };
150 void onGetFamilyName(SkString* familyName) const override {
151 familyName->reset();
152 }
153 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
154 return new EmptyLocalizedStrings;
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400155 }
Ben Wagnerfc497342017-02-24 11:15:26 -0500156 int onGetVariationDesignPosition(
157 SkFontArguments::VariationPosition::Coordinate coordinates[],
158 int coordinateCount) const override
159 {
160 return 0;
161 }
Ben Wagner2c2240f2019-04-17 16:04:30 -0400162 int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
163 int parameterCount) const override
164 {
165 return -1;
166 }
bungeman147ea2f2015-11-12 09:50:08 -0800167 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
168 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
169 return 0;
170 }
171 };
172
173 class TestFontStyleSet : public SkFontStyleSet {
174 public:
175 TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {}
176 int count() override { return static_cast<int>(fStyles.size()); }
177 void getStyle(int index, SkFontStyle* style, SkString*) override {
178 if (style) {
179 *style = fStyles[index];
180 }
181 }
182 SkTypeface* createTypeface(int index) override {
183 if (index < 0 || this->count() <= index) {
bungemane3aea102016-07-13 05:16:58 -0700184 return new TestTypeface(invalidFontStyle);
bungeman147ea2f2015-11-12 09:50:08 -0800185 }
bungemane3aea102016-07-13 05:16:58 -0700186 return new TestTypeface(fStyles[index]);
bungeman147ea2f2015-11-12 09:50:08 -0800187 }
188 SkTypeface* matchStyle(const SkFontStyle& pattern) override {
189 return this->matchStyleCSS3(pattern);
190 }
191 private:
192 std::vector<SkFontStyle> fStyles;
193 };
194
195 SkFontStyle condensed_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
196 SkFontStyle condensed_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
197 SkFontStyle condensed_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
198 SkFontStyle condensed_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700199 SkFontStyle condensed_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
200 SkFontStyle condensed_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800201 SkFontStyle expanded_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
202 SkFontStyle expanded_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
203 SkFontStyle expanded_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
204 SkFontStyle expanded_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700205 SkFontStyle expanded_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
206 SkFontStyle expanded_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800207
208 SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800209 SkFontStyle normal_normal_300(SkFontStyle::kLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
210 SkFontStyle normal_normal_400(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
211 SkFontStyle normal_normal_500(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
212 SkFontStyle normal_normal_600(SkFontStyle::kSemiBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800213 SkFontStyle normal_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
214
215 struct StyleSetTest {
216 TestFontStyleSet styleSet;
217 struct Case {
218 SkFontStyle pattern;
219 SkFontStyle expectedResult;
220 };
221 std::vector<Case> cases;
222 } tests[] = {
223 {
Ben Wagner22e04c62019-08-02 01:04:37 -0400224 { normal_normal_500, normal_normal_400 },
225 {
226 { normal_normal_400, normal_normal_400 },
227 { normal_normal_500, normal_normal_500 },
228 },
229 },
230
231 {
232 { normal_normal_500, normal_normal_300 },
233 {
234 { normal_normal_300, normal_normal_300 },
235 { normal_normal_400, normal_normal_500 },
236 { normal_normal_500, normal_normal_500 },
237 },
238 },
239
240 {
bungeman147ea2f2015-11-12 09:50:08 -0800241 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900,
242 expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 },
243 {
244 { condensed_normal_100, condensed_normal_100 },
245 { condensed_normal_900, condensed_normal_900 },
246 { condensed_italic_100, condensed_italic_100 },
247 { condensed_italic_900, condensed_italic_900 },
248 { expanded_normal_100, expanded_normal_100 },
249 { expanded_normal_900, expanded_normal_900 },
250 { expanded_italic_100, expanded_italic_100 },
251 { expanded_italic_900, expanded_italic_900 },
252 },
253 },
254
255 {
256 { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 },
257 {
258 { condensed_normal_100, condensed_normal_100 },
259 { condensed_normal_900, condensed_normal_100 },
260 { condensed_italic_100, condensed_italic_100 },
261 { condensed_italic_900, condensed_italic_100 },
262 { expanded_normal_100, expanded_normal_100 },
263 { expanded_normal_900, expanded_normal_100 },
264 { expanded_italic_100, expanded_italic_100 },
265 { expanded_italic_900, expanded_italic_100 },
266 },
267 },
268
269 {
270 { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 },
271 {
272 { condensed_normal_100, condensed_normal_900 },
273 { condensed_normal_900, condensed_normal_900 },
274 { condensed_italic_100, condensed_italic_900 },
275 { condensed_italic_900, condensed_italic_900 },
276 { expanded_normal_100, expanded_normal_900 },
277 { expanded_normal_900, expanded_normal_900 },
278 { expanded_italic_100, expanded_italic_900 },
279 { expanded_italic_900, expanded_italic_900 },
280 },
281 },
282
283 {
284 { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 },
285 {
286 { condensed_normal_100, condensed_normal_100 },
287 { condensed_normal_900, condensed_normal_900 },
288 { condensed_italic_100, condensed_normal_100 },
289 { condensed_italic_900, condensed_normal_900 },
290 { expanded_normal_100, expanded_normal_100 },
291 { expanded_normal_900, expanded_normal_900 },
292 { expanded_italic_100, expanded_normal_100 },
293 { expanded_italic_900, expanded_normal_900 },
294 },
295 },
296
297 {
298 { condensed_normal_100,expanded_normal_100 },
299 {
300 { condensed_normal_100, condensed_normal_100 },
301 { condensed_normal_900, condensed_normal_100 },
302 { condensed_italic_100, condensed_normal_100 },
303 { condensed_italic_900, condensed_normal_100 },
304 { expanded_normal_100, expanded_normal_100 },
305 { expanded_normal_900, expanded_normal_100 },
306 { expanded_italic_100, expanded_normal_100 },
307 { expanded_italic_900, expanded_normal_100 },
308 },
309 },
310
311 {
312 { condensed_normal_900,expanded_normal_900 },
313 {
314 { condensed_normal_100, condensed_normal_900 },
315 { condensed_normal_900, condensed_normal_900 },
316 { condensed_italic_100, condensed_normal_900 },
317 { condensed_italic_900, condensed_normal_900 },
318 { expanded_normal_100, expanded_normal_900 },
319 { expanded_normal_900, expanded_normal_900 },
320 { expanded_italic_100, expanded_normal_900 },
321 { expanded_italic_900, expanded_normal_900 },
322 },
323 },
324
325 {
326 { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 },
327 {
328 { condensed_normal_100, condensed_italic_100 },
329 { condensed_normal_900, condensed_italic_900 },
330 { condensed_italic_100, condensed_italic_100 },
331 { condensed_italic_900, condensed_italic_900 },
332 { expanded_normal_100, expanded_italic_100 },
333 { expanded_normal_900, expanded_italic_900 },
334 { expanded_italic_100, expanded_italic_100 },
335 { expanded_italic_900, expanded_italic_900 },
336 },
337 },
338
339 {
340 { condensed_italic_100,expanded_italic_100 },
341 {
342 { condensed_normal_100, condensed_italic_100 },
343 { condensed_normal_900, condensed_italic_100 },
344 { condensed_italic_100, condensed_italic_100 },
345 { condensed_italic_900, condensed_italic_100 },
346 { expanded_normal_100, expanded_italic_100 },
347 { expanded_normal_900, expanded_italic_100 },
348 { expanded_italic_100, expanded_italic_100 },
349 { expanded_italic_900, expanded_italic_100 },
350 },
351 },
352
353 {
354 { condensed_italic_900,expanded_italic_900 },
355 {
356 { condensed_normal_100, condensed_italic_900 },
357 { condensed_normal_900, condensed_italic_900 },
358 { condensed_italic_100, condensed_italic_900 },
359 { condensed_italic_900, condensed_italic_900 },
360 { expanded_normal_100, expanded_italic_900 },
361 { expanded_normal_900, expanded_italic_900 },
362 { expanded_italic_100, expanded_italic_900 },
363 { expanded_italic_900, expanded_italic_900 },
364 },
365 },
366
367 {
368 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 },
369 {
370 { condensed_normal_100, condensed_normal_100 },
371 { condensed_normal_900, condensed_normal_900 },
372 { condensed_italic_100, condensed_italic_100 },
373 { condensed_italic_900, condensed_italic_900 },
374 { expanded_normal_100, condensed_normal_100 },
375 { expanded_normal_900, condensed_normal_900 },
376 { expanded_italic_100, condensed_italic_100 },
377 { expanded_italic_900, condensed_italic_900 },
378 },
379 },
380
381 {
382 { condensed_normal_100,condensed_italic_100 },
383 {
384 { condensed_normal_100, condensed_normal_100 },
385 { condensed_normal_900, condensed_normal_100 },
386 { condensed_italic_100, condensed_italic_100 },
387 { condensed_italic_900, condensed_italic_100 },
388 { expanded_normal_100, condensed_normal_100 },
389 { expanded_normal_900, condensed_normal_100 },
390 { expanded_italic_100, condensed_italic_100 },
391 { expanded_italic_900, condensed_italic_100 },
392 },
393 },
394
395 {
396 { condensed_normal_900,condensed_italic_900 },
397 {
398 { condensed_normal_100, condensed_normal_900 },
399 { condensed_normal_900, condensed_normal_900 },
400 { condensed_italic_100, condensed_italic_900 },
401 { condensed_italic_900, condensed_italic_900 },
402 { expanded_normal_100, condensed_normal_900 },
403 { expanded_normal_900, condensed_normal_900 },
404 { expanded_italic_100, condensed_italic_900 },
405 { expanded_italic_900, condensed_italic_900 },
406 },
407 },
408
409 {
410 { condensed_normal_100,condensed_normal_900 },
411 {
412 { condensed_normal_100, condensed_normal_100 },
413 { condensed_normal_900, condensed_normal_900 },
414 { condensed_italic_100, condensed_normal_100 },
415 { condensed_italic_900, condensed_normal_900 },
416 { expanded_normal_100, condensed_normal_100 },
417 { expanded_normal_900, condensed_normal_900 },
418 { expanded_italic_100, condensed_normal_100 },
419 { expanded_italic_900, condensed_normal_900 },
420 },
421 },
422
423 {
424 { condensed_normal_100 },
425 {
426 { condensed_normal_100, condensed_normal_100 },
427 { condensed_normal_900, condensed_normal_100 },
428 { condensed_italic_100, condensed_normal_100 },
429 { condensed_italic_900, condensed_normal_100 },
430 { expanded_normal_100, condensed_normal_100 },
431 { expanded_normal_900, condensed_normal_100 },
432 { expanded_italic_100, condensed_normal_100 },
433 { expanded_italic_900, condensed_normal_100 },
434 },
435 },
436
437 {
438 { condensed_normal_900 },
439 {
440 { condensed_normal_100, condensed_normal_900 },
441 { condensed_normal_900, condensed_normal_900 },
442 { condensed_italic_100, condensed_normal_900 },
443 { condensed_italic_900, condensed_normal_900 },
444 { expanded_normal_100, condensed_normal_900 },
445 { expanded_normal_900, condensed_normal_900 },
446 { expanded_italic_100, condensed_normal_900 },
447 { expanded_italic_900, condensed_normal_900 },
448 },
449 },
450
451 {
452 { condensed_italic_100,condensed_italic_900 },
453 {
454 { condensed_normal_100, condensed_italic_100 },
455 { condensed_normal_900, condensed_italic_900 },
456 { condensed_italic_100, condensed_italic_100 },
457 { condensed_italic_900, condensed_italic_900 },
458 { expanded_normal_100, condensed_italic_100 },
459 { expanded_normal_900, condensed_italic_900 },
460 { expanded_italic_100, condensed_italic_100 },
461 { expanded_italic_900, condensed_italic_900 },
462 },
463 },
464
465 {
466 { condensed_italic_100 },
467 {
468 { condensed_normal_100, condensed_italic_100 },
469 { condensed_normal_900, condensed_italic_100 },
470 { condensed_italic_100, condensed_italic_100 },
471 { condensed_italic_900, condensed_italic_100 },
472 { expanded_normal_100, condensed_italic_100 },
473 { expanded_normal_900, condensed_italic_100 },
474 { expanded_italic_100, condensed_italic_100 },
475 { expanded_italic_900, condensed_italic_100 },
476 },
477 },
478
479 {
480 { condensed_italic_900 },
481 {
482 { condensed_normal_100, condensed_italic_900 },
483 { condensed_normal_900, condensed_italic_900 },
484 { condensed_italic_100, condensed_italic_900 },
485 { condensed_italic_900, condensed_italic_900 },
486 { expanded_normal_100, condensed_italic_900 },
487 { expanded_normal_900, condensed_italic_900 },
488 { expanded_italic_100, condensed_italic_900 },
489 { expanded_italic_900, condensed_italic_900 },
490 },
491 },
492
493 {
bungemanb4bb7d82016-04-27 10:21:04 -0700494 { expanded_normal_100,expanded_normal_900,
495 expanded_italic_100,expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800496 {
497 { condensed_normal_100, expanded_normal_100 },
498 { condensed_normal_900, expanded_normal_900 },
499 { condensed_italic_100, expanded_italic_100 },
500 { condensed_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700501 { condensed_obliqu_100, expanded_italic_100 },
502 { condensed_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800503 { expanded_normal_100, expanded_normal_100 },
504 { expanded_normal_900, expanded_normal_900 },
505 { expanded_italic_100, expanded_italic_100 },
506 { expanded_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700507 { expanded_obliqu_100, expanded_italic_100 },
508 { expanded_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800509 },
510 },
511
512 {
513 { expanded_normal_100,expanded_italic_100 },
514 {
515 { condensed_normal_100, expanded_normal_100 },
516 { condensed_normal_900, expanded_normal_100 },
517 { condensed_italic_100, expanded_italic_100 },
518 { condensed_italic_900, expanded_italic_100 },
519 { expanded_normal_100, expanded_normal_100 },
520 { expanded_normal_900, expanded_normal_100 },
521 { expanded_italic_100, expanded_italic_100 },
522 { expanded_italic_900, expanded_italic_100 },
523 },
524 },
525
526 {
527 { expanded_normal_900,expanded_italic_900 },
528 {
529 { condensed_normal_100, expanded_normal_900 },
530 { condensed_normal_900, expanded_normal_900 },
531 { condensed_italic_100, expanded_italic_900 },
532 { condensed_italic_900, expanded_italic_900 },
533 { expanded_normal_100, expanded_normal_900 },
534 { expanded_normal_900, expanded_normal_900 },
535 { expanded_italic_100, expanded_italic_900 },
536 { expanded_italic_900, expanded_italic_900 },
537 },
538 },
539
540 {
541 { expanded_normal_100,expanded_normal_900 },
542 {
543 { condensed_normal_100, expanded_normal_100 },
544 { condensed_normal_900, expanded_normal_900 },
545 { condensed_italic_100, expanded_normal_100 },
546 { condensed_italic_900, expanded_normal_900 },
547 { expanded_normal_100, expanded_normal_100 },
548 { expanded_normal_900, expanded_normal_900 },
549 { expanded_italic_100, expanded_normal_100 },
550 { expanded_italic_900, expanded_normal_900 },
551 },
552 },
553
554 {
555 { expanded_normal_100 },
556 {
557 { condensed_normal_100, expanded_normal_100 },
558 { condensed_normal_900, expanded_normal_100 },
559 { condensed_italic_100, expanded_normal_100 },
560 { condensed_italic_900, expanded_normal_100 },
561 { expanded_normal_100, expanded_normal_100 },
562 { expanded_normal_900, expanded_normal_100 },
563 { expanded_italic_100, expanded_normal_100 },
564 { expanded_italic_900, expanded_normal_100 },
565 },
566 },
567
568 {
569 { expanded_normal_900 },
570 {
571 { condensed_normal_100, expanded_normal_900 },
572 { condensed_normal_900, expanded_normal_900 },
573 { condensed_italic_100, expanded_normal_900 },
574 { condensed_italic_900, expanded_normal_900 },
575 { expanded_normal_100, expanded_normal_900 },
576 { expanded_normal_900, expanded_normal_900 },
577 { expanded_italic_100, expanded_normal_900 },
578 { expanded_italic_900, expanded_normal_900 },
579 },
580 },
581
582 {
583 { expanded_italic_100,expanded_italic_900 },
584 {
585 { condensed_normal_100, expanded_italic_100 },
586 { condensed_normal_900, expanded_italic_900 },
587 { condensed_italic_100, expanded_italic_100 },
588 { condensed_italic_900, expanded_italic_900 },
589 { expanded_normal_100, expanded_italic_100 },
590 { expanded_normal_900, expanded_italic_900 },
591 { expanded_italic_100, expanded_italic_100 },
592 { expanded_italic_900, expanded_italic_900 },
593 },
594 },
595
596 {
597 { expanded_italic_100 },
598 {
599 { condensed_normal_100, expanded_italic_100 },
600 { condensed_normal_900, expanded_italic_100 },
601 { condensed_italic_100, expanded_italic_100 },
602 { condensed_italic_900, expanded_italic_100 },
603 { expanded_normal_100, expanded_italic_100 },
604 { expanded_normal_900, expanded_italic_100 },
605 { expanded_italic_100, expanded_italic_100 },
606 { expanded_italic_900, expanded_italic_100 },
607 },
608 },
609
610 {
611 { expanded_italic_900 },
612 {
613 { condensed_normal_100, expanded_italic_900 },
614 { condensed_normal_900, expanded_italic_900 },
615 { condensed_italic_100, expanded_italic_900 },
616 { condensed_italic_900, expanded_italic_900 },
617 { expanded_normal_100, expanded_italic_900 },
618 { expanded_normal_900, expanded_italic_900 },
619 { expanded_italic_100, expanded_italic_900 },
620 { expanded_italic_900, expanded_italic_900 },
621 },
622 },
623
624 {
625 { normal_normal_100, normal_normal_900 },
626 {
627 { normal_normal_300, normal_normal_100 },
628 { normal_normal_400, normal_normal_100 },
629 { normal_normal_500, normal_normal_100 },
630 { normal_normal_600, normal_normal_900 },
631 },
632 },
633
634 {
635 { normal_normal_100, normal_normal_400, normal_normal_900 },
636 {
637 { normal_normal_300, normal_normal_100 },
638 { normal_normal_400, normal_normal_400 },
639 { normal_normal_500, normal_normal_400 },
640 { normal_normal_600, normal_normal_900 },
641 },
642 },
643
644 {
645 { normal_normal_100, normal_normal_500, normal_normal_900 },
646 {
647 { normal_normal_300, normal_normal_100 },
648 { normal_normal_400, normal_normal_500 },
649 { normal_normal_500, normal_normal_500 },
650 { normal_normal_600, normal_normal_900 },
651 },
652 },
653
654 {
655 { },
656 {
657 { normal_normal_300, invalidFontStyle },
658 { normal_normal_400, invalidFontStyle },
659 { normal_normal_500, invalidFontStyle },
660 { normal_normal_600, invalidFontStyle },
661 },
662 },
bungemanb4bb7d82016-04-27 10:21:04 -0700663 {
664 { expanded_normal_100,expanded_normal_900,
665 expanded_italic_100,expanded_italic_900,
666 expanded_obliqu_100,expanded_obliqu_900, },
667 {
668 { condensed_normal_100, expanded_normal_100 },
669 { condensed_normal_900, expanded_normal_900 },
670 { condensed_italic_100, expanded_italic_100 },
671 { condensed_italic_900, expanded_italic_900 },
672 { condensed_obliqu_100, expanded_obliqu_100 },
673 { condensed_obliqu_900, expanded_obliqu_900 },
674 { expanded_normal_100, expanded_normal_100 },
675 { expanded_normal_900, expanded_normal_900 },
676 { expanded_italic_100, expanded_italic_100 },
677 { expanded_italic_900, expanded_italic_900 },
678 { expanded_obliqu_100, expanded_obliqu_100 },
679 { expanded_obliqu_900, expanded_obliqu_900 },
680 },
681 },
682 {
683 { expanded_normal_100,expanded_normal_900,
684 expanded_obliqu_100,expanded_obliqu_900, },
685 {
686 { condensed_normal_100, expanded_normal_100 },
687 { condensed_normal_900, expanded_normal_900 },
688 { condensed_italic_100, expanded_obliqu_100 },
689 { condensed_italic_900, expanded_obliqu_900 },
690 { condensed_obliqu_100, expanded_obliqu_100 },
691 { condensed_obliqu_900, expanded_obliqu_900 },
692 { expanded_normal_100, expanded_normal_100 },
693 { expanded_normal_900, expanded_normal_900 },
694 { expanded_italic_100, expanded_obliqu_100 },
695 { expanded_italic_900, expanded_obliqu_900 },
696 { expanded_obliqu_100, expanded_obliqu_100 },
697 { expanded_obliqu_900, expanded_obliqu_900 },
698 },
699 },
700 {
701 { expanded_italic_100,expanded_italic_900,
702 expanded_obliqu_100,expanded_obliqu_900, },
703 {
704 { condensed_normal_100, expanded_obliqu_100 },
705 { condensed_normal_900, expanded_obliqu_900 },
706 { condensed_italic_100, expanded_italic_100 },
707 { condensed_italic_900, expanded_italic_900 },
708 { condensed_obliqu_100, expanded_obliqu_100 },
709 { condensed_obliqu_900, expanded_obliqu_900 },
710 { expanded_normal_100, expanded_obliqu_100 },
711 { expanded_normal_900, expanded_obliqu_900 },
712 { expanded_italic_100, expanded_italic_100 },
713 { expanded_italic_900, expanded_italic_900 },
714 { expanded_obliqu_100, expanded_obliqu_100 },
715 { expanded_obliqu_900, expanded_obliqu_900 },
716 },
717 },
bungeman147ea2f2015-11-12 09:50:08 -0800718 };
719
720 for (StyleSetTest& test : tests) {
Mike Klein6ad99092016-10-26 10:35:22 -0400721 for (const StyleSetTest::Case& testCase : test.cases) {
Hal Canary342b7ac2016-11-04 11:49:42 -0400722 sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern));
bungeman147ea2f2015-11-12 09:50:08 -0800723 if (typeface) {
724 REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult);
725 } else {
726 REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult);
727 }
728 }
729 }
730}
731
reed@google.com66c9f992013-04-11 19:04:34 +0000732DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
reed@google.com83165a52013-04-11 18:31:25 +0000733
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +0000734DEF_TEST(FontMgr, reporter) {
bungeman7575bb12017-05-01 13:02:42 -0400735 test_match(reporter);
bungeman147ea2f2015-11-12 09:50:08 -0800736 test_matchStyleCSS3(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000737 test_fontiter(reporter, FLAGS_verboseFontMgr);
reed@google.comc1a81eb2013-09-19 18:06:03 +0000738 test_alias_names(reporter);
reed@google.com43c27582014-04-08 15:04:29 +0000739 test_font(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000740}