2018-02-20 22:06:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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 "tools/ToolUtils.h"
|
2018-08-21 15:45:46 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkFontMgr.h"
|
|
|
|
#include "include/core/SkFontStyle.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/private/SkMutex.h"
|
2020-08-18 17:17:09 +00:00
|
|
|
#include "include/utils/SkCustomTypeface.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkOSFile.h"
|
|
|
|
#include "src/utils/SkUTF.h"
|
|
|
|
#include "tools/Resources.h"
|
|
|
|
#include "tools/fonts/TestFontMgr.h"
|
2018-02-20 22:06:07 +00:00
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
namespace ToolUtils {
|
2018-02-20 22:06:07 +00:00
|
|
|
|
2019-03-08 23:05:47 +00:00
|
|
|
sk_sp<SkTypeface> planet_typeface() {
|
2019-03-20 16:12:10 +00:00
|
|
|
static const sk_sp<SkTypeface> planetTypeface = []() {
|
2019-03-08 23:05:47 +00:00
|
|
|
const char* filename;
|
|
|
|
#if defined(SK_BUILD_FOR_WIN)
|
|
|
|
filename = "fonts/planetcolr.ttf";
|
|
|
|
#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
|
|
|
filename = "fonts/planetsbix.ttf";
|
|
|
|
#else
|
|
|
|
filename = "fonts/planetcbdt.ttf";
|
|
|
|
#endif
|
|
|
|
sk_sp<SkTypeface> typeface = MakeResourceAsTypeface(filename);
|
|
|
|
if (typeface) {
|
|
|
|
return typeface;
|
|
|
|
}
|
|
|
|
return SkTypeface::MakeFromName("Planet", SkFontStyle());
|
|
|
|
}();
|
|
|
|
return planetTypeface;
|
|
|
|
}
|
|
|
|
|
2018-02-20 22:06:07 +00:00
|
|
|
sk_sp<SkTypeface> emoji_typeface() {
|
2019-03-20 16:12:10 +00:00
|
|
|
static const sk_sp<SkTypeface> emojiTypeface = []() {
|
2019-03-08 23:05:47 +00:00
|
|
|
const char* filename;
|
2018-02-20 22:06:07 +00:00
|
|
|
#if defined(SK_BUILD_FOR_WIN)
|
2019-03-08 23:05:47 +00:00
|
|
|
filename = "fonts/colr.ttf";
|
2018-03-27 18:15:53 +00:00
|
|
|
#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
2019-03-08 23:05:47 +00:00
|
|
|
filename = "fonts/sbix.ttf";
|
2018-03-27 18:15:53 +00:00
|
|
|
#else
|
2019-03-08 23:05:47 +00:00
|
|
|
filename = "fonts/cbdt.ttf";
|
2018-03-27 18:15:53 +00:00
|
|
|
#endif
|
2019-03-08 23:05:47 +00:00
|
|
|
sk_sp<SkTypeface> typeface = MakeResourceAsTypeface(filename);
|
|
|
|
if (typeface) {
|
|
|
|
return typeface;
|
|
|
|
}
|
|
|
|
return SkTypeface::MakeFromName("Emoji", SkFontStyle());
|
|
|
|
}();
|
|
|
|
return emojiTypeface;
|
2018-02-20 22:06:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* emoji_sample_text() {
|
2019-03-20 16:12:10 +00:00
|
|
|
return "\xF0\x9F\x98\x80"
|
|
|
|
" "
|
|
|
|
"\xE2\x99\xA2"; // 😀 ♢
|
2018-02-20 22:06:07 +00:00
|
|
|
}
|
2020-08-18 17:17:09 +00:00
|
|
|
|
|
|
|
sk_sp<SkTypeface> sample_user_typeface() {
|
|
|
|
SkCustomTypefaceBuilder builder;
|
|
|
|
SkFont font;
|
|
|
|
const float upem = 200;
|
|
|
|
|
|
|
|
{
|
|
|
|
SkFontMetrics metrics;
|
|
|
|
metrics.fFlags = 0;
|
|
|
|
metrics.fTop = -200;
|
|
|
|
metrics.fAscent = -150;
|
|
|
|
metrics.fDescent = 50;
|
|
|
|
metrics.fBottom = -75;
|
|
|
|
metrics.fLeading = 10;
|
|
|
|
metrics.fAvgCharWidth = 150;
|
|
|
|
metrics.fMaxCharWidth = 300;
|
|
|
|
metrics.fXMin = -20;
|
|
|
|
metrics.fXMax = 290;
|
|
|
|
metrics.fXHeight = -100;
|
|
|
|
metrics.fCapHeight = 0;
|
|
|
|
metrics.fUnderlineThickness = 5;
|
|
|
|
metrics.fUnderlinePosition = 2;
|
|
|
|
metrics.fStrikeoutThickness = 5;
|
|
|
|
metrics.fStrikeoutPosition = -50;
|
|
|
|
builder.setMetrics(metrics, 1.0f/upem);
|
|
|
|
}
|
|
|
|
builder.setFontStyle(SkFontStyle(367, 3, SkFontStyle::kOblique_Slant));
|
|
|
|
|
|
|
|
const SkMatrix scale = SkMatrix::Scale(1.0f/upem, 1.0f/upem);
|
|
|
|
for (SkGlyphID index = 0; index <= 67; ++index) {
|
|
|
|
SkScalar width;
|
|
|
|
width = 100;
|
|
|
|
|
2020-08-25 15:48:41 +00:00
|
|
|
builder.setGlyph(index, width/upem, SkPath::Circle(50, -50, 75).makeTransform(scale));
|
2020-08-18 17:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return builder.detach();
|
|
|
|
}
|
|
|
|
|
2018-07-10 23:40:15 +00:00
|
|
|
static sk_sp<SkTypeface> create_font(const char* name, SkFontStyle style) {
|
|
|
|
static sk_sp<SkFontMgr> portableFontMgr = MakePortableFontMgr();
|
|
|
|
return portableFontMgr->legacyMakeTypeface(name, style);
|
|
|
|
}
|
|
|
|
|
2018-02-20 22:06:07 +00:00
|
|
|
sk_sp<SkTypeface> create_portable_typeface(const char* name, SkFontStyle style) {
|
|
|
|
return create_font(name, style);
|
|
|
|
}
|
2019-03-20 16:12:10 +00:00
|
|
|
} // namespace ToolUtils
|