forked from masterzorag/xbm_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xbm_print.c
102 lines (81 loc) · 2.26 KB
/
xbm_print.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
/*
gcc -O2 -Wall -o xbm_print xbm_print.c
# 1. rebuild C header (razors.ttf/xbm/razors.ttf.h)
# ./genXBMfonts.sh
# 2. use generated XBM fonts, hardcode in xbm_print
# cp razors.ttf/xbm/razors.ttf.h xbm_font.h
# 3. rebuild xbm_tools
# make clean && make
xbm_tools # ./xbm_print mz
109 [m]
***** *****
****** ******
**************
**** **** ****
**** ** ****
**** ****
***** ****
****** ****
****** ****
****** ****
****** ****
****** ****
****** ****
****** ****
122 [z]
**************
**************
****
****
****
****
***********
***********
*****
*****
**************
**************
**************
**************
*/
#include <stdio.h>
/* generate with genXBMfonts, https://github.com/masterzorag/xbm_tools */
#include "xbm_font.h"
void xbm_print(const int x, const int y, const char *text, unsigned int *buffer) {
short i, j, tx = 0;
char c;
while(*text != '\0') {
c = *text;
if(c < LOWER_ASCII_CODE || c > UPPER_ASCII_CODE) c = 180;
printf("%d [%c]\n", c, c);
// font indexing by current char
char *bit = xbmFont[c - LOWER_ASCII_CODE];
// dump bits map:
for(i = 0; i < (FONT_W * FONT_H) / BITS_IN_BYTE; i++) {
for(j = 0; j < BITS_IN_BYTE; j++) {
// printf("%c", (data[i] & (1 << j)) ? ' ' : '0' ); // least significant bit first
// printf("%d", (data[i] & (0x80 >> j)) ? 1 : 0); // right shifting the value will print bits in reverse.
if(bit[i] & (1 << j)){ // least significant bit first
printf("*"); // paint FG
} else {
printf(" "); // paint BG pixel
}
}
tx++;
if(tx == (FONT_W / BITS_IN_BYTE)) {
tx = 0;
puts("");
}
}
// glyph painted, move one char right on text
++text;
}
}
int main(int argc, char **argv) {
if(argv[1]){
xbm_print(0, 0, argv[1], NULL);
return 0;
} else {
return -1;
}
}