blob: 9fcab6a1361981ef6f3e366e47d58d8117c3de94 [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001#if 0 // Disabled until updated to use current API.
2// Copyright 2019 Google LLC.
3// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05004#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04005// HASH=005502b502c1282cb8d306d6c8d998fb
Hal Canarya7181e7c2019-03-18 16:06:34 -04006REG_FIDDLE(Canvas_drawTextBlob, 256, 120, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04007void draw(SkCanvas* canvas) {
8 SkTextBlobBuilder textBlobBuilder;
9 const char bunny[] = "/(^x^)\\";
10 const int len = sizeof(bunny) - 1;
11 uint16_t glyphs[len];
12 SkPaint paint;
13 paint.textToGlyphs(bunny, len, glyphs);
Ben Wagner51e15a62019-05-07 15:38:46 -040014 paint.setTextEncoding(SkTextEncoding::kGlyphID);
Hal Canary87515122019-03-15 14:22:51 -040015 SkFont font;
16 int runs[] = { 3, 1, 3 };
17 SkPoint textPos = { 20, 100 };
18 int glyphIndex = 0;
19 for (auto runLen : runs) {
20 font.setSize(1 == runLen ? 20 : 50);
21 const SkTextBlobBuilder::RunBuffer& run =
22 textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);
23 memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);
24 paint.setTextSize(1 == runLen ? 20 : 50);
25 textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);
26 glyphIndex += runLen;
27 }
28 sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
29 paint.reset();
30 canvas->drawTextBlob(blob.get(), 0, 0, paint);
31}
32} // END FIDDLE
33#endif // Disabled until updated to use current API.