blob: b6a0cc5a740f3d80eda7fd8867a29228a7746627 [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
reed@google.com83165a52013-04-11 18:31:25 +00008#include "SkCommandLineFlags.h"
9#include "SkFontMgr.h"
10#include "SkTypeface.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000011#include "Test.h"
reed@google.com83165a52013-04-11 18:31:25 +000012
reed@google.com43c27582014-04-08 15:04:29 +000013#include "SkFont.h"
14#include "SkPaint.h"
bungeman147ea2f2015-11-12 09:50:08 -080015
16#include <initializer_list>
17#include <limits>
18#include <vector>
19
reed@google.com43c27582014-04-08 15:04:29 +000020static void test_font(skiatest::Reporter* reporter) {
21 uint32_t flags = 0;
bungeman13b9c952016-05-12 10:09:30 -070022 sk_sp<SkFont> font(SkFont::Make(nullptr, 24, SkFont::kA8_MaskType, flags));
skia.committer@gmail.come1d94432014-04-09 03:04:11 +000023
bsalomon49f085d2014-09-05 13:34:00 -070024 REPORTER_ASSERT(reporter, font->getTypeface());
reed@google.com43c27582014-04-08 15:04:29 +000025 REPORTER_ASSERT(reporter, 24 == font->getSize());
26 REPORTER_ASSERT(reporter, 1 == font->getScaleX());
27 REPORTER_ASSERT(reporter, 0 == font->getSkewX());
28 REPORTER_ASSERT(reporter, SkFont::kA8_MaskType == font->getMaskType());
29
30 uint16_t glyphs[5];
31 sk_bzero(glyphs, sizeof(glyphs));
32
33 int count = font->textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, SK_ARRAY_COUNT(glyphs));
34
35 REPORTER_ASSERT(reporter, 5 == count);
36 for (int i = 0; i < count; ++i) {
37 REPORTER_ASSERT(reporter, 0 != glyphs[i]);
38 }
39 REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
40 REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
skia.committer@gmail.come1d94432014-04-09 03:04:11 +000041
bungeman13b9c952016-05-12 10:09:30 -070042 sk_sp<SkFont> newFont(font->makeWithSize(36));
reed@google.com43c27582014-04-08 15:04:29 +000043 REPORTER_ASSERT(reporter, newFont.get());
44 REPORTER_ASSERT(reporter, font->getTypeface() == newFont->getTypeface());
45 REPORTER_ASSERT(reporter, 36 == newFont->getSize()); // double check we haven't changed
46 REPORTER_ASSERT(reporter, 24 == font->getSize()); // double check we haven't changed
47
48 SkPaint paint;
49 paint.setTextSize(18);
bungeman13b9c952016-05-12 10:09:30 -070050 font = SkFont::Testing_CreateFromPaint(paint);
reed@google.com43c27582014-04-08 15:04:29 +000051 REPORTER_ASSERT(reporter, font.get());
52 REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize());
53 REPORTER_ASSERT(reporter, SkFont::kBW_MaskType == font->getMaskType());
54}
55
reed@google.comd44d9882013-09-18 20:32:25 +000056/*
57 * If the font backend is going to "alias" some font names to other fonts
58 * (e.g. sans -> Arial) then we want to at least get the same typeface back
59 * if we request the alias name multiple times.
60 */
reed@google.comc1a81eb2013-09-19 18:06:03 +000061static void test_alias_names(skiatest::Reporter* reporter) {
62 const char* inNames[] = {
63 "sans", "sans-serif", "serif", "monospace", "times", "helvetica"
64 };
skia.committer@gmail.comf91e3d42013-09-20 07:01:33 +000065
reed@google.comc1a81eb2013-09-19 18:06:03 +000066 for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) {
mbocee6a9912016-05-31 11:42:36 -070067 sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkFontStyle()));
halcanary96fcdcc2015-08-27 07:41:13 -070068 if (nullptr == first.get()) {
reed@google.comc1a81eb2013-09-19 18:06:03 +000069 continue;
70 }
71 for (int j = 0; j < 10; ++j) {
mbocee6a9912016-05-31 11:42:36 -070072 sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkFontStyle()));
reed@google.comc1a81eb2013-09-19 18:06:03 +000073 #if 0
74 SkString name;
75 face->getFamilyName(&name);
76 printf("request %s, received %s, first id %x received %x\n",
77 inNames[i], name.c_str(), first->uniqueID(), face->uniqueID());
78 #endif
79 REPORTER_ASSERT(reporter, first->uniqueID() == face->uniqueID());
80 }
reed@google.comd44d9882013-09-18 20:32:25 +000081 }
82}
83
reed@google.com83165a52013-04-11 18:31:25 +000084static void test_fontiter(skiatest::Reporter* reporter, bool verbose) {
Hal Canary342b7ac2016-11-04 11:49:42 -040085 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
reed@google.com83165a52013-04-11 18:31:25 +000086 int count = fm->countFamilies();
87
88 for (int i = 0; i < count; ++i) {
89 SkString fname;
90 fm->getFamilyName(i, &fname);
reed@google.com83165a52013-04-11 18:31:25 +000091
Hal Canary342b7ac2016-11-04 11:49:42 -040092 sk_sp<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str()));
93 sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
bungeman@google.com71033442013-05-01 14:21:20 +000094 REPORTER_ASSERT(reporter, fnset->count() == set->count());
reed@google.com83165a52013-04-11 18:31:25 +000095
96 if (verbose) {
97 SkDebugf("[%2d] %s\n", i, fname.c_str());
98 }
99
100 for (int j = 0; j < set->count(); ++j) {
101 SkString sname;
102 SkFontStyle fs;
103 set->getStyle(j, &fs, &sname);
reed@google.comeb029572013-04-25 14:59:32 +0000104// REPORTER_ASSERT(reporter, sname.size() > 0);
reed@google.com83165a52013-04-11 18:31:25 +0000105
Hal Canary342b7ac2016-11-04 11:49:42 -0400106 sk_sp<SkTypeface> face(set->createTypeface(j));
reed@google.comc1ccda32013-04-19 14:28:54 +0000107// REPORTER_ASSERT(reporter, face.get());
reed@google.com83165a52013-04-11 18:31:25 +0000108
109 if (verbose) {
110 SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(),
bungemanb4bb7d82016-04-27 10:21:04 -0700111 fs.weight(), fs.width(), fs.slant());
reed@google.com83165a52013-04-11 18:31:25 +0000112 }
113 }
114 }
115}
116
bungeman147ea2f2015-11-12 09:50:08 -0800117static void test_matchStyleCSS3(skiatest::Reporter* reporter) {
bungeman147ea2f2015-11-12 09:50:08 -0800118 static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
119
120 class TestTypeface : public SkTypeface {
121 public:
bungemane3aea102016-07-13 05:16:58 -0700122 TestTypeface(const SkFontStyle& fontStyle) : SkTypeface(fontStyle, false){}
bungeman147ea2f2015-11-12 09:50:08 -0800123 protected:
124 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
reeda9322c22016-04-12 06:47:05 -0700125 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
126 const SkDescriptor*) const override {
bungeman147ea2f2015-11-12 09:50:08 -0800127 return nullptr;
128 }
129 void onFilterRec(SkScalerContextRec*) const override { }
130 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
131 PerGlyphInfo,
132 const uint32_t*, uint32_t) const override { return nullptr; }
133 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
134 virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
135 uint16_t glyphs[], int glyphCount) const override {
136 if (glyphs && glyphCount > 0) {
137 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0]));
138 }
139 return 0;
140 }
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400141 int onCountGlyphs() const override { return 0; }
142 int onGetUPEM() const override { return 0; }
bungeman147ea2f2015-11-12 09:50:08 -0800143 class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
144 public:
145 bool next(SkTypeface::LocalizedString*) override { return false; }
146 };
147 void onGetFamilyName(SkString* familyName) const override {
148 familyName->reset();
149 }
150 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
151 return new EmptyLocalizedStrings;
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400152 }
Ben Wagnerfc497342017-02-24 11:15:26 -0500153 int onGetVariationDesignPosition(
154 SkFontArguments::VariationPosition::Coordinate coordinates[],
155 int coordinateCount) const override
156 {
157 return 0;
158 }
bungeman147ea2f2015-11-12 09:50:08 -0800159 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
160 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
161 return 0;
162 }
163 };
164
165 class TestFontStyleSet : public SkFontStyleSet {
166 public:
167 TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {}
168 int count() override { return static_cast<int>(fStyles.size()); }
169 void getStyle(int index, SkFontStyle* style, SkString*) override {
170 if (style) {
171 *style = fStyles[index];
172 }
173 }
174 SkTypeface* createTypeface(int index) override {
175 if (index < 0 || this->count() <= index) {
bungemane3aea102016-07-13 05:16:58 -0700176 return new TestTypeface(invalidFontStyle);
bungeman147ea2f2015-11-12 09:50:08 -0800177 }
bungemane3aea102016-07-13 05:16:58 -0700178 return new TestTypeface(fStyles[index]);
bungeman147ea2f2015-11-12 09:50:08 -0800179 }
180 SkTypeface* matchStyle(const SkFontStyle& pattern) override {
181 return this->matchStyleCSS3(pattern);
182 }
183 private:
184 std::vector<SkFontStyle> fStyles;
185 };
186
187 SkFontStyle condensed_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
188 SkFontStyle condensed_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
189 SkFontStyle condensed_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
190 SkFontStyle condensed_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700191 SkFontStyle condensed_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
192 SkFontStyle condensed_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800193 SkFontStyle expanded_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
194 SkFontStyle expanded_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
195 SkFontStyle expanded_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
196 SkFontStyle expanded_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700197 SkFontStyle expanded_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
198 SkFontStyle expanded_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800199
200 SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
201 SkFontStyle normal_normal_200(SkFontStyle::kExtraLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
202 SkFontStyle normal_normal_300(SkFontStyle::kLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
203 SkFontStyle normal_normal_400(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
204 SkFontStyle normal_normal_500(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
205 SkFontStyle normal_normal_600(SkFontStyle::kSemiBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
206 SkFontStyle normal_normal_700(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
207 SkFontStyle normal_normal_800(SkFontStyle::kExtraBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
208 SkFontStyle normal_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
209
210 struct StyleSetTest {
211 TestFontStyleSet styleSet;
212 struct Case {
213 SkFontStyle pattern;
214 SkFontStyle expectedResult;
215 };
216 std::vector<Case> cases;
217 } tests[] = {
218 {
219 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900,
220 expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 },
221 {
222 { condensed_normal_100, condensed_normal_100 },
223 { condensed_normal_900, condensed_normal_900 },
224 { condensed_italic_100, condensed_italic_100 },
225 { condensed_italic_900, condensed_italic_900 },
226 { expanded_normal_100, expanded_normal_100 },
227 { expanded_normal_900, expanded_normal_900 },
228 { expanded_italic_100, expanded_italic_100 },
229 { expanded_italic_900, expanded_italic_900 },
230 },
231 },
232
233 {
234 { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 },
235 {
236 { condensed_normal_100, condensed_normal_100 },
237 { condensed_normal_900, condensed_normal_100 },
238 { condensed_italic_100, condensed_italic_100 },
239 { condensed_italic_900, condensed_italic_100 },
240 { expanded_normal_100, expanded_normal_100 },
241 { expanded_normal_900, expanded_normal_100 },
242 { expanded_italic_100, expanded_italic_100 },
243 { expanded_italic_900, expanded_italic_100 },
244 },
245 },
246
247 {
248 { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 },
249 {
250 { condensed_normal_100, condensed_normal_900 },
251 { condensed_normal_900, condensed_normal_900 },
252 { condensed_italic_100, condensed_italic_900 },
253 { condensed_italic_900, condensed_italic_900 },
254 { expanded_normal_100, expanded_normal_900 },
255 { expanded_normal_900, expanded_normal_900 },
256 { expanded_italic_100, expanded_italic_900 },
257 { expanded_italic_900, expanded_italic_900 },
258 },
259 },
260
261 {
262 { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 },
263 {
264 { condensed_normal_100, condensed_normal_100 },
265 { condensed_normal_900, condensed_normal_900 },
266 { condensed_italic_100, condensed_normal_100 },
267 { condensed_italic_900, condensed_normal_900 },
268 { expanded_normal_100, expanded_normal_100 },
269 { expanded_normal_900, expanded_normal_900 },
270 { expanded_italic_100, expanded_normal_100 },
271 { expanded_italic_900, expanded_normal_900 },
272 },
273 },
274
275 {
276 { condensed_normal_100,expanded_normal_100 },
277 {
278 { condensed_normal_100, condensed_normal_100 },
279 { condensed_normal_900, condensed_normal_100 },
280 { condensed_italic_100, condensed_normal_100 },
281 { condensed_italic_900, condensed_normal_100 },
282 { expanded_normal_100, expanded_normal_100 },
283 { expanded_normal_900, expanded_normal_100 },
284 { expanded_italic_100, expanded_normal_100 },
285 { expanded_italic_900, expanded_normal_100 },
286 },
287 },
288
289 {
290 { condensed_normal_900,expanded_normal_900 },
291 {
292 { condensed_normal_100, condensed_normal_900 },
293 { condensed_normal_900, condensed_normal_900 },
294 { condensed_italic_100, condensed_normal_900 },
295 { condensed_italic_900, condensed_normal_900 },
296 { expanded_normal_100, expanded_normal_900 },
297 { expanded_normal_900, expanded_normal_900 },
298 { expanded_italic_100, expanded_normal_900 },
299 { expanded_italic_900, expanded_normal_900 },
300 },
301 },
302
303 {
304 { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 },
305 {
306 { condensed_normal_100, condensed_italic_100 },
307 { condensed_normal_900, condensed_italic_900 },
308 { condensed_italic_100, condensed_italic_100 },
309 { condensed_italic_900, condensed_italic_900 },
310 { expanded_normal_100, expanded_italic_100 },
311 { expanded_normal_900, expanded_italic_900 },
312 { expanded_italic_100, expanded_italic_100 },
313 { expanded_italic_900, expanded_italic_900 },
314 },
315 },
316
317 {
318 { condensed_italic_100,expanded_italic_100 },
319 {
320 { condensed_normal_100, condensed_italic_100 },
321 { condensed_normal_900, condensed_italic_100 },
322 { condensed_italic_100, condensed_italic_100 },
323 { condensed_italic_900, condensed_italic_100 },
324 { expanded_normal_100, expanded_italic_100 },
325 { expanded_normal_900, expanded_italic_100 },
326 { expanded_italic_100, expanded_italic_100 },
327 { expanded_italic_900, expanded_italic_100 },
328 },
329 },
330
331 {
332 { condensed_italic_900,expanded_italic_900 },
333 {
334 { condensed_normal_100, condensed_italic_900 },
335 { condensed_normal_900, condensed_italic_900 },
336 { condensed_italic_100, condensed_italic_900 },
337 { condensed_italic_900, condensed_italic_900 },
338 { expanded_normal_100, expanded_italic_900 },
339 { expanded_normal_900, expanded_italic_900 },
340 { expanded_italic_100, expanded_italic_900 },
341 { expanded_italic_900, expanded_italic_900 },
342 },
343 },
344
345 {
346 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 },
347 {
348 { condensed_normal_100, condensed_normal_100 },
349 { condensed_normal_900, condensed_normal_900 },
350 { condensed_italic_100, condensed_italic_100 },
351 { condensed_italic_900, condensed_italic_900 },
352 { expanded_normal_100, condensed_normal_100 },
353 { expanded_normal_900, condensed_normal_900 },
354 { expanded_italic_100, condensed_italic_100 },
355 { expanded_italic_900, condensed_italic_900 },
356 },
357 },
358
359 {
360 { condensed_normal_100,condensed_italic_100 },
361 {
362 { condensed_normal_100, condensed_normal_100 },
363 { condensed_normal_900, condensed_normal_100 },
364 { condensed_italic_100, condensed_italic_100 },
365 { condensed_italic_900, condensed_italic_100 },
366 { expanded_normal_100, condensed_normal_100 },
367 { expanded_normal_900, condensed_normal_100 },
368 { expanded_italic_100, condensed_italic_100 },
369 { expanded_italic_900, condensed_italic_100 },
370 },
371 },
372
373 {
374 { condensed_normal_900,condensed_italic_900 },
375 {
376 { condensed_normal_100, condensed_normal_900 },
377 { condensed_normal_900, condensed_normal_900 },
378 { condensed_italic_100, condensed_italic_900 },
379 { condensed_italic_900, condensed_italic_900 },
380 { expanded_normal_100, condensed_normal_900 },
381 { expanded_normal_900, condensed_normal_900 },
382 { expanded_italic_100, condensed_italic_900 },
383 { expanded_italic_900, condensed_italic_900 },
384 },
385 },
386
387 {
388 { condensed_normal_100,condensed_normal_900 },
389 {
390 { condensed_normal_100, condensed_normal_100 },
391 { condensed_normal_900, condensed_normal_900 },
392 { condensed_italic_100, condensed_normal_100 },
393 { condensed_italic_900, condensed_normal_900 },
394 { expanded_normal_100, condensed_normal_100 },
395 { expanded_normal_900, condensed_normal_900 },
396 { expanded_italic_100, condensed_normal_100 },
397 { expanded_italic_900, condensed_normal_900 },
398 },
399 },
400
401 {
402 { condensed_normal_100 },
403 {
404 { condensed_normal_100, condensed_normal_100 },
405 { condensed_normal_900, condensed_normal_100 },
406 { condensed_italic_100, condensed_normal_100 },
407 { condensed_italic_900, condensed_normal_100 },
408 { expanded_normal_100, condensed_normal_100 },
409 { expanded_normal_900, condensed_normal_100 },
410 { expanded_italic_100, condensed_normal_100 },
411 { expanded_italic_900, condensed_normal_100 },
412 },
413 },
414
415 {
416 { condensed_normal_900 },
417 {
418 { condensed_normal_100, condensed_normal_900 },
419 { condensed_normal_900, condensed_normal_900 },
420 { condensed_italic_100, condensed_normal_900 },
421 { condensed_italic_900, condensed_normal_900 },
422 { expanded_normal_100, condensed_normal_900 },
423 { expanded_normal_900, condensed_normal_900 },
424 { expanded_italic_100, condensed_normal_900 },
425 { expanded_italic_900, condensed_normal_900 },
426 },
427 },
428
429 {
430 { condensed_italic_100,condensed_italic_900 },
431 {
432 { condensed_normal_100, condensed_italic_100 },
433 { condensed_normal_900, condensed_italic_900 },
434 { condensed_italic_100, condensed_italic_100 },
435 { condensed_italic_900, condensed_italic_900 },
436 { expanded_normal_100, condensed_italic_100 },
437 { expanded_normal_900, condensed_italic_900 },
438 { expanded_italic_100, condensed_italic_100 },
439 { expanded_italic_900, condensed_italic_900 },
440 },
441 },
442
443 {
444 { condensed_italic_100 },
445 {
446 { condensed_normal_100, condensed_italic_100 },
447 { condensed_normal_900, condensed_italic_100 },
448 { condensed_italic_100, condensed_italic_100 },
449 { condensed_italic_900, condensed_italic_100 },
450 { expanded_normal_100, condensed_italic_100 },
451 { expanded_normal_900, condensed_italic_100 },
452 { expanded_italic_100, condensed_italic_100 },
453 { expanded_italic_900, condensed_italic_100 },
454 },
455 },
456
457 {
458 { condensed_italic_900 },
459 {
460 { condensed_normal_100, condensed_italic_900 },
461 { condensed_normal_900, condensed_italic_900 },
462 { condensed_italic_100, condensed_italic_900 },
463 { condensed_italic_900, condensed_italic_900 },
464 { expanded_normal_100, condensed_italic_900 },
465 { expanded_normal_900, condensed_italic_900 },
466 { expanded_italic_100, condensed_italic_900 },
467 { expanded_italic_900, condensed_italic_900 },
468 },
469 },
470
471 {
bungemanb4bb7d82016-04-27 10:21:04 -0700472 { expanded_normal_100,expanded_normal_900,
473 expanded_italic_100,expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800474 {
475 { condensed_normal_100, expanded_normal_100 },
476 { condensed_normal_900, expanded_normal_900 },
477 { condensed_italic_100, expanded_italic_100 },
478 { condensed_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700479 { condensed_obliqu_100, expanded_italic_100 },
480 { condensed_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800481 { expanded_normal_100, expanded_normal_100 },
482 { expanded_normal_900, expanded_normal_900 },
483 { expanded_italic_100, expanded_italic_100 },
484 { expanded_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700485 { expanded_obliqu_100, expanded_italic_100 },
486 { expanded_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800487 },
488 },
489
490 {
491 { expanded_normal_100,expanded_italic_100 },
492 {
493 { condensed_normal_100, expanded_normal_100 },
494 { condensed_normal_900, expanded_normal_100 },
495 { condensed_italic_100, expanded_italic_100 },
496 { condensed_italic_900, expanded_italic_100 },
497 { expanded_normal_100, expanded_normal_100 },
498 { expanded_normal_900, expanded_normal_100 },
499 { expanded_italic_100, expanded_italic_100 },
500 { expanded_italic_900, expanded_italic_100 },
501 },
502 },
503
504 {
505 { expanded_normal_900,expanded_italic_900 },
506 {
507 { condensed_normal_100, expanded_normal_900 },
508 { condensed_normal_900, expanded_normal_900 },
509 { condensed_italic_100, expanded_italic_900 },
510 { condensed_italic_900, expanded_italic_900 },
511 { expanded_normal_100, expanded_normal_900 },
512 { expanded_normal_900, expanded_normal_900 },
513 { expanded_italic_100, expanded_italic_900 },
514 { expanded_italic_900, expanded_italic_900 },
515 },
516 },
517
518 {
519 { expanded_normal_100,expanded_normal_900 },
520 {
521 { condensed_normal_100, expanded_normal_100 },
522 { condensed_normal_900, expanded_normal_900 },
523 { condensed_italic_100, expanded_normal_100 },
524 { condensed_italic_900, expanded_normal_900 },
525 { expanded_normal_100, expanded_normal_100 },
526 { expanded_normal_900, expanded_normal_900 },
527 { expanded_italic_100, expanded_normal_100 },
528 { expanded_italic_900, expanded_normal_900 },
529 },
530 },
531
532 {
533 { expanded_normal_100 },
534 {
535 { condensed_normal_100, expanded_normal_100 },
536 { condensed_normal_900, expanded_normal_100 },
537 { condensed_italic_100, expanded_normal_100 },
538 { condensed_italic_900, expanded_normal_100 },
539 { expanded_normal_100, expanded_normal_100 },
540 { expanded_normal_900, expanded_normal_100 },
541 { expanded_italic_100, expanded_normal_100 },
542 { expanded_italic_900, expanded_normal_100 },
543 },
544 },
545
546 {
547 { expanded_normal_900 },
548 {
549 { condensed_normal_100, expanded_normal_900 },
550 { condensed_normal_900, expanded_normal_900 },
551 { condensed_italic_100, expanded_normal_900 },
552 { condensed_italic_900, expanded_normal_900 },
553 { expanded_normal_100, expanded_normal_900 },
554 { expanded_normal_900, expanded_normal_900 },
555 { expanded_italic_100, expanded_normal_900 },
556 { expanded_italic_900, expanded_normal_900 },
557 },
558 },
559
560 {
561 { expanded_italic_100,expanded_italic_900 },
562 {
563 { condensed_normal_100, expanded_italic_100 },
564 { condensed_normal_900, expanded_italic_900 },
565 { condensed_italic_100, expanded_italic_100 },
566 { condensed_italic_900, expanded_italic_900 },
567 { expanded_normal_100, expanded_italic_100 },
568 { expanded_normal_900, expanded_italic_900 },
569 { expanded_italic_100, expanded_italic_100 },
570 { expanded_italic_900, expanded_italic_900 },
571 },
572 },
573
574 {
575 { expanded_italic_100 },
576 {
577 { condensed_normal_100, expanded_italic_100 },
578 { condensed_normal_900, expanded_italic_100 },
579 { condensed_italic_100, expanded_italic_100 },
580 { condensed_italic_900, expanded_italic_100 },
581 { expanded_normal_100, expanded_italic_100 },
582 { expanded_normal_900, expanded_italic_100 },
583 { expanded_italic_100, expanded_italic_100 },
584 { expanded_italic_900, expanded_italic_100 },
585 },
586 },
587
588 {
589 { expanded_italic_900 },
590 {
591 { condensed_normal_100, expanded_italic_900 },
592 { condensed_normal_900, expanded_italic_900 },
593 { condensed_italic_100, expanded_italic_900 },
594 { condensed_italic_900, expanded_italic_900 },
595 { expanded_normal_100, expanded_italic_900 },
596 { expanded_normal_900, expanded_italic_900 },
597 { expanded_italic_100, expanded_italic_900 },
598 { expanded_italic_900, expanded_italic_900 },
599 },
600 },
601
602 {
603 { normal_normal_100, normal_normal_900 },
604 {
605 { normal_normal_300, normal_normal_100 },
606 { normal_normal_400, normal_normal_100 },
607 { normal_normal_500, normal_normal_100 },
608 { normal_normal_600, normal_normal_900 },
609 },
610 },
611
612 {
613 { normal_normal_100, normal_normal_400, normal_normal_900 },
614 {
615 { normal_normal_300, normal_normal_100 },
616 { normal_normal_400, normal_normal_400 },
617 { normal_normal_500, normal_normal_400 },
618 { normal_normal_600, normal_normal_900 },
619 },
620 },
621
622 {
623 { normal_normal_100, normal_normal_500, normal_normal_900 },
624 {
625 { normal_normal_300, normal_normal_100 },
626 { normal_normal_400, normal_normal_500 },
627 { normal_normal_500, normal_normal_500 },
628 { normal_normal_600, normal_normal_900 },
629 },
630 },
631
632 {
633 { },
634 {
635 { normal_normal_300, invalidFontStyle },
636 { normal_normal_400, invalidFontStyle },
637 { normal_normal_500, invalidFontStyle },
638 { normal_normal_600, invalidFontStyle },
639 },
640 },
bungemanb4bb7d82016-04-27 10:21:04 -0700641 {
642 { expanded_normal_100,expanded_normal_900,
643 expanded_italic_100,expanded_italic_900,
644 expanded_obliqu_100,expanded_obliqu_900, },
645 {
646 { condensed_normal_100, expanded_normal_100 },
647 { condensed_normal_900, expanded_normal_900 },
648 { condensed_italic_100, expanded_italic_100 },
649 { condensed_italic_900, expanded_italic_900 },
650 { condensed_obliqu_100, expanded_obliqu_100 },
651 { condensed_obliqu_900, expanded_obliqu_900 },
652 { expanded_normal_100, expanded_normal_100 },
653 { expanded_normal_900, expanded_normal_900 },
654 { expanded_italic_100, expanded_italic_100 },
655 { expanded_italic_900, expanded_italic_900 },
656 { expanded_obliqu_100, expanded_obliqu_100 },
657 { expanded_obliqu_900, expanded_obliqu_900 },
658 },
659 },
660 {
661 { expanded_normal_100,expanded_normal_900,
662 expanded_obliqu_100,expanded_obliqu_900, },
663 {
664 { condensed_normal_100, expanded_normal_100 },
665 { condensed_normal_900, expanded_normal_900 },
666 { condensed_italic_100, expanded_obliqu_100 },
667 { condensed_italic_900, expanded_obliqu_900 },
668 { condensed_obliqu_100, expanded_obliqu_100 },
669 { condensed_obliqu_900, expanded_obliqu_900 },
670 { expanded_normal_100, expanded_normal_100 },
671 { expanded_normal_900, expanded_normal_900 },
672 { expanded_italic_100, expanded_obliqu_100 },
673 { expanded_italic_900, expanded_obliqu_900 },
674 { expanded_obliqu_100, expanded_obliqu_100 },
675 { expanded_obliqu_900, expanded_obliqu_900 },
676 },
677 },
678 {
679 { expanded_italic_100,expanded_italic_900,
680 expanded_obliqu_100,expanded_obliqu_900, },
681 {
682 { condensed_normal_100, expanded_obliqu_100 },
683 { condensed_normal_900, expanded_obliqu_900 },
684 { condensed_italic_100, expanded_italic_100 },
685 { condensed_italic_900, expanded_italic_900 },
686 { condensed_obliqu_100, expanded_obliqu_100 },
687 { condensed_obliqu_900, expanded_obliqu_900 },
688 { expanded_normal_100, expanded_obliqu_100 },
689 { expanded_normal_900, expanded_obliqu_900 },
690 { expanded_italic_100, expanded_italic_100 },
691 { expanded_italic_900, expanded_italic_900 },
692 { expanded_obliqu_100, expanded_obliqu_100 },
693 { expanded_obliqu_900, expanded_obliqu_900 },
694 },
695 },
bungeman147ea2f2015-11-12 09:50:08 -0800696 };
697
698 for (StyleSetTest& test : tests) {
Mike Klein6ad99092016-10-26 10:35:22 -0400699 for (const StyleSetTest::Case& testCase : test.cases) {
Hal Canary342b7ac2016-11-04 11:49:42 -0400700 sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern));
bungeman147ea2f2015-11-12 09:50:08 -0800701 if (typeface) {
702 REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult);
703 } else {
704 REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult);
705 }
706 }
707 }
708}
709
reed@google.com66c9f992013-04-11 19:04:34 +0000710DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
reed@google.com83165a52013-04-11 18:31:25 +0000711
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +0000712DEF_TEST(FontMgr, reporter) {
bungeman147ea2f2015-11-12 09:50:08 -0800713 test_matchStyleCSS3(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000714 test_fontiter(reporter, FLAGS_verboseFontMgr);
reed@google.comc1a81eb2013-09-19 18:06:03 +0000715 test_alias_names(reporter);
reed@google.com43c27582014-04-08 15:04:29 +0000716 test_font(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000717}