The headless browser for AI agents and web scraping
fix(render): cover SVG symbol glyphs with the embedded broad-coverage face
xrip4f8ef1e4b6db
diff --git a/Cargo.lock b/Cargo.lockindex d0c2d178..6a6cbad8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -2019,6 +2019,7 @@ dependencies = ["cosmic-text","cssparser","image",+ "log","obscura-dom","resvg","swash",diff --git a/crates/obscura-render/Cargo.toml b/crates/obscura-render/Cargo.tomlindex e450056b..4c8e19ec 100644--- a/crates/obscura-render/Cargo.toml+++ b/crates/obscura-render/Cargo.toml@@ -37,6 +37,11 @@ usvg = { version = "0.47", default-features = false, optional = true }url = { workspace = true, optional = true }cssparser = "0.34"wuff = { version = "0.2.7", optional = true }+# Same `log` instance usvg emits glyph-fallback warnings through, so tests can+# install a collector and assert on them.+[dev-dependencies]+log = "0.4"+[lib]path = "src/lib.rs"diff --git a/crates/obscura-render/src/paint.rs b/crates/obscura-render/src/paint.rsindex a87e242a..b8ea22bc 100644--- a/crates/obscura-render/src/paint.rs+++ b/crates/obscura-render/src/paint.rs@@ -10107,6 +10107,15 @@ fn svg_font_database() -> std::sync::Arc<usvg::fontdb::Database> {FONT_BOLD_OBLIQUE_BYTES,SERIF_FONT_BYTES,MONO_FONT_BYTES,+ // The Liberation families stop at Latin/Greek/Cyrillic: an SVG+ // text run with a symbol glyph (★/U+2605 and friends) had no face+ // covering it anywhere in the database, so usvg's per-glyph+ // fallback dropped the glyph and warned per character (#701).+ // DejaVu Sans is the same embedded broad-coverage face the HTML+ // engine already keeps for `system-ui`; family selection is+ // unchanged (Liberation stays the sans/serif/mono default), it+ // only extends what the fallback search can find.+ SYSTEM_FONT_BYTES,] {database.load_font_data(bytes.to_vec());}@@ -14672,6 +14681,61 @@ mod tests {);}+ #[test]+ fn svg_text_symbol_glyphs_resolve_in_the_font_database() {+ // The Liberation faces stop at Latin/Greek/Cyrillic: without a+ // broad-coverage face in the SVG database, usvg's per-glyph fallback+ // finds nothing for ★/U+2605, renders the .notdef tofu, and warns per+ // character (#701). Pixel presence cannot distinguish a real glyph+ // from tofu, so capture usvg's warnings while rasterizing a+ // symbol-bearing SVG text run through the same database the page+ // pipeline uses.+ static WARNINGS: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());+ struct SymbolWarningLogger;+ impl log::Log for SymbolWarningLogger {+ fn enabled(&self, _metadata: &log::Metadata) -> bool {+ true+ }+ fn log(&self, record: &log::Record) {+ if record.level() == log::Level::Warn {+ WARNINGS.lock().unwrap().push(record.args().to_string());+ }+ }+ fn flush(&self) {}+ }+ let _ = log::set_boxed_logger(Box::new(SymbolWarningLogger));+ log::set_max_level(log::LevelFilter::Warn);+ WARNINGS.lock().unwrap().clear();++ let svg = r##"<svg xmlns="http://www.w3.org/2000/svg" width="60" height="50">+ <text x="8" y="34" font-size="24" fill="#00cc55">★</text>+ <text x="8" y="4" font-size="24" fill="#00cc55">͸</text>+ </svg>"##;+ let pixmap = render_svg_with_font_database(svg.as_bytes(), 60, 50, &svg_font_database())+ .expect("raster");+ assert!(+ pixmap+ .pixels()+ .iter()+ .any(|pixel| pixel.green() > 150 && pixel.red() < 80 && pixel.blue() < 120),+ "the ★ text run should rasterize"+ );+ let warnings = WARNINGS.lock().unwrap();+ // Positive control first: an unassigned codepoint must still warn, so+ // the test fails loudly if the logger wiring breaks instead of+ // vacuously passing.+ assert!(+ warnings+ .iter()+ .any(|warning| warning.contains("U+378 character")),+ "the unassigned-codepoint control must warn: {warnings:?}"+ );+ assert!(+ !warnings.iter().any(|warning| warning.contains("U+2605")),+ "the SVG font database must cover ★ instead of dropping to .notdef: {warnings:?}"+ );+ }+#[test]fn injects_xmlns_only_when_absent() {let tree = parse_html(