aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-11-14 10:34:48 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-14 16:24:44 +0000
commitccafca0054670b02a02d6d256de490c45e787391 (patch)
treeb8242b71f83713481aeb0a5e3c9cdd3402663538 /dm
parent3e31e99babe3a6776d345f433d6966ef444d640b (diff)
DM: hide DM:FontMgr behind a factory
Change-Id: I4dc745479ceb1d5ca1ddb4a0904f342576e4562c Reviewed-on: https://skia-review.googlesource.com/71240 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'dm')
-rw-r--r--dm/DM.cpp8
-rw-r--r--dm/DMFontMgr.cpp89
-rw-r--r--dm/DMFontMgr.h48
3 files changed, 53 insertions, 92 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 075a0b2c83..77538cfdc3 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -1320,16 +1320,12 @@ int main(int argc, char** argv) {
SkCommandLineFlags::Parse(argc, argv);
if (!FLAGS_nativeFonts) {
- gSkFontMgr_DefaultFactory = []() -> sk_sp<SkFontMgr> {
- return sk_make_sp<DM::FontMgr>();
- };
+ gSkFontMgr_DefaultFactory = &DM::MakeFontMgr;
}
#if defined(SK_BUILD_FOR_WIN)
if (FLAGS_gdi) {
- gSkFontMgr_DefaultFactory = []() -> sk_sp<SkFontMgr> {
- return SkFontMgr_New_GDI();
- };
+ gSkFontMgr_DefaultFactory = &SkFontMgr_New_GDI;
}
#endif
diff --git a/dm/DMFontMgr.cpp b/dm/DMFontMgr.cpp
index d275c412c7..d5915724d3 100644
--- a/dm/DMFontMgr.cpp
+++ b/dm/DMFontMgr.cpp
@@ -9,15 +9,17 @@
#include "SkFontDescriptor.h"
#include "sk_tool_utils.h"
-namespace DM {
+namespace {
- static constexpr const char* kFamilyNames[] = {
- "Toy Liberation Sans",
- "Toy Liberation Serif",
- "Toy Liberation Mono",
- };
+static constexpr const char* kFamilyNames[] = {
+ "Toy Liberation Sans",
+ "Toy Liberation Serif",
+ "Toy Liberation Mono",
+};
- FontStyleSet::FontStyleSet(int familyIndex) {
+class FontStyleSet final : public SkFontStyleSet {
+public:
+ explicit FontStyleSet(int familyIndex) {
using sk_tool_utils::create_portable_typeface;
const char* familyName = kFamilyNames[familyIndex];
@@ -27,9 +29,9 @@ namespace DM {
fTypefaces[3] = create_portable_typeface(familyName, SkFontStyle::BoldItalic());
}
- int FontStyleSet::count() { return 4; }
+ int count() override { return 4; }
- void FontStyleSet::getStyle(int index, SkFontStyle* style, SkString* name) {
+ void getStyle(int index, SkFontStyle* style, SkString* name) override {
switch (index) {
default:
case 0: if (style) { *style = SkFontStyle::Normal(); }
@@ -47,33 +49,39 @@ namespace DM {
}
}
- SkTypeface* FontStyleSet::createTypeface(int index) {
+ SkTypeface* createTypeface(int index) override {
return SkRef(fTypefaces[index].get());
}
- SkTypeface* FontStyleSet::matchStyle(const SkFontStyle& pattern) {
+ SkTypeface* matchStyle(const SkFontStyle& pattern) override {
return this->matchStyleCSS3(pattern);
}
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
+private:
+ sk_sp<SkTypeface> fTypefaces[4];
+};
+
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
- FontMgr::FontMgr() {
+class FontMgr final : public SkFontMgr {
+public:
+ 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); }
+ int onCountFamilies() const override { return SK_ARRAY_COUNT(fFamilies); }
- void FontMgr::onGetFamilyName(int index, SkString* familyName) const {
+ void onGetFamilyName(int index, SkString* familyName) const override {
*familyName = kFamilyNames[index];
}
- SkFontStyleSet* FontMgr::onCreateStyleSet(int index) const {
+ SkFontStyleSet* onCreateStyleSet(int index) const override {
return SkRef(fFamilies[index].get());
}
- SkFontStyleSet* FontMgr::onMatchFamily(const char familyName[]) const {
+ SkFontStyleSet* onMatchFamily(const char familyName[]) const override {
if (familyName) {
if (strstr(familyName, "ans")) { return this->createStyleSet(0); }
if (strstr(familyName, "erif")) { return this->createStyleSet(1); }
@@ -82,55 +90,58 @@ namespace DM {
return this->createStyleSet(0);
}
- SkTypeface* FontMgr::onMatchFamilyStyle(const char familyName[],
- const SkFontStyle& style) const {
+
+ SkTypeface* onMatchFamilyStyle(const char familyName[],
+ const SkFontStyle& style) const override {
sk_sp<SkFontStyleSet> styleSet(this->matchFamily(familyName));
return styleSet->matchStyle(style);
}
- SkTypeface* FontMgr::onMatchFamilyStyleCharacter(const char familyName[],
- const SkFontStyle& style,
- const char* bcp47[],
- int bcp47Count,
- SkUnichar character) const {
+ SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
+ const SkFontStyle& style,
+ const char* bcp47[], int bcp47Count,
+ SkUnichar character) const override {
(void)bcp47;
(void)bcp47Count;
(void)character;
return this->matchFamilyStyle(familyName, style);
}
- SkTypeface* FontMgr::onMatchFaceStyle(const SkTypeface* tf,
- const SkFontStyle& style) const {
+ SkTypeface* onMatchFaceStyle(const SkTypeface* tf,
+ const SkFontStyle& style) const override {
SkString familyName;
tf->getFamilyName(&familyName);
return this->matchFamilyStyle(familyName.c_str(), style);
}
- sk_sp<SkTypeface> FontMgr::onMakeFromData(sk_sp<SkData>, int ttcIndex) const {
+ sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override {
return nullptr;
}
-
- sk_sp<SkTypeface> FontMgr::onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
- int ttcIndex) const {
+ sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
+ int ttcIndex) const override {
return nullptr;
}
-
- sk_sp<SkTypeface> FontMgr::onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
- const SkFontArguments&) const {
+ sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
+ const SkFontArguments&) const override {
return nullptr;
}
-
- sk_sp<SkTypeface> FontMgr::onMakeFromFontData(std::unique_ptr<SkFontData>) const {
+ sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) const override {
return nullptr;
}
-
- sk_sp<SkTypeface> FontMgr::onMakeFromFile(const char path[], int ttcIndex) const {
+ sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
return nullptr;
}
- sk_sp<SkTypeface> FontMgr::onLegacyMakeTypeface(const char familyName[],
- SkFontStyle style) const {
+ sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[],
+ SkFontStyle style) const override {
return sk_sp<SkTypeface>(this->matchFamilyStyle(familyName, style));
}
+private:
+ sk_sp<FontStyleSet> fFamilies[3];
+};
+}
+
+namespace DM {
+sk_sp<SkFontMgr> MakeFontMgr() { return sk_make_sp<FontMgr>(); }
} // namespace DM
diff --git a/dm/DMFontMgr.h b/dm/DMFontMgr.h
index c484644fb4..dbbe61c3b4 100644
--- a/dm/DMFontMgr.h
+++ b/dm/DMFontMgr.h
@@ -13,53 +13,7 @@
// An SkFontMgr that always uses sk_tool_utils::create_portable_typeface().
namespace DM {
-
- class FontStyleSet final : public SkFontStyleSet {
- public:
- explicit FontStyleSet(int familyIndex);
-
- int count() override;
- void getStyle(int index, SkFontStyle* style, SkString* name) override;
- SkTypeface* createTypeface(int index) override;
- SkTypeface* matchStyle(const SkFontStyle& pattern) override;
-
- private:
- sk_sp<SkTypeface> fTypefaces[4];
- };
-
- class FontMgr final : public SkFontMgr {
- public:
- FontMgr();
-
- int onCountFamilies() const override;
- void onGetFamilyName(int index, SkString* familyName) const override;
-
- SkFontStyleSet* onCreateStyleSet(int index) const override;
- SkFontStyleSet* onMatchFamily(const char familyName[]) const override;
-
- SkTypeface* onMatchFamilyStyle(const char familyName[],
- const SkFontStyle&) const override;
- SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
- const SkFontStyle&,
- const char* bcp47[], int bcp47Count,
- SkUnichar character) const override;
- SkTypeface* onMatchFaceStyle(const SkTypeface*,
- const SkFontStyle&) const override;
-
- sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData>, int ttcIndex) const override;
- sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset>,
- int ttcIndex) const override;
- sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset>,
- const SkFontArguments&) const override;
- sk_sp<SkTypeface> onMakeFromFontData(std::unique_ptr<SkFontData>) const override;
- 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];
- };
-
+ sk_sp<SkFontMgr> MakeFontMgr();
} // namespace DM
#endif//DMFontMgr_DEFINED