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 {
|
|
|
|
|
2015-06-10 16:31:09 +00:00
|
|
|
#include "test_font_monospace.cpp"
|
|
|
|
#include "test_font_sans_serif.cpp"
|
|
|
|
#include "test_font_serif.cpp"
|
|
|
|
#include "test_font_index.cpp"
|
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
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
SK_DECLARE_STATIC_MUTEX(gTestFontMutex);
|
|
|
|
|
|
|
|
SkTypeface* create_font(const char* name, SkTypeface::Style 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
|
|
|
|
// SK_CRASH();
|
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());
|
|
|
|
return 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);
|
|
|
|
}
|
|
|
|
}
|
2015-08-26 20:07:48 +00:00
|
|
|
return new SkTestTypeface(font, SkFontStyle(style));
|
2014-07-31 12:58:44 +00:00
|
|
|
}
|
2014-06-23 18:25:00 +00:00
|
|
|
|
|
|
|
}
|