libepaper 2.0.0
A C++23 library for controlling Waveshare e-paper displays on Raspberry Pi, featuring transparent sleep/wake management and a fluent builder API.
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
epaper::Font Class Reference

#include <font.hpp>

Public Member Functions

constexpr Font (const std::uint8_t *table, std::uint16_t width, std::uint16_t height)
 
constexpr auto metrics () const noexcept -> FontMetrics
 Get font dimensions.
 
constexpr auto width () const noexcept -> std::uint16_t
 Get character width in pixels.
 
constexpr auto height () const noexcept -> std::uint16_t
 Get character height in pixels.
 
auto char_data (char c) const -> std::span< const std::uint8_t >
 Get bitmap data for a specific character.
 
constexpr auto bytes_per_char () const noexcept -> std::size_t
 Calculate storage size for a single character.
 

Static Public Member Functions

static auto font8 () -> const Font &
 Get 8-pixel font.
 
static auto font12 () -> const Font &
 Get 12-pixel font.
 
static auto font16 () -> const Font &
 Get 16-pixel font.
 
static auto font20 () -> const Font &
 Get 20-pixel font.
 
static auto font24 () -> const Font &
 Get 24-pixel font.
 

Constructor & Destructor Documentation

◆ Font()

constexpr epaper::Font::Font ( const std::uint8_t *  table,
std::uint16_t  width,
std::uint16_t  height 
)
inlineconstexpr

Member Function Documentation

◆ bytes_per_char()

constexpr auto epaper::Font::bytes_per_char ( ) const -> std::size_t
inlineconstexprnoexcept

Calculate storage size for a single character.

Computes the number of bytes needed to store one character's bitmap based on font dimensions.

Formula:

width_bytes = ceil(width / 8)
bytes_per_char = width_bytes × height
constexpr auto height() const noexcept -> std::uint16_t
Get character height in pixels.
Definition font.hpp:194
constexpr auto width() const noexcept -> std::uint16_t
Get character width in pixels.
Definition font.hpp:188
constexpr auto bytes_per_char() const noexcept -> std::size_t
Calculate storage size for a single character.
Definition font.hpp:261

Examples:

  • 8×8 font: 1 × 8 = 8 bytes
  • 12×12 font: 2 × 12 = 24 bytes
  • 16×16 font: 2 × 16 = 32 bytes
  • 24×24 font: 3 × 24 = 72 bytes

Total Font Size:

total_bytes = 95 × bytes_per_char() // 95 ASCII printable chars
Returns
Number of bytes per character
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

◆ char_data()

auto epaper::Font::char_data ( char  c) const -> std::span<const std::uint8_t>

Get bitmap data for a specific character.

Returns a span containing the packed bitmap bytes for the requested character. Bitmap is MSB-first, row-major encoded.

Supported Range:

  • Printable ASCII: 0x20 (space) to 0x7E (tilde)
  • Control characters (< 0x20) return empty span
  • Extended ASCII (> 0x7E) return empty span

Bitmap Layout:

For 12px wide font:
[Row 0 byte 0][Row 0 byte 1] ← First row (MSB-first)
[Row 1 byte 0][Row 1 byte 1] ← Second row
...
[Row N byte 0][Row N byte 1] ← Last row

Decoding:

auto bitmap = font.char_data('A');
for (size_t row = 0; row < font.height(); ++row) {
for (size_t col = 0; col < font.width(); ++col) {
size_t byte_idx = row * width_bytes + col / 8;
bool pixel = (bitmap[byte_idx] & (0x80 >> (col % 8))) != 0;
// pixel: true = foreground, false = background
}
}
Parameters
cCharacter to retrieve (ASCII 0x20-0x7E)
Returns
Span containing bitmap bytes (size = bytes_per_char()) Returns empty span for unsupported characters
See also
bytes_per_char(), Graphics::draw_text()
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

◆ font12()

auto epaper::Font::font12 ( ) -> const Font &
static

Get 12-pixel font.

Returns
Font reference
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

◆ font16()

auto epaper::Font::font16 ( ) -> const Font &
static

Get 16-pixel font.

Returns
Font reference
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

◆ font20()

auto epaper::Font::font20 ( ) -> const Font &
static

Get 20-pixel font.

Returns
Font reference
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

◆ font24()

auto epaper::Font::font24 ( ) -> const Font &
static

Get 24-pixel font.

Returns
Font reference
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

◆ font8()

auto epaper::Font::font8 ( ) -> const Font &
static

Get 8-pixel font.

Returns
Font reference
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

◆ height()

constexpr auto epaper::Font::height ( ) const -> std::uint16_t
inlineconstexprnoexcept

Get character height in pixels.

Returns
Height
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

◆ metrics()

constexpr auto epaper::Font::metrics ( ) const -> FontMetrics
inlineconstexprnoexcept

Get font dimensions.

Returns
FontMetrics structure
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

◆ width()

constexpr auto epaper::Font::width ( ) const -> std::uint16_t
inlineconstexprnoexcept

Get character width in pixels.

Returns
Width
Examples
/mnt/nas/libepaper/include/epaper/graphics/font.hpp.

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