add test (and fix) for glyphsToUnichars

Bug: skia:
Change-Id: I2defcea7e9a37bdd203acc4ca97fc47a7f57cd43
Reviewed-on: https://skia-review.googlesource.com/c/176221
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2018-12-10 15:26:09 -05:00 committed by Skia Commit-Bot
parent d1ca672673
commit a0b54cd589
4 changed files with 29 additions and 1 deletions

View File

@ -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;
};

View File

@ -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<SkUnichar> unichars(count);
SkAutoTArray<SkUnichar> 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);
}

View File

@ -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 {

View File

@ -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);
}