| Flutter Impeller |

text_frame.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_TYPOGRAPHER_TEXT_FRAME_H_
6 #define FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_FRAME_H_
7
8 #include <cstdint>
9 #include "impeller/typographer/glyph_atlas.h"
10 #include "impeller/typographer/text_run.h"
11
12 namespace impeller {
13
14 //------------------------------------------------------------------------------
15 /// @brief Represents a collection of shaped text runs.
16 ///
17 /// This object is typically the entrypoint in the Impeller type
18 /// rendering subsystem.
19 ///
20 /// A text frame should not be reused in multiple places within a single frame,
21 /// as internally it is used as a cache for various glyph properties.
22 class TextFrame {
23 public:
24 TextFrame();
25
26 TextFrame(std::vector<TextRun>& runs, Rect bounds, bool has_color);
27
28 ~TextFrame();
29
30 static Point ComputeSubpixelPosition(
31 const TextRun::GlyphPosition& glyph_position,
32 AxisAlignment alignment,
33 const Matrix& transform);
34
35 static Scalar RoundScaledFontSize(Scalar scale);
36
37 //----------------------------------------------------------------------------
38 /// @brief The conservative bounding box for this text frame.
39 ///
40 /// @return The bounds rectangle. If there are no glyphs in this text
41 /// frame and empty Rectangle is returned instead.
42 ///
43 Rect GetBounds() const;
44
45 //----------------------------------------------------------------------------
46 /// @brief The number of runs in this text frame.
47 ///
48 /// @return The run count.
49 ///
50 size_t GetRunCount() const;
51
52 //----------------------------------------------------------------------------
53 /// @brief Returns a reference to all the text runs in this frame.
54 ///
55 /// @return The runs in this frame.
56 ///
57 const std::vector<TextRun>& GetRuns() const;
58
59 //----------------------------------------------------------------------------
60 /// @brief Returns the paint color this text frame was recorded with.
61 ///
62 /// Non-bitmap/COLR fonts always use a black text color here, but
63 /// COLR fonts can potentially use the paint color in the glyph
64 /// atlas, so this color must be considered as part of the cache
65 /// key.
66 bool HasColor() const;
67
68 //----------------------------------------------------------------------------
69 /// @brief The type of atlas this run should be place in.
70 GlyphAtlas::Type GetAtlasType() const;
71
72 /// @brief Verifies that all glyphs in this text frame have computed bounds
73 /// information.
74 bool IsFrameComplete() const;
75
76 /// @brief Retrieve the frame bounds for the glyph at [index].
77 ///
78 /// This method is only valid if [IsFrameComplete] returns true.
79 const FrameBounds& GetFrameBounds(size_t index) const;
80
81 /// @brief Store text frame scale, offset, and properties for hashing in th
82 /// glyph atlas.
83 void SetPerFrameData(Scalar scale,
84 Point offset,
85 const Matrix& transform,
86 std::optional<GlyphProperties> properties);
87
88 // A generation id for the glyph atlas this text run was associated
89 // with. As long as the frame generation matches the atlas generation,
90 // the contents are guaranteed to be populated and do not need to be
91 // processed.
92 std::pair<size_t, intptr_t> GetAtlasGenerationAndID() const;
93
94 TextFrame& operator=(TextFrame&& other) = default;
95
96 TextFrame(const TextFrame& other) = default;
97
98 const Matrix& GetTransform() const { return transform_; }
99
100 private:
101 friend class TypographerContextSkia;
102 friend class LazyGlyphAtlas;
103
104 Scalar GetScale() const;
105
106 Point GetOffset() const;
107
108 std::optional<GlyphProperties> GetProperties() const;
109
110 void AppendFrameBounds(const FrameBounds& frame_bounds);
111
112 void ClearFrameBounds();
113
114 void SetAtlasGeneration(size_t value, intptr_t atlas_id);
115
116 std::vector<TextRun> runs_;
117 Rect bounds_;
118 bool has_color_;
119
120 // Data that is cached when rendering the text frame and is only
121 // valid for the current atlas generation.
122 std::vector<FrameBounds> bound_values_;
123 Scalar scale_ = 0;
124 size_t generation_ = 0;
125 intptr_t atlas_id_ = 0;
126 Point offset_;
127 std::optional<GlyphProperties> properties_;
128 Matrix transform_;
129 };
130
131 } // namespace impeller
132
133 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_FRAME_H_
impeller::TextFrame::operator=
TextFrame & operator=(TextFrame &&other)=default
impeller::TextFrame::HasColor
bool HasColor() const
Returns the paint color this text frame was recorded with.
Definition: text_frame.cc:49
impeller::TextFrame::GetAtlasGenerationAndID
std::pair< size_t, intptr_t > GetAtlasGenerationAndID() const
Definition: text_frame.cc:149
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::TextFrame::TextFrame
TextFrame()
impeller::TextFrame
Represents a collection of shaped text runs.
Definition: text_frame.h:22
value
int32_t value
Definition: dl_golden_unittests.cc:444
impeller::TextFrame::~TextFrame
~TextFrame()
impeller::TextFrame::SetPerFrameData
void SetPerFrameData(Scalar scale, Point offset, const Matrix &transform, std::optional< GlyphProperties > properties)
Store text frame scale, offset, and properties for hashing in th glyph atlas.
Definition: text_frame.cc:100
impeller::TextFrame::GetRuns
const std::vector< TextRun > & GetRuns() const
Returns a reference to all the text runs in this frame.
Definition: text_frame.cc:40
impeller::TextFrame::GetRunCount
size_t GetRunCount() const
The number of runs in this text frame.
Definition: text_frame.cc:36
impeller::TextFrame::GetFrameBounds
const FrameBounds & GetFrameBounds(size_t index) const
Retrieve the frame bounds for the glyph at [index].
Definition: text_frame.cc:144
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:319
impeller::TextFrame::RoundScaledFontSize
static Scalar RoundScaledFontSize(Scalar scale)
Definition: text_frame.cc:54
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
impeller::GlyphAtlas::Type
Type
Describes how the glyphs are represented in the texture.
Definition: glyph_atlas.h:74
impeller::AxisAlignment
AxisAlignment
Determines the axis along which there is subpixel positioning.
Definition: font.h:20
impeller::TypographerContextSkia
Definition: typographer_context_skia.h:12
impeller::TextFrame::GetBounds
Rect GetBounds() const
The conservative bounding box for this text frame.
Definition: text_frame.cc:32
text_run.h
impeller::TextFrame::GetAtlasType
GlyphAtlas::Type GetAtlasType() const
The type of atlas this run should be place in.
Definition: text_frame.cc:44
impeller::TPoint< Scalar >
impeller::TextRun::GlyphPosition
Definition: text_run.h:22
scale
const Scalar scale
Definition: stroke_path_geometry.cc:316
impeller::FrameBounds
Definition: glyph_atlas.h:55
impeller::TextFrame::IsFrameComplete
bool IsFrameComplete() const
Verifies that all glyphs in this text frame have computed bounds information.
Definition: text_frame.cc:136
glyph_atlas.h
impeller::TextFrame::GetTransform
const Matrix & GetTransform() const
Definition: text_frame.h:98
impeller::TextFrame::ComputeSubpixelPosition
static Point ComputeSubpixelPosition(const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, const Matrix &transform)
Definition: text_frame.cc:82
impeller::LazyGlyphAtlas
Definition: lazy_glyph_atlas.h:15
impeller
Definition: allocation.cc:12
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37