ESPHome 2025.9.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
15struct GlyphData {
16 const uint8_t *a_char;
17 const uint8_t *data;
21 int width;
22 int height;
23};
24
25class Glyph {
26 public:
27 Glyph(const GlyphData *data) : glyph_data_(data) {}
28
29 const uint8_t *get_char() const;
30
31 bool compare_to(const uint8_t *str) const;
32
33 int match_length(const uint8_t *str) const;
34
35 void scan_area(int *x1, int *y1, int *width, int *height) const;
36
37 const GlyphData *get_glyph_data() const { return this->glyph_data_; }
38
39 protected:
40 friend Font;
41
43};
44
45class Font
46#ifdef USE_DISPLAY
47 : public display::BaseFont
48#endif
49{
50 public:
62 Font(const GlyphData *data, int data_nr, int baseline, int height, int descender, int xheight, int capheight,
63 uint8_t bpp = 1);
64
65 int match_next_glyph(const uint8_t *str, int *match_length);
66
67#ifdef USE_DISPLAY
68 void print(int x_start, int y_start, display::Display *display, Color color, const char *text,
69 Color background) override;
70 void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override;
71#endif
72 inline int get_baseline() { return this->baseline_; }
73 inline int get_height() { return this->height_; }
74 inline int get_ascender() { return this->baseline_; }
75 inline int get_descender() { return this->descender_; }
76 inline int get_linegap() { return this->linegap_; }
77 inline int get_xheight() { return this->xheight_; }
78 inline int get_capheight() { return this->capheight_; }
79 inline int get_bpp() { return this->bpp_; }
80
81 const std::vector<Glyph, RAMAllocator<Glyph>> &get_glyphs() const { return glyphs_; }
82
83 protected:
84 std::vector<Glyph, RAMAllocator<Glyph>> glyphs_;
91 uint8_t bpp_; // bits per pixel
92};
93
94} // namespace font
95} // namespace esphome
void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override
Definition font.cpp:78
int get_ascender()
Definition font.h:74
int get_linegap()
Definition font.h:76
int get_xheight()
Definition font.h:77
int get_height()
Definition font.h:73
const std::vector< Glyph, RAMAllocator< Glyph > > & get_glyphs() const
Definition font.h:81
int get_capheight()
Definition font.h:78
int get_baseline()
Definition font.h:72
Font(const GlyphData *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:48
int match_next_glyph(const uint8_t *str, int *match_length)
Definition font.cpp:61
int get_descender()
Definition font.h:75
uint8_t bpp_
Definition font.h:91
std::vector< Glyph, RAMAllocator< Glyph > > glyphs_
Definition font.h:84
const GlyphData * glyph_data_
Definition font.h:42
bool compare_to(const uint8_t *str) const
Definition font.cpp:15
void scan_area(int *x1, int *y1, int *width, int *height) const
Definition font.cpp:41
const uint8_t * get_char() const
Definition font.cpp:12
int match_length(const uint8_t *str) const
Definition font.cpp:31
const GlyphData * get_glyph_data() const
Definition font.h:37
Glyph(const GlyphData *data)
Definition font.h:27
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
const uint8_t * data
Definition font.h:17
const uint8_t * a_char
Definition font.h:16
std::string print()