Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Unified Diff: samplecode/SampleText.cpp

Issue 473633002: SkTextBlob (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: More const API, minimal docs. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: samplecode/SampleText.cpp
diff --git a/samplecode/SampleText.cpp b/samplecode/SampleText.cpp
index 17456b2ee988e6cbfca5d02d6caa1fba434db5a3..bde8494c6b151e36253d6fd9f4e81c557348618a 100644
--- a/samplecode/SampleText.cpp
+++ b/samplecode/SampleText.cpp
@@ -20,6 +20,7 @@
#include "SkUtils.h"
#include "SkColorPriv.h"
#include "SkColorFilter.h"
+#include "SkTextBlob.h"
#include "SkTime.h"
#include "SkTypeface.h"
#include "SkXfermode.h"
@@ -77,6 +78,13 @@ static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc
const SkPaint& paint, SkScalar clickX) {
SkPaint p(paint);
+ uint16_t glyphs[1000];
+ SkASSERT(length <= SK_ARRAY_COUNT(glyphs));
+ int glyphCount = paint.textToGlyphs(text, length, glyphs);
+ SkPaint glyphPaint = paint;
+ glyphPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+ SkTextBlobBuilder blobBuilder;
+
#if 0
canvas->drawText(text, length, x, y, paint);
#else
@@ -88,6 +96,11 @@ static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc
pts[i].set(xpos, y), xpos += paint.getTextSize();
}
canvas->drawPosText(text, length, pts, paint);
+
+ SkAutoTUnref<const SkTextBlob> blob(SkTextBlob::Create(
+ SkTextChunk::Create(glyphs, glyphCount, pts, glyphPaint)));
+ canvas->drawTextBlob(blob, SkPoint::Make(0, 400), glyphPaint);
+
}
#endif
@@ -95,6 +108,13 @@ static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc
x += SkIntToScalar(180);
canvas->drawText(text, length, x, y, p);
+ {
+ glyphPaint.setSubpixelText(true);
+ SkAutoTUnref<const SkTextBlob> blob(SkTextBlob::Create(
+ SkTextChunk::Create(glyphs, glyphCount, glyphPaint)));
+ canvas->drawTextBlob(blob, SkPoint::Make(x, y + 400), glyphPaint);
+ }
+
#ifdef SK_DEBUG
if (true) {
p.setSubpixelText(false);

Powered by Google App Engine
This is Rietveld 408576698