| Flutter Impeller |

Public Member Functions | Static Public Member Functions | Friends | List of all members
impeller::TextFrame Class Reference

Represents a collection of shaped text runs. More...

`#include <text_frame.h>`

## Public Member Functions
| TextFrame ()
| TextFrame (std::vector< TextRun > &runs, Rect bounds, bool has_color, const PathCreator &path_creator={})
| ~TextFrame ()
Rect | GetBounds () const
| The conservative bounding box for this text frame. More...
size_t | GetRunCount () const
| The number of runs in this text frame. More...
const std::vector< TextRun > & | GetRuns () const
| Returns a reference to all the text runs in this frame. More...
bool | HasColor () const
| Returns the paint color this text frame was recorded with. More...
GlyphAtlas::Type | GetAtlasType () const
| The type of atlas this run should be place in. More...
bool | IsFrameComplete () const
| Verifies that all glyphs in this text frame have computed bounds information. More...
const FrameBounds & | GetFrameBounds (size_t index) const
| Retrieve the frame bounds for the glyph at [index]. More...
std::optional< Glyph > | AsSingleGlyph () const
| If this text frame contains a single glyph (such as for an Icon), then return it, otherwise std::nullopt. More...
const Font & | GetFont () const
| Return the font of the first glyph run. More...
void | SetPerFrameData (Rational scale, Point offset, const Matrix &transform, std::optional< GlyphProperties > properties)
| Store text frame scale, offset, and properties for hashing in th glyph atlas. More...
std::pair< size_t, intptr_t > | GetAtlasGenerationAndID () const
Rational | GetScale () const
const Matrix & | GetTransform () const
fml::StatusOr< flutter::DlPath > | GetPath () const
Point | GetOffset () const
Matrix | GetOffsetTransform () const

## Static Public Member Functions
static SubpixelPosition | ComputeSubpixelPosition (const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, const Matrix &transform)
static Rational | RoundScaledFontSize (Scalar scale)
static Rational | RoundScaledFontSize (Rational scale)

## Friends
class | TypographerContextSkia
class | LazyGlyphAtlas

## Detailed Description

Represents a collection of shaped text runs.

            This object is typically the entrypoint in the Impeller type
            rendering subsystem.

A text frame should not be reused in multiple places within a single frame, as internally it is used as a cache for various glyph properties.

Definition at line 29 of file text_frame.h.

## Constructor & Destructor Documentation

## ◆ TextFrame() [1/2]

impeller::TextFrame::TextFrame | ( |  | ) |
| default

## ◆ TextFrame() [2/2]

impeller::TextFrame::TextFrame | ( | std::vector< TextRun > & | runs,
|  | Rect | bounds,
|  | bool | has_color,
|  | const PathCreator & | path_creator = `{}`
| ) |  |

Definition at line 16 of file text_frame.cc.

20 : runs_(std::move(runs)),
21 bounds_(bounds),
22 has_color_(has_color),
23 path_creator_(path_creator) {}

## ◆ ~TextFrame()

impeller::TextFrame::~TextFrame | ( |  | ) |
| default

## Member Function Documentation

## ◆ AsSingleGlyph()

std::optional< Glyph > impeller::TextFrame::AsSingleGlyph | ( |  | ) | const

If this text frame contains a single glyph (such as for an Icon), then return it, otherwise std::nullopt.

Definition at line 168 of file text_frame.cc.

168 {
169 if (runs_.size() == 1 && runs_[0].GetGlyphCount() == 1) {
170 return runs_[0].GetGlyphPositions()[0].glyph;
171 }
172 return std::nullopt;
173 }

## ◆ ComputeSubpixelPosition()

SubpixelPosition impeller::TextFrame::ComputeSubpixelPosition | ( | const TextRun::GlyphPosition & | glyph_position,
|  | AxisAlignment | alignment,
|  | const Matrix & | transform
| ) |  |
| static

Definition at line 94 of file text_frame.cc.

