Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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.
 
size_t GetRunCount () const
 The number of runs in this text frame.
 
const std::vector< TextRun > & GetRuns () const
 Returns a reference to all the text runs in this frame.
 
bool MaybeHasOverlapping () const
 Whether any of the glyphs of this run are potentially overlapping.
 
GlyphAtlas::Type GetAtlasType () const
 The type of atlas this run should be emplaced in.
 
TextFrameoperator= (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.
81if (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}
static Scalar RoundScaledFontSize(Scalar scale, Scalar point_size)
Definition text_frame.cc:66
const std::vector< TextRun > & GetRuns() const
Returns a reference to all the text runs in this frame.
Definition text_frame.cc:24
#define FML_LOG(severity)
Definition logging.h:82
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition switches.h:76
font
Font Metadata and Metrics.
Definition run.py:1
const Scalar scale
#define ERROR(message)

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

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

◆ 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}
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
Definition rect.h:140

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

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