-
Notifications
You must be signed in to change notification settings - Fork 1
/
font.hpp
49 lines (44 loc) · 1.01 KB
/
font.hpp
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
#pragma once
#include <iostream>
#include <cstring>
#include "font/consola_ascii_0_ff.h"
const int MAXCOL = 0x100;
class Font {
private:
char o[MAXCOL][MAXCOL];
FILE *fp;
inline int g() {
int c = getc(fp);
while (c == '\n' || c == '\r') {
c = getc(fp);
}
return c;
}
inline void init() {
for (auto i = 0; i < MAXCOL; i++) {
std::memcpy(o[i], map65536[i], sizeof(map65536[i]));
}
}
inline void init(const char *s) {
if (!strlen(s)) {
init();
return;
}
fp = fopen(s, "r");
if (!fp) {
init();
return;
}
for (auto i = 0; i < MAXCOL; i++) {
for (auto j = 0; j < MAXCOL; j++) {
o[i][j] = g();
}
}
fclose(fp);
}
public:
Font() { init(); }
Font(const char *s) { init(s); }
Font(std::string s) { init(s.c_str()); }
inline char get(int x, int y) { return o[x][y]; }
};