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