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];
|
|
|
|
SkSafeUnref(fontData.fFontCache);
|
|
|
|
}
|
|
|
|
}
|
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();
|
2014-07-31 12:58:44 +00:00
|
|
|
SkDebugf("missing %s %d\n", name, style);
|
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.
|
|
|
|
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
|
2016-05-31 18:42:36 +00:00
|
|
|
return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, style));
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sub = &gSubFonts[gDefaultFontIndex];
|
|
|
|
fontData = &sub->fFont;
|
|
|
|
}
|
|
|
|
SkTestFont* font;
|
|
|
|
{
|
|
|
|
SkAutoMutexAcquire ac(gTestFontMutex);
|
|
|
|
if (fontData->fFontCache) {
|
|
|
|
font = SkSafeRef(fontData->fFontCache);
|
|
|
|
} else {
|
2015-08-26 20:07:48 +00:00
|
|
|
font = new SkTestFont(*fontData);
|
2014-07-31 12:58:44 +00:00
|
|
|
SkDEBUGCODE(font->fDebugName = sub->fName);
|
|
|
|
SkDEBUGCODE(font->fDebugStyle = sub->fStyle);
|
|
|
|
fontData->fFontCache = SkSafeRef(font);
|
|
|
|
}
|
|
|
|
}
|
2016-05-31 18:42:36 +00:00
|
|
|
return sk_make_sp<SkTestTypeface>(font, style);
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
2014-06-23 18:25:00 +00:00
|
|
|
|
|
|
|
}
|