Flutter Impeller
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 
15 namespace impeller {
16 
17 class LazyGlyphAtlas;
18 class Context;
19 
20 class TextContents final : public Contents {
21  public:
22  TextContents();
23 
24  ~TextContents();
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.
53  void SetOffset(Vector2 offset);
54 
55  std::optional<Rect> GetTextFrameBounds() const;
56 
57  // |Contents|
58  std::optional<Rect> GetCoverage(const Entity& entity) const override;
59 
60  // |Contents|
61  void PopulateGlyphAtlas(
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_
impeller::TextContents::CanInheritOpacity
bool CanInheritOpacity(const Entity &entity) const override
Whether or not this contents can accept the opacity peephole optimization.
Definition: text_contents.cc:40
contents.h
impeller::TextContents
Definition: text_contents.h:20
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::GlyphProperties
Definition: font_glyph_pair.h:19
impeller::TextContents::GetTextFrameBounds
std::optional< Rect > GetTextFrameBounds() const
impeller::Color
Definition: color.h:124
impeller::TextContents::SetForceTextColor
void SetForceTextColor(bool value)
Force the text color to apply to the rendered glyphs, even if those glyphs are bitmaps.
Definition: text_contents.cc:58
impeller::TextContents::SetTextProperties
void SetTextProperties(Color color, bool stroke, Scalar stroke_width, Cap stroke_cap, Join stroke_join, Scalar stroke_miter)
Must be set after text frame.
Definition: text_contents.cc:73
impeller::TextContents::GetCoverage
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.
Definition: text_contents.cc:62
impeller::TextContents::SetColor
void SetColor(Color color)
Definition: text_contents.cc:32
stroke_width
const Scalar stroke_width
Definition: stroke_path_geometry.cc:304
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:311
impeller::Entity
Definition: entity.h:20
impeller::TextContents::SetScale
void SetScale(Scalar scale)
Definition: text_contents.h:65
impeller::TextContents::PopulateGlyphAtlas
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...
Definition: text_contents.cc:66
font_glyph_pair.h
impeller::TextContents::~TextContents
~TextContents()
impeller::TextContents::SetOffset
void SetOffset(Vector2 offset)
Definition: text_contents.cc:54
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
impeller::Join
Join
Definition: path.h:24
impeller::TextContents::TextContents
TextContents()
impeller::TextContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: text_contents.cc:50
impeller::TPoint< Scalar >
impeller::TextContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: text_contents.cc:93
scale
const Scalar scale
Definition: stroke_path_geometry.cc:308
impeller::TextContents::GetColor
Color GetColor() const
Definition: text_contents.cc:36
color.h
color
DlColor color
Definition: dl_golden_blur_unittests.cc:23
impeller::TextContents::SetTextFrame
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
Definition: text_contents.cc:28
text_frame.h
impeller::Contents
Definition: contents.h:31
impeller
Definition: aiks_blend_unittests.cc:18
stroke
bool stroke
Definition: dl_golden_blur_unittests.cc:21
impeller::ContentContext
Definition: content_context.h:366
impeller::Cap
Cap
Definition: path.h:18