reed@google.com | af0fa6a | 2013-03-28 13:39:35 +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 | |
| 8 | #include "gm.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkFontMgr.h" |
| 11 | #include "SkGraphics.h" |
| 12 | #include "SkTypeface.h" |
| 13 | |
bungeman@google.com | bfc6cc4 | 2013-08-21 15:20:43 +0000 | [diff] [blame] | 14 | #ifdef SK_BUILD_FOR_WIN |
reed@google.com | d1bcfc9 | 2013-08-28 20:31:58 +0000 | [diff] [blame] | 15 | #include "SkTypeface_win.h" |
bungeman@google.com | bfc6cc4 | 2013-08-21 15:20:43 +0000 | [diff] [blame] | 16 | #endif |
| 17 | |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 18 | // limit this just so we don't take too long to draw |
| 19 | #define MAX_FAMILIES 30 |
| 20 | |
| 21 | static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x, |
| 22 | SkScalar y, const SkPaint& paint) { |
| 23 | canvas->drawText(text.c_str(), text.size(), x, y, paint); |
| 24 | return x + paint.measureText(text.c_str(), text.size()); |
| 25 | } |
| 26 | |
djsollen | 0d393a9 | 2014-08-27 07:03:13 -0700 | [diff] [blame] | 27 | static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x, |
| 28 | SkScalar y, SkPaint& paint, SkFontMgr* fm, |
bungeman | c9232dc | 2014-11-10 13:29:33 -0800 | [diff] [blame] | 29 | const char* fontName, const char* bcp47[], int bcp47Count, |
djsollen | 0d393a9 | 2014-08-27 07:03:13 -0700 | [diff] [blame] | 30 | const SkFontStyle& fontStyle) { |
| 31 | // find typeface containing the requested character and draw it |
| 32 | SkString ch; |
| 33 | ch.appendUnichar(character); |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 34 | sk_sp<SkTypeface> typeface(fm->matchFamilyStyleCharacter(fontName, fontStyle, |
| 35 | bcp47, bcp47Count, character)); |
| 36 | paint.setTypeface(typeface); |
djsollen | 0d393a9 | 2014-08-27 07:03:13 -0700 | [diff] [blame] | 37 | x = drawString(canvas, ch, x, y, paint) + 20; |
| 38 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 39 | if (nullptr == typeface) { |
djsollen | 0d393a9 | 2014-08-27 07:03:13 -0700 | [diff] [blame] | 40 | return x; |
| 41 | } |
| 42 | |
| 43 | // repeat the process, but this time use the family name of the typeface |
| 44 | // from the first pass. This emulates the behavior in Blink where it |
| 45 | // it expects to get the same glyph when following this pattern. |
| 46 | SkString familyName; |
| 47 | typeface->getFamilyName(&familyName); |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 48 | paint.setTypeface(sk_sp<SkTypeface>(fm->legacyCreateTypeface(familyName.c_str(), |
| 49 | typeface->fontStyle()))); |
djsollen | 0d393a9 | 2014-08-27 07:03:13 -0700 | [diff] [blame] | 50 | return drawString(canvas, ch, x, y, paint) + 20; |
| 51 | } |
| 52 | |
bungeman | c9232dc | 2014-11-10 13:29:33 -0800 | [diff] [blame] | 53 | static const char* zh = "zh"; |
| 54 | static const char* ja = "ja"; |
| 55 | |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 56 | class FontMgrGM : public skiagm::GM { |
| 57 | public: |
Ben Wagner | 3546ff1 | 2017-01-03 13:32:36 -0500 | [diff] [blame] | 58 | #ifdef SK_LEGACY_FONTMGR_FACTORY |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 59 | FontMgrGM(SkFontMgr* fontMgr = nullptr) { |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 60 | SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); |
bungeman@google.com | bfc6cc4 | 2013-08-21 15:20:43 +0000 | [diff] [blame] | 61 | |
| 62 | fName.set("fontmgr_iter"); |
bungeman@google.com | 6eddc77 | 2014-03-31 19:18:07 +0000 | [diff] [blame] | 63 | if (fontMgr) { |
bungeman@google.com | bfc6cc4 | 2013-08-21 15:20:43 +0000 | [diff] [blame] | 64 | fName.append("_factory"); |
bungeman@google.com | 6eddc77 | 2014-03-31 19:18:07 +0000 | [diff] [blame] | 65 | fFM.reset(fontMgr); |
bungeman@google.com | bfc6cc4 | 2013-08-21 15:20:43 +0000 | [diff] [blame] | 66 | } else { |
| 67 | fFM.reset(SkFontMgr::RefDefault()); |
| 68 | } |
caryclark | 6531c36 | 2015-07-20 13:38:56 -0700 | [diff] [blame] | 69 | fName.append(sk_tool_utils::platform_os_name()); |
| 70 | fName.append(sk_tool_utils::platform_extra_config("GDI")); |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 71 | } |
Ben Wagner | 3546ff1 | 2017-01-03 13:32:36 -0500 | [diff] [blame] | 72 | #else |
| 73 | FontMgrGM(sk_sp<SkFontMgr> fontMgr = nullptr) { |
| 74 | SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); |
| 75 | |
| 76 | fName.set("fontmgr_iter"); |
| 77 | if (fontMgr) { |
| 78 | fName.append("_factory"); |
| 79 | fFM = std::move(fontMgr); |
| 80 | } else { |
| 81 | fFM = SkFontMgr::RefDefault(); |
| 82 | } |
| 83 | fName.append(sk_tool_utils::platform_os_name()); |
| 84 | fName.append(sk_tool_utils::platform_extra_config("GDI")); |
| 85 | } |
| 86 | #endif |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 87 | |
| 88 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 89 | SkString onShortName() override { |
bungeman@google.com | bfc6cc4 | 2013-08-21 15:20:43 +0000 | [diff] [blame] | 90 | return fName; |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 91 | } |
| 92 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 93 | SkISize onISize() override { |
djsollen | 0d393a9 | 2014-08-27 07:03:13 -0700 | [diff] [blame] | 94 | return SkISize::Make(1536, 768); |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 95 | } |
| 96 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 97 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 98 | SkScalar y = 20; |
| 99 | SkPaint paint; |
| 100 | paint.setAntiAlias(true); |
| 101 | paint.setLCDRenderText(true); |
| 102 | paint.setSubpixelText(true); |
| 103 | paint.setTextSize(17); |
skia.committer@gmail.com | 6acd09e | 2013-03-29 07:01:22 +0000 | [diff] [blame] | 104 | |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 105 | SkFontMgr* fm = fFM.get(); |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 106 | int count = SkMin32(fm->countFamilies(), MAX_FAMILIES); |
| 107 | |
| 108 | for (int i = 0; i < count; ++i) { |
bungeman | c64239a | 2015-04-29 08:15:31 -0700 | [diff] [blame] | 109 | SkString familyName; |
| 110 | fm->getFamilyName(i, &familyName); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 111 | paint.setTypeface(nullptr); |
bungeman | c64239a | 2015-04-29 08:15:31 -0700 | [diff] [blame] | 112 | (void)drawString(canvas, familyName, 20, y, paint); |
skia.committer@gmail.com | 6acd09e | 2013-03-29 07:01:22 +0000 | [diff] [blame] | 113 | |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 114 | SkScalar x = 220; |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 115 | |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 116 | sk_sp<SkFontStyleSet> set(fm->createStyleSet(i)); |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 117 | for (int j = 0; j < set->count(); ++j) { |
| 118 | SkString sname; |
| 119 | SkFontStyle fs; |
| 120 | set->getStyle(j, &fs, &sname); |
bungeman | b4bb7d8 | 2016-04-27 10:21:04 -0700 | [diff] [blame] | 121 | sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.slant()); |
skia.committer@gmail.com | 6acd09e | 2013-03-29 07:01:22 +0000 | [diff] [blame] | 122 | |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 123 | paint.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j))); |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 124 | x = drawString(canvas, sname, x, y, paint) + 20; |
djsollen | 0d393a9 | 2014-08-27 07:03:13 -0700 | [diff] [blame] | 125 | |
| 126 | // check to see that we get different glyphs in japanese and chinese |
bungeman | c64239a | 2015-04-29 08:15:31 -0700 | [diff] [blame] | 127 | x = drawCharacter(canvas, 0x5203, x, y, paint, fm, familyName.c_str(), &zh, 1, fs); |
| 128 | x = drawCharacter(canvas, 0x5203, x, y, paint, fm, familyName.c_str(), &ja, 1, fs); |
djsollen | 0d393a9 | 2014-08-27 07:03:13 -0700 | [diff] [blame] | 129 | // check that emoji characters are found |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 130 | x = drawCharacter(canvas, 0x1f601, x, y, paint, fm, familyName.c_str(), nullptr,0, fs); |
skia.committer@gmail.com | 6acd09e | 2013-03-29 07:01:22 +0000 | [diff] [blame] | 131 | } |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 132 | y += 24; |
| 133 | } |
| 134 | } |
| 135 | |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 136 | private: |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 137 | sk_sp<SkFontMgr> fFM; |
bungeman@google.com | bfc6cc4 | 2013-08-21 15:20:43 +0000 | [diff] [blame] | 138 | SkString fName; |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 139 | typedef GM INHERITED; |
| 140 | }; |
| 141 | |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 142 | class FontMgrMatchGM : public skiagm::GM { |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 143 | sk_sp<SkFontMgr> fFM; |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 144 | |
| 145 | public: |
| 146 | FontMgrMatchGM() : fFM(SkFontMgr::RefDefault()) { |
| 147 | SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); |
| 148 | } |
skia.committer@gmail.com | d55846d | 2013-03-30 07:01:27 +0000 | [diff] [blame] | 149 | |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 150 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 151 | SkString onShortName() override { |
caryclark | 6531c36 | 2015-07-20 13:38:56 -0700 | [diff] [blame] | 152 | SkString name("fontmgr_match"); |
| 153 | name.append(sk_tool_utils::platform_os_name()); |
| 154 | name.append(sk_tool_utils::platform_extra_config("GDI")); |
| 155 | return name; |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 156 | } |
skia.committer@gmail.com | d55846d | 2013-03-30 07:01:27 +0000 | [diff] [blame] | 157 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 158 | SkISize onISize() override { |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 159 | return SkISize::Make(640, 1024); |
| 160 | } |
| 161 | |
| 162 | void iterateFamily(SkCanvas* canvas, const SkPaint& paint, |
| 163 | SkFontStyleSet* fset) { |
| 164 | SkPaint p(paint); |
| 165 | SkScalar y = 0; |
| 166 | |
| 167 | for (int j = 0; j < fset->count(); ++j) { |
| 168 | SkString sname; |
| 169 | SkFontStyle fs; |
| 170 | fset->getStyle(j, &fs, &sname); |
| 171 | |
| 172 | sname.appendf(" [%d %d]", fs.weight(), fs.width()); |
| 173 | |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 174 | p.setTypeface(sk_sp<SkTypeface>(fset->createTypeface(j))); |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 175 | (void)drawString(canvas, sname, 0, y, p); |
| 176 | y += 24; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | void exploreFamily(SkCanvas* canvas, const SkPaint& paint, |
| 181 | SkFontStyleSet* fset) { |
| 182 | SkPaint p(paint); |
| 183 | SkScalar y = 0; |
| 184 | |
| 185 | for (int weight = 100; weight <= 900; weight += 200) { |
| 186 | for (int width = 1; width <= 9; width += 2) { |
| 187 | SkFontStyle fs(weight, width, SkFontStyle::kUpright_Slant); |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 188 | sk_sp<SkTypeface> face(fset->matchStyle(fs)); |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 189 | if (face) { |
| 190 | SkString str; |
| 191 | str.printf("request [%d %d]", fs.weight(), fs.width()); |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 192 | p.setTypeface(std::move(face)); |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 193 | (void)drawString(canvas, str, 0, y, p); |
| 194 | y += 24; |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | } |
skia.committer@gmail.com | d55846d | 2013-03-30 07:01:27 +0000 | [diff] [blame] | 199 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 200 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 201 | SkPaint paint; |
| 202 | paint.setAntiAlias(true); |
| 203 | paint.setLCDRenderText(true); |
| 204 | paint.setSubpixelText(true); |
| 205 | paint.setTextSize(17); |
| 206 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 207 | const char* gNames[] = { |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 208 | "Helvetica Neue", "Arial" |
| 209 | }; |
| 210 | |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 211 | sk_sp<SkFontStyleSet> fset; |
skia.committer@gmail.com | d55846d | 2013-03-30 07:01:27 +0000 | [diff] [blame] | 212 | for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) { |
bungeman@google.com | 9fc5c68 | 2013-11-12 15:25:29 +0000 | [diff] [blame] | 213 | fset.reset(fFM->matchFamily(gNames[i])); |
| 214 | if (fset->count() > 0) { |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 215 | break; |
| 216 | } |
| 217 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 218 | if (nullptr == fset.get()) { |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 219 | return; |
| 220 | } |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 221 | |
| 222 | canvas->translate(20, 40); |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 223 | this->exploreFamily(canvas, paint, fset.get()); |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 224 | canvas->translate(150, 0); |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 225 | this->iterateFamily(canvas, paint, fset.get()); |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 226 | } |
skia.committer@gmail.com | d55846d | 2013-03-30 07:01:27 +0000 | [diff] [blame] | 227 | |
reed@google.com | 964988f | 2013-03-29 14:57:22 +0000 | [diff] [blame] | 228 | private: |
| 229 | typedef GM INHERITED; |
| 230 | }; |
| 231 | |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 232 | class FontMgrBoundsGM : public skiagm::GM { |
| 233 | public: |
reed | 8893e5f | 2014-12-15 13:27:26 -0800 | [diff] [blame] | 234 | FontMgrBoundsGM(double scale, double skew) |
| 235 | : fScaleX(SkDoubleToScalar(scale)) |
| 236 | , fSkewX(SkDoubleToScalar(skew)) |
| 237 | { |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 238 | fName.set("fontmgr_bounds"); |
reed | 8893e5f | 2014-12-15 13:27:26 -0800 | [diff] [blame] | 239 | if (scale != 1 || skew != 0) { |
| 240 | fName.appendf("_%g_%g", scale, skew); |
| 241 | } |
caryclark | 6531c36 | 2015-07-20 13:38:56 -0700 | [diff] [blame] | 242 | fName.append(sk_tool_utils::platform_os_name()); |
| 243 | fName.append(sk_tool_utils::platform_extra_config("GDI")); |
Ben Wagner | 3546ff1 | 2017-01-03 13:32:36 -0500 | [diff] [blame] | 244 | #ifdef SK_LEGACY_FONTMGR_FACTORY |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 245 | fFM.reset(SkFontMgr::RefDefault()); |
Ben Wagner | 3546ff1 | 2017-01-03 13:32:36 -0500 | [diff] [blame] | 246 | #else |
| 247 | fFM = SkFontMgr::RefDefault(); |
| 248 | #endif |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static void show_bounds(SkCanvas* canvas, const SkPaint& paint, SkScalar x, SkScalar y, |
| 252 | SkColor boundsColor) { |
| 253 | const char str[] = "jyHO[]{}@-_&%$"; |
| 254 | |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 255 | for (int i = 0; str[i]; ++i) { |
| 256 | canvas->drawText(&str[i], 1, x, y, paint); |
| 257 | } |
tfarina | aa458fb | 2015-01-05 17:18:51 -0800 | [diff] [blame] | 258 | |
reed | 8893e5f | 2014-12-15 13:27:26 -0800 | [diff] [blame] | 259 | SkRect r = paint.getFontBounds(); |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 260 | r.offset(x, y); |
| 261 | SkPaint p(paint); |
| 262 | p.setColor(boundsColor); |
| 263 | canvas->drawRect(r, p); |
| 264 | } |
| 265 | |
| 266 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 267 | SkString onShortName() override { |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 268 | return fName; |
| 269 | } |
tfarina | aa458fb | 2015-01-05 17:18:51 -0800 | [diff] [blame] | 270 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 271 | SkISize onISize() override { |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 272 | return SkISize::Make(1024, 850); |
| 273 | } |
tfarina | aa458fb | 2015-01-05 17:18:51 -0800 | [diff] [blame] | 274 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 275 | void onDraw(SkCanvas* canvas) override { |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 276 | SkPaint paint; |
| 277 | paint.setAntiAlias(true); |
| 278 | paint.setSubpixelText(true); |
| 279 | paint.setTextSize(100); |
| 280 | paint.setStyle(SkPaint::kStroke_Style); |
reed | 8893e5f | 2014-12-15 13:27:26 -0800 | [diff] [blame] | 281 | paint.setTextScaleX(fScaleX); |
| 282 | paint.setTextSkewX(fSkewX); |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 283 | |
| 284 | const SkColor boundsColors[2] = { SK_ColorRED, SK_ColorBLUE }; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 285 | |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 286 | SkFontMgr* fm = fFM.get(); |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 287 | int count = SkMin32(fm->countFamilies(), 32); |
| 288 | |
| 289 | int index = 0; |
| 290 | SkScalar x = 0, y = 0; |
| 291 | |
| 292 | canvas->translate(80, 120); |
| 293 | |
| 294 | for (int i = 0; i < count; ++i) { |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 295 | sk_sp<SkFontStyleSet> set(fm->createStyleSet(i)); |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 296 | for (int j = 0; j < set->count(); ++j) { |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 297 | paint.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j))); |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 298 | if (paint.getTypeface()) { |
| 299 | show_bounds(canvas, paint, x, y, boundsColors[index & 1]); |
| 300 | index += 1; |
| 301 | x += 160; |
| 302 | if (0 == (index % 6)) { |
| 303 | x = 0; |
| 304 | y += 160; |
| 305 | } |
| 306 | if (index >= 30) { |
| 307 | return; |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | } |
mtklein | 1c40292 | 2015-01-23 11:07:07 -0800 | [diff] [blame] | 313 | |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 314 | private: |
Hal Canary | cefc431 | 2016-11-04 16:26:16 -0400 | [diff] [blame] | 315 | sk_sp<SkFontMgr> fFM; |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 316 | SkString fName; |
reed | 8893e5f | 2014-12-15 13:27:26 -0800 | [diff] [blame] | 317 | SkScalar fScaleX, fSkewX; |
reed | a0c814c | 2014-10-22 13:20:58 -0700 | [diff] [blame] | 318 | typedef GM INHERITED; |
| 319 | }; |
| 320 | |
reed@google.com | af0fa6a | 2013-03-28 13:39:35 +0000 | [diff] [blame] | 321 | ////////////////////////////////////////////////////////////////////////////// |
| 322 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 323 | DEF_GM(return new FontMgrGM;) |
| 324 | DEF_GM(return new FontMgrMatchGM;) |
| 325 | DEF_GM(return new FontMgrBoundsGM(1.0, 0);) |
| 326 | DEF_GM(return new FontMgrBoundsGM(0.75, 0);) |
| 327 | DEF_GM(return new FontMgrBoundsGM(1.0, -0.25);) |
bungeman@google.com | bfc6cc4 | 2013-08-21 15:20:43 +0000 | [diff] [blame] | 328 | |
| 329 | #ifdef SK_BUILD_FOR_WIN |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 330 | DEF_GM(return new FontMgrGM(SkFontMgr_New_DirectWrite());) |
bungeman@google.com | bfc6cc4 | 2013-08-21 15:20:43 +0000 | [diff] [blame] | 331 | #endif |