LcdFont.h
Go to the documentation of this file.
1 /****
2  * glcdfont.cpp
3  *
4  * This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
5  *
6  * See https://github.com/adafruit/Adafruit-GFX-Library
7  *
8  ****/
9 
10 #pragma once
11 
12 #include "Object.h"
13 
14 namespace Graphics
15 {
16 class LcdGlyph : public GlyphObject
17 {
18 public:
19  static constexpr Size rawSize{5, 8};
20  static constexpr Metrics metrics{
21  .width = rawSize.w + 1,
22  .height = rawSize.h,
23  .xOffset = 0,
24  .yOffset = rawSize.h,
25  .advance = rawSize.w + 1,
26  };
27 
28  LcdGlyph(size_t bmOffset, const Options& options);
29 
30  bool init() override
31  {
32  return true;
33  }
34 
35  Bits getBits(uint16_t row) const override
36  {
37  return rowBits[row].to_ulong();
38  }
39 
40  void readAlpha(void* buffer, Point origin, size_t stride) const override;
41 
42 private:
43  PackedColor clFore;
44  PackedColor clBack;
45  uint8_t scale;
46  std::bitset<rawSize.w> rowBits[rawSize.h];
47 };
48 
49 class LcdTypeFace : public TypeFace
50 {
51 public:
52  FontStyles getStyle() const override
53  {
54  return 0;
55  }
56 
57  uint8_t height() const override
58  {
60  }
61 
62  uint8_t descent() const override
63  {
64  return 1;
65  }
66 
67  GlyphObject::Metrics getMetrics(char ch) const override
68  {
69  (void)ch;
70  return LcdGlyph::metrics;
71  }
72 
73  GlyphObject* getGlyph(char ch, const GlyphObject::Options& options) const override;
74 };
75 
76 class LcdFont : public Font
77 {
78 public:
79  String name() const override
80  {
81  return F("glcdfont");
82  }
83 
84  uint16_t height() const override
85  {
87  }
88 
89  const TypeFace* getFace(FontStyles style) const
90  {
91  (void)style;
92  return &typeface;
93  }
94 
95 private:
96  LcdTypeFace typeface;
97 };
98 
99 extern LcdFont lcdFont;
100 
101 } // namespace Graphics
uint8_t descent() const override
Definition: LcdFont.h:69
uint16_t w
Definition: Libraries/Graphics/src/include/Graphics/Types.h:125
Base class for a loaded font.
Definition: Asset.h:590
A character glyph image.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:870
static constexpr Size rawSize
Definition: LcdFont.h:33
void readAlpha(void *buffer, Point origin, size_t stride) const override
Obtain glyph information as block of 8-bit alpha values.
The String class.
Definition: WString.h:136
uint8_t height() const override
Get height of typeface, same for all characters.
Definition: LcdFont.h:64
TextOptions Options
Definition: Libraries/Graphics/src/include/Graphics/Object.h:874
LcdFont lcdFont
LcdGlyph(size_t bmOffset, const Options &options)
Definition: LcdFont.h:83
std::bitset< 64 > Bits
Definition: Libraries/Graphics/src/include/Graphics/Object.h:873
String name() const override
Definition: LcdFont.h:86
Definition: Asset.h:471
GlyphMetrics Metrics
Definition: Libraries/Graphics/src/include/Graphics/Object.h:875
Definition: Virtual.h:30
uint16_t h
Definition: Libraries/Graphics/src/include/Graphics/Types.h:126
Options options
Definition: Libraries/Graphics/src/include/Graphics/Object.h:914
uint8_t width
Width of glyph.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:858
Glyph metrics.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:857
FontStyles getStyle() const override
Style of this typeface (bold, italic, etc.)
Definition: LcdFont.h:59
Base class for a loaded typeface, e.g. Sans 16pt bold.
Definition: Asset.h:524
#define F(string_literal)
Wrap a string literal stored in flash and access it using a String object.
Definition: WString.h:113
Bits getBits(uint16_t row) const override
Definition: LcdFont.h:49
uint16_t height() const override
Definition: LcdFont.h:91
GlyphObject::Metrics getMetrics(char ch) const override
Get metrics for a character.
Definition: LcdFont.h:74
static constexpr Metrics metrics
Definition: LcdFont.h:34
bool init() override
Initialise the object, e.g. parse header content and obtain dimensions.
Definition: LcdFont.h:44
Colour in device pixel format.
Definition: Colors.h:339
Definition: LcdFont.h:56
const TypeFace * getFace(FontStyles style) const
Definition: LcdFont.h:96
GlyphObject * getGlyph(char ch, const GlyphObject::Options &options) const override
Get the glyph for a character.