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

Fixed-size 5x7 bitmap font with ASCII and extended character support. More...

#include <BitmapFont.h>

Inheritance diagram for BitmapFont< RGB_T >:
Inheritance graph
[legend]
Collaboration diagram for BitmapFont< RGB_T >:
Collaboration graph
[legend]

Public Types

using Glyph = std::array< uint8_t, 7 >
 Glyph storage for one 5x7 character.
 
using CodePoint = uint32_t
 Unicode code point type used during UTF-8 decoding.
 

Public Member Functions

 BitmapFont ()=default
 Creates a bitmap font instance.
 
const Glyphglyph (char character) const
 Returns the glyph for an 8-bit character.
 
const Glyphglyph (CodePoint codePoint) const
 Returns the glyph for a Unicode code point.
 
bool pixel (char character, uint8_t x, uint8_t y) const
 Returns whether a pixel is set in an 8-bit character glyph.
 
bool pixel (CodePoint codePoint, uint8_t x, uint8_t y) const
 Returns whether a pixel is set in a code point glyph.
 
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 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
 Draws a single Unicode code point.
 
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
 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
 Returns the total text height in pixels.
 
size_t getHeight (uint8_t scale) const
 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.
 

Static Public Attributes

static constexpr uint8_t kGlyphWidth = 5
 Width of a glyph in pixels.
 
static constexpr uint8_t kGlyphHeight = 7
 Height of a glyph in pixels.
 
static constexpr char kFirstChar = ' '
 First directly stored ASCII character.
 
static constexpr char kLastChar = '~'
 Last directly stored ASCII character.
 

Detailed Description

template<typename RGB_T = RGB565>
class tinygpu::BitmapFont< RGB_T >

Fixed-size 5x7 bitmap font with ASCII and extended character support.

The font can inspect glyph data, measure text, and render UTF-8 strings to any framebuffer implementation that follows the TinyGPU font interface.

Member Typedef Documentation

◆ CodePoint

using CodePoint = uint32_t

Unicode code point type used during UTF-8 decoding.

◆ Glyph

using Glyph = std::array<uint8_t, 7>

Glyph storage for one 5x7 character.

Constructor & Destructor Documentation

◆ BitmapFont()

BitmapFont ( )
default

Creates a bitmap font instance.

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.

◆ 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
inlinevirtual

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]

const Glyph & glyph ( CodePoint  codePoint) const
inline

Returns the glyph for a Unicode code point.

◆ measureTextHeight()

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

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
inlinevirtual

Returns the width of the longest text line in pixels.

Implements IFont< RGB_T >.

◆ pixel() [1/2]

bool pixel ( char  character,
uint8_t  x,
uint8_t  y 
) const
inline

Returns whether a pixel is set in an 8-bit character glyph.

◆ pixel() [2/2]

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

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

Member Data Documentation

◆ kFirstChar

constexpr char kFirstChar = ' '
staticconstexpr

First directly stored ASCII character.

◆ kGlyphHeight

constexpr uint8_t kGlyphHeight = 7
staticconstexpr

Height of a glyph in pixels.

◆ kGlyphWidth

constexpr uint8_t kGlyphWidth = 5
staticconstexpr

Width of a glyph in pixels.

◆ kLastChar

constexpr char kLastChar = '~'
staticconstexpr

Last directly stored ASCII character.


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