2014-06-23 18:25:00 +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.
|
|
|
|
*/
|
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
#include "Resources.h"
|
2015-06-10 16:31:09 +00:00
|
|
|
#include "SkFontMgr.h"
|
2015-07-07 19:21:21 +00:00
|
|
|
#include "SkMutex.h"
|
2014-07-31 12:58:44 +00:00
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkTestScalerContext.h"
|
|
|
|
#include "SkUtils.h"
|
|
|
|
#include "sk_tool_utils.h"
|
2014-06-23 18:25:00 +00:00
|
|
|
|
|
|
|
namespace sk_tool_utils {
|
|
|
|
|
2016-07-27 18:12:12 +00:00
|
|
|
#include "test_font_monospace.inc"
|
|
|
|
#include "test_font_sans_serif.inc"
|
|
|
|
#include "test_font_serif.inc"
|
|
|
|
#include "test_font_index.inc"
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2015-06-15 13:48:30 +00:00
|
|
|
void release_portable_typefaces() {
|
2014-07-31 13:36:45 +00:00
|
|
|
for (int index = 0; index < gTestFontsCount; ++index) {
|
2014-07-31 12:58:44 +00:00
|
|
|
SkTestFontData& fontData = gTestFonts[index];
|
2016-10-20 20:06:52 +00:00
|
|
|
fontData.fCachedFont.reset();
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-23 18:25:00 +00:00
|
|
|
|
2016-05-05 00:12:46 +00:00
|
|
|
SK_DECLARE_STATIC_MUTEX(gTestFontMutex);
|
2014-07-31 12:58:44 +00:00
|
|
|
|
2016-05-31 18:42:36 +00:00
|
|
|
sk_sp<SkTypeface> create_font(const char* name, SkFontStyle style) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkTestFontData* fontData = nullptr;
|
2014-07-31 12:58:44 +00:00
|
|
|
const SubFont* sub;
|
|
|
|
if (name) {
|
2014-07-31 13:36:45 +00:00
|
|
|
for (int index = 0; index < gSubFontsCount; ++index) {
|
2014-07-31 12:58:44 +00:00
|
|
|
sub = &gSubFonts[index];
|
|
|
|
if (!strcmp(name, sub->fName) && sub->fStyle == style) {
|
|
|
|
fontData = &sub->fFont;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!fontData) {
|
2015-06-10 16:31:09 +00:00
|
|
|
// Once all legacy callers to portable fonts are converted, replace this with
|
2016-01-29 16:51:04 +00:00
|
|
|
// SK_ABORT();
|
2016-09-27 13:10:15 +00:00
|
|
|
SkDebugf("missing %s weight %d, width %d, slant %d\n",
|
|
|
|
name, style.weight(), style.width(), style.slant());
|
2015-06-10 16:31:09 +00:00
|
|
|
// If we called SkTypeface::CreateFromName() here we'd recurse infinitely,
|
|
|
|
// so we reimplement its core logic here inline without the recursive aspect.
|
2016-11-03 20:26:13 +00:00
|
|
|
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
|
2017-09-26 13:46:08 +00:00
|
|
|
return fm->legacyMakeTypeface(name, style);
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sub = &gSubFonts[gDefaultFontIndex];
|
|
|
|
fontData = &sub->fFont;
|
|
|
|
}
|
2016-10-20 20:06:52 +00:00
|
|
|
sk_sp<SkTestFont> font;
|
2014-07-31 12:58:44 +00:00
|
|
|
{
|
|
|
|
SkAutoMutexAcquire ac(gTestFontMutex);
|
2016-10-20 20:06:52 +00:00
|
|
|
if (fontData->fCachedFont) {
|
|
|
|
font = fontData->fCachedFont;
|
2014-07-31 12:58:44 +00:00
|
|
|
} else {
|
2016-10-20 20:06:52 +00:00
|
|
|
font = sk_make_sp<SkTestFont>(*fontData);
|
|
|
|
fontData->fCachedFont = font;
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-20 20:06:52 +00:00
|
|
|
return sk_make_sp<SkTestTypeface>(std::move(font), style);
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
2014-06-23 18:25:00 +00:00
|
|
|
|
|
|
|
}
|