blob: 49b00d2c9356c6c4e55f7ad3f73f16bed6b18b98 [file] [log] [blame]
Hal Canary6c8422c2020-01-10 15:22:09 -05001// 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"
4REG_FIDDLE(measure_text_bounds, 256, 128, false, 0) {
5void 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