aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-11-10 13:42:29 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-10 19:19:07 +0000
commit71a38d9baecf18a684a9c59752b3e9b46a04bce4 (patch)
tree4baef03f63b6b45a06392f7ae1684e5d09a9784d /tools
parent36068b232c4e615e8bd6f9c0528b7819530c8796 (diff)
implement SkTestTypeface::onCharsToGlyphs()
It has only been working for UTF32. Change-Id: I69329dd43b6d240516e4ab40df6e8c9f7bebf8a8 Reviewed-on: https://skia-review.googlesource.com/70102 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/SkTestScalerContext.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/tools/SkTestScalerContext.cpp b/tools/SkTestScalerContext.cpp
index 34ec6af849..8a3c304849 100644
--- a/tools/SkTestScalerContext.cpp
+++ b/tools/SkTestScalerContext.cpp
@@ -18,6 +18,7 @@
#include "SkScalerContext.h"
#include "SkTestScalerContext.h"
#include "SkTypefaceCache.h"
+#include "SkUtils.h"
SkTestFont::SkTestFont(const SkTestFontData& fontData)
: INHERITED()
@@ -173,10 +174,18 @@ void SkTestTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal)
int SkTestTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const {
- SkASSERT(encoding == kUTF32_Encoding);
- for (int index = 0; index < glyphCount; ++index) {
- SkUnichar ch = ((SkUnichar*) chars)[index];
- glyphs[index] = fTestFont->codeToIndex(ch);
+ auto utf8 = (const char*)chars;
+ auto utf16 = (const uint16_t*)chars;
+ auto utf32 = (const SkUnichar*)chars;
+
+ for (int i = 0; i < glyphCount; i++) {
+ SkUnichar ch;
+ switch (encoding) {
+ case kUTF8_Encoding: ch = SkUTF8_NextUnichar(&utf8 ); break;
+ case kUTF16_Encoding: ch = SkUTF16_NextUnichar(&utf16); break;
+ case kUTF32_Encoding: ch = *utf32++; break;
+ }
+ glyphs[i] = fTestFont->codeToIndex(ch);
}
return glyphCount;
}