Skip to content

Instantly share code, notes, and snippets.

@rnhmjoj
Created August 30, 2020 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnhmjoj/bfa1af90c7f0f99b730eb8d4a7f6bd32 to your computer and use it in GitHub Desktop.
Save rnhmjoj/bfa1af90c7f0f99b730eb8d4a7f6bd32 to your computer and use it in GitHub Desktop.
{ pkgs ? import ./. { } }:
let
nonfree = [
];
excluded = [
# cursor fonts
# These are not really a font and X11 specific,
# so they shouldn't be converted.
"fontxfree86type1"
"fontmicromisc"
"fontsunmisc"
"fontcursormisc"
"fontdecmisc"
# unfree license restricts modification
"fontadobeutopiatype1"
"fontadobeutopia100dpi"
"fontadobeutopia75dpi"
"fontbhtype1"
"fontibmtype1"
# unfree license restricts modification
# It could be argued that we can convert the font
# as
# > absolutely necessary to accommodate the standard
# > resolution of the screen or other output device
#
# and then gets AT&T to validate our change, so probably
# not going to happen.
"fontbh100dpi"
"fontbh75dpi"
# no license, just a copyright notice
"fontbhlucidatypewriter100dpi"
"fontbhlucidatypewriter75dpi"
"fontdaewoomisc"
# unclear license, "permission to use"?
"fontjismisc"
];
included = [
# Type 1 (Postscript)
# Converted with some very subtle changes
# to the metric.
"fontbitstreamtype1"
# X11 bitmaps
# This contain thousands of fonts:
# impossibile to check them all.
"fontadobe100dpi"
"fontadobe75dpi"
"fontbitstream100dpi"
"fontarabicmisc" # arabic24 terrible
"fontbitstream75dpi" # broken encoding?
"fontcronyxcyrillic" # broken encoding?
"fontisasmisc" # jiskan16 broken encoding?
"fontmisccyrillic" # terrible
"fontmuttmisc" # 8vx16rk wrong sizing
"fontmiscmisc"
"fontschumachermisc"
"fontscreencyrillic"
"fontsonymisc"
"fontwinitzkicyrillic"
];
lib = pkgs.lib;
convert = type: name: pkg: pkg.overrideDerivation (old: {
nativeBuildInputs = with pkgs;
old.nativeBuildInputs ++ [ xorg.fonttosfnt libfaketime fontforge ];
postBuild = ''
# convert X11 bitmap fonts to otb
for i in $(find -type f -name '*.bdf'); do
name=$(basename $i | cut -d. -f1)
${if type == "ff"
then
''fontforge -lang=ff -c "Open(\"$i\"); Generate(\"$name.otb\")"''
else
''
faketime -f "1970-01-01 00:00:01" \
fonttosfnt -v -o "$name.otb" "$i" || true
''
}
done
# convert Postscript (Type 1) font to otf
for i in $(find -type f -name '*.pfa' -o -name '*.pfb'); do
name=$(basename $i | cut -d. -f1)
fontforge -lang=ff -c "Open(\"$i\"); Generate(\"$name.otf\")"
done
'';
postInstall = ''
# install the otb fonts
if test -n "$(find -type f -name '*.otb' -print -quit)"; then
fontDir="$out/lib/X11/fonts/misc/"
install -D -m 644 -t "$fontDir" *.otb
mkfontdir "$fontDir"
fi
# install the otf fonts
if test -n "$(find -type f -name '*.otf' -print -quit)"; then
fontDir="$out/lib/X11/fonts/misc/"
install -D -m 644 -t "$fontDir" *.otf
mkfontscale "$fontDir"
fi
'';
});
bitmaps = lib.filterAttrs (n: v: !lib.elem n excluded) pkgs.xorg;
in
{
ff = lib.mapAttrs (convert "ff") bitmaps;
sf = lib.mapAttrs (convert "sf") bitmaps;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment