Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
impeller::GlyphAtlas Class Reference

A texture containing the bitmap representation of glyphs in different fonts along with the ability to query the location of specific font glyphs within the texture. More...

#include <glyph_atlas.h>

Public Types

enum class  Type { kAlphaBitmap , kColorBitmap }
 Describes how the glyphs are represented in the texture. More...
 

Public Member Functions

 GlyphAtlas (Type type)
 Create an empty glyph atlas.
 
 ~GlyphAtlas ()
 
bool IsValid () const
 
Type GetType () const
 Describes how the glyphs are represented in the texture.
 
void SetTexture (std::shared_ptr< Texture > texture)
 Set the texture for the glyph atlas.
 
const std::shared_ptr< Texture > & GetTexture () const
 Get the texture for the glyph atlas.
 
void AddTypefaceGlyphPosition (const FontGlyphPair &pair, Rect rect)
 Record the location of a specific font-glyph pair within the atlas.
 
size_t GetGlyphCount () const
 Get the number of unique font-glyph pairs in this atlas.
 
size_t IterateGlyphs (const std::function< bool(const ScaledFont &scaled_font, const Glyph &glyph, const Rect &rect)> &iterator) const
 Iterate of all the glyphs along with their locations in the atlas.
 
std::optional< RectFindFontGlyphBounds (const FontGlyphPair &pair) const
 Find the location of a specific font-glyph pair in the atlas.
 
const FontGlyphAtlasGetFontGlyphAtlas (const Font &font, Scalar scale) const
 Obtain an interface for querying the location of glyphs in the atlas for the given font and scale. This provides a more efficient way to look up a run of glyphs in the same font.
 

Detailed Description

A texture containing the bitmap representation of glyphs in different fonts along with the ability to query the location of specific font glyphs within the texture.

Definition at line 28 of file glyph_atlas.h.

Member Enumeration Documentation

◆ Type

enum class impeller::GlyphAtlas::Type
strong

Describes how the glyphs are represented in the texture.

Enumerator
kAlphaBitmap 

The glyphs are reprsented at their requested size using only an 8-bit color channel.

This might be backed by a grey or red single channel texture, depending on the backend capabilities.

kColorBitmap 

The glyphs are reprsented at their requested size using N32 premul colors.

Definition at line 32 of file glyph_atlas.h.

32 {
33 //--------------------------------------------------------------------------
34 /// The glyphs are reprsented at their requested size using only an 8-bit
35 /// color channel.
36 ///
37 /// This might be backed by a grey or red single channel texture, depending
38 /// on the backend capabilities.
40
41 //--------------------------------------------------------------------------
42 /// The glyphs are reprsented at their requested size using N32 premul
43 /// colors.
44 ///
46 };

Constructor & Destructor Documentation

◆ GlyphAtlas()

impeller::GlyphAtlas::GlyphAtlas ( Type  type)
explicit

Create an empty glyph atlas.

Parameters
[in]typeHow the glyphs are represented in the texture.

Definition at line 41 of file glyph_atlas.cc.

41: type_(type) {}

◆ ~GlyphAtlas()

impeller::GlyphAtlas::~GlyphAtlas ( )
default

Member Function Documentation

◆ AddTypefaceGlyphPosition()

void impeller::GlyphAtlas::AddTypefaceGlyphPosition ( const FontGlyphPair pair,
Rect  rect 
)

Record the location of a specific font-glyph pair within the atlas.

Parameters
[in]pairThe font-glyph pair
[in]rectThe rectangle

Definition at line 61 of file glyph_atlas.cc.

62 {
63 font_atlas_map_[pair.scaled_font].positions_[pair.glyph] = rect;
64}
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350

◆ FindFontGlyphBounds()

std::optional< Rect > impeller::GlyphAtlas::FindFontGlyphBounds ( const FontGlyphPair pair) const

Find the location of a specific font-glyph pair in the atlas.

Parameters
[in]pairThe font-glyph pair
Returns
The location of the font-glyph pair in the atlas. std::nullopt if the pair is not in the atlas.

Definition at line 66 of file glyph_atlas.cc.

67 {
68 const auto& found = font_atlas_map_.find(pair.scaled_font);
69 if (found == font_atlas_map_.end()) {
70 return std::nullopt;
71 }
72 return found->second.FindGlyphBounds(pair.glyph);
73}

◆ GetFontGlyphAtlas()

const FontGlyphAtlas * impeller::GlyphAtlas::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. This provides a more efficient way to look up a run of glyphs in the same font.

Parameters
[in]fontThe font
[in]scaleThe scale
Returns
A pointer to a FontGlyphAtlas, or nullptr if the font and scale are not available in the atlas. The pointer is only valid for the lifetime of the GlyphAtlas.

Definition at line 75 of file glyph_atlas.cc.

76 {
77 const auto& found = font_atlas_map_.find({font, scale});
78 if (found == font_atlas_map_.end()) {
79 return nullptr;
80 }
81 return &found->second;
82}
font
Font Metadata and Metrics.
const Scalar scale

◆ GetGlyphCount()

size_t impeller::GlyphAtlas::GetGlyphCount ( ) const

Get the number of unique font-glyph pairs in this atlas.

Returns
The glyph count.

Definition at line 84 of file glyph_atlas.cc.

84 {
85 return std::accumulate(font_atlas_map_.begin(), font_atlas_map_.end(), 0,
86 [](const int a, const auto& b) {
87 return a + b.second.positions_.size();
88 });
89}
static bool b
struct MyStruct a[10]

◆ GetTexture()

const std::shared_ptr< Texture > & impeller::GlyphAtlas::GetTexture ( ) const

Get the texture for the glyph atlas.

Returns
The texture.

Definition at line 53 of file glyph_atlas.cc.

53 {
54 return texture_;
55}

◆ GetType()

GlyphAtlas::Type impeller::GlyphAtlas::GetType ( ) const

Describes how the glyphs are represented in the texture.

Definition at line 49 of file glyph_atlas.cc.

49 {
50 return type_;
51}

◆ IsValid()

bool impeller::GlyphAtlas::IsValid ( ) const

Definition at line 45 of file glyph_atlas.cc.

45 {
46 return !!texture_;
47}

◆ IterateGlyphs()

size_t impeller::GlyphAtlas::IterateGlyphs ( const std::function< bool(const ScaledFont &scaled_font, const Glyph &glyph, const Rect &rect)> &  iterator) const

Iterate of all the glyphs along with their locations in the atlas.

Parameters
[in]iteratorThe iterator. Return false from the iterator to stop iterating.
Returns
The number of glyphs iterated over.

Definition at line 91 of file glyph_atlas.cc.

94 {
95 if (!iterator) {
96 return 0u;
97 }
98
99 size_t count = 0u;
100 for (const auto& font_value : font_atlas_map_) {
101 for (const auto& glyph_value : font_value.second.positions_) {
102 count++;
103 if (!iterator(font_value.first, glyph_value.first, glyph_value.second)) {
104 return count;
105 }
106 }
107 }
108 return count;
109}
int count

◆ SetTexture()

void impeller::GlyphAtlas::SetTexture ( std::shared_ptr< Texture texture)

Set the texture for the glyph atlas.

Parameters
[in]textureThe texture

Definition at line 57 of file glyph_atlas.cc.

57 {
58 texture_ = std::move(texture);
59}
FlTexture * texture

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