Identity unichar <-> glyph_id mapping for SkCustomTypeface

Would be neat to support explicit mappings, but this is sufficient for
what I'm looking at now (allows passing custom tf + "strings" through
the existing shaping pipeline).

Change-Id: I62a8a0c90cc9f6bf3ede82932a8b6a2a933521c1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290197
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/gm/userfont.cpp b/gm/userfont.cpp
index ed20109..6a3bc89 100644
--- a/gm/userfont.cpp
+++ b/gm/userfont.cpp
@@ -54,17 +54,7 @@
         font.setSize(100);
         font.setEdging(SkFont::Edging::kAntiAlias);
 
-        std::vector<SkGlyphID> array;
-        auto expand8to16 = [&](const char str[]) {
-            for (int i = 0; str[i]; ++i) {
-                array.push_back(str[i]);
-            }
-        };
-
-        expand8to16("User Typeface");
-        fBlob = SkTextBlob::MakeFromText(array.data(), array.size() * sizeof(SkGlyphID),
-                                         font, SkTextEncoding::kGlyphID);
-
+        fBlob = SkTextBlob::MakeFromString("User Typeface", font);
     }
 
     bool runAsBench() const override { return true; }
diff --git a/src/utils/SkCustomTypeface.cpp b/src/utils/SkCustomTypeface.cpp
index 08a6569..36d2838 100644
--- a/src/utils/SkCustomTypeface.cpp
+++ b/src/utils/SkCustomTypeface.cpp
@@ -105,7 +105,7 @@
 
 void SkUserTypeface::getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const {
     for (int gid = 0; gid < this->glyphCount(); ++gid) {
-        glyphToUnicode[gid] = 0;
+        glyphToUnicode[gid] = SkTo<SkUnichar>(gid);
     }
 }
 
@@ -119,7 +119,7 @@
 
 void SkUserTypeface::onCharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const {
     for (int i = 0; i < count; ++i) {
-        glyphs[i] = 0;
+        glyphs[i] = uni[i] < this->glyphCount() ? SkTo<SkGlyphID>(uni[i]) : 0;
     }
 }