| 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/geometry/stroke_parameters.h"
15 #include "impeller/typographer/font_glyph_pair.h"
16 #include "impeller/typographer/text_frame.h"
17
18 namespace impeller {
19
20 class LazyGlyphAtlas;
21 class Context;
22
23 class TextContents final : public Contents {
24 public:
25 TextContents();
26
27 ~TextContents();
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_
impeller::ContentContext
Definition: content_context.h:122
impeller::Contents
Definition: contents.h:31
impeller::Entity
Definition: entity.h:26
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:23
impeller::TextContents::~TextContents
~TextContents()
impeller::TextContents::SetOffset
void SetOffset(Vector2 offset)
Definition: text_contents.cc:48
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::SetTextProperties
void SetTextProperties(Color color, const std::optional< StrokeParameters > &stroke)
Must be set after text frame.
Definition: text_contents.cc:60
impeller::TextContents::Render
bool Render(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Definition: text_contents.cc:220
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:56
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:87
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::Scalar
float Scalar
Definition: scalar.h:19
pipelines.h
stroke_parameters.h
impeller::Color
Definition: color.h:124
impeller::GlyphProperties
Definition: font_glyph_pair.h:19
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TPoint< Scalar >
text_frame.h