COSA
An Object-Oriented Platform for Arduino Programming
Font.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_FONT_HH
22 #define COSA_FONT_HH
23 
24 #include "Cosa/Types.h"
25 #include "Canvas.hh"
26 
27 /*
28  * Bitmap font library handler.
29  */
30 class Font {
31 public:
35  const uint8_t WIDTH;
36  const uint8_t HEIGHT;
37  const uint8_t SPACING;
38  uint8_t LINE_SPACING;
39 
43  const uint8_t FIRST;
44  const uint8_t LAST;
45 
57  Font(uint8_t width, uint8_t height,
58  uint8_t first, uint8_t last,
59  const uint8_t* bitmap,
60  uint8_t compression_type = 0,
61  uint8_t spacing = 1, uint8_t line_spacing = 1) :
62  WIDTH(width),
63  HEIGHT(height),
64  SPACING(spacing),
65  LINE_SPACING(line_spacing),
66  FIRST(first),
67  LAST(last),
68  m_bitmap(bitmap),
69  m_compression_type(compression_type)
70  {
71  }
72 
79  bool available(char c)
80  __attribute__((always_inline))
81  {
82  return (c >= FIRST && c <= LAST);
83  }
84 
94  virtual void draw(Canvas* canvas, char c, uint16_t x, uint16_t y,
95  uint8_t scale);
96 
108  class Glyph {
109  public:
110  Glyph(Font* font, char c = ' ') :
111  m_font(font),
112  m_char(c)
113  {
114  begin(c);
115  }
116 
122  void begin(char c);
123 
129  uint8_t next();
130 
131  protected:
133  char m_char;
134  uint8_t m_offset;
135  uint8_t m_flags;
136  uint8_t* m_bitset; // in progmem
137  uint8_t* m_bitmap; // in progmem
138  uint8_t m_next;
139  };
140 
141 protected:
143  const uint8_t* m_bitmap;
144 
146  const uint8_t m_compression_type;
147 };
148 
149 #endif
Definition: Font.hh:30
const uint8_t LAST
Definition: Font.hh:44
Glyph(Font *font, char c= ' ')
Definition: Font.hh:110
const uint8_t * m_bitmap
Definition: Font.hh:143
uint8_t next()
Definition: Font.cpp:110
const uint8_t SPACING
Definition: Font.hh:37
uint8_t * m_bitmap
Definition: Font.hh:137
const uint8_t WIDTH
Definition: Font.hh:35
const uint8_t HEIGHT
Definition: Font.hh:36
uint8_t LINE_SPACING
Definition: Font.hh:38
uint8_t * m_bitset
Definition: Font.hh:136
bool available(char c)
Definition: Font.hh:79
const uint8_t FIRST
Definition: Font.hh:43
Font * m_font
Definition: Font.hh:132
uint8_t m_next
Definition: Font.hh:138
uint8_t m_offset
Definition: Font.hh:134
Font(uint8_t width, uint8_t height, uint8_t first, uint8_t last, const uint8_t *bitmap, uint8_t compression_type=0, uint8_t spacing=1, uint8_t line_spacing=1)
Definition: Font.hh:57
virtual void draw(Canvas *canvas, char c, uint16_t x, uint16_t y, uint8_t scale)
Definition: Font.cpp:24
uint8_t m_flags
Definition: Font.hh:135
char m_char
Definition: Font.hh:133
Definition: Canvas.hh:44
void begin(char c)
Definition: Font.cpp:63
const uint8_t m_compression_type
Definition: Font.hh:146