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

Unified Diff: samplecode/SampleText.cpp

Issue 473633002: SkTextBlob (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Alloc API + review comments 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..c028b32bfbbea3d427829803efe3747f83743669 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"
@@ -76,16 +77,18 @@ static const struct {
static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkScalar x, SkScalar y,
const SkPaint& paint, SkScalar clickX) {
SkPaint p(paint);
+ SkPoint pts[1000];
+ SkScalar xPos[1000];
+ SkASSERT(length <= SK_ARRAY_COUNT(pts));
#if 0
canvas->drawText(text, length, x, y, paint);
#else
{
- SkPoint pts[1000];
SkScalar xpos = x;
- SkASSERT(length <= SK_ARRAY_COUNT(pts));
for (size_t i = 0; i < length; i++) {
pts[i].set(xpos, y), xpos += paint.getTextSize();
+ xPos[i] = pts[i].x();
}
canvas->drawPosText(text, length, pts, paint);
}
@@ -103,6 +106,35 @@ static void DrawTheText(SkCanvas* canvas, const char text[], size_t length, SkSc
canvas->drawText(text, length, x, y, p);
}
#endif
+
+
+ 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;
+ SkTextBlobBuilder::RunBuffer posRun = blobBuilder.allocRun(glyphPaint, glyphCount);
+ memcpy(posRun.glyphs, glyphs, glyphCount * sizeof(uint16_t));
+ memcpy(posRun.pos, pts, glyphCount * sizeof(SkScalar) * 2);
+ SkAutoTUnref<const SkTextBlob> posBlob(blobBuilder.build());
+ canvas->drawTextBlob(posBlob, 0, 400, glyphPaint);
+
+ glyphPaint.setSubpixelText(true);
+ uint16_t* defaultRun = blobBuilder.allocRun(glyphPaint, glyphCount,
+ SkPoint::Make(0, 0));
+ memcpy(defaultRun, glyphs, glyphCount * sizeof(uint16_t));
+ SkAutoTUnref<const SkTextBlob> blob(blobBuilder.build());
+ canvas->drawTextBlob(blob, 180, 400 + y, glyphPaint);
+
+ glyphPaint.setSubpixelText(false);
+ glyphPaint.setLinearText(true);
+ SkTextBlobBuilder::RunBuffer hPosRun = blobBuilder.allocRun(glyphPaint, glyphCount, 0, NULL);
+ memcpy(hPosRun.glyphs, glyphs, glyphCount * sizeof(uint16_t));
+ memcpy(hPosRun.pos, xPos, glyphCount * sizeof(SkScalar));
+ SkAutoTUnref<const SkTextBlob> hPosBlob(blobBuilder.build());
+ canvas->drawTextBlob(hPosBlob, 360, 400 + y, glyphPaint);
}
class TextSpeedView : public SampleView {

Powered by Google App Engine
This is Rietveld 408576698