reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 1 | /* |
| 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 Canary | 209e4b1 | 2017-05-04 14:23:55 -0400 | [diff] [blame] | 8 | #include "SkAdvancedTypefaceMetrics.h" |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 9 | #include "SkCommandLineFlags.h" |
Hal Canary | 209e4b1 | 2017-05-04 14:23:55 -0400 | [diff] [blame] | 10 | #include "SkFont.h" |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 11 | #include "SkFontMgr.h" |
Hal Canary | 209e4b1 | 2017-05-04 14:23:55 -0400 | [diff] [blame] | 12 | #include "SkPaint.h" |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 13 | #include "SkTypeface.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 14 | #include "Test.h" |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 15 | |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 16 | #include <initializer_list> |
| 17 | #include <limits> |
| 18 | #include <vector> |
| 19 | |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 20 | static void test_font(skiatest::Reporter* reporter) { |
| 21 | uint32_t flags = 0; |
Mike Reed | fe4fc14 | 2018-10-22 14:24:07 -0400 | [diff] [blame^] | 22 | SkFont font(nullptr, 24, flags); |
skia.committer@gmail.com | e1d9443 | 2014-04-09 03:04:11 +0000 | [diff] [blame] | 23 | |
Mike Reed | fe4fc14 | 2018-10-22 14:24:07 -0400 | [diff] [blame^] | 24 | 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.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 28 | |
| 29 | uint16_t glyphs[5]; |
| 30 | sk_bzero(glyphs, sizeof(glyphs)); |
| 31 | |
Mike Reed | fe4fc14 | 2018-10-22 14:24:07 -0400 | [diff] [blame^] | 32 | int count = font.textToGlyphs("Hello", 5, kUTF8_SkTextEncoding, glyphs, SK_ARRAY_COUNT(glyphs)); |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 33 | |
| 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.com | e1d9443 | 2014-04-09 03:04:11 +0000 | [diff] [blame] | 40 | |
Mike Reed | fe4fc14 | 2018-10-22 14:24:07 -0400 | [diff] [blame^] | 41 | 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.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 45 | |
| 46 | SkPaint paint; |
| 47 | paint.setTextSize(18); |
Mike Reed | fe4fc14 | 2018-10-22 14:24:07 -0400 | [diff] [blame^] | 48 | font = SkFont::LEGACY_ExtractFromPaint(paint); |
| 49 | REPORTER_ASSERT(reporter, font.getSize() == paint.getTextSize()); |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 50 | } |
| 51 | |
reed@google.com | d44d988 | 2013-09-18 20:32:25 +0000 | [diff] [blame] | 52 | /* |
| 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.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 57 | static void test_alias_names(skiatest::Reporter* reporter) { |
| 58 | const char* inNames[] = { |
| 59 | "sans", "sans-serif", "serif", "monospace", "times", "helvetica" |
| 60 | }; |
skia.committer@gmail.com | f91e3d4 | 2013-09-20 07:01:33 +0000 | [diff] [blame] | 61 | |
reed@google.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 62 | for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) { |
mboc | ee6a991 | 2016-05-31 11:42:36 -0700 | [diff] [blame] | 63 | sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkFontStyle())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 64 | if (nullptr == first.get()) { |
reed@google.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 65 | continue; |
| 66 | } |
| 67 | for (int j = 0; j < 10; ++j) { |
mboc | ee6a991 | 2016-05-31 11:42:36 -0700 | [diff] [blame] | 68 | sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkFontStyle())); |
reed@google.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 69 | #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.com | d44d988 | 2013-09-18 20:32:25 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 80 | static void test_fontiter(skiatest::Reporter* reporter, bool verbose) { |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 81 | sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 82 | int count = fm->countFamilies(); |
| 83 | |
| 84 | for (int i = 0; i < count; ++i) { |
| 85 | SkString fname; |
| 86 | fm->getFamilyName(i, &fname); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 87 | |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 88 | sk_sp<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str())); |
| 89 | sk_sp<SkFontStyleSet> set(fm->createStyleSet(i)); |
bungeman@google.com | 7103344 | 2013-05-01 14:21:20 +0000 | [diff] [blame] | 90 | REPORTER_ASSERT(reporter, fnset->count() == set->count()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 91 | |
| 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.com | eb02957 | 2013-04-25 14:59:32 +0000 | [diff] [blame] | 100 | // REPORTER_ASSERT(reporter, sname.size() > 0); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 101 | |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 102 | sk_sp<SkTypeface> face(set->createTypeface(j)); |
reed@google.com | c1ccda3 | 2013-04-19 14:28:54 +0000 | [diff] [blame] | 103 | // REPORTER_ASSERT(reporter, face.get()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 104 | |
| 105 | if (verbose) { |
| 106 | SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(), |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 107 | fs.weight(), fs.width(), fs.slant()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
bungeman | 7575bb1 | 2017-05-01 13:02:42 -0400 | [diff] [blame] | 113 | static 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 | |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 119 | static void test_matchStyleCSS3(skiatest::Reporter* reporter) { |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 120 | static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 121 | |
| 122 | class TestTypeface : public SkTypeface { |
| 123 | public: |
bungeman | e3aea10 | 2016-07-13 05:16:58 -0700 | [diff] [blame] | 124 | TestTypeface(const SkFontStyle& fontStyle) : SkTypeface(fontStyle, false){} |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 125 | protected: |
| 126 | SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; } |
Bruce Wang | 536ad2c | 2018-06-25 11:37:25 -0400 | [diff] [blame] | 127 | sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override { |
| 128 | return sk_ref_sp(this); |
| 129 | } |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 130 | SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, |
| 131 | const SkDescriptor*) const override { |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 132 | return nullptr; |
| 133 | } |
| 134 | void onFilterRec(SkScalerContextRec*) const override { } |
Hal Canary | 209e4b1 | 2017-05-04 14:23:55 -0400 | [diff] [blame] | 135 | std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override { |
| 136 | return nullptr; |
| 137 | } |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 138 | 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 Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 146 | int onCountGlyphs() const override { return 0; } |
| 147 | int onGetUPEM() const override { return 0; } |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 148 | 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 Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 157 | } |
Ben Wagner | fc49734 | 2017-02-24 11:15:26 -0500 | [diff] [blame] | 158 | int onGetVariationDesignPosition( |
| 159 | SkFontArguments::VariationPosition::Coordinate coordinates[], |
| 160 | int coordinateCount) const override |
| 161 | { |
| 162 | return 0; |
| 163 | } |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 164 | 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) { |
bungeman | e3aea10 | 2016-07-13 05:16:58 -0700 | [diff] [blame] | 181 | return new TestTypeface(invalidFontStyle); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 182 | } |
bungeman | e3aea10 | 2016-07-13 05:16:58 -0700 | [diff] [blame] | 183 | return new TestTypeface(fStyles[index]); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 184 | } |
| 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); |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 196 | 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); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 198 | 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); |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 202 | 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); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 204 | |
| 205 | SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 206 | 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); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 210 | 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 | { |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 474 | { expanded_normal_100,expanded_normal_900, |
| 475 | expanded_italic_100,expanded_italic_900 }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 476 | { |
| 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 }, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 481 | { condensed_obliqu_100, expanded_italic_100 }, |
| 482 | { condensed_obliqu_900, expanded_italic_900 }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 483 | { 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 }, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 487 | { expanded_obliqu_100, expanded_italic_100 }, |
| 488 | { expanded_obliqu_900, expanded_italic_900 }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 489 | }, |
| 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 | }, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 643 | { |
| 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 | }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 698 | }; |
| 699 | |
| 700 | for (StyleSetTest& test : tests) { |
Mike Klein | 6ad9909 | 2016-10-26 10:35:22 -0400 | [diff] [blame] | 701 | for (const StyleSetTest::Case& testCase : test.cases) { |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 702 | sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern)); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 703 | 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.com | 66c9f99 | 2013-04-11 19:04:34 +0000 | [diff] [blame] | 712 | DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 713 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 714 | DEF_TEST(FontMgr, reporter) { |
bungeman | 7575bb1 | 2017-05-01 13:02:42 -0400 | [diff] [blame] | 715 | test_match(reporter); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 716 | test_matchStyleCSS3(reporter); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 717 | test_fontiter(reporter, FLAGS_verboseFontMgr); |
reed@google.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 718 | test_alias_names(reporter); |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 719 | test_font(reporter); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 720 | } |