blob: 8eb24f1a4ccba6cbfe5f3475b9dd13c9ce9fcda8 [file] [log] [blame]
reed@google.comaf0fa6a2013-03-28 13:39:35 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkColor.h"
11#include "include/core/SkFont.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkFontMetrics.h"
13#include "include/core/SkFontMgr.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#include "include/core/SkFontStyle.h"
15#include "include/core/SkFontTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/core/SkGraphics.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040017#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "include/core/SkPath.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040019#include "include/core/SkPoint.h"
20#include "include/core/SkRect.h"
21#include "include/core/SkRefCnt.h"
22#include "include/core/SkScalar.h"
23#include "include/core/SkSize.h"
24#include "include/core/SkString.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "include/core/SkTypeface.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040026#include "include/core/SkTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/core/SkFontPriv.h"
Hal Canarye574f1e2019-07-15 14:01:37 -040028#include "tools/SkMetaData.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050029#include "tools/ToolUtils.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040030
31#include <utility>
reed@google.comaf0fa6a2013-03-28 13:39:35 +000032
33// limit this just so we don't take too long to draw
34#define MAX_FAMILIES 30
35
36static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x,
Mike Reed560d5b32018-12-16 16:36:48 -050037 SkScalar y, const SkFont& font) {
Hal Canary89a644b2019-01-07 09:36:09 -050038 canvas->drawString(text, x, y, font, SkPaint());
Ben Wagner51e15a62019-05-07 15:38:46 -040039 return x + font.measureText(text.c_str(), text.size(), SkTextEncoding::kUTF8);
reed@google.comaf0fa6a2013-03-28 13:39:35 +000040}
41
djsollen0d393a92014-08-27 07:03:13 -070042static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
Mike Reed560d5b32018-12-16 16:36:48 -050043 SkScalar y, const SkFont& origFont, SkFontMgr* fm,
bungemanc9232dc2014-11-10 13:29:33 -080044 const char* fontName, const char* bcp47[], int bcp47Count,
djsollen0d393a92014-08-27 07:03:13 -070045 const SkFontStyle& fontStyle) {
Mike Reed560d5b32018-12-16 16:36:48 -050046 SkFont font = origFont;
djsollen0d393a92014-08-27 07:03:13 -070047 // find typeface containing the requested character and draw it
48 SkString ch;
49 ch.appendUnichar(character);
bungeman13b9c952016-05-12 10:09:30 -070050 sk_sp<SkTypeface> typeface(fm->matchFamilyStyleCharacter(fontName, fontStyle,
51 bcp47, bcp47Count, character));
Mike Reed560d5b32018-12-16 16:36:48 -050052 font.setTypeface(typeface);
53 x = drawString(canvas, ch, x, y, font) + 20;
djsollen0d393a92014-08-27 07:03:13 -070054
halcanary96fcdcc2015-08-27 07:41:13 -070055 if (nullptr == typeface) {
djsollen0d393a92014-08-27 07:03:13 -070056 return x;
57 }
58
59 // repeat the process, but this time use the family name of the typeface
60 // from the first pass. This emulates the behavior in Blink where it
61 // it expects to get the same glyph when following this pattern.
62 SkString familyName;
63 typeface->getFamilyName(&familyName);
Mike Reed560d5b32018-12-16 16:36:48 -050064 font.setTypeface(fm->legacyMakeTypeface(familyName.c_str(), typeface->fontStyle()));
65 return drawString(canvas, ch, x, y, font) + 20;
djsollen0d393a92014-08-27 07:03:13 -070066}
67
bungemanc9232dc2014-11-10 13:29:33 -080068static const char* zh = "zh";
69static const char* ja = "ja";
70
reed@google.comaf0fa6a2013-03-28 13:39:35 +000071class FontMgrGM : public skiagm::GM {
Hal Canary594fe852019-07-18 13:35:49 -040072 sk_sp<SkFontMgr> fFM;
Ben Wagner3546ff12017-01-03 13:32:36 -050073
Hal Canary594fe852019-07-18 13:35:49 -040074 void onOnceBeforeDraw() override {
75 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
Mike Klein8073e792017-11-13 18:10:54 -050076 fFM = SkFontMgr::RefDefault();
Ben Wagner3546ff12017-01-03 13:32:36 -050077 }
reed@google.comaf0fa6a2013-03-28 13:39:35 +000078
Hal Canary594fe852019-07-18 13:35:49 -040079 SkString onShortName() override { return SkString("fontmgr_iter"); }
reed@google.comaf0fa6a2013-03-28 13:39:35 +000080
Hal Canary594fe852019-07-18 13:35:49 -040081 SkISize onISize() override { return {1536, 768}; }
reed@google.comaf0fa6a2013-03-28 13:39:35 +000082
mtklein36352bf2015-03-25 18:17:31 -070083 void onDraw(SkCanvas* canvas) override {
reed@google.comaf0fa6a2013-03-28 13:39:35 +000084 SkScalar y = 20;
Mike Reed560d5b32018-12-16 16:36:48 -050085 SkFont font;
86 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
87 font.setSubpixel(true);
88 font.setSize(17);
skia.committer@gmail.com6acd09e2013-03-29 07:01:22 +000089
Hal Canarycefc4312016-11-04 16:26:16 -040090 SkFontMgr* fm = fFM.get();
reed@google.comaf0fa6a2013-03-28 13:39:35 +000091 int count = SkMin32(fm->countFamilies(), MAX_FAMILIES);
92
93 for (int i = 0; i < count; ++i) {
bungemanc64239a2015-04-29 08:15:31 -070094 SkString familyName;
95 fm->getFamilyName(i, &familyName);
Mike Reed560d5b32018-12-16 16:36:48 -050096 font.setTypeface(nullptr);
97 (void)drawString(canvas, familyName, 20, y, font);
skia.committer@gmail.com6acd09e2013-03-29 07:01:22 +000098
reed@google.comaf0fa6a2013-03-28 13:39:35 +000099 SkScalar x = 220;
reed@google.com964988f2013-03-29 14:57:22 +0000100
Hal Canarycefc4312016-11-04 16:26:16 -0400101 sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
reed@google.comaf0fa6a2013-03-28 13:39:35 +0000102 for (int j = 0; j < set->count(); ++j) {
103 SkString sname;
104 SkFontStyle fs;
105 set->getStyle(j, &fs, &sname);
bungemanb4bb7d82016-04-27 10:21:04 -0700106 sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.slant());
skia.committer@gmail.com6acd09e2013-03-29 07:01:22 +0000107
Mike Reed560d5b32018-12-16 16:36:48 -0500108 font.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j)));
109 x = drawString(canvas, sname, x, y, font) + 20;
djsollen0d393a92014-08-27 07:03:13 -0700110
111 // check to see that we get different glyphs in japanese and chinese
Mike Reed560d5b32018-12-16 16:36:48 -0500112 x = drawCharacter(canvas, 0x5203, x, y, font, fm, familyName.c_str(), &zh, 1, fs);
113 x = drawCharacter(canvas, 0x5203, x, y, font, fm, familyName.c_str(), &ja, 1, fs);
djsollen0d393a92014-08-27 07:03:13 -0700114 // check that emoji characters are found
Mike Reed560d5b32018-12-16 16:36:48 -0500115 x = drawCharacter(canvas, 0x1f601, x, y, font, fm, familyName.c_str(), nullptr,0, fs);
skia.committer@gmail.com6acd09e2013-03-29 07:01:22 +0000116 }
reed@google.comaf0fa6a2013-03-28 13:39:35 +0000117 y += 24;
118 }
119 }
reed@google.comaf0fa6a2013-03-28 13:39:35 +0000120};
121
reed@google.com964988f2013-03-29 14:57:22 +0000122class FontMgrMatchGM : public skiagm::GM {
Hal Canarycefc4312016-11-04 16:26:16 -0400123 sk_sp<SkFontMgr> fFM;
reed@google.com964988f2013-03-29 14:57:22 +0000124
Hal Canary594fe852019-07-18 13:35:49 -0400125 void onOnceBeforeDraw() override {
126 fFM = SkFontMgr::RefDefault();
reed@google.com964988f2013-03-29 14:57:22 +0000127 SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
128 }
skia.committer@gmail.comd55846d2013-03-30 07:01:27 +0000129
Hal Canary594fe852019-07-18 13:35:49 -0400130 SkString onShortName() override { return SkString("fontmgr_match"); }
skia.committer@gmail.comd55846d2013-03-30 07:01:27 +0000131
Hal Canary594fe852019-07-18 13:35:49 -0400132 SkISize onISize() override { return {640, 1024}; }
reed@google.com964988f2013-03-29 14:57:22 +0000133
Mike Reed560d5b32018-12-16 16:36:48 -0500134 void iterateFamily(SkCanvas* canvas, const SkFont& font, SkFontStyleSet* fset) {
135 SkFont f(font);
reed@google.com964988f2013-03-29 14:57:22 +0000136 SkScalar y = 0;
137
138 for (int j = 0; j < fset->count(); ++j) {
139 SkString sname;
140 SkFontStyle fs;
141 fset->getStyle(j, &fs, &sname);
142
143 sname.appendf(" [%d %d]", fs.weight(), fs.width());
144
Mike Reed560d5b32018-12-16 16:36:48 -0500145 f.setTypeface(sk_sp<SkTypeface>(fset->createTypeface(j)));
146 (void)drawString(canvas, sname, 0, y, f);
reed@google.com964988f2013-03-29 14:57:22 +0000147 y += 24;
148 }
149 }
150
Mike Reed560d5b32018-12-16 16:36:48 -0500151 void exploreFamily(SkCanvas* canvas, const SkFont& font, SkFontStyleSet* fset) {
152 SkFont f(font);
reed@google.com964988f2013-03-29 14:57:22 +0000153 SkScalar y = 0;
154
155 for (int weight = 100; weight <= 900; weight += 200) {
156 for (int width = 1; width <= 9; width += 2) {
157 SkFontStyle fs(weight, width, SkFontStyle::kUpright_Slant);
bungeman13b9c952016-05-12 10:09:30 -0700158 sk_sp<SkTypeface> face(fset->matchStyle(fs));
reed@google.com964988f2013-03-29 14:57:22 +0000159 if (face) {
160 SkString str;
161 str.printf("request [%d %d]", fs.weight(), fs.width());
Mike Reed560d5b32018-12-16 16:36:48 -0500162 f.setTypeface(std::move(face));
163 (void)drawString(canvas, str, 0, y, f);
reed@google.com964988f2013-03-29 14:57:22 +0000164 y += 24;
165 }
166 }
167 }
168 }
skia.committer@gmail.comd55846d2013-03-30 07:01:27 +0000169
Chris Dalton50e24d72019-02-07 16:20:09 -0700170 DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
Mike Reed560d5b32018-12-16 16:36:48 -0500171 SkFont font;
172 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
173 font.setSubpixel(true);
174 font.setSize(17);
reed@google.com964988f2013-03-29 14:57:22 +0000175
mtkleindbfd7ab2016-09-01 11:24:54 -0700176 const char* gNames[] = {
Ben Wagner83c6b962018-07-10 19:40:15 -0400177 "Helvetica Neue", "Arial", "sans"
reed@google.com964988f2013-03-29 14:57:22 +0000178 };
179
Hal Canarycefc4312016-11-04 16:26:16 -0400180 sk_sp<SkFontStyleSet> fset;
skia.committer@gmail.comd55846d2013-03-30 07:01:27 +0000181 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
bungeman@google.com9fc5c682013-11-12 15:25:29 +0000182 fset.reset(fFM->matchFamily(gNames[i]));
183 if (fset->count() > 0) {
reed@google.com964988f2013-03-29 14:57:22 +0000184 break;
185 }
186 }
halcanary96fcdcc2015-08-27 07:41:13 -0700187 if (nullptr == fset.get()) {
Chris Dalton50e24d72019-02-07 16:20:09 -0700188 *errorMsg = "No SkFontStyleSet";
189 return DrawResult::kFail;
reed@google.com964988f2013-03-29 14:57:22 +0000190 }
reed@google.com964988f2013-03-29 14:57:22 +0000191
192 canvas->translate(20, 40);
Mike Reed560d5b32018-12-16 16:36:48 -0500193 this->exploreFamily(canvas, font, fset.get());
reed@google.com964988f2013-03-29 14:57:22 +0000194 canvas->translate(150, 0);
Mike Reed560d5b32018-12-16 16:36:48 -0500195 this->iterateFamily(canvas, font, fset.get());
Chris Dalton50e24d72019-02-07 16:20:09 -0700196 return DrawResult::kOk;
reed@google.com964988f2013-03-29 14:57:22 +0000197 }
reed@google.com964988f2013-03-29 14:57:22 +0000198};
199
reeda0c814c2014-10-22 13:20:58 -0700200class FontMgrBoundsGM : public skiagm::GM {
201public:
Hal Canary594fe852019-07-18 13:35:49 -0400202 FontMgrBoundsGM(float scale, float skew) : fScaleX(scale) , fSkewX(skew) {}
203
204private:
205 SkString onShortName() override {
206 if (fScaleX != 1 || fSkewX != 0) {
207 return SkStringPrintf("fontmgr_bounds_%g_%g", fScaleX, fSkewX);
reed8893e5f2014-12-15 13:27:26 -0800208 }
Hal Canary594fe852019-07-18 13:35:49 -0400209 return SkString("fontmgr_bounds");
210 }
211
212 void onOnceBeforeDraw() override {
213 fFM = SkFontMgr::RefDefault();
Ben Wagner110c7032019-03-22 17:03:59 -0400214 }
215
216 bool onGetControls(SkMetaData* controls) override {
217 controls->setBool("Label Bounds", fLabelBounds);
218 return true;
219 }
220
221 void onSetControls(const SkMetaData& controls) override {
222 controls.findBool("Label Bounds", &fLabelBounds);
reeda0c814c2014-10-22 13:20:58 -0700223 }
224
Mike Reed7d1eb332018-12-04 17:35:56 -0500225 static void show_bounds(SkCanvas* canvas, const SkFont& font, SkScalar x, SkScalar y,
Ben Wagner110c7032019-03-22 17:03:59 -0400226 SkColor boundsColor, bool labelBounds)
Ben Wagner219f3622017-07-17 15:32:25 -0400227 {
Mike Reed7d1eb332018-12-04 17:35:56 -0500228 SkRect fontBounds = SkFontPriv::GetFontBounds(font).makeOffset(x, y);
229
230 SkPaint boundsPaint;
231 boundsPaint.setAntiAlias(true);
Ben Wagner219f3622017-07-17 15:32:25 -0400232 boundsPaint.setColor(boundsColor);
Ben Wagner97182cc2018-02-15 10:20:04 -0500233 boundsPaint.setStyle(SkPaint::kStroke_Style);
Ben Wagner219f3622017-07-17 15:32:25 -0400234 canvas->drawRect(fontBounds, boundsPaint);
reeda0c814c2014-10-22 13:20:58 -0700235
Mike Reedcb6f53e2018-11-06 12:44:54 -0500236 SkFontMetrics fm;
Mike Reed7d1eb332018-12-04 17:35:56 -0500237 font.getMetrics(&fm);
Ben Wagner219f3622017-07-17 15:32:25 -0400238 SkPaint metricsPaint(boundsPaint);
239 metricsPaint.setStyle(SkPaint::kFill_Style);
Mike Reed9407e242019-02-15 16:13:57 -0500240 metricsPaint.setAlphaf(0.25f);
Mike Reedb5784ac2018-11-12 09:35:15 -0500241 if ((fm.fFlags & SkFontMetrics::kUnderlinePositionIsValid_Flag) &&
Ben Wagner9ca55f22019-02-12 15:04:17 -0500242 (fm.fFlags & SkFontMetrics::kUnderlineThicknessIsValid_Flag))
Ben Wagner219f3622017-07-17 15:32:25 -0400243 {
244 SkRect underline{ fontBounds.fLeft, fm.fUnderlinePosition+y,
245 fontBounds.fRight, fm.fUnderlinePosition+y + fm.fUnderlineThickness };
246 canvas->drawRect(underline, metricsPaint);
reeda0c814c2014-10-22 13:20:58 -0700247 }
tfarinaaa458fb2015-01-05 17:18:51 -0800248
Mike Reedb5784ac2018-11-12 09:35:15 -0500249 if ((fm.fFlags & SkFontMetrics::kStrikeoutPositionIsValid_Flag) &&
Ben Wagner9ca55f22019-02-12 15:04:17 -0500250 (fm.fFlags & SkFontMetrics::kStrikeoutThicknessIsValid_Flag))
Ben Wagner219f3622017-07-17 15:32:25 -0400251 {
252 SkRect strikeout{ fontBounds.fLeft, fm.fStrikeoutPosition+y - fm.fStrikeoutThickness,
253 fontBounds.fRight, fm.fStrikeoutPosition+y };
254 canvas->drawRect(strikeout, metricsPaint);
255 }
256
257 SkGlyphID left = 0, right = 0, top = 0, bottom = 0;
258 {
Herb Derby087fad72019-01-22 14:45:16 -0500259 int numGlyphs = font.getTypefaceOrDefault()->countGlyphs();
Ben Wagner219f3622017-07-17 15:32:25 -0400260 SkRect min = {0, 0, 0, 0};
Ben Wagner219f3622017-07-17 15:32:25 -0400261 for (int i = 0; i < numGlyphs; ++i) {
262 SkGlyphID glyphId = i;
263 SkRect cur;
Mike Reed7d1eb332018-12-04 17:35:56 -0500264 font.getBounds(&glyphId, 1, &cur, nullptr);
Ben Wagner219f3622017-07-17 15:32:25 -0400265 if (cur.fLeft < min.fLeft ) { min.fLeft = cur.fLeft; left = i; }
266 if (cur.fTop < min.fTop ) { min.fTop = cur.fTop ; top = i; }
267 if (min.fRight < cur.fRight ) { min.fRight = cur.fRight; right = i; }
268 if (min.fBottom < cur.fBottom) { min.fBottom = cur.fBottom; bottom = i; }
269 }
270 }
271 SkGlyphID str[] = { left, right, top, bottom };
Ben Wagner17bca9a2018-06-22 15:27:52 -0400272 SkPoint location[] = {
273 {fontBounds.left(), fontBounds.centerY()},
274 {fontBounds.right(), fontBounds.centerY()},
275 {fontBounds.centerX(), fontBounds.top()},
276 {fontBounds.centerX(), fontBounds.bottom()}
277 };
278
Mike Reed7d1eb332018-12-04 17:35:56 -0500279 SkFont labelFont;
280 labelFont.setEdging(SkFont::Edging::kAntiAlias);
Mike Kleinea3f0142019-03-20 11:12:10 -0500281 labelFont.setTypeface(ToolUtils::create_portable_typeface());
Mike Reed7d1eb332018-12-04 17:35:56 -0500282
Ben Wagner110c7032019-03-22 17:03:59 -0400283 if (labelBounds) {
Ben Wagner17bca9a2018-06-22 15:27:52 -0400284 SkString name;
Herb Derby087fad72019-01-22 14:45:16 -0500285 font.getTypefaceOrDefault()->getFamilyName(&name);
Hal Canary89a644b2019-01-07 09:36:09 -0500286 canvas->drawString(name, fontBounds.fLeft, fontBounds.fBottom, labelFont, SkPaint());
Ben Wagner17bca9a2018-06-22 15:27:52 -0400287 }
Ben Wagner219f3622017-07-17 15:32:25 -0400288 for (size_t i = 0; i < SK_ARRAY_COUNT(str); ++i) {
Ben Wagner97182cc2018-02-15 10:20:04 -0500289 SkPath path;
Mike Reed7d1eb332018-12-04 17:35:56 -0500290 font.getPath(str[i], &path);
291 path.offset(x, y);
Ben Wagner97182cc2018-02-15 10:20:04 -0500292 SkPaint::Style style = path.isEmpty() ? SkPaint::kFill_Style : SkPaint::kStroke_Style;
Mike Reed7d1eb332018-12-04 17:35:56 -0500293 SkPaint glyphPaint;
Ben Wagner97182cc2018-02-15 10:20:04 -0500294 glyphPaint.setStyle(style);
Ben Wagner51e15a62019-05-07 15:38:46 -0400295 canvas->drawSimpleText(&str[i], sizeof(str[0]), SkTextEncoding::kGlyphID, x, y, font, glyphPaint);
Ben Wagner17bca9a2018-06-22 15:27:52 -0400296
Ben Wagner110c7032019-03-22 17:03:59 -0400297 if (labelBounds) {
Ben Wagner17bca9a2018-06-22 15:27:52 -0400298 SkString glyphStr;
299 glyphStr.appendS32(str[i]);
Hal Canary89a644b2019-01-07 09:36:09 -0500300 canvas->drawString(glyphStr, location[i].fX, location[i].fY, labelFont, SkPaint());
Ben Wagner17bca9a2018-06-22 15:27:52 -0400301 }
302
Ben Wagner219f3622017-07-17 15:32:25 -0400303 }
reeda0c814c2014-10-22 13:20:58 -0700304 }
305
Hal Canary594fe852019-07-18 13:35:49 -0400306 SkISize onISize() override { return {1024, 850}; }
tfarinaaa458fb2015-01-05 17:18:51 -0800307
mtklein36352bf2015-03-25 18:17:31 -0700308 void onDraw(SkCanvas* canvas) override {
Mike Reed7d1eb332018-12-04 17:35:56 -0500309 SkFont font;
310 font.setEdging(SkFont::Edging::kAntiAlias);
311 font.setSubpixel(true);
312 font.setSize(100);
313 font.setScaleX(fScaleX);
314 font.setSkewX(fSkewX);
reeda0c814c2014-10-22 13:20:58 -0700315
316 const SkColor boundsColors[2] = { SK_ColorRED, SK_ColorBLUE };
halcanary9d524f22016-03-29 09:03:52 -0700317
Hal Canarycefc4312016-11-04 16:26:16 -0400318 SkFontMgr* fm = fFM.get();
reeda0c814c2014-10-22 13:20:58 -0700319 int count = SkMin32(fm->countFamilies(), 32);
320
321 int index = 0;
322 SkScalar x = 0, y = 0;
323
Ben Wagner219f3622017-07-17 15:32:25 -0400324 canvas->translate(10, 120);
reeda0c814c2014-10-22 13:20:58 -0700325
326 for (int i = 0; i < count; ++i) {
Hal Canarycefc4312016-11-04 16:26:16 -0400327 sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
Ben Wagner219f3622017-07-17 15:32:25 -0400328 for (int j = 0; j < set->count() && j < 3; ++j) {
Mike Reed7d1eb332018-12-04 17:35:56 -0500329 font.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j)));
Ben Wagner2112df02017-07-24 11:04:21 -0400330 // Fonts with lots of glyphs are interesting, but can take a long time to find
331 // the glyphs which make up the maximum extent.
Herb Derby087fad72019-01-22 14:45:16 -0500332 if (font.getTypefaceOrDefault() && font.getTypefaceOrDefault()->countGlyphs() < 1000) {
Mike Reed7d1eb332018-12-04 17:35:56 -0500333 SkRect fontBounds = SkFontPriv::GetFontBounds(font);
Ben Wagner219f3622017-07-17 15:32:25 -0400334 x -= fontBounds.fLeft;
Ben Wagner110c7032019-03-22 17:03:59 -0400335 show_bounds(canvas, font, x, y, boundsColors[index & 1], fLabelBounds);
Ben Wagner219f3622017-07-17 15:32:25 -0400336 x += fontBounds.fRight + 20;
reeda0c814c2014-10-22 13:20:58 -0700337 index += 1;
Ben Wagner219f3622017-07-17 15:32:25 -0400338 if (x > 900) {
reeda0c814c2014-10-22 13:20:58 -0700339 x = 0;
340 y += 160;
341 }
Ben Wagner219f3622017-07-17 15:32:25 -0400342 if (y >= 700) {
reeda0c814c2014-10-22 13:20:58 -0700343 return;
344 }
345 }
346 }
347 }
348 }
mtklein1c402922015-01-23 11:07:07 -0800349
Hal Canary594fe852019-07-18 13:35:49 -0400350 sk_sp<SkFontMgr> fFM;
Ben Wagner110c7032019-03-22 17:03:59 -0400351 const SkScalar fScaleX;
352 const SkScalar fSkewX;
Hal Canary594fe852019-07-18 13:35:49 -0400353 bool fLabelBounds = false;
reeda0c814c2014-10-22 13:20:58 -0700354};
355
reed@google.comaf0fa6a2013-03-28 13:39:35 +0000356//////////////////////////////////////////////////////////////////////////////
357
halcanary385fe4d2015-08-26 13:07:48 -0700358DEF_GM(return new FontMgrGM;)
359DEF_GM(return new FontMgrMatchGM;)
Hal Canary594fe852019-07-18 13:35:49 -0400360DEF_GM(return new FontMgrBoundsGM(1, 0);)
361DEF_GM(return new FontMgrBoundsGM(0.75f, 0);)
362DEF_GM(return new FontMgrBoundsGM(1, -0.25f);)