Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
11#include "fml/status_or.h"
16
17namespace impeller {
18
19using PathCreator = std::function<fml::StatusOr<flutter::DlPath>()>;
20
21//------------------------------------------------------------------------------
22/// @brief Represents a collection of shaped text runs.
23///
24/// This object is typically the entrypoint in the Impeller type
25/// rendering subsystem.
26class TextFrame {
27 public:
29
30 TextFrame(std::vector<TextRun>& runs,
31 Rect bounds,
32 bool has_color,
33 const PathCreator& path_creator = {});
34
36
38 const TextRun::GlyphPosition& glyph_position,
39 AxisAlignment alignment,
40 const Matrix& transform);
41
44
45 //----------------------------------------------------------------------------
46 /// @brief The conservative bounding box for this text frame.
47 ///
48 /// @return The bounds rectangle. If there are no glyphs in this text
49 /// frame an empty Rectangle is returned instead.
50 ///
51 Rect GetBounds() const;
52
53 //----------------------------------------------------------------------------
54 /// @brief The number of runs in this text frame.
55 ///
56 /// @return The run count.
57 ///
58 size_t GetRunCount() const;
59
60 //----------------------------------------------------------------------------
61 /// @brief Returns a reference to all the text runs in this frame.
62 ///
63 /// @return The runs in this frame.
64 ///
65 const std::vector<TextRun>& GetRuns() const;
66
67 //----------------------------------------------------------------------------
68 /// @brief Returns whether any glyph in any run in this TextFrame
69 /// is colored and so would be cached with color already
70 /// baked in to the colored glyph.
71 ///
72 /// Non-bitmap/COLR fonts only store an alpha bitmap, but
73 /// COLR fonts can potentially use the paint color in the glyph
74 /// atlas, so the color the text is being rendered with must
75 /// be considered as part of the cache key.
76 bool HasColor() const;
77
78 //----------------------------------------------------------------------------
79 /// @brief The type of atlas this run should be place in.
80 ///
81 /// This return value depends primarily on the HasColor
82 /// property.
84
85 /// @brief If this text frame contains a single glyph (such as for an Icon),
86 /// then return it, otherwise std::nullopt.
87 std::optional<Glyph> AsSingleGlyph() const;
88
89 /// @brief Return the font of the first glyph run.
90 const Font& GetFont() const;
91
93
94 private:
95 std::vector<TextRun> runs_;
96 Rect bounds_;
97 bool has_color_;
98 const PathCreator path_creator_;
99};
100
101} // namespace impeller
102
103#endif // FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_FRAME_H_
Describes a typeface along with any modifications to its intrinsic properties.
Definition font.h:36
Type
Describes how the glyphs are represented in the texture.
Definition glyph_atlas.h:41
Represents a collection of shaped text runs.
Definition text_frame.h:26
static Rational RoundScaledFontSize(Scalar scale)
Definition text_frame.cc:55
Rect GetBounds() const
The conservative bounding box for this text frame.
Definition text_frame.cc:27
GlyphAtlas::Type GetAtlasType() const
The type of atlas this run should be place in.
Definition text_frame.cc:39
std::optional< Glyph > AsSingleGlyph() const
If this text frame contains a single glyph (such as for an Icon), then return it, otherwise std::null...
bool HasColor() const
Returns whether any glyph in any run in this TextFrame is colored and so would be cached with color a...
Definition text_frame.cc:44
const Font & GetFont() const
Return the font of the first glyph run.
size_t GetRunCount() const
The number of runs in this text frame.
Definition text_frame.cc:31
fml::StatusOr< flutter::DlPath > GetPath() const
static SubpixelPosition ComputeSubpixelPosition(const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, const Matrix &transform)
Definition text_frame.cc:94
const std::vector< TextRun > & GetRuns() const
Returns a reference to all the text runs in this frame.
Definition text_frame.cc:35
float Scalar
Definition scalar.h:19
AxisAlignment
Determines the axis along which there is subpixel positioning.
Definition font.h:21
std::function< fml::StatusOr< flutter::DlPath >()> PathCreator
Definition text_frame.h:19
A 4x4 matrix using column-major storage.
Definition matrix.h:37