blob: 1ef97ee6ffbc77d228aecc92b81b0951836e83e3 [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;
Mike Reedfe4fc142018-10-22 14:24:07 -040022 SkFont font(nullptr, 24, flags);
skia.committer@gmail.come1d94432014-04-09 03:04:11 +000023
Mike Reedfe4fc142018-10-22 14:24:07 -040024 REPORTER_ASSERT(reporter, font.getTypeface());
25 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
Mike Reedfe4fc142018-10-22 14:24:07 -040032 int count = font.textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, SK_ARRAY_COUNT(glyphs));
reed@google.com43c27582014-04-08 15:04:29 +000033
34 REPORTER_ASSERT(reporter, 5 == count);
35 for (int i = 0; i < count; ++i) {
36 REPORTER_ASSERT(reporter, 0 != glyphs[i]);
37 }
38 REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
39 REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
skia.committer@gmail.come1d94432014-04-09 03:04:11 +000040
Mike Reedfe4fc142018-10-22 14:24:07 -040041 const SkFont newFont(font.makeWithSize(36));
42 REPORTER_ASSERT(reporter, font.getTypeface() == newFont.getTypeface());
43 REPORTER_ASSERT(reporter, 36 == newFont.getSize()); // double check we haven't changed
44 REPORTER_ASSERT(reporter, 24 == font.getSize()); // double check we haven't changed
reed@google.com43c27582014-04-08 15:04:29 +000045
46 SkPaint paint;
47 paint.setTextSize(18);
Mike Reedfe4fc142018-10-22 14:24:07 -040048 font = SkFont::LEGACY_ExtractFromPaint(paint);
49 REPORTER_ASSERT(reporter, font.getSize() == paint.getTextSize());
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:
126 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 { }
139 virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
140 uint16_t glyphs[], int glyphCount) const override {
141 if (glyphs && glyphCount > 0) {
142 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0]));
143 }
144 return 0;
145 }
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400146 int onCountGlyphs() const override { return 0; }
147 int onGetUPEM() const override { return 0; }
bungeman147ea2f2015-11-12 09:50:08 -0800148 class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
149 public:
150 bool next(SkTypeface::LocalizedString*) override { return false; }
151 };
152 void onGetFamilyName(SkString* familyName) const override {
153 familyName->reset();
154 }
155 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
156 return new EmptyLocalizedStrings;
Mike Kleinfc6c37b2016-09-27 09:34:10 -0400157 }
Ben Wagnerfc497342017-02-24 11:15:26 -0500158 int onGetVariationDesignPosition(
159 SkFontArguments::VariationPosition::Coordinate coordinates[],
160 int coordinateCount) const override
161 {
162 return 0;
163 }
bungeman147ea2f2015-11-12 09:50:08 -0800164 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
165 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
166 return 0;
167 }
168 };
169
170 class TestFontStyleSet : public SkFontStyleSet {
171 public:
172 TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {}
173 int count() override { return static_cast<int>(fStyles.size()); }
174 void getStyle(int index, SkFontStyle* style, SkString*) override {
175 if (style) {
176 *style = fStyles[index];
177 }
178 }
179 SkTypeface* createTypeface(int index) override {
180 if (index < 0 || this->count() <= index) {
bungemane3aea102016-07-13 05:16:58 -0700181 return new TestTypeface(invalidFontStyle);
bungeman147ea2f2015-11-12 09:50:08 -0800182 }
bungemane3aea102016-07-13 05:16:58 -0700183 return new TestTypeface(fStyles[index]);
bungeman147ea2f2015-11-12 09:50:08 -0800184 }
185 SkTypeface* matchStyle(const SkFontStyle& pattern) override {
186 return this->matchStyleCSS3(pattern);
187 }
188 private:
189 std::vector<SkFontStyle> fStyles;
190 };
191
192 SkFontStyle condensed_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
193 SkFontStyle condensed_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant);
194 SkFontStyle condensed_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
195 SkFontStyle condensed_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700196 SkFontStyle condensed_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
197 SkFontStyle condensed_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800198 SkFontStyle expanded_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
199 SkFontStyle expanded_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant);
200 SkFontStyle expanded_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
201 SkFontStyle expanded_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant);
bungemanb4bb7d82016-04-27 10:21:04 -0700202 SkFontStyle expanded_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
203 SkFontStyle expanded_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800204
205 SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800206 SkFontStyle normal_normal_300(SkFontStyle::kLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
207 SkFontStyle normal_normal_400(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
208 SkFontStyle normal_normal_500(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
209 SkFontStyle normal_normal_600(SkFontStyle::kSemiBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
bungeman147ea2f2015-11-12 09:50:08 -0800210 SkFontStyle normal_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
211
212 struct StyleSetTest {
213 TestFontStyleSet styleSet;
214 struct Case {
215 SkFontStyle pattern;
216 SkFontStyle expectedResult;
217 };
218 std::vector<Case> cases;
219 } tests[] = {
220 {
221 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900,
222 expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 },
223 {
224 { condensed_normal_100, condensed_normal_100 },
225 { condensed_normal_900, condensed_normal_900 },
226 { condensed_italic_100, condensed_italic_100 },
227 { condensed_italic_900, condensed_italic_900 },
228 { expanded_normal_100, expanded_normal_100 },
229 { expanded_normal_900, expanded_normal_900 },
230 { expanded_italic_100, expanded_italic_100 },
231 { expanded_italic_900, expanded_italic_900 },
232 },
233 },
234
235 {
236 { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 },
237 {
238 { condensed_normal_100, condensed_normal_100 },
239 { condensed_normal_900, condensed_normal_100 },
240 { condensed_italic_100, condensed_italic_100 },
241 { condensed_italic_900, condensed_italic_100 },
242 { expanded_normal_100, expanded_normal_100 },
243 { expanded_normal_900, expanded_normal_100 },
244 { expanded_italic_100, expanded_italic_100 },
245 { expanded_italic_900, expanded_italic_100 },
246 },
247 },
248
249 {
250 { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 },
251 {
252 { condensed_normal_100, condensed_normal_900 },
253 { condensed_normal_900, condensed_normal_900 },
254 { condensed_italic_100, condensed_italic_900 },
255 { condensed_italic_900, condensed_italic_900 },
256 { expanded_normal_100, expanded_normal_900 },
257 { expanded_normal_900, expanded_normal_900 },
258 { expanded_italic_100, expanded_italic_900 },
259 { expanded_italic_900, expanded_italic_900 },
260 },
261 },
262
263 {
264 { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 },
265 {
266 { condensed_normal_100, condensed_normal_100 },
267 { condensed_normal_900, condensed_normal_900 },
268 { condensed_italic_100, condensed_normal_100 },
269 { condensed_italic_900, condensed_normal_900 },
270 { expanded_normal_100, expanded_normal_100 },
271 { expanded_normal_900, expanded_normal_900 },
272 { expanded_italic_100, expanded_normal_100 },
273 { expanded_italic_900, expanded_normal_900 },
274 },
275 },
276
277 {
278 { condensed_normal_100,expanded_normal_100 },
279 {
280 { condensed_normal_100, condensed_normal_100 },
281 { condensed_normal_900, condensed_normal_100 },
282 { condensed_italic_100, condensed_normal_100 },
283 { condensed_italic_900, condensed_normal_100 },
284 { expanded_normal_100, expanded_normal_100 },
285 { expanded_normal_900, expanded_normal_100 },
286 { expanded_italic_100, expanded_normal_100 },
287 { expanded_italic_900, expanded_normal_100 },
288 },
289 },
290
291 {
292 { condensed_normal_900,expanded_normal_900 },
293 {
294 { condensed_normal_100, condensed_normal_900 },
295 { condensed_normal_900, condensed_normal_900 },
296 { condensed_italic_100, condensed_normal_900 },
297 { condensed_italic_900, condensed_normal_900 },
298 { expanded_normal_100, expanded_normal_900 },
299 { expanded_normal_900, expanded_normal_900 },
300 { expanded_italic_100, expanded_normal_900 },
301 { expanded_italic_900, expanded_normal_900 },
302 },
303 },
304
305 {
306 { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 },
307 {
308 { condensed_normal_100, condensed_italic_100 },
309 { condensed_normal_900, condensed_italic_900 },
310 { condensed_italic_100, condensed_italic_100 },
311 { condensed_italic_900, condensed_italic_900 },
312 { expanded_normal_100, expanded_italic_100 },
313 { expanded_normal_900, expanded_italic_900 },
314 { expanded_italic_100, expanded_italic_100 },
315 { expanded_italic_900, expanded_italic_900 },
316 },
317 },
318
319 {
320 { condensed_italic_100,expanded_italic_100 },
321 {
322 { condensed_normal_100, condensed_italic_100 },
323 { condensed_normal_900, condensed_italic_100 },
324 { condensed_italic_100, condensed_italic_100 },
325 { condensed_italic_900, condensed_italic_100 },
326 { expanded_normal_100, expanded_italic_100 },
327 { expanded_normal_900, expanded_italic_100 },
328 { expanded_italic_100, expanded_italic_100 },
329 { expanded_italic_900, expanded_italic_100 },
330 },
331 },
332
333 {
334 { condensed_italic_900,expanded_italic_900 },
335 {
336 { condensed_normal_100, condensed_italic_900 },
337 { condensed_normal_900, condensed_italic_900 },
338 { condensed_italic_100, condensed_italic_900 },
339 { condensed_italic_900, condensed_italic_900 },
340 { expanded_normal_100, expanded_italic_900 },
341 { expanded_normal_900, expanded_italic_900 },
342 { expanded_italic_100, expanded_italic_900 },
343 { expanded_italic_900, expanded_italic_900 },
344 },
345 },
346
347 {
348 { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 },
349 {
350 { condensed_normal_100, condensed_normal_100 },
351 { condensed_normal_900, condensed_normal_900 },
352 { condensed_italic_100, condensed_italic_100 },
353 { condensed_italic_900, condensed_italic_900 },
354 { expanded_normal_100, condensed_normal_100 },
355 { expanded_normal_900, condensed_normal_900 },
356 { expanded_italic_100, condensed_italic_100 },
357 { expanded_italic_900, condensed_italic_900 },
358 },
359 },
360
361 {
362 { condensed_normal_100,condensed_italic_100 },
363 {
364 { condensed_normal_100, condensed_normal_100 },
365 { condensed_normal_900, condensed_normal_100 },
366 { condensed_italic_100, condensed_italic_100 },
367 { condensed_italic_900, condensed_italic_100 },
368 { expanded_normal_100, condensed_normal_100 },
369 { expanded_normal_900, condensed_normal_100 },
370 { expanded_italic_100, condensed_italic_100 },
371 { expanded_italic_900, condensed_italic_100 },
372 },
373 },
374
375 {
376 { condensed_normal_900,condensed_italic_900 },
377 {
378 { condensed_normal_100, condensed_normal_900 },
379 { condensed_normal_900, condensed_normal_900 },
380 { condensed_italic_100, condensed_italic_900 },
381 { condensed_italic_900, condensed_italic_900 },
382 { expanded_normal_100, condensed_normal_900 },
383 { expanded_normal_900, condensed_normal_900 },
384 { expanded_italic_100, condensed_italic_900 },
385 { expanded_italic_900, condensed_italic_900 },
386 },
387 },
388
389 {
390 { condensed_normal_100,condensed_normal_900 },
391 {
392 { condensed_normal_100, condensed_normal_100 },
393 { condensed_normal_900, condensed_normal_900 },
394 { condensed_italic_100, condensed_normal_100 },
395 { condensed_italic_900, condensed_normal_900 },
396 { expanded_normal_100, condensed_normal_100 },
397 { expanded_normal_900, condensed_normal_900 },
398 { expanded_italic_100, condensed_normal_100 },
399 { expanded_italic_900, condensed_normal_900 },
400 },
401 },
402
403 {
404 { condensed_normal_100 },
405 {
406 { condensed_normal_100, condensed_normal_100 },
407 { condensed_normal_900, condensed_normal_100 },
408 { condensed_italic_100, condensed_normal_100 },
409 { condensed_italic_900, condensed_normal_100 },
410 { expanded_normal_100, condensed_normal_100 },
411 { expanded_normal_900, condensed_normal_100 },
412 { expanded_italic_100, condensed_normal_100 },
413 { expanded_italic_900, condensed_normal_100 },
414 },
415 },
416
417 {
418 { condensed_normal_900 },
419 {
420 { condensed_normal_100, condensed_normal_900 },
421 { condensed_normal_900, condensed_normal_900 },
422 { condensed_italic_100, condensed_normal_900 },
423 { condensed_italic_900, condensed_normal_900 },
424 { expanded_normal_100, condensed_normal_900 },
425 { expanded_normal_900, condensed_normal_900 },
426 { expanded_italic_100, condensed_normal_900 },
427 { expanded_italic_900, condensed_normal_900 },
428 },
429 },
430
431 {
432 { condensed_italic_100,condensed_italic_900 },
433 {
434 { condensed_normal_100, condensed_italic_100 },
435 { condensed_normal_900, condensed_italic_900 },
436 { condensed_italic_100, condensed_italic_100 },
437 { condensed_italic_900, condensed_italic_900 },
438 { expanded_normal_100, condensed_italic_100 },
439 { expanded_normal_900, condensed_italic_900 },
440 { expanded_italic_100, condensed_italic_100 },
441 { expanded_italic_900, condensed_italic_900 },
442 },
443 },
444
445 {
446 { condensed_italic_100 },
447 {
448 { condensed_normal_100, condensed_italic_100 },
449 { condensed_normal_900, condensed_italic_100 },
450 { condensed_italic_100, condensed_italic_100 },
451 { condensed_italic_900, condensed_italic_100 },
452 { expanded_normal_100, condensed_italic_100 },
453 { expanded_normal_900, condensed_italic_100 },
454 { expanded_italic_100, condensed_italic_100 },
455 { expanded_italic_900, condensed_italic_100 },
456 },
457 },
458
459 {
460 { condensed_italic_900 },
461 {
462 { condensed_normal_100, condensed_italic_900 },
463 { condensed_normal_900, condensed_italic_900 },
464 { condensed_italic_100, condensed_italic_900 },
465 { condensed_italic_900, condensed_italic_900 },
466 { expanded_normal_100, condensed_italic_900 },
467 { expanded_normal_900, condensed_italic_900 },
468 { expanded_italic_100, condensed_italic_900 },
469 { expanded_italic_900, condensed_italic_900 },
470 },
471 },
472
473 {
bungemanb4bb7d82016-04-27 10:21:04 -0700474 { expanded_normal_100,expanded_normal_900,
475 expanded_italic_100,expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800476 {
477 { condensed_normal_100, expanded_normal_100 },
478 { condensed_normal_900, expanded_normal_900 },
479 { condensed_italic_100, expanded_italic_100 },
480 { condensed_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700481 { condensed_obliqu_100, expanded_italic_100 },
482 { condensed_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800483 { expanded_normal_100, expanded_normal_100 },
484 { expanded_normal_900, expanded_normal_900 },
485 { expanded_italic_100, expanded_italic_100 },
486 { expanded_italic_900, expanded_italic_900 },
bungemanb4bb7d82016-04-27 10:21:04 -0700487 { expanded_obliqu_100, expanded_italic_100 },
488 { expanded_obliqu_900, expanded_italic_900 },
bungeman147ea2f2015-11-12 09:50:08 -0800489 },
490 },
491
492 {
493 { expanded_normal_100,expanded_italic_100 },
494 {
495 { condensed_normal_100, expanded_normal_100 },
496 { condensed_normal_900, expanded_normal_100 },
497 { condensed_italic_100, expanded_italic_100 },
498 { condensed_italic_900, expanded_italic_100 },
499 { expanded_normal_100, expanded_normal_100 },
500 { expanded_normal_900, expanded_normal_100 },
501 { expanded_italic_100, expanded_italic_100 },
502 { expanded_italic_900, expanded_italic_100 },
503 },
504 },
505
506 {
507 { expanded_normal_900,expanded_italic_900 },
508 {
509 { condensed_normal_100, expanded_normal_900 },
510 { condensed_normal_900, expanded_normal_900 },
511 { condensed_italic_100, expanded_italic_900 },
512 { condensed_italic_900, expanded_italic_900 },
513 { expanded_normal_100, expanded_normal_900 },
514 { expanded_normal_900, expanded_normal_900 },
515 { expanded_italic_100, expanded_italic_900 },
516 { expanded_italic_900, expanded_italic_900 },
517 },
518 },
519
520 {
521 { expanded_normal_100,expanded_normal_900 },
522 {
523 { condensed_normal_100, expanded_normal_100 },
524 { condensed_normal_900, expanded_normal_900 },
525 { condensed_italic_100, expanded_normal_100 },
526 { condensed_italic_900, expanded_normal_900 },
527 { expanded_normal_100, expanded_normal_100 },
528 { expanded_normal_900, expanded_normal_900 },
529 { expanded_italic_100, expanded_normal_100 },
530 { expanded_italic_900, expanded_normal_900 },
531 },
532 },
533
534 {
535 { expanded_normal_100 },
536 {
537 { condensed_normal_100, expanded_normal_100 },
538 { condensed_normal_900, expanded_normal_100 },
539 { condensed_italic_100, expanded_normal_100 },
540 { condensed_italic_900, expanded_normal_100 },
541 { expanded_normal_100, expanded_normal_100 },
542 { expanded_normal_900, expanded_normal_100 },
543 { expanded_italic_100, expanded_normal_100 },
544 { expanded_italic_900, expanded_normal_100 },
545 },
546 },
547
548 {
549 { expanded_normal_900 },
550 {
551 { condensed_normal_100, expanded_normal_900 },
552 { condensed_normal_900, expanded_normal_900 },
553 { condensed_italic_100, expanded_normal_900 },
554 { condensed_italic_900, expanded_normal_900 },
555 { expanded_normal_100, expanded_normal_900 },
556 { expanded_normal_900, expanded_normal_900 },
557 { expanded_italic_100, expanded_normal_900 },
558 { expanded_italic_900, expanded_normal_900 },
559 },
560 },
561
562 {
563 { expanded_italic_100,expanded_italic_900 },
564 {
565 { condensed_normal_100, expanded_italic_100 },
566 { condensed_normal_900, expanded_italic_900 },
567 { condensed_italic_100, expanded_italic_100 },
568 { condensed_italic_900, expanded_italic_900 },
569 { expanded_normal_100, expanded_italic_100 },
570 { expanded_normal_900, expanded_italic_900 },
571 { expanded_italic_100, expanded_italic_100 },
572 { expanded_italic_900, expanded_italic_900 },
573 },
574 },
575
576 {
577 { expanded_italic_100 },
578 {
579 { condensed_normal_100, expanded_italic_100 },
580 { condensed_normal_900, expanded_italic_100 },
581 { condensed_italic_100, expanded_italic_100 },
582 { condensed_italic_900, expanded_italic_100 },
583 { expanded_normal_100, expanded_italic_100 },
584 { expanded_normal_900, expanded_italic_100 },
585 { expanded_italic_100, expanded_italic_100 },
586 { expanded_italic_900, expanded_italic_100 },
587 },
588 },
589
590 {
591 { expanded_italic_900 },
592 {
593 { condensed_normal_100, expanded_italic_900 },
594 { condensed_normal_900, expanded_italic_900 },
595 { condensed_italic_100, expanded_italic_900 },
596 { condensed_italic_900, expanded_italic_900 },
597 { expanded_normal_100, expanded_italic_900 },
598 { expanded_normal_900, expanded_italic_900 },
599 { expanded_italic_100, expanded_italic_900 },
600 { expanded_italic_900, expanded_italic_900 },
601 },
602 },
603
604 {
605 { normal_normal_100, normal_normal_900 },
606 {
607 { normal_normal_300, normal_normal_100 },
608 { normal_normal_400, normal_normal_100 },
609 { normal_normal_500, normal_normal_100 },
610 { normal_normal_600, normal_normal_900 },
611 },
612 },
613
614 {
615 { normal_normal_100, normal_normal_400, normal_normal_900 },
616 {
617 { normal_normal_300, normal_normal_100 },
618 { normal_normal_400, normal_normal_400 },
619 { normal_normal_500, normal_normal_400 },
620 { normal_normal_600, normal_normal_900 },
621 },
622 },
623
624 {
625 { normal_normal_100, normal_normal_500, normal_normal_900 },
626 {
627 { normal_normal_300, normal_normal_100 },
628 { normal_normal_400, normal_normal_500 },
629 { normal_normal_500, normal_normal_500 },
630 { normal_normal_600, normal_normal_900 },
631 },
632 },
633
634 {
635 { },
636 {
637 { normal_normal_300, invalidFontStyle },
638 { normal_normal_400, invalidFontStyle },
639 { normal_normal_500, invalidFontStyle },
640 { normal_normal_600, invalidFontStyle },
641 },
642 },
bungemanb4bb7d82016-04-27 10:21:04 -0700643 {
644 { expanded_normal_100,expanded_normal_900,
645 expanded_italic_100,expanded_italic_900,
646 expanded_obliqu_100,expanded_obliqu_900, },
647 {
648 { condensed_normal_100, expanded_normal_100 },
649 { condensed_normal_900, expanded_normal_900 },
650 { condensed_italic_100, expanded_italic_100 },
651 { condensed_italic_900, expanded_italic_900 },
652 { condensed_obliqu_100, expanded_obliqu_100 },
653 { condensed_obliqu_900, expanded_obliqu_900 },
654 { expanded_normal_100, expanded_normal_100 },
655 { expanded_normal_900, expanded_normal_900 },
656 { expanded_italic_100, expanded_italic_100 },
657 { expanded_italic_900, expanded_italic_900 },
658 { expanded_obliqu_100, expanded_obliqu_100 },
659 { expanded_obliqu_900, expanded_obliqu_900 },
660 },
661 },
662 {
663 { expanded_normal_100,expanded_normal_900,
664 expanded_obliqu_100,expanded_obliqu_900, },
665 {
666 { condensed_normal_100, expanded_normal_100 },
667 { condensed_normal_900, expanded_normal_900 },
668 { condensed_italic_100, expanded_obliqu_100 },
669 { condensed_italic_900, expanded_obliqu_900 },
670 { condensed_obliqu_100, expanded_obliqu_100 },
671 { condensed_obliqu_900, expanded_obliqu_900 },
672 { expanded_normal_100, expanded_normal_100 },
673 { expanded_normal_900, expanded_normal_900 },
674 { expanded_italic_100, expanded_obliqu_100 },
675 { expanded_italic_900, expanded_obliqu_900 },
676 { expanded_obliqu_100, expanded_obliqu_100 },
677 { expanded_obliqu_900, expanded_obliqu_900 },
678 },
679 },
680 {
681 { expanded_italic_100,expanded_italic_900,
682 expanded_obliqu_100,expanded_obliqu_900, },
683 {
684 { condensed_normal_100, expanded_obliqu_100 },
685 { condensed_normal_900, expanded_obliqu_900 },
686 { condensed_italic_100, expanded_italic_100 },
687 { condensed_italic_900, expanded_italic_900 },
688 { condensed_obliqu_100, expanded_obliqu_100 },
689 { condensed_obliqu_900, expanded_obliqu_900 },
690 { expanded_normal_100, expanded_obliqu_100 },
691 { expanded_normal_900, expanded_obliqu_900 },
692 { expanded_italic_100, expanded_italic_100 },
693 { expanded_italic_900, expanded_italic_900 },
694 { expanded_obliqu_100, expanded_obliqu_100 },
695 { expanded_obliqu_900, expanded_obliqu_900 },
696 },
697 },
bungeman147ea2f2015-11-12 09:50:08 -0800698 };
699
700 for (StyleSetTest& test : tests) {
Mike Klein6ad99092016-10-26 10:35:22 -0400701 for (const StyleSetTest::Case& testCase : test.cases) {
Hal Canary342b7ac2016-11-04 11:49:42 -0400702 sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern));
bungeman147ea2f2015-11-12 09:50:08 -0800703 if (typeface) {
704 REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult);
705 } else {
706 REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult);
707 }
708 }
709 }
710}
711
reed@google.com66c9f992013-04-11 19:04:34 +0000712DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests.");
reed@google.com83165a52013-04-11 18:31:25 +0000713
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +0000714DEF_TEST(FontMgr, reporter) {
bungeman7575bb12017-05-01 13:02:42 -0400715 test_match(reporter);
bungeman147ea2f2015-11-12 09:50:08 -0800716 test_matchStyleCSS3(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000717 test_fontiter(reporter, FLAGS_verboseFontMgr);
reed@google.comc1a81eb2013-09-19 18:06:03 +0000718 test_alias_names(reporter);
reed@google.com43c27582014-04-08 15:04:29 +0000719 test_font(reporter);
reed@google.com83165a52013-04-11 18:31:25 +0000720}