| Flutter Impeller |

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, size_t initial_generation)
| Create an empty glyph atlas. More...
| ~GlyphAtlas ()
bool | IsValid () const
Type | GetType () const
| Describes how the glyphs are represented in the texture. More...
void | SetTexture (std::shared_ptr< Texture > texture)
| Set the texture for the glyph atlas. More...
const std::shared_ptr< Texture > & | GetTexture () const
| Get the texture for the glyph atlas. More...
void | AddTypefaceGlyphPositionAndBounds (const FontGlyphPair &pair, Rect position, Rect bounds)
| Record the location of a specific font-glyph pair within the atlas. More...
size_t | GetGlyphCount () const
| Get the number of unique font-glyph pairs in this atlas. More...
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. More...
std::optional< FrameBounds > | FindFontGlyphBounds (const FontGlyphPair &pair) const
| Find the location of a specific font-glyph pair in the atlas. More...
FontGlyphAtlas * | GetOrCreateFontGlyphAtlas (const ScaledFont &scaled_font)
| 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. More...
size_t | GetAtlasGeneration () const
| Retrieve the generation id for this glyph atlas. More...
void | SetAtlasGeneration (size_t value)
| Update the atlas generation. More...

## 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 70 of file glyph_atlas.h.

## Member Enumeration Documentation

## ◆ Type

enum 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 74 of file glyph_atlas.h.

74 {
75 //--------------------------------------------------------------------------
76 /// The glyphs are reprsented at their requested size using only an 8-bit
77 /// color channel.
78 ///
79 /// This might be backed by a grey or red single channel texture, depending
80 /// on the backend capabilities.
81 kAlphaBitmap,
82
83 //--------------------------------------------------------------------------
84 /// The glyphs are reprsented at their requested size using N32 premul
85 /// colors.
86 ///
87 kColorBitmap,
88 };

## Constructor & Destructor Documentation

## ◆ GlyphAtlas()

impeller::GlyphAtlas::GlyphAtlas | ( | Type | type,
|  | size_t | initial_generation
| ) |  |

Create an empty glyph atlas.

Parameters

  [in] | type | How the glyphs are represented in the texture.
  [in] | initial_generation | the atlas generation.

Definition at line 49 of file glyph_atlas.cc.

50 : type_(type), generation_(initial_generation) {}
type
GLenum type
Definition: blit_command_gles.cc:151

## ◆ ~GlyphAtlas()

impeller::GlyphAtlas::~GlyphAtlas | ( |  | ) |
| default

## Member Function Documentation

## ◆ AddTypefaceGlyphPositionAndBounds()

void impeller::GlyphAtlas::AddTypefaceGlyphPositionAndBounds | ( | const FontGlyphPair & | pair,
|  | Rect | position,
|  | Rect | bounds
| ) |  |

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

Parameters

  [in] | pair | The font-glyph pair
  [in] | rect | The position in the atlas
  [in] | bounds | The bounds of the glyph at scale

Definition at line 78 of file glyph_atlas.cc.

80 {
81 FontAtlasMap::iterator it = font_atlas_map_.find(pair.scaled_font);
82 FML_DCHECK(it != font_atlas_map_.end());
83 it->second.positions_[pair.glyph] =
84 FrameBounds{position, bounds, /*is_placeholder=*/false};
85 }

References impeller::FontGlyphPair::glyph, and impeller::FontGlyphPair::scaled_font.

## ◆ FindFontGlyphBounds()

std::optional< FrameBounds > impeller::GlyphAtlas::FindFontGlyphBounds | ( | const FontGlyphPair & | pair | ) | const

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

Parameters

  [in] | pair | The 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 87 of file glyph_atlas.cc.

88 {
89 const auto& found = font_atlas_map_.find(pair.scaled_font);
90 if (found == font_atlas_map_.end()) {
91 return std::nullopt;
92 }
93 return found->second.FindGlyphBounds(pair.glyph);
94 }

References impeller::FontGlyphPair::glyph, and impeller::FontGlyphPair::scaled_font.

Referenced by impeller::BulkUpdateAtlasBitmap(), and impeller::UpdateAtlasBitmap().

## ◆ GetAtlasGeneration()

size_t impeller::GlyphAtlas::GetAtlasGeneration | ( |  | ) | const

Retrieve the generation id for this glyph atlas.

            The generation id is used to match with a TextFrame to
            determine if the frame is guaranteed to already be populated
            in the atlas.

Definition at line 70 of file glyph_atlas.cc.

70 {
71 return generation_;
72 }

## ◆ 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 103 of file glyph_atlas.cc.

103 {
104 return std::accumulate(font_atlas_map_.begin(), font_atlas_map_.end(), 0,
105 [](const int a, const auto& b) {
106 return a + b.second.positions_.size();
107 });
108 }
impeller::saturated::b
SI b
Definition: saturated_math.h:87

References impeller::saturated::b.

## ◆ GetOrCreateFontGlyphAtlas()

FontGlyphAtlas * impeller::GlyphAtlas::GetOrCreateFontGlyphAtlas | ( | const ScaledFont & | scaled_font | ) |

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] | font | The font
  [in] | scale | The 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 96 of file glyph_atlas.cc.

97 {
98 auto [iter, inserted] =
99 font_atlas_map_.try_emplace(scaled_font, FontGlyphAtlas());
100 return &iter->second;
101 }

## ◆ GetTexture()

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

Get the texture for the glyph atlas.

Returns
  The texture.

Definition at line 62 of file glyph_atlas.cc.

62 {
63 return texture_;
64 }

Referenced by impeller::BulkUpdateAtlasBitmap(), and impeller::UpdateAtlasBitmap().

## ◆ GetType()

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

Describes how the glyphs are represented in the texture.

Definition at line 58 of file glyph_atlas.cc.

58 {
59 return type_;
60 }

Referenced by impeller::BulkUpdateAtlasBitmap(), impeller::GetImageInfo(), and impeller::UpdateAtlasBitmap().

## ◆ IsValid()

bool impeller::GlyphAtlas::IsValid | ( |  | ) | const

Definition at line 54 of file glyph_atlas.cc.

54 {
55 return !!texture_;
56 }

## ◆ IterateGlyphs()

size_t impeller::GlyphAtlas::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.

Parameters

  [in] | iterator | The iterator. Return `false` from the iterator to stop iterating.

Returns
  The number of glyphs iterated over.

Definition at line 110 of file glyph_atlas.cc.

113 {
114 if (!iterator) {
115 return 0u;
116 }
117
118 size_t count = 0u;
119 for (const auto& font_value : font_atlas_map_) {
120 for (const auto& glyph_value : font_value.second.positions_) {
121 count++;
122 if (!iterator(font_value.first, glyph_value.first,
123 glyph_value.second.atlas_bounds)) {
124 return count;
125 }
126 }
127 }
128 return count;
129 }

## ◆ SetAtlasGeneration()

void impeller::GlyphAtlas::SetAtlasGeneration | ( | size_t | value | ) |

Update the atlas generation.

Definition at line 74 of file glyph_atlas.cc.

74 {
75 generation_ = generation;
76 }

## ◆ SetTexture()

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

Set the texture for the glyph atlas.

Parameters

  [in] | texture | The texture

Definition at line 66 of file glyph_atlas.cc.

66 {
67 texture_ = std::move(texture);
68 }

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

- impeller/typographer/glyph_atlas.h
- impeller/typographer/glyph_atlas.cc