TinyGPU
Loading...
Searching...
No Matches
IFont.h
Go to the documentation of this file.
1#pragma once
2#include <stddef.h>
3#include <stdint.h>
4#include "TinyGPU/Color/RGB565.h"
5
6namespace tinygpu {
7// Forward declaration to avoid circular dependency
8template <typename RGB_T> class ISurface;
9
10/**
11 * @brief Font rendering interface for TinyGPU-compatible framebuffers.
12 *
13 * @tparam RGB_T The pixel color type. Can be RGB565, RGB666, RGB888, etc.
14 *
15 * Implementations render text onto an ISurface target using their own glyph
16 * storage, layout, and scaling behavior.
17 */
18template <typename RGB_T = RGB565>
19class IFont {
20 public:
21 /// Destroys the font interface.
22 virtual ~IFont() = default;
23
24 /// Draws a text string onto a framebuffer target.
25 virtual void drawText(ISurface<RGB_T>& target, int16_t x, int16_t y,
26 const char* text, RGB_T foreground, RGB_T background,
27 bool opaque = false, uint8_t scale = 1,
28 uint8_t spacing = 1, uint8_t lineSpacing = 1) const = 0;
29
30 /// Returns the width of the longest text line in pixels.
31 virtual size_t measureTextWidth(const char* text, uint8_t scale = 1,
32 uint8_t spacing = 1) const = 0;
33
34 /// Returns the total text height in pixels.
35 virtual size_t measureTextHeight(const char* text, uint8_t scale = 1,
36 uint8_t lineSpacing = 1) const = 0;
37
38 /// Returns the scaled glyph height in pixels.
39 virtual size_t getHeight(uint8_t scale) const = 0;
40
41 /// Enables/disables proportional spacing based on each glyph's effective
42 /// (used) width instead of a fixed glyph width. Implementations that only
43 /// support fixed-width rendering may ignore this.
44 virtual void setProportional(bool proportional) { (void)proportional; }
45 /// Returns whether proportional spacing is enabled.
46 virtual bool isProportional() const { return false; }
47};
48
49} // namespace tinygpu
Font rendering interface for TinyGPU-compatible framebuffers.
Definition: IFont.h:19
virtual void setProportional(bool proportional)
Definition: IFont.h:44
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 bool isProportional() const
Returns whether proportional spacing is enabled.
Definition: IFont.h:46
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 ~IFont()=default
Destroys the font interface.
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 getHeight(uint8_t scale) const =0
Returns the scaled glyph height in pixels.
RGB color stored in 16-bit RGB565 format, byte-swapped from the conventional bit layout.
Definition: RGB565.h:24
Definition: DSIBusESP32.h:19