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  void SetInheritedOpacity(Scalar opacity) override;
48 
49  // The offset is only used for computing the subpixel glyph position.
50  void SetOffset(Vector2 offset);
51 
52  std::optional<Rect> GetTextFrameBounds() const;
53 
54  // |Contents|
55  std::optional<Rect> GetCoverage(const Entity& entity) const override;
56 
57  void SetScale(Scalar scale) { scale_ = scale; }
58 
59  // |Contents|
60  bool Render(const ContentContext& renderer,
61  const Entity& entity,
62  RenderPass& pass) const override;
63 
64  private:
65  std::shared_ptr<TextFrame> frame_;
66  Scalar scale_ = 1.0;
67  Scalar inherited_opacity_ = 1.0;
68  Vector2 offset_;
69  bool force_text_color_ = false;
70  Color color_;
71  GlyphProperties properties_;
72 
73  TextContents(const TextContents&) = delete;
74 
75  TextContents& operator=(const TextContents&) = delete;
76 };
77 
78 } // namespace impeller
79 
80 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_TEXT_CONTENTS_H_
contents.h
impeller::TextContents
Definition: text_contents.h:20
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::GlyphProperties
Definition: font_glyph_pair.h:20
impeller::TextContents::GetTextFrameBounds
std::optional< Rect > GetTextFrameBounds() const
impeller::Color
Definition: color.h:123
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:48
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:56
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:52
impeller::TextContents::SetColor
void SetColor(Color color)
Definition: text_contents.cc:32
stroke_width
const Scalar stroke_width
Definition: stroke_path_geometry.cc:297
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:304
impeller::Entity
Definition: entity.h:20
impeller::TextContents::SetScale
void SetScale(Scalar scale)
Definition: text_contents.h:57
font_glyph_pair.h
impeller::TextContents::~TextContents
~TextContents()
impeller::TextContents::SetOffset
void SetOffset(Vector2 offset)
Definition: text_contents.cc:44
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:40
impeller::TPoint< Scalar >
impeller::TextContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: text_contents.cc:76
scale
const Scalar scale
Definition: stroke_path_geometry.cc:301
impeller::TextContents::GetColor
Color GetColor() const
Definition: text_contents.cc:36
color.h
color
DlColor color
Definition: dl_golden_blur_unittests.cc:24
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: allocation.cc:12
stroke
bool stroke
Definition: dl_golden_blur_unittests.cc:22
impeller::ContentContext
Definition: content_context.h:366
impeller::Cap
Cap
Definition: path.h:18