Flutter Engine
 
Loading...
Searching...
No Matches
render_text_in_canvas.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
9#include "txt/platform.h"
10
11namespace flutter {
12namespace testing {
13
15 const std::string& text,
16 const std::string_view& font_fixture,
17 DlPoint position,
18 const TextRenderOptions& options) {
19 auto c_font_fixture = std::string(font_fixture);
20 auto mapping = flutter::testing::OpenFixtureAsSkData(c_font_fixture.c_str());
21 if (!mapping) {
22 return false;
23 }
24 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
25 SkFont sk_font(font_mgr->makeFromData(mapping), options.font_size);
26 if (options.is_subpixel) {
27 sk_font.setSubpixel(true);
28 }
29 auto blob = SkTextBlob::MakeFromString(text.c_str(), sk_font);
30 if (!blob) {
31 return false;
32 }
33
35
36 DlPaint text_paint;
37 text_paint.setColor(options.color);
38 text_paint.setMaskFilter(options.mask_filter);
39 // text_paint.mask_blur_descriptor = options.mask_blur_descriptor;
40 // text_paint.stroke_width = 1;
41 // text_paint.style =
42 // options.stroke ? Paint::Style::kStroke : Paint::Style::kFill;
43 canvas->DrawText(DlTextImpeller::Make(frame), position.x, position.y,
44 text_paint);
45 return true;
46}
47} // namespace testing
48} // namespace flutter
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
virtual void DrawText(const std::shared_ptr< DlText > &text, DlScalar x, DlScalar y, const DlPaint &paint)=0
DlPaint & setColor(DlColor color)
Definition dl_paint.h:70
DlPaint & setMaskFilter(std::nullptr_t filter)
Definition dl_paint.h:185
static std::shared_ptr< DlTextImpeller > Make(const std::shared_ptr< impeller::TextFrame > &frame)
std::u16string text
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.
Definition testing.cc:63
bool RenderTextInCanvasSkia(DlCanvas *canvas, const std::string &text, const std::string_view &font_fixture, DlPoint position, const TextRenderOptions &options)
std::shared_ptr< TextFrame > MakeTextFrameFromTextBlobSkia(const sk_sp< SkTextBlob > &blob)
sk_sp< SkFontMgr > GetDefaultFontManager(uint32_t font_initialization_data)
Definition platform.cc:17
std::shared_ptr< DlMaskFilter > mask_filter