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 
17 
18 namespace impeller {
19 
20 class LazyGlyphAtlas;
21 class Context;
22 
23 class TextContents final : public Contents {
24  public:
26 
28 
29  void SetTextFrame(const std::shared_ptr<TextFrame>& frame);
30 
31  void SetColor(Color color);
32 
33  /// @brief Force the text color to apply to the rendered glyphs, even if those
34  /// glyphs are bitmaps.
35  ///
36  /// This is used to ensure that mask blurs work correctly on emoji.
37  void SetForceTextColor(bool value);
38 
39  /// Must be set after text frame.
40  void SetTextProperties(Color color,
41  const std::optional<StrokeParameters>& stroke);
42 
43  Color GetColor() const;
44 
45  // |Contents|
46  void SetInheritedOpacity(Scalar opacity) override;
47 
48  // The offset is only used for computing the subpixel glyph position.
49  void SetOffset(Vector2 offset);
50 
51  std::optional<Rect> GetTextFrameBounds() const;
52 
53  // |Contents|
54  std::optional<Rect> GetCoverage(const Entity& entity) const override;
55 
56  void SetScale(Scalar scale) { scale_ = scale; }
57 
58  // |Contents|
59  bool Render(const ContentContext& renderer,
60  const Entity& entity,
61  RenderPass& pass) const override;
62 
63  static void ComputeVertexData(
64  GlyphAtlasPipeline::VertexShader::PerVertexData* vtx_contents,
65  const std::shared_ptr<TextFrame>& frame,
66  Scalar scale,
67  const Matrix& entity_transform,
68  Vector2 offset,
69  std::optional<GlyphProperties> glyph_properties,
70  const std::shared_ptr<GlyphAtlas>& atlas);
71 
72  private:
73  std::optional<GlyphProperties> GetGlyphProperties() const;
74 
75  std::shared_ptr<TextFrame> frame_;
76  Scalar scale_ = 1.0;
77  Scalar inherited_opacity_ = 1.0;
78  Vector2 offset_;
79  bool force_text_color_ = false;
80  Color color_;
81  GlyphProperties properties_;
82 
83  TextContents(const TextContents&) = delete;
84 
85  TextContents& operator=(const TextContents&) = delete;
86 };
87 
88 } // namespace impeller
89 
90 #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:30
void SetOffset(Vector2 offset)
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.
void SetTextProperties(Color color, const std::optional< StrokeParameters > &stroke)
Must be set after text frame.
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:56
void SetColor(Color color)
std::optional< Rect > GetTextFrameBounds() const
static void ComputeVertexData(GlyphAtlasPipeline::VertexShader::PerVertexData *vtx_contents, const std::shared_ptr< TextFrame > &frame, Scalar scale, const Matrix &entity_transform, Vector2 offset, std::optional< GlyphProperties > glyph_properties, const std::shared_ptr< GlyphAtlas > &atlas)
Color GetColor() const
int32_t value
float Scalar
Definition: scalar.h:19
A 4x4 matrix using column-major storage.
Definition: matrix.h:37