diff --git a/reaction_systems_gui/Cargo.toml b/reaction_systems_gui/Cargo.toml index 902ad08..788427e 100644 --- a/reaction_systems_gui/Cargo.toml +++ b/reaction_systems_gui/Cargo.toml @@ -15,6 +15,7 @@ colored = "*" lalrpop-util = "*" petgraph = ">=0.8" resvg = "*" +fontdb = "*" dyn-clone = "*" petgraph-graphml = "*" egui_node_graph2 = { path = "../egui_node_graph2" } diff --git a/reaction_systems_gui/src/app.rs b/reaction_systems_gui/src/app.rs index b4e8515..f775ffe 100644 --- a/reaction_systems_gui/src/app.rs +++ b/reaction_systems_gui/src/app.rs @@ -1981,7 +1981,7 @@ impl eframe::App for AppHandle { ); if let Err(e) = err { let text = get_layout(Err(e), &self.translator.lock().unwrap(), ctx); - self.cached_last_value = Some(content.clone()); + self.cached_last_value = Some(text); } else if let Some(l_b_v) = self.cache.get_last_state() { if let BasicValue::SaveBytes { path, value } = &l_b_v { use std::io::Write; @@ -1992,7 +1992,7 @@ impl eframe::App for AppHandle { return; } }; - if let Err(e) = write!(f, "{}", value) { + if let Err(e) = f.write_all(value) { println!("Error writing to file {path}: {e}"); return; } diff --git a/reaction_systems_gui/src/svg.rs b/reaction_systems_gui/src/svg.rs index 28d3571..615c050 100644 --- a/reaction_systems_gui/src/svg.rs +++ b/reaction_systems_gui/src/svg.rs @@ -21,6 +21,9 @@ pub(crate) struct Svg { impl Svg { pub(crate) fn parse_dot_string(dot_str: &str) -> Result { + let mut fontdb = fontdb::Database::new(); + fontdb.load_system_fonts(); + let mut parser = gv::DotParser::new(dot_str); let g = match parser.process() { Ok(g) => g, @@ -41,7 +44,15 @@ impl Svg { ); let content = svg.finalize(); - let svg_tree = match resvg::usvg::Tree::from_str(&content, &resvg::usvg::Options::default()) { + let svg_tree = match resvg::usvg::Tree::from_str( + &content, + &resvg::usvg::Options { + dpi: 92., + font_family: "Andale Mono".into(), + fontdb: Arc::new(fontdb), + ..Default::default() + } + ) { Ok(svg) => svg, Err(err) => return Err(format!("{}", err)), }; @@ -77,7 +88,14 @@ impl Svg { } pub(crate) fn rasterize(&self) -> Result, String> { - let svg_tree = match resvg::usvg::Tree::from_str(&self.original, &resvg::usvg::Options::default()) { + let svg_tree = match resvg::usvg::Tree::from_str( + &self.original, + &resvg::usvg::Options { + dpi: 92., + font_family: "Andale Mono".into(), + ..Default::default() + } + ) { Ok(svg) => svg, Err(err) => return Err(format!("{}", err)), };