commit bda09ce

uint  ·  2026-07-14 14:14:35 +0000 UTC
parent 3372c36
add `fontscale`
2 files changed,  +75, -0
+3, -0
1@@ -31,3 +31,6 @@ do!).
2 
3 Reloading the font can be done with `AltR + r`
4 
5+There is also a ![font scaling program](scripts/fontscale) provided which uses
6+`otf2ttf` to scale any font in a libary if needed.
7+
+72, -0
 1@@ -0,0 +1,72 @@
 2+#       fontscale
 3+# Font scaling program which converts a vector font to a FONT.bdf
 4+# using `otf2bdf`
 5+#
 6+# This program is licensed under the ISC License.
 7+# Copyright 2026 uint
 8+# 
 9+# Permission to use, copy, modify, and/or distribute this software for any
10+# purpose with or without fee is hereby granted, provided that the above
11+# copyright notice and this permission notice appear in all copies.
12+# 
13+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
15+# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18+# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19+# PERFORMANCE OF THIS SOFTWARE.
20+
21+#!/bin/sh
22+set -eu
23+
24+DIR="$HOME/.local/share/fonts"
25+FONT="$DIR/FONT.ttf"
26+BDF="$DIR/FONT.bdf"
27+META="$DIR/fontscale"
28+DPI=96
29+
30+[ "$#" -eq 1 ] || {
31+	echo "Usage: fontscale {+|-}" >&2
32+	exit 1
33+}
34+
35+[ -f "$FONT" ] || {
36+	echo "Font not found: $FONT" >&2
37+	exit 1
38+}
39+
40+[ -f "$META" ] || {
41+	echo "Scale file not found: $META" >&2
42+	exit 1
43+}
44+
45+scale=$(cat "$META")
46+
47+case "$scale" in
48+	''|*[!0-9]*)
49+		echo "Invalid scale in $META: $scale" >&2
50+		exit 1
51+		;;
52+esac
53+
54+case "$1" in
55+	+)
56+		scale=$((scale + 1))
57+		;;
58+	-)
59+		[ "$scale" -gt 1 ] || {
60+			echo "Scale cannot be less than 1" >&2
61+			exit 1
62+		}
63+		scale=$((scale - 1))
64+		;;
65+	*)
66+		echo "Usage: fontscale [+|-]" >&2
67+		exit 1
68+		;;
69+esac
70+
71+otf2bdf -n -p "$scale" -r "$DPI" -o "$BDF" "$FONT"
72+printf '%s\n' "$scale" >"$META"
73+