LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
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
internal int type, used by the library.
Definition: canvas_types.h:79
NanoFont(const uint8_t *progmemFont)
Creates NanoFont object and loads font of fixed type from flash memory.
Definition: font.h:60
const uint8_t * primary_table
font chars bits
Definition: canvas_types.h:134
Structure describes single char information.
Definition: canvas_types.h:141
lcduint_t getTextSize(const char *text, lcduint_t *height=nullptr)
returns text width in pixels (and its height if height is requested)
NanoFont()
Creates empty NanoFont object.
Definition: font.h:53
Structure is used for internal font presentation.
Definition: canvas_types.h:127
NanoFont class implements work with fonts provided by the library: loading fonts, providing their par...
Definition: font.h:45
void setSpacing(uint8_t spacing)
Sets spacing in pixels between 2 nearest characters.
Definition: font.h:152
Basic structures of canvas gfx library.
uint8_t getPages()
Returns how many pages in terms of ssd1306 display are required for the font height.
Definition: font.h:161
static uint16_t unicode16FromUtf8(uint8_t ch)
Returns 16-bit unicode char, encoded in utf8 SSD1306_MORE_CHARS_REQUIRED if more characters is expect...
const SFontHeaderRecord & getHeader()
Returns reference to SFontHeaderRecord.
Definition: font.h:142
SFontHeaderRecord h
record, containing information on font
Definition: canvas_types.h:129
Structure describes font format in memory.
Definition: canvas_types.h:117
void loadFixedFont(const uint8_t *progmemFont)
Function allows to set another fixed font for the library.
void loadSecondaryFont(const uint8_t *progmemUnicode)
Function allows sets secondary font for specific language.
uint8_t spacing
spacing between two characters
Definition: canvas_types.h:133
void loadFreeFont(const uint8_t *progmemFont)
Function allows to set another free font for the library.
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.