From 506efa92fb05c6408b72cdda6493d4b17d0523ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 07:35:17 -0500 Subject: [PATCH 1/3] =?UTF-8?q?feat(symbology):=20Image=E2=80=A6=20lists?= =?UTF-8?q?=20SVG=20files,=20and=20an=20SVG=20marker=20image=20requires=20?= =?UTF-8?q?svg-markers=20(#2266)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rustgis-web/src/web.rs | 4 +- crates/engine/src/project.rs | 1 + crates/engine/src/project_capabilities.rs | 74 +++++++++++++++++++++-- crates/engine/src/tests.rs | 62 ++++++++++++++++++- crates/render/src/lib.rs | 6 ++ crates/render/src/picture.rs | 5 ++ crates/ui-egui/src/lib.rs | 4 ++ crates/ui-egui/src/markerpick.rs | 62 ++++++++++++++----- docs/maintaining.md | 4 +- docs/user-guide/cartography.md | 4 +- schema/fixtures/picture_markers_svg.rgis | 2 +- schema/project.schema.json | 6 +- 12 files changed, 207 insertions(+), 27 deletions(-) diff --git a/apps/rustgis-web/src/web.rs b/apps/rustgis-web/src/web.rs index 3ed3e78761..e0c7628e58 100644 --- a/apps/rustgis-web/src/web.rs +++ b/apps/rustgis-web/src/web.rs @@ -1405,7 +1405,9 @@ fn services(inbox: Inbox, font_inbox: Inbox, notes: Notes, ctx: egui::Context, e } else if purpose == "assistantPicture" { rfd::AsyncFileDialog::new() .add_filter(rustgis_ui_egui::tl!("Pictures"), rustgis_ui_egui::rustgis_assistant::attach::EXTENSIONS) - } else if purpose == "picture" || marker.is_some() { + } else if marker.is_some() { + rfd::AsyncFileDialog::new().add_filter(rustgis_ui_egui::tl!("Pictures"), rustgis_ui_egui::MARKER_EXTENSIONS) + } else if purpose == "picture" { rfd::AsyncFileDialog::new().add_filter(rustgis_ui_egui::tl!("Pictures"), &["png", "jpg", "jpeg"]) } else { rfd::AsyncFileDialog::new().add_filter( diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 90993f023d..136a9b3129 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -115,6 +115,7 @@ pub const CAPABILITIES: &[&str] = &[ PROJECT_CRS, "dggs-system", "label-clearance", + "svg-markers", ]; /// An offline area keeping the versions that lost a sync or a Bring Back /// (`OfflineArea::conflicts`, #2468): an older reader would save it again without them. diff --git a/crates/engine/src/project_capabilities.rs b/crates/engine/src/project_capabilities.rs index 5b3590e0ed..ec0cdf0a46 100644 --- a/crates/engine/src/project_capabilities.rs +++ b/crates/engine/src/project_capabilities.rs @@ -60,6 +60,9 @@ impl Project { if !required.contains(&"picture-markers") && self.styles.iter().any(|s| s.renderer.has_picture_markers()) { required.push("picture-markers"); } + if !required.contains(&"svg-markers") && self.styles.iter().any(|s| s.renderer.any_picture(svg_picture)) { + required.push("svg-markers"); + } // And its labels' weights (#2803): an older reader would apply the style without them. if !required.contains(&"label-weight") && self.styles.iter().any(|s| s.labels.in_order().any(|c| c.weight != rustgis_map::symbology::DEFAULT_LABEL_WEIGHT)) @@ -133,6 +136,7 @@ const COMMAND_CAPABILITIES: &[(&str, CommandCheck)] = &[ ("tabulate-intersection-empty-zones", command_uses_tabulate_empty_zones), ("layout-element-background", command_uses_element_background), ("picture-markers", command_uses_picture_marker), + ("svg-markers", command_uses_svg_marker), ("graticule-mgrs", command_draws_mgrs_graticule), ("graticule-on-top", command_puts_graticule_on_top), ("graticule-color", command_colors_graticule), @@ -533,18 +537,37 @@ fn tool_uses(tools: &[&str], id: &str, params: &Value, uses: fn(&Value) -> bool) /// `layer.marker`, a line stroke's markers or a dot fill given an image: an older reader would /// leave its `image` out and keep the marker it had, or refuse `"image"` as a mark. fn command_uses_picture_marker(id: &str, params: &Value) -> bool { - let any = |list: &str, image: fn(&Value) -> Option<&Value>| { - params.get(list).and_then(Value::as_array).is_some_and(|l| l.iter().any(|v| image(v).is_some_and(Value::is_string))) + command_sets_marker_image(id, params, |_| true) +} + +/// [`command_uses_picture_marker`] with an SVG (#2266 part E1b): a reader of PNG and JPEG markers +/// only would refuse the command. +fn command_uses_svg_marker(id: &str, params: &Value) -> bool { + command_sets_marker_image(id, params, rustgis_render::picture_marker_is_svg) +} + +/// Whether command `id` gives a marker an image (base64) that `image` holds true for. +fn command_sets_marker_image(id: &str, params: &Value, image: fn(&str) -> bool) -> bool { + let any = |list: &str, at: fn(&Value) -> Option<&Value>| { + params.get(list).and_then(Value::as_array).is_some_and(|l| l.iter().any(|v| at(v).and_then(Value::as_str).is_some_and(image))) }; match id { - "layer.marker" => params.get("image").is_some_and(Value::is_string), + "layer.marker" => params.get("image").and_then(Value::as_str).is_some_and(image), "layer.lineStrokes" => any("strokes", |st| st.get("markers")?.get("image")), "layer.fillLayers" => any("fills", |f| f.get("image")), - "script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_uses_picture_marker)), + "script.run" => params + .get("script") + .and_then(Value::as_str) + .is_some_and(|s| script_uses(s, |id, params| command_sets_marker_image(id, params, image))), _ => false, } } +/// Whether marker image `p` is an SVG ([`command_uses_svg_marker`]'s reason, for saved symbology). +fn svg_picture(p: rustgis_map::Picture) -> bool { + rustgis_render::picture_marker_is_svg(p.base64()) +} + /// Use the executor's line grammar; comments/invalid lines are not executable commands, and /// script_line refuses nested scripts, so this check cannot recurse through script.run. fn script_uses(script: &str, uses: impl Fn(&str, &Value) -> bool) -> bool { @@ -607,6 +630,7 @@ fn layer_capabilities(layer: &Layer) -> Vec<&'static str> { (relief_light(layer), "shaded-relief-light"), (layer.size_by.is_some(), super::SIZE_BY_CAPABILITY), (layer.has_picture_markers(), "picture-markers"), + (layer.any_picture(svg_picture), "svg-markers"), (zarr_window(layer), "zarr-window"), (label_guide(layer), "label-guide"), (label_weight(layer), "label-weight"), @@ -636,7 +660,7 @@ fn map_capabilities<'a>(maps: impl IntoIterator) -> Vec<&'static mut on_top, mut grid_color, ) = (false, false, false, false, false, false, false, false, false, false, false, false, false, false, false); - let mut polygon = false; + let (mut polygon, mut svg) = (false, false); let (mut offline_area_id, mut paper, mut native, mut guided, mut weighed, mut cleared) = (false, false, false, false, false, false); for map in maps { offline_area_id |= map.offline_area_id.is_some(); @@ -669,6 +693,7 @@ fn map_capabilities<'a>(maps: impl IntoIterator) -> Vec<&'static light |= map.layers.iter().any(relief_light); sized |= map.layers.iter().any(|layer| layer.size_by.is_some()); pictures |= map.layers.iter().any(Layer::has_picture_markers); + svg |= map.layers.iter().any(|layer| layer.any_picture(svg_picture)); zarr |= map.layers.iter().any(zarr_window); native |= map.layers.iter().any(|layer| held_natively(&layer.dataset)); legends |= map.tiles.iter().any(|tile| { @@ -688,6 +713,7 @@ fn map_capabilities<'a>(maps: impl IntoIterator) -> Vec<&'static (legends, "normalized-legend-urls"), (sized, super::SIZE_BY_CAPABILITY), (pictures, "picture-markers"), + (svg, "svg-markers"), (zarr, "zarr-window"), (guided, "label-guide"), (weighed, "label-weight"), @@ -888,6 +914,44 @@ mod tests { assert_eq!(serde_json::to_value(&fixture).unwrap()["requires"], json!(["dggs-system"])); } + /// A saved command that sets an SVG as a marker's image requires `svg-markers` as well as + /// `picture-markers`, in every replayable container: a reader of PNG and JPEG markers only + /// would refuse the command when it replays. A PNG requires `picture-markers` alone, and an + /// image that is neither is refused by the command anyway (#2266 part E1b). + #[test] + fn a_saved_command_setting_an_svg_marker_requires_svg_markers() { + use base64::Engine; + let svg = base64::engine::general_purpose::STANDARD.encode(r#""#); + let png = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGNgYGD4DwABBAEAwS2OUAAAAABJRU5ErkJggg=="; + let base = serde_json::to_value(Project::default()).unwrap(); + for (image, expected) in [(png.to_string(), vec!["picture-markers"]), (svg, vec!["picture-markers", "svg-markers"])] { + for (command, params) in [ + ("layer.marker", json!({"layer": "Cities", "image": image})), + ("layer.lineStrokes", json!({"layer": "Rivers", "strokes": [{"width": 1}, {"markers": {"image": image}}]})), + ("layer.fillLayers", json!({"layer": "Lakes", "fills": [{"pattern": "dots", "image": image}]})), + ] { + let script = format!("# Icons\n{command} {params}"); + for (field, value) in [ + ("tasks", json!([{"name": "Task", "steps": [{"title": "Icon", "command": command, "params": params}]}])), + ( + "tasks", + json!([{"name": "Script", "steps": [{"title": "Icon", "command": "script.run", "params": {"script": script}}]}]), + ), + ("notebooks", json!([{"name": "Notebook", "cells": [{"kind": "code", "source": script}]}])), + ( + "gp_history", + json!([{"tool": "Marker", "params": {}, "command": [command, params], "ok": true, "messages": [], "millis": 0}]), + ), + ] { + let mut document = base.clone(); + document[field] = value; + let project = Project::from_json(&document.to_string()).unwrap(); + assert_eq!(serde_json::to_value(&project).unwrap()["requires"], json!(expected), "{field} {command} {image}"); + } + } + } + } + /// All replayable project containers require non-default options only when requested. /// Selection of executable notebook cells follows the notebook runner's language boundary. #[test] diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 30bdc16be1..33e4626b1d 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -2738,6 +2738,66 @@ fn an_svg_picture_marker_fixture_opens_drawn_or_said() { }; assert!(rustgis_render::picture_marker_draws(picture(0))); assert!(picture(1).base64().starts_with("PHN2Zy") && !rustgis_render::picture_marker_draws(picture(1))); + // Saving names the SVGs for a reader of PNG and JPEG markers only to refuse (#2266 part E1b). + assert_eq!(serde_json::to_value(&s.project).unwrap()["requires"], json!(["picture-markers", "svg-markers"])); +} + +/// An SVG image marker requires `svg-markers` as well as `picture-markers` wherever it is saved: +/// a symbol's, a stroke's markers, a dot fill, what No Fill hid and a saved style, in a project, a +/// map file and a layer file. A reader of PNG and JPEG markers only would draw it as a circle. A +/// PNG, or an image that is neither, requires `picture-markers` alone (#2266 part E1b). +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn an_svg_image_marker_requires_svg_markers_wherever_it_is_saved() { + use base64::Engine; + let b64 = |bytes: &[u8]| base64::engine::general_purpose::STANDARD.encode(bytes); + let svg = b64(br##""##); + let mut png = Vec::new(); + image::RgbaImage::from_pixel(8, 4, image::Rgba([200, 30, 30, 255])) + .write_to(&mut std::io::Cursor::new(&mut png), image::ImageFormat::Png) + .unwrap(); + let png = b64(&png); + let pictures = json!(["picture-markers"]); + let both = json!(["picture-markers", "svg-markers"]); + let requires = |p: &Project| serde_json::to_value(p).unwrap()["requires"].clone(); + let dir = std::env::temp_dir().join(format!("rustgis-svg-markers-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let file = |s: &mut Session, command: &str, mut params: Value, name: &str| { + let path = dir.join(name); + params["path"] = json!(path.display().to_string()); + s.run(command, ¶ms).unwrap(); + serde_json::from_slice::(&std::fs::read(&path).unwrap()).unwrap()["requires"].clone() + }; + for (image, expected) in [(png.as_str(), &pictures), (svg.as_str(), &both), ("bm90IGFuIGltYWdl", &pictures)] { + // A symbol's (set directly: the command refuses an image that is neither), in the + // project, a map file and a layer file. + let mut s = world(); + let cities = s.map().layer_by_name("Cities").unwrap().id; + let picture = rustgis_map::Marker::Picture(rustgis_map::Picture::new(image)); + s.map_mut().layer_mut(cities).unwrap().renderer.map_symbols(|sym| sym.marker = picture); + assert_eq!(&requires(&s.project), expected, "symbol {image}"); + assert_eq!(&file(&mut s, "map.save", json!({}), "map.rgismap"), expected, "map file {image}"); + assert_eq!(&file(&mut s, "layer.save", json!({"layer": "Cities"}), "cities.rgislayer"), expected, "layer file {image}"); + // A saved style keeps it once the layer no longer does. + s.run("style.new", &json!({"layer": "Cities", "name": "Icons"})).unwrap(); + s.run("layer.marker", &json!({"layer": "Cities", "shape": "circle"})).unwrap(); + assert_eq!(&requires(&s.project), expected, "style {image}"); + } + for (image, expected) in [(&png, &pictures), (&svg, &both)] { + // A stroke's markers. + let mut s = world(); + s.run("layer.lineStrokes", &json!({"layer": "Rivers", "strokes": [{"width": 1}, {"markers": {"image": image}}]})).unwrap(); + assert_eq!(&requires(&s.project), expected, "stroke"); + assert_eq!(&file(&mut s, "layer.save", json!({"layer": "Rivers"}), "rivers.rgislayer"), expected, "stroke layer file"); + // A dot fill, and what No Fill hid of it. + let (mut s, id) = no_fill_layer(false); + s.run("layer.fillLayers", &json!({"layer": id, "fills": [{"pattern": "dots", "image": image}]})).unwrap(); + assert_eq!(&requires(&s.project), expected, "dot fill"); + s.run("layer.noFill", &Value::Null).unwrap(); + assert!(s.map().layer(id).unwrap().hidden_fills.is_some()); + assert_eq!(&requires(&s.project), expected, "hidden by No Fill"); + } + std::fs::remove_dir_all(&dir).ok(); } /// A saved image marker that is a GIF (which the desktop's decoder reads and the web's doesn't) @@ -26477,7 +26537,7 @@ fn an_arcgis_services_picture_markers_draw_their_images() { let texts: Vec<_> = s.notices.iter().map(|n| n.text.as_str()).collect(); let said = "Places: the service's symbology came in, except: picture markers whose image isn't a PNG, JPEG or SVG RustGIS reads, drawn as circles"; assert!(texts.contains(&said), "{texts:?}"); - assert_eq!(serde_json::to_value(&s.project).unwrap()["requires"], json!(["picture-markers"])); + assert_eq!(serde_json::to_value(&s.project).unwrap()["requires"], json!(["picture-markers", "svg-markers"])); } /// An ArcGIS layer's description, read before its features, doesn't count against their budget: diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index 62bc2ceb97..dbdd0dd976 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -630,6 +630,12 @@ pub fn picture_marker_kept_refusal(p: rustgis_map::Picture) -> Option bool { + picture::is_svg(b64) +} + /// Whether picture marker `p` draws rather than a circle ([`picture_marker_kept_check`]). pub fn picture_marker_draws(p: rustgis_map::Picture) -> bool { picture_marker_kept_check(p).is_ok() diff --git a/crates/render/src/picture.rs b/crates/render/src/picture.rs index 4bced884fc..7e0ec25321 100644 --- a/crates/render/src/picture.rs +++ b/crates/render/src/picture.rs @@ -564,6 +564,11 @@ enum Format { Svg, } +/// Whether base64 `b64` starts as an SVG would, as [`format`] tells it. +pub(crate) fn is_svg(b64: &str) -> bool { + format(b64) == Some(Format::Svg) +} + /// What base64 `b64` starts as, if a picture marker may be one. Picture markers take PNG, JPEG and /// SVG alone, on every platform: the desktop's decoder also reads GIF (the engine's `gif` feature, /// for raster files), the web's doesn't, so a GIF marker would draw on one and not the other. diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 0d1bb0fb2c..ec2381883f 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -227,6 +227,10 @@ pub const ASSISTANT_FILE_MAX_BYTES: usize = rustgis_assistant::attach::MAX_FILE_ /// refuse a larger one before reading it. pub const MARKER_FILE_MAX_BYTES: usize = rustgis_engine::map::symbology::MAX_PICTURE_BYTES / 4 * 3; +/// The files «Image…» lists for a marker, on the computer and in the browser (the phone's picker +/// lists every file). +pub const MARKER_EXTENSIONS: &[&str] = &["png", "jpg", "jpeg", "svg"]; + /// The largest script file the Script pane's Load… reads, as the assistant's command file; the /// browser's shell refuses a larger one before reading it. pub const SCRIPT_FILE_MAX_BYTES: usize = 1024 * 1024; diff --git a/crates/ui-egui/src/markerpick.rs b/crates/ui-egui/src/markerpick.rs index 17ef0d3fd0..558155551b 100644 --- a/crates/ui-egui/src/markerpick.rs +++ b/crates/ui-egui/src/markerpick.rs @@ -1,9 +1,9 @@ //! «Image…» in the marker menus (#2266 part B): the symbol editor's Shape, the stroke editor's -//! Shape and the fill editor's Marker each end with it, and it makes a PNG or JPEG file the +//! Shape and the fill editor's Marker each end with it, and it makes a PNG, JPEG or SVG file the //! marker. The file is read into the command that sets the marker (`layer.marker`, //! `layer.lineStrokes`, `layer.fillLayers`), which keeps the image as it does one given by -//! script. A file that isn't a PNG or JPEG, one too large, or one that doesn't decode is said in -//! a notice and leaves the marker as it was. +//! script. A file that isn't a PNG, JPEG or SVG, one too large, or one that doesn't decode or that +//! RustGIS doesn't draw is said in a notice and leaves the marker as it was. use std::io::Read; @@ -68,8 +68,8 @@ impl MarkerImage { } /// Runs the command with `bytes` as the image, as base64. A file that is too large, or that - /// doesn't decode as a PNG or JPEG (another format, or a broken one), is said in a notice in a - /// file's terms (the command's speak of base64) and runs nothing. + /// doesn't decode as a PNG, JPEG or SVG (another format, a broken one, or an SVG RustGIS doesn't + /// draw), is said in a notice in a file's terms (the command's speak of base64) and runs nothing. pub(crate) fn apply(mut self, app: &mut RustGisApp, bytes: &[u8]) -> Result { use base64::Engine; // The size first, so a file too large isn't decoded. @@ -80,13 +80,11 @@ impl MarkerImage { use rustgis_engine::render::MarkerRefusal; // One phrase per refusal, whole, for translation. rustgis_engine::render::picture_marker_check(b64).err().map(|why| match why { - MarkerRefusal::NotAnImage => tl!("This image can't be a marker: it isn't a readable PNG or JPEG").to_string(), + MarkerRefusal::NotAnImage => tl!("This image can't be a marker: it isn't a readable PNG, JPEG or SVG").to_string(), MarkerRefusal::TooManyPixels => crate::i18n::fmt( "This image can't be a marker: it has more pixels than {side} × {side}; make it smaller", &[("side", &rustgis_engine::render::MARKER_PIXELS_SIDE.to_string())], ), - // An SVG's (a file of another name holding one, as the picker lists PNG and - // JPEG). MarkerRefusal::TooMuchToDraw => crate::i18n::fmt( "This image can't be a marker: it is an SVG with more to draw than a {side} × {side} image", &[("side", &rustgis_engine::render::MARKER_PIXELS_SIDE.to_string())], @@ -145,7 +143,7 @@ impl MarkerImage { /// The marker menus' last entry, after the shapes (and Character): picks an image file as the /// marker, or another for the one it has (`on`). pub(crate) fn entry(ui: &mut Ui, on: bool) -> bool { - ui.selectable_label(on, tl!("Image…")).on_hover_text(tl!("A PNG or JPEG file as the marker")).clicked() + ui.selectable_label(on, tl!("Image…")).on_hover_text(tl!("A PNG, JPEG or SVG file as the marker")).clicked() } /// Asks for the image of `marker`: the system's dialog on a computer, read at once; the browser's @@ -159,7 +157,7 @@ pub(crate) fn pick(app: &mut RustGisApp, mut marker: MarkerImage) { let purpose = format!("marker:{}", marker.request); app.ui.pending_marker_image = Some(marker); open(&purpose); - } else if let Some(path) = crate::dialogs::pick_open(&["png", "jpg", "jpeg"], tl!("Pictures")) { + } else if let Some(path) = crate::dialogs::pick_open(crate::MARKER_EXTENSIONS, tl!("Pictures")) { match read_capped(&path) { Ok(bytes) => { let _ = marker.apply(app, &bytes); @@ -212,8 +210,8 @@ mod tests { pick(app, marker); } - /// The notice for a file that isn't a readable PNG or JPEG the marker can take. - const UNREADABLE: &str = "This image can't be a marker: it isn't a readable PNG or JPEG"; + /// The notice for a file that isn't a readable PNG, JPEG or SVG the marker can take. + const UNREADABLE: &str = "This image can't be a marker: it isn't a readable PNG, JPEG or SVG"; /// «Image…» makes the file the marker of a point symbol, of one mark in a stack of strokes /// (the others as they were) and of a dot fill, on the layer it was clicked for even when @@ -249,7 +247,7 @@ mod tests { assert!(matches!(now[1].pattern, FillPattern::Dots { marker, size: 5.0, .. } if drawn(marker))); } - /// A file that isn't a PNG or JPEG, a PNG that doesn't decode, or one too large, is said in a + /// A file that isn't a PNG, JPEG or SVG, a PNG that doesn't decode, or one too large, is said in a /// file's terms and changes nothing (no undo step either); a dialog cancelled changes nothing /// and says nothing. #[test] @@ -292,9 +290,45 @@ mod tests { assert_eq!(app.session.undo_depth(), steps); } + /// «Image…» lists SVG files beside PNG and JPEG ones, on the computer and in the browser, and + /// a picked SVG becomes the marker; one RustGIS doesn't draw (a filter) is said with why, and + /// text that isn't an image is said as not a PNG, JPEG or SVG; neither changes anything + /// (#2266 part E1b). + #[test] + fn a_picked_svg_becomes_the_marker_and_one_it_cant_draw_is_said() { + assert_eq!(crate::MARKER_EXTENSIONS, ["png", "jpg", "jpeg", "svg"]); + let dir = tempfile::tempdir().unwrap(); + let svg = |name: &str, body: &str| { + let path = dir.path().join(name); + std::fs::write(&path, format!(r#"{body}"#)).unwrap(); + path + }; + let pin = svg("pin.svg", r##""##); + let blurred = svg( + "blurred.svg", + r#""#, + ); + let text = dir.path().join("notes.svg"); + std::fs::write(&text, "not an image").unwrap(); + let mut app = RustGisApp::with_sample(); + let cities = id(&app, "Cities"); + let before = layer(&app, "Cities").renderer.base_symbol(); + let steps = app.session.undo_depth(); + let undrawn = "This image can't be a marker: it is an SVG with filters, text, images, animation or links to other files, which RustGIS doesn't draw in marker images"; + for (file, said) in [(&blurred, undrawn), (&text, UNREADABLE)] { + pick_file(&mut app, file, MarkerImage::symbol(cities)); + assert_eq!(layer(&app, "Cities").renderer.base_symbol(), before); + assert!(app.session.notices.iter().any(|n| n.error && n.text == said), "{said}: {:?}", app.session.notices); + } + assert_eq!(app.session.undo_depth(), steps); + pick_file(&mut app, &pin, MarkerImage::symbol(cities)); + assert!(drawn(layer(&app, "Cities").renderer.base_symbol().marker)); + assert_eq!(app.session.undo_depth(), steps + 1); + } + /// In the browser «Image…» asks the `"marker:"` picker for a file and the file it gives /// back, marked with its request, becomes the marker. A dropped PNG, or another picker's, - /// leaves the marker waiting; a marked file that isn't a PNG or JPEG is said and changes + /// leaves the marker waiting; a marked file that isn't a PNG, JPEG or SVG is said and changes /// nothing; an earlier request's file, arriving after another «Image…», is dropped; a file /// arriving after the map changed is said and changes nothing; a cancelled picker ends the /// wait. diff --git a/docs/maintaining.md b/docs/maintaining.md index 316d103338..c863fc80ff 100644 --- a/docs/maintaining.md +++ b/docs/maintaining.md @@ -127,7 +127,9 @@ Projects, map files and layer files whose symbology draws an image as a marker ( a symbol's, a stacked stroke's or a dot fill's, saved styles included), or whose replayable commands set one (an `image` in `layer.marker`, a `layer.lineStrokes` stroke's markers or a `layer.fillLayers` fill), require `picture-markers`: -an older reader must refuse them rather than fail on the marker or lose it. +an older reader must refuse them rather than fail on the marker or lose it. Where such an image +is an SVG, they also require `svg-markers`: a reader of PNG and JPEG markers only would draw it +as a circle and refuse the command that sets it. Projects, model files and web tools that save a percent-slope function require `slope-percent`: an older reader must refuse them rather than run the saved function in degrees. Project diff --git a/docs/user-guide/cartography.md b/docs/user-guide/cartography.md index 7f52afe621..f614caabcd 100644 --- a/docs/user-guide/cartography.md +++ b/docs/user-guide/cartography.md @@ -94,8 +94,8 @@ draws a circle, so the point still shows. By command: layer.marker={"layer":"Peaks","char":"▲","font":"DejaVu Sans","size":12} ``` -A marker can also be an **image**: a PNG or JPEG picked with **Image…** at the end of **Shape** -(choose it again for another image), or a PNG, JPEG or SVG given by command as base64 (at most +A marker can also be an **image**: a PNG, JPEG or SVG file picked with **Image…** at the end of +**Shape** (choose it again for another image), or given by command as base64 (at most 2 MiB of base64 text, an image of about 1.5 MiB). A PNG or JPEG may have at most 2048 × 2048 pixels (by area: a 4096 × 1024 strip is taken). Other formats, such as GIF, aren't taken: a file in another format, one too large, or one that doesn't decode is said in a notice, with why, and diff --git a/schema/fixtures/picture_markers_svg.rgis b/schema/fixtures/picture_markers_svg.rgis index 6040419e34..676a71f11f 100644 --- a/schema/fixtures/picture_markers_svg.rgis +++ b/schema/fixtures/picture_markers_svg.rgis @@ -1 +1 @@ -{"format":2,"name":"SVG picture markers","maps":[{"name":"Map","layers":[],"basemap":"Paper","camera":{"center":{"x":0.0,"y":2000000.0},"res":30000.0,"bearing":0.0,"pitch":0.0},"bookmarks":[],"graticule":true,"projection":"WebMercator","popup_mode":"Topmost","label_display":{"paused":false,"locked":false,"show_unplaced":false},"editing":{"relationships":[],"snapping":{"enabled":false,"tolerance_px":10.0,"vertex":true,"edge":true,"end":true},"topology":[],"settings":{"enabled":true,"show_vertices":true,"elevation":"None","ground_to_grid":null}},"swipe":null,"view":{"effects":{"stars":true,"sun_time":null,"weather":"None","vignette":false,"edges":false,"tilt_shift":false,"grain":false,"brightness":0.0,"contrast":0.0,"saturation":0.0,"sepia":0.0},"wireframe":false,"clip_distance":null,"terrain":null},"animation":[],"next_layer_id":1}],"active_map":0,"tables":[],"next_table_id":1,"gp_history":[],"layouts":[],"folders":[],"styles":[{"name":"Pins","geometry":"Point","renderer":{"Single":{"fill":[30,90,168,255],"stroke":[255,255,255,255],"stroke_width":0.0,"size":16.0,"marker":{"Picture":"PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAzMiI+PHBhdGggZD0iTTEyIDFDNiAxIDIgNS41IDIgMTFjMCA3LjUgMTAgMjAgMTAgMjBzMTAtMTIuNSAxMC0yMEMyMiA1LjUgMTggMSAxMiAxeiIgZmlsbD0iI2MwMTIyYSIvPjxjaXJjbGUgY3g9IjEyIiBjeT0iMTEiIHI9IjQiIGZpbGw9IiNmZmYiLz48L3N2Zz4="}}},"labels":{"enabled":false,"field":"","size":10.0,"color":[0,0,0,255],"halo":true,"bold":false},"transparency":0.0},{"name":"Glows","geometry":"Point","renderer":{"Single":{"fill":[30,90,168,255],"stroke":[255,255,255,255],"stroke_width":0.0,"size":16.0,"marker":{"Picture":"PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PGZpbHRlciBpZD0iZiI+PGZlR2F1c3NpYW5CbHVyIHN0ZERldmlhdGlvbj0iMiIvPjwvZmlsdGVyPjxjaXJjbGUgY3g9IjEyIiBjeT0iMTIiIHI9IjgiIGZpbGw9IiNmMGEwMDAiIGZpbHRlcj0idXJsKCNmKSIvPjwvc3ZnPg=="}}},"labels":{"enabled":false,"field":"","size":10.0,"color":[0,0,0,255],"halo":true,"bold":false},"transparency":0.0}],"ramps":[],"tasks":[],"gp_env":{"extent":null,"cell_size":null},"models":[],"workspaces":[],"link_views":false,"jobs":[],"offline_areas":[],"reports":[],"presentations":[],"notebooks":[],"dl_models":[],"shared":[],"data_stores":[],"requires":["picture-markers"]} +{"format":2,"name":"SVG picture markers","maps":[{"name":"Map","layers":[],"basemap":"Paper","camera":{"center":{"x":0.0,"y":2000000.0},"res":30000.0,"bearing":0.0,"pitch":0.0},"bookmarks":[],"graticule":true,"projection":"WebMercator","popup_mode":"Topmost","label_display":{"paused":false,"locked":false,"show_unplaced":false},"editing":{"relationships":[],"snapping":{"enabled":false,"tolerance_px":10.0,"vertex":true,"edge":true,"end":true},"topology":[],"settings":{"enabled":true,"show_vertices":true,"elevation":"None","ground_to_grid":null}},"swipe":null,"view":{"effects":{"stars":true,"sun_time":null,"weather":"None","vignette":false,"edges":false,"tilt_shift":false,"grain":false,"brightness":0.0,"contrast":0.0,"saturation":0.0,"sepia":0.0},"wireframe":false,"clip_distance":null,"terrain":null},"animation":[],"next_layer_id":1}],"active_map":0,"tables":[],"next_table_id":1,"gp_history":[],"layouts":[],"folders":[],"styles":[{"name":"Pins","geometry":"Point","renderer":{"Single":{"fill":[30,90,168,255],"stroke":[255,255,255,255],"stroke_width":0.0,"size":16.0,"marker":{"Picture":"PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAzMiI+PHBhdGggZD0iTTEyIDFDNiAxIDIgNS41IDIgMTFjMCA3LjUgMTAgMjAgMTAgMjBzMTAtMTIuNSAxMC0yMEMyMiA1LjUgMTggMSAxMiAxeiIgZmlsbD0iI2MwMTIyYSIvPjxjaXJjbGUgY3g9IjEyIiBjeT0iMTEiIHI9IjQiIGZpbGw9IiNmZmYiLz48L3N2Zz4="}}},"labels":{"enabled":false,"field":"","size":10.0,"color":[0,0,0,255],"halo":true,"bold":false},"transparency":0.0},{"name":"Glows","geometry":"Point","renderer":{"Single":{"fill":[30,90,168,255],"stroke":[255,255,255,255],"stroke_width":0.0,"size":16.0,"marker":{"Picture":"PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PGZpbHRlciBpZD0iZiI+PGZlR2F1c3NpYW5CbHVyIHN0ZERldmlhdGlvbj0iMiIvPjwvZmlsdGVyPjxjaXJjbGUgY3g9IjEyIiBjeT0iMTIiIHI9IjgiIGZpbGw9IiNmMGEwMDAiIGZpbHRlcj0idXJsKCNmKSIvPjwvc3ZnPg=="}}},"labels":{"enabled":false,"field":"","size":10.0,"color":[0,0,0,255],"halo":true,"bold":false},"transparency":0.0}],"ramps":[],"tasks":[],"gp_env":{"extent":null,"cell_size":null},"models":[],"workspaces":[],"link_views":false,"jobs":[],"offline_areas":[],"reports":[],"presentations":[],"notebooks":[],"dl_models":[],"shared":[],"data_stores":[],"requires":["picture-markers","svg-markers"]} diff --git a/schema/project.schema.json b/schema/project.schema.json index 69ecfcd3a9..4361402df2 100644 --- a/schema/project.schema.json +++ b/schema/project.schema.json @@ -1278,7 +1278,8 @@ "label-weight", "project-crs", "dggs-system", - "label-clearance" + "label-clearance", + "svg-markers" ], "type": "string" }, @@ -1385,7 +1386,8 @@ "label-weight", "project-crs", "dggs-system", - "label-clearance" + "label-clearance", + "svg-markers" ], "x-rustgis-reads-format": 2, "x-rustgis-writes-format": 2 From 7a13b06904c4315cf0df7f313134f8be2db2820e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 07:49:22 -0500 Subject: [PATCH 2/3] test(symbology): an SVG marker's svg-markers in map packages too, and its test cleans up however it ends (#2266) --- ROADMAP.md | 2 +- crates/engine/src/tests.rs | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index e9b8de528f..768679f71d 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -211,7 +211,7 @@ And alongside it: ([#995](https://github.com/opengeos/RustGIS/issues/995)); line labels that try other places along the line (an offset above or below it is done) ([#1187](https://github.com/opengeos/RustGIS/issues/1187)). - Kernel density (heat map) as a renderer; point clustering. -- SVG markers (PNG and JPEG pictures are done, +- QGIS SVG markers brought in by the style importer (PNG, JPEG and SVG pictures are done, [#2266](https://github.com/opengeos/RustGIS/issues/2266)), image fill patterns and a symbol library. - A legend and colour bar on the map (layouts have both). diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 33e4626b1d..1597c3077c 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -2760,10 +2760,18 @@ fn an_svg_image_marker_requires_svg_markers_wherever_it_is_saved() { let pictures = json!(["picture-markers"]); let both = json!(["picture-markers", "svg-markers"]); let requires = |p: &Project| serde_json::to_value(p).unwrap()["requires"].clone(); - let dir = std::env::temp_dir().join(format!("rustgis-svg-markers-{}", std::process::id())); - std::fs::create_dir_all(&dir).unwrap(); + // Removed however the test ends, and its own each run (the process id alone can repeat). + struct Dir(std::path::PathBuf); + impl Drop for Dir { + fn drop(&mut self) { + let _ = std::fs::remove_dir_all(&self.0); + } + } + let nanos = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_nanos()); + let dir = Dir(std::env::temp_dir().join(format!("rustgis-svg-markers-{}-{nanos}", std::process::id()))); + std::fs::create_dir_all(&dir.0).unwrap(); let file = |s: &mut Session, command: &str, mut params: Value, name: &str| { - let path = dir.join(name); + let path = dir.0.join(name); params["path"] = json!(path.display().to_string()); s.run(command, ¶ms).unwrap(); serde_json::from_slice::(&std::fs::read(&path).unwrap()).unwrap()["requires"].clone() @@ -2778,6 +2786,14 @@ fn an_svg_image_marker_requires_svg_markers_wherever_it_is_saved() { assert_eq!(&requires(&s.project), expected, "symbol {image}"); assert_eq!(&file(&mut s, "map.save", json!({}), "map.rgismap"), expected, "map file {image}"); assert_eq!(&file(&mut s, "layer.save", json!({"layer": "Cities"}), "cities.rgislayer"), expected, "layer file {image}"); + // And the map file a map package holds, for a computer and for a phone. + for mobile in [false, true] { + let pkg = dir.0.join("map.rgismpk"); + s.run("map.package", &json!({"path": pkg.display().to_string(), "mobile": mobile})).unwrap(); + let entries = rustgis_data::zip::read_matching(&std::fs::read(&pkg).unwrap(), |n| n.ends_with(".rgismap")).unwrap(); + let packed: Value = serde_json::from_slice(&entries[0].1).unwrap(); + assert_eq!(&packed["requires"], expected, "package {image}, mobile: {mobile}"); + } // A saved style keeps it once the layer no longer does. s.run("style.new", &json!({"layer": "Cities", "name": "Icons"})).unwrap(); s.run("layer.marker", &json!({"layer": "Cities", "shape": "circle"})).unwrap(); @@ -2797,7 +2813,6 @@ fn an_svg_image_marker_requires_svg_markers_wherever_it_is_saved() { assert!(s.map().layer(id).unwrap().hidden_fills.is_some()); assert_eq!(&requires(&s.project), expected, "hidden by No Fill"); } - std::fs::remove_dir_all(&dir).ok(); } /// A saved image marker that is a GIF (which the desktop's decoder reads and the web's doesn't) From 81b355bc5e58e0e90736280ad141b7057080473e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 24 Nov 2026 07:54:13 -0500 Subject: [PATCH 3/3] test(symbology): text that starts as XML counts as an SVG marker image (#2266) --- crates/engine/src/tests.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 1597c3077c..42331709e6 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -2745,7 +2745,8 @@ fn an_svg_picture_marker_fixture_opens_drawn_or_said() { /// An SVG image marker requires `svg-markers` as well as `picture-markers` wherever it is saved: /// a symbol's, a stroke's markers, a dot fill, what No Fill hid and a saved style, in a project, a /// map file and a layer file. A reader of PNG and JPEG markers only would draw it as a circle. A -/// PNG, or an image that is neither, requires `picture-markers` alone (#2266 part E1b). +/// PNG, or text that doesn't start as XML, requires `picture-markers` alone; text that starts as +/// XML counts as an SVG, as the renderer tells one, without reading it (#2266 part E1b). #[test] #[cfg(not(target_arch = "wasm32"))] fn an_svg_image_marker_requires_svg_markers_wherever_it_is_saved() { @@ -2776,7 +2777,8 @@ fn an_svg_image_marker_requires_svg_markers_wherever_it_is_saved() { s.run(command, ¶ms).unwrap(); serde_json::from_slice::(&std::fs::read(&path).unwrap()).unwrap()["requires"].clone() }; - for (image, expected) in [(png.as_str(), &pictures), (svg.as_str(), &both), ("bm90IGFuIGltYWdl", &pictures)] { + // ``: XML that isn't an SVG, which the renderer refuses when it reads it. + for (image, expected) in [(png.as_str(), &pictures), (svg.as_str(), &both), ("bm90IGFuIGltYWdl", &pictures), ("PGh0bWw+", &both)] { // A symbol's (set directly: the command refuses an image that is neither), in the // project, a map file and a layer file. let mut s = world();