Flutter Engine
The Flutter Engine
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
8
9namespace impeller {
10
11TextFrame::TextFrame() = default;
12
13TextFrame::TextFrame(std::vector<TextRun>& runs, Rect bounds, bool has_color)
14 : runs_(std::move(runs)), bounds_(bounds), has_color_(has_color) {}
15
16TextFrame::~TextFrame() = default;
17
19 return bounds_;
20}
21
22size_t TextFrame::GetRunCount() const {
23 return runs_.size();
24}
25
26const std::vector<TextRun>& TextFrame::GetRuns() const {
27 return runs_;
28}
29
31 return has_color_ ? GlyphAtlas::Type::kColorBitmap
33}
34
35bool TextFrame::HasColor() const {
36 return has_color_;
37}
38
39// static
41 // An arbitrarily chosen maximum text scale to ensure that regardless of the
42 // CTM, a glyph will fit in the atlas. If we clamp significantly, this may
43 // reduce fidelity but is preferable to the alternative of failing to render.
44 constexpr Scalar kMaximumTextScale = 48;
45 Scalar result = std::round(scale * 100) / 100;
46 return std::clamp(result, 0.0f, kMaximumTextScale);
47}
48
50 value += 0.125;
51 value = (value - floorf(value));
52 if (value < 0.25) {
53 return 0;
54 }
55 if (value < 0.5) {
56 return 0.25;
57 }
58 if (value < 0.75) {
59 return 0.5;
60 }
61 return 0.75;
62}
63
64// Compute subpixel position for glyphs based on X position and provided
65// max basis length (scale).
66// This logic is based on the SkPackedGlyphID logic in SkGlyph.h
67// static
69 const TextRun::GlyphPosition& glyph_position,
70 AxisAlignment alignment,
72 Scalar scale) {
73 Point pos = glyph_position.position + offset;
74 switch (alignment) {
76 return Point(0, 0);
84 }
85}
86
88 FontGlyphMap& glyph_map,
91 const GlyphProperties& properties) const {
92 for (const TextRun& run : GetRuns()) {
93 const Font& font = run.GetFont();
94 auto rounded_scale =
95 RoundScaledFontSize(scale, font.GetMetrics().point_size);
96 auto& set = glyph_map[ScaledFont{font, rounded_scale}];
97 for (const TextRun::GlyphPosition& glyph_position :
98 run.GetGlyphPositions()) {
100 glyph_position, font.GetAxisAlignment(), offset, scale);
101 set.emplace(glyph_position.glyph, subpixel, properties);
102 }
103 }
104}
105
106} // namespace impeller
static void round(SkPoint *p)
SkPoint pos
static unsigned clamp(SkFixed fx, int max)
Describes a typeface along with any modifications to its intrinsic properties.
Definition: font.h:35
Type
Describes how the glyphs are represented in the texture.
Definition: glyph_atlas.h:31
Rect GetBounds() const
The conservative bounding box for this text frame.
Definition: text_frame.cc:18
static Scalar RoundScaledFontSize(Scalar scale, Scalar point_size)
Definition: text_frame.cc:40
GlyphAtlas::Type GetAtlasType() const
The type of atlas this run should be emplaced in.
Definition: text_frame.cc:30
bool HasColor() const
Returns the paint color this text frame was recorded with.
Definition: text_frame.cc:35
void CollectUniqueFontGlyphPairs(FontGlyphMap &glyph_map, Scalar scale, Point offset, const GlyphProperties &properties) const
Definition: text_frame.cc:87
size_t GetRunCount() const
The number of runs in this text frame.
Definition: text_frame.cc:22
static Point ComputeSubpixelPosition(const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, Point offset, Scalar scale)
Definition: text_frame.cc:68
const std::vector< TextRun > & GetRuns() const
Returns a reference to all the text runs in this frame.
Definition: text_frame.cc:26
Represents a collection of positioned glyphs from a specific font.
Definition: text_run.h:20
uint8_t value
GAsyncResult * result
Optional< SkRect > bounds
Definition: SkRecords.h:189
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.
float Scalar
Definition: scalar.h:18
TPoint< Scalar > Point
Definition: point.h:322
AxisAlignment
Determines the axis along which there is subpixel positioning.
Definition: font.h:20
static constexpr Scalar ComputeFractionalPosition(Scalar value)
Definition: text_frame.cc:49
std::unordered_map< ScaledFont, std::unordered_set< SubpixelGlyph > > FontGlyphMap
Definition: run.py:1
Definition: ref_ptr.h:256
const Scalar scale
SeparatedVector2 offset
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181
A font and a scale. Used as a key that represents a typeface within a glyph atlas.