Add an empty typeface for testing

Change-Id: I091389fcc41b9eb5002ae0d005360249b51884d9
Reviewed-on: https://skia-review.googlesource.com/150137
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 3369a9a..4350eb6 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1351,6 +1351,7 @@
       "tools/debugger/SkDrawCommand.cpp",
       "tools/debugger/SkJsonWriteBuffer.cpp",
       "tools/fonts/SkRandomScalerContext.cpp",
+      "tools/fonts/SkTestEmptyTypeface.h",
       "tools/fonts/SkTestFontMgr.cpp",
       "tools/fonts/SkTestFontMgr.h",
       "tools/fonts/SkTestSVGTypeface.cpp",
diff --git a/tests/TypefaceTest.cpp b/tests/TypefaceTest.cpp
index cc04fa2..37408f0 100644
--- a/tests/TypefaceTest.cpp
+++ b/tests/TypefaceTest.cpp
@@ -15,6 +15,7 @@
 #include "SkSFNTHeader.h"
 #include "SkStream.h"
 #include "SkRefCnt.h"
+#include "SkTestEmptyTypeface.h"
 #include "SkTypeface.h"
 #include "SkTypefaceCache.h"
 #include "Resources.h"
@@ -263,55 +264,6 @@
 
 }
 
-namespace {
-
-class EmptyTypeface : public SkTypeface {
-public:
-    static sk_sp<SkTypeface> Create() { return sk_sp<SkTypeface>(new EmptyTypeface()); }
-protected:
-    EmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
-
-    SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
-    sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
-        return sk_ref_sp(this);
-    }
-    SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
-                                           const SkDescriptor*) const override {
-        return nullptr;
-    }
-    void onFilterRec(SkScalerContextRec*) const override { }
-    std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
-        return nullptr;
-    }
-    void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
-    virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
-                                uint16_t glyphs[], int glyphCount) const override {
-        SK_ABORT("unimplemented");
-        return 0;
-    }
-    int onCountGlyphs() const override { return 0; }
-    int onGetUPEM() const override { return 0; }
-    void onGetFamilyName(SkString* familyName) const override { familyName->reset(); }
-    SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
-        SK_ABORT("unimplemented");
-        return nullptr;
-    }
-    int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
-                                     int coordinateCount) const override
-    {
-        return 0;
-    }
-    int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
-                                       int parameterCount) const override
-    {
-        return 0;
-    }
-    int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
-    size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override { return 0; }
-};
-
-}
-
 static bool count_proc(SkTypeface* face, void* ctx) {
     int* count = static_cast<int*>(ctx);
     *count = *count + 1;
@@ -325,12 +277,12 @@
 }
 
 DEF_TEST(TypefaceCache, reporter) {
-    sk_sp<SkTypeface> t1(EmptyTypeface::Create());
+    sk_sp<SkTypeface> t1(SkTestEmptyTypeface::Make());
     {
         SkTypefaceCache cache;
         REPORTER_ASSERT(reporter, count(reporter, cache) == 0);
         {
-            sk_sp<SkTypeface> t0(EmptyTypeface::Create());
+            sk_sp<SkTypeface> t0(SkTestEmptyTypeface::Make());
             cache.add(t0.get());
             REPORTER_ASSERT(reporter, count(reporter, cache) == 1);
             cache.add(t1.get());
diff --git a/tools/fonts/SkTestEmptyTypeface.h b/tools/fonts/SkTestEmptyTypeface.h
new file mode 100644
index 0000000..51ce6a6
--- /dev/null
+++ b/tools/fonts/SkTestEmptyTypeface.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkTestEmptyTypeface_DEFINED
+#define SkTestEmptyTypeface_DEFINED
+
+#include "SkTypeface.h"
+
+class SkTestEmptyTypeface : public SkTypeface {
+public:
+    static sk_sp<SkTypeface> Make() { return sk_sp<SkTypeface>(new SkTestEmptyTypeface); }
+protected:
+    SkTestEmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
+
+    SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
+    sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
+        return sk_ref_sp(this);
+    }
+    SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
+                                           const SkDescriptor*) const override {
+        return nullptr;
+    }
+    void onFilterRec(SkScalerContextRec*) const override { }
+    std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
+        return nullptr;
+    }
+    void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
+    virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
+                                uint16_t glyphs[], int glyphCount) const override {
+        if (glyphs && glyphCount > 0) {
+            sk_bzero(glyphs, glyphCount * sizeof(glyphs[0]));
+        }
+        return 0;
+    }
+    int onCountGlyphs() const override { return 0; }
+    int onGetUPEM() const override { return 0; }
+    class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings {
+    public:
+        bool next(SkTypeface::LocalizedString*) override { return false; }
+    };
+    void onGetFamilyName(SkString* familyName) const override {
+        familyName->reset();
+    }
+    SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
+        return new EmptyLocalizedStrings;
+    }
+    int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
+                                     int coordinateCount) const override
+    {
+        return 0;
+    }
+    int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
+                                       int parameterCount) const override
+    {
+        return 0;
+    }
+    int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
+    size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override {
+        return 0;
+    }
+};
+
+
+#endif  // SkTestEmptyTypeface_DEFINED