-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtomthumb.c
135 lines (120 loc) · 4.05 KB
/
tomthumb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include "bmp.h"
/*
Robey Pointer's "Tom Thumb" tiny monospace font for
my bitmap module, with some minor changes.
http://robey.lag.net/2010/01/23/tiny-monospace-font.html
To use:
extern BmFont tomthumb;
then call bm_set_font(b, &tomthumb);
To compile the test program:
$ gcc -I ../ -D TEST tomthumb.c ../bmp.o
*/
//--- XBM -------------------------------------------------------------------
#define tom_thumb_width 48
#define tom_thumb_height 40
static unsigned char tom_thumb_bits[] = {
0xbf, 0x89, 0xad, 0xac, 0xee, 0xff, 0xdf, 0xaa, 0xaa, 0xaa, 0xcd, 0xac,
0xdf, 0x8a, 0x88, 0xdc, 0xaf, 0xda, 0xdf, 0xaa, 0xae, 0xae, 0xaf, 0xd8,
0xbf, 0x8c, 0xa9, 0xae, 0xaf, 0xae, 0xdd, 0x8d, 0x8d, 0xad, 0xdf, 0xff,
0xbd, 0xac, 0xda, 0xaa, 0xfc, 0xa9, 0xbd, 0x8d, 0xd8, 0xda, 0xd9, 0x8a,
0xbf, 0xbd, 0xda, 0xd8, 0xda, 0xb8, 0xdd, 0xcd, 0x8a, 0xd9, 0xd8, 0xcb,
0xaa, 0xdc, 0xbc, 0x8c, 0xbe, 0xff, 0xda, 0xfb, 0xba, 0xba, 0xfc, 0x89,
0xaf, 0xfd, 0xbc, 0xdc, 0xba, 0x9e, 0xff, 0xde, 0xaa, 0xea, 0xaa, 0xce,
0xff, 0xf8, 0xdc, 0x8a, 0xdc, 0x8e, 0xfa, 0xd8, 0xa9, 0x99, 0xef, 0x9f,
0xd8, 0xfb, 0xae, 0xde, 0xa9, 0xd9, 0x8a, 0xfd, 0xce, 0xdd, 0xce, 0xec,
0xd8, 0xdb, 0xae, 0xdb, 0xce, 0xd9, 0xfa, 0xec, 0xa9, 0x9c, 0xa9, 0x9c,
0xf9, 0xba, 0xec, 0xf8, 0xcb, 0xdd, 0xfc, 0xda, 0xea, 0xed, 0xd9, 0xd8,
0xf9, 0xe8, 0xea, 0xdd, 0xda, 0xfd, 0xdc, 0xdb, 0xea, 0xbd, 0xda, 0xdd,
0xed, 0xbb, 0x8c, 0xfd, 0x89, 0xd9, 0xfe, 0xf8, 0xa8, 0x9a, 0xff, 0xcf,
0xfb, 0x8e, 0x8e, 0xba, 0x89, 0xda, 0x8d, 0xfc, 0x8c, 0xba, 0x8a, 0xba,
0xfe, 0x8b, 0xae, 0xba, 0xac, 0xda, 0xfb, 0xfc, 0xa8, 0x99, 0xa9, 0xc9,
0xfd, 0xe9, 0xa8, 0xda, 0xfb, 0x9f, 0xfa, 0xde, 0x8e, 0xaa, 0xcd, 0xca,
0xfd, 0xb8, 0x8c, 0xfa, 0xa8, 0xfa, 0xda, 0xda, 0x8e, 0xfa, 0xad, 0xfa,
0xf9, 0xe8, 0xae, 0xfd, 0xad, 0xfd, 0xfd, 0x88, 0xd9, 0xfa, 0xff, 0x8f,
0xbd, 0xbb, 0xae, 0xfa, 0xd9, 0x8a, 0xdf, 0xdd, 0xaa, 0xf8, 0xa8, 0x8a,
0xef, 0xfe, 0xaa, 0xf8, 0xab, 0x88, 0xff, 0xde, 0xd9, 0x8a, 0xdc, 0x88 };
//---------------------------------------------------------------------------
static void tt_putc(Bitmap *b, int x, int y, unsigned short c) {
int frow, fcol, byte;
unsigned int col;
BmRect clip = bm_get_clip(b);
int i, j;
if(c < 32 || c > 127) c = 127;
c -= 0x20;
fcol = c >> 3;
int shf = (fcol & 0x1);
fcol >>= 1;
frow = c & 0x7;
byte = frow * 5 * 6 + fcol;
col = bm_get_color(b);
for(j = 0; j < 5 && y + j < clip.y1; j++) {
if(y + j >= clip.y0) {
unsigned char bits = tom_thumb_bits[byte];
if(shf) bits >>= 4;
for(i = 0; i < 4 && x + i < clip.x1; i++) {
if(x + i >= clip.x0 && !(bits & (1 << i))) {
bm_set(b, x + i, y + j, col);
}
}
}
byte += 6;
}
}
static int tt_puts(Bitmap *b, int x, int y, const char *s) {
int x0 = x;
while(*s) {
if(*s == '\n') {
y += 6;
x = x0;
} else if(*s == '\b') {
if(x > x0) x -= 4;
} else if(*s == '\r') {
x = x0;
} else if(*s == '\t') {
x += 4 * 4;
} else {
tt_putc(b, x, y, *s);
x += 4;
}
s++;
}
return 1;
}
static int tt_width(struct bitmap_font *font, unsigned int codepoint) {
(void)font,(void)codepoint;
return 4;
}
static int tt_height(struct bitmap_font *font, unsigned int codepoint) {
(void)font,(void)codepoint;
return 6;
}
BmFont tomthumb = {
"TOMTHUMB",
1,
tt_puts,
tt_width,
tt_height,
NULL,
NULL,
NULL
};
#ifdef TEST
int main(int argc, char *argv[]) {
Bitmap *b = bm_create(240, 160);
bm_set_color(b, 0xFFFFFF);
bm_set_font(b, &tomthumb);
bm_printf(b, 10, 16, "the quick brown fox jumps\nover the lazy dog");
bm_printf(b, 10, 28, "THE QUICK BROWN FOX JUMPS\nOVER THE LAZY DOG");
bm_printf(b, 10, 40, "1234567890!@#$%%^&*()-=_+");
bm_printf(b, 10, 46, "[](){}.,<>/?\\|~'`\"\a\b");
bm_printf(b, 10, 52, "Hello World! %d", 123);
bm_set_color(b, 0xFFFFFE);
bm_save(b, "out.gif");
bm_free(b);
return 0;
}
#endif