-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssd1306_psf2ch.c
More file actions
93 lines (80 loc) · 2.14 KB
/
ssd1306_psf2ch.c
File metadata and controls
93 lines (80 loc) · 2.14 KB
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
/* */
/* This program converts PSFv1 and PSFv2 font files */
/* (256 characters without Unicode tables only) to */
/* array in C-program source code */
/* */
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <wiringPi.h>
#include "oled_lib.h"
/* Show help */
void help(char *progname)
{
printf("Usage:\n\t%s infile\n\n", progname);
puts("Where:");
puts("\tinfile\t - path to PSF font file - no Unicode, 256 chars (mandatory)");
}
/* ********** */
/* * MAIN * */
/* ********** */
int main(int argc, char *argv[])
{
int fontid;
unsigned char *fi;
int fl;
int i, j, w, h, cw, ch, bh, chsz;
if (argc < 2 || !strcmp(argv[1], "--?")) {
help(argv[0]);
exit(0);
}
fontid = OLED_loadPsf(argv[1]);
if (fontid < 0) {
fprintf(stderr, "Unable to open font file: %s\n", argv[1]);
exit(-1);
}
fi = OLED_getFontMemory(fontid, &fl);
if (!fi)
exit(-1);
chsz = OLED_getFontScreenSize(fontid, &w, &h, &cw, &ch, &bh);
puts("#ifndef FONT_FILE\n#define FONT_FILE\n");
puts("/*\n Font information:\n");
printf(" File name: %s\n", argv[1]);
puts(" Characters: 256");
printf(" Font width in pixels: %d\n", w);
printf(" Font height in pixels: %d\n", h);
printf(" Font box width in pixels: %d\n", cw);
printf(" Font box height in pixels: %d\n", ch);
printf(" Font box height in bytes (pages): %d\n", bh);
printf(" Font size in bytes: %d\n", chsz);
puts("*/\n\nstatic unsigned char font[] = {");
for(i = 0; i < 256; i++)
for(j = 0; j < chsz; j++) {
/* print tab at beginning of each 8th byte */
if (!(j & 0x07))
printf("\t");
/* print byte */
printf("0x%02X", fi[i * chsz + j]);
fl--;
if (!fl)
break; /* if end of image, exit */
/* print separator */
printf(", ");
/* print character in comment for 1st line */
if (j == 7) {
if (i >= 0x20 && i <= 0x7a)
printf("\t/* 0x%02X = \'%c\' */", i, i);
else
printf("\t/* 0x%02X */", i);
}
/* newline after max 8 bytes */
if ((j & 0x07) == 7 || j == chsz - 1)
puts("");
}
puts("\n};\n\n#endif");
return 0;
}