Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
text_frame.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7namespace impeller {
8
9TextFrame::TextFrame() = default;
10
11TextFrame::TextFrame(std::vector<TextRun>& runs, Rect bounds, bool has_color)
12 : runs_(std::move(runs)), bounds_(bounds), has_color_(has_color) {}
13
14TextFrame::~TextFrame() = default;
15
17 return bounds_;
18}
19
20size_t TextFrame::GetRunCount() const {
21 return runs_.size();
22}
23
24const std::vector<TextRun>& TextFrame::GetRuns() const {
25 return runs_;
26}
27
32
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}
64
65// static
67 return std::round(scale * 100) / 100;
68}
69
71 Scalar scale) const {
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}
90
91} // namespace impeller
Describes a typeface along with any modifications to its intrinsic properties.
Definition font.h:22
Type
Describes how the glyphs are represented in the texture.
Definition glyph_atlas.h:32
Rect GetBounds() const
The conservative bounding box for this text frame.
Definition text_frame.cc:16
static Scalar RoundScaledFontSize(Scalar scale, Scalar point_size)
Definition text_frame.cc:66
GlyphAtlas::Type GetAtlasType() const
The type of atlas this run should be emplaced in.
Definition text_frame.cc:28
void CollectUniqueFontGlyphPairs(FontGlyphMap &glyph_map, Scalar scale) const
Definition text_frame.cc:70
bool MaybeHasOverlapping() const
Whether any of the glyphs of this run are potentially overlapping.
Definition text_frame.cc:33
size_t GetRunCount() const
The number of runs in this text frame.
Definition text_frame.cc:20
const std::vector< TextRun > & GetRuns() const
Returns a reference to all the text runs in this frame.
Definition text_frame.cc:24
Represents a collection of positioned glyphs from a specific font.
Definition text_run.h:20
#define FML_LOG(severity)
Definition logging.h:82
float Scalar
Definition scalar.h:18
std::unordered_map< ScaledFont, std::unordered_set< Glyph > > FontGlyphMap
Definition run.py:1
Definition ref_ptr.h:256
const Scalar scale
static constexpr TRect MakeOriginSize(const TPoint< Type > &origin, const TSize< Type > &size)
Definition rect.h:140
#define ERROR(message)