blob: 94d10ea98d377215179d42aaf19a01e653f8114a [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=6b9e101f49e9c2c28755c5bdcef64dfb
Hal Canarya7181e7c2019-03-18 16:06:34 -04006REG_FIDDLE(Paint_getTextWidths, 256, 160, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04007void draw(SkCanvas* canvas) {
8 SkPaint paint;
9 paint.setAntiAlias(true);
10 paint.setTextSize(50);
11 const char str[] = "abc";
12 const int bytes = sizeof(str) - 1;
13 int count = paint.getTextWidths(str, bytes, nullptr);
14 std::vector<SkScalar> widths;
15 std::vector<SkRect> bounds;
16 widths.resize(count);
17 bounds.resize(count);
18 for (int loop = 0; loop < 2; ++loop) {
19 (void) paint.getTextWidths(str, count, &widths.front(), &bounds.front());
20 SkPoint loc = { 25, 50 };
21 canvas->drawText(str, bytes, loc.fX, loc.fY, paint);
22 paint.setStyle(SkPaint::kStroke_Style);
23 paint.setStrokeWidth(0);
24 SkScalar advanceY = loc.fY + 10;
25 for (int index = 0; index < count; ++index) {
26 bounds[index].offset(loc.fX, loc.fY);
27 canvas->drawRect(bounds[index], paint);
28 canvas->drawLine(loc.fX, advanceY, loc.fX + widths[index], advanceY, paint);
29 loc.fX += widths[index];
30 advanceY += 5;
31 }
32 canvas->translate(0, 80);
33 paint.setStrokeWidth(3);
34 }
35}
36} // END FIDDLE
37#endif // Disabled until updated to use current API.