-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscroll.c
74 lines (61 loc) · 1.59 KB
/
scroll.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
#include "../r1b.h"
wchar_t* read_file(char* path, int n){
char* raw = (char*)malloc(sizeof(char)*n*2);
FILE *fp;
char c;
int i = 0;
fp = fopen(path,"r");
while(1) {
c = fgetc(fp);
if( feof(fp) ) {
break;
}
raw[i] = c;
i++;
}
raw[i] = 0;
fclose(fp);
wchar_t* wstr = (wchar_t*)malloc(sizeof(wchar_t)*n);
int len = i;
void* next = (void*)raw;
int e;
i = 0;
while((char*)next <= (char*)raw+len){
next = r1b_utf8_decode(next, (uint32_t *)&wstr[i], &e);
i++;
}
wstr[i] = 0;
wstr[i+1] = 0;
wstr[i+2] = 0;
wstr[i+3] = 0;
free(raw);
return wstr;
}
int main(){
r1b_font_t font = r1b_load_font_hex("fonts/unifont.hex",16,0,INT_MAX,R1B_FLAG_SORTED);
wchar_t* txt = read_file("examples/assets/5000.txt",10000);
r1b_im_t im = r1b_zeros(3976,384);
r1b_line(&im,0.5,0.5,im.w-0.5,0.5,1,R1B_BLIT_SET);
r1b_line(&im,im.w-0.5,0.5,im.w-0.5,im.h-0.5,1,R1B_BLIT_SET);
r1b_line(&im,0.5,im.h-0.5,im.w-0.5,im.h-0.5,1,R1B_BLIT_SET);
r1b_line(&im,0.5,0.5,0.5,im.h-0.5,1,R1B_BLIT_SET);
int i = 0;
int x = 3960;
int y = 0;
while(1){
if (txt[i] == 0){
break;
}
r1b_putchar(&im,(int)txt[i],x,y,&font,1,R1B_BLIT_SET,0);
y += 16;
if (y >= 384){
y = 0;
x -= 18;
r1b_line(&im,x+16,0,x+16,384,1,R1B_BLIT_SET);
}
i++;
}
r1b_snapshot("examples/out/scroll.png",&im);
r1b_transpose_flip(&im);
r1b_lpr("Printer_USB_Thermal_Printer",&im);
}