Hal Canary | 6c8422c | 2020-01-10 15:22:09 -0500 | [diff] [blame] | 1 | // Copyright 2020 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 3 | #include "tools/fiddle/examples.h" |
| 4 | REG_FIDDLE(measure_text_bounds, 256, 128, false, 0) { |
| 5 | void draw(SkCanvas* canvas) { |
| 6 | canvas->clear(SK_ColorWHITE); |
| 7 | |
| 8 | SkPaint paint; |
| 9 | paint.setAntiAlias(true); |
| 10 | SkFont font(nullptr, 64, 1.25f, -0.25f); |
| 11 | |
| 12 | float x = 32.0f; |
| 13 | float y = 88.0f; |
| 14 | const char text[] = "Skia"; |
| 15 | |
| 16 | SkRect bounds; |
| 17 | (void)font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); |
| 18 | |
| 19 | canvas->drawRect(bounds.makeOffset(x, y), paint); |
| 20 | |
| 21 | paint.setColor(SK_ColorWHITE); |
| 22 | canvas->drawString(text, x, y, font, paint); |
| 23 | } |
| 24 | } // END FIDDLE |