Review: report missing alt text on inserted icons

This commit is contained in:
cloutier
2026-11-25 08:55:18 -05:00
parent 02f7fcdf73
commit 2ee3785c5e
3 changed files with 48 additions and 1 deletions
+2
View File
@@ -275,6 +275,7 @@ fn insert_icon(s: &mut Session, p: &Value) -> Result<Value> {
if rect.w < 1.0 || rect.h < 1.0 {
return Err(bad("insert.icon", "rect needs a positive width and height"));
}
let (tag, value) = crate::icons::INSERTED_ICON_TAG;
let shape = Shape {
name: icon.label.to_string(),
xfrm: Some(rect),
@@ -296,6 +297,7 @@ fn insert_icon(s: &mut Session, p: &Value) -> Result<Value> {
..Default::default()
}),
style: Some(ShapeStyle::line(SchemeSlot::Tx1)),
tags: vec![(tag.into(), value.into())],
..Default::default()
};
let id = add_shape(s, "insert.icon", shape, true)?;
+1 -1
View File
@@ -261,7 +261,7 @@ fn accessibility(s: &mut Session, _p: &Value) -> Result<Value> {
| deckcraft_model::ShapeKind::Media(_)
| deckcraft_model::ShapeKind::Group { .. }
);
if needs_alt && sh.descr.trim().is_empty() && !sh.decorative {
if sh.descr.trim().is_empty() && !sh.decorative && (needs_alt || crate::icons::is_inserted_icon(sh)) {
out.push(json!({"slide": i, "shape": sh.id, "name": sh.name, "issue": "Missing alternative text"}));
}
});
+45
View File
@@ -12,6 +12,14 @@ use deckcraft_geom::{BezPath, PathEl};
/// Design size of every icon, in path units. Lucide's viewBox is `0 0 24 24`.
pub const VIEW: f64 = 24.0;
/// Shape tag that preserves gallery icon identity in native and PPTX files.
pub(crate) const INSERTED_ICON_TAG: (&str, &str) = ("DECKCRAFT_INSERTED_ICON", "1");
pub(crate) fn is_inserted_icon(shape: &deckcraft_model::Shape) -> bool {
let (name, value) = INSERTED_ICON_TAG;
shape.tags.iter().any(|(key, tag_value)| key == name && tag_value == value)
}
/// One icon from the Insert gallery.
pub struct Icon {
pub name: &'static str,
@@ -210,6 +218,43 @@ mod tests {
assert!((width - 8.0).abs() < 0.05, "{width}");
}
#[test]
fn missing_icon_alt_text_is_reported_after_round_trips() {
let mut s = Session::with_new();
let insert_icon = |s: &mut Session| s.execute("insert.icon", &json!({"name": "star"})).unwrap()["id"].as_u64().unwrap();
let missing = insert_icon(&mut s);
let described = insert_icon(&mut s);
let decorative = insert_icon(&mut s);
let freeform = s.execute("shape.freeform", &json!({"points": [[0, 0], [20, 10], [5, 25]], "closed": true})).unwrap()["id"].as_u64().unwrap();
s.execute("shape.rename", &json!({"ids": [freeform], "name": "Star"})).unwrap();
s.execute("shape.rename", &json!({"ids": [missing], "name": "Repainted symbol"})).unwrap();
s.execute("shape.altText", &json!({"ids": [described], "text": "Five-point outline"})).unwrap();
s.execute("shape.altText", &json!({"ids": [decorative], "decorative": true})).unwrap();
let assert_alert = |s: &mut Session| {
let issues = s.execute("review.accessibility", &json!({})).unwrap();
let shapes: Vec<_> = issues
.as_array()
.unwrap()
.iter()
.filter(|issue| issue["issue"] == "Missing alternative text")
.map(|issue| issue["shape"].as_u64().unwrap())
.collect();
assert_eq!(shapes, [missing], "{issues}");
};
assert_alert(&mut s);
let doc = &s.doc().unwrap().doc;
let native = deckcraft_format::load(&deckcraft_format::save(doc).unwrap()).unwrap();
let pptx = deckcraft_pptx::import(&deckcraft_pptx::export(doc).unwrap()).unwrap();
let second_pptx = deckcraft_pptx::import(&deckcraft_pptx::export(&pptx).unwrap()).unwrap();
for doc in [native, pptx, second_pptx] {
let mut reopened = Session::new();
reopened.add_document(crate::DocState::new(doc, None, "Reopened deck".into()));
assert_alert(&mut reopened);
}
}
fn ink_in(img: &deckcraft_render::Image, x: f64, y: f64, w: f64, h: f64, scale: f64) -> usize {
let x0 = (x * scale).floor().max(0.0) as u32;
let y0 = (y * scale).floor().max(0.0) as u32;