skia2/docs/examples/measure_text_bounds.cpp
Hal Canary 6c8422c671 add more docs/examples from named fiddles.
ignore offscreen, srgb, and animated fiddles for now.

Change-Id: I923131b684865698e6cda138b004930e11f504d5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/263713
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2020-01-14 19:22:26 +00:00

25 lines
713 B
C++

// Copyright 2020 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "tools/fiddle/examples.h"
REG_FIDDLE(measure_text_bounds, 256, 128, false, 0) {
void draw(SkCanvas* canvas) {
canvas->clear(SK_ColorWHITE);
SkPaint paint;
paint.setAntiAlias(true);
SkFont font(nullptr, 64, 1.25f, -0.25f);
float x = 32.0f;
float y = 88.0f;
const char text[] = "Skia";
SkRect bounds;
(void)font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
canvas->drawRect(bounds.makeOffset(x, y), paint);
paint.setColor(SK_ColorWHITE);
canvas->drawString(text, x, y, font, paint);
}
} // END FIDDLE