| 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
10 #include "impeller/entity/contents/content_context.h"
11 #include "impeller/entity/contents/contents.h"
12 #include "impeller/entity/contents/pipelines.h"
13 #include "impeller/geometry/color.h"
14 #include "impeller/typographer/font_glyph_pair.h"
15 #include "impeller/typographer/text_frame.h"
16
17 namespace impeller {
18
19 class LazyGlyphAtlas;
20 class Context;
21
22 class TextContents final : public Contents {
23 public:
24 TextContents();
25
26 ~TextContents();
27
28 void SetTextFrame(const std::shared_ptr<TextFrame>& frame);
29
30 void SetColor(Color color);
31
32 /// @brief Force the text color to apply to the rendered glyphs, even if those
33 /// glyphs are bitmaps.
34 ///
35 /// This is used to ensure that mask blurs work correctly on emoji.
36 void SetForceTextColor(bool value);
37
38 /// Must be set after text frame.
39 void SetTextProperties(Color color,
40 bool stroke,
41 Scalar stroke_width,
42 Cap stroke_cap,
43 Join stroke_join,
44 Scalar stroke_miter);
45
46 Color GetColor() const;
47
48 // |Contents|
49 void SetInheritedOpacity(Scalar opacity) override;
50
51 // The offset is only used for computing the subpixel glyph position.
52 void SetOffset(Vector2 offset);
53
54 std::optional<Rect> GetTextFrameBounds() const;
55
56 // |Contents|
57 std::optional<Rect> GetCoverage(const Entity& entity) const override;
58
59 void SetScale(Scalar scale) { scale_ = scale; }
60
61 // |Contents|
62 bool Render(const ContentContext& renderer,
63 const Entity& entity,
64 RenderPass& pass) const override;
65
66 static void ComputeVertexData(
67 GlyphAtlasPipeline::VertexShader::PerVertexData* vtx_contents,
68 const std::shared_ptr<TextFrame>& frame,
69 Scalar scale,
70 const Matrix& entity_transform,
71 Vector2 offset,
72 std::optional<GlyphProperties> glyph_properties,
73 const std::shared_ptr<GlyphAtlas>& atlas);
74
75 private:
76 std::optional<GlyphProperties> GetGlyphProperties() const;
77
78 std::shared_ptr<TextFrame> frame_;
79 Scalar scale_ = 1.0;
80 Scalar inherited_opacity_ = 1.0;
81 Vector2 offset_;
82 bool force_text_color_ = false;
83 Color color_;
84 GlyphProperties properties_;
85
86 TextContents(const TextContents&) = delete;
87
88 TextContents& operator=(const TextContents&) = delete;
89 };
90
91 } // namespace impeller
92
93 #endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_TEXT_CONTENTS_H_
impeller::ContentContext
Definition: content_context.h:138
impeller::Contents
Definition: contents.h:31
impeller::Entity
Definition: entity.h:20
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:30
impeller::TextContents
Definition: text_contents.h:22
impeller::TextContents::~TextContents
~TextContents()
impeller::TextContents::SetOffset
void SetOffset(Vector2 offset)
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:60
impeller::TextContents::SetInheritedOpacity
void SetInheritedOpacity(Scalar opacity) override
Inherit the provided opacity.
Definition: text_contents.cc:44
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:52
impeller::TextContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: text_contents.cc:229
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:56
impeller::TextContents::SetTextFrame
void SetTextFrame(const std::shared_ptr< TextFrame > &frame)
Definition: text_contents.cc:32
impeller::TextContents::SetScale
void SetScale(Scalar scale)
Definition: text_contents.h:59
impeller::TextContents::SetColor
void SetColor(Color color)
Definition: text_contents.cc:36
impeller::TextContents::TextContents
TextContents()
impeller::TextContents::GetTextFrameBounds
std::optional< Rect > GetTextFrameBounds() const
impeller::TextContents::ComputeVertexData
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)
Definition: text_contents.cc:96
impeller::TextContents::GetColor
Color GetColor() const
Definition: text_contents.cc:40
color.h
content_context.h
contents.h
value
int32_t value
Definition: dl_golden_unittests.cc:459
font_glyph_pair.h
impeller
Definition: allocation.cc:12
impeller::Join
Join
Definition: path.h:26
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Cap
Cap
Definition: path.h:20
pipelines.h
stroke_width
const Scalar stroke_width
Definition: stroke_path_geometry.cc:315
scale
const Scalar scale
Definition: stroke_path_geometry.cc:319
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:322
impeller::Color
Definition: color.h:124
impeller::GlyphProperties
Definition: font_glyph_pair.h:17
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TPoint< Scalar >
text_frame.h