Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / docs / examples / Paint_getTextWidths.cpp
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.
4 #include "tools/fiddle/examples.h"
5 // HASH=6b9e101f49e9c2c28755c5bdcef64dfb
6 REG_FIDDLE(Paint_getTextWidths, 256, 160, false, 0) {
7 void 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.