ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
font.h
Go to the documentation of this file.
1#pragma once
2
6#ifdef USE_DISPLAY
8#endif
9
10namespace esphome {
11namespace font {
12
13class Font;
14
15class Glyph {
16 public:
17 constexpr Glyph(const char *a_char, const uint8_t *data, int advance, int offset_x, int offset_y, int width,
18 int height)
19 : a_char(a_char),
20 data(data),
24 width(width),
25 height(height) {}
26
27 const uint8_t *get_char() const { return reinterpret_cast<const uint8_t *>(this->a_char); }
28
29 bool compare_to(const uint8_t *str) const;
30
31 int match_length(const uint8_t *str) const;
32
33 void scan_area(int *x1, int *y1, int *width, int *height) const;
34
35 const char *a_char;
36 const uint8_t *data;
40 int width;
41 int height;
42
43 protected:
44 friend Font;
45};
46
47class Font
48#ifdef USE_DISPLAY
49 : public display::BaseFont
50#endif
51{
52 public:
64 Font(const Glyph *data, int data_nr, int baseline, int height, int descender, int xheight, int capheight,
65 uint8_t bpp = 1);
66
67 int match_next_glyph(const uint8_t *str, int *match_length) const;
68
69#ifdef USE_DISPLAY
70 void print(int x_start, int y_start, display::Display *display, Color color, const char *text,
71 Color background) override;
72 void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override;
73#endif
74 inline int get_baseline() { return this->baseline_; }
75 inline int get_height() { return this->height_; }
76 inline int get_ascender() { return this->baseline_; }
77 inline int get_descender() { return this->descender_; }
78 inline int get_linegap() { return this->linegap_; }
79 inline int get_xheight() { return this->xheight_; }
80 inline int get_capheight() { return this->capheight_; }
81 inline int get_bpp() { return this->bpp_; }
82
83 const ConstVector<Glyph> &get_glyphs() const { return glyphs_; }
84
85 protected:
93 uint8_t bpp_; // bits per pixel
94};
95
96} // namespace font
97} // namespace esphome
Lightweight read-only view over a const array stored in RODATA (will typically be in flash memory) Av...
Definition helpers.h:118
void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override
Definition font.cpp:74
int get_ascender()
Definition font.h:76
int get_linegap()
Definition font.h:78
int get_xheight()
Definition font.h:79
int get_height()
Definition font.h:75
int get_capheight()
Definition font.h:80
int get_baseline()
Definition font.h:74
const ConstVector< Glyph > & get_glyphs() const
Definition font.h:83
int get_descender()
Definition font.h:77
int match_next_glyph(const uint8_t *str, int *match_length) const
Definition font.cpp:57
uint8_t bpp_
Definition font.h:93
ConstVector< Glyph > glyphs_
Definition font.h:86
Font(const Glyph *data, int data_nr, int baseline, int height, int descender, int xheight, int capheight, uint8_t bpp=1)
Construct the font with the given glyphs.
Definition font.cpp:47
bool compare_to(const uint8_t *str) const
Definition font.cpp:14
const uint8_t * data
Definition font.h:36
constexpr Glyph(const char *a_char, const uint8_t *data, int advance, int offset_x, int offset_y, int width, int height)
Definition font.h:17
void scan_area(int *x1, int *y1, int *width, int *height) const
Definition font.cpp:40
const uint8_t * get_char() const
Definition font.h:27
int match_length(const uint8_t *str) const
Definition font.cpp:30
const char * a_char
Definition font.h:35
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string print()