11#include "gtest/gtest.h"
12#include "include/core/SkScalar.h"
25 "Apple Color Emoji.ttc";
55 lines_.emplace_back(p0, p1);
58 void drawDashedLine(
const DlPoint& p0,
62 dashed_lines_.emplace_back(p0, p1,
DlPoint(on_length, off_length));
65 void drawText(
const std::shared_ptr<DlText>&
text,
67 SkScalar
y)
override {
68 auto blob =
text->GetTextBlob();
70 blobs_.push_back(sk_ref_sp(blob));
72 auto frame =
text->GetTextFrame();
74 text_frames_.push_back(frame);
78 void drawRect(
const DlRect& rect)
override { rects_.push_back(rect); }
80 void drawPath(
const DlPath&
path)
override { paths_.push_back(
path); }
82 std::vector<std::shared_ptr<impeller::TextFrame>> text_frames_;
83 std::vector<sk_sp<SkTextBlob>> blobs_;
84 std::vector<std::pair<DlPoint, DlPoint>> lines_;
85 std::vector<std::tuple<DlPoint, DlPoint, DlPoint>> dashed_lines_;
86 std::vector<DlRect> rects_;
87 std::vector<DlPath> paths_;
100 t_style.color = SK_ColorBLACK;
102 t_style.font_size = 14;
104 t_style.decoration_style = style;
105 t_style.decoration_color = SK_ColorBLACK;
106 t_style.font_families.push_back(
"ahem");
112 t_style.color = SK_ColorBLACK;
114 t_style.font_size = 14;
121 t_style.color = SK_ColorBLACK;
123 t_style.font_size = 14;
124 t_style.font_families.push_back(
"ahem");
129 const std::u16string&
text)
const {
130 auto pb_skia = makeParagraphBuilder();
131 pb_skia.PushStyle(style);
132 pb_skia.AddText(
text);
136 auto paragraph = pb_skia.Build();
137 paragraph->Layout(10000);
138 paragraph->Paint(&builder, 0, 0);
140 return builder.Build();
144 auto pb_skia = makeParagraphBuilder();
145 pb_skia.PushStyle(style);
146 pb_skia.AddText(u
"Hello World!");
150 auto paragraph = pb_skia.Build();
151 paragraph->Layout(10000);
152 paragraph->Paint(&builder, 0, 0);
154 return builder.Build();
158 std::shared_ptr<txt::FontCollection> makeFontCollection()
const {
159 auto f_collection = std::make_shared<txt::FontCollection>();
160 auto font_provider = std::make_unique<txt::TypefaceFontAssetProvider>();
162 font_provider->RegisterTypeface(font);
170 font_provider->RegisterTypeface(typeface);
173 auto manager = sk_make_sp<txt::AssetFontManager>(std::move(font_provider));
174 f_collection->SetAssetFontManager(
manager);
180 auto f_collection = makeFontCollection();
184 bool impeller_ =
false;
190 PretendImpellerIsEnabled(
false);
194 ->Dispatch(recorder);
198 EXPECT_EQ(recorder.rectCount(), 1);
202 PretendImpellerIsEnabled(
false);
206 ->Dispatch(recorder);
209 EXPECT_EQ(recorder.lineCount(), 0);
210 EXPECT_EQ(recorder.dashedLineCount(), 1);
213#ifdef IMPELLER_SUPPORTS_RENDERING
215 PretendImpellerIsEnabled(
true);
217 auto recorder = DlOpRecorder();
219 ->Dispatch(recorder);
223 EXPECT_EQ(recorder.rectCount(), 1);
227 PretendImpellerIsEnabled(
true);
229 auto recorder = DlOpRecorder();
231 ->Dispatch(recorder);
234 EXPECT_EQ(recorder.pathCount(), 0);
235 EXPECT_EQ(recorder.dashedLineCount(), 1);
239 PretendImpellerIsEnabled(
true);
241 auto recorder = DlOpRecorder();
242 draw(makeStyle())->Dispatch(recorder);
244 EXPECT_EQ(recorder.textFrameCount(), 1);
245 EXPECT_EQ(recorder.blobCount(), 0);
249 PretendImpellerIsEnabled(
true);
251 auto style = makeStyle();
255 style.foreground = foreground;
257 auto recorder = DlOpRecorder();
258 draw(style)->Dispatch(recorder);
260 EXPECT_EQ(recorder.textFrameCount(), 1);
261 EXPECT_EQ(recorder.blobCount(), 0);
262 EXPECT_EQ(recorder.pathCount(), 0);
266 PretendImpellerIsEnabled(
true);
268 auto style = makeStyle();
272 style.foreground = foreground;
274 auto recorder = DlOpRecorder();
275 draw(style)->Dispatch(recorder);
277 EXPECT_EQ(recorder.textFrameCount(), 0);
278 EXPECT_EQ(recorder.blobCount(), 0);
279 EXPECT_EQ(recorder.pathCount(), 1);
283 PretendImpellerIsEnabled(
true);
285 auto style = makeStyle();
289 std::vector<float> stops = {0.0, 1.0};
293 style.foreground = foreground;
295 auto recorder = DlOpRecorder();
296 draw(style)->Dispatch(recorder);
298 EXPECT_EQ(recorder.textFrameCount(), 0);
299 EXPECT_EQ(recorder.blobCount(), 0);
300 EXPECT_EQ(recorder.pathCount(), 1);
304 PretendImpellerIsEnabled(
true);
306 auto style = makeEmoji();
310 std::vector<float> stops = {0.0, 1.0};
314 style.foreground = foreground;
316 auto recorder = DlOpRecorder();
317 drawText(style, u
"😀 😃 😄 😁 😆 😅 😂 🤣 🥲 😊")->Dispatch(recorder);
319 EXPECT_EQ(recorder.textFrameCount(), 1);
320 EXPECT_EQ(recorder.blobCount(), 0);
321 EXPECT_EQ(recorder.pathCount(), 0);
325 PretendImpellerIsEnabled(
false);
327 auto recorder = DlOpRecorder();
328 draw(makeStyle())->Dispatch(recorder);
330 EXPECT_EQ(recorder.textFrameCount(), 0);
331 EXPECT_EQ(recorder.blobCount(), 1);
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
Internal API for rendering recorded display lists to backends.
DlPaint & setStrokeWidth(float width)
DlPaint & setDrawStyle(DlDrawStyle style)
A custom |DlOpReceiver| that records some |DlOps| it receives.
int dashedLineCount() const
int textFrameCount() const
txt::TextStyle makeStyle()
txt::TextStyle makeEmoji()
PainterTestBase()=default
sk_sp< DisplayList > draw(const txt::TextStyle &style) const
txt::TextStyle makeDecoratedStyle(txt::TextDecorationStyle style)
void PretendImpellerIsEnabled(bool impeller)
sk_sp< DisplayList > drawText(const txt::TextStyle &style, const std::u16string &text) const
ParagraphBuilder implementation using Skia's text layout module.
#define FML_CHECK(condition)
static const std::string kEmojiFontName
TEST_F(DisplayListTest, Defaults)
sk_sp< SkData > OpenFixtureAsSkData(const std::string &fixture_name)
Opens a fixture of the given file name and returns a Skia SkData holding its contents.
PainterTestBase<::testing::Test > PainterTest
static const std::string kEmojiFontFile
impeller::Scalar DlScalar
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font manager
@ kStroke
strokes boundary of shapes
std::vector< sk_sp< SkTypeface > > GetTestFontData()
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
static constexpr DlColor kRed()
static constexpr DlColor kCyan()