| 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 | Type { Type::kAlphaBitmap, Type::kColorBitmap }
| Describes how the glyphs are represented in the texture. More...

## Public Member Functions
| GlyphAtlas (Type type)
| 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 | AddTypefaceGlyphPosition (const FontGlyphPair &pair, Rect rect)
| 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 Glyph &glyph, const Rect &rect)> &iterator) const
| Iterate of all the glyphs along with their locations in the atlas. More...
std::optional< Rect > | FindFontGlyphBounds (const FontGlyphPair &pair) const
| Find the location of a specific font-glyph pair in the atlas. More...
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. This provides a more efficient way to look up a run of glyphs in the same font. 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 28 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 alpha channel.
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 /// alpha channel.
36 ///
37 kAlphaBitmap,
38
39 //--------------------------------------------------------------------------
40 /// The glyphs are reprsented at their requested size using N32 premul
41 /// colors.
42 ///
43 kColorBitmap,
44 };

## Constructor & Destructor Documentation

## ◆ GlyphAtlas()

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

Create an empty glyph atlas.

Parameters

  [in] | type | How 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] | pair | The font-glyph pair
  [in] | rect | The rectangle

Definition at line 61 of file glyph_atlas.cc.

62 {
63 font_atlas_map_[pair.scaled_font].positions_[pair.glyph] = rect;
64 }

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

## ◆ 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] | 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 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 }

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

Referenced by impeller::UpdateAtlasBitmap().

## ◆ 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] | 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 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 }

## ◆ 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 }

## ◆ 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 }

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

## ◆ 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] | iterator | The 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 }

Referenced by impeller::CreateAtlasBitmap().

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

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

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

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