MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Portal::Text::GlyphAtlas Class Reference

Rasterizes and packs glyphs from a FontFace into a TextureContainer. More...

#include <GlyphAtlas.hpp>

+ Collaboration diagram for MayaFlux::Portal::Text::GlyphAtlas:

Public Member Functions

void add_fallback (FontFace &face)
 Register a fallback face, tried in order after the primary on a miss.
 
uint32_t ascender () const
 Ascender in pixels for this atlas's pixel_size.
 
uint32_t atlas_size () const
 Atlas texture dimension (width == height == atlas_size).
 
void clear_dirty ()
 Clear the dirty flag after re-uploading the atlas to GPU.
 
FontFace & get_face ()
 Access the backing FontFace.
 
const FontFace & get_face () const
 
const GlyphMetrics * get_or_rasterize (FT_UInt glyph_index)
 Return metrics for a glyph, rasterizing it into the atlas if needed.
 
const GlyphMetrics * get_or_rasterize (FT_ULong codepoint)
 Convenience: look up by Unicode codepoint.
 
 GlyphAtlas (const GlyphAtlas &)=delete
 
 GlyphAtlas (FontFace &face, uint32_t pixel_size, uint32_t atlas_size=512)
 Construct an atlas for a specific face and pixel size.
 
 GlyphAtlas (GlyphAtlas &&)=delete
 
bool is_dirty () const
 Returns true if at least one glyph was rasterized since the last call to clear_dirty().
 
uint32_t line_height () const
 Line advance in pixels for this atlas's pixel_size.
 
GlyphAtlas & operator= (const GlyphAtlas &)=delete
 
GlyphAtlas & operator= (GlyphAtlas &&)=delete
 
uint32_t pixel_size () const
 Pixel size passed at construction.
 
Kakshya::TextureContainer & texture ()
 
const Kakshya::TextureContainer & texture () const
 The atlas texture as a TextureContainer (R8, atlas_size x atlas_size).
 
 ~GlyphAtlas ()=default
 

Private Member Functions

const GlyphMetrics * get_or_rasterize_from (FontFace &face, FT_UInt glyph_index)
 
void grow ()
 Double the atlas texture and re-rasterize every cached glyph into it.
 
bool rasterize (FontFace &face, FT_UInt glyph_index)
 

Private Attributes

uint32_t m_atlas_size
 
std::unordered_map< FontFace *, std::unordered_map< FT_UInt, GlyphMetrics > > m_cache
 Per-face glyph cache.
 
uint32_t m_cursor_x { 0 }
 
uint32_t m_cursor_y { 0 }
 
bool m_dirty { false }
 
FontFace & m_face
 
std::vector< FontFace * > m_fallbacks
 
uint32_t m_pixel_size
 
uint32_t m_shelf_height { 0 }
 
std::unique_ptr< Kakshya::TextureContainer > m_texture
 

Detailed Description

Rasterizes and packs glyphs from a FontFace into a TextureContainer.

One atlas corresponds to one (FontFace, pixel_size) pair. The atlas texture is R8 (single-channel coverage); colour is applied in the shader.

Glyphs are rasterized on first request via get_or_rasterize() and packed into the atlas using a simple shelf packing algorithm. On shelf overflow the atlas texture doubles in size and every previously cached glyph is re-rasterized into the new texture from its owning face; rasterization never permanently refuses for lack of room.

The primary face is fixed at construction. A codepoint the primary face lacks is looked up in the fallback chain (add_fallback()), in order, and the first face reporting a glyph produces it; a codepoint absent from every face fails as before. The atlas's cache is keyed on (face, glyph_index) rather than glyph_index alone, since glyph indices are only unique within the face that assigned them: the same numeric index from two different faces names two unrelated glyphs.

Callers obtain glyph indices via FT_Get_Char_Index on the FontFace. This keeps the path open for HarfBuzz, which outputs glyph indices directly (against the primary face; HarfBuzz does not participate in fallback).

Thread safety: not thread-safe. Rasterization must occur on the thread that owns the FontFace.

Definition at line 72 of file GlyphAtlas.hpp.


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