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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# Maintainer: gaou-piou <i.am.piou@gmail.com>
# Contributor: GCMarvin <GCMarvin@users.noreply.github.com>
pkgname=ttf-google-sans-hinted
_ftapi=1 # fonttune API this PKGBUILD was written for; the build stops if main moved to another one
_nfver=3.5.1
pkgver=1.020
pkgrel=3
pkgdesc='Google Sans and Google Sans Display, tuned with fonttune (optionally Nerd Fonts patched)'
url='https://flutter.googlesource.com/gallery-assets'
arch=('any')
license=('LicenseRef-Google-Sans')
makedepends=('git' 'python' 'python-fonttools' 'parallel' 'fontforge' 'ttfautohint')
options=(!strip !zipman)
conflicts=('ttf-google-sans')
provides=('ttf-google-sans')
source=(
'fonts.tar.gz::https://flutter.googlesource.com/gallery-assets/+archive/refs/heads/master/lib/fonts.tar.gz'
"font-patcher-${_nfver}.zip::https://github.com/ryanoasis/nerd-fonts/releases/download/v${_nfver}/FontPatcher.zip"
"fonttune::git+${FONTTUNE_REPO:-https://github.com/gaou-piou/fonttune.git}#${FONTTUNE_REF:-branch=main}"
)
noextract=("font-patcher-${_nfver}.zip")
# gitiles builds the archive on every request and stamps each entry with the
# download time, so its checksum changes every time - even for a pinned commit.
# The archive is SKIPped here; prepare() checks the fonts themselves instead.
sha256sums=('SKIP'
'42bcb32145499a35732274c7fc48deb434ad0d2e0e118f98527c1479c6fa251a'
'SKIP')
# sha256 of the upstream TTFs (see the note above sha256sums). When Google
# updates the fonts, prepare() fails here: refresh this list and set pkgver to
# the new name ID 5 version.
_font_sums=(
'804fdad80c0a5bf7ea7a2396f7368abbcb4d948f31f0ac88b199dc4c18ef3391 GoogleSans-Bold.ttf'
'c22e02ace4469ff22340fc1c90c10e9414910f3dadf51e91c50445000b843bea GoogleSans-BoldItalic.ttf'
'011fbabfe51a86e81401ffa3eb87df74dec15ad38e75b9ade8460f6ca630e657 GoogleSans-Italic.ttf'
'8e72f9df72eddef9a75aa93b0972c35491bab52d65c32714fe004b75bd7b5271 GoogleSans-Medium.ttf'
'cefc41078b3da17b5c1aa9ccf8507b911e50b42005f70f18a7128eb47d3285f7 GoogleSans-MediumItalic.ttf'
'f8914b020e2c78fe86ca14198095455139f08047b8b52ab69003cb5af35cbbc0 GoogleSans-Regular.ttf'
'842e6578c478336a0ecd49ed7779bb67cd2dfb4188aff9a7e24fd6ed868eac2a GoogleSansDisplay-Bold.ttf'
'603682b81c56ddd52af4a22eb5e1f9d82cea836ea5d0016f1611a447b0a39569 GoogleSansDisplay-BoldItalic.ttf'
'4af7c400d97c640a2e12155734637f65beacc0a4c51853b676e785faae1af417 GoogleSansDisplay-Italic.ttf'
'40c1436cb0e94370dee18db4f09e3eb8e199713919adb33295536e6c26d9b74d GoogleSansDisplay-Medium.ttf'
'2419ca16947c7e974a537f8e887a73d67ec2c8ac7dd1f6fc47b1a22f4d56a68f GoogleSansDisplay-MediumItalic.ttf'
'c1b3bd356f209f250345f33413fe659d8f0634fb15bb2b640b2eee24708978fd GoogleSansDisplay-Regular.ttf'
)
# Google Sans and Google Sans Display (Google, Flutter gallery assets): six
# static TTFs each (Regular, Medium, Bold and their italics). Tuning (hinting,
# gasp, features baked into calt, ...) is done by fonttune, which asks in
# prepare(); every key can be preset as FONTTUNE_<KEY>. Local testing:
# `FONTTUNE_DEV=true` (see _ft_local).
#
# WANT_GOOGLE_SANS=true|false "Google Sans" (default true)
# WANT_GOOGLE_SANS_DISPLAY=true|false "Google Sans Display" (default true)
# NERD_PATCH=true patch with Nerd Fonts glyphs (default false)
# Local fonttune, uncommitted edits included, only with FONTTUNE_DEV=true: the
# tree in FONTTUNE_DEV_DIR, else the one saved by `fonttune dev set [path]`, else
# ../fonttune next to this PKGBUILD, else (with a note) the git source. Unset or
# false (AUR helpers): always the git source. A missing tree never stops the
# build. The tree is copied to $srcdir/fonttune-local; the git source and
# .SRCINFO stay as they are.
_ft() { if [[ -d "$srcdir/fonttune-local" ]]; then echo "$srcdir/fonttune-local"; else echo "$srcdir/fonttune"; fi; }
_ft_local() { # in prepare(): with FONTTUNE_DEV=true the local tree, if there is one
local _dev=${FONTTUNE_DEV-} _cf=${XDG_CONFIG_HOME:-$HOME/.config}/fonttune/dev _t
local -a _try=()
rm -rf "$srcdir/fonttune-local"
case "${_dev,,}" in
true|1|yes|on) ;;
''|false|0|no|off) return 0 ;;
*) echo "==> fonttune: FONTTUNE_DEV=$_dev is not true/false: building with the git source" \
"(the tree goes in FONTTUNE_DEV_DIR or \`fonttune dev set\`)" >&2
return 0 ;;
esac
[[ -n "${FONTTUNE_DEV_DIR-}" ]] && _try+=("$FONTTUNE_DEV_DIR")
[[ -r "$_cf" ]] && _try+=("$(<"$_cf")")
_try+=("$(realpath -m "$startdir/../fonttune")")
for _t in "${_try[@]}" ''; do
[[ -n "$_t" && -f "$_t/fonttune/__init__.py" ]] && break
done
if [[ -z "$_t" ]]; then
echo "==> fonttune: FONTTUNE_DEV=$_dev but no fonttune tree at ${_try[*]}: building with the git source" >&2
return 0
fi
mkdir "$srcdir/fonttune-local"
tar -C "$_t" --exclude=.git --exclude=__pycache__ -cf - . | tar -C "$srcdir/fonttune-local" -xf -
echo "local:$(git -C "$_t" describe --always --dirty 2>/dev/null || echo "$_t")" \
> "$srcdir/fonttune-local/.rev"
echo "==> fonttune: LOCAL tree $_t ($(<"$srcdir/fonttune-local/.rev"))" >&2
}
_ft_rev() { cat "$(_ft)/.rev" 2>/dev/null || git -C "$srcdir/fonttune" describe --always --dirty 2>/dev/null; }
_check_fonttune() {
local _api
_api=$(sed -nE 's/^API *= *([0-9]+).*/\1/p' "$(_ft)/fonttune/__init__.py")
if [[ "$_api" != "$_ftapi" ]]; then
echo "Error: fonttune API is '${_api:-?}', this PKGBUILD expects $_ftapi." >&2
echo " Update the PKGBUILD for the new fonttune, or pin FONTTUNE_REF=tag=<last-good>." >&2
exit 1
fi
}
_ask() { # _ask VAR "question" default(y|n): only on a TTY and when VAR is unset
local _v="$1" _a
[[ -n "${!_v:-}" ]] && return 0
if [[ -t 0 ]]; then
read -r -p "[$_v] $2 [$3] " _a
_a="${_a:-$3}"
else
_a="$3"
fi
[[ "$_a" =~ ^[yYtT] ]] && printf -v "$_v" true || printf -v "$_v" false
}
prepare() {
cd "$srcdir"
printf '%s\n' "${_font_sums[@]}" | sha256sum -c --quiet - || {
echo "Error: the upstream fonts changed - update _font_sums and pkgver." >&2; exit 1
}
_ft_local
_check_fonttune
_ask WANT_GOOGLE_SANS "Include Google Sans" y
_ask WANT_GOOGLE_SANS_DISPLAY "Include Google Sans Display" y
_ask NERD_PATCH "Patch with Nerd Fonts glyphs" n
if [[ "$WANT_GOOGLE_SANS$WANT_GOOGLE_SANS_DISPLAY" != *true* ]]; then
echo "Error: select at least one family." >&2; exit 1
fi
printf '%s\n' "$NERD_PATCH" > "$srcdir/.nerd"
rm -rf "$srcdir/selected" "$srcdir/font-patcher"; mkdir -p "$srcdir/selected"
if [[ "$WANT_GOOGLE_SANS" == true ]]; then cp "$srcdir"/GoogleSans-*.ttf "$srcdir/selected/"; fi
if [[ "$WANT_GOOGLE_SANS_DISPLAY" == true ]]; then cp "$srcdir"/GoogleSansDisplay-*.ttf "$srcdir/selected/"; fi
if [[ "$NERD_PATCH" == true ]]; then
mkdir -p "$srcdir/font-patcher"
bsdtar xf "$srcdir/font-patcher-${_nfver}.zip" -C "$srcdir/font-patcher"
fi
python "$(_ft)/bin/fonttune" configure --defaults clean \
--save-to "$srcdir/fonttune.toml" "$srcdir/selected/"*.ttf
}
build() {
_check_fonttune
local _src="$srcdir/selected"
if [[ "$(< "$srcdir/.nerd")" == true ]]; then
printf "%b" "\e[1;33m==> WARNING:\e[0m Patching with Nerd Fonts glyphs, this takes a while...\n"
rm -rf "$srcdir/patched"; mkdir -p "$srcdir/patched"
find "$srcdir/selected" -name '*.ttf' | sort | \
parallel --will-cite -j"$(nproc)" python "$srcdir/font-patcher/font-patcher" \
--variable-width-glyphs -q -c {} -out "$srcdir/patched" '>/dev/null'
compgen -G "$srcdir/patched/*.ttf" >/dev/null || { echo "Error: font-patcher produced no output." >&2; exit 1; }
parallel --will-cite -j"$(nproc)" python "$(_ft)/fonttune/steps/fix_names.py" ::: "$srcdir/patched/"*.ttf
_src="$srcdir/patched"
fi
python "$(_ft)/bin/fonttune" run --config "$srcdir/fonttune.toml" --in-place \
--fonts-conf "${GS_FONTS_CONF:-${XDG_CONFIG_HOME:-$HOME/.config}/fontconfig/fonts.conf}" \
--features-match '^Google Sans' "$_src/"*.ttf
echo "$_src" > "$srcdir/.out"
}
package() {
local _src; _src=$(< "$srcdir/.out")
local _fontdir="$pkgdir/usr/share/fonts/google-sans"
install -Dm644 -t "$_fontdir" "$_src/"*.ttf
install -d "$pkgdir/usr/share/licenses/$pkgname"
cat > "$pkgdir/usr/share/licenses/$pkgname/LICENSE" <<'EOF'
Google Sans fonts are proprietary fonts owned by Google LLC.
They are distributed as part of Google's Flutter gallery assets.
See https://flutter.googlesource.com/gallery-assets for details.
Nerd Fonts glyphs are licensed under their respective open-source licenses.
See https://github.com/ryanoasis/nerd-fonts for details.
EOF
install -d "$pkgdir/usr/share/doc/$pkgname"
_ft_rev > "$pkgdir/usr/share/doc/$pkgname/FONTTUNE_REV" 2>/dev/null || true
install -m644 "$srcdir/fonttune.toml" "$pkgdir/usr/share/doc/$pkgname/fonttune.toml"
if grep -q '^hint = "[a-z]' "$srcdir/fonttune.toml"; then
install -d "$pkgdir/usr/share/fontconfig/conf.avail"
python "$(_ft)/bin/fonttune" hintconf --name "$pkgname" \
-o "$pkgdir/usr/share/fontconfig/conf.avail/80-$pkgname.conf" "$_fontdir/"*.ttf
chmod 644 "$pkgdir/usr/share/fontconfig/conf.avail/80-$pkgname.conf"
fi
}
|