-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-numbers.html
238 lines (210 loc) · 8.91 KB
/
test-numbers.html
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html>
<html lang="en">
<head>
<title>test numerals</title>
<meta property="og:site_name" content="orbit-loona.github.io" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Test numerals" />
<meta property="og:url" content="https://orbit-loona.github.io/test-numbers.html" />
<meta property="og:description" content="Test numeral system" />
<meta property="og:locale" content="en_US" />
<meta property="og:image" content="https://orbit-loona.github.io/bin/test-numbers.png" />
<meta property="og:image:width" content="119" />
<meta property="og:image:height" content="96" />
<meta property="og:image:alt" content="image" />
<meta name="twitter:image:src" content="https://orbit-loona.github.io/bin/test-numbers.png" />
<meta name="twitter:title" content="Test numerals" />
<meta name="twitter:description" content="Test numeral system" />
<link rel="stylesheet" href="main.css"/>
<meta name="SKYPE_TOOLBAR" content="SKYPE_TOOLBAR_PARSER_COMPATIBLE">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="An Orbit">
<meta charset="UTF-8">
<script>
//Needed for the punycode script to work because it's meant for use with a package manager module system
module = {
exports: {}
}
</script>
<script src="https://cdn.jsdelivr.net/gh/mathiasbynens/punycode.js@main/punycode.js"></script>
<style>
@font-face {
font-family: "Test";
src: url("bin/Test.ttf");
}
body {
font-family: 'Gamja Flower', 'Test', 'Arial', 'Comic Mono', sans-serif;
}
#testNumberOutput {
line-height: 120%;
font-size: 300%;
border: 1px solid white;
padding: 3px;
}
#testNumberOutput, #testNumberInput {
font-family: 'Test', 'Arial', 'Comic Mono', sans-serif;
}
#decimalNumberOutput {
line-height: 130%;
font-size: 180%;
border: 1px solid white;
padding: 3px;
}
#decimalNumberOutput, #testNumberOutput {
max-width: 97vw;
word-wrap: break-word;
display: inline-block;
}
.label, #decimalNumberInput {
display: block;
}
#decimalNumberInput, #testNumberInput {
width: 600px;
}
#testNumberInput {
font-size: 160%;
}
.warning {
background-color: #2f0000;
color: white;
border: 1px solid red;
padding: 8px;
color: #fcc;
}
.warning a:normal {
color: #2eb;
}
.warning a:visited {
color: #f0c;
}
</style>
<script>
var urlParams = new URLSearchParams(window.location.search);
function bigintToBaseFooArray(bigintNumber,bigintBase) {
if(bigintNumber < 0n) { bigintNumber *= (-1n) };
if(bigintBase < 2n) {
throw new RangeError("Base must be greater than 2")
};
var result = [];
if(bigintNumber === 0n) {
return [0]
} else {
while(bigintNumber > 0n) {
var moduloResult = bigintNumber % bigintBase;
result.unshift(moduloResult);
bigintNumber -= moduloResult;
bigintNumber /= bigintBase
};
return result
}
};
function bigintCommas(bigint) {
var numberText = bigint.toString().replaceAll(/(?=\d)(?=(\d\d\d)+(?!\d))/g,",");
if(numberText.startsWith(",")) { numberText = numberText.substring(1) };
return numberText;
};
</script>
</head>
<body>
<h1>Test numerals</h1>
<div id="description">
<p>This is a fictional number system I made to see how FontForge worked. It is probably complete.</p><br/>
<noscript>This page (like nearly every other page on my site) relies heavily on JS. It's useless without it.<br/></noscript>
<p>This script is encoded in the <a href="https://en.wikipedia.org/wiki/Private_Use_Areas">Unicode <em>Private Use Area</em></a> and will not render properly anywhere on the Web, unless it embeds the special font as a <a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Web_fonts">web font</a>, or you have the font installed and the website you're on <em>specifically includes it</em> in its stylesheet (which isn't going to happen because I just made it up; if you can install browser extensions, CSS injector extensions such as Stylebot can be used to add such a style to a webpage, but due to the inherent nature of the PUA, only people with the font installed and the same such style would be able to see it).</p><br/>
<p>Current base: <span id="base">a lot</span></p>
<p id="noPunycodeWarning" class="warning" style="display: none;">The Test-to-Decimal functionality relies on <a href="https://github.com/mathiasbynens/punycode.js/">Mathias Bynens's <em>Punycode</em> library</a> to properly split the string of non-<a href="https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane">BMP</a> Unicode characters, but it was unable to load for some reason (maybe JSDelivr is down?). Conversion of Test numerals to Decimal will not be available.</p>
</div><br/>
<div id="main">
<div id="decimalToTest">
<h3>Decimal to Test Numerals</h3>
<span class="label">Enter the input number</span>
<input id="decimalNumberInput" type="number"/>
<br/>
<span class="label">Output:</span>
<span id="testNumberOutput"> </span><br/>
</div>
<div id="testToDecimal">
<h3>Test Numerals to Decimal</h3>
<span class="label">Enter the input number</span>
<input id="testNumberInput"/>
<br/>
<span class="label">Output:</span>
<span id="decimalNumberOutput"> </span><br/>
</div>
<script>
var glyphs = [];
var fontStart = 0xF3000; //Don't change, but not using const because weird Chrome/Safari scoping differences with const bit me in the a** last time
var fontEnd = 0xF3577; //Subject to change if more glyphs are added
var baseResult = BigInt(fontEnd - (fontStart - 1));
for(var i = fontStart; i <= fontEnd; i++) {
glyphs.push(String.fromCodePoint(i))
};
document.getElementById("base").innerText = baseResult.toLocaleString();
var testOutputField = document.getElementById("testNumberOutput");
var decimalOutputField = document.getElementById("decimalNumberOutput");
var twoNonBreakingSpaces = String.fromCharCode(0xA0,0xA0);
var decimalInputBoxFunction = function() {
var value = decimalInputBox.value;
if(value.length === 0) {
testOutputField.innerText = twoNonBreakingSpaces;
return
};
//console.log(value);
var parseintValue = parseInt(value);
if(isNaN(parseintValue)) {
return
} else {
var valueAsBigint = BigInt(value);
if(valueAsBigint < 0n) {
var wasNegative = true;
valueAsBigint = valueAsBigint * (-1n);
};
var resultArray = bigintToBaseFooArray(valueAsBigint,baseResult);
var resultText = resultArray.map(x => glyphs[x]).join("");
testOutputField.innerText = (wasNegative ? "" : "") + resultText
}
};
decimalInputBox = document.getElementById("decimalNumberInput");
decimalInputBox.addEventListener("change",decimalInputBoxFunction);
decimalInputBox.addEventListener("keyup",decimalInputBoxFunction);
if(module.exports.ucs2) {
var testInputBoxFunction = function() {
//module.exports = punycode
var value = this.value;
if(value.length === 0) {
decimalOutputField.innerText = twoNonBreakingSpaces;
return
};
if(value.match(/^(\-|)?(\d+\.|)\d+$/)) {
decimalOutputField.innerText = parseInt(value.replace("","-")).toLocaleString();
return
};
var splitValue = module.exports.ucs2.decode(value)
if(splitValue.length == 0) { return };
var wasNegative = (value.startsWith("-") || value.startsWith(""));
splitValue = splitValue.filter(number => ((number >= fontStart) && (number <= fontEnd))).map(x => String.fromCodePoint(x)).toReversed();
var result = 0n;
for(var i = 0; i < splitValue.length; i++) {
var glyph = splitValue[i];
var glyphValue = glyphs.indexOf(glyph);
if(glyphValue < 0) { continue };
result += BigInt(glyphValue) * (baseResult ** BigInt(i))
};
decimalOutputField.innerText = (wasNegative ? "-" : "") + (bigintCommas(result))
};
testInputBox = document.getElementById("testNumberInput");
testInputBox.addEventListener("change",testInputBoxFunction);
testInputBox.addEventListener("keyup",testInputBoxFunction)
} else {
var warning = document.getElementById("noPunycodeWarning");
warning.style.display = "block";
warning.before(document.createElement("br"));
var ttdElements = document.getElementById("testToDecimal");
var mainDiv = document.getElementById("main");
mainDiv.removeChild(ttdElements);
ttdElements = null
}
</script>
<br/><br/><a href="index.html"><small>go to main page</small></a>
</body>
</html>