Last active
May 18, 2023 22:42
-
-
Save aglitchman/3590d4259d3cc3fcb289bea7abe168e9 to your computer and use it in GitHub Desktop.
NodeJS script to generate FF script to keep in the font required characters only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
USAGE: | |
1. RUN: | |
node ff_unique_symbols.js | |
2. Copy the result, i.e. the FF script. | |
3. Open a font in FontForge | |
4. File -> Execute Script | |
5. In the popup select FF, paste the script. | |
6. Execute it. | |
7. Save the font. | |
*/ | |
function onlyUnique(value, index, self) { | |
return self.indexOf(value) === index; | |
} | |
function escapeChar(escape) { | |
return '"u' + ("0000" + escape.charCodeAt().toString(16)).slice(-4) + '"'; | |
} | |
// --> INSERT HERE REQUIRED CHARACTERS OR JUST ALL STRINGS FROM YOUR GAME | |
const text = " 0123456789~-+"; | |
// ^^^ (it's a nice idea to keep the characters " " (space) and "~" (tilde)) | |
// Keep only unique characters | |
let chars = text.split("").filter(onlyUnique).map(escapeChar); | |
// Output the FF scripts | |
console.log("SelectNone()"); | |
while (chars.length > 0) { | |
console.log("SelectMore(" + chars.splice(0, 1).join(", ") + ")"); | |
} | |
console.log("SelectInvert()"); | |
console.log("DetachAndRemoveGlyphs()"); | |
console.log("Reencode(\"compacted\")"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Online tool - https://jsbin.com/molahek