Newer
Older
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Font maker</title>
<style>
input[type="checkbox"] {
all: unset;
display: inline-block;
border: 1px solid #ccc;
width: 20px;
height: 20px;
/* No padding */
padding: 0;
margin: 0;
vertical-align: middle;
}
input[type="checkbox"]:checked {
background-color: rgb(0, 0, 0);
}
input[type="checkbox"]:focus {
outline: none;
}
</style>
</head>
<body>
<div id="inputbox">
<!-- 16x16 grid of checkboxes -->
</div>
<pre id="output">
</pre>
<canvas id="renderedOutput">
Your browser doesn't support canvas.
</canvas>
<script>
var drawing = document.getElementById("inputbox");
var routput = document.getElementById("renderedOutput");
var ctx = routput.getContext("2d");
chkNum = 0;
for (var i = 0; i < 8; i++) {
for (var j = 0; j < 8; j++) {
var checkbox = document.createElement("input");
chkNum++;
checkbox.type = "checkbox";
checkbox.id = chkNum;
checkbox.addEventListener("change", function() {
updateOutput();
});
drawing.appendChild(checkbox);
}
drawing.appendChild(document.createElement("br"));
}
var output = document.getElementById("output");
var outputText = "";
var listOfBoxes = [];
var updateOutput = () => {
listOfBoxes = [];
// for each row of checkboxes, give it its own array in the listOfBoxes array
for (var i = 0; i < 8; i++) {
listOfBoxes.push([]);
for (var j = 0; j < 8; j++) {
var chk = document.getElementById(i * 8 + j + 1);
if (chk.checked) {
listOfBoxes[i].push(1);
} else {
listOfBoxes[i].push(0);
}
}
}
// run through each item in the listOfBoxes array and remove leading zeros
for (var i = 0; i < listOfBoxes.length; i++) {
var row = listOfBoxes[i];
// run through the array backwards
for (var j = row.length - 1; j >= 0; j--) {
// if it's a 0, remove it
if (row[j] == 0) {
row.splice(j, 1);
} else {
// if it's a 1, stop removing
break;
}
}
}
// output the listOfBoxes array to the output textarea, row by row
outputText = "const fntCHAR = [\n";
for (var i = 0; i < listOfBoxes.length; i++) {
outputText += " [";
for (var j = 0; j < listOfBoxes[i].length; j++) {
if (listOfBoxes[i][j] == 1) {
outputText += "1";
} else {
outputText += "";
}
if (j != listOfBoxes[i].length - 1) {
outputText += ", ";
}
}
outputText += "],\n";
}
outputText += "];\n";
output.innerHTML = outputText;
}
updateOutput();
</script>
</body>