From 1f2fea34274a48463bd781e570cd7be9594fc430 Mon Sep 17 00:00:00 2001 From: rob thijssen Date: Mon, 11 May 2026 16:17:17 +0300 Subject: [PATCH] fix: load system fonts for OG image text rendering usvg's default Options creates an empty fontdb, so no fonts are found for text rendering regardless of what's installed. Load system fonts into a fontdb::Database and set the default font family to Noto Sans. Also picks up a formatting change to index.html from a linter. Co-Authored-By: Claude Opus 4.6 (1M context) --- Cargo.toml | 1 + crates/moments-api/Cargo.toml | 1 + crates/moments-api/src/main.rs | 7 ++- ui/index.html | 81 +++++++++++++++++++++++++--------- 4 files changed, 67 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 99cd0c9..762f23b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ reqwest = { version = "0.12", default-features = false, features = ["rustls-tls" figment = { version = "0.10", features = ["toml", "env"] } clap = { version = "4", features = ["derive", "env"] } resvg = "0.45" +fontdb = "0.23" # internal moments-entities = { path = "crates/moments-entities", version = "=0.1.0" } diff --git a/crates/moments-api/Cargo.toml b/crates/moments-api/Cargo.toml index 3812de7..5048dcd 100644 --- a/crates/moments-api/Cargo.toml +++ b/crates/moments-api/Cargo.toml @@ -22,3 +22,4 @@ chrono.workspace = true clap.workspace = true reqwest.workspace = true resvg.workspace = true +fontdb.workspace = true diff --git a/crates/moments-api/src/main.rs b/crates/moments-api/src/main.rs index 88d6df1..0951a82 100644 --- a/crates/moments-api/src/main.rs +++ b/crates/moments-api/src/main.rs @@ -360,7 +360,12 @@ fn render_contributions_png( svg.push_str(""); // Rasterize at 1200x630 - let tree = resvg::usvg::Tree::from_str(&svg, &resvg::usvg::Options::default()) + let mut fontdb = fontdb::Database::new(); + fontdb.load_system_fonts(); + let mut opts = resvg::usvg::Options::default(); + opts.fontdb = std::sync::Arc::new(fontdb); + opts.font_family = "Noto Sans".to_owned(); + let tree = resvg::usvg::Tree::from_str(&svg, &opts) .map_err(|e| format!("svg parse: {e}"))?; let mut pixmap = diff --git a/ui/index.html b/ui/index.html index 73b1f26..7704df9 100644 --- a/ui/index.html +++ b/ui/index.html @@ -1,25 +1,62 @@ - - - - rob.tn - - - - - - - - - - - - - - - -
- - + + + + rob.tn + + + + + + + + + + + + + + + +
+ +