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
font.hpp
Go to the documentation of this file.
1#pragma once
2
75#include <cstddef>
76#include <cstdint>
77#include <span>
78
79namespace epaper {
80
100 std::uint16_t width;
101 std::uint16_t height;
102};
103
142class Font {
143public:
175 constexpr Font(const std::uint8_t *table, std::uint16_t width, std::uint16_t height)
176 : table_(table), width_(width), height_(height) {}
177
182 [[nodiscard]] constexpr auto metrics() const noexcept -> FontMetrics { return {.width = width_, .height = height_}; }
183
188 [[nodiscard]] constexpr auto width() const noexcept -> std::uint16_t { return width_; }
189
194 [[nodiscard]] constexpr auto height() const noexcept -> std::uint16_t { return height_; }
195
234 [[nodiscard]] auto char_data(char c) const -> std::span<const std::uint8_t>;
235
261 [[nodiscard]] constexpr auto bytes_per_char() const noexcept -> std::size_t {
262 const auto width_bytes = static_cast<std::size_t>((width_ % 8 == 0) ? (width_ / 8) : ((width_ / 8) + 1));
263 return width_bytes * static_cast<std::size_t>(height_);
264 }
265
266 // Factory methods for built-in fonts
271 static auto font8() -> const Font &;
272
277 static auto font12() -> const Font &;
278
283 static auto font16() -> const Font &;
284
289 static auto font20() -> const Font &;
290
295 static auto font24() -> const Font &;
296
297private:
298 const std::uint8_t *table_;
299 std::uint16_t width_;
300 std::uint16_t height_;
301};
302
303} // namespace epaper
Definition font.hpp:142
constexpr auto height() const noexcept -> std::uint16_t
Get character height in pixels.
Definition font.hpp:194
auto char_data(char c) const -> std::span< const std::uint8_t >
Get bitmap data for a specific character.
Definition font.cpp:11
constexpr auto width() const noexcept -> std::uint16_t
Get character width in pixels.
Definition font.hpp:188
static auto font8() -> const Font &
Get 8-pixel font.
Definition font.cpp:40
static auto font24() -> const Font &
Get 24-pixel font.
Definition font.cpp:64
static auto font12() -> const Font &
Get 12-pixel font.
Definition font.cpp:46
static auto font16() -> const Font &
Get 16-pixel font.
Definition font.cpp:52
constexpr auto bytes_per_char() const noexcept -> std::size_t
Calculate storage size for a single character.
Definition font.hpp:261
constexpr auto metrics() const noexcept -> FontMetrics
Get font dimensions.
Definition font.hpp:182
static auto font20() -> const Font &
Get 20-pixel font.
Definition font.cpp:58
constexpr Font(const std::uint8_t *table, std::uint16_t width, std::uint16_t height)
Definition font.hpp:175
Definition color.hpp:5
Font dimension metrics.
Definition font.hpp:99
std::uint16_t height
Definition font.hpp:101
std::uint16_t width
Definition font.hpp:100