blob: 01bc97c27a3524879cd6ebfb8a5636c5ddf7cebf [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=6e12cceca981ddabc0fc18c380543f34
Hal Canarya7181e7c2019-03-18 16:06:34 -04006REG_FIDDLE(TextBlob_uniqueID, 256, 256, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04007void draw(SkCanvas* canvas) {
8 for (int index = 0; index < 2; ++index) {
9 SkTextBlobBuilder textBlobBuilder;
10 const char bunny[] = "/(^x^)\\";
11 const int len = sizeof(bunny) - 1;
12 uint16_t glyphs[len];
13 SkPaint paint;
14 paint.textToGlyphs(bunny, len, glyphs);
Ben Wagner51e15a62019-05-07 15:38:46 -040015 paint.setTextEncoding(SkTextEncoding::kGlyphID);
Hal Canary87515122019-03-15 14:22:51 -040016 paint.setTextScaleX(0.5);
17 SkFont font;
18 font.setScaleX(0.5);
19 int runs[] = { 3, 1, 3 };
20 SkPoint textPos = { 20, 50 };
21 int glyphIndex = 0;
22 for (auto runLen : runs) {
23 font.setSize(1 == runLen ? 20 : 50);
24 paint.setTextSize(1 == runLen ? 20 : 50);
25 const SkTextBlobBuilder::RunBuffer& run =
26 textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);
27 memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);
28 textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);
29 glyphIndex += runLen;
30 }
31 sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
32 paint.reset();
33 canvas->drawTextBlob(blob.get(), 0, 0, paint);
34 std::string id = "unique ID:" + std::to_string(blob->uniqueID());
35 canvas->drawString(id.c_str(), 30, blob->bounds().fBottom + 15, paint);
36 canvas->translate(blob->bounds().fRight + 10, 0);
37 }
38}
39} // END FIDDLE
40#endif // Disabled until updated to use current API.