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 | |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 8 | #include "SkCommandLineFlags.h" |
| 9 | #include "SkFontMgr.h" |
| 10 | #include "SkTypeface.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 11 | #include "Test.h" |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 12 | |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 13 | #include "SkFont.h" |
| 14 | #include "SkPaint.h" |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 15 | |
| 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; |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 22 | sk_sp<SkFont> font(SkFont::Make(nullptr, 24, SkFont::kA8_MaskType, flags)); |
skia.committer@gmail.com | e1d9443 | 2014-04-09 03:04:11 +0000 | [diff] [blame] | 23 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 24 | REPORTER_ASSERT(reporter, font->getTypeface()); |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 25 | 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.com | e1d9443 | 2014-04-09 03:04:11 +0000 | [diff] [blame] | 41 | |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 42 | sk_sp<SkFont> newFont(font->makeWithSize(36)); |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 43 | 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); |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 50 | font = SkFont::Testing_CreateFromPaint(paint); |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 51 | 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.com | d44d988 | 2013-09-18 20:32:25 +0000 | [diff] [blame] | 56 | /* |
| 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.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 61 | static void test_alias_names(skiatest::Reporter* reporter) { |
| 62 | const char* inNames[] = { |
| 63 | "sans", "sans-serif", "serif", "monospace", "times", "helvetica" |
| 64 | }; |
skia.committer@gmail.com | f91e3d4 | 2013-09-20 07:01:33 +0000 | [diff] [blame] | 65 | |
reed@google.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 66 | for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) { |
mboc | ee6a991 | 2016-05-31 11:42:36 -0700 | [diff] [blame] | 67 | sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkFontStyle())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 68 | if (nullptr == first.get()) { |
reed@google.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 69 | continue; |
| 70 | } |
| 71 | for (int j = 0; j < 10; ++j) { |
mboc | ee6a991 | 2016-05-31 11:42:36 -0700 | [diff] [blame] | 72 | sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkFontStyle())); |
reed@google.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 73 | #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.com | d44d988 | 2013-09-18 20:32:25 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 84 | static void test_fontiter(skiatest::Reporter* reporter, bool verbose) { |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 85 | sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 86 | int count = fm->countFamilies(); |
| 87 | |
| 88 | for (int i = 0; i < count; ++i) { |
| 89 | SkString fname; |
| 90 | fm->getFamilyName(i, &fname); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 91 | |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 92 | sk_sp<SkFontStyleSet> fnset(fm->matchFamily(fname.c_str())); |
| 93 | sk_sp<SkFontStyleSet> set(fm->createStyleSet(i)); |
bungeman@google.com | 7103344 | 2013-05-01 14:21:20 +0000 | [diff] [blame] | 94 | REPORTER_ASSERT(reporter, fnset->count() == set->count()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 95 | |
| 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.com | eb02957 | 2013-04-25 14:59:32 +0000 | [diff] [blame] | 104 | // REPORTER_ASSERT(reporter, sname.size() > 0); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 105 | |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 106 | sk_sp<SkTypeface> face(set->createTypeface(j)); |
reed@google.com | c1ccda3 | 2013-04-19 14:28:54 +0000 | [diff] [blame] | 107 | // REPORTER_ASSERT(reporter, face.get()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 108 | |
| 109 | if (verbose) { |
| 110 | SkDebugf("\t[%d] %s [%3d %d %d]\n", j, sname.c_str(), |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 111 | fs.weight(), fs.width(), fs.slant()); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 117 | static void test_matchStyleCSS3(skiatest::Reporter* reporter) { |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 118 | static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 119 | |
| 120 | class TestTypeface : public SkTypeface { |
| 121 | public: |
bungeman | e3aea10 | 2016-07-13 05:16:58 -0700 | [diff] [blame] | 122 | TestTypeface(const SkFontStyle& fontStyle) : SkTypeface(fontStyle, false){} |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 123 | protected: |
| 124 | SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; } |
reed | a9322c2 | 2016-04-12 06:47:05 -0700 | [diff] [blame] | 125 | SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, |
| 126 | const SkDescriptor*) const override { |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 127 | return nullptr; |
| 128 | } |
| 129 | void onFilterRec(SkScalerContextRec*) const override { } |
| 130 | virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 131 | PerGlyphInfo, |
| 132 | const uint32_t*, uint32_t) const override { return nullptr; } |
| 133 | void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { } |
| 134 | virtual int onCharsToGlyphs(const void* chars, Encoding encoding, |
| 135 | uint16_t glyphs[], int glyphCount) const override { |
| 136 | if (glyphs && glyphCount > 0) { |
| 137 | sk_bzero(glyphs, glyphCount * sizeof(glyphs[0])); |
| 138 | } |
| 139 | return 0; |
| 140 | } |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 141 | int onCountGlyphs() const override { return 0; } |
| 142 | int onGetUPEM() const override { return 0; } |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 143 | class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings { |
| 144 | public: |
| 145 | bool next(SkTypeface::LocalizedString*) override { return false; } |
| 146 | }; |
| 147 | void onGetFamilyName(SkString* familyName) const override { |
| 148 | familyName->reset(); |
| 149 | } |
| 150 | SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override { |
| 151 | return new EmptyLocalizedStrings; |
Mike Klein | fc6c37b | 2016-09-27 09:34:10 -0400 | [diff] [blame] | 152 | } |
Ben Wagner | fc49734 | 2017-02-24 11:15:26 -0500 | [diff] [blame] | 153 | int onGetVariationDesignPosition( |
| 154 | SkFontArguments::VariationPosition::Coordinate coordinates[], |
| 155 | int coordinateCount) const override |
| 156 | { |
| 157 | return 0; |
| 158 | } |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 159 | int onGetTableTags(SkFontTableTag tags[]) const override { return 0; } |
| 160 | size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override { |
| 161 | return 0; |
| 162 | } |
| 163 | }; |
| 164 | |
| 165 | class TestFontStyleSet : public SkFontStyleSet { |
| 166 | public: |
| 167 | TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {} |
| 168 | int count() override { return static_cast<int>(fStyles.size()); } |
| 169 | void getStyle(int index, SkFontStyle* style, SkString*) override { |
| 170 | if (style) { |
| 171 | *style = fStyles[index]; |
| 172 | } |
| 173 | } |
| 174 | SkTypeface* createTypeface(int index) override { |
| 175 | if (index < 0 || this->count() <= index) { |
bungeman | e3aea10 | 2016-07-13 05:16:58 -0700 | [diff] [blame] | 176 | return new TestTypeface(invalidFontStyle); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 177 | } |
bungeman | e3aea10 | 2016-07-13 05:16:58 -0700 | [diff] [blame] | 178 | return new TestTypeface(fStyles[index]); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 179 | } |
| 180 | SkTypeface* matchStyle(const SkFontStyle& pattern) override { |
| 181 | return this->matchStyleCSS3(pattern); |
| 182 | } |
| 183 | private: |
| 184 | std::vector<SkFontStyle> fStyles; |
| 185 | }; |
| 186 | |
| 187 | SkFontStyle condensed_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant); |
| 188 | SkFontStyle condensed_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant); |
| 189 | SkFontStyle condensed_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant); |
| 190 | SkFontStyle condensed_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant); |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 191 | SkFontStyle condensed_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant); |
| 192 | SkFontStyle condensed_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 193 | SkFontStyle expanded_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant); |
| 194 | SkFontStyle expanded_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant); |
| 195 | SkFontStyle expanded_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant); |
| 196 | SkFontStyle expanded_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant); |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 197 | SkFontStyle expanded_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant); |
| 198 | SkFontStyle expanded_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 199 | |
| 200 | SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 201 | SkFontStyle normal_normal_200(SkFontStyle::kExtraLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 202 | SkFontStyle normal_normal_300(SkFontStyle::kLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 203 | SkFontStyle normal_normal_400(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 204 | SkFontStyle normal_normal_500(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 205 | SkFontStyle normal_normal_600(SkFontStyle::kSemiBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 206 | SkFontStyle normal_normal_700(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 207 | SkFontStyle normal_normal_800(SkFontStyle::kExtraBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 208 | SkFontStyle normal_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 209 | |
| 210 | struct StyleSetTest { |
| 211 | TestFontStyleSet styleSet; |
| 212 | struct Case { |
| 213 | SkFontStyle pattern; |
| 214 | SkFontStyle expectedResult; |
| 215 | }; |
| 216 | std::vector<Case> cases; |
| 217 | } tests[] = { |
| 218 | { |
| 219 | { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900, |
| 220 | expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 }, |
| 221 | { |
| 222 | { condensed_normal_100, condensed_normal_100 }, |
| 223 | { condensed_normal_900, condensed_normal_900 }, |
| 224 | { condensed_italic_100, condensed_italic_100 }, |
| 225 | { condensed_italic_900, condensed_italic_900 }, |
| 226 | { expanded_normal_100, expanded_normal_100 }, |
| 227 | { expanded_normal_900, expanded_normal_900 }, |
| 228 | { expanded_italic_100, expanded_italic_100 }, |
| 229 | { expanded_italic_900, expanded_italic_900 }, |
| 230 | }, |
| 231 | }, |
| 232 | |
| 233 | { |
| 234 | { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 }, |
| 235 | { |
| 236 | { condensed_normal_100, condensed_normal_100 }, |
| 237 | { condensed_normal_900, condensed_normal_100 }, |
| 238 | { condensed_italic_100, condensed_italic_100 }, |
| 239 | { condensed_italic_900, condensed_italic_100 }, |
| 240 | { expanded_normal_100, expanded_normal_100 }, |
| 241 | { expanded_normal_900, expanded_normal_100 }, |
| 242 | { expanded_italic_100, expanded_italic_100 }, |
| 243 | { expanded_italic_900, expanded_italic_100 }, |
| 244 | }, |
| 245 | }, |
| 246 | |
| 247 | { |
| 248 | { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 }, |
| 249 | { |
| 250 | { condensed_normal_100, condensed_normal_900 }, |
| 251 | { condensed_normal_900, condensed_normal_900 }, |
| 252 | { condensed_italic_100, condensed_italic_900 }, |
| 253 | { condensed_italic_900, condensed_italic_900 }, |
| 254 | { expanded_normal_100, expanded_normal_900 }, |
| 255 | { expanded_normal_900, expanded_normal_900 }, |
| 256 | { expanded_italic_100, expanded_italic_900 }, |
| 257 | { expanded_italic_900, expanded_italic_900 }, |
| 258 | }, |
| 259 | }, |
| 260 | |
| 261 | { |
| 262 | { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 }, |
| 263 | { |
| 264 | { condensed_normal_100, condensed_normal_100 }, |
| 265 | { condensed_normal_900, condensed_normal_900 }, |
| 266 | { condensed_italic_100, condensed_normal_100 }, |
| 267 | { condensed_italic_900, condensed_normal_900 }, |
| 268 | { expanded_normal_100, expanded_normal_100 }, |
| 269 | { expanded_normal_900, expanded_normal_900 }, |
| 270 | { expanded_italic_100, expanded_normal_100 }, |
| 271 | { expanded_italic_900, expanded_normal_900 }, |
| 272 | }, |
| 273 | }, |
| 274 | |
| 275 | { |
| 276 | { condensed_normal_100,expanded_normal_100 }, |
| 277 | { |
| 278 | { condensed_normal_100, condensed_normal_100 }, |
| 279 | { condensed_normal_900, condensed_normal_100 }, |
| 280 | { condensed_italic_100, condensed_normal_100 }, |
| 281 | { condensed_italic_900, condensed_normal_100 }, |
| 282 | { expanded_normal_100, expanded_normal_100 }, |
| 283 | { expanded_normal_900, expanded_normal_100 }, |
| 284 | { expanded_italic_100, expanded_normal_100 }, |
| 285 | { expanded_italic_900, expanded_normal_100 }, |
| 286 | }, |
| 287 | }, |
| 288 | |
| 289 | { |
| 290 | { condensed_normal_900,expanded_normal_900 }, |
| 291 | { |
| 292 | { condensed_normal_100, condensed_normal_900 }, |
| 293 | { condensed_normal_900, condensed_normal_900 }, |
| 294 | { condensed_italic_100, condensed_normal_900 }, |
| 295 | { condensed_italic_900, condensed_normal_900 }, |
| 296 | { expanded_normal_100, expanded_normal_900 }, |
| 297 | { expanded_normal_900, expanded_normal_900 }, |
| 298 | { expanded_italic_100, expanded_normal_900 }, |
| 299 | { expanded_italic_900, expanded_normal_900 }, |
| 300 | }, |
| 301 | }, |
| 302 | |
| 303 | { |
| 304 | { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 }, |
| 305 | { |
| 306 | { condensed_normal_100, condensed_italic_100 }, |
| 307 | { condensed_normal_900, condensed_italic_900 }, |
| 308 | { condensed_italic_100, condensed_italic_100 }, |
| 309 | { condensed_italic_900, condensed_italic_900 }, |
| 310 | { expanded_normal_100, expanded_italic_100 }, |
| 311 | { expanded_normal_900, expanded_italic_900 }, |
| 312 | { expanded_italic_100, expanded_italic_100 }, |
| 313 | { expanded_italic_900, expanded_italic_900 }, |
| 314 | }, |
| 315 | }, |
| 316 | |
| 317 | { |
| 318 | { condensed_italic_100,expanded_italic_100 }, |
| 319 | { |
| 320 | { condensed_normal_100, condensed_italic_100 }, |
| 321 | { condensed_normal_900, condensed_italic_100 }, |
| 322 | { condensed_italic_100, condensed_italic_100 }, |
| 323 | { condensed_italic_900, condensed_italic_100 }, |
| 324 | { expanded_normal_100, expanded_italic_100 }, |
| 325 | { expanded_normal_900, expanded_italic_100 }, |
| 326 | { expanded_italic_100, expanded_italic_100 }, |
| 327 | { expanded_italic_900, expanded_italic_100 }, |
| 328 | }, |
| 329 | }, |
| 330 | |
| 331 | { |
| 332 | { condensed_italic_900,expanded_italic_900 }, |
| 333 | { |
| 334 | { condensed_normal_100, condensed_italic_900 }, |
| 335 | { condensed_normal_900, condensed_italic_900 }, |
| 336 | { condensed_italic_100, condensed_italic_900 }, |
| 337 | { condensed_italic_900, condensed_italic_900 }, |
| 338 | { expanded_normal_100, expanded_italic_900 }, |
| 339 | { expanded_normal_900, expanded_italic_900 }, |
| 340 | { expanded_italic_100, expanded_italic_900 }, |
| 341 | { expanded_italic_900, expanded_italic_900 }, |
| 342 | }, |
| 343 | }, |
| 344 | |
| 345 | { |
| 346 | { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 }, |
| 347 | { |
| 348 | { condensed_normal_100, condensed_normal_100 }, |
| 349 | { condensed_normal_900, condensed_normal_900 }, |
| 350 | { condensed_italic_100, condensed_italic_100 }, |
| 351 | { condensed_italic_900, condensed_italic_900 }, |
| 352 | { expanded_normal_100, condensed_normal_100 }, |
| 353 | { expanded_normal_900, condensed_normal_900 }, |
| 354 | { expanded_italic_100, condensed_italic_100 }, |
| 355 | { expanded_italic_900, condensed_italic_900 }, |
| 356 | }, |
| 357 | }, |
| 358 | |
| 359 | { |
| 360 | { condensed_normal_100,condensed_italic_100 }, |
| 361 | { |
| 362 | { condensed_normal_100, condensed_normal_100 }, |
| 363 | { condensed_normal_900, condensed_normal_100 }, |
| 364 | { condensed_italic_100, condensed_italic_100 }, |
| 365 | { condensed_italic_900, condensed_italic_100 }, |
| 366 | { expanded_normal_100, condensed_normal_100 }, |
| 367 | { expanded_normal_900, condensed_normal_100 }, |
| 368 | { expanded_italic_100, condensed_italic_100 }, |
| 369 | { expanded_italic_900, condensed_italic_100 }, |
| 370 | }, |
| 371 | }, |
| 372 | |
| 373 | { |
| 374 | { condensed_normal_900,condensed_italic_900 }, |
| 375 | { |
| 376 | { condensed_normal_100, condensed_normal_900 }, |
| 377 | { condensed_normal_900, condensed_normal_900 }, |
| 378 | { condensed_italic_100, condensed_italic_900 }, |
| 379 | { condensed_italic_900, condensed_italic_900 }, |
| 380 | { expanded_normal_100, condensed_normal_900 }, |
| 381 | { expanded_normal_900, condensed_normal_900 }, |
| 382 | { expanded_italic_100, condensed_italic_900 }, |
| 383 | { expanded_italic_900, condensed_italic_900 }, |
| 384 | }, |
| 385 | }, |
| 386 | |
| 387 | { |
| 388 | { condensed_normal_100,condensed_normal_900 }, |
| 389 | { |
| 390 | { condensed_normal_100, condensed_normal_100 }, |
| 391 | { condensed_normal_900, condensed_normal_900 }, |
| 392 | { condensed_italic_100, condensed_normal_100 }, |
| 393 | { condensed_italic_900, condensed_normal_900 }, |
| 394 | { expanded_normal_100, condensed_normal_100 }, |
| 395 | { expanded_normal_900, condensed_normal_900 }, |
| 396 | { expanded_italic_100, condensed_normal_100 }, |
| 397 | { expanded_italic_900, condensed_normal_900 }, |
| 398 | }, |
| 399 | }, |
| 400 | |
| 401 | { |
| 402 | { condensed_normal_100 }, |
| 403 | { |
| 404 | { condensed_normal_100, condensed_normal_100 }, |
| 405 | { condensed_normal_900, condensed_normal_100 }, |
| 406 | { condensed_italic_100, condensed_normal_100 }, |
| 407 | { condensed_italic_900, condensed_normal_100 }, |
| 408 | { expanded_normal_100, condensed_normal_100 }, |
| 409 | { expanded_normal_900, condensed_normal_100 }, |
| 410 | { expanded_italic_100, condensed_normal_100 }, |
| 411 | { expanded_italic_900, condensed_normal_100 }, |
| 412 | }, |
| 413 | }, |
| 414 | |
| 415 | { |
| 416 | { condensed_normal_900 }, |
| 417 | { |
| 418 | { condensed_normal_100, condensed_normal_900 }, |
| 419 | { condensed_normal_900, condensed_normal_900 }, |
| 420 | { condensed_italic_100, condensed_normal_900 }, |
| 421 | { condensed_italic_900, condensed_normal_900 }, |
| 422 | { expanded_normal_100, condensed_normal_900 }, |
| 423 | { expanded_normal_900, condensed_normal_900 }, |
| 424 | { expanded_italic_100, condensed_normal_900 }, |
| 425 | { expanded_italic_900, condensed_normal_900 }, |
| 426 | }, |
| 427 | }, |
| 428 | |
| 429 | { |
| 430 | { condensed_italic_100,condensed_italic_900 }, |
| 431 | { |
| 432 | { condensed_normal_100, condensed_italic_100 }, |
| 433 | { condensed_normal_900, condensed_italic_900 }, |
| 434 | { condensed_italic_100, condensed_italic_100 }, |
| 435 | { condensed_italic_900, condensed_italic_900 }, |
| 436 | { expanded_normal_100, condensed_italic_100 }, |
| 437 | { expanded_normal_900, condensed_italic_900 }, |
| 438 | { expanded_italic_100, condensed_italic_100 }, |
| 439 | { expanded_italic_900, condensed_italic_900 }, |
| 440 | }, |
| 441 | }, |
| 442 | |
| 443 | { |
| 444 | { condensed_italic_100 }, |
| 445 | { |
| 446 | { condensed_normal_100, condensed_italic_100 }, |
| 447 | { condensed_normal_900, condensed_italic_100 }, |
| 448 | { condensed_italic_100, condensed_italic_100 }, |
| 449 | { condensed_italic_900, condensed_italic_100 }, |
| 450 | { expanded_normal_100, condensed_italic_100 }, |
| 451 | { expanded_normal_900, condensed_italic_100 }, |
| 452 | { expanded_italic_100, condensed_italic_100 }, |
| 453 | { expanded_italic_900, condensed_italic_100 }, |
| 454 | }, |
| 455 | }, |
| 456 | |
| 457 | { |
| 458 | { condensed_italic_900 }, |
| 459 | { |
| 460 | { condensed_normal_100, condensed_italic_900 }, |
| 461 | { condensed_normal_900, condensed_italic_900 }, |
| 462 | { condensed_italic_100, condensed_italic_900 }, |
| 463 | { condensed_italic_900, condensed_italic_900 }, |
| 464 | { expanded_normal_100, condensed_italic_900 }, |
| 465 | { expanded_normal_900, condensed_italic_900 }, |
| 466 | { expanded_italic_100, condensed_italic_900 }, |
| 467 | { expanded_italic_900, condensed_italic_900 }, |
| 468 | }, |
| 469 | }, |
| 470 | |
| 471 | { |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 472 | { expanded_normal_100,expanded_normal_900, |
| 473 | expanded_italic_100,expanded_italic_900 }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 474 | { |
| 475 | { condensed_normal_100, expanded_normal_100 }, |
| 476 | { condensed_normal_900, expanded_normal_900 }, |
| 477 | { condensed_italic_100, expanded_italic_100 }, |
| 478 | { condensed_italic_900, expanded_italic_900 }, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 479 | { condensed_obliqu_100, expanded_italic_100 }, |
| 480 | { condensed_obliqu_900, expanded_italic_900 }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 481 | { expanded_normal_100, expanded_normal_100 }, |
| 482 | { expanded_normal_900, expanded_normal_900 }, |
| 483 | { expanded_italic_100, expanded_italic_100 }, |
| 484 | { expanded_italic_900, expanded_italic_900 }, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 485 | { expanded_obliqu_100, expanded_italic_100 }, |
| 486 | { expanded_obliqu_900, expanded_italic_900 }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 487 | }, |
| 488 | }, |
| 489 | |
| 490 | { |
| 491 | { expanded_normal_100,expanded_italic_100 }, |
| 492 | { |
| 493 | { condensed_normal_100, expanded_normal_100 }, |
| 494 | { condensed_normal_900, expanded_normal_100 }, |
| 495 | { condensed_italic_100, expanded_italic_100 }, |
| 496 | { condensed_italic_900, expanded_italic_100 }, |
| 497 | { expanded_normal_100, expanded_normal_100 }, |
| 498 | { expanded_normal_900, expanded_normal_100 }, |
| 499 | { expanded_italic_100, expanded_italic_100 }, |
| 500 | { expanded_italic_900, expanded_italic_100 }, |
| 501 | }, |
| 502 | }, |
| 503 | |
| 504 | { |
| 505 | { expanded_normal_900,expanded_italic_900 }, |
| 506 | { |
| 507 | { condensed_normal_100, expanded_normal_900 }, |
| 508 | { condensed_normal_900, expanded_normal_900 }, |
| 509 | { condensed_italic_100, expanded_italic_900 }, |
| 510 | { condensed_italic_900, expanded_italic_900 }, |
| 511 | { expanded_normal_100, expanded_normal_900 }, |
| 512 | { expanded_normal_900, expanded_normal_900 }, |
| 513 | { expanded_italic_100, expanded_italic_900 }, |
| 514 | { expanded_italic_900, expanded_italic_900 }, |
| 515 | }, |
| 516 | }, |
| 517 | |
| 518 | { |
| 519 | { expanded_normal_100,expanded_normal_900 }, |
| 520 | { |
| 521 | { condensed_normal_100, expanded_normal_100 }, |
| 522 | { condensed_normal_900, expanded_normal_900 }, |
| 523 | { condensed_italic_100, expanded_normal_100 }, |
| 524 | { condensed_italic_900, expanded_normal_900 }, |
| 525 | { expanded_normal_100, expanded_normal_100 }, |
| 526 | { expanded_normal_900, expanded_normal_900 }, |
| 527 | { expanded_italic_100, expanded_normal_100 }, |
| 528 | { expanded_italic_900, expanded_normal_900 }, |
| 529 | }, |
| 530 | }, |
| 531 | |
| 532 | { |
| 533 | { expanded_normal_100 }, |
| 534 | { |
| 535 | { condensed_normal_100, expanded_normal_100 }, |
| 536 | { condensed_normal_900, expanded_normal_100 }, |
| 537 | { condensed_italic_100, expanded_normal_100 }, |
| 538 | { condensed_italic_900, expanded_normal_100 }, |
| 539 | { expanded_normal_100, expanded_normal_100 }, |
| 540 | { expanded_normal_900, expanded_normal_100 }, |
| 541 | { expanded_italic_100, expanded_normal_100 }, |
| 542 | { expanded_italic_900, expanded_normal_100 }, |
| 543 | }, |
| 544 | }, |
| 545 | |
| 546 | { |
| 547 | { expanded_normal_900 }, |
| 548 | { |
| 549 | { condensed_normal_100, expanded_normal_900 }, |
| 550 | { condensed_normal_900, expanded_normal_900 }, |
| 551 | { condensed_italic_100, expanded_normal_900 }, |
| 552 | { condensed_italic_900, expanded_normal_900 }, |
| 553 | { expanded_normal_100, expanded_normal_900 }, |
| 554 | { expanded_normal_900, expanded_normal_900 }, |
| 555 | { expanded_italic_100, expanded_normal_900 }, |
| 556 | { expanded_italic_900, expanded_normal_900 }, |
| 557 | }, |
| 558 | }, |
| 559 | |
| 560 | { |
| 561 | { expanded_italic_100,expanded_italic_900 }, |
| 562 | { |
| 563 | { condensed_normal_100, expanded_italic_100 }, |
| 564 | { condensed_normal_900, expanded_italic_900 }, |
| 565 | { condensed_italic_100, expanded_italic_100 }, |
| 566 | { condensed_italic_900, expanded_italic_900 }, |
| 567 | { expanded_normal_100, expanded_italic_100 }, |
| 568 | { expanded_normal_900, expanded_italic_900 }, |
| 569 | { expanded_italic_100, expanded_italic_100 }, |
| 570 | { expanded_italic_900, expanded_italic_900 }, |
| 571 | }, |
| 572 | }, |
| 573 | |
| 574 | { |
| 575 | { expanded_italic_100 }, |
| 576 | { |
| 577 | { condensed_normal_100, expanded_italic_100 }, |
| 578 | { condensed_normal_900, expanded_italic_100 }, |
| 579 | { condensed_italic_100, expanded_italic_100 }, |
| 580 | { condensed_italic_900, expanded_italic_100 }, |
| 581 | { expanded_normal_100, expanded_italic_100 }, |
| 582 | { expanded_normal_900, expanded_italic_100 }, |
| 583 | { expanded_italic_100, expanded_italic_100 }, |
| 584 | { expanded_italic_900, expanded_italic_100 }, |
| 585 | }, |
| 586 | }, |
| 587 | |
| 588 | { |
| 589 | { expanded_italic_900 }, |
| 590 | { |
| 591 | { condensed_normal_100, expanded_italic_900 }, |
| 592 | { condensed_normal_900, expanded_italic_900 }, |
| 593 | { condensed_italic_100, expanded_italic_900 }, |
| 594 | { condensed_italic_900, expanded_italic_900 }, |
| 595 | { expanded_normal_100, expanded_italic_900 }, |
| 596 | { expanded_normal_900, expanded_italic_900 }, |
| 597 | { expanded_italic_100, expanded_italic_900 }, |
| 598 | { expanded_italic_900, expanded_italic_900 }, |
| 599 | }, |
| 600 | }, |
| 601 | |
| 602 | { |
| 603 | { normal_normal_100, normal_normal_900 }, |
| 604 | { |
| 605 | { normal_normal_300, normal_normal_100 }, |
| 606 | { normal_normal_400, normal_normal_100 }, |
| 607 | { normal_normal_500, normal_normal_100 }, |
| 608 | { normal_normal_600, normal_normal_900 }, |
| 609 | }, |
| 610 | }, |
| 611 | |
| 612 | { |
| 613 | { normal_normal_100, normal_normal_400, normal_normal_900 }, |
| 614 | { |
| 615 | { normal_normal_300, normal_normal_100 }, |
| 616 | { normal_normal_400, normal_normal_400 }, |
| 617 | { normal_normal_500, normal_normal_400 }, |
| 618 | { normal_normal_600, normal_normal_900 }, |
| 619 | }, |
| 620 | }, |
| 621 | |
| 622 | { |
| 623 | { normal_normal_100, normal_normal_500, normal_normal_900 }, |
| 624 | { |
| 625 | { normal_normal_300, normal_normal_100 }, |
| 626 | { normal_normal_400, normal_normal_500 }, |
| 627 | { normal_normal_500, normal_normal_500 }, |
| 628 | { normal_normal_600, normal_normal_900 }, |
| 629 | }, |
| 630 | }, |
| 631 | |
| 632 | { |
| 633 | { }, |
| 634 | { |
| 635 | { normal_normal_300, invalidFontStyle }, |
| 636 | { normal_normal_400, invalidFontStyle }, |
| 637 | { normal_normal_500, invalidFontStyle }, |
| 638 | { normal_normal_600, invalidFontStyle }, |
| 639 | }, |
| 640 | }, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 641 | { |
| 642 | { expanded_normal_100,expanded_normal_900, |
| 643 | expanded_italic_100,expanded_italic_900, |
| 644 | expanded_obliqu_100,expanded_obliqu_900, }, |
| 645 | { |
| 646 | { condensed_normal_100, expanded_normal_100 }, |
| 647 | { condensed_normal_900, expanded_normal_900 }, |
| 648 | { condensed_italic_100, expanded_italic_100 }, |
| 649 | { condensed_italic_900, expanded_italic_900 }, |
| 650 | { condensed_obliqu_100, expanded_obliqu_100 }, |
| 651 | { condensed_obliqu_900, expanded_obliqu_900 }, |
| 652 | { expanded_normal_100, expanded_normal_100 }, |
| 653 | { expanded_normal_900, expanded_normal_900 }, |
| 654 | { expanded_italic_100, expanded_italic_100 }, |
| 655 | { expanded_italic_900, expanded_italic_900 }, |
| 656 | { expanded_obliqu_100, expanded_obliqu_100 }, |
| 657 | { expanded_obliqu_900, expanded_obliqu_900 }, |
| 658 | }, |
| 659 | }, |
| 660 | { |
| 661 | { expanded_normal_100,expanded_normal_900, |
| 662 | expanded_obliqu_100,expanded_obliqu_900, }, |
| 663 | { |
| 664 | { condensed_normal_100, expanded_normal_100 }, |
| 665 | { condensed_normal_900, expanded_normal_900 }, |
| 666 | { condensed_italic_100, expanded_obliqu_100 }, |
| 667 | { condensed_italic_900, expanded_obliqu_900 }, |
| 668 | { condensed_obliqu_100, expanded_obliqu_100 }, |
| 669 | { condensed_obliqu_900, expanded_obliqu_900 }, |
| 670 | { expanded_normal_100, expanded_normal_100 }, |
| 671 | { expanded_normal_900, expanded_normal_900 }, |
| 672 | { expanded_italic_100, expanded_obliqu_100 }, |
| 673 | { expanded_italic_900, expanded_obliqu_900 }, |
| 674 | { expanded_obliqu_100, expanded_obliqu_100 }, |
| 675 | { expanded_obliqu_900, expanded_obliqu_900 }, |
| 676 | }, |
| 677 | }, |
| 678 | { |
| 679 | { expanded_italic_100,expanded_italic_900, |
| 680 | expanded_obliqu_100,expanded_obliqu_900, }, |
| 681 | { |
| 682 | { condensed_normal_100, expanded_obliqu_100 }, |
| 683 | { condensed_normal_900, expanded_obliqu_900 }, |
| 684 | { condensed_italic_100, expanded_italic_100 }, |
| 685 | { condensed_italic_900, expanded_italic_900 }, |
| 686 | { condensed_obliqu_100, expanded_obliqu_100 }, |
| 687 | { condensed_obliqu_900, expanded_obliqu_900 }, |
| 688 | { expanded_normal_100, expanded_obliqu_100 }, |
| 689 | { expanded_normal_900, expanded_obliqu_900 }, |
| 690 | { expanded_italic_100, expanded_italic_100 }, |
| 691 | { expanded_italic_900, expanded_italic_900 }, |
| 692 | { expanded_obliqu_100, expanded_obliqu_100 }, |
| 693 | { expanded_obliqu_900, expanded_obliqu_900 }, |
| 694 | }, |
| 695 | }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 696 | }; |
| 697 | |
| 698 | for (StyleSetTest& test : tests) { |
Mike Klein | 6ad9909 | 2016-10-26 10:35:22 -0400 | [diff] [blame] | 699 | for (const StyleSetTest::Case& testCase : test.cases) { |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 700 | sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern)); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 701 | if (typeface) { |
| 702 | REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult); |
| 703 | } else { |
| 704 | REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult); |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | |
reed@google.com | 66c9f99 | 2013-04-11 19:04:34 +0000 | [diff] [blame] | 710 | DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 711 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 712 | DEF_TEST(FontMgr, reporter) { |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 713 | test_matchStyleCSS3(reporter); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 714 | test_fontiter(reporter, FLAGS_verboseFontMgr); |
reed@google.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 715 | test_alias_names(reporter); |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 716 | test_font(reporter); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 717 | } |