Flutter Engine
The Flutter Engine
glyph_atlas.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
7#include <numeric>
8#include <utility>
9
10namespace impeller {
11
13 : atlas_(std::make_shared<GlyphAtlas>(type)), atlas_size_(ISize(0, 0)) {}
14
16
17std::shared_ptr<GlyphAtlas> GlyphAtlasContext::GetGlyphAtlas() const {
18 return atlas_;
19}
20
22 return atlas_size_;
23}
24
26 return height_adjustment_;
27}
28
29std::shared_ptr<RectanglePacker> GlyphAtlasContext::GetRectPacker() const {
30 return rect_packer_;
31}
32
33void GlyphAtlasContext::UpdateGlyphAtlas(std::shared_ptr<GlyphAtlas> atlas,
34 ISize size,
35 int64_t height_adjustment) {
36 atlas_ = std::move(atlas);
37 atlas_size_ = size;
38 height_adjustment_ = height_adjustment;
39}
40
42 std::shared_ptr<RectanglePacker> rect_packer) {
43 rect_packer_ = std::move(rect_packer);
44}
45
47
48GlyphAtlas::~GlyphAtlas() = default;
49
50bool GlyphAtlas::IsValid() const {
51 return !!texture_;
52}
53
55 return type_;
56}
57
58const std::shared_ptr<Texture>& GlyphAtlas::GetTexture() const {
59 return texture_;
60}
61
62void GlyphAtlas::SetTexture(std::shared_ptr<Texture> texture) {
63 texture_ = std::move(texture);
64}
65
67 Rect position,
68 Rect bounds) {
69 font_atlas_map_[pair.scaled_font].positions_[pair.glyph] =
70 std::make_pair(position, bounds);
71}
72
73std::optional<std::pair<Rect, Rect>> GlyphAtlas::FindFontGlyphBounds(
74 const FontGlyphPair& pair) const {
75 const auto& found = font_atlas_map_.find(pair.scaled_font);
76 if (found == font_atlas_map_.end()) {
77 return std::nullopt;
78 }
79 return found->second.FindGlyphBounds(pair.glyph);
80}
81
83 Scalar scale) const {
84 const auto& found = font_atlas_map_.find(ScaledFont{font, scale});
85 if (found == font_atlas_map_.end()) {
86 return nullptr;
87 }
88 return &found->second;
89}
90
92 return std::accumulate(font_atlas_map_.begin(), font_atlas_map_.end(), 0,
93 [](const int a, const auto& b) {
94 return a + b.second.positions_.size();
95 });
96}
97
99 const std::function<bool(const ScaledFont& scaled_font,
100 const SubpixelGlyph& glyph,
101 const Rect& rect)>& iterator) const {
102 if (!iterator) {
103 return 0u;
104 }
105
106 size_t count = 0u;
107 for (const auto& font_value : font_atlas_map_) {
108 for (const auto& glyph_value : font_value.second.positions_) {
109 count++;
110 if (!iterator(font_value.first, glyph_value.first,
111 glyph_value.second.first)) {
112 return count;
113 }
114 }
115 }
116 return count;
117}
118
119std::optional<std::pair<Rect, Rect>> FontGlyphAtlas::FindGlyphBounds(
120 const SubpixelGlyph& glyph) const {
121 const auto& found = positions_.find(glyph);
122 if (found == positions_.end()) {
123 return std::nullopt;
124 }
125 return found->second;
126}
127
128} // namespace impeller
int count
Definition: FontMgrTest.cpp:50
GLenum type
An object that can look up glyph locations within the GlyphAtlas for a particular typeface.
Definition: glyph_atlas.h:200
std::optional< std::pair< Rect, Rect > > FindGlyphBounds(const SubpixelGlyph &glyph) const
Find the location of a glyph in the atlas.
Definition: glyph_atlas.cc:119
Describes a typeface along with any modifications to its intrinsic properties.
Definition: font.h:35
GlyphAtlasContext(GlyphAtlas::Type type)
Definition: glyph_atlas.cc:12
std::shared_ptr< RectanglePacker > GetRectPacker() const
Retrieve the previous (if any) rect packer.
Definition: glyph_atlas.cc:29
void UpdateRectPacker(std::shared_ptr< RectanglePacker > rect_packer)
Definition: glyph_atlas.cc:41
std::shared_ptr< GlyphAtlas > GetGlyphAtlas() const
Retrieve the current glyph atlas.
Definition: glyph_atlas.cc:17
const ISize & GetAtlasSize() const
Retrieve the size of the current glyph atlas.
Definition: glyph_atlas.cc:21
int64_t GetHeightAdjustment() const
A y-coordinate shift that must be applied to glyphs appended to the atlas.
Definition: glyph_atlas.cc:25
void UpdateGlyphAtlas(std::shared_ptr< GlyphAtlas > atlas, ISize size, int64_t height_adjustment_)
Update the context with a newly constructed glyph atlas.
Definition: glyph_atlas.cc:33
A texture containing the bitmap representation of glyphs in different fonts along with the ability to...
Definition: glyph_atlas.h:27
GlyphAtlas(Type type)
Create an empty glyph atlas.
Definition: glyph_atlas.cc:46
bool IsValid() const
Definition: glyph_atlas.cc:50
std::optional< std::pair< Rect, Rect > > FindFontGlyphBounds(const FontGlyphPair &pair) const
Find the location of a specific font-glyph pair in the atlas.
Definition: glyph_atlas.cc:73
void SetTexture(std::shared_ptr< Texture > texture)
Set the texture for the glyph atlas.
Definition: glyph_atlas.cc:62
Type
Describes how the glyphs are represented in the texture.
Definition: glyph_atlas.h:31
Type GetType() const
Describes how the glyphs are represented in the texture.
Definition: glyph_atlas.cc:54
const std::shared_ptr< Texture > & GetTexture() const
Get the texture for the glyph atlas.
Definition: glyph_atlas.cc:58
const FontGlyphAtlas * GetFontGlyphAtlas(const Font &font, Scalar scale) const
Obtain an interface for querying the location of glyphs in the atlas for the given font and scale....
Definition: glyph_atlas.cc:82
size_t IterateGlyphs(const std::function< bool(const ScaledFont &scaled_font, const SubpixelGlyph &glyph, const Rect &rect)> &iterator) const
Iterate of all the glyphs along with their locations in the atlas.
Definition: glyph_atlas.cc:98
void AddTypefaceGlyphPositionAndBounds(const FontGlyphPair &pair, Rect position, Rect bounds)
Record the location of a specific font-glyph pair within the atlas.
Definition: glyph_atlas.cc:66
size_t GetGlyphCount() const
Get the number of unique font-glyph pairs in this atlas.
Definition: glyph_atlas.cc:91
static bool b
struct MyStruct a[10]
Dart_NativeFunction function
Definition: fuchsia.cc:51
FlTexture * texture
sk_sp< const SkImage > atlas
Definition: SkRecords.h:331
Optional< SkRect > bounds
Definition: SkRecords.h:189
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
float Scalar
Definition: scalar.h:18
Definition: ref_ptr.h:256
const Scalar scale
A font along with a glyph in that font rendered at a particular scale and subpixel position.
const SubpixelGlyph & glyph
const ScaledFont & scaled_font
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
A glyph and its subpixel position.