| 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)
| ~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...
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. More...
std::pair< size_t, intptr_t > | GetAtlasGenerationAndID () const
TextFrame & | operator= (TextFrame &&other)=default
| TextFrame (const TextFrame &other)=default
const Matrix & | GetTransform () const

## Static Public Member Functions
static Point | ComputeSubpixelPosition (const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, const Matrix &transform)
static Scalar | RoundScaledFontSize (Scalar 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 22 of file text_frame.h.

## Constructor & Destructor Documentation

## ◆ TextFrame() [1/3]

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

## ◆ TextFrame() [2/3]

impeller::TextFrame::TextFrame | ( | std::vector< TextRun > & | runs,
|  | Rect | bounds,
|  | bool | has_color
| ) |  |

Definition at line 27 of file text_frame.cc.

28 : runs_(std::move(runs)), bounds_(bounds), has_color_(has_color) {}

## ◆ ~TextFrame()

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

## ◆ TextFrame() [3/3]

impeller::TextFrame::TextFrame | ( | const TextFrame & | other | ) |
| default

## Member Function Documentation

## ◆ ComputeSubpixelPosition()

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

Definition at line 82 of file text_frame.cc.

85 {
86 Point pos = transform * glyph_position.position;
87 switch (alignment) {
88 case AxisAlignment::kNone:
89 return Point(0, 0);
90 case AxisAlignment::kX:
91 return Point(ComputeFractionalPosition(pos.x), 0);
92 case AxisAlignment::kY:
93 return Point(0, ComputeFractionalPosition(pos.y));
94 case AxisAlignment::kAll:
95 return Point(ComputeFractionalPosition(pos.x),
96 ComputeFractionalPosition(pos.y));
97 }
98 }

References impeller::ComputeFractionalPosition(), impeller::kAll, impeller::kNone, 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 149 of file text_frame.cc.

149 {
150 return std::make_pair(generation_, atlas_id_);
151 }

## ◆ GetAtlasType()

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

The type of atlas this run should be place in.

Definition at line 44 of file text_frame.cc.

44 {
45 return has_color_ ? GlyphAtlas::Type::kColorBitmap
46 : GlyphAtlas::Type::kAlphaBitmap;
47 }

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 32 of file text_frame.cc.

32 {
33 return bounds_;
34 }

## ◆ 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 144 of file text_frame.cc.

144 {
145 FML_DCHECK(index < bound_values_.size());
146 return bound_values_[index];
147 }

## ◆ GetRunCount()

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

The number of runs in this text frame.

Returns
  The run count.

Definition at line 36 of file text_frame.cc.

36 {
37 return runs_.size();
38 }

## ◆ 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 40 of file text_frame.cc.

40 {
41 return runs_;
42 }

## ◆ GetTransform()

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

Definition at line 98 of file text_frame.h.

98 { 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 49 of file text_frame.cc.

49 {
50 return has_color_;
51 }

## ◆ IsFrameComplete()

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

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

Definition at line 136 of file text_frame.cc.

136 {
137 size_t run_size = 0;
138 for (const auto& x : runs_) {
139 run_size += x.GetGlyphCount();
140 }
141 return bound_values_.size() == run_size;
142 }

References x.

## ◆ operator=()

TextFrame& impeller::TextFrame::operator= | ( | TextFrame && | other | ) |
| default

## ◆ RoundScaledFontSize()

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

Definition at line 54 of file text_frame.cc.

54 {
55 // An arbitrarily chosen maximum text scale to ensure that regardless of the
56 // CTM, a glyph will fit in the atlas. If we clamp significantly, this may
57 // reduce fidelity but is preferable to the alternative of failing to render.
58 constexpr Scalar kMaximumTextScale = 48;
59 Scalar result = std::round(scale * 200) / 200;
60 return std::clamp(result, 0.0f, kMaximumTextScale);
61 }

References scale.

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

## ◆ SetPerFrameData()

void impeller::TextFrame::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 at line 100 of file text_frame.cc.

103 {
104 if (!transform_.Equals(transform) || !ScalarNearlyEqual(scale_, scale) ||
105 !ScalarNearlyEqual(offset_.x, offset.x) ||
106 !ScalarNearlyEqual(offset_.y, offset.y) ||
107 !TextPropertiesEquals(properties_, properties)) {
108 bound_values_.clear();
109 }
110 scale_ = scale;
111 offset_ = offset;
112 properties_ = properties;
113 transform_ = transform;
114 }

References impeller::Matrix::Equals(), offset, impeller::ScalarNearlyEqual(), scale, transform, impeller::TPoint< T >::x, and impeller::TPoint< T >::y.

## Friends And Related Function Documentation

## ◆ LazyGlyphAtlas

friend class LazyGlyphAtlas
| friend

Definition at line 102 of file text_frame.h.

## ◆ TypographerContextSkia

friend class TypographerContextSkia
| friend

Definition at line 101 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

impeller::GlyphAtlas::Type::kColorBitmap
@ kColorBitmap
impeller::AxisAlignment::kAll
@ kAll
impeller::Matrix::Equals
bool Equals(const Matrix &matrix, Scalar epsilon=1e-5f) const
Definition: matrix.h:440
impeller::TPoint::y
Type y
Definition: point.h:31
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::GlyphAtlas::Type::kAlphaBitmap
@ kAlphaBitmap
x
int32_t x
Definition: dl_golden_unittests.cc:443
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:319
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
transform
Matrix transform
Definition: gaussian_blur_filter_contents.cc:214
impeller::AxisAlignment::kX
@ kX
impeller::TPoint::x
Type x
Definition: point.h:30
scale
const Scalar scale
Definition: stroke_path_geometry.cc:316
impeller::ScalarNearlyEqual
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:35
impeller::ComputeFractionalPosition
static constexpr Scalar ComputeFractionalPosition(Scalar value)
Definition: text_frame.cc:63
impeller::AxisAlignment::kNone
@ kNone
impeller::AxisAlignment::kY
@ kY