Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
gm
bigtext.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2013 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
gm/gm.h
"
9
#include "
include/core/SkCanvas.h
"
10
#include "
include/core/SkColor.h
"
11
#include "
include/core/SkData.h
"
12
#include "
include/core/SkFont.h
"
13
#include "
include/core/SkFontTypes.h
"
14
#include "
include/core/SkPaint.h
"
15
#include "
include/core/SkPoint.h
"
16
#include "
include/core/SkRect.h
"
17
#include "
include/core/SkSize.h
"
18
#include "
include/core/SkString.h
"
19
#include "
include/core/SkTypeface.h
"
20
#include "
tools/Resources.h
"
21
#include "
tools/ToolUtils.h
"
22
#include "
tools/fonts/FontToolUtils.h
"
23
24
/**
25
* Skia may draw from outlines when the size is very large, so we exercise that
26
* here.
27
*/
28
29
class
BigTextGM
:
public
skiagm::GM
{
30
public
:
31
BigTextGM
() {}
32
33
protected
:
34
SkString
getName
()
const override
{
return
SkString
(
"bigtext"
); }
35
36
SkISize
getISize
()
override
{
return
SkISize::Make
(640, 480); }
37
38
void
onDraw
(
SkCanvas
* canvas)
override
{
39
SkPaint
paint
;
40
paint
.setAntiAlias(
true
);
41
SkFont
font(
ToolUtils::DefaultPortableTypeface
(), 1500);
42
43
SkRect
r;
44
(void)font.measureText(
"/"
, 1,
SkTextEncoding::kUTF8
, &r);
45
SkPoint
pos
= {
46
this->
width
()/2 - r.
centerX
(),
47
this->
height
()/2 - r.
centerY
()
48
};
49
50
paint
.setColor(
SK_ColorRED
);
51
canvas->
drawSimpleText
(
"/"
, 1,
SkTextEncoding::kUTF8
,
pos
.
fX
,
pos
.
fY
, font,
paint
);
52
53
paint
.setColor(
SK_ColorBLUE
);
54
canvas->
drawSimpleText
(
"\\"
, 1,
SkTextEncoding::kUTF8
,
pos
.
fX
,
pos
.
fY
, font,
paint
);
55
}
56
57
private
:
58
using
INHERITED =
skiagm::GM
;
59
};
60
61
DEF_GM
(
return
new
BigTextGM
;)
62
63
// Exercise the case where the glyph is sufficiently large that we should just draw with a path,
64
// but the DirectWrite scaler context failed to calculate the bounds and reported empty bounds.
65
// With empty bounds the glyph was discarded instead of rendered from path. See crbug.com/1370488
66
DEF_SIMPLE_GM
(bigtext_crbug_1370488, canvas, 512, 512) {
67
auto
typeface =
ToolUtils::CreateTypefaceFromResource
(
"fonts/SpiderSymbol.ttf"
);
68
const
char
*
text
=
"\xEF\x80\xA1"
;
69
if
(!typeface) {
70
typeface =
ToolUtils::DefaultPortableTypeface
();
71
text
=
"H"
;
72
}
73
74
SkFont
font(typeface, 12.f);
75
canvas->translate(-1800.f, 1800.f);
76
canvas->scale(437.5f, 437.5f);
77
SkPaint
paint
;
78
paint
.setAntiAlias(
true
);
79
canvas->drawString(
text
, 0.f, 0.f, font,
paint
);
80
}
FontToolUtils.h
pos
SkPoint pos
Definition
ImageShaderTest.cpp:27
Resources.h
SkCanvas.h
SkColor.h
SK_ColorBLUE
constexpr SkColor SK_ColorBLUE
Definition
SkColor.h:135
SK_ColorRED
constexpr SkColor SK_ColorRED
Definition
SkColor.h:126
SkData.h
SkFontTypes.h
SkTextEncoding::kUTF8
@ kUTF8
uses bytes to represent UTF-8 or ASCII
SkFont.h
SkPaint.h
SkPoint.h
SkRect.h
SkSize.h
SkString.h
SkTypeface.h
ToolUtils.h
BigTextGM
Definition
bigtext.cpp:29
BigTextGM::BigTextGM
BigTextGM()
Definition
bigtext.cpp:31
BigTextGM::onDraw
void onDraw(SkCanvas *canvas) override
Definition
bigtext.cpp:38
BigTextGM::getName
SkString getName() const override
Definition
bigtext.cpp:34
BigTextGM::getISize
SkISize getISize() override
Definition
bigtext.cpp:36
SkCanvas
Definition
SkCanvas.h:106
SkCanvas::drawSimpleText
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition
SkCanvas.cpp:2840
SkFont
Definition
SkFont.h:35
SkPaint
Definition
SkPaint.h:44
SkString
Definition
SkString.h:118
skiagm::GM
Definition
gm.h:110
skiagm::GM::width
SkScalar width()
Definition
gm.h:159
skiagm::GM::height
SkScalar height()
Definition
gm.h:162
paint
const Paint & paint
Definition
color_source.cc:38
gm.h
DEF_GM
#define DEF_GM(CODE)
Definition
gm.h:40
DEF_SIMPLE_GM
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition
gm.h:50
text
std::u16string text
Definition
keyboard_unittests.cc:332
ToolUtils::DefaultPortableTypeface
sk_sp< SkTypeface > DefaultPortableTypeface()
Definition
FontToolUtils.cpp:195
ToolUtils::CreateTypefaceFromResource
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)
Definition
FontToolUtils.cpp:317
SkISize
Definition
SkSize.h:16
SkISize::Make
static constexpr SkISize Make(int32_t w, int32_t h)
Definition
SkSize.h:20
SkPoint
Definition
SkPoint_impl.h:163
SkPoint::fX
float fX
x-axis value
Definition
SkPoint_impl.h:164
SkPoint::fY
float fY
y-axis value
Definition
SkPoint_impl.h:165
SkRect
Definition
extension.cpp:13
SkRect::centerX
constexpr float centerX() const
Definition
SkRect.h:776
SkRect::centerY
constexpr float centerY() const
Definition
SkRect.h:785
Generated on Fri Apr 26 2024 06:16:00 for Flutter Engine by
1.9.8