Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 1 | #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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 4 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 5 | // HASH=fb8b2502bbe52d2029aecdf569dd9fdb |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 6 | REG_FIDDLE(TextBlob_bounds, 256, 70, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 7 | void 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 Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 14 | paint.setTextEncoding(SkTextEncoding::kGlyphID); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 15 | SkFont font; |
| 16 | int runs[] = { 3, 1, 3 }; |
| 17 | SkPoint textPos = { 20, 50 }; |
| 18 | int glyphIndex = 0; |
| 19 | for (auto runLen : runs) { |
| 20 | font.setSize(1 == runLen ? 20 : 50); |
| 21 | paint.setTextSize(1 == runLen ? 20 : 50); |
| 22 | const SkTextBlobBuilder::RunBuffer& run = |
| 23 | textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY); |
| 24 | memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); |
| 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 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 30 | paint.setStyle(SkPaint::kStroke_Style); |
| 31 | canvas->drawRect(blob->bounds(), paint); |
| 32 | } |
| 33 | } // END FIDDLE |
| 34 | #endif // Disabled until updated to use current API. |