| 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 Scalar GetScale() const;
95
96 TextFrame& operator=(TextFrame&& other) = default;
97
98 TextFrame(const TextFrame& other) = default;
99
100 const Matrix& GetTransform() const { return transform_; }
101
102 Point GetOffset() const;
103
104 Matrix GetOffsetTransform() const;
105
106 private:
107 friend class TypographerContextSkia;
108 friend class LazyGlyphAtlas;
109
110 std::optional<GlyphProperties> GetProperties() const;
111
112 void AppendFrameBounds(const FrameBounds& frame_bounds);
113
114 void ClearFrameBounds();
115
116 void SetAtlasGeneration(size_t value, intptr_t atlas_id);
117
118 std::vector<TextRun> runs_;
119 Rect bounds_;
120 bool has_color_;
121
122 // Data that is cached when rendering the text frame and is only
123 // valid for the current atlas generation.
124 std::vector<FrameBounds> bound_values_;
125 Scalar scale_ = 0;
126 size_t generation_ = 0;
127 intptr_t atlas_id_ = 0;
128 Point offset_;
129 std::optional<GlyphProperties> properties_;
130 Matrix transform_;
131 };
132
133 } // namespace impeller
134
135 #endif // FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_FRAME_H_
impeller::GlyphAtlas::Type
Type
Describes how the glyphs are represented in the texture.
Definition: glyph_atlas.h:74
impeller::LazyGlyphAtlas
Definition: lazy_glyph_atlas.h:15
impeller::TextFrame
Represents a collection of shaped text runs.
Definition: text_frame.h:22
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:91
impeller::TextFrame::GetBounds
Rect GetBounds() const
The conservative bounding box for this text frame.
Definition: text_frame.cc:19
impeller::TextFrame::TextFrame
TextFrame()
impeller::TextFrame::IsFrameComplete
bool IsFrameComplete() const
Verifies that all glyphs in this text frame have computed bounds information.
Definition: text_frame.cc:122
impeller::TextFrame::GetScale
Scalar GetScale() const
Definition: text_frame.cc:102
impeller::TextFrame::GetAtlasType
GlyphAtlas::Type GetAtlasType() const
The type of atlas this run should be place in.
Definition: text_frame.cc:31
impeller::TextFrame::HasColor
bool HasColor() const
Returns the paint color this text frame was recorded with.
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:130
impeller::TextFrame::GetTransform
const Matrix & GetTransform() const
Definition: text_frame.h:100
impeller::TextFrame::GetAtlasGenerationAndID
std::pair< size_t, intptr_t > GetAtlasGenerationAndID() const
Definition: text_frame.cc:135
impeller::TextFrame::ComputeSubpixelPosition
static Point ComputeSubpixelPosition(const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, const Matrix &transform)
Definition: text_frame.cc:69
impeller::TextFrame::TextFrame
TextFrame(const TextFrame &other)=default
impeller::TextFrame::GetRunCount
size_t GetRunCount() const
The number of runs in this text frame.
Definition: text_frame.cc:23
impeller::TextFrame::GetOffset
Point GetOffset() const
Definition: text_frame.cc:106
impeller::TextFrame::GetOffsetTransform
Matrix GetOffsetTransform() const
Definition: text_frame.cc:87
impeller::TextFrame::operator=
TextFrame & operator=(TextFrame &&other)=default
impeller::TextFrame::RoundScaledFontSize
static Scalar RoundScaledFontSize(Scalar scale)
Definition: text_frame.cc:41
impeller::TextFrame::GetRuns
const std::vector< TextRun > & GetRuns() const
Returns a reference to all the text runs in this frame.
Definition: text_frame.cc:27
impeller::TextFrame::~TextFrame
~TextFrame()
impeller::TypographerContextSkia
Definition: typographer_context_skia.h:12
value
int32_t value
Definition: dl_golden_unittests.cc:444
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
glyph_atlas.h
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::AxisAlignment
AxisAlignment
Determines the axis along which there is subpixel positioning.
Definition: font.h:20
scale
const Scalar scale
Definition: stroke_path_geometry.cc:316
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:319
impeller::FrameBounds
Definition: glyph_atlas.h:55
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TPoint< Scalar >
impeller::TRect< Scalar >
impeller::TextRun::GlyphPosition
Definition: text_run.h:22
text_run.h