Antkeeper  0.0.1
Public Member Functions | List of all members
type::bitmap_font Class Reference

Raster font in which glyphs are stored as arrays of pixels. More...

#include <bitmap-font.hpp>

Inheritance diagram for type::bitmap_font:
type::font

Public Member Functions

 bitmap_font (const font_metrics &metrics)
 Creates a bitmap font and sets its metrics. More...
 
 bitmap_font ()
 Creates an empty bitmap font. More...
 
virtual ~bitmap_font ()=default
 Destroys a bitmap font. More...
 
virtual bool contains (char32_t code) const
 Returns true if the font contains a glyph with the given character code. More...
 
bitmap_glyphinsert (char32_t code)
 Inserts a glyph into the font. More...
 
void remove (char32_t code)
 Removes a glyph from the font. More...
 
void clear ()
 Removes all glyphs from the font. More...
 
bool pack (bool resize=true)
 Packs all glyph bitmaps into the font bitmap. More...
 
void unpack (bool resize=true)
 Unpacks all glyph bitmaps from the font bitmap. More...
 
virtual const glyph_metricsget_glyph_metrics (char32_t code) const
 Returns metrics describing a glyph. More...
 
const std::shared_ptr< gl::texture_2d > & get_texture () const noexcept
 Returns a pointer to the glyph corresponding to a UTF-32 character code, or nullptr if no such glyph was found. More...
 
const bitmap_glyphget_glyph (char32_t code) const
 Returns a pointer to the glyph corresponding to a UTF-32 character code, or nullptr if no such glyph was found. More...
 
bitmap_glyphget_glyph (char32_t code)
 Returns a pointer to the glyph corresponding to a UTF-32 character code, or nullptr if no such glyph was found. More...
 
- Public Member Functions inherited from type::font
 font (const font_metrics &metrics)
 Creates a font and sets its metrics. More...
 
 font ()
 Creates an empty font. More...
 
virtual ~font ()
 Destroys a font. More...
 
void kern (char32_t first, char32_t second, const math::fvec2 &offset)
 Sets the kerning offset for a pair of glyphs. More...
 
void set_font_metrics (const font_metrics &metrics)
 Sets the font metrics. More...
 
const math::fvec2get_kerning (char32_t first, char32_t second) const
 Returns the kerning offset for a pair of glyphs. More...
 
const kerning_tableget_kerning_table () const
 Returns the font's kerning table. More...
 
const font_metricsget_font_metrics () const
 Returns metrics describing the font. More...
 

Additional Inherited Members

- Protected Attributes inherited from type::font
font_metrics metrics
 
kerning_table kerning_table
 

Detailed Description

Raster font in which glyphs are stored as arrays of pixels.

See also
type::font
type::font_metrics
type::bitmap_glyph
image

Definition at line 38 of file bitmap-font.hpp.

Constructor & Destructor Documentation

◆ bitmap_font() [1/2]

type::bitmap_font::bitmap_font ( const font_metrics metrics)
explicit

Creates a bitmap font and sets its metrics.

Parameters
metricsMetrics describing the font.

Definition at line 26 of file bitmap-font.cpp.

◆ bitmap_font() [2/2]

type::bitmap_font::bitmap_font ( )

Creates an empty bitmap font.

Definition at line 30 of file bitmap-font.cpp.

◆ ~bitmap_font()

virtual type::bitmap_font::~bitmap_font ( )
virtualdefault

Destroys a bitmap font.

Member Function Documentation

◆ clear()

void type::bitmap_font::clear ( )

Removes all glyphs from the font.

Definition at line 52 of file bitmap-font.cpp.

◆ contains()

bool type::bitmap_font::contains ( char32_t  code) const
virtual

Returns true if the font contains a glyph with the given character code.

Parameters
codeUTF-32 character code of a glyph.
Returns
true if the font contains the glyph, false otherwise.

Implements type::font.

Definition at line 34 of file bitmap-font.cpp.

◆ get_glyph() [1/2]

bitmap_glyph * type::bitmap_font::get_glyph ( char32_t  code)

Returns a pointer to the glyph corresponding to a UTF-32 character code, or nullptr if no such glyph was found.

Parameters
codeUTF-32 character code of a glyph.
Returns
Pointer to the corresponding glyph.

Definition at line 236 of file bitmap-font.cpp.

◆ get_glyph() [2/2]

const bitmap_glyph * type::bitmap_font::get_glyph ( char32_t  code) const

Returns a pointer to the glyph corresponding to a UTF-32 character code, or nullptr if no such glyph was found.

Parameters
codeUTF-32 character code of a glyph.
Returns
Pointer to the corresponding glyph.

Definition at line 226 of file bitmap-font.cpp.

◆ get_glyph_metrics()

const glyph_metrics & type::bitmap_font::get_glyph_metrics ( char32_t  code) const
virtual

Returns metrics describing a glyph.

Parameters
codeUTF-32 character code of a glyph.
Returns
Metrics describing the glyph.

@except std::invalid_argument Cannot fetch metrics of unknown bitmap glyph

Implements type::font.

Definition at line 217 of file bitmap-font.cpp.

◆ get_texture()

const std::shared_ptr<gl::texture_2d>& type::bitmap_font::get_texture ( ) const
inlinenoexcept

Returns a pointer to the glyph corresponding to a UTF-32 character code, or nullptr if no such glyph was found.

Parameters
codeUTF-32 character code of a glyph.
Returns
Pointer to the corresponding glyph. Returns the bitmap font's bitmap texture.

Definition at line 118 of file bitmap-font.hpp.

◆ insert()

bitmap_glyph & type::bitmap_font::insert ( char32_t  code)

Inserts a glyph into the font.

Parameters
codeUTF-32 character code of the glyph to insert.
Returns
Reference to the inserted glyph.

Definition at line 39 of file bitmap-font.cpp.

◆ pack()

bool type::bitmap_font::pack ( bool  resize = true)

Packs all glyph bitmaps into the font bitmap.

Parameters
resizeAutomatically resize the font bitmap to contain all glyphs. Bitmap size will start at the closest power of two to the largest glyph, then its dimensions will increase to the next power of two until its large enough that all glyphs can be contained.
Returns
true if all glyphs were successfully packed, false otherwise.

@except std::runtime_error Glyph bitmap format doesn't match font bitmap format. @except std::runtime_error Not enough space in font bitmap to pack glyph.

Definition at line 57 of file bitmap-font.cpp.

◆ remove()

void type::bitmap_font::remove ( char32_t  code)

Removes a glyph from the font.

Parameters
codeUTF-32 character code of the glyph to remove.

Definition at line 44 of file bitmap-font.cpp.

◆ unpack()

void type::bitmap_font::unpack ( bool  resize = true)

Unpacks all glyph bitmaps from the font bitmap.

Parameters
resizeAutomatically resizes the font bitmap to zero.

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