aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-11-09 13:45:10 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-10 15:30:57 +0000
commitcb6940bf42e39271afe0fb3c2bfdd9e28d12f504 (patch)
tree9d600f8679a5694c3b4ff71166d67cf09a37d433 /dm
parent35970ec0c861f7b5ee7cca2789b7dc5954cb6bb4 (diff)
DM FontMgr updates
- return nullptr for the various makeFromFoo() that we can't support, and tweak a few unit tests to bail out early when they do - create FontStyleSet and SkTypefaces once - abort early from FontHostStream if we can't openStream() - implement SkTestTypeface::onCreateFamilyNameIterator() with SkOTUtils::LocalizedStrings_SingleName() so FontNames passes - pin out-of-range glyph IDs to zero in SkTestTypeface Change-Id: Iac53265e331fc1c5c507513af3ab299063e6610a Reviewed-on: https://skia-review.googlesource.com/69501 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'dm')
-rw-r--r--dm/DMFontMgr.cpp43
-rw-r--r--dm/DMFontMgr.h10
2 files changed, 34 insertions, 19 deletions
diff --git a/dm/DMFontMgr.cpp b/dm/DMFontMgr.cpp
index 51ee6122d0..d275c412c7 100644
--- a/dm/DMFontMgr.cpp
+++ b/dm/DMFontMgr.cpp
@@ -17,10 +17,18 @@ namespace DM {
"Toy Liberation Mono",
};
- FontStyleSet::FontStyleSet(int familyIndex) : fFamilyName(kFamilyNames[familyIndex]) {}
+ FontStyleSet::FontStyleSet(int familyIndex) {
+ using sk_tool_utils::create_portable_typeface;
+ const char* familyName = kFamilyNames[familyIndex];
+
+ fTypefaces[0] = create_portable_typeface(familyName, SkFontStyle::Normal());
+ fTypefaces[1] = create_portable_typeface(familyName, SkFontStyle::Bold());
+ fTypefaces[2] = create_portable_typeface(familyName, SkFontStyle::Italic());
+ fTypefaces[3] = create_portable_typeface(familyName, SkFontStyle::BoldItalic());
+ }
- // Each font family has 4 styles: Normal, Bold, Italic, BoldItalic.
int FontStyleSet::count() { return 4; }
+
void FontStyleSet::getStyle(int index, SkFontStyle* style, SkString* name) {
switch (index) {
default:
@@ -39,27 +47,30 @@ namespace DM {
}
}
- SkTypeface* FontStyleSet::matchStyle(const SkFontStyle& style) {
- return this->matchStyleCSS3(style);
- }
-
SkTypeface* FontStyleSet::createTypeface(int index) {
- SkFontStyle style;
- this->getStyle(index, &style, nullptr);
+ return SkRef(fTypefaces[index].get());
+ }
- return sk_tool_utils::create_portable_typeface(fFamilyName, style).release();
+ SkTypeface* FontStyleSet::matchStyle(const SkFontStyle& pattern) {
+ return this->matchStyleCSS3(pattern);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
- int FontMgr::onCountFamilies() const { return SK_ARRAY_COUNT(kFamilyNames); }
+ FontMgr::FontMgr() {
+ fFamilies[0] = sk_make_sp<FontStyleSet>(0);
+ fFamilies[1] = sk_make_sp<FontStyleSet>(1);
+ fFamilies[2] = sk_make_sp<FontStyleSet>(2);
+ }
+
+ int FontMgr::onCountFamilies() const { return SK_ARRAY_COUNT(fFamilies); }
void FontMgr::onGetFamilyName(int index, SkString* familyName) const {
*familyName = kFamilyNames[index];
}
SkFontStyleSet* FontMgr::onCreateStyleSet(int index) const {
- return new FontStyleSet(index);
+ return SkRef(fFamilies[index].get());
}
SkFontStyleSet* FontMgr::onMatchFamily(const char familyName[]) const {
@@ -96,25 +107,25 @@ namespace DM {
}
sk_sp<SkTypeface> FontMgr::onMakeFromData(sk_sp<SkData>, int ttcIndex) const {
- return sk_sp<SkTypeface>(this->matchFamilyStyle("Sans", SkFontStyle::Normal()));
+ return nullptr;
}
sk_sp<SkTypeface> FontMgr::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
int ttcIndex) const {
- return sk_sp<SkTypeface>(this->matchFamilyStyle("Sans", SkFontStyle::Normal()));
+ return nullptr;
}
sk_sp<SkTypeface> FontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
const SkFontArguments&) const {
- return sk_sp<SkTypeface>(this->matchFamilyStyle("Sans", SkFontStyle::Normal()));
+ return nullptr;
}
sk_sp<SkTypeface> FontMgr::onMakeFromFontData(std::unique_ptr<SkFontData>) const {
- return sk_sp<SkTypeface>(this->matchFamilyStyle("Sans", SkFontStyle::Normal()));
+ return nullptr;
}
sk_sp<SkTypeface> FontMgr::onMakeFromFile(const char path[], int ttcIndex) const {
- return sk_sp<SkTypeface>(this->matchFamilyStyle("Sans", SkFontStyle::Normal()));
+ return nullptr;
}
sk_sp<SkTypeface> FontMgr::onLegacyMakeTypeface(const char familyName[],
diff --git a/dm/DMFontMgr.h b/dm/DMFontMgr.h
index b2eb0ac864..c484644fb4 100644
--- a/dm/DMFontMgr.h
+++ b/dm/DMFontMgr.h
@@ -14,7 +14,6 @@
namespace DM {
- // Returned by DM::FontMgr below.
class FontStyleSet final : public SkFontStyleSet {
public:
explicit FontStyleSet(int familyIndex);
@@ -25,10 +24,12 @@ namespace DM {
SkTypeface* matchStyle(const SkFontStyle& pattern) override;
private:
- const char* fFamilyName;
+ sk_sp<SkTypeface> fTypefaces[4];
};
- struct FontMgr final : public SkFontMgr {
+ class FontMgr final : public SkFontMgr {
+ public:
+ FontMgr();
int onCountFamilies() const override;
void onGetFamilyName(int index, SkString* familyName) const override;
@@ -54,6 +55,9 @@ namespace DM {
sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override;
sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle) const override;
+
+ private:
+ sk_sp<FontStyleSet> fFamilies[3];
};
} // namespace DM