97 {
98 Point pos = transform * glyph_position.position;
99 switch (alignment) {
100 case AxisAlignment::kNone:
101 return SubpixelPosition::kSubpixel00;
102 case AxisAlignment::kX:
103 return ComputeFractionalPosition(pos.x);
104 case AxisAlignment::kY:
105 return static_cast<SubpixelPosition>(ComputeFractionalPosition(pos.y)
106 << 2);
107 case AxisAlignment::kAll:
108 return static_cast<SubpixelPosition>(
109 ComputeFractionalPosition(pos.x) |
110 (ComputeFractionalPosition(pos.y) << 2));
111 }
112 }
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::AxisAlignment::kX
@ kX
impeller::AxisAlignment::kAll
@ kAll
impeller::AxisAlignment::kNone
@ kNone
impeller::AxisAlignment::kY
@ kY
impeller::SubpixelPosition
SubpixelPosition
Definition: font_glyph_pair.h:56
impeller::kSubpixel00
@ kSubpixel00
Definition: font_glyph_pair.h:58
impeller::ComputeFractionalPosition
static constexpr SubpixelPosition ComputeFractionalPosition(Scalar value)
Definition: text_frame.cc:75

References impeller::ComputeFractionalPosition(), impeller::kAll, impeller::kNone, impeller::kSubpixel00, impeller::kX, impeller::kY, impeller::TextRun::GlyphPosition::position, transform, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

Referenced by impeller::TextContents::ComputeVertexData().

## ◆ GetAtlasGenerationAndID()

std::pair< size_t, intptr_t > impeller::TextFrame::GetAtlasGenerationAndID | ( |  | ) | const

Definition at line 180 of file text_frame.cc.

180 {
181 return std::make_pair(generation_, atlas_id_);
182 }

## ◆ GetAtlasType()

GlyphAtlas::Type impeller::TextFrame::GetAtlasType | ( |  | ) | const

The type of atlas this run should be place in.

Definition at line 39 of file text_frame.cc.

39 {
40 return has_color_ ? GlyphAtlas::Type::kColorBitmap
41 : GlyphAtlas::Type::kAlphaBitmap;
42 }
impeller::GlyphAtlas::Type::kAlphaBitmap
@ kAlphaBitmap
impeller::GlyphAtlas::Type::kColorBitmap
@ kColorBitmap

References impeller::GlyphAtlas::kAlphaBitmap, and impeller::GlyphAtlas::kColorBitmap.

## ◆ GetBounds()

Rect impeller::TextFrame::GetBounds | ( |  | ) | const

The conservative bounding box for this text frame.

Returns
  The bounds rectangle. If there are no glyphs in this text frame and empty Rectangle is returned instead.

Definition at line 27 of file text_frame.cc.

27 {
28 return bounds_;
29 }

## ◆ GetFont()

const Font & impeller::TextFrame::GetFont | ( |  | ) | const

Return the font of the first glyph run.

Definition at line 164 of file text_frame.cc.

164 {
165 return runs_[0].GetFont();
166 }

## ◆ GetFrameBounds()

const FrameBounds & impeller::TextFrame::GetFrameBounds | ( | size_t | index | ) | const

Retrieve the frame bounds for the glyph at [index].

This method is only valid if [IsFrameComplete] returns true.

Definition at line 175 of file text_frame.cc.

175 {
176 FML_DCHECK(index < bound_values_.size());
177 return bound_values_[index];
178 }

## ◆ GetOffset()

Point impeller::TextFrame::GetOffset | ( |  | ) | const

Definition at line 133 of file text_frame.cc.

133 {
134 return offset_;
135 }

## ◆ GetOffsetTransform()

Matrix impeller::TextFrame::GetOffsetTransform | ( |  | ) | const

Definition at line 114 of file text_frame.cc.

114 {
115 return transform_ * Matrix::MakeTranslation(offset_);
116 }
impeller::Matrix::MakeTranslation
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition: matrix.h:95

References impeller::Matrix::MakeTranslation().

## ◆ GetPath()

fml::StatusOr< flutter::DlPath > impeller::TextFrame::GetPath | ( |  | ) | const

Definition at line 149 of file text_frame.cc.

149 {
150 if (path_creator_) {
151 return path_creator_();
152 }
153 return fml::Status(fml::StatusCode::kCancelled, "no path creator specified.");
154 }

## ◆ GetRunCount()

size_t impeller::TextFrame::GetRunCount | ( |  | ) | const

The number of runs in this text frame.

Returns
  The run count.

