aboutsummaryrefslogtreecommitdiff
path: root/conv.sh
blob: 396d08a8b1f4017bb0269ede57185669b3484870 (plain)
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
#!/bin/bash

# 20170403 bkw:

# convert TTF (or OTF) fonts to *.psfu.gz fonts that can be used
# on the Linux console.

# conversion isn't done directly. instead, the TTF is rendered as a
# BDF (via otf2bdf), then converted to a psfu via bdf2psf.

# these are supposedly in points. yeah, right.
SIZES=${SIZES:-8 12 15 19}

warn() {
	echo "$@" 1>&2
}

die() {
	warn "$@"
	exit 1
}

convfont() {
	font="$1"
	file="$( fc-list "$font" | head -n1 | cut -d: -f1 )"

	psfname="$( basename "$( echo $file | cut -d. -f1 | tr A-Z a-z | tr -d " " )" )"
	echo -n "$file => $psfname: "

	if [ ! -e "$file" ]; then
		warn "Font '$font' not found, skipping"
		return 1
	fi

	for size in $SIZES; do
		echo -n "$size"
		sh ./ttf2psfu.sh -p $size "$file" &> $psfname.$size.log

		# bug in file? if the width is double-digit, file prints HxW, but if
		# width is single-digit it prints WxH, WTF?
		#pxsize=$( file test.psfu | sed 's|.*, \(.*\)x\(.*\)$|\2x\1|' )

		w="$( psf2txt test.psfu | sed -n '/^Width/s,.* ,,p' )"
		h="$( psf2txt test.psfu | sed -n '/^Height/s,.* ,,p' )"
		pxsize=${w}x${h}
		gzip -9c < test.psfu > $psfname-$pxsize.psfu.gz
		rm -f test.psfu
		echo -n ":$pxsize "
	done
	echo
}

cat fonts | while read font; do
	convfont "$font"
done