From 483c772cfdd646fad3ae8aa187136191ae3babdc Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Tue, 20 Feb 2018 17:06:07 -0500 Subject: Add nativeFonts flag to Viewer. This moves DMFontMgr and several related files which are tightly related to fonts into tools/fonts, moves some flags around to prevent duplication, and adds the nativeFonts handling to Viewer. Change-Id: Id1bdad708a6b74319ac5ac9adfe21025db4ca0b2 Reviewed-on: https://skia-review.googlesource.com/108904 Commit-Queue: Ben Wagner Reviewed-by: Mike Klein --- dm/DM.cpp | 6 +-- dm/DMFontMgr.cpp | 147 ------------------------------------------------------- dm/DMFontMgr.h | 19 ------- 3 files changed, 2 insertions(+), 170 deletions(-) delete mode 100644 dm/DMFontMgr.cpp delete mode 100644 dm/DMFontMgr.h (limited to 'dm') diff --git a/dm/DM.cpp b/dm/DM.cpp index f1c4a4ca74..ef35e2cd02 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -5,7 +5,6 @@ * found in the LICENSE file. */ -#include "DMFontMgr.h" #include "DMJsonWriter.h" #include "DMSrcSink.h" #include "ProcStats.h" @@ -37,6 +36,7 @@ #include "SkPngEncoder.h" #include "SkScan.h" #include "SkSpinlock.h" +#include "SkTestFontMgr.h" #include "SkTHash.h" #include "SkTaskGroup.h" #include "SkTypeface_win.h" @@ -103,8 +103,6 @@ DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execution"); DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821 -DEFINE_bool(nativeFonts, true, "If true, use native font manager and rendering. " - "If false, fonts will draw as portably as possible."); DEFINE_bool(gdi, false, "On Windows, use GDI instead of DirectWrite for font rendering."); using namespace DM; @@ -1323,7 +1321,7 @@ int main(int argc, char** argv) { SkCommandLineFlags::Parse(argc, argv); if (!FLAGS_nativeFonts) { - gSkFontMgr_DefaultFactory = &DM::MakeFontMgr; + gSkFontMgr_DefaultFactory = &sk_tool_utils::MakePortableFontMgr; } #if defined(SK_BUILD_FOR_WIN) diff --git a/dm/DMFontMgr.cpp b/dm/DMFontMgr.cpp deleted file mode 100644 index d5915724d3..0000000000 --- a/dm/DMFontMgr.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "DMFontMgr.h" -#include "SkFontDescriptor.h" -#include "sk_tool_utils.h" - -namespace { - -static constexpr const char* kFamilyNames[] = { - "Toy Liberation Sans", - "Toy Liberation Serif", - "Toy Liberation Mono", -}; - -class FontStyleSet final : public SkFontStyleSet { -public: - explicit 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()); - } - - int count() override { return 4; } - - void getStyle(int index, SkFontStyle* style, SkString* name) override { - switch (index) { - default: - case 0: if (style) { *style = SkFontStyle::Normal(); } - if (name) { *name = "Normal"; } - break; - case 1: if (style) { *style = SkFontStyle::Bold(); } - if (name) { *name = "Bold"; } - break; - case 2: if (style) { *style = SkFontStyle::Italic(); } - if (name) { *name = "Italic"; } - break; - case 3: if (style) { *style = SkFontStyle::BoldItalic(); } - if (name) { *name = "BoldItalic"; } - break; - } - } - - SkTypeface* createTypeface(int index) override { - return SkRef(fTypefaces[index].get()); - } - - SkTypeface* matchStyle(const SkFontStyle& pattern) override { - return this->matchStyleCSS3(pattern); - } - -private: - sk_sp fTypefaces[4]; -}; - -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // - -class FontMgr final : public SkFontMgr { -public: - FontMgr() { - fFamilies[0] = sk_make_sp(0); - fFamilies[1] = sk_make_sp(1); - fFamilies[2] = sk_make_sp(2); - } - - int onCountFamilies() const override { return SK_ARRAY_COUNT(fFamilies); } - - void onGetFamilyName(int index, SkString* familyName) const override { - *familyName = kFamilyNames[index]; - } - - SkFontStyleSet* onCreateStyleSet(int index) const override { - return SkRef(fFamilies[index].get()); - } - - 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); } - if (strstr(familyName, "ono")) { return this->createStyleSet(2); } - } - return this->createStyleSet(0); - } - - - SkTypeface* onMatchFamilyStyle(const char familyName[], - const SkFontStyle& style) const override { - sk_sp styleSet(this->matchFamily(familyName)); - return styleSet->matchStyle(style); - } - - 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* onMatchFaceStyle(const SkTypeface* tf, - const SkFontStyle& style) const override { - SkString familyName; - tf->getFamilyName(&familyName); - return this->matchFamilyStyle(familyName.c_str(), style); - } - - sk_sp onMakeFromData(sk_sp, int ttcIndex) const override { - return nullptr; - } - sk_sp onMakeFromStreamIndex(std::unique_ptr, - int ttcIndex) const override { - return nullptr; - } - sk_sp onMakeFromStreamArgs(std::unique_ptr, - const SkFontArguments&) const override { - return nullptr; - } - sk_sp onMakeFromFontData(std::unique_ptr) const override { - return nullptr; - } - sk_sp onMakeFromFile(const char path[], int ttcIndex) const override { - return nullptr; - } - - sk_sp onLegacyMakeTypeface(const char familyName[], - SkFontStyle style) const override { - return sk_sp(this->matchFamilyStyle(familyName, style)); - } - -private: - sk_sp fFamilies[3]; -}; -} - -namespace DM { -sk_sp MakeFontMgr() { return sk_make_sp(); } -} // namespace DM diff --git a/dm/DMFontMgr.h b/dm/DMFontMgr.h deleted file mode 100644 index dbbe61c3b4..0000000000 --- a/dm/DMFontMgr.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef DMFontMgr_DEFINED -#define DMFontMgr_DEFINED - -#include "SkFontMgr.h" - -// An SkFontMgr that always uses sk_tool_utils::create_portable_typeface(). - -namespace DM { - sk_sp MakeFontMgr(); -} // namespace DM - -#endif//DMFontMgr_DEFINED -- cgit v1.2.3