Skip to content

Instantly share code, notes, and snippets.

@aglitchman
Last active May 18, 2023 22:42
Show Gist options
  • Save aglitchman/3590d4259d3cc3fcb289bea7abe168e9 to your computer and use it in GitHub Desktop.
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
/*
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\")");
@aglitchman
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment