aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/fonts/sk_tool_utils_font.cpp
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2018-07-10 19:40:15 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-13 15:01:04 +0000
commit83c6b96bcd38702ec8bbe98f5f77f91121102ad9 (patch)
tree62f6b918894e7d1865c020bb0828b0250c2062c8 /tools/fonts/sk_tool_utils_font.cpp
parenta07bf6788e926c41d52ae4bed592ec8a187ee4ab (diff)
Improve SkTestFontMgr.
This moves the portable typefaces into the portable font manager. Change-Id: Id25e8f0b90f99c82d09cfb3ef136bda8c7728ee9 Reviewed-on: https://skia-review.googlesource.com/140351 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'tools/fonts/sk_tool_utils_font.cpp')
-rw-r--r--tools/fonts/sk_tool_utils_font.cpp60
1 files changed, 7 insertions, 53 deletions
diff --git a/tools/fonts/sk_tool_utils_font.cpp b/tools/fonts/sk_tool_utils_font.cpp
index 4d5b86aa0a..f14825adeb 100644
--- a/tools/fonts/sk_tool_utils_font.cpp
+++ b/tools/fonts/sk_tool_utils_font.cpp
@@ -11,64 +11,13 @@
#include "SkFontStyle.h"
#include "SkMutex.h"
#include "SkOSFile.h"
-#include "SkTestTypeface.h"
+#include "SkPaint.h"
+#include "SkTestFontMgr.h"
#include "SkUtils.h"
#include "sk_tool_utils.h"
namespace sk_tool_utils {
-#include "test_font_monospace.inc"
-#include "test_font_sans_serif.inc"
-#include "test_font_serif.inc"
-#include "test_font_index.inc"
-
-void release_portable_typefaces() {
- for (int index = 0; index < gTestFontsCount; ++index) {
- SkTestFontData& fontData = gTestFonts[index];
- fontData.fCachedFont.reset();
- }
-}
-
-SK_DECLARE_STATIC_MUTEX(gTestFontMutex);
-
-sk_sp<SkTypeface> create_font(const char* name, SkFontStyle style) {
- SkTestFontData* fontData = nullptr;
- const SubFont* sub;
- if (name) {
- for (int index = 0; index < gSubFontsCount; ++index) {
- sub = &gSubFonts[index];
- if (!strcmp(name, sub->fName) && sub->fStyle == style) {
- fontData = &sub->fFont;
- break;
- }
- }
- if (!fontData) {
- // Once all legacy callers to portable fonts are converted, replace this with
- // SK_ABORT();
- SkDebugf("missing %s weight %d, width %d, slant %d\n",
- name, style.weight(), style.width(), style.slant());
- // If we called SkTypeface::CreateFromName() here we'd recurse infinitely,
- // so we reimplement its core logic here inline without the recursive aspect.
- sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
- return fm->legacyMakeTypeface(name, style);
- }
- } else {
- sub = &gSubFonts[gDefaultFontIndex];
- fontData = &sub->fFont;
- }
- sk_sp<SkTestFont> font;
- {
- SkAutoMutexAcquire ac(gTestFontMutex);
- if (fontData->fCachedFont) {
- font = fontData->fCachedFont;
- } else {
- font = sk_make_sp<SkTestFont>(*fontData);
- fontData->fCachedFont = font;
- }
- }
- return sk_make_sp<SkTestTypeface>(std::move(font), style);
-}
-
sk_sp<SkTypeface> emoji_typeface() {
const char* filename;
#if defined(SK_BUILD_FOR_WIN)
@@ -118,6 +67,11 @@ const char* platform_font_manager() {
return "";
}
+static sk_sp<SkTypeface> create_font(const char* name, SkFontStyle style) {
+ static sk_sp<SkFontMgr> portableFontMgr = MakePortableFontMgr();
+ return portableFontMgr->legacyMakeTypeface(name, style);
+}
+
sk_sp<SkTypeface> create_portable_typeface(const char* name, SkFontStyle style) {
return create_font(name, style);
}