Vendor Nunito as a TTF so the device renders in the right face

Slint cannot read woff2, which is the only form web/public/fonts/ carries, and Raspbian
has no fonts-nunito to install instead - so the device was going to fall back to
DejaVu Sans, which is not what any of this was drawn in. The upstream variable TTF
(SIL OFL, weights 200-1000) is small enough to vendor and covers every weight the
design uses, including the 800/900 the headings lean on.

SLINT_DEFAULT_FONT takes one file and makes it the primary font. shell.nix now points
at this copy rather than at nixpkgs' own, so development and the device render from the
identical file, and the binary falls back to finding it beside the executable when
neither the dev shell nor the device's launcher has set the variable.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-20 22:45:37 +02:00
parent 6ccb3e458f
commit ec9d617ad8
4 changed files with 34 additions and 13 deletions

View File

@@ -637,14 +637,28 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.unwrap_or_else(|| api::DEFAULT_BASE_URL.to_string());
println!("musicmouse-slint → {base}");
// Nunito is the face the design is drawn in. Slint takes one file as the primary
// font through `SLINT_DEFAULT_FONT`; the dev shell sets it, and a deployment can
// drop the TTF next to the binary instead. Neither present just means the system
// sans - a missing font should change how this looks, not whether it runs.
// Nunito is the face the design is drawn in, vendored as a TTF in `fonts/` because
// Slint cannot read the woff2 the web front-end self-hosts. Slint takes one file as
// the primary font through `SLINT_DEFAULT_FONT`; the dev shell and the device's
// launcher both set it, and this is the fallback for running the binary directly.
// None of them finding it just means the system sans - a missing font should change
// how this looks, not whether it runs.
if std::env::var_os("SLINT_DEFAULT_FONT").is_none() {
let local = std::path::Path::new("fonts/Nunito.ttf");
if local.exists() {
std::env::set_var("SLINT_DEFAULT_FONT", local);
let beside_exe = std::env::current_exe()
.ok()
// target/release/<bin> -> the crate root
.and_then(|exe| Some(exe.parent()?.parent()?.parent()?.join("fonts/Nunito.ttf")));
for candidate in [
Some(std::path::PathBuf::from("fonts/Nunito.ttf")),
beside_exe,
]
.into_iter()
.flatten()
{
if candidate.exists() {
std::env::set_var("SLINT_DEFAULT_FONT", candidate);
break;
}
}
}