Flutter Engine
The Flutter Engine
text_contents.h
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
5#ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_TEXT_CONTENTS_H_
6#define FLUTTER_IMPELLER_ENTITY_CONTENTS_TEXT_CONTENTS_H_
7
8#include <memory>
9
14
15namespace impeller {
16
17class LazyGlyphAtlas;
18class Context;
19
20class TextContents final : public Contents {
21 public:
23
25
26 void SetTextFrame(const std::shared_ptr<TextFrame>& frame);
27
28 void SetColor(Color color);
29
30 /// @brief Force the text color to apply to the rendered glyphs, even if those
31 /// glyphs are bitmaps.
32 ///
33 /// This is used to ensure that mask blurs work correctly on emoji.
34 void SetForceTextColor(bool value);
35
36 /// Must be set after text frame.
38 bool stroke,
40 Cap stroke_cap,
41 Join stroke_join,
42 Scalar stroke_miter);
43
44 Color GetColor() const;
45
46 // |Contents|
47 bool CanInheritOpacity(const Entity& entity) const override;
48
49 // |Contents|
50 void SetInheritedOpacity(Scalar opacity) override;
51
52 // The offset is only used for computing the subpixel glyph position.
54
55 std::optional<Rect> GetTextFrameBounds() const;
56
57 // |Contents|
58 std::optional<Rect> GetCoverage(const Entity& entity) const override;
59
60 // |Contents|
62 const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
63 Scalar scale) override;
64
65 void SetScale(Scalar scale) { scale_ = scale; }
66
67 // |Contents|
68 bool Render(const ContentContext& renderer,
69 const Entity& entity,
70 RenderPass& pass) const override;
71
72 private:
73 std::shared_ptr<TextFrame> frame_;
74 Scalar scale_ = 1.0;
75 Scalar inherited_opacity_ = 1.0;
76 Vector2 offset_;
77 bool force_text_color_ = false;
78 Color color_;
79 GlyphProperties properties_;
80
81 TextContents(const TextContents&) = delete;
82
83 TextContents& operator=(const TextContents&) = delete;
84};
85
86} // namespace impeller
87
88#endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_TEXT_CONTENTS_H_
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
void PopulateGlyphAtlas(const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale) override
Add any text data to the specified lazy atlas. The scale parameter must be used again later when draw...
void SetOffset(Vector2 offset)
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
void SetTextProperties(Color color, bool stroke, Scalar stroke_width, Cap stroke_cap, Join stroke_join, Scalar stroke_miter)
Must be set after text frame.
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
void SetForceTextColor(bool value)
Force the text color to apply to the rendered glyphs, even if those glyphs are bitmaps.
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
std::optional< Rect > GetCoverage(const Entity &entity) const override
Get the area of the render pass that will be affected when this contents is rendered.
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
void SetScale(Scalar scale)
Definition: text_contents.h:65
void SetColor(Color color)
Color GetColor() const
std::optional< Rect > GetTextFrameBounds() const
DlColor color
double frame
Definition: examples.cpp:31
uint8_t value
Join
Definition: path.h:24
float Scalar
Definition: scalar.h:18
Cap
Definition: path.h:18
const Scalar stroke_width
const Scalar scale
SeparatedVector2 offset