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 <functional>
9 #include <memory>
10 #include <variant>
11 #include <vector>
12 
13 #include "flutter/fml/macros.h"
18 
19 namespace impeller {
20 
21 class LazyGlyphAtlas;
22 class Context;
23 
24 class TextContents final : public Contents {
25  public:
26  TextContents();
27 
28  ~TextContents();
29 
30  void SetTextFrame(const std::shared_ptr<TextFrame>& frame);
31 
32  void SetColor(Color color);
33 
34  /// @brief Force the text color to apply to the rendered glyphs, even if those
35  /// glyphs are bitmaps.
36  ///
37  /// This is used to ensure that mask blurs work correctly on emoji.
38  void SetForceTextColor(bool value);
39 
40  Color GetColor() const;
41 
42  // |Contents|
43  bool CanInheritOpacity(const Entity& entity) const override;
44 
45  // |Contents|
46  void SetInheritedOpacity(Scalar opacity) override;
47 
48  void SetOffset(Vector2 offset);
49 
50  std::optional<Rect> GetTextFrameBounds() const;
51 
52  // |Contents|
53  std::optional<Rect> GetCoverage(const Entity& entity) const override;
54 
55  // |Contents|
56  void PopulateGlyphAtlas(
57  const std::shared_ptr<LazyGlyphAtlas>& lazy_glyph_atlas,
58  Scalar scale) override;
59 
60  // |Contents|
61  bool Render(const ContentContext& renderer,
62  const Entity& entity,
63  RenderPass& pass) const override;
64 
65  private:
66  std::shared_ptr<TextFrame> frame_;
67  Scalar scale_ = 1.0;
68  Color color_;
69  Scalar inherited_opacity_ = 1.0;
70  Vector2 offset_;
71  bool force_text_color_ = false;
72 
73  std::shared_ptr<GlyphAtlas> ResolveAtlas(
74  Context& context,
75  GlyphAtlas::Type type,
76  const std::shared_ptr<LazyGlyphAtlas>& lazy_atlas) const;
77 
78  TextContents(const TextContents&) = delete;
79 
80  TextContents& operator=(const TextContents&) = delete;
81 };
82 
83 } // namespace impeller
84 
85 #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:49
contents.h
impeller::TextContents
Definition: text_contents.h:24
impeller::Scalar
float Scalar
Definition: scalar.h:18
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:61
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:65
impeller::TextContents::SetColor
void SetColor(Color color)
Definition: text_contents.cc:41
impeller::Entity
Definition: entity.h:21
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:69
impeller::GlyphAtlas::Type
Type
Describes how the glyphs are represented in the texture.
Definition: glyph_atlas.h:33
impeller::TextContents::~TextContents
~TextContents()
impeller::TextContents::SetOffset
void SetOffset(Vector2 offset)
Definition: text_contents.cc:57
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:29
impeller::TextContents::TextContents
TextContents()
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition: context.h:47
impeller::TextContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: text_contents.cc:53
impeller::TPoint< Scalar >
impeller::TextContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: text_contents.cc:76
impeller::TextContents::GetColor
Color GetColor() const
Definition: text_contents.cc:45
color.h
impeller::TextContents::SetTextFrame
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
Definition: text_contents.cc:25
glyph_atlas.h
text_frame.h
impeller::Contents
Definition: contents.h:34
impeller
Definition: aiks_context.cc:10
impeller::ContentContext
Definition: content_context.h:332