font-cache without indent

master
Denis Knauf 2023-06-20 23:35:28 +02:00
parent 8960e7db51
commit d223b86670
1 changed files with 90 additions and 85 deletions

View File

@ -1,91 +1,96 @@
# vim: set noet sw=2 ts=2 sts=2: # vim: set noet sw=2 ts=2 sts=2:
{lib, pkgs, ...}: {lib, pkgs, ...}:
({src ? null , srcs ? null, name ? "", pname ? "", version ? ""}: ({src ? null , srcs ? null, name ? "", pname ? "", version ? ""}:
with pkgs; with pkgs;
let let
name_ = name_ =
if "" != name if "" != name
then name then name
else "${pname}-v${version}"; else "${pname}-v${version}";
in stdenv.mkDerivation ({ in stdenv.mkDerivation ({
name = name_; name = name_;
nativeBuildInputs = [ sfnt2woff-zopfli unzip coreutils fontconfig woff2 ]; nativeBuildInputs = [ sfnt2woff-zopfli unzip coreutils fontconfig woff2 ];
unpackPhase = '' unpackPhase = ''
source_dir="$TMPDIR/src" source_dir="$TMPDIR/src"
mkdir "$source_dir" mkdir "$source_dir"
cd "$source_dir" cd "$source_dir"
for s in $src $srcs for s in $src $srcs
do do
case "$s" in case "$s" in
*.zip|*.tar|*.tar.gz|*.tgz|*.tar.xz|*.txz|*.tar.bz2|*.tbz2) *.zip|*.tar|*.tar.gz|*.tgz|*.tar.xz|*.txz|*.tar.bz2|*.tbz2)
unpackFile "$s" unpackFile "$s"
;; ;;
*) *)
cp -pr --reflink=auto -- "$s" "$(stripHash "$s")" cp -pr --reflink=auto -- "$s" "$(stripHash "$s")"
;; ;;
esac esac
done done
''; '';
buildPhase = '' buildPhase = ''
set -e set -e
build_dir="$TMPDIR/build" build_dir="$TMPDIR/build"
mkdir "$build_dir" mkdir "$build_dir"
find "$source_dir" \( -name \*.otf -or -name \*.ttf -or -name \*.woff -or -name \*.woff2 \) -exec cp \{\} "$build_dir" \; find "$source_dir" \( -name \*.otf -or -name \*.ttf -or -name \*.woff -or -name \*.woff2 \) -exec cp \{\} "$build_dir" \;
cd "$build_dir" cd "$build_dir"
for s in *.otf *.ttf for s in *.otf *.ttf
do do
bn="''${s%.otf}" bn="''${s%.otf}"
bn="''${bn%.ttf}" bn="''${bn%.ttf}"
if ! [ -e "$bn.woff" ] if ! [ -e "$bn.woff" ]
then then
echo "sfnt2woff-zopfli $s => $bn.woff" echo "sfnt2woff-zopfli $s => $bn.woff"
sfnt2woff-zopfli "$s" sfnt2woff-zopfli "$s"
fi fi
if ! [ -e "$bn.woff2" ] if ! [ -e "$bn.woff2" ]
then then
echo "woff2_compress $s => $bn.woff2" echo "woff2_compress $s => $bn.woff2"
woff2_compress "$s" woff2_compress "$s"
fi fi
done done
for s in *.otf *.ttf *.woff for s in *.otf *.ttf *.woff
do do
fc="`dirname "$s"`/`basename "$s"`.fc" fc="`dirname "$s"`/`basename "$s"`.fc"
echo "fc-scan $s" echo "fc-scan $s"
LANG=C LC_NUMERIC=C fc-scan --format 'family=%{family} LANG=C LC_NUMERIC=C fc-scan --format 'family=%{family}
fullname=%{fullname} fullname=%{fullname}
postscriptname=%{postscriptname} postscriptname=%{postscriptname}
variable=%{variable} variable=%{variable}
slant=%{slant} slant=%{slant}
style=%{style} style=%{style}
weight=%{weight} weight=%{weight}
width=%{width} width=%{width}
' "$s" > "$fc" ' "$s" > "$fc"
done done
for s in *.woff2 for s in *.woff2
do do
o="`dirname "$s"`/`basename "$s" .woff2`.woff.fc" o="`dirname "$s"`/`basename "$s" .woff2`.woff.fc"
fc="`dirname "$s"`/`basename "$s"`.fc" fc="`dirname "$s"`/`basename "$s"`.fc"
cp "$o" "$fc" cp "$o" "$fc"
done done
''; '';
installPhase = '' installPhase = ''
cd "$TMPDIR" cd "$TMPDIR"
mkdir -p $out/share/{doc/${name_},fonts/{opentype,truetype,WOFF,WOFF2}{,/.fc}} mkdir -p $out/share/{doc/${name_},fonts/{opentype,truetype,WOFF,WOFF2}{,/.fc}}
find "$build_dir" -name \*.otf -exec cp \{\} $out/share/fonts/opentype \; find "$build_dir" -name \*.otf -exec cp \{\} $out/share/fonts/opentype \;
find "$build_dir" -name \*.ttf -exec cp \{\} $out/share/fonts/truetype \; find "$build_dir" -name \*.ttf -exec cp \{\} $out/share/fonts/truetype \;
find "$build_dir" -name \*.woff -exec cp \{\} $out/share/fonts/WOFF \; find "$build_dir" -name \*.woff -exec cp \{\} $out/share/fonts/WOFF \;
find "$build_dir" -name \*.woff2 -exec cp \{\} $out/share/fonts/WOFF2 \; find "$build_dir" -name \*.woff2 -exec cp \{\} $out/share/fonts/WOFF2 \;
find "$build_dir" -name \*.otf.fc -exec cp \{\} $out/share/fonts/opentype/.fc \; find "$build_dir" -name \*.otf.fc -exec cp \{\} $out/share/fonts/opentype/.fc \;
find "$build_dir" -name \*.ttf.fc -exec cp \{\} $out/share/fonts/truetype/.fc \; find "$build_dir" -name \*.ttf.fc -exec cp \{\} $out/share/fonts/truetype/.fc \;
find "$build_dir" -name \*.woff.fc -exec cp \{\} $out/share/fonts/WOFF/.fc \; find "$build_dir" -name \*.woff.fc -exec cp \{\} $out/share/fonts/WOFF/.fc \;
find "$build_dir" -name \*.woff2.fc -exec cp \{\} $out/share/fonts/WOFF2/.fc \; find "$build_dir" -name \*.woff2.fc -exec cp \{\} $out/share/fonts/WOFF2/.fc \;
find "$source_dir" -name \*.txt -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.txt -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.md -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.md -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.adoc -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.adoc -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.html -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.html -exec cp \{\} $out/share/doc/${name_} \;
find "$source_dir" -name \*.css -exec cp \{\} $out/share/doc/${name_} \; find "$source_dir" -name \*.css -exec cp \{\} $out/share/doc/${name_} \;
''; '';
} // (if null != src then { src = src; } else { srcs = srcs; }))) } // (
if null != src
then { src = src; }
else { srcs = srcs; }
))
)