Rev 13 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 13 | Rev 17 | ||
|---|---|---|---|
| Line 3... | Line 3... | ||
| 3 | #include <cstdint> |
3 | #include <cstdint> |
| 4 | 4 | ||
| 5 | class font_t |
5 | class font_t |
| 6 | { |
6 | { |
| 7 | public: |
7 | public: |
| - | 8 | ||
| - | 9 | ||
| 8 | /// \param height - pixel character height |
10 | /// \param height - pixel character height |
| 9 | /// \param width - pixel character width |
11 | /// \param width - pixel character width |
| 10 | /// \param spacing - character to character spacing |
12 | /// \param spacing - character to character spacing |
| 11 | /// \param chars - number of characters in character set |
13 | /// \param chars - number of characters in character set |
| 12 | /// \param data - constant data |
14 | /// \param data - constant data |
| - | 15 | /// \param mult - coordinate multiplied by before sampling bitmap |
|
| - | 16 | /// \param shift- coordinate right shifted by after multiplication : mult=1, shift=1 means half sized |
|
| 13 | font_t(uint8_t const height, uint8_t const width, |
17 | font_t(uint8_t const height, uint8_t const width, |
| 14 | uint8_t const spacing, uint8_t const chars, |
18 | uint8_t const spacing, uint8_t const chars, |
| - | 19 | char const *data, |
|
| 15 | char const *data) : m_height(height), m_width(width), m_spacing(spacing), m_chars(chars), m_data(data) |
20 | uint8_t const mult, uint8_t const shift) |
| - | 21 | : m_height(height), |
|
| - | 22 | m_width(width), |
|
| - | 23 | m_mapheight(PIXELS(height,mult,shift)), |
|
| - | 24 | m_mapwidth(PIXELS(width,mult,shift)), |
|
| - | 25 | m_spacing(PIXELS(spacing,mult,shift)), |
|
| - | 26 | m_chars(chars), |
|
| - | 27 | m_data(data), |
|
| - | 28 | m_mult(mult), |
|
| - | 29 | m_shift(shift), |
|
| - | 30 | m_round(ROUNDING(shift)) |
|
| 16 | { |
31 | { |
| 17 | } |
32 | } |
| 18 | 33 | ||
| 19 | virtual char |
34 | virtual char |
| 20 | getPixel(char c, int x, int y) = 0; |
35 | getPixel(char c, int x, int y) = 0; |
| 21 | 36 | ||
| 22 | // character width |
37 | // character width |
| 23 | uint8_t |
38 | uint8_t |
| 24 | width() |
39 | width() |
| 25 | { |
40 | { |
| 26 | return m_width; |
41 | return m_mapwidth; |
| 27 | } |
42 | } |
| 28 | 43 | ||
| 29 | // character height |
44 | // character height |
| 30 | uint8_t |
45 | uint8_t |
| 31 | height() |
46 | height() |
| 32 | { |
47 | { |
| 33 | return m_height; |
48 | return m_mapheight; |
| 34 | } |
49 | } |
| 35 | 50 | ||
| 36 | uint8_t |
51 | uint8_t |
| 37 | chars() |
52 | chars() |
| 38 | { |
53 | { |
| Line 43... | Line 58... | ||
| 43 | spacing() |
58 | spacing() |
| 44 | { |
59 | { |
| 45 | return m_spacing; |
60 | return m_spacing; |
| 46 | } |
61 | } |
| 47 | 62 | ||
| - | 63 | private: |
|
| - | 64 | ||
| - | 65 | /// @brief Convert from real bitmap dimension to virtual dimension given |
|
| - | 66 | /// @param dimension original dimension |
|
| - | 67 | /// @param mult scale up multiplier |
|
| - | 68 | /// @param shift bit shift right after scaling |
|
| - | 69 | /// @return virtual dimension |
|
| - | 70 | static constexpr unsigned PIXELS(uint8_t dimension,uint8_t mult, uint8_t shift) { return (dimension << shift )/mult; }; |
|
| - | 71 | ||
| - | 72 | /// @brief Calculate a rounding value that is 0.5 << shift |
|
| - | 73 | /// @param val shift value |
|
| - | 74 | /// @return 0.5 << shift or 0 |
|
| - | 75 | static constexpr uint8_t ROUNDING(uint8_t shift) { return (shift>0) ? (0) : 1<<(shift-1);}; |
|
| - | 76 | ||
| - | 77 | ||
| 48 | protected: |
78 | protected: |
| 49 | /// @brief Pixel height |
79 | /// @brief Pixel height |
| 50 | uint8_t const m_height; |
80 | uint8_t const m_height; |
| 51 | /// @brief Bitmap width |
81 | /// @brief Bitmap width |
| 52 | uint8_t const m_width; |
82 | uint8_t const m_width; |
| - | 83 | ||
| - | 84 | /// @brief bitmap virtual height |
|
| - | 85 | uint8_t const m_mapheight; |
|
| - | 86 | /// @brief Bitmap virtual width |
|
| - | 87 | uint8_t const m_mapwidth; |
|
| - | 88 | ||
| 53 | /// @brief Spacing between characters |
89 | /// @brief Spacing between characters |
| 54 | uint8_t const m_spacing; |
90 | uint8_t const m_spacing; |
| 55 | /// @brief Number of characters in the character set bit map |
91 | /// @brief Number of characters in the character set bit map |
| - | 92 | ||
| - | 93 | ||
| 56 | uint8_t const m_chars; |
94 | uint8_t const m_chars; |
| 57 | char const *m_data; |
95 | char const *m_data; |
| - | 96 | ||
| - | 97 | unsigned char const m_mult; // |
|
| - | 98 | unsigned char const m_shift; // bit shift after multiplication |
|
| - | 99 | unsigned char const m_round; // round up value 0.5 << shift |
|
| 58 | }; |
100 | }; |
| 59 | 101 | ||
| 60 | class font5x7_t : public font_t |
102 | class font5x7_t : public font_t |
| 61 | { |
103 | { |
| 62 | public: |
104 | public: |
| 63 | // one byte of pixels per character row. |
105 | // one byte of pixels per character row. |
| 64 | font5x7_t(unsigned char_count, char const *data) : font_t(7, 5, 6, char_count, data){}; |
106 | font5x7_t(unsigned char_count, char const *data) : font_t(7, 5, 6, char_count, data, 1, 0){}; |
| 65 | 107 | ||
| 66 | char |
108 | char |
| 67 | getPixel(char c, int x, int y) override; |
109 | getPixel(char c, int x, int y) override; |
| 68 | }; |
110 | }; |
| 69 | 111 | ||
| 70 | class font10x18_t : public font_t |
112 | class font10x18_t : public font_t |
| 71 | { |
113 | { |
| 72 | public: |
114 | public: |
| 73 | // XBM format |
115 | |
| - | 116 | // XBM format with optional multiply, right shift scaling of coordinates |
|
| 74 | font10x18_t(unsigned char_count, char const *data) : font_t(18, 10, 10, char_count, data){}; |
117 | font10x18_t(unsigned char_count, char const *data, unsigned char mult=1, unsigned char shift=0) : font_t(18,10,10, char_count, data, mult, shift){}; |
| 75 | 118 | ||
| 76 | char |
119 | char |
| 77 | getPixel(char c, int x, int y) override; |
120 | getPixel(char c, int x, int y) override; |
| 78 | }; |
121 | }; |
| 79 | 122 | ||
| Line 82... | Line 125... | ||
| 82 | extern font5x7_t small_font; |
125 | extern font5x7_t small_font; |
| 83 | 126 | ||
| 84 | // lucida font |
127 | // lucida font |
| 85 | // in 10x18 |
128 | // in 10x18 |
| 86 | extern font10x18_t large_font; |
129 | extern font10x18_t large_font; |
| - | 130 | ||
| - | 131 | // scaled down lucida font |
|
| - | 132 | // in 5 x 9 |
|
| - | 133 | extern font10x18_t medium_font; |
|
| 87 | 134 | ||