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 | } |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 153 | int onGetTableTags(SkFontTableTag tags[]) const override { return 0; } |
| 154 | size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override { |
| 155 | return 0; |
| 156 | } |
| 157 | }; |
| 158 | |
| 159 | class TestFontStyleSet : public SkFontStyleSet { |
| 160 | public: |
| 161 | TestFontStyleSet(std::initializer_list<SkFontStyle> styles) : fStyles(styles) {} |
| 162 | int count() override { return static_cast<int>(fStyles.size()); } |
| 163 | void getStyle(int index, SkFontStyle* style, SkString*) override { |
| 164 | if (style) { |
| 165 | *style = fStyles[index]; |
| 166 | } |
| 167 | } |
| 168 | SkTypeface* createTypeface(int index) override { |
| 169 | if (index < 0 || this->count() <= index) { |
bungeman | e3aea10 | 2016-07-13 05:16:58 -0700 | [diff] [blame] | 170 | return new TestTypeface(invalidFontStyle); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 171 | } |
bungeman | e3aea10 | 2016-07-13 05:16:58 -0700 | [diff] [blame] | 172 | return new TestTypeface(fStyles[index]); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 173 | } |
| 174 | SkTypeface* matchStyle(const SkFontStyle& pattern) override { |
| 175 | return this->matchStyleCSS3(pattern); |
| 176 | } |
| 177 | private: |
| 178 | std::vector<SkFontStyle> fStyles; |
| 179 | }; |
| 180 | |
| 181 | SkFontStyle condensed_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant); |
| 182 | SkFontStyle condensed_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kUpright_Slant); |
| 183 | SkFontStyle condensed_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant); |
| 184 | SkFontStyle condensed_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kItalic_Slant); |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 185 | SkFontStyle condensed_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant); |
| 186 | SkFontStyle condensed_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kCondensed_Width, SkFontStyle::kOblique_Slant); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 187 | SkFontStyle expanded_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant); |
| 188 | SkFontStyle expanded_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kUpright_Slant); |
| 189 | SkFontStyle expanded_italic_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant); |
| 190 | SkFontStyle expanded_italic_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kItalic_Slant); |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 191 | SkFontStyle expanded_obliqu_100(SkFontStyle::kThin_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant); |
| 192 | SkFontStyle expanded_obliqu_900(SkFontStyle::kBlack_Weight, SkFontStyle::kExpanded_Width, SkFontStyle::kOblique_Slant); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 193 | |
| 194 | SkFontStyle normal_normal_100(SkFontStyle::kThin_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 195 | SkFontStyle normal_normal_200(SkFontStyle::kExtraLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 196 | SkFontStyle normal_normal_300(SkFontStyle::kLight_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 197 | SkFontStyle normal_normal_400(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 198 | SkFontStyle normal_normal_500(SkFontStyle::kMedium_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 199 | SkFontStyle normal_normal_600(SkFontStyle::kSemiBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 200 | SkFontStyle normal_normal_700(SkFontStyle::kBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 201 | SkFontStyle normal_normal_800(SkFontStyle::kExtraBold_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 202 | SkFontStyle normal_normal_900(SkFontStyle::kBlack_Weight, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant); |
| 203 | |
| 204 | struct StyleSetTest { |
| 205 | TestFontStyleSet styleSet; |
| 206 | struct Case { |
| 207 | SkFontStyle pattern; |
| 208 | SkFontStyle expectedResult; |
| 209 | }; |
| 210 | std::vector<Case> cases; |
| 211 | } tests[] = { |
| 212 | { |
| 213 | { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900, |
| 214 | expanded_normal_100, expanded_normal_900, expanded_italic_100, expanded_italic_900 }, |
| 215 | { |
| 216 | { condensed_normal_100, condensed_normal_100 }, |
| 217 | { condensed_normal_900, condensed_normal_900 }, |
| 218 | { condensed_italic_100, condensed_italic_100 }, |
| 219 | { condensed_italic_900, condensed_italic_900 }, |
| 220 | { expanded_normal_100, expanded_normal_100 }, |
| 221 | { expanded_normal_900, expanded_normal_900 }, |
| 222 | { expanded_italic_100, expanded_italic_100 }, |
| 223 | { expanded_italic_900, expanded_italic_900 }, |
| 224 | }, |
| 225 | }, |
| 226 | |
| 227 | { |
| 228 | { condensed_normal_100,condensed_italic_100,expanded_normal_100,expanded_italic_100 }, |
| 229 | { |
| 230 | { condensed_normal_100, condensed_normal_100 }, |
| 231 | { condensed_normal_900, condensed_normal_100 }, |
| 232 | { condensed_italic_100, condensed_italic_100 }, |
| 233 | { condensed_italic_900, condensed_italic_100 }, |
| 234 | { expanded_normal_100, expanded_normal_100 }, |
| 235 | { expanded_normal_900, expanded_normal_100 }, |
| 236 | { expanded_italic_100, expanded_italic_100 }, |
| 237 | { expanded_italic_900, expanded_italic_100 }, |
| 238 | }, |
| 239 | }, |
| 240 | |
| 241 | { |
| 242 | { condensed_normal_900,condensed_italic_900,expanded_normal_900,expanded_italic_900 }, |
| 243 | { |
| 244 | { condensed_normal_100, condensed_normal_900 }, |
| 245 | { condensed_normal_900, condensed_normal_900 }, |
| 246 | { condensed_italic_100, condensed_italic_900 }, |
| 247 | { condensed_italic_900, condensed_italic_900 }, |
| 248 | { expanded_normal_100, expanded_normal_900 }, |
| 249 | { expanded_normal_900, expanded_normal_900 }, |
| 250 | { expanded_italic_100, expanded_italic_900 }, |
| 251 | { expanded_italic_900, expanded_italic_900 }, |
| 252 | }, |
| 253 | }, |
| 254 | |
| 255 | { |
| 256 | { condensed_normal_100,condensed_normal_900,expanded_normal_100,expanded_normal_900 }, |
| 257 | { |
| 258 | { condensed_normal_100, condensed_normal_100 }, |
| 259 | { condensed_normal_900, condensed_normal_900 }, |
| 260 | { condensed_italic_100, condensed_normal_100 }, |
| 261 | { condensed_italic_900, condensed_normal_900 }, |
| 262 | { expanded_normal_100, expanded_normal_100 }, |
| 263 | { expanded_normal_900, expanded_normal_900 }, |
| 264 | { expanded_italic_100, expanded_normal_100 }, |
| 265 | { expanded_italic_900, expanded_normal_900 }, |
| 266 | }, |
| 267 | }, |
| 268 | |
| 269 | { |
| 270 | { condensed_normal_100,expanded_normal_100 }, |
| 271 | { |
| 272 | { condensed_normal_100, condensed_normal_100 }, |
| 273 | { condensed_normal_900, condensed_normal_100 }, |
| 274 | { condensed_italic_100, condensed_normal_100 }, |
| 275 | { condensed_italic_900, condensed_normal_100 }, |
| 276 | { expanded_normal_100, expanded_normal_100 }, |
| 277 | { expanded_normal_900, expanded_normal_100 }, |
| 278 | { expanded_italic_100, expanded_normal_100 }, |
| 279 | { expanded_italic_900, expanded_normal_100 }, |
| 280 | }, |
| 281 | }, |
| 282 | |
| 283 | { |
| 284 | { condensed_normal_900,expanded_normal_900 }, |
| 285 | { |
| 286 | { condensed_normal_100, condensed_normal_900 }, |
| 287 | { condensed_normal_900, condensed_normal_900 }, |
| 288 | { condensed_italic_100, condensed_normal_900 }, |
| 289 | { condensed_italic_900, condensed_normal_900 }, |
| 290 | { expanded_normal_100, expanded_normal_900 }, |
| 291 | { expanded_normal_900, expanded_normal_900 }, |
| 292 | { expanded_italic_100, expanded_normal_900 }, |
| 293 | { expanded_italic_900, expanded_normal_900 }, |
| 294 | }, |
| 295 | }, |
| 296 | |
| 297 | { |
| 298 | { condensed_italic_100,condensed_italic_900,expanded_italic_100,expanded_italic_900 }, |
| 299 | { |
| 300 | { condensed_normal_100, condensed_italic_100 }, |
| 301 | { condensed_normal_900, condensed_italic_900 }, |
| 302 | { condensed_italic_100, condensed_italic_100 }, |
| 303 | { condensed_italic_900, condensed_italic_900 }, |
| 304 | { expanded_normal_100, expanded_italic_100 }, |
| 305 | { expanded_normal_900, expanded_italic_900 }, |
| 306 | { expanded_italic_100, expanded_italic_100 }, |
| 307 | { expanded_italic_900, expanded_italic_900 }, |
| 308 | }, |
| 309 | }, |
| 310 | |
| 311 | { |
| 312 | { condensed_italic_100,expanded_italic_100 }, |
| 313 | { |
| 314 | { condensed_normal_100, condensed_italic_100 }, |
| 315 | { condensed_normal_900, condensed_italic_100 }, |
| 316 | { condensed_italic_100, condensed_italic_100 }, |
| 317 | { condensed_italic_900, condensed_italic_100 }, |
| 318 | { expanded_normal_100, expanded_italic_100 }, |
| 319 | { expanded_normal_900, expanded_italic_100 }, |
| 320 | { expanded_italic_100, expanded_italic_100 }, |
| 321 | { expanded_italic_900, expanded_italic_100 }, |
| 322 | }, |
| 323 | }, |
| 324 | |
| 325 | { |
| 326 | { condensed_italic_900,expanded_italic_900 }, |
| 327 | { |
| 328 | { condensed_normal_100, condensed_italic_900 }, |
| 329 | { condensed_normal_900, condensed_italic_900 }, |
| 330 | { condensed_italic_100, condensed_italic_900 }, |
| 331 | { condensed_italic_900, condensed_italic_900 }, |
| 332 | { expanded_normal_100, expanded_italic_900 }, |
| 333 | { expanded_normal_900, expanded_italic_900 }, |
| 334 | { expanded_italic_100, expanded_italic_900 }, |
| 335 | { expanded_italic_900, expanded_italic_900 }, |
| 336 | }, |
| 337 | }, |
| 338 | |
| 339 | { |
| 340 | { condensed_normal_100,condensed_normal_900,condensed_italic_100,condensed_italic_900 }, |
| 341 | { |
| 342 | { condensed_normal_100, condensed_normal_100 }, |
| 343 | { condensed_normal_900, condensed_normal_900 }, |
| 344 | { condensed_italic_100, condensed_italic_100 }, |
| 345 | { condensed_italic_900, condensed_italic_900 }, |
| 346 | { expanded_normal_100, condensed_normal_100 }, |
| 347 | { expanded_normal_900, condensed_normal_900 }, |
| 348 | { expanded_italic_100, condensed_italic_100 }, |
| 349 | { expanded_italic_900, condensed_italic_900 }, |
| 350 | }, |
| 351 | }, |
| 352 | |
| 353 | { |
| 354 | { condensed_normal_100,condensed_italic_100 }, |
| 355 | { |
| 356 | { condensed_normal_100, condensed_normal_100 }, |
| 357 | { condensed_normal_900, condensed_normal_100 }, |
| 358 | { condensed_italic_100, condensed_italic_100 }, |
| 359 | { condensed_italic_900, condensed_italic_100 }, |
| 360 | { expanded_normal_100, condensed_normal_100 }, |
| 361 | { expanded_normal_900, condensed_normal_100 }, |
| 362 | { expanded_italic_100, condensed_italic_100 }, |
| 363 | { expanded_italic_900, condensed_italic_100 }, |
| 364 | }, |
| 365 | }, |
| 366 | |
| 367 | { |
| 368 | { condensed_normal_900,condensed_italic_900 }, |
| 369 | { |
| 370 | { condensed_normal_100, condensed_normal_900 }, |
| 371 | { condensed_normal_900, condensed_normal_900 }, |
| 372 | { condensed_italic_100, condensed_italic_900 }, |
| 373 | { condensed_italic_900, condensed_italic_900 }, |
| 374 | { expanded_normal_100, condensed_normal_900 }, |
| 375 | { expanded_normal_900, condensed_normal_900 }, |
| 376 | { expanded_italic_100, condensed_italic_900 }, |
| 377 | { expanded_italic_900, condensed_italic_900 }, |
| 378 | }, |
| 379 | }, |
| 380 | |
| 381 | { |
| 382 | { condensed_normal_100,condensed_normal_900 }, |
| 383 | { |
| 384 | { condensed_normal_100, condensed_normal_100 }, |
| 385 | { condensed_normal_900, condensed_normal_900 }, |
| 386 | { condensed_italic_100, condensed_normal_100 }, |
| 387 | { condensed_italic_900, condensed_normal_900 }, |
| 388 | { expanded_normal_100, condensed_normal_100 }, |
| 389 | { expanded_normal_900, condensed_normal_900 }, |
| 390 | { expanded_italic_100, condensed_normal_100 }, |
| 391 | { expanded_italic_900, condensed_normal_900 }, |
| 392 | }, |
| 393 | }, |
| 394 | |
| 395 | { |
| 396 | { condensed_normal_100 }, |
| 397 | { |
| 398 | { condensed_normal_100, condensed_normal_100 }, |
| 399 | { condensed_normal_900, condensed_normal_100 }, |
| 400 | { condensed_italic_100, condensed_normal_100 }, |
| 401 | { condensed_italic_900, condensed_normal_100 }, |
| 402 | { expanded_normal_100, condensed_normal_100 }, |
| 403 | { expanded_normal_900, condensed_normal_100 }, |
| 404 | { expanded_italic_100, condensed_normal_100 }, |
| 405 | { expanded_italic_900, condensed_normal_100 }, |
| 406 | }, |
| 407 | }, |
| 408 | |
| 409 | { |
| 410 | { condensed_normal_900 }, |
| 411 | { |
| 412 | { condensed_normal_100, condensed_normal_900 }, |
| 413 | { condensed_normal_900, condensed_normal_900 }, |
| 414 | { condensed_italic_100, condensed_normal_900 }, |
| 415 | { condensed_italic_900, condensed_normal_900 }, |
| 416 | { expanded_normal_100, condensed_normal_900 }, |
| 417 | { expanded_normal_900, condensed_normal_900 }, |
| 418 | { expanded_italic_100, condensed_normal_900 }, |
| 419 | { expanded_italic_900, condensed_normal_900 }, |
| 420 | }, |
| 421 | }, |
| 422 | |
| 423 | { |
| 424 | { condensed_italic_100,condensed_italic_900 }, |
| 425 | { |
| 426 | { condensed_normal_100, condensed_italic_100 }, |
| 427 | { condensed_normal_900, condensed_italic_900 }, |
| 428 | { condensed_italic_100, condensed_italic_100 }, |
| 429 | { condensed_italic_900, condensed_italic_900 }, |
| 430 | { expanded_normal_100, condensed_italic_100 }, |
| 431 | { expanded_normal_900, condensed_italic_900 }, |
| 432 | { expanded_italic_100, condensed_italic_100 }, |
| 433 | { expanded_italic_900, condensed_italic_900 }, |
| 434 | }, |
| 435 | }, |
| 436 | |
| 437 | { |
| 438 | { condensed_italic_100 }, |
| 439 | { |
| 440 | { condensed_normal_100, condensed_italic_100 }, |
| 441 | { condensed_normal_900, condensed_italic_100 }, |
| 442 | { condensed_italic_100, condensed_italic_100 }, |
| 443 | { condensed_italic_900, condensed_italic_100 }, |
| 444 | { expanded_normal_100, condensed_italic_100 }, |
| 445 | { expanded_normal_900, condensed_italic_100 }, |
| 446 | { expanded_italic_100, condensed_italic_100 }, |
| 447 | { expanded_italic_900, condensed_italic_100 }, |
| 448 | }, |
| 449 | }, |
| 450 | |
| 451 | { |
| 452 | { condensed_italic_900 }, |
| 453 | { |
| 454 | { condensed_normal_100, condensed_italic_900 }, |
| 455 | { condensed_normal_900, condensed_italic_900 }, |
| 456 | { condensed_italic_100, condensed_italic_900 }, |
| 457 | { condensed_italic_900, condensed_italic_900 }, |
| 458 | { expanded_normal_100, condensed_italic_900 }, |
| 459 | { expanded_normal_900, condensed_italic_900 }, |
| 460 | { expanded_italic_100, condensed_italic_900 }, |
| 461 | { expanded_italic_900, condensed_italic_900 }, |
| 462 | }, |
| 463 | }, |
| 464 | |
| 465 | { |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 466 | { expanded_normal_100,expanded_normal_900, |
| 467 | expanded_italic_100,expanded_italic_900 }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 468 | { |
| 469 | { condensed_normal_100, expanded_normal_100 }, |
| 470 | { condensed_normal_900, expanded_normal_900 }, |
| 471 | { condensed_italic_100, expanded_italic_100 }, |
| 472 | { condensed_italic_900, expanded_italic_900 }, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 473 | { condensed_obliqu_100, expanded_italic_100 }, |
| 474 | { condensed_obliqu_900, expanded_italic_900 }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 475 | { expanded_normal_100, expanded_normal_100 }, |
| 476 | { expanded_normal_900, expanded_normal_900 }, |
| 477 | { expanded_italic_100, expanded_italic_100 }, |
| 478 | { expanded_italic_900, expanded_italic_900 }, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 479 | { expanded_obliqu_100, expanded_italic_100 }, |
| 480 | { expanded_obliqu_900, expanded_italic_900 }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 481 | }, |
| 482 | }, |
| 483 | |
| 484 | { |
| 485 | { expanded_normal_100,expanded_italic_100 }, |
| 486 | { |
| 487 | { condensed_normal_100, expanded_normal_100 }, |
| 488 | { condensed_normal_900, expanded_normal_100 }, |
| 489 | { condensed_italic_100, expanded_italic_100 }, |
| 490 | { condensed_italic_900, expanded_italic_100 }, |
| 491 | { expanded_normal_100, expanded_normal_100 }, |
| 492 | { expanded_normal_900, expanded_normal_100 }, |
| 493 | { expanded_italic_100, expanded_italic_100 }, |
| 494 | { expanded_italic_900, expanded_italic_100 }, |
| 495 | }, |
| 496 | }, |
| 497 | |
| 498 | { |
| 499 | { expanded_normal_900,expanded_italic_900 }, |
| 500 | { |
| 501 | { condensed_normal_100, expanded_normal_900 }, |
| 502 | { condensed_normal_900, expanded_normal_900 }, |
| 503 | { condensed_italic_100, expanded_italic_900 }, |
| 504 | { condensed_italic_900, expanded_italic_900 }, |
| 505 | { expanded_normal_100, expanded_normal_900 }, |
| 506 | { expanded_normal_900, expanded_normal_900 }, |
| 507 | { expanded_italic_100, expanded_italic_900 }, |
| 508 | { expanded_italic_900, expanded_italic_900 }, |
| 509 | }, |
| 510 | }, |
| 511 | |
| 512 | { |
| 513 | { expanded_normal_100,expanded_normal_900 }, |
| 514 | { |
| 515 | { condensed_normal_100, expanded_normal_100 }, |
| 516 | { condensed_normal_900, expanded_normal_900 }, |
| 517 | { condensed_italic_100, expanded_normal_100 }, |
| 518 | { condensed_italic_900, expanded_normal_900 }, |
| 519 | { expanded_normal_100, expanded_normal_100 }, |
| 520 | { expanded_normal_900, expanded_normal_900 }, |
| 521 | { expanded_italic_100, expanded_normal_100 }, |
| 522 | { expanded_italic_900, expanded_normal_900 }, |
| 523 | }, |
| 524 | }, |
| 525 | |
| 526 | { |
| 527 | { expanded_normal_100 }, |
| 528 | { |
| 529 | { condensed_normal_100, expanded_normal_100 }, |
| 530 | { condensed_normal_900, expanded_normal_100 }, |
| 531 | { condensed_italic_100, expanded_normal_100 }, |
| 532 | { condensed_italic_900, expanded_normal_100 }, |
| 533 | { expanded_normal_100, expanded_normal_100 }, |
| 534 | { expanded_normal_900, expanded_normal_100 }, |
| 535 | { expanded_italic_100, expanded_normal_100 }, |
| 536 | { expanded_italic_900, expanded_normal_100 }, |
| 537 | }, |
| 538 | }, |
| 539 | |
| 540 | { |
| 541 | { expanded_normal_900 }, |
| 542 | { |
| 543 | { condensed_normal_100, expanded_normal_900 }, |
| 544 | { condensed_normal_900, expanded_normal_900 }, |
| 545 | { condensed_italic_100, expanded_normal_900 }, |
| 546 | { condensed_italic_900, expanded_normal_900 }, |
| 547 | { expanded_normal_100, expanded_normal_900 }, |
| 548 | { expanded_normal_900, expanded_normal_900 }, |
| 549 | { expanded_italic_100, expanded_normal_900 }, |
| 550 | { expanded_italic_900, expanded_normal_900 }, |
| 551 | }, |
| 552 | }, |
| 553 | |
| 554 | { |
| 555 | { expanded_italic_100,expanded_italic_900 }, |
| 556 | { |
| 557 | { condensed_normal_100, expanded_italic_100 }, |
| 558 | { condensed_normal_900, expanded_italic_900 }, |
| 559 | { condensed_italic_100, expanded_italic_100 }, |
| 560 | { condensed_italic_900, expanded_italic_900 }, |
| 561 | { expanded_normal_100, expanded_italic_100 }, |
| 562 | { expanded_normal_900, expanded_italic_900 }, |
| 563 | { expanded_italic_100, expanded_italic_100 }, |
| 564 | { expanded_italic_900, expanded_italic_900 }, |
| 565 | }, |
| 566 | }, |
| 567 | |
| 568 | { |
| 569 | { expanded_italic_100 }, |
| 570 | { |
| 571 | { condensed_normal_100, expanded_italic_100 }, |
| 572 | { condensed_normal_900, expanded_italic_100 }, |
| 573 | { condensed_italic_100, expanded_italic_100 }, |
| 574 | { condensed_italic_900, expanded_italic_100 }, |
| 575 | { expanded_normal_100, expanded_italic_100 }, |
| 576 | { expanded_normal_900, expanded_italic_100 }, |
| 577 | { expanded_italic_100, expanded_italic_100 }, |
| 578 | { expanded_italic_900, expanded_italic_100 }, |
| 579 | }, |
| 580 | }, |
| 581 | |
| 582 | { |
| 583 | { expanded_italic_900 }, |
| 584 | { |
| 585 | { condensed_normal_100, expanded_italic_900 }, |
| 586 | { condensed_normal_900, expanded_italic_900 }, |
| 587 | { condensed_italic_100, expanded_italic_900 }, |
| 588 | { condensed_italic_900, expanded_italic_900 }, |
| 589 | { expanded_normal_100, expanded_italic_900 }, |
| 590 | { expanded_normal_900, expanded_italic_900 }, |
| 591 | { expanded_italic_100, expanded_italic_900 }, |
| 592 | { expanded_italic_900, expanded_italic_900 }, |
| 593 | }, |
| 594 | }, |
| 595 | |
| 596 | { |
| 597 | { normal_normal_100, normal_normal_900 }, |
| 598 | { |
| 599 | { normal_normal_300, normal_normal_100 }, |
| 600 | { normal_normal_400, normal_normal_100 }, |
| 601 | { normal_normal_500, normal_normal_100 }, |
| 602 | { normal_normal_600, normal_normal_900 }, |
| 603 | }, |
| 604 | }, |
| 605 | |
| 606 | { |
| 607 | { normal_normal_100, normal_normal_400, normal_normal_900 }, |
| 608 | { |
| 609 | { normal_normal_300, normal_normal_100 }, |
| 610 | { normal_normal_400, normal_normal_400 }, |
| 611 | { normal_normal_500, normal_normal_400 }, |
| 612 | { normal_normal_600, normal_normal_900 }, |
| 613 | }, |
| 614 | }, |
| 615 | |
| 616 | { |
| 617 | { normal_normal_100, normal_normal_500, normal_normal_900 }, |
| 618 | { |
| 619 | { normal_normal_300, normal_normal_100 }, |
| 620 | { normal_normal_400, normal_normal_500 }, |
| 621 | { normal_normal_500, normal_normal_500 }, |
| 622 | { normal_normal_600, normal_normal_900 }, |
| 623 | }, |
| 624 | }, |
| 625 | |
| 626 | { |
| 627 | { }, |
| 628 | { |
| 629 | { normal_normal_300, invalidFontStyle }, |
| 630 | { normal_normal_400, invalidFontStyle }, |
| 631 | { normal_normal_500, invalidFontStyle }, |
| 632 | { normal_normal_600, invalidFontStyle }, |
| 633 | }, |
| 634 | }, |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 635 | { |
| 636 | { expanded_normal_100,expanded_normal_900, |
| 637 | expanded_italic_100,expanded_italic_900, |
| 638 | expanded_obliqu_100,expanded_obliqu_900, }, |
| 639 | { |
| 640 | { condensed_normal_100, expanded_normal_100 }, |
| 641 | { condensed_normal_900, expanded_normal_900 }, |
| 642 | { condensed_italic_100, expanded_italic_100 }, |
| 643 | { condensed_italic_900, expanded_italic_900 }, |
| 644 | { condensed_obliqu_100, expanded_obliqu_100 }, |
| 645 | { condensed_obliqu_900, expanded_obliqu_900 }, |
| 646 | { expanded_normal_100, expanded_normal_100 }, |
| 647 | { expanded_normal_900, expanded_normal_900 }, |
| 648 | { expanded_italic_100, expanded_italic_100 }, |
| 649 | { expanded_italic_900, expanded_italic_900 }, |
| 650 | { expanded_obliqu_100, expanded_obliqu_100 }, |
| 651 | { expanded_obliqu_900, expanded_obliqu_900 }, |
| 652 | }, |
| 653 | }, |
| 654 | { |
| 655 | { expanded_normal_100,expanded_normal_900, |
| 656 | expanded_obliqu_100,expanded_obliqu_900, }, |
| 657 | { |
| 658 | { condensed_normal_100, expanded_normal_100 }, |
| 659 | { condensed_normal_900, expanded_normal_900 }, |
| 660 | { condensed_italic_100, expanded_obliqu_100 }, |
| 661 | { condensed_italic_900, expanded_obliqu_900 }, |
| 662 | { condensed_obliqu_100, expanded_obliqu_100 }, |
| 663 | { condensed_obliqu_900, expanded_obliqu_900 }, |
| 664 | { expanded_normal_100, expanded_normal_100 }, |
| 665 | { expanded_normal_900, expanded_normal_900 }, |
| 666 | { expanded_italic_100, expanded_obliqu_100 }, |
| 667 | { expanded_italic_900, expanded_obliqu_900 }, |
| 668 | { expanded_obliqu_100, expanded_obliqu_100 }, |
| 669 | { expanded_obliqu_900, expanded_obliqu_900 }, |
| 670 | }, |
| 671 | }, |
| 672 | { |
| 673 | { expanded_italic_100,expanded_italic_900, |
| 674 | expanded_obliqu_100,expanded_obliqu_900, }, |
| 675 | { |
| 676 | { condensed_normal_100, expanded_obliqu_100 }, |
| 677 | { condensed_normal_900, expanded_obliqu_900 }, |
| 678 | { condensed_italic_100, expanded_italic_100 }, |
| 679 | { condensed_italic_900, expanded_italic_900 }, |
| 680 | { condensed_obliqu_100, expanded_obliqu_100 }, |
| 681 | { condensed_obliqu_900, expanded_obliqu_900 }, |
| 682 | { expanded_normal_100, expanded_obliqu_100 }, |
| 683 | { expanded_normal_900, expanded_obliqu_900 }, |
| 684 | { expanded_italic_100, expanded_italic_100 }, |
| 685 | { expanded_italic_900, expanded_italic_900 }, |
| 686 | { expanded_obliqu_100, expanded_obliqu_100 }, |
| 687 | { expanded_obliqu_900, expanded_obliqu_900 }, |
| 688 | }, |
| 689 | }, |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 690 | }; |
| 691 | |
| 692 | for (StyleSetTest& test : tests) { |
Mike Klein | 6ad9909 | 2016-10-26 10:35:22 -0400 | [diff] [blame] | 693 | for (const StyleSetTest::Case& testCase : test.cases) { |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 694 | sk_sp<SkTypeface> typeface(test.styleSet.matchStyle(testCase.pattern)); |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 695 | if (typeface) { |
| 696 | REPORTER_ASSERT(reporter, typeface->fontStyle() == testCase.expectedResult); |
| 697 | } else { |
| 698 | REPORTER_ASSERT(reporter, invalidFontStyle == testCase.expectedResult); |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
reed@google.com | 66c9f99 | 2013-04-11 19:04:34 +0000 | [diff] [blame] | 704 | DEFINE_bool(verboseFontMgr, false, "run verbose fontmgr tests."); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 705 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 706 | DEF_TEST(FontMgr, reporter) { |
bungeman | 147ea2f | 2015-11-12 09:50:08 -0800 | [diff] [blame] | 707 | test_matchStyleCSS3(reporter); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 708 | test_fontiter(reporter, FLAGS_verboseFontMgr); |
reed@google.com | c1a81eb | 2013-09-19 18:06:03 +0000 | [diff] [blame] | 709 | test_alias_names(reporter); |
reed@google.com | 43c2758 | 2014-04-08 15:04:29 +0000 | [diff] [blame] | 710 | test_font(reporter); |
reed@google.com | 83165a5 | 2013-04-11 18:31:25 +0000 | [diff] [blame] | 711 | } |