TinyGPU
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
BitmapFont< Width, Height, RowT, RGB_T > Class Template Reference

Fixed-size bitmap font backed by a caller-supplied glyph table. More...

#include <BitmapFont.h>

Inheritance diagram for BitmapFont< Width, Height, RowT, RGB_T >:
Inheritance graph
[legend]
Collaboration diagram for BitmapFont< Width, Height, RowT, RGB_T >:
Collaboration graph
[legend]

Public Types

using Glyph = std::array< RowT, Height >
 Glyph storage: one row entry per pixel row.
 
using CodePoint = uint32_t
 Unicode code point type used during UTF-8 decoding.
 

Public Member Functions

 BitmapFont (const Glyph *table, size_t glyphCount, char firstChar=' ')
 Creates a fixed bitmap font over a contiguous glyph table.
 
void setProportional (bool proportional) override
 
bool isProportional () const override
 Returns whether proportional spacing is enabled.
 
uint8_t glyphLeftOffset (CodePoint codePoint) const
 
uint8_t glyphEffectiveWidth (CodePoint codePoint) const
 
uint8_t glyphAdvanceWidth (CodePoint codePoint) const
 
const Glyph & glyph (char character) const
 Returns the glyph for an 8-bit character.
 
virtual const Glyph & glyph (CodePoint codePoint) const
 
bool pixel (CodePoint codePoint, uint8_t x, uint8_t y) const
 Returns whether a pixel is set in a code point glyph.
 
void drawCodePoint (ISurface< RGB_T > &target, int16_t x, int16_t y, CodePoint codePoint, RGB_T foreground, RGB_T background=RGB_T(0), bool opaque=false, uint8_t scale=1) const
 
void drawChar (ISurface< RGB_T > &target, int16_t x, int16_t y, char character, RGB_T foreground, RGB_T background=RGB_T(0), bool opaque=false, uint8_t scale=1) const
 Draws a single character.
 
void drawText (ISurface< RGB_T > &target, int16_t x, int16_t y, const char *text, RGB_T foreground, RGB_T background=RGB_T(0), bool opaque=false, uint8_t scale=1, uint8_t spacing=1, uint8_t lineSpacing=1) const override
 Draws a UTF-8 text string.
 
size_t measureTextWidth (const char *text, uint8_t scale=1, uint8_t spacing=1) const override
 Returns the width of the longest text line in pixels.
 
size_t measureTextHeight (const char *text, uint8_t scale=1, uint8_t lineSpacing=1) const override
 Returns the total text height in pixels.
 
size_t getHeight (uint8_t scale) const override
 Returns the scaled glyph height in pixels.
 
- Public Member Functions inherited from IFont< RGB_T >
virtual ~IFont ()=default
 Destroys the font interface.
 
virtual void drawText (ISurface< RGB_T > &target, int16_t x, int16_t y, const char *text, RGB_T foreground, RGB_T background, bool opaque=false, uint8_t scale=1, uint8_t spacing=1, uint8_t lineSpacing=1) const =0
 Draws a text string onto a framebuffer target.
 
virtual size_t measureTextWidth (const char *text, uint8_t scale=1, uint8_t spacing=1) const =0
 Returns the width of the longest text line in pixels.
 
virtual size_t measureTextHeight (const char *text, uint8_t scale=1, uint8_t lineSpacing=1) const =0
 Returns the total text height in pixels.
 
virtual size_t getHeight (uint8_t scale) const =0
 Returns the scaled glyph height in pixels.
 
virtual void setProportional (bool proportional)
 
virtual bool isProportional () const
 Returns whether proportional spacing is enabled.
 

Static Public Attributes

static constexpr uint8_t kGlyphWidth = Width
 Width of a glyph in pixels.
 
static constexpr uint8_t kGlyphHeight = Height
 Height of a glyph in pixels.
 
static constexpr uint8_t kBlankGlyphWidth = (kGlyphWidth > 2) ? kGlyphWidth - 2 : kGlyphWidth
 

Detailed Description

template<uint8_t Width, uint8_t Height, typename RowT, typename RGB_T = RGB565>
class tinygpu::BitmapFont< Width, Height, RowT, RGB_T >

Fixed-size bitmap font backed by a caller-supplied glyph table.

Template Parameters
WidthGlyph width in pixels.
HeightGlyph height in pixels.
RowTUnsigned integer type used to store one glyph row. Only the Width most significant bits of each row are used (bit Width-1 is the left-most pixel), mirroring the bit order used by Font5x7.
RGB_TThe pixel color type. Can be RGB565, RGB666, RGB888, etc.

Concrete fonts (e.g. converted from vendor font tables) subclass this and pass their own glyph table to the constructor. Only a contiguous ASCII range starting at firstChar is supported; any code point outside that range falls back to the glyph for '?'.

Member Typedef Documentation

◆ CodePoint

using CodePoint = uint32_t

Unicode code point type used during UTF-8 decoding.

◆ Glyph

using Glyph = std::array<RowT, Height>

