Files

73 lines
2.8 KiB
C

#ifndef BOB64_FONT_H
#define BOB64_FONT_H
#define FONT_WIDTH 8u
#define FONT_HEIGHT 16u
#define LINE_HEIGHT 18u
#define CHAR_SPACING 1u
#define FONT_CELL_WIDTH (FONT_WIDTH+CHAR_SPACING)
/* Compact 5x7 font: blank, A-Z, 0-9, ?, !, -, period, colon, equals, >. */
static const u8 bob64_font5x7[44][5]={
{0,0,0,0,0},
{0x7e,0x11,0x11,0x11,0x7e},{0x7f,0x49,0x49,0x49,0x36},
{0x3e,0x41,0x41,0x41,0x22},{0x7f,0x41,0x41,0x22,0x1c},
{0x7f,0x49,0x49,0x49,0x41},{0x7f,0x09,0x09,0x09,0x01},
{0x3e,0x41,0x49,0x49,0x7a},{0x7f,0x08,0x08,0x08,0x7f},
{0x00,0x41,0x7f,0x41,0x00},{0x20,0x40,0x41,0x3f,0x01},
{0x7f,0x08,0x14,0x22,0x41},{0x7f,0x40,0x40,0x40,0x40},
{0x7f,0x02,0x0c,0x02,0x7f},{0x7f,0x04,0x08,0x10,0x7f},
{0x3e,0x41,0x41,0x41,0x3e},{0x7f,0x09,0x09,0x09,0x06},
{0x3e,0x41,0x51,0x21,0x5e},{0x7f,0x09,0x19,0x29,0x46},
{0x46,0x49,0x49,0x49,0x31},{0x01,0x01,0x7f,0x01,0x01},
{0x3f,0x40,0x40,0x40,0x3f},{0x1f,0x20,0x40,0x20,0x1f},
{0x3f,0x40,0x38,0x40,0x3f},{0x63,0x14,0x08,0x14,0x63},
{0x07,0x08,0x70,0x08,0x07},{0x61,0x51,0x49,0x45,0x43},
{0x3e,0x51,0x49,0x45,0x3e},{0x00,0x42,0x7f,0x40,0x00},
{0x62,0x51,0x49,0x49,0x46},{0x22,0x41,0x49,0x49,0x36},
{0x18,0x14,0x12,0x7f,0x10},{0x2f,0x49,0x49,0x49,0x31},
{0x3e,0x49,0x49,0x49,0x32},{0x01,0x71,0x09,0x05,0x03},
{0x36,0x49,0x49,0x49,0x36},{0x26,0x49,0x49,0x49,0x3e},
{0x02,0x01,0x51,0x09,0x06},{0x00,0x00,0x5f,0x00,0x00},
{0x08,0x08,0x08,0x08,0x08},{0x00,0x60,0x60,0x00,0x00},
{0x00,0x36,0x36,0x00,0x00},{0x14,0x14,0x14,0x14,0x14},
{0x41,0x22,0x14,0x08,0x00}
};
typedef struct {
const u8 *Data;
u8 Width,Height;
u16 GlyphCount;
u8 BytesPerGlyph,ColumnMajor,MostSignificantBitFirst;
} BOB64_BITMAP_FONT;
static const BOB64_BITMAP_FONT bob64_font_compact5x7={
&bob64_font5x7[0][0],5,7,44,5,1,0
};
typedef void (*BOB64_FONT_PLOT_PIXEL)(void *context,s64 x,s64 y,
u32 scale,u32 color);
static inline int bob64_font_sample(const BOB64_BITMAP_FONT *font,u32 glyph,
u32 x,u32 y) {
u32 axis,bit;
if(!font||!font->Data||glyph>=font->GlyphCount||x>=font->Width||
y>=font->Height)return 0;
if(font->ColumnMajor)axis=x,bit=y;
else axis=y,bit=x;
u8 mask=font->MostSignificantBitFirst?
(u8)(0x80u>>bit):(u8)(1u<<bit);
return (font->Data[(usize)glyph*font->BytesPerGlyph+axis]&mask)!=0;
}
static inline void bob64_font_draw_glyph(const BOB64_BITMAP_FONT *font,
u32 glyph,s64 x,s64 y,u32 scale,BOB64_FONT_PLOT_PIXEL plot,
void *context,u32 color) {
if(!font||!plot||!scale||glyph>=font->GlyphCount)return;
for(u32 row=0;row<font->Height;row++)for(u32 column=0;column<font->Width;column++)
if(bob64_font_sample(font,glyph,column,row))
plot(context,x+(s64)column*scale,y+(s64)row*scale,scale,color);
}
#endif