2013-03-28 13:39:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkFontMetrics.h"
|
|
|
|
#include "include/core/SkFontMgr.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkFontStyle.h"
|
|
|
|
#include "include/core/SkFontTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkGraphics.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2020-08-21 16:06:03 +00:00
|
|
|
#include "include/effects/SkDashPathEffect.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkFontPriv.h"
|
2019-07-15 18:01:37 +00:00
|
|
|
#include "tools/SkMetaData.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
|
|
|
|
#include <utility>
|
2013-03-28 13:39:35 +00:00
|
|
|
|
|
|
|
// limit this just so we don't take too long to draw
|
|
|
|
#define MAX_FAMILIES 30
|
|
|
|
|
|
|
|
static SkScalar drawString(SkCanvas* canvas, const SkString& text, SkScalar x,
|
2018-12-16 21:36:48 +00:00
|
|
|
SkScalar y, const SkFont& font) {
|
2019-01-07 14:36:09 +00:00
|
|
|
canvas->drawString(text, x, y, font, SkPaint());
|
2019-05-07 19:38:46 +00:00
|
|
|
return x + font.measureText(text.c_str(), text.size(), SkTextEncoding::kUTF8);
|
2013-03-28 13:39:35 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 14:03:13 +00:00
|
|
|
static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
|
2018-12-16 21:36:48 +00:00
|
|
|
SkScalar y, const SkFont& origFont, SkFontMgr* fm,
|
2014-11-10 21:29:33 +00:00
|
|
|
const char* fontName, const char* bcp47[], int bcp47Count,
|
2014-08-27 14:03:13 +00:00
|
|
|
const SkFontStyle& fontStyle) {
|
2018-12-16 21:36:48 +00:00
|
|
|
SkFont font = origFont;
|
2014-08-27 14:03:13 +00:00
|
|
|
// find typeface containing the requested character and draw it
|
|
|
|
SkString ch;
|
|
|
|
ch.appendUnichar(character);
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> typeface(fm->matchFamilyStyleCharacter(fontName, fontStyle,
|
|
|
|
bcp47, bcp47Count, character));
|
2018-12-16 21:36:48 +00:00
|
|
|
font.setTypeface(typeface);
|
|
|
|
x = drawString(canvas, ch, x, y, font) + 20;
|
2014-08-27 14:03:13 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == typeface) {
|
2014-08-27 14:03:13 +00:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
// repeat the process, but this time use the family name of the typeface
|
|
|
|
// from the first pass. This emulates the behavior in Blink where it
|
|
|
|
// it expects to get the same glyph when following this pattern.
|
|
|
|
SkString familyName;
|
|
|
|
typeface->getFamilyName(&familyName);
|
2018-12-16 21:36:48 +00:00
|
|
|
font.setTypeface(fm->legacyMakeTypeface(familyName.c_str(), typeface->fontStyle()));
|
|
|
|
return drawString(canvas, ch, x, y, font) + 20;
|
2014-08-27 14:03:13 +00:00
|
|
|
}
|
|
|
|
|
2014-11-10 21:29:33 +00:00
|
|
|
static const char* zh = "zh";
|
|
|
|
static const char* ja = "ja";
|
|
|
|
|
2013-03-28 13:39:35 +00:00
|
|
|
class FontMgrGM : public skiagm::GM {
|
2019-07-18 17:35:49 +00:00
|
|
|
sk_sp<SkFontMgr> fFM;
|
2017-01-03 18:32:36 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
|
2017-11-13 23:10:54 +00:00
|
|
|
fFM = SkFontMgr::RefDefault();
|
2017-01-03 18:32:36 +00:00
|
|
|
}
|
2013-03-28 13:39:35 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkString onShortName() override { return SkString("fontmgr_iter"); }
|
2013-03-28 13:39:35 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkISize onISize() override { return {1536, 768}; }
|
2013-03-28 13:39:35 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-03-28 13:39:35 +00:00
|
|
|
SkScalar y = 20;
|
2018-12-16 21:36:48 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
font.setSubpixel(true);
|
|
|
|
font.setSize(17);
|
2013-03-29 07:01:22 +00:00
|
|
|
|
2016-11-04 20:26:16 +00:00
|
|
|
SkFontMgr* fm = fFM.get();
|
2020-02-06 16:25:43 +00:00
|
|
|
int count = std::min(fm->countFamilies(), MAX_FAMILIES);
|
2013-03-28 13:39:35 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
2015-04-29 15:15:31 +00:00
|
|
|
SkString familyName;
|
|
|
|
fm->getFamilyName(i, &familyName);
|
2018-12-16 21:36:48 +00:00
|
|
|
font.setTypeface(nullptr);
|
|
|
|
(void)drawString(canvas, familyName, 20, y, font);
|
2013-03-29 07:01:22 +00:00
|
|
|
|
2013-03-28 13:39:35 +00:00
|
|
|
SkScalar x = 220;
|
2013-03-29 14:57:22 +00:00
|
|
|
|
2016-11-04 20:26:16 +00:00
|
|
|
sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
|
2013-03-28 13:39:35 +00:00
|
|
|
for (int j = 0; j < set->count(); ++j) {
|
|
|
|
SkString sname;
|
|
|
|
SkFontStyle fs;
|
|
|
|
set->getStyle(j, &fs, &sname);
|
2016-04-27 17:21:04 +00:00
|
|
|
sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.slant());
|
2013-03-29 07:01:22 +00:00
|
|
|
|
2018-12-16 21:36:48 +00:00
|
|
|
font.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j)));
|
|
|
|
x = drawString(canvas, sname, x, y, font) + 20;
|
2014-08-27 14:03:13 +00:00
|
|
|
|
|
|
|
// check to see that we get different glyphs in japanese and chinese
|
2018-12-16 21:36:48 +00:00
|
|
|
x = drawCharacter(canvas, 0x5203, x, y, font, fm, familyName.c_str(), &zh, 1, fs);
|
|
|
|
x = drawCharacter(canvas, 0x5203, x, y, font, fm, familyName.c_str(), &ja, 1, fs);
|
2014-08-27 14:03:13 +00:00
|
|
|
// check that emoji characters are found
|
2018-12-16 21:36:48 +00:00
|
|
|
x = drawCharacter(canvas, 0x1f601, x, y, font, fm, familyName.c_str(), nullptr,0, fs);
|
2013-03-29 07:01:22 +00:00
|
|
|
}
|
2013-03-28 13:39:35 +00:00
|
|
|
y += 24;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-29 14:57:22 +00:00
|
|
|
class FontMgrMatchGM : public skiagm::GM {
|
2016-11-04 20:26:16 +00:00
|
|
|
sk_sp<SkFontMgr> fFM;
|
2013-03-29 14:57:22 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
fFM = SkFontMgr::RefDefault();
|
2013-03-29 14:57:22 +00:00
|
|
|
SkGraphics::SetFontCacheLimit(16 * 1024 * 1024);
|
|
|
|
}
|
2013-03-30 07:01:27 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkString onShortName() override { return SkString("fontmgr_match"); }
|
2013-03-30 07:01:27 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkISize onISize() override { return {640, 1024}; }
|
2013-03-29 14:57:22 +00:00
|
|
|
|
2018-12-16 21:36:48 +00:00
|
|
|
void iterateFamily(SkCanvas* canvas, const SkFont& font, SkFontStyleSet* fset) {
|
|
|
|
SkFont f(font);
|
2013-03-29 14:57:22 +00:00
|
|
|
SkScalar y = 0;
|
|
|
|
|
|
|
|
for (int j = 0; j < fset->count(); ++j) {
|
|
|
|
SkString sname;
|
|
|
|
SkFontStyle fs;
|
|
|
|
fset->getStyle(j, &fs, &sname);
|
|
|
|
|
|
|
|
sname.appendf(" [%d %d]", fs.weight(), fs.width());
|
|
|
|
|
2018-12-16 21:36:48 +00:00
|
|
|
f.setTypeface(sk_sp<SkTypeface>(fset->createTypeface(j)));
|
|
|
|
(void)drawString(canvas, sname, 0, y, f);
|
2013-03-29 14:57:22 +00:00
|
|
|
y += 24;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 21:36:48 +00:00
|
|
|
void exploreFamily(SkCanvas* canvas, const SkFont& font, SkFontStyleSet* fset) {
|
|
|
|
SkFont f(font);
|
2013-03-29 14:57:22 +00:00
|
|
|
SkScalar y = 0;
|
|
|
|
|
|
|
|
for (int weight = 100; weight <= 900; weight += 200) {
|
|
|
|
for (int width = 1; width <= 9; width += 2) {
|
|
|
|
SkFontStyle fs(weight, width, SkFontStyle::kUpright_Slant);
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> face(fset->matchStyle(fs));
|
2013-03-29 14:57:22 +00:00
|
|
|
if (face) {
|
|
|
|
SkString str;
|
|
|
|
str.printf("request [%d %d]", fs.weight(), fs.width());
|
2018-12-16 21:36:48 +00:00
|
|
|
f.setTypeface(std::move(face));
|
|
|
|
(void)drawString(canvas, str, 0, y, f);
|
2013-03-29 14:57:22 +00:00
|
|
|
y += 24;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-30 07:01:27 +00:00
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
|
2018-12-16 21:36:48 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
font.setSubpixel(true);
|
|
|
|
font.setSize(17);
|
2013-03-29 14:57:22 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
const char* gNames[] = {
|
2018-07-10 23:40:15 +00:00
|
|
|
"Helvetica Neue", "Arial", "sans"
|
2013-03-29 14:57:22 +00:00
|
|
|
};
|
|
|
|
|
2016-11-04 20:26:16 +00:00
|
|
|
sk_sp<SkFontStyleSet> fset;
|
2013-03-30 07:01:27 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
|
2013-11-12 15:25:29 +00:00
|
|
|
fset.reset(fFM->matchFamily(gNames[i]));
|
|
|
|
if (fset->count() > 0) {
|
2013-03-29 14:57:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == fset.get()) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "No SkFontStyleSet";
|
|
|
|
return DrawResult::kFail;
|
2013-03-29 14:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas->translate(20, 40);
|
2018-12-16 21:36:48 +00:00
|
|
|
this->exploreFamily(canvas, font, fset.get());
|
2013-03-29 14:57:22 +00:00
|
|
|
canvas->translate(150, 0);
|
2018-12-16 21:36:48 +00:00
|
|
|
this->iterateFamily(canvas, font, fset.get());
|
2019-02-07 23:20:09 +00:00
|
|
|
return DrawResult::kOk;
|
2013-03-29 14:57:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-22 20:20:58 +00:00
|
|
|
class FontMgrBoundsGM : public skiagm::GM {
|
|
|
|
public:
|
2019-07-18 17:35:49 +00:00
|
|
|
FontMgrBoundsGM(float scale, float skew) : fScaleX(scale) , fSkewX(skew) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString onShortName() override {
|
|
|
|
if (fScaleX != 1 || fSkewX != 0) {
|
|
|
|
return SkStringPrintf("fontmgr_bounds_%g_%g", fScaleX, fSkewX);
|
2014-12-15 21:27:26 +00:00
|
|
|
}
|
2019-07-18 17:35:49 +00:00
|
|
|
return SkString("fontmgr_bounds");
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
fFM = SkFontMgr::RefDefault();
|
2019-03-22 21:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool onGetControls(SkMetaData* controls) override {
|
|
|
|
controls->setBool("Label Bounds", fLabelBounds);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onSetControls(const SkMetaData& controls) override {
|
|
|
|
controls.findBool("Label Bounds", &fLabelBounds);
|
2014-10-22 20:20:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 16:06:03 +00:00
|
|
|
static SkRect show_bounds(SkCanvas* canvas, const SkFont& font, SkScalar x, SkScalar y,
|
|
|
|
SkColor boundsColor, bool labelBounds)
|
2017-07-17 19:32:25 +00:00
|
|
|
{
|
2020-08-21 16:06:03 +00:00
|
|
|
SkGlyphID left = 0, right = 0, top = 0, bottom = 0;
|
|
|
|
SkRect min = SkRect::MakeLTRB(SK_ScalarInfinity, SK_ScalarInfinity,
|
|
|
|
SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity);
|
|
|
|
{
|
|
|
|
int numGlyphs = font.getTypefaceOrDefault()->countGlyphs();
|
|
|
|
for (int i = 0; i < numGlyphs; ++i) {
|
|
|
|
SkGlyphID glyphId = i;
|
|
|
|
SkRect cur;
|
|
|
|
font.getBounds(&glyphId, 1, &cur, nullptr);
|
|
|
|
if (cur.fLeft < min.fLeft ) { min.fLeft = cur.fLeft; left = i; }
|
|
|
|
if (cur.fTop < min.fTop ) { min.fTop = cur.fTop ; top = i; }
|
|
|
|
if (min.fRight < cur.fRight ) { min.fRight = cur.fRight; right = i; }
|
|
|
|
if (min.fBottom < cur.fBottom) { min.fBottom = cur.fBottom; bottom = i; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRect fontBounds = SkFontPriv::GetFontBounds(font);
|
|
|
|
|
|
|
|
SkRect drawBounds = min;
|
|
|
|
drawBounds.join(fontBounds);
|
|
|
|
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->translate(x - drawBounds.left(), y);
|
2018-12-04 22:35:56 +00:00
|
|
|
|
|
|
|
SkPaint boundsPaint;
|
|
|
|
boundsPaint.setAntiAlias(true);
|
2017-07-17 19:32:25 +00:00
|
|
|
boundsPaint.setColor(boundsColor);
|
2018-02-15 15:20:04 +00:00
|
|
|
boundsPaint.setStyle(SkPaint::kStroke_Style);
|
2017-07-17 19:32:25 +00:00
|
|
|
canvas->drawRect(fontBounds, boundsPaint);
|
|
|
|
|
2020-08-21 16:06:03 +00:00
|
|
|
const SkScalar intervals[] = { 10.f, 10.f };
|
|
|
|
boundsPaint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0.f));
|
|
|
|
canvas->drawRect(min, boundsPaint);
|
|
|
|
|
2018-11-06 17:44:54 +00:00
|
|
|
SkFontMetrics fm;
|
2018-12-04 22:35:56 +00:00
|
|
|
font.getMetrics(&fm);
|
2017-07-17 19:32:25 +00:00
|
|
|
SkPaint metricsPaint(boundsPaint);
|
|
|
|
metricsPaint.setStyle(SkPaint::kFill_Style);
|
2019-02-15 21:13:57 +00:00
|
|
|
metricsPaint.setAlphaf(0.25f);
|
2018-11-12 14:35:15 +00:00
|
|
|
if ((fm.fFlags & SkFontMetrics::kUnderlinePositionIsValid_Flag) &&
|
2019-02-12 20:04:17 +00:00
|
|
|
(fm.fFlags & SkFontMetrics::kUnderlineThicknessIsValid_Flag))
|
2017-07-17 19:32:25 +00:00
|
|
|
{
|
2020-08-21 20:52:48 +00:00
|
|
|
SkRect underline{ min.fLeft, fm.fUnderlinePosition,
|
|
|
|
min.fRight, fm.fUnderlinePosition + fm.fUnderlineThickness };
|
2017-07-17 19:32:25 +00:00
|
|
|
canvas->drawRect(underline, metricsPaint);
|
|
|
|
}
|
2014-10-22 20:20:58 +00:00
|
|
|
|
2018-11-12 14:35:15 +00:00
|
|
|
if ((fm.fFlags & SkFontMetrics::kStrikeoutPositionIsValid_Flag) &&
|
2019-02-12 20:04:17 +00:00
|
|
|
(fm.fFlags & SkFontMetrics::kStrikeoutThicknessIsValid_Flag))
|
2017-07-17 19:32:25 +00:00
|
|
|
{
|
2020-08-21 20:52:48 +00:00
|
|
|
SkRect strikeout{ min.fLeft, fm.fStrikeoutPosition - fm.fStrikeoutThickness,
|
|
|
|
min.fRight, fm.fStrikeoutPosition };
|
2017-07-17 19:32:25 +00:00
|
|
|
canvas->drawRect(strikeout, metricsPaint);
|
2014-10-22 20:20:58 +00:00
|
|
|
}
|
2015-01-06 01:18:51 +00:00
|
|
|
|
2020-08-21 20:52:48 +00:00
|
|
|
struct GlyphToDraw {
|
|
|
|
SkGlyphID id;
|
|
|
|
SkPoint location;
|
|
|
|
SkScalar rotation;
|
|
|
|
} glyphsToDraw [] = {
|
|
|
|
{left, {min.left(), min.centerY()}, 270},
|
|
|
|
{right, {min.right(), min.centerY()}, 90},
|
|
|
|
{top, {min.centerX(), min.top() }, 0},
|
|
|
|
{bottom, {min.centerX(), min.bottom() }, 180},
|
2018-06-22 19:27:52 +00:00
|
|
|
};
|
|
|
|
|
2018-12-04 22:35:56 +00:00
|
|
|
SkFont labelFont;
|
|
|
|
labelFont.setEdging(SkFont::Edging::kAntiAlias);
|
2019-03-20 16:12:10 +00:00
|
|
|
labelFont.setTypeface(ToolUtils::create_portable_typeface());
|
2018-12-04 22:35:56 +00:00
|
|
|
|
2019-03-22 21:03:59 +00:00
|
|
|
if (labelBounds) {
|
2018-06-22 19:27:52 +00:00
|
|
|
SkString name;
|
2019-01-22 19:45:16 +00:00
|
|
|
font.getTypefaceOrDefault()->getFamilyName(&name);
|
2020-08-21 20:52:48 +00:00
|
|
|
canvas->drawString(name, min.fLeft, min.fBottom, labelFont, SkPaint());
|
2018-06-22 19:27:52 +00:00
|
|
|
}
|
2020-08-21 20:52:48 +00:00
|
|
|
for (const GlyphToDraw& glyphToDraw : glyphsToDraw) {
|
2018-02-15 15:20:04 +00:00
|
|
|
SkPath path;
|
2020-08-21 20:52:48 +00:00
|
|
|
font.getPath(glyphToDraw.id, &path);
|
2018-02-15 15:20:04 +00:00
|
|
|
SkPaint::Style style = path.isEmpty() ? SkPaint::kFill_Style : SkPaint::kStroke_Style;
|
2018-12-04 22:35:56 +00:00
|
|
|
SkPaint glyphPaint;
|
2018-02-15 15:20:04 +00:00
|
|
|
glyphPaint.setStyle(style);
|
2020-08-21 20:52:48 +00:00
|
|
|
canvas->drawSimpleText(&glyphToDraw.id, sizeof(glyphToDraw.id),
|
|
|
|
SkTextEncoding::kGlyphID, 0, 0, font, glyphPaint);
|
2018-06-22 19:27:52 +00:00
|
|
|
|
2019-03-22 21:03:59 +00:00
|
|
|
if (labelBounds) {
|
2021-08-13 02:33:57 +00:00
|
|
|
SkAutoCanvasRestore acr2(canvas, true);
|
2020-08-21 20:52:48 +00:00
|
|
|
canvas->translate(glyphToDraw.location.fX, glyphToDraw.location.fY);
|
|
|
|
canvas->rotate(glyphToDraw.rotation);
|
2018-06-22 19:27:52 +00:00
|
|
|
SkString glyphStr;
|
2020-08-21 20:52:48 +00:00
|
|
|
glyphStr.appendS32(glyphToDraw.id);
|
|
|
|
canvas->drawString(glyphStr, 0, 0, labelFont, SkPaint());
|
2018-06-22 19:27:52 +00:00
|
|
|
}
|
2017-07-17 19:32:25 +00:00
|
|
|
}
|
2020-08-21 16:06:03 +00:00
|
|
|
|
|
|
|
return drawBounds;
|
2014-10-22 20:20:58 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkISize onISize() override { return {1024, 850}; }
|
2015-01-06 01:18:51 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2018-12-04 22:35:56 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setEdging(SkFont::Edging::kAntiAlias);
|
|
|
|
font.setSubpixel(true);
|
|
|
|
font.setSize(100);
|
|
|
|
font.setScaleX(fScaleX);
|
|
|
|
font.setSkewX(fSkewX);
|
2014-10-22 20:20:58 +00:00
|
|
|
|
|
|
|
const SkColor boundsColors[2] = { SK_ColorRED, SK_ColorBLUE };
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2016-11-04 20:26:16 +00:00
|
|
|
SkFontMgr* fm = fFM.get();
|
2020-02-06 16:25:43 +00:00
|
|
|
int count = std::min(fm->countFamilies(), 32);
|
2014-10-22 20:20:58 +00:00
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
SkScalar x = 0, y = 0;
|
|
|
|
|
2017-07-17 19:32:25 +00:00
|
|
|
canvas->translate(10, 120);
|
2014-10-22 20:20:58 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
2016-11-04 20:26:16 +00:00
|
|
|
sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
|
2017-07-17 19:32:25 +00:00
|
|
|
for (int j = 0; j < set->count() && j < 3; ++j) {
|
2018-12-04 22:35:56 +00:00
|
|
|
font.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j)));
|
2017-07-24 15:04:21 +00:00
|
|
|
// Fonts with lots of glyphs are interesting, but can take a long time to find
|
|
|
|
// the glyphs which make up the maximum extent.
|
2020-08-21 16:06:03 +00:00
|
|
|
SkTypeface* typeface = font.getTypefaceOrDefault();
|
|
|
|
if (typeface && 0 < typeface->countGlyphs() && typeface->countGlyphs() < 1000) {
|
2020-08-21 20:52:48 +00:00
|
|
|
SkColor color = boundsColors[index & 1];
|
|
|
|
SkRect drawBounds = show_bounds(canvas, font, x, y, color, fLabelBounds);
|
2020-08-21 16:06:03 +00:00
|
|
|
x += drawBounds.width() + 20;
|
2014-10-22 20:20:58 +00:00
|
|
|
index += 1;
|
2017-07-17 19:32:25 +00:00
|
|
|
if (x > 900) {
|
2014-10-22 20:20:58 +00:00
|
|
|
x = 0;
|
|
|
|
y += 160;
|
|
|
|
}
|
2017-07-17 19:32:25 +00:00
|
|
|
if (y >= 700) {
|
2014-10-22 20:20:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-23 19:07:07 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
sk_sp<SkFontMgr> fFM;
|
2019-03-22 21:03:59 +00:00
|
|
|
const SkScalar fScaleX;
|
|
|
|
const SkScalar fSkewX;
|
2019-07-18 17:35:49 +00:00
|
|
|
bool fLabelBounds = false;
|
2014-10-22 20:20:58 +00:00
|
|
|
};
|
|
|
|
|
2013-03-28 13:39:35 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new FontMgrGM;)
|
|
|
|
DEF_GM(return new FontMgrMatchGM;)
|
2019-07-18 17:35:49 +00:00
|
|
|
DEF_GM(return new FontMgrBoundsGM(1, 0);)
|
|
|
|
DEF_GM(return new FontMgrBoundsGM(0.75f, 0);)
|
|
|
|
DEF_GM(return new FontMgrBoundsGM(1, -0.25f);)
|