ESPHome  2024.11.1
font.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/color.h"
5 #include "esphome/core/defines.h"
6 #ifdef USE_DISPLAY
8 #endif
9 
10 namespace esphome {
11 namespace font {
12 
13 class Font;
14 
15 struct GlyphData {
16  const uint8_t *a_char;
17  const uint8_t *data;
18  int offset_x;
19  int offset_y;
20  int width;
21  int height;
22 };
23 
24 class Glyph {
25  public:
26  Glyph(const GlyphData *data) : glyph_data_(data) {}
27 
28  const uint8_t *get_char() const;
29 
30  bool compare_to(const uint8_t *str) const;
31 
32  int match_length(const uint8_t *str) const;
33 
34  void scan_area(int *x1, int *y1, int *width, int *height) const;
35 
36  const GlyphData *get_glyph_data() const { return this->glyph_data_; }
37 
38  protected:
39  friend Font;
40 
42 };
43 
44 class Font
45 #ifdef USE_DISPLAY
46  : public display::BaseFont
47 #endif
48 {
49  public:
56  Font(const GlyphData *data, int data_nr, int baseline, int height, uint8_t bpp = 1);
57 
58  int match_next_glyph(const uint8_t *str, int *match_length);
59 
60 #ifdef USE_DISPLAY
61  void print(int x_start, int y_start, display::Display *display, Color color, const char *text,
62  Color background) override;
63  void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override;
64 #endif
65  inline int get_baseline() { return this->baseline_; }
66  inline int get_height() { return this->height_; }
67  inline int get_bpp() { return this->bpp_; }
68 
69  const std::vector<Glyph, ExternalRAMAllocator<Glyph>> &get_glyphs() const { return glyphs_; }
70 
71  protected:
72  std::vector<Glyph, ExternalRAMAllocator<Glyph>> glyphs_;
73  int baseline_;
74  int height_;
75  uint8_t bpp_; // bits per pixel
76 };
77 
78 } // namespace font
79 } // namespace esphome
std::vector< Glyph, ExternalRAMAllocator< Glyph > > glyphs_
Definition: font.h:72
const uint8_t * a_char
Definition: font.h:16
const std::vector< Glyph, ExternalRAMAllocator< Glyph > > & get_glyphs() const
Definition: font.h:69
const GlyphData * get_glyph_data() const
Definition: font.h:36
Glyph(const GlyphData *data)
Definition: font.h:26
const uint8_t * data
Definition: font.h:17
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
const GlyphData * glyph_data_
Definition: font.h:41