Flutter Engine
The Flutter Engine
third_party
skia
docs
examples
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.
3
#include "
tools/fiddle/examples.h
"
4
REG_FIDDLE
(measure_text_bounds, 256, 128,
false
, 0) {
5
void
draw
(
SkCanvas
* canvas) {
6
canvas->
clear
(
SK_ColorWHITE
);
7
8
SkPaint
paint
;
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
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
SK_ColorWHITE
constexpr SkColor SK_ColorWHITE
Definition:
SkColor.h:122
SkTextEncoding::kUTF8
@ kUTF8
uses bytes to represent UTF-8 or ASCII
draw
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition:
aaclip.cpp:27
SkCanvas
Definition:
SkCanvas.h:106
SkCanvas::drawRect
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition:
SkCanvas.cpp:1673
SkCanvas::clear
void clear(SkColor color)
Definition:
SkCanvas.h:1199
SkCanvas::drawString
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition:
SkCanvas.h:1803
SkFontMgr::matchFamilyStyle
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition:
SkFontMgr.cpp:109
SkFont
Definition:
SkFont.h:35
SkPaint
Definition:
SkPaint.h:44
paint
const Paint & paint
Definition:
color_source.cc:38
fontMgr
sk_sp< SkFontMgr > fontMgr
Definition:
examples.cpp:32
examples.h
text
std::u16string text
Definition:
keyboard_unittests.cc:332
REG_FIDDLE
REG_FIDDLE(measure_text_bounds, 256, 128, false, 0)
Definition:
measure_text_bounds.cpp:4
y
double y
Definition:
mouse-input-test.cc:83
x
double x
Definition:
mouse-input-test.cc:82
SkRecords::bounds
Optional< SkRect > bounds
Definition:
SkRecords.h:189
gen_test_font.font
font
Font Metadata and Metrics.
Definition:
gen_test_font.py:26
SkRect
Definition:
extension.cpp:13
Generated on Sun Jun 23 2024 21:55:55 for Flutter Engine by
1.9.4