aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/atlastext.cpp
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-11-20 13:13:01 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-20 18:33:38 +0000
commit0c1c2b39dd93100542236b23546ed0b855816a49 (patch)
tree2f84e885f100bab54a5dc60c5565a639fa12b8d5 /gm/atlastext.cpp
parent999ec57291dc7cf1d8e3a745627670e6cadc1c12 (diff)
Make SkAtlasTextTarget use glyph IDs
Bug: skia: Change-Id: Idefd69f02f62fea22c41a3476676773221c3ae81 Reviewed-on: https://skia-review.googlesource.com/73700 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'gm/atlastext.cpp')
-rw-r--r--gm/atlastext.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/gm/atlastext.cpp b/gm/atlastext.cpp
index a25bb875b3..8270306e5e 100644
--- a/gm/atlastext.cpp
+++ b/gm/atlastext.cpp
@@ -15,6 +15,7 @@
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkTypeface.h"
+#include "SkUtils.h"
#include "gpu/TestContext.h"
#include "gpu/atlastext/GLTestAtlasTextRenderer.h"
#include "gpu/atlastext/TestAtlasTextRenderer.h"
@@ -24,10 +25,18 @@
static SkScalar draw_string(SkAtlasTextTarget* target, const SkString& text, SkScalar x, SkScalar y,
uint32_t color, sk_sp<SkTypeface> typeface, float size) {
- auto font = SkAtlasTextFont::Make(std::move(typeface), size);
- target->drawText(text.c_str(), text.size(), x, y, color, *font);
+ auto font = SkAtlasTextFont::Make(typeface, size);
+ int cnt = SkUTF8_CountUnichars(text.c_str());
+ std::unique_ptr<SkGlyphID[]> glyphs(new SkGlyphID[cnt]);
+ typeface->charsToGlyphs(text.c_str(), SkTypeface::Encoding::kUTF8_Encoding, glyphs.get(), cnt);
+
+ target->drawText(glyphs.get(), cnt, x, y, color, *font);
+
+ // Using a paint just to perform a measure to let the caller know how much space to skip in x.
SkPaint paint;
paint.setTextSize(size);
+ paint.setTypeface(std::move(typeface));
+ paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
return x + paint.measureText(text.c_str(), text.size());
}