Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
text_frame.h
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
5#ifndef FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_FRAME_H_
6#define FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_FRAME_H_
7
8#include <cstdint>
9#include <optional>
10
12#include "fml/status_or.h"
17
18namespace impeller {
19
20using PathCreator = std::function<fml::StatusOr<flutter::DlPath>()>;
21
22//------------------------------------------------------------------------------
23/// @brief Represents a collection of shaped text runs.
24///
25/// This object is typically the entrypoint in the Impeller type
26/// rendering subsystem.
27class TextFrame {
28 public:
30
31 TextFrame(std::vector<TextRun>& runs,
32 Rect bounds,
33 bool has_color,
34 const PathCreator& path_creator = {});
35
37
39 const TextRun::GlyphPosition& glyph_position,
40 AxisAlignment alignment,
41 const Matrix& transform);
42
45
46 //----------------------------------------------------------------------------
47 /// @brief The conservative bounding box for this text frame.
48 ///
49 /// @return The bounds rectangle. If there are no glyphs in this text
50 /// frame an empty Rectangle is returned instead.
51 ///
52 Rect GetBounds() const;
53
54 //----------------------------------------------------------------------------
55 /// @brief The number of runs in this text frame.
56 ///
57 /// @return The run count.
58 ///
59 size_t GetRunCount() const;
60
61 //----------------------------------------------------------------------------
62 /// @brief Returns a reference to all the text runs in this frame.
63 ///
64 /// @return The runs in this frame.
65 ///
66 const std::vector<TextRun>& GetRuns() const;
67
68 //----------------------------------------------------------------------------
69 /// @brief Returns whether any glyph in any run in this TextFrame
70 /// is colored and so would be cached with color already
71 /// baked in to the colored glyph.
72 ///
73 /// Non-bitmap/COLR fonts only store an alpha bitmap, but
74 /// COLR fonts can potentially use the paint color in the glyph
75 /// atlas, so the color the text is being rendered with must
76 /// be considered as part of the cache key.
77 bool HasColor() const;
78
79 //----------------------------------------------------------------------------
80 /// @brief The type of atlas this run should be place in.
81 ///
82 /// This return value depends primarily on the HasColor
83 /// property.
85
86 /// @brief If this text frame contains a single glyph (such as for an Icon),
87 /// then return it, otherwise std::nullopt.
88 std::optional<Glyph> AsSingleGlyph() const;
89
90 /// @brief Return the font of the first glyph run.
91 const Font& GetFont() const;
92
94
95 /// @brief Toggle the platform-specific contrast and gamma correction in the
96 /// fragment shader.
97 ///
98 /// By default, this is true on Linux to compensate for FreeType
99 /// rasterization in linear space, and false elsewhere. Setting a
100 /// value overrides this default behavior.
101 void SetEnableGammaCorrection(std::optional<bool> value) {
102 enable_gamma_correction_ = value;
103 }
104 std::optional<bool> GetEnableGammaCorrection() const {
105 return enable_gamma_correction_;
106 }
107
108 private:
109 std::vector<TextRun> runs_;
110 Rect bounds_;
111 bool has_color_;
112 const PathCreator path_creator_;
113 std::optional<bool> enable_gamma_correction_ = std::nullopt;
114};
115
116} // namespace impeller
117
118#endif // FLUTTER_IMPELLER_TYPOGRAPHER_TEXT_FRAME_H_
Describes a typeface along with any modifications to its intrinsic properties.
Definition font.h:36
Type
Describes how the glyphs are represented in the texture.
Definition glyph_atlas.h:41
Represents a collection of shaped text runs.
Definition text_frame.h:27
static Rational RoundScaledFontSize(Scalar scale)
Definition text_frame.cc:55
Rect GetBounds() const
The conservative bounding box for this text frame.
Definition text_frame.cc:27
GlyphAtlas::Type GetAtlasType() const
The type of atlas this run should be place in.
Definition text_frame.cc:39
std::optional< Glyph > AsSingleGlyph() const
If this text frame contains a single glyph (such as for an Icon), then return it, otherwise std::null...
bool HasColor() const
Returns whether any glyph in any run in this TextFrame is colored and so would be cached with color a...
Definition text_frame.cc:44
std::optional< bool > GetEnableGammaCorrection() const
Definition text_frame.h:104
const Font & GetFont() const
Return the font of the first glyph run.
void SetEnableGammaCorrection(std::optional< bool > value)
Toggle the platform-specific contrast and gamma correction in the fragment shader.
Definition text_frame.h:101
size_t GetRunCount() const
The number of runs in this text frame.
Definition text_frame.cc:31
fml::StatusOr< flutter::DlPath > GetPath() const
static SubpixelPosition ComputeSubpixelPosition(const TextRun::GlyphPosition &glyph_position, AxisAlignment alignment, const Matrix &transform)
Definition text_frame.cc:94
const std::vector< TextRun > & GetRuns() const
Returns a reference to all the text runs in this frame.
Definition text_frame.cc:35
int32_t value
float Scalar
Definition scalar.h:19
AxisAlignment
Determines the axis along which there is subpixel positioning.
Definition font.h:21
std::function< fml::StatusOr< flutter::DlPath >()> PathCreator
Definition text_frame.h:20
A 4x4 matrix using column-major storage.
Definition matrix.h:37