LCDGFX LCD display driver  1.1.5
This library is developed to control SSD1306/SSD1325/SSD1327/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
font.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2019-2020, Alexey Dynda
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23 */
28 #ifndef _NANO_FONT_H_
29 #define _NANO_FONT_H_
30 
31 #include "canvas_types.h"
32 
39 #define SSD1306_MORE_CHARS_REQUIRED 0xffff
40 
45 class NanoFont
46 {
47 public:
54  {
55  }
56 
60  explicit NanoFont(const uint8_t *progmemFont)
61  {
62  loadFixedFont(progmemFont);
63  }
64 
71  void loadFixedFont(const uint8_t *progmemFont);
72 
79  void loadFreeFont(const uint8_t *progmemFont);
80 
88  void loadSecondaryFont(const uint8_t *progmemUnicode);
89 
90 #ifndef DOXYGEN_SHOULD_SKIP_THIS
91  void loadFixedFont_oldStyle(const uint8_t *progmemFont);
92 #endif
93 
94 #ifndef DOXYGEN_SHOULD_SKIP_THIS
95 
100  void loadSquixFont(const uint8_t *progmemFont);
101 #endif
102 
117  void getCharBitmap(uint16_t ch, SCharInfo *info);
118 
127  lcduint_t getTextSize(const char *text, lcduint_t *height = nullptr);
128 
136  static uint16_t unicode16FromUtf8(uint8_t ch);
137 
143  {
144  return m_fixedFont.h;
145  }
146 
152  void setSpacing(uint8_t spacing)
153  {
154  m_fixedFont.spacing = spacing;
155  }
156 
161  uint8_t getPages()
162  {
163  return m_fixedFont.pages;
164  }
165 
166 #ifndef DOXYGEN_SHOULD_SKIP_THIS
167  const uint8_t *getPrimaryTable()
168  {
169  return m_fixedFont.primary_table;
170  }
171 #endif
172 
173 private:
174  SFixedFontInfo m_fixedFont{};
175 
176  void (*m_getCharBitmap)(const SFixedFontInfo &font, uint16_t unicode, SCharInfo *info) = nullptr;
177 };
178 
179 extern NanoFont g_canvas_font;
180 
185 #endif
uint8_t lcduint_t
Definition: canvas_types.h:79
NanoFont(const uint8_t *progmemFont)
Definition: font.h:60
const uint8_t * primary_table
font chars bits
Definition: canvas_types.h:134
lcduint_t getTextSize(const char *text, lcduint_t *height=nullptr)
returns text width in pixels (and its height if height is requested)
NanoFont()
Definition: font.h:53
Definition: font.h:45
void setSpacing(uint8_t spacing)
Definition: font.h:152
uint8_t getPages()
Definition: font.h:161
static uint16_t unicode16FromUtf8(uint8_t ch)
const SFontHeaderRecord & getHeader()
Definition: font.h:142
SFontHeaderRecord h
record, containing information on font
Definition: canvas_types.h:129
void loadFixedFont(const uint8_t *progmemFont)
void loadSecondaryFont(const uint8_t *progmemUnicode)
uint8_t spacing
spacing between two characters
Definition: canvas_types.h:133
void loadFreeFont(const uint8_t *progmemFont)
uint8_t pages
height in pages (each page height is 8-pixels)
Definition: canvas_types.h:131
void getCharBitmap(uint16_t ch, SCharInfo *info)
returns char data for currently set (active) font.