Definition at line 31 of file text_frame.cc.

31 {
32 return runs_.size();
33 }

## ◆ GetRuns()

const std::vector< TextRun > & impeller::TextFrame::GetRuns | ( |  | ) | const

Returns a reference to all the text runs in this frame.

Returns
  The runs in this frame.

Definition at line 35 of file text_frame.cc.

35 {
36 return runs_;
37 }

## ◆ GetScale()

Rational impeller::TextFrame::GetScale | ( |  | ) | const

Definition at line 129 of file text_frame.cc.

129 {
130 return scale_;
131 }

## ◆ GetTransform()

const Matrix& impeller::TextFrame::GetTransform | ( |  | ) | const
| inline

Definition at line 114 of file text_frame.h.

114 { return transform_; }

## ◆ HasColor()

bool impeller::TextFrame::HasColor | ( |  | ) | const

Returns the paint color this text frame was recorded with.

            Non-bitmap/COLR fonts always use a black text color here, but
            COLR fonts can potentially use the paint color in the glyph
            atlas, so this color must be considered as part of the cache
            key.

Definition at line 44 of file text_frame.cc.

44 {
45 return has_color_;
46 }

## ◆ IsFrameComplete()

bool impeller::TextFrame::IsFrameComplete | ( |  | ) | const

Verifies that all glyphs in this text frame have computed bounds information.

Definition at line 156 of file text_frame.cc.

156 {
157 size_t run_size = 0;
158 for (const auto& x : runs_) {
159 run_size += x.GetGlyphCount();
160 }
161 return bound_values_.size() == run_size;
162 }
x
int32_t x
Definition: dl_golden_unittests.cc:458

References x.

## ◆ RoundScaledFontSize() [1/2]

Rational impeller::TextFrame::RoundScaledFontSize | ( | Rational | scale | ) |
| static

Definition at line 66 of file text_frame.cc.

66 {
67 Rational result = Rational(
68 std::round((scale.GetNumerator() * static_cast<Scalar>(kDenominator))) /
69 scale.GetDenominator(),
70 kDenominator);
71 return std::clamp(result, Rational(0, kDenominator),
72 Rational(kMaximumTextScale * kDenominator, kDenominator));
73 }
impeller::Scalar
float Scalar
Definition: scalar.h:19

References impeller::Rational::GetDenominator(), and impeller::Rational::GetNumerator().

## ◆ RoundScaledFontSize() [2/2]

Rational impeller::TextFrame::RoundScaledFontSize | ( | Scalar | scale | ) |
| static

Definition at line 55 of file text_frame.cc.

55 {
56 if (scale > kMaximumTextScale) {
57 return Rational(kMaximumTextScale * kDenominator, kDenominator);
58 }
59 // An arbitrarily chosen maximum text scale to ensure that regardless of the
60 // CTM, a glyph will fit in the atlas. If we clamp significantly, this may
61 // reduce fidelity but is preferable to the alternative of failing to render.
62 Rational result = Rational(std::round(scale * kDenominator), kDenominator);
63 return result < kZero ? kZero : result;
64 }
impeller::BlendFactor::kZero
@ kZero

References impeller::kZero.

Referenced by impeller::FirstPassDispatcher::drawTextFrame(), and impeller::testing::TEST_P().

## ◆ SetPerFrameData()

void impeller::TextFrame::SetPerFrameData | ( | Rational | scale,
|  | Point | offset,
|  | const Matrix & | transform,
|  | std::optional< GlyphProperties > | properties
| ) |  |

Store text frame scale, offset, and properties for hashing in th glyph atlas.

Definition at line 118 of file text_frame.cc.

121 {
122 bound_values_.clear();
123 scale_ = scale;
124 offset_ = offset;
125 properties_ = properties;
126 transform_ = transform;
127 }

References transform.

## Friends And Related Function Documentation

## ◆ LazyGlyphAtlas

friend class LazyGlyphAtlas
| friend

Definition at line 124 of file text_frame.h.

## ◆ TypographerContextSkia

friend class TypographerContextSkia
| friend

Definition at line 123 of file text_frame.h.

The documentation for this class was generated from the following files:

- impeller/typographer/text_frame.h
- impeller/typographer/text_frame.cc