Glyph storage: one row entry per pixel row.

Constructor & Destructor Documentation

◆ BitmapFont()

BitmapFont ( const Glyph *  table,
size_t  glyphCount,
char  firstChar = ' ' 
)
inline

Creates a fixed bitmap font over a contiguous glyph table.

Member Function Documentation

◆ drawChar()

void drawChar ( ISurface< RGB_T > &  target,
int16_t  x,
int16_t  y,
char  character,
RGB_T  foreground,
RGB_T  background = RGB_T(0),
bool  opaque = false,
uint8_t  scale = 1 
) const
inline

Draws a single character.

◆ drawCodePoint()

void drawCodePoint ( ISurface< RGB_T > &  target,
int16_t  x,
int16_t  y,
CodePoint  codePoint,
RGB_T  foreground,
RGB_T  background = RGB_T(0),
bool  opaque = false,
uint8_t  scale = 1 
) const
inline

Draws a single Unicode code point. In proportional mode, leading blank columns of the glyph are skipped so the visible pixels start at x.

◆ drawText()

void drawText ( ISurface< RGB_T > &  target,
int16_t  x,
int16_t  y,
const char *  text,
RGB_T  foreground,
RGB_T  background = RGB_T(0),
bool  opaque = false,
uint8_t  scale = 1,
uint8_t  spacing = 1,
uint8_t  lineSpacing = 1 
) const
inlineoverridevirtual

Draws a UTF-8 text string.

Implements IFont< RGB_T >.

◆ getHeight()

size_t getHeight ( uint8_t  scale) const
inlineoverridevirtual

Returns the scaled glyph height in pixels.

Implements IFont< RGB_T >.

◆ glyph() [1/2]

const Glyph & glyph ( char  character) const
inline

Returns the glyph for an 8-bit character.

◆ glyph() [2/2]

virtual const Glyph & glyph ( CodePoint  codePoint) const
inlinevirtual

Returns the glyph for a Unicode code point. Virtual so a subclass with its own extra fallback logic (e.g. Font5x7's mapping of Latin-1/CP1252-ish codepoints outside its stored ASCII range) can override just this lookup and get every other method here - pixel(), drawText(), measureTextWidth(), ... - for free, since they all call glyph() internally rather than duplicating the lookup themselves.

Reimplemented in Font5x7< RGB_T >, Font5x7< RGB565 >, Font5x7< tinygpu::RGB565 >, Font5x7< RGB_T >, Font5x7< RGB565 >, and Font5x7< tinygpu::RGB565 >.

◆ glyphAdvanceWidth()

uint8_t glyphAdvanceWidth ( CodePoint  codePoint) const
inline

Returns the advance width (in unscaled pixels) used to move the cursor past a code point's glyph, honoring proportional mode when enabled.

◆ glyphEffectiveWidth()

uint8_t glyphEffectiveWidth ( CodePoint  codePoint) const
inline

Returns the effective (used) width in pixels of a code point's glyph, i.e. the span from its left-most to right-most set pixel column, inclusive. Glyphs with no set pixels (e.g. the space) fall back to a default blank width.

◆ glyphLeftOffset()

uint8_t glyphLeftOffset ( CodePoint  codePoint) const
inline

Returns the left-most column (0-based) that has a set pixel in a code point's glyph. Glyphs with no set pixels (e.g. the space) return 0.

◆ isProportional()

bool isProportional ( ) const
inlineoverridevirtual

Returns whether proportional spacing is enabled.

Reimplemented from IFont< RGB_T >.

◆ measureTextHeight()

size_t measureTextHeight ( const char *  text,
uint8_t  scale = 1,
uint8_t  lineSpacing = 1 
) const
inlineoverridevirtual

Returns the total text height in pixels.

Implements IFont< RGB_T >.

◆ measureTextWidth()

size_t measureTextWidth ( const char *  text,
uint8_t  scale = 1,
uint8_t  spacing = 1 
) const
inlineoverridevirtual

Returns the width of the longest text line in pixels.

Implements IFont< RGB_T >.

◆ pixel()

bool pixel ( CodePoint  codePoint,
uint8_t  x,
uint8_t  y 
) const
inline

Returns whether a pixel is set in a code point glyph.

◆ setProportional()

void setProportional ( bool  proportional)
inlineoverridevirtual

Enables/disables proportional spacing based on each glyph's effective (used) width instead of the fixed glyph width.

Reimplemented from IFont< RGB_T >.

Member Data Documentation

◆ kBlankGlyphWidth

constexpr uint8_t kBlankGlyphWidth = (kGlyphWidth > 2) ? kGlyphWidth - 2 : kGlyphWidth
staticconstexpr

Advance width used in proportional mode for glyphs with no set pixels (e.g. the space character).

◆ kGlyphHeight

constexpr uint8_t kGlyphHeight = Height
staticconstexpr

Height of a glyph in pixels.

◆ kGlyphWidth

constexpr uint8_t kGlyphWidth = Width
staticconstexpr

Width of a glyph in pixels.


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