diff options
authorB. Watson <yalhcru@gmail.com>2017-04-03 07:30:23 (GMT)
committerB. Watson <yalhcru@gmail.com>2017-04-03 07:30:23 (GMT)
commit229dc8d1b9372f89343b3742486496b06aeb813b (patch)
initial commit
7 files changed, 263 insertions, 0 deletions
diff --git a/.makepp/.done.mk b/.makepp/.done.mk
new file mode 100644
index 0000000..13b01b0
--- /dev/null
+++ b/.makepp/.done.mk
@@ -0,0 +1,13 @@
+COMMAND=sh conv.shtouch .done
+END= \ No newline at end of file
diff --git a/.makepp/log b/.makepp/log
new file mode 100644
index 0000000..bca8776
--- /dev/null
+++ b/.makepp/log
@@ -0,0 +1,39 @@
+USEdefault rule
+USEdefault rule
+LEX_RULE43040760info not cached
+USEdefault rule
+PARSEtouch .done34441736/export/home/urchlay/ttf-console-fonts/Makefile:6
+USEdefault rule
+USEdefault rule
+USEdefault rule
+SUCCESSdefault rule43275680
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..64840e1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,17 @@
+.PHONY: all clean install
+all: .done
+.done: conv.sh fonts ttf2psfu.sh
+ sh conv.sh
+ touch .done
+ rm -f *.psfu *.psfu.gz *.log *.bdf .done
+install: all
+ mkdir -p $(DESTDIR)$(PSFDIR)
+ install -m0644 *.psfu.gz $(DESTDIR)$(PSFDIR)
diff --git a/README b/README
new file mode 100644
index 0000000..2010fda
--- /dev/null
+++ b/README
@@ -0,0 +1,107 @@
+ttf-console-fonts, by B. Watson <yalhcru@gmail.com>.
+Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
+ttf-console-fonts is a collection of Linux console fonts, converted from
+various TrueType fonts found in a typical Linux install.
+No TTF fonts are included here. Instead, the ones installed on your system
+(usually in /usr/share/fonts/TTF) are used. Also, I don't include prebuilt
+console fonts because I'm not so sure the licensing allows it (dammit,
+I'm a doc... uh, programmer, not a lawyer).
+The name is slightly misleading: obviously the console doesn't support
+TTF, only bitmap fonts in PSF format. What this package does is convert
+various TTFs into the PSF (aka .psfu) bitmapped font format used by
+the kernel.
+Notice that these are framebuffer fonts. Pretty much everyone these
+days is likely to be using the framebuffer console (thanks to kernel
+modesetting and Xorg's requirement for it). If you're somehow still using
+a VGA textmode console, only fonts 8 or 9 pixels wide are supported.
+For this package, that means the ones with "8x" in their filenames.
+If the converted fonts don't look the same to you on the console as the
+original fonts do in X, that's because X and most modern X applications
+do subpixel rendering for antialiasing. The Linux console doesn't support
+this at all.
+Another difference between TTF and console fonts: only 512 glyphs are
+allowed per console font. This means Unicode support will be limited.
+The generated fonts include the full ASCII set, plus Latin-1 (aka
+ISO-8859-1) and at least partial support for Latin-2. If your requirements
+are different, change SETS in conv.sh (read the bdf2psf documentation,
+and possibly the source code, to understand how this stuff works). One
+useful piece of information: the same glyph can represent more than one
+Unicode codepoint (if they have the same appearance, e.g. C in Latin
+and Cyrillic).
+ - bdf2psf
+ - otf2bdf
+ - psftools
+For Slackware, the above are available on SlackBuilds.org. For Debian
+or Ubuntu, try apt-getting them.
+"Core system" requirements (included in Slackware, may need installing
+if you're on Debian/etc):
+ - fontconfig
+ - freetype2
+ - perl
+ - stuff like coreutils and bash
+ - whatever fonts are listed in the file 'fonts', of course.
+To build the fonts, simply run "make". If you get errors, especially
+"command not found" or "no such file or directory", you're missing a
+requirement (see above).
+After they're built, the fonts will have filenames like:
+The "8x12" is the pixel size (NOT the point size).
+If you're running in the console, you can test out the fonts by loading
+them with "setfont". If the results look OK, you can install the fonts via
+"make install" (if you're making a distro package, DESTDIR is supported).
+On Slackware, you can edit /etc/rc.d/rc.font to set the default system
+font to whichever one you like best. Don't forget to make rc.font
+executable. I have no idea how to set the default console font on other
+distributions (sorry).
+If you want to try converting other fonts, edit the file "fonts". The font
+names there are whatever "fc-list" calls the font. You can probably use
+wildcards or inexact matches (fc-list is pretty user-friendly). Whatever
+fonts you choose *must* be TrueType or OpenType (.ttf or .otf). They
+also *must* be "monospace" or "fixed width". Trying to convert
+proportional/variable-width fonts will "work", but the result won't be
+very pleasing to look at.
+If you don't like the sizes I picked, you can set SIZES in the
+environment. It's a space-separated list of point sizes. Example:
+SIZES="6 9 12 15" make
+Don't get too crazy with the cheez-wiz: the kernel (or at least the
+setfont command) has a font height limit of 32 rows. And in my testing, I
+found that fonts 31 or 32 rows tall would load, but displayed incorrectly.
+The practical limit (for my system at least) seems to be 30.
+The point sizes might be a bit different than they are in X. This is
+because Xorg's Xrandr extension is smart enough to know your monitor's
+actual DPI, and will scale TTFs to the correct size. The otf2bdf utility
+used here could theoretically do the same thing, but it doesn't: it
+just assumes 100x100 DPI. If your monitor doesn't have square pixels,
+this will be even more noticeable.
+If you're wondering how many rows/columns of text each font will give you,
+the calculation is simple enough: find out your framebuffer resolution
+(e.g. by running 'fbset' with no arguments), and divide the width of
+the fb by the width of the font (e.g. 1920/15 = 128, throw away any
+remainder). Do the same calculation for the height (e.g. 1080/27 = 40).
+Or, you could just load the font, then:
+kill -WINCH $$; echo $COLUMNS $LINES
diff --git a/conv.sh b/conv.sh
new file mode 100644
index 0000000..396d08a
--- /dev/null
+++ b/conv.sh
@@ -0,0 +1,55 @@
+# 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"
diff --git a/fonts b/fonts
new file mode 100644
index 0000000..20b37d1
--- /dev/null
+++ b/fonts
@@ -0,0 +1,3 @@
+DejaVu Sans Mono:style=Book
+Liberation Mono:style=Regular
diff --git a/ttf2psfu.sh b/ttf2psfu.sh
new file mode 100644
index 0000000..ef5a55a
--- /dev/null
+++ b/ttf2psfu.sh
@@ -0,0 +1,29 @@
+# uses otf2bdf and bdf2psf to turn a ttf/otf font into a console font.
+# all args are passed through to otf2bdf, please don't pass -o file.bdf.
+# right now, output is to test.psfu. This will change in the future.
+otf2bdf "$@" -c C -o tmp.bdf
+# lie to bdf2psf, dirty hack alert! bdf2psf needs the AVERAGE_WIDTH
+# to be a multiple of 10. And it messes up the kerning if we don't
+# add a fudge factor (the 30, below).
+AV=$( sed -n 's,AVERAGE_WIDTH ,,p' tmp.bdf )
+AV=$(( ( AV + 30 ) / 10 * 10 ))
+sed -i "/AVERAGE_WIDTH/s, .*, $AV," tmp.bdf
+# bdf2psf wants all this crap passed as a single argument with no
+# spaces. I need to be able to read and maybe modify the list, so:
+bdf2psf --fb tmp.bdf $SETDIR/standard.equivalents $SETS 512 test.psfu