Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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
14absl::StatusOr<DlRect> RenderTextInCanvasSkia(
15 DlCanvas* canvas,
16 const std::string& text,
17 const std::string_view& font_fixture,
18 DlPoint position,
19 const TextRenderOptions& options) {
20 auto c_font_fixture = std::string(font_fixture);
21 auto mapping = flutter::testing::OpenFixtureAsSkData(c_font_fixture.c_str());
22 if (!mapping) {
23 return absl::NotFoundError("Font fixture not found");
24 }
25 sk_sp<SkFontMgr> font_mgr = txt::GetDefaultFontManager();
26 SkFont sk_font(font_mgr->makeFromData(mapping), options.font_size);
27 if (options.is_subpixel) {
28 sk_font.setSubpixel(true);
29 }
30 auto blob = SkTextBlob::MakeFromString(text.c_str(), sk_font);
31 if (!blob) {
32 return absl::InvalidArgumentError("String could not be converted to Blob");
33 }
34
36
37 DlPaint text_paint;
38 text_paint.setColor(options.color);
39 text_paint.setMaskFilter(options.mask_filter);
40 // text_paint.mask_blur_descriptor = options.mask_blur_descriptor;
41 // text_paint.stroke_width = 1;
42 // text_paint.style =
43 // options.stroke ? Paint::Style::kStroke : Paint::Style::kFill;
44 canvas->DrawText(DlTextImpeller::Make(frame), position.x, position.y,
45 text_paint);
46 return frame->GetBounds().Shift(position);
47}
48} // namespace testing
49} // 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
absl::StatusOr< DlRect > 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