| 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 | 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< std::pair< Rect, 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 27 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 31 of file glyph_atlas.h.

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

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

46 : type_(type) {}

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

68 {
69 font_atlas_map_[pair.scaled_font].positions_[pair.glyph] =
70 std::make_pair(position, bounds);
71 }

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

## ◆ FindFontGlyphBounds()

std::optional< std::pair< Rect, 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 73 of file glyph_atlas.cc.

74 {
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 }

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

Referenced by impeller::BulkUpdateAtlasBitmap(), and 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 82 of file glyph_atlas.cc.

83 {
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 }

References 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 91 of file glyph_atlas.cc.

91 {
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 }

References impeller::saturated::b.

## ◆ GetTexture()

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

Get the texture for the glyph atlas.

Returns
  The texture.

Definition at line 58 of file glyph_atlas.cc.

58 {
59 return texture_;
60 }

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 54 of file glyph_atlas.cc.

54 {
55 return type_;
56 }

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

## ◆ IsValid()

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

Definition at line 50 of file glyph_atlas.cc.

50 {
51 return !!texture_;
52 }

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

101 {
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 }

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 62 of file glyph_atlas.cc.

62 {
63 texture_ = std::move(texture);
64 }

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

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

type
GLenum type
Definition: blit_command_gles.cc:127
impeller::saturated::b
SI b
Definition: saturated_math.h:87
scale
const Scalar scale
Definition: stroke_path_geometry.cc:301