ESPHome  2024.6.6
font.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/color.h"
6 
7 namespace esphome {
8 namespace font {
9 
10 class Font;
11 
12 struct GlyphData {
13  const uint8_t *a_char;
14  const uint8_t *data;
15  int offset_x;
16  int offset_y;
17  int width;
18  int height;
19 };
20 
21 class Glyph {
22  public:
23  Glyph(const GlyphData *data) : glyph_data_(data) {}
24 
25  const uint8_t *get_char() const;
26 
27  bool compare_to(const uint8_t *str) const;
28 
29  int match_length(const uint8_t *str) const;
30 
31  void scan_area(int *x1, int *y1, int *width, int *height) const;
32 
33  const GlyphData *get_glyph_data() const { return this->glyph_data_; }
34 
35  protected:
36  friend Font;
37 
39 };
40 
41 class Font : public display::BaseFont {
42  public:
49  Font(const GlyphData *data, int data_nr, int baseline, int height, uint8_t bpp = 1);
50 
51  int match_next_glyph(const uint8_t *str, int *match_length);
52 
53  void print(int x_start, int y_start, display::Display *display, Color color, const char *text,
54  Color background) override;
55  void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override;
56  inline int get_baseline() { return this->baseline_; }
57  inline int get_height() { return this->height_; }
58  inline int get_bpp() { return this->bpp_; }
59 
60  const std::vector<Glyph, ExternalRAMAllocator<Glyph>> &get_glyphs() const { return glyphs_; }
61 
62  protected:
63  std::vector<Glyph, ExternalRAMAllocator<Glyph>> glyphs_;
64  int baseline_;
65  int height_;
66  uint8_t bpp_; // bits per pixel
67 };
68 
69 } // namespace font
70 } // namespace esphome
const uint8_t * a_char
Definition: font.h:13
int get_baseline()
Definition: font.h:56
uint8_t bpp_
Definition: font.h:66
const GlyphData * get_glyph_data() const
Definition: font.h:33
Glyph(const GlyphData *data)
Definition: font.h:23
const std::vector< Glyph, ExternalRAMAllocator< Glyph > > & get_glyphs() const
Definition: font.h:60
int get_height()
Definition: font.h:57
const uint8_t * data
Definition: font.h:14
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
const GlyphData * glyph_data_
Definition: font.h:38
int get_bpp()
Definition: font.h:58
std::vector< Glyph, ExternalRAMAllocator< Glyph > > glyphs_
Definition: font.h:63