hachem.wtf
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-10-10 15:57:52 +0200
committerhachem <im@hachem.wtf>2026-10-10 15:57:52 +0200
commit88750ed7132c08bcfb24e878c893ef7185c3c0b0 (patch)
tree6274d4918c82ee0c8c9c258ff8d9d3340b0b28e6
parentcc8768d33a6ff6cc64306d01679a10c3a1847736 (diff)
chore: rewrite tools in revo
-rw-r--r--tools/genfonts.py41
-rw-r--r--tools/genfonts.rv97
-rw-r--r--tools/subset-ttf.rv21
-rwxr-xr-xtools/subset-ttf.sh13
4 files changed, 118 insertions, 54 deletions
diff --git a/tools/genfonts.py b/tools/genfonts.py
deleted file mode 100644
index e5afb7e..0000000
--- a/tools/genfonts.py
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env python3
-# this just turns the linxu console fonts which are C arrays into psf1 fonts
-# that i can load on disk since half of my psf1 fonts are stolen from there.
-#
-# usage: genfonts.py <font_8x16.c> <out.psf> [height]
-
-import re
-import sys
-
-
-def parse_c(path):
- text = open(path).read()
- cut = text.index("}, {")
- body = text[cut + 4 :]
- body = re.sub(r"/\*.*?\*/", "", body, flags=re.S)
- bytes_ = [int(m, 16) for m in re.findall(r"0x([0-9a-fA-F]{2})", body)]
- return bytes_
-
-def write_psf1(rows, height, out):
- count = len(rows) // height
- if count < 256:
- rows = rows + [0] * (height * (256 - count))
- count = 256
- if count not in (256, 512):
- rows = rows[: height * 256]
- count = 256
- mode = 0x00 if count == 256 else 0x01 # bit0 set => 512 glyphs
- header = bytes([0x36, 0x04, mode, height])
- with open(out, "wb") as f:
- f.write(header)
- f.write(bytes(rows[: height * count]))
-
-def main():
- src, out = sys.argv[1], sys.argv[2]
- height = int(sys.argv[3]) if len(sys.argv) > 3 else int(re.search(r"8x(\d+)", src).group(1))
- rows = parse_c(src)
- write_psf1(rows, height, out)
- print(f"{out}: psf1 8x{height}, {len(rows) // height} glyphs in")
-
-if __name__ == "__main__":
- main()
diff --git a/tools/genfonts.rv b/tools/genfonts.rv
new file mode 100644
index 0000000..6ee6eda
--- /dev/null
+++ b/tools/genfonts.rv
@@ -0,0 +1,97 @@
+# I yoinked a lot of fonts from the linux source code but they are written as C arrays
+# which is cool dont get me wrong, C supremacy and all that bullshit, but I need them as
+# psf1 fonts, so this converts them and shit
+#
+# usage: revo genfonts.rv <font_8x16.c> <out.psf> [height]
+
+fn hexval(character) -> num do
+ const code = character:ascii()
+ if (code >= 48 and code <= 57)
+ return code - 48
+ if (code >= 97 and code <= 102)
+ return code - 87
+ if (code >= 65 and code <= 70)
+ return code - 55
+ return 0
+end
+
+fn read_int(text, start) -> num do
+ let position = start
+ let value = 0
+ let seen = :false
+ while (position < text:len() and text[position]:ascii() >= 48 and text[position]:ascii() <= 57) do
+ value = value * 10 + (text[position]:ascii() - 48)
+ seen = :true
+ position += 1
+ end
+ return if (seen) value else 0
+end
+
+fn parse_c(text) -> table do
+ const marker = text:index_of("}, {")
+ let position = if (marker == :nil) 0 else marker + 4
+ const length = text:len()
+ let bytes = {}
+
+ while (position < length) do
+ if (position + 1 < length and text[position] == "/" and text[position + 1] == "*") do
+ position += 2
+ while (position + 1 < length and (text[position] != "*" or text[position + 1] != "/")) do position += 1 end
+ position += 2
+ end else if (position + 3 < length and text[position] == "0" and text[position + 1] == "x") do
+ bytes:push(hexval(text[position + 2]) * 16 + hexval(text[position + 3]))
+ position += 4
+ end else do
+ position += 1
+ end
+ end
+
+ return bytes
+end
+
+fn main() do
+ if argv:len() < 3 do
+ panic("usage: genfonts.rv <font.c> <out.psf> [height]")
+ end
+
+ const source = argv[1]
+ const output = argv[2]
+
+ let height = 0
+ if (argv:len() > 3)
+ height = read_int(argv[3], 0)
+ else do
+ const marker = source:index_of("8x")
+ height = if (marker == :nil) 16 else read_int(source, marker + 2)
+ end
+
+ const handle = fs.open(source, "r"):unwrap()
+ const text = file.read(handle):unwrap()
+ file.close(handle)
+
+ let rows = parse_c(text)
+ let count = math.floor(rows:len() / height)
+
+ if count < 256 do
+ const padding = height * (256 - count)
+ for index in 0..padding do rows:push(0) end
+ count = 256
+ end
+
+ if (count != 256 and count != 512)
+ count = 256
+
+ const mode = if (count == 256) 0 else 1
+ let bytes = { 0x36, 0x04, mode, height }
+ const total = height * count
+ for i in 0..total do bytes:push(rows[i]) end
+
+ const data = iter.collect_string(bytes)
+ const sink = fs.open(output, "w"):unwrap()
+ file.write(sink, data):unwrap()
+ file.close(sink)
+
+ print("#{output}: psf1 8x#{height}, #{count} glyphs in")
+end
+
+main()
diff --git a/tools/subset-ttf.rv b/tools/subset-ttf.rv
new file mode 100644
index 0000000..e795149
--- /dev/null
+++ b/tools/subset-ttf.rv
@@ -0,0 +1,21 @@
+# trim a ttf down to the printable ascii subset (U+0020..007E) so we only embed
+# since revel doesnt actually render all glyphs, some fonts that lung wanted are
+# nerd fonts because hes a NERD and are HUGE like my PENIS.
+#
+# usage: revo subset-ttf.rv <in.ttf> <out.ttf>
+
+if argv:len() < 3 do
+ panic("usage: subset-ttf.rv <in.ttf> <out.ttf>")
+end
+
+const in_path = argv[1]
+const out_path = argv[2]
+
+match system({
+ "python3", "-m", "fontTools.subset", in_path,
+ "--unicodes=U+0020-007E",
+ "--no-hinting", "--glyph-names",
+ "--output-file=" ~ out_path,
+})
+ | {:ok, _} => print("wrote " ~ out_path)
+ | {:err, error} => panic("subset failed (#{error}), need fonttools: python3 -m pip install fonttools")
diff --git a/tools/subset-ttf.sh b/tools/subset-ttf.sh
deleted file mode 100755
index 70cffa2..0000000
--- a/tools/subset-ttf.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-# trim the ttf into a subset (U+0020..007E), its just to embed fonts that are actually
-# rendered, since we have NERD fonts and shit, they can be quite large
-
-set -e
-IN="$1"
-OUT="$2"
-python3 -m fontTools.subset "$IN" \
- --unicodes=U+0020-007E \
- --no-hinting --glyph-names \
- --output-file="$OUT"
-echo "wrote $OUT"