Text of api-docs-dev.esphome.io › font_8h_source as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

ESPHome: esphome/components/font/font.h Source File

ESPHome 2026.12.0-dev Loading... Searching... No Matches esphome components font font.h Go to the documentation of this file. 1 #pragma once 2 3 #include <type_traits> 4 5 #include " esphome/core/color.h " 6 #include " esphome/core/datatypes.h " 7 #include " esphome/core/defines.h " 8 #ifdef USE_DISPLAY 9 #include " esphome/components/display/display.h " 10 #endif 11 #ifdef USE_LVGL_FONT 12 #include <lvgl.h> 13 #endif 14 15 namespace esphome::font { 16 17 class Font; 18 19 class Glyph final { 20 public : 21 constexpr Glyph ( uint32_t code_point , const uint8_t * data , int advance , int offset_x , int offset_y , int width , 22 int height ) 23 : code_point ( code_point ), 24 data ( data ), 25 advance ( advance ), 26 offset_x ( offset_x ), 27 offset_y ( offset_y ), 28 width ( width ), 29 height ( height ) {} 30 31 bool is_less_or_equal ( uint32_t other) const { return this-> code_point <= other; } 32 33 const uint32_t code_point ; 34 const uint8_t * data ; 35 int advance ; 36 int offset_x ; 37 int offset_y ; 38 int width ; 39 int height ; 40 }; 41 // The glyph table lives in flash, read with plain loads, which ESP8266 only allows for whole words.

42 static_assert (std::is_same_v< decltype ( Glyph::code_point ), const uint32_t >, "Glyph fields must stay word sized" ); 43 static_assert (std::is_same_v< decltype ( Glyph::data ), const uint8_t *>, "Glyph fields must stay word sized" ); 44 static_assert (std::is_same_v< decltype ( Glyph::advance ), int >, "Glyph fields must stay word sized" ); 45 static_assert (std::is_same_v< decltype ( Glyph::offset_x ), int >, "Glyph fields must stay word sized" ); 46 static_assert (std::is_same_v< decltype ( Glyph::offset_y ), int >, "Glyph fields must stay word sized" ); 47 static_assert (std::is_same_v< decltype ( Glyph::width ), int >, "Glyph fields must stay word sized" ); 48 static_assert (std::is_same_v< decltype ( Glyph::height ), int >, "Glyph fields must stay word sized" ); 49 #ifdef USE_ESP8266 50 static_assert ( alignof ( Glyph ) == sizeof ( uint32_t ), "Glyph fields must stay word sized" ); 51 static_assert ( sizeof ( Glyph ) == 7 * sizeof ( uint32_t ), "Glyph is read from flash with word loads" ); 52 #endif 53 54 class Font final 55 #ifdef USE_DISPLAY 56 : public display::BaseFont 57 #endif 58 { 59 public : 71 Font ( const Glyph *data, int data_nr, int baseline, int height, int descender, int xheight, int capheight, 72 uint8_t bpp = 1); 73 74 const Glyph * find_glyph ( uint32_t codepoint) const ; 75 76 #ifdef USE_DISPLAY 77 void print ( int x_start, int y_start, display::Display *display, Color color, const char *text, 78 Color background) override ; 79 void measure ( const char *str, int *width, int *x_offset, int *baseline, int *height) override ; 80 #endif 81 inline int get_baseline () { return this-> baseline_ ; } 82 inline int get_height () { return this-> height_ ; } 83 inline int get_ascender () { return this-> baseline_ ; } 84 inline int get_descender () { return this-> descender_ ; } 85 inline int get_linegap () { return this-> linegap_ ; } 86 inline int get_xheight () { return this-> xheight_ ; } 87 inline int get_capheight () { return this-> capheight_ ; } 88 inline int get_bpp () { return this-> bpp_ ; } 89 #ifdef USE_LVGL_FONT 90 const lv_font_t * get_lv_font () const { return &this-> lv_font_ ; } 91 #endif 92 93 const ConstVector<Glyph> & get_glyphs () const { return glyphs_ ; } 94 95 protected : 96 ConstVector<Glyph> glyphs_ ; 97 int baseline_ ; 98 int height_ ; 99 int descender_ ; 100 int linegap_ ; 101 int xheight_ ; 102 int capheight_ ; 103 uint8_t bpp_ ; // bits per pixel 104 #ifdef USE_LVGL_FONT 105 lv_font_t lv_font_ {}; 106 static const void * get_glyph_bitmap (lv_font_glyph_dsc_t *dsc, lv_draw_buf_t *draw_buf); 107 static bool get_glyph_dsc_cb ( const lv_font_t *font, lv_font_glyph_dsc_t *dsc, uint32_t unicode_letter, uint32_t next ); 108 const Glyph * get_glyph_data_ ( uint32_t unicode_letter); 109 uint32_t last_letter_ {}; 110 const Glyph * last_data_ {}; 111 #endif 112 }; 113 114 } // namespace esphome::font esphome::ConstVector Lightweight read-only view over a const array stored in RODATA (will typically be in flash memory).

Definition helpers.h:150 esphome::display::BaseFont Definition display.h:324 esphome::display::Display Definition display.h:330 esphome::font::Font Definition font.h:58 esphome::font::Font::lv_font_ lv_font_t lv_font_ Definition font.h:105 esphome::font::Font::measure void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override Definition font.cpp:165 esphome::font::Font::find_glyph const Glyph * find_glyph(uint32_t codepoint) const Definition font.cpp:147 esphome::font::Font::get_ascender int get_ascender() Definition font.h:83 esphome::font::Font::get_linegap int get_linegap() Definition font.h:85 esphome::font::Font::get_glyph_dsc_cb static bool get_glyph_dsc_cb(const lv_font_t *font, lv_font_glyph_dsc_t *dsc, uint32_t unicode_letter, uint32_t next) Definition font.cpp:95 esphome::font::Font::get_xheight int get_xheight() Definition font.h:86 esphome::font::Font::get_bpp int get_bpp() Definition font.h:88 esphome::font::Font::linegap_ int linegap_ Definition font.h:100 esphome::font::Font::xheight_ int xheight_ Definition font.h:101 esphome::font::Font::get_height int get_height() Definition font.h:82 esphome::font::Font::height_ int height_ Definition font.h:98 esphome::font::Font::get_capheight int get_capheight() Definition font.h:87 esphome::font::Font::last_letter_ uint32_t last_letter_ Definition font.h:109 esphome::font::Font::get_glyph_data_ const Glyph * get_glyph_data_(uint32_t unicode_letter) Definition font.cpp:112 esphome::font::Font::get_baseline int get_baseline() Definition font.h:81 esphome::font::Font::get_glyphs const ConstVector< Glyph > & get_glyphs() const Definition font.h:93 esphome::font::Font::last_data_ const Glyph * last_data_ Definition font.h:110 esphome::font::Font::get_glyph_bitmap static const void * get_glyph_bitmap(lv_font_glyph_dsc_t *dsc, lv_draw_buf_t *draw_buf) Definition font.cpp:16 esphome::font::Font::get_descender int get_descender() Definition font.h:84 esphome::font::Font::get_lv_font const lv_font_t * get_lv_font() const Definition font.h:90 esphome::font::Font::bpp_ uint8_t bpp_ Definition font.h:103 esphome::font::Font::glyphs_ ConstVector< Glyph > glyphs_ Definition font.h:96 esphome::font::Font::descender_ int descender_ Definition font.h:99 esphome::font::Font::Font 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:125 esphome::font::Font::capheight_ int capheight_ Definition font.h:102 esphome::font::Font::baseline_ int baseline_ Definition font.h:97 esphome::font::Glyph Definition font.h:19 esphome::font::Glyph::height int height Definition font.h:39 esphome::font::Glyph::data const uint8_t * data Definition font.h:34 esphome::font::Glyph::is_less_or_equal bool is_less_or_equal(uint32_t other) const Definition font.h:31 esphome::font::Glyph::offset_y int offset_y Definition font.h:37 esphome::font::Glyph::advance int advance Definition font.h:35 esphome::font::Glyph::width int width Definition font.h:38 esphome::font::Glyph::code_point const uint32_t code_point Definition font.h:33 esphome::font::Glyph::Glyph constexpr Glyph(uint32_t code_point, const uint8_t *data, int advance, int offset_x, int offset_y, int width, int height) Definition font.h:21 esphome::font::Glyph::offset_x int offset_x Definition font.h:36 color.h datatypes.h defines.h display.h next NameCopy * next Definition entity_base.cpp:19 esphome::font Definition font.cpp:8 uint32_t static void uint32_t Definition crash_handler.cpp:179 esphome::Color Definition color.h:34 print std::string print() Definition tormatic_protocol.h:14 Generated by 1.12.0