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>
This commit is contained in:
Florin Malita 2020-05-15 15:56:07 -04:00 committed by Skia Commit-Bot
parent 3ea86251b9
commit 839e70f17e
2 changed files with 3 additions and 13 deletions

View File

@ -54,17 +54,7 @@ public:
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; }

View File

@ -105,7 +105,7 @@ void SkUserTypeface::onFilterRec(SkScalerContextRec* rec) const {
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::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal)
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;
}
}