blob: 4abbd19fb97d4c1140b3bb364852f793d31ee715 [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
Hal Canary209e4b12017-05-04 14:23:55 -04008#include "SkAdvancedTypefaceMetrics.h"
reed@google.com83165a52013-04-11 18:31:25 +00009#include "SkCommandLineFlags.h"
Hal Canary209e4b12017-05-04 14:23:55 -040010#include "SkFont.h"
reed@google.com83165a52013-04-11 18:31:25 +000011#include "SkFontMgr.h"
Hal Canary209e4b12017-05-04 14:23:55 -040012#include "SkPaint.h"
reed@google.com83165a52013-04-11 18:31:25 +000013#include "SkTypeface.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000014#include "Test.h"
reed@google.com83165a52013-04-11 18:31:25 +000015
bungeman147ea2f2015-11-12 09:50:08 -080016#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
bungeman7575bb12017-05-01 13:02:42 -0400117static void test_match(skiatest::Reporter* reporter) {
118 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
119 sk_sp<SkFontStyleSet> styleSet(fm->matchFamily(nullptr));
120 REPORTER_ASSERT(reporter, styleSet);
121}
122
bungeman147ea2f2015-11-12 09:50:08 -0800123static void test_matchStyleCSS3(skiatest::Reporter* reporter) {
bungeman147ea2f2015-11-12 09:50:08 -0800124 static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
125
126 class TestTypeface : public SkTypeface {
127 public:
bungemane3aea102016-07-13 05:16:58 -0700128 TestTypeface(const SkFontStyle& fontStyle) : SkTypeface(fontStyle, false){}
bungeman147ea2f2015-11-12 09:50:08 -0800129 protected:
130 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
Bruce Wang536ad2c2018-06-25 11:37:25 -0400131 sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
132 return sk_ref_sp(this);
133 }
reeda9322c22016-04-12 06:47:05 -0700134 SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
135 const SkDescriptor*) const override {
bungeman147ea2f2015-11-12 09:50:08 -0800136 return nullptr;
137 }
138 void onFilterRec(SkScalerContextRec*) const override { }
Hal Canary209e4b12017-05-04 14:23:55 -0400139 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
140 return nullptr;
141 }
bungeman147ea2f2015-11-12 09:50:08 -0800142 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
143 virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
144 uint16_t glyphs[], int glyphCount) const override {
145 if (glyphs && glyphCount > 0) {
146 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0]));
147 }
148 return 0;
149 }
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400150 int onCountGlyphs() const override { return 0; }
151 int onGetUPEM() const override { return 0; }
bungeman147ea2f2015-11-12 09:50:08 -0800152 class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
153 public:
154 bool next(SkTypeface::LocalizedString*) override { return false; }
155 };
156 void onGetFamilyName(SkString* familyName) const override {
157 familyName->reset();
158 }
159 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
160 return new EmptyLocalizedStrings;
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400161 }
Ben Wagnerfc497342017-02-24 11:15:26 -0500162 int onGetVariationDesignPosition(
163 SkFontArguments::VariationPosition::Coordinate coordinates[],
164 int coordinateCount) const override
165 {
166 return 0;
167 }
bungeman147ea2f2015-11-12 09:50:08 -0800168 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
169 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
170 return 0;
171 }
172 };
173
174 class TestFontStyleSet : public SkFontStyleSet {
175 public:
176 TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {}
177 int count() override { return static_cast<int>(fStyles.size()); }
178 void getStyle(int index, SkFontStyle* style, SkString*) override {
179 if (style) {
180 *style = fStyles[index];
181 }
182 }
183 SkTypeface* createTypeface(int index) override {
184 if (index < 0 || this->count() <= index) {
bungemane3aea102016-07-13 05:16:58 -0700185 return new TestTypeface(invalidFontStyle);
bungeman147ea2f2015-11-12 09:50:08 -0800186 }
bungemane3aea102016-07-13 05:16:58 -0700187 return new TestTypeface(fStyles[index]);
bungeman147ea2f2015-11-12 09:50:08 -0800188 }
189 SkTypeface* matchStyle(const SkFontStyle& pattern) override {
190 return this->matchStyleCSS3(pattern);
191 }
192 private:
193 std::vector<SkFontStyle> fStyles;
194 };
195
196 SkFontStyle condensed_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
197 SkFontStyle condensed_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
198 SkFontStyle condensed_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
199 SkFontStyle condensed_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700200 SkFontStyle condensed_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
201 SkFontStyle condensed_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800202 SkFontStyle expanded_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
203 SkFontStyle expanded_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
204 SkFontStyle expanded_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
205 SkFontStyle expanded_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700206 SkFontStyle expanded_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
207 SkFontStyle expanded_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800208
209 SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800210 SkFontStyle normal_normal_300(SkFontStyle::kLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
211 SkFontStyle normal_normal_400(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
212 SkFontStyle normal_normal_500(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
213 SkFontStyle normal_normal_600(SkFontStyle::kSemiBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800214 SkFontStyle normal_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
215
216 struct StyleSetTest {
217 TestFontStyleSet styleSet;
218 struct Case {
219 SkFontStyle pattern;
220 SkFontStyle expectedResult;
221 };
222 std::vector<Case> cases;
223 } tests[] = {
224 {
225 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900,
226 expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 },
227 {
228 { condensed_normal_100, condensed_normal_100 },
229 { condensed_normal_900, condensed_normal_900 },
230 { condensed_italic_100, condensed_italic_100 },
231 { condensed_italic_900, condensed_italic_900 },
232 { expanded_normal_100, expanded_normal_100 },
233 { expanded_normal_900, expanded_normal_900 },
234 { expanded_italic_100, expanded_italic_100 },
235 { expanded_italic_900, expanded_italic_900 },
236 },
237 },
238
239 {
240 { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 },
241 {
242 { condensed_normal_100, condensed_normal_100 },
243 { condensed_normal_900, condensed_normal_100 },
244 { condensed_italic_100, condensed_italic_100 },
245 { condensed_italic_900, condensed_italic_100 },
246 { expanded_normal_100, expanded_normal_100 },
247 { expanded_normal_900, expanded_normal_100 },
248 { expanded_italic_100, expanded_italic_100 },
249 { expanded_italic_900, expanded_italic_100 },
250 },
251 },
252
253 {
254 { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 },
255 {
256 { condensed_normal_100, condensed_normal_900 },
257 { condensed_normal_900, condensed_normal_900 },
258 { condensed_italic_100, condensed_italic_900 },
259 { condensed_italic_900, condensed_italic_900 },
260 { expanded_normal_100, expanded_normal_900 },
261 { expanded_normal_900, expanded_normal_900 },
262 { expanded_italic_100, expanded_italic_900 },
263 { expanded_italic_900, expanded_italic_900 },
264 },
265 },
266
267 {
268 { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 },
269 {
270 { condensed_normal_100, condensed_normal_100 },
271 { condensed_normal_900, condensed_normal_900 },
272 { condensed_italic_100, condensed_normal_100 },
273 { condensed_italic_900, condensed_normal_900 },
274 { expanded_normal_100, expanded_normal_100 },
275 { expanded_normal_900, expanded_normal_900 },
276 { expanded_italic_100, expanded_normal_100 },
277 { expanded_italic_900, expanded_normal_900 },
278 },
279 },
280
281 {
282 { condensed_normal_100,expanded_normal_100 },
283 {
284 { condensed_normal_100, condensed_normal_100 },
285 { condensed_normal_900, condensed_normal_100 },
286 { condensed_italic_100, condensed_normal_100 },
287 { condensed_italic_900, condensed_normal_100 },
288 { expanded_normal_100, expanded_normal_100 },
289 { expanded_normal_900, expanded_normal_100 },
290 { expanded_italic_100, expanded_normal_100 },
291 { expanded_italic_900, expanded_normal_100 },
292 },
293 },
294
295 {
296 { condensed_normal_900,expanded_normal_900 },
297 {
298 { condensed_normal_100, condensed_normal_900 },
299 { condensed_normal_900, condensed_normal_900 },
300 { condensed_italic_100, condensed_normal_900 },
301 { condensed_italic_900, condensed_normal_900 },
302 { expanded_normal_100, expanded_normal_900 },
303 { expanded_normal_900, expanded_normal_900 },
304 { expanded_italic_100, expanded_normal_900 },
305 { expanded_italic_900, expanded_normal_900 },
306 },
307 },
308
309 {
310 { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 },
311 {
312 { condensed_normal_100, condensed_italic_100 },
313 { condensed_normal_900, condensed_italic_900 },
314 { condensed_italic_100, condensed_italic_100 },
315 { condensed_italic_900, condensed_italic_900 },
316 { expanded_normal_100, expanded_italic_100 },
317 { expanded_normal_900, expanded_italic_900 },
318 { expanded_italic_100, expanded_italic_100 },
319 { expanded_italic_900, expanded_italic_900 },
320 },
321 },
322
323 {
324 { condensed_italic_100,expanded_italic_100 },
325 {
326 { condensed_normal_100, condensed_italic_100 },
327 { condensed_normal_900, condensed_italic_100 },
328 { condensed_italic_100, condensed_italic_100 },
329 { condensed_italic_900, condensed_italic_100 },
330 { expanded_normal_100, expanded_italic_100 },
331 { expanded_normal_900, expanded_italic_100 },
332 { expanded_italic_100, expanded_italic_100 },
333 { expanded_italic_900, expanded_italic_100 },
334 },
335 },
336
337 {
338 { condensed_italic_900,expanded_italic_900 },
339 {
340 { condensed_normal_100, condensed_italic_900 },
341 { condensed_normal_900, condensed_italic_900 },
342 { condensed_italic_100, condensed_italic_900 },
343 { condensed_italic_900, condensed_italic_900 },
344 { expanded_normal_100, expanded_italic_900 },
345 { expanded_normal_900, expanded_italic_900 },
346 { expanded_italic_100, expanded_italic_900 },
347 { expanded_italic_900, expanded_italic_900 },
348 },
349 },
350
351 {
352 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 },
353 {
354 { condensed_normal_100, condensed_normal_100 },
355 { condensed_normal_900, condensed_normal_900 },
356 { condensed_italic_100, condensed_italic_100 },
357 { condensed_italic_900, condensed_italic_900 },
358 { expanded_normal_100, condensed_normal_100 },
359 { expanded_normal_900, condensed_normal_900 },
360 { expanded_italic_100, condensed_italic_100 },
361 { expanded_italic_900, condensed_italic_900 },
362 },
363 },
364
365 {
366 { condensed_normal_100,condensed_italic_100 },
367 {
368 { condensed_normal_100, condensed_normal_100 },
369 { condensed_normal_900, condensed_normal_100 },
370 { condensed_italic_100, condensed_italic_100 },
371 { condensed_italic_900, condensed_italic_100 },
372 { expanded_normal_100, condensed_normal_100 },
373 { expanded_normal_900, condensed_normal_100 },
374 { expanded_italic_100, condensed_italic_100 },
375 { expanded_italic_900, condensed_italic_100 },
376 },
377 },
378
379 {
380 { condensed_normal_900,condensed_italic_900 },
381 {
382 { condensed_normal_100, condensed_normal_900 },
383 { condensed_normal_900, condensed_normal_900 },
384 { condensed_italic_100, condensed_italic_900 },
385 { condensed_italic_900, condensed_italic_900 },
386 { expanded_normal_100, condensed_normal_900 },
387 { expanded_normal_900, condensed_normal_900 },
388 { expanded_italic_100, condensed_italic_900 },
389 { expanded_italic_900, condensed_italic_900 },
390 },
391 },
392
393 {
394 { condensed_normal_100,condensed_normal_900 },
395 {
396 { condensed_normal_100, condensed_normal_100 },
397 { condensed_normal_900, condensed_normal_900 },
398 { condensed_italic_100, condensed_normal_100 },
399 { condensed_italic_900, condensed_normal_900 },
400 { expanded_normal_100, condensed_normal_100 },
401 { expanded_normal_900, condensed_normal_900 },
402 { expanded_italic_100, condensed_normal_100 },
403 { expanded_italic_900, condensed_normal_900 },
404 },
405 },
406
407 {
408 { condensed_normal_100 },
409 {
410 { condensed_normal_100, condensed_normal_100 },
411 { condensed_normal_900, condensed_normal_100 },
412 { condensed_italic_100, condensed_normal_100 },
413 { condensed_italic_900, condensed_normal_100 },
414 { expanded_normal_100, condensed_normal_100 },
415 { expanded_normal_900, condensed_normal_100 },
416 { expanded_italic_100, condensed_normal_100 },
417 { expanded_italic_900, condensed_normal_100 },
418 },
419 },
420
421 {
422 { condensed_normal_900 },
423 {
424 { condensed_normal_100, condensed_normal_900 },
425 { condensed_normal_900, condensed_normal_900 },
426 { condensed_italic_100, condensed_normal_900 },
427 { condensed_italic_900, condensed_normal_900 },
428 { expanded_normal_100, condensed_normal_900 },
429 { expanded_normal_900, condensed_normal_900 },
430 { expanded_italic_100, condensed_normal_900 },
431 { expanded_italic_900, condensed_normal_900 },
432 },
433 },
434
435 {
436 { condensed_italic_100,condensed_italic_900 },
437 {
438 { condensed_normal_100, condensed_italic_100 },
439 { condensed_normal_900, condensed_italic_900 },
440 { condensed_italic_100, condensed_italic_100 },
441 { condensed_italic_900, condensed_italic_900 },
442 { expanded_normal_100, condensed_italic_100 },
443 { expanded_normal_900, condensed_italic_900 },
444 { expanded_italic_100, condensed_italic_100 },
445 { expanded_italic_900, condensed_italic_900 },
446 },
447 },
448
449 {
450 { condensed_italic_100 },
451 {
452 { condensed_normal_100, condensed_italic_100 },
453 { condensed_normal_900, condensed_italic_100 },
454 { condensed_italic_100, condensed_italic_100 },
455 { condensed_italic_900, condensed_italic_100 },
456 { expanded_normal_100, condensed_italic_100 },
457 { expanded_normal_900, condensed_italic_100 },
458 { expanded_italic_100, condensed_italic_100 },
459 { expanded_italic_900, condensed_italic_100 },
460 },
461 },
462
463 {
464 { condensed_italic_900 },
465 {
466 { condensed_normal_100, condensed_italic_900 },
467 { condensed_normal_900, condensed_italic_900 },
468 { condensed_italic_100, condensed_italic_900 },
469 { condensed_italic_900, condensed_italic_900 },
470 { expanded_normal_100, condensed_italic_900 },
471 { expanded_normal_900, condensed_italic_900 },
472 { expanded_italic_100, condensed_italic_900 },
473 { expanded_italic_900, condensed_italic_900 },
474 },
475 },
476
477 {
bungemanb4bb7d82016-04-27 10:21:04 -0700478 { expanded_normal_100,expanded_normal_900,
479 expanded_italic_100,expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800480 {
481 { condensed_normal_100, expanded_normal_100 },
482 { condensed_normal_900, expanded_normal_900 },
483 { condensed_italic_100, expanded_italic_100 },
484 { condensed_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700485 { condensed_obliqu_100, expanded_italic_100 },
486 { condensed_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800487 { expanded_normal_100, expanded_normal_100 },
488 { expanded_normal_900, expanded_normal_900 },
489 { expanded_italic_100, expanded_italic_100 },
490 { expanded_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700491 { expanded_obliqu_100, expanded_italic_100 },
492 { expanded_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800493 },
494 },
495
496 {
497 { expanded_normal_100,expanded_italic_100 },
498 {
499 { condensed_normal_100, expanded_normal_100 },
500 { condensed_normal_900, expanded_normal_100 },
501 { condensed_italic_100, expanded_italic_100 },
502 { condensed_italic_900, expanded_italic_100 },
503 { expanded_normal_100, expanded_normal_100 },
504 { expanded_normal_900, expanded_normal_100 },
505 { expanded_italic_100, expanded_italic_100 },
506 { expanded_italic_900, expanded_italic_100 },
507 },
508 },
509
510 {
511 { expanded_normal_900,expanded_italic_900 },
512 {
513 { condensed_normal_100, expanded_normal_900 },
514 { condensed_normal_900, expanded_normal_900 },
515 { condensed_italic_100, expanded_italic_900 },
516 { condensed_italic_900, expanded_italic_900 },
517 { expanded_normal_100, expanded_normal_900 },
518 { expanded_normal_900, expanded_normal_900 },
519 { expanded_italic_100, expanded_italic_900 },
520 { expanded_italic_900, expanded_italic_900 },
521 },
522 },
523
524 {
525 { expanded_normal_100,expanded_normal_900 },
526 {
527 { condensed_normal_100, expanded_normal_100 },
528 { condensed_normal_900, expanded_normal_900 },
529 { condensed_italic_100, expanded_normal_100 },
530 { condensed_italic_900, expanded_normal_900 },
531 { expanded_normal_100, expanded_normal_100 },
532 { expanded_normal_900, expanded_normal_900 },
533 { expanded_italic_100, expanded_normal_100 },
534 { expanded_italic_900, expanded_normal_900 },
535 },
536 },
537
538 {
539 { expanded_normal_100 },
540 {
541 { condensed_normal_100, expanded_normal_100 },
542 { condensed_normal_900, expanded_normal_100 },
543 { condensed_italic_100, expanded_normal_100 },
544 { condensed_italic_900, expanded_normal_100 },
545 { expanded_normal_100, expanded_normal_100 },
546 { expanded_normal_900, expanded_normal_100 },
547 { expanded_italic_100, expanded_normal_100 },
548 { expanded_italic_900, expanded_normal_100 },
549 },
550 },
551
552 {
553 { expanded_normal_900 },
554 {
555 { condensed_normal_100, expanded_normal_900 },
556 { condensed_normal_900, expanded_normal_900 },
557 { condensed_italic_100, expanded_normal_900 },
558 { condensed_italic_900, expanded_normal_900 },
559 { expanded_normal_100, expanded_normal_900 },
560 { expanded_normal_900, expanded_normal_900 },
561 { expanded_italic_100, expanded_normal_900 },
562 { expanded_italic_900, expanded_normal_900 },
563 },
564 },
565
566 {
567 { expanded_italic_100,expanded_italic_900 },
568 {
569 { condensed_normal_100, expanded_italic_100 },
570 { condensed_normal_900, expanded_italic_900 },
571 { condensed_italic_100, expanded_italic_100 },
572 { condensed_italic_900, expanded_italic_900 },
573 { expanded_normal_100, expanded_italic_100 },
574 { expanded_normal_900, expanded_italic_900 },
575 { expanded_italic_100, expanded_italic_100 },
576 { expanded_italic_900, expanded_italic_900 },
577 },
578 },
579
580 {
581 { expanded_italic_100 },
582 {
583 { condensed_normal_100, expanded_italic_100 },
584 { condensed_normal_900, expanded_italic_100 },
585 { condensed_italic_100, expanded_italic_100 },
586 { condensed_italic_900, expanded_italic_100 },
587 { expanded_normal_100, expanded_italic_100 },
588 { expanded_normal_900, expanded_italic_100 },
589 { expanded_italic_100, expanded_italic_100 },
590 { expanded_italic_900, expanded_italic_100 },
591 },
592 },
593
594 {
595 { expanded_italic_900 },
596 {
597 { condensed_normal_100, expanded_italic_900 },
598 { condensed_normal_900, expanded_italic_900 },
599 { condensed_italic_100, expanded_italic_900 },
600 { condensed_italic_900, expanded_italic_900 },
601 { expanded_normal_100, expanded_italic_900 },
602 { expanded_normal_900, expanded_italic_900 },
603 { expanded_italic_100, expanded_italic_900 },
604 { expanded_italic_900, expanded_italic_900 },
605 },
606 },
607
608 {
609 { normal_normal_100, normal_normal_900 },
610 {
611 { normal_normal_300, normal_normal_100 },
612 { normal_normal_400, normal_normal_100 },
613 { normal_normal_500, normal_normal_100 },
614 { normal_normal_600, normal_normal_900 },
615 },
616 },
617
618 {
619 { normal_normal_100, normal_normal_400, normal_normal_900 },
620 {
621 { normal_normal_300, normal_normal_100 },
622 { normal_normal_400, normal_normal_400 },
623 { normal_normal_500, normal_normal_400 },
624 { normal_normal_600, normal_normal_900 },
625 },
626 },
627
628 {
629 { normal_normal_100, normal_normal_500, normal_normal_900 },
630 {
631 { normal_normal_300, normal_normal_100 },
632 { normal_normal_400, normal_normal_500 },
633 { normal_normal_500, normal_normal_500 },
634 { normal_normal_600, normal_normal_900 },
635 },
636 },
637
638 {
639 { },
640 {
641 { normal_normal_300, invalidFontStyle },
642 { normal_normal_400, invalidFontStyle },
643 { normal_normal_500, invalidFontStyle },
644 { normal_normal_600, invalidFontStyle },
645 },
646 },
bungemanb4bb7d82016-04-27 10:21:04 -0700647 {
648 { expanded_normal_100,expanded_normal_900,
649 expanded_italic_100,expanded_italic_900,
650 expanded_obliqu_100,expanded_obliqu_900, },
651 {
652 { condensed_normal_100, expanded_normal_100 },
653 { condensed_normal_900, expanded_normal_900 },
654 { condensed_italic_100, expanded_italic_100 },
655 { condensed_italic_900, expanded_italic_900 },
656 { condensed_obliqu_100, expanded_obliqu_100 },
657 { condensed_obliqu_900, expanded_obliqu_900 },
658 { expanded_normal_100, expanded_normal_100 },
659 { expanded_normal_900, expanded_normal_900 },
660 { expanded_italic_100, expanded_italic_100 },
661 { expanded_italic_900, expanded_italic_900 },
662 { expanded_obliqu_100, expanded_obliqu_100 },
663 { expanded_obliqu_900, expanded_obliqu_900 },
664 },
665 },
666 {
667 { expanded_normal_100,expanded_normal_900,
668 expanded_obliqu_100,expanded_obliqu_900, },
669 {
670 { condensed_normal_100, expanded_normal_100 },
671 { condensed_normal_900, expanded_normal_900 },
672 { condensed_italic_100, expanded_obliqu_100 },
673 { condensed_italic_900, expanded_obliqu_900 },
674 { condensed_obliqu_100, expanded_obliqu_100 },
675 { condensed_obliqu_900, expanded_obliqu_900 },
676 { expanded_normal_100, expanded_normal_100 },
677 { expanded_normal_900, expanded_normal_900 },
678 { expanded_italic_100, expanded_obliqu_100 },
679 { expanded_italic_900, expanded_obliqu_900 },
680 { expanded_obliqu_100, expanded_obliqu_100 },
681 { expanded_obliqu_900, expanded_obliqu_900 },
682 },
683 },
684 {
685 { expanded_italic_100,expanded_italic_900,
686 expanded_obliqu_100,expanded_obliqu_900, },
687 {
688 { condensed_normal_100, expanded_obliqu_100 },
689 { condensed_normal_900, expanded_obliqu_900 },
690 { condensed_italic_100, expanded_italic_100 },
691 { condensed_italic_900, expanded_italic_900 },
692 { condensed_obliqu_100, expanded_obliqu_100 },
693 { condensed_obliqu_900, expanded_obliqu_900 },
694 { expanded_normal_100, expanded_obliqu_100 },
695 { expanded_normal_900, expanded_obliqu_900 },
696 { expanded_italic_100, expanded_italic_100 },
697 { expanded_italic_900, expanded_italic_900 },
698 { expanded_obliqu_100, expanded_obliqu_100 },
699 { expanded_obliqu_900, expanded_obliqu_900 },
700 },
701 },
bungeman147ea2f2015-11-12 09:50:08 -0800702 };
703
704 for (StyleSetTest& test : tests) {
Mike Klein6ad99092016-10-26 10:35:22 -0400705 for (const StyleSetTest::Case& testCase : test.cases) {
Hal Canary342b7ac2016-11-04 11:49:42 -0400706 sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern));
bungeman147ea2f2015-11-12 09:50:08 -0800707 if (typeface) {
708 REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult);
709 } else {
710 REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult);
711 }
712 }
713 }
714}
715
reed@google.com66c9f992013-04-11 19:04:34 +0000716DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
reed@google.com83165a52013-04-11 18:31:25 +0000717
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +0000718DEF_TEST(FontMgr, reporter) {
bungeman7575bb12017-05-01 13:02:42 -0400719 test_match(reporter);
bungeman147ea2f2015-11-12 09:50:08 -0800720 test_matchStyleCSS3(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000721 test_fontiter(reporter, FLAGS_verboseFontMgr);
reed@google.comc1a81eb2013-09-19 18:06:03 +0000722 test_alias_names(reporter);
reed@google.com43c27582014-04-08 15:04:29 +0000723 test_font(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000724}