diff --git a/include/core/SkFont.h b/include/core/SkFont.h index 08928ae4ec..ce910bb739 100644 --- a/include/core/SkFont.h +++ b/include/core/SkFont.h @@ -495,6 +495,7 @@ private: void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const; friend class SkCanonicalizeFont; + friend class SkFontPriv; friend class SkPaint; friend class SVGTextBuilder; }; diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp index db07281c57..6db43ea0b5 100644 --- a/src/core/SkFont.cpp +++ b/src/core/SkFont.cpp @@ -186,7 +186,7 @@ void SkFont::glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar tex auto typeface = SkFontPriv::GetTypefaceOrDefault(*this); const unsigned numGlyphsInTypeface = typeface->countGlyphs(); - SkAutoTArray unichars(count); + SkAutoTArray unichars(numGlyphsInTypeface); typeface->getGlyphToUnicodeMap(unichars.get()); for (int i = 0; i < count; ++i) { @@ -558,3 +558,7 @@ int SkFontPriv::CountTextElements(const void* text, size_t byteLength, SkTextEnc return 0; } +void SkFontPriv::GlyphsToUnichars(const SkFont& font, const uint16_t glyphs[], int count, + SkUnichar uni[]) { + font.glyphsToUnichars(glyphs, count, uni); +} diff --git a/src/core/SkFontPriv.h b/src/core/SkFontPriv.h index a0bbec3ae4..6b34aa0214 100644 --- a/src/core/SkFontPriv.h +++ b/src/core/SkFontPriv.h @@ -61,6 +61,8 @@ public: // Returns the number of elements (characters or glyphs) in the array. static int CountTextElements(const void* text, size_t byteLength, SkTextEncoding); + + static void GlyphsToUnichars(const SkFont&, const uint16_t glyphs[], int count, SkUnichar[]); }; class SkAutoToGlyphs { diff --git a/tests/UnicodeTest.cpp b/tests/UnicodeTest.cpp index 62174e9809..fac3eb9cc2 100644 --- a/tests/UnicodeTest.cpp +++ b/tests/UnicodeTest.cpp @@ -47,3 +47,24 @@ DEF_TEST(Unicode_textencodings, reporter) { REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs16, count8 * sizeof(uint16_t))); REPORTER_ASSERT(reporter, !memcmp(glyphs8, glyphs32, count8 * sizeof(uint16_t))); } + +#include "SkFont.h" +#include "SkFontPriv.h" + +DEF_TEST(glyphs_to_unichars, reporter) { + SkFont font; + + const int N = 52; + SkUnichar uni[N]; + for (int i = 0; i < 26; ++i) { + uni[i + 0] = i + 'A'; + uni[i + 26] = i + 'a'; + } + uint16_t glyphs[N]; + font.textToGlyphs(uni, sizeof(uni), kUTF32_SkTextEncoding, glyphs, N); + + SkUnichar uni2[N]; + SkFontPriv::GlyphsToUnichars(font, glyphs, N, uni2); + REPORTER_ASSERT(reporter, memcmp(uni, uni2, sizeof(uni)) == 0); +} +