| Flutter Impeller |

Public Member Functions | Static Public Member Functions | 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 ()
void | CollectUniqueFontGlyphPairs (FontGlyphMap &glyph_map, Scalar scale) const
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 | MaybeHasOverlapping () const
| Whether any of the glyphs of this run are potentially overlapping. More...
GlyphAtlas::Type | GetAtlasType () const
| The type of atlas this run should be emplaced in. More...
TextFrame & | operator= (TextFrame &&other)=default
| TextFrame (const TextFrame &other)=default

## Static Public Member Functions
static Scalar | RoundScaledFontSize (Scalar scale, Scalar point_size)

## Detailed Description

Represents a collection of shaped text runs.

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

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

12 : 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

## ◆ CollectUniqueFontGlyphPairs()

void impeller::TextFrame::CollectUniqueFontGlyphPairs | ( | FontGlyphMap & | glyph_map,
|  | Scalar | scale
| ) |  | const

Definition at line 70 of file text_frame.cc.

71 {
72 for (const TextRun& run : GetRuns()) {
73 const Font& font = run.GetFont();
74 auto rounded_scale =
75 RoundScaledFontSize(scale, font.GetMetrics().point_size);
76 auto& set = glyph_map[{font, rounded_scale}];
77 for (const TextRun::GlyphPosition& glyph_position :
78 run.GetGlyphPositions()) {
79 #if false
80 // Glyph size error due to RoundScaledFontSize usage above.
81 if (rounded_scale != scale) {
82 auto delta = std::abs(rounded_scale - scale);
83 FML_LOG(ERROR) << glyph_position.glyph.bounds.size * delta;
84 }
85 #endif
86 set.insert(glyph_position.glyph);
87 }
88 }
89 }

References impeller::Font::GetMetrics(), GetRuns(), impeller::Font::Metrics::point_size, and RoundScaledFontSize().

Referenced by impeller::LazyGlyphAtlas::AddTextFrame(), and impeller::testing::CreateGlyphAtlas().

## ◆ GetAtlasType()

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

The type of atlas this run should be emplaced in.

Definition at line 28 of file text_frame.cc.

28 {
29 return has_color_ ? GlyphAtlas::Type::kColorBitmap
30 : GlyphAtlas::Type::kAlphaBitmap;
31 }

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

Referenced by impeller::LazyGlyphAtlas::AddTextFrame().

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

16 {
17 return bounds_;
18 }

## ◆ GetRunCount()

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

The number of runs in this text frame.

Returns
  The run count.

Definition at line 20 of file text_frame.cc.

20 {
21 return runs_.size();
22 }

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

24 {
25 return runs_;
26 }

Referenced by CollectUniqueFontGlyphPairs().

## ◆ MaybeHasOverlapping()

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

Whether any of the glyphs of this run are potentially overlapping.

            It is always safe to return true from this method. Generally,
            any large blobs of text should return true to avoid
            computationally complex calculations. This information is used
            to apply opacity peephole optimizations to text blobs.

Definition at line 33 of file text_frame.cc.

33 {
34 if (runs_.size() > 1) {
35 return true;
36 }
37 auto glyph_positions = runs_[0].GetGlyphPositions();
38 if (glyph_positions.size() > 10) {
39 return true;
40 }
41 if (glyph_positions.size() == 1) {
42 return false;
43 }
44 // To avoid quadradic behavior the overlapping is checked against an
45 // accumulated bounds rect. This gives faster but less precise information
46 // on text runs.
47 auto first_position = glyph_positions[0];
48 auto overlapping_rect = Rect::MakeOriginSize(
49 first_position.position + first_position.glyph.bounds.GetOrigin(),
50 first_position.glyph.bounds.GetSize());
51 for (auto i = 1u; i < glyph_positions.size(); i++) {
52 auto glyph_position = glyph_positions[i];
53 auto glyph_rect = Rect::MakeOriginSize(
54 glyph_position.position + glyph_position.glyph.bounds.GetOrigin(),
55 glyph_position.glyph.bounds.GetSize());
56 auto intersection = glyph_rect.Intersection(overlapping_rect);
57 if (intersection.has_value()) {
58 return true;
59 }
60 overlapping_rect = overlapping_rect.Union(glyph_rect);
61 }
62 return false;
63 }

References impeller::TRect< Scalar >::MakeOriginSize().

## ◆ operator=()

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

## ◆ RoundScaledFontSize()

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

Definition at line 66 of file text_frame.cc.

66 {
67 return std::round(scale * 100) / 100;
68 }

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

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::GlyphAtlas::Type::kAlphaBitmap
@ kAlphaBitmap
impeller::TextFrame::GetRuns
const std::vector< TextRun > & GetRuns() const
Returns a reference to all the text runs in this frame.
Definition: text_frame.cc:24
impeller::TextFrame::RoundScaledFontSize
static Scalar RoundScaledFontSize(Scalar scale, Scalar point_size)
Definition: text_frame.cc:66
impeller::TRect< Scalar >::MakeOriginSize
constexpr static TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
Definition: rect.h:38