Flutter Impeller
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 whether any glyph in any run in this TextFrame is colored and so would be cached with color already baked in to the colored glyph. More...
 
GlyphAtlas::Type GetAtlasType () const
 The type of atlas this run should be place in. More...
 
std::optional< GlyphAsSingleGlyph () const
 If this text frame contains a single glyph (such as for an Icon), then return it, otherwise std::nullopt. More...
 
const FontGetFont () const
 Return the font of the first glyph run. More...
 
fml::StatusOr< flutter::DlPath > GetPath () 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)
 

Detailed Description

Represents a collection of shaped text runs.

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

Definition at line 26 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 125 of file text_frame.cc.

125  {
126  if (runs_.size() == 1 && runs_[0].GetGlyphCount() == 1) {
127  return runs_[0].GetGlyphPositions()[0].glyph;
128  }
129  return std::nullopt;
130 }

◆ 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) {
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>(
110  (ComputeFractionalPosition(pos.y) << 2));
111  }
112 }
TPoint< Scalar > Point
Definition: point.h:426
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().

◆ GetAtlasType()

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

The type of atlas this run should be place in.

        This return value depends primarily on the HasColor
        property. 

Definition at line 39 of file text_frame.cc.

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

121  {
122  return runs_[0].GetFont();
123 }

◆ GetPath()

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

Definition at line 114 of file text_frame.cc.

114  {
115  if (path_creator_) {
116  return path_creator_();
117  }
118  return fml::Status(fml::StatusCode::kCancelled, "no path creator specified.");
119 }

◆ 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 }

◆ HasColor()

bool impeller::TextFrame::HasColor ( ) const

Returns whether any glyph in any run in this TextFrame is colored and so would be cached with color already baked in to the colored glyph.

Non-bitmap/COLR fonts only store an alpha bitmap, but COLR fonts can potentially use the paint color in the glyph atlas, so the color the text is being rendered with must be considered as part of the cache key.

Definition at line 44 of file text_frame.cc.

44  {
45  return has_color_;
46 }

◆ 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 }
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 }

References impeller::kZero.

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


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