1
This commit is contained in:
churl
2022-06-19 13:23:54 +02:00
parent eccc31545e
commit a18636ce87
2 changed files with 22 additions and 27 deletions

View File

@ -11,25 +11,22 @@
#ifndef __FONTS_H__ #ifndef __FONTS_H__
#define __FONTS_H__ #define __FONTS_H__
class Font {
class Font
{
public: public:
virtual unsigned char* getChar(int c) const = 0; virtual unsigned char* getChar(int c) const = 0;
virtual unsigned int get_char_width() const = 0; virtual unsigned int get_char_width() const = 0;
virtual unsigned int get_char_height() const = 0; virtual unsigned int get_char_height() const = 0;
}; };
template<unsigned int width, unsigned int height, unsigned char* data> template<unsigned int width, unsigned int height, unsigned char* data>
class FontInstance : public Font class FontInstance : public Font {
{
const unsigned int char_width; const unsigned int char_width;
const unsigned int char_height; const unsigned int char_height;
const unsigned int char_mem_size; const unsigned int char_mem_size;
unsigned char* font_data; unsigned char* font_data;
public: public:
FontInstance() : char_width(width), char_height(height), char_mem_size((((char_width + (8 >> 1)) / 8) * char_height)), font_data(data) { } FontInstance() : char_width(width), char_height(height), char_mem_size((((char_width + (8 >> 1)) / 8) * char_height)), font_data(data) {}
inline unsigned char* getChar(int c) const { inline unsigned char* getChar(int c) const {
return &font_data[char_mem_size * c]; return &font_data[char_mem_size * c];
} }
@ -41,7 +38,6 @@ public:
} }
}; };
extern unsigned char fontdata_8x16[]; extern unsigned char fontdata_8x16[];
extern unsigned char fontdata_8x8[]; extern unsigned char fontdata_8x8[];
extern unsigned char acorndata_8x8[]; extern unsigned char acorndata_8x8[];
@ -49,13 +45,12 @@ extern unsigned char fontdata_pearl_8x8[];
extern unsigned char fontdata_sun_12x22[]; extern unsigned char fontdata_sun_12x22[];
extern unsigned char fontdata_sun_8x16[]; extern unsigned char fontdata_sun_8x16[];
typedef FontInstance<8, 16, fontdata_8x16> Font_8x16;
typedef FontInstance<8,16,fontdata_8x16> Font_8x16; typedef FontInstance<8, 8, fontdata_8x8> Font_8x8;
typedef FontInstance<8,8,fontdata_8x8> Font_8x8; typedef FontInstance<8, 8, acorndata_8x8> Font_acorn_8x8;
typedef FontInstance<8,8,acorndata_8x8> Font_acorn_8x8; typedef FontInstance<8, 8, fontdata_pearl_8x8> Font_pearl_8x8;
typedef FontInstance<8,8,fontdata_pearl_8x8> Font_pearl_8x8; typedef FontInstance<12, 22, fontdata_sun_12x22> Font_sun_12x22;
typedef FontInstance<12,22,fontdata_sun_12x22> Font_sun_12x22; typedef FontInstance<8, 16, fontdata_sun_8x16> Font_sun_8x16;
typedef FontInstance<8,16,fontdata_sun_8x16> Font_sun_8x16;
extern Font_8x16 std_font_8x16; extern Font_8x16 std_font_8x16;
extern Font_8x8 std_font_8x8; extern Font_8x8 std_font_8x8;