ESPHome 2025.5.0
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:
57 Font(const GlyphData *data, int data_nr, int baseline, int height, uint8_t bpp = 1);
58
59 int match_next_glyph(const uint8_t *str, int *match_length);
60
61#ifdef USE_DISPLAY
62 void print(int x_start, int y_start, display::Display *display, Color color, const char *text,
63 Color background) override;
64 void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override;
65#endif
66 inline int get_baseline() { return this->baseline_; }
67 inline int get_height() { return this->height_; }
68 inline int get_bpp() { return this->bpp_; }
69
70 const std::vector<Glyph, ExternalRAMAllocator<Glyph>> &get_glyphs() const { return glyphs_; }
71
72 protected:
73 std::vector<Glyph, ExternalRAMAllocator<Glyph>> glyphs_;
76 uint8_t bpp_; // bits per pixel
77};
78
79} // namespace font
80} // namespace esphome
void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override
Definition font.cpp:71
std::vector< Glyph, ExternalRAMAllocator< Glyph > > glyphs_
Definition font.h:73
const std::vector< Glyph, ExternalRAMAllocator< Glyph > > & get_glyphs() const
Definition font.h:70
int get_height()
Definition font.h:67
int get_baseline()
Definition font.h:66
Font(const GlyphData *data, int data_nr, int baseline, int height, 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:54
uint8_t bpp_
Definition font.h:76
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()