Flutter Engine
The Flutter Engine
measure_text_bounds.cpp
Go to the documentation of this file.
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.
4REG_FIDDLE(measure_text_bounds, 256, 128, false, 0) {
5void draw(SkCanvas* canvas) {
6 canvas->clear(SK_ColorWHITE);
7
9 paint.setAntiAlias(true);
10 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 64, 1.25f, -0.25f);
11
12 float x = 32.0f;
13 float y = 88.0f;
14 const char text[] = "Skia";
15
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
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
std::u16string text
REG_FIDDLE(measure_text_bounds, 256, 128, false, 0)
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
font
Font Metadata and Metrics.