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  std::bitset<rawSize.w> rowBits[rawSize.h];
44 };
45 
46 class LcdTypeFace : public TypeFace
47 {
48 public:
49  FontStyles getStyle() const override
50  {
51  return 0;
52  }
53 
54  uint8_t height() const override
55  {
56  return LcdGlyph::rawSize.h;
57  }
58 
59  uint8_t descent() const override
60  {
61  return 1;
62  }
63 
64  GlyphObject::Metrics getMetrics(char ch) const override
65  {
66  (void)ch;
67  return LcdGlyph::metrics;
68  }
69 
70  std::unique_ptr<GlyphObject> getGlyph(char ch, const GlyphObject::Options& options) const override;
71 };
72 
73 class LcdFont : public Font
74 {
75 public:
76  String name() const override
77  {
78  return F("glcdfont");
79  }
80 
81  uint16_t height() const override
82  {
83  return LcdGlyph::rawSize.h;
84  }
85 
86  const TypeFace* getFace(FontStyles style) const
87  {
88  (void)style;
89  return &typeface;
90  }
91 
92 private:
93  LcdTypeFace typeface;
94 };
95 
96 extern LcdFont lcdFont;
97 
98 } // namespace Graphics
#define F(string_literal)
Wrap a string literal stored in flash and access it using a String object.
Definition: WString.h:113
Base class for a loaded font.
Definition: Asset.h:572
A character glyph image.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:850
std::bitset< 64 > Bits
Definition: Libraries/Graphics/src/include/Graphics/Object.h:852
Options options
Definition: Libraries/Graphics/src/include/Graphics/Object.h:893
Definition: LcdFont.h:74
uint16_t height() const override
Definition: LcdFont.h:81
String name() const override
Definition: LcdFont.h:76
const TypeFace * getFace(FontStyles style) const
Definition: LcdFont.h:86
Definition: LcdFont.h:17
static constexpr Metrics metrics
Definition: LcdFont.h:20
void readAlpha(void *buffer, Point origin, size_t stride) const override
Obtain glyph information as block of 8-bit alpha values.
bool init() override
Initialise the object, e.g. parse header content and obtain dimensions.
Definition: LcdFont.h:30
Bits getBits(uint16_t row) const override
Definition: LcdFont.h:35
static constexpr Size rawSize
Definition: LcdFont.h:19
LcdGlyph(size_t bmOffset, const Options &options)
Definition: LcdFont.h:47
GlyphObject::Metrics getMetrics(char ch) const override
Get metrics for a character.
Definition: LcdFont.h:64
FontStyles getStyle() const override
Style of this typeface (bold, italic, etc.)
Definition: LcdFont.h:49
std::unique_ptr< GlyphObject > getGlyph(char ch, const GlyphObject::Options &options) const override
Get the glyph for a character.
uint8_t height() const override
Get height of typeface, same for all characters.
Definition: LcdFont.h:54
uint8_t descent() const override
Definition: LcdFont.h:59
Definition: Asset.h:453
Base class for a loaded typeface, e.g. Sans 16pt bold.
Definition: Asset.h:506
The String class.
Definition: WString.h:137
Definition: Virtual.h:31
LcdFont lcdFont
Glyph metrics.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:838
uint8_t width
Width of glyph.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:839
Size of rectangular area (width x height)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:105
uint16_t w
Definition: Libraries/Graphics/src/include/Graphics/Types.h:106
uint16_t h
Definition: Libraries/Graphics/src/include/Graphics/Types.h:107