//! Strokes on type in SVG: character stroke options on live text (and back), runs that differ //! from the first, and the object's own strokes drawn over the glyph outlines. // Integration tests: unwrapping and panicking on failure is fine here, unlike in shipped code (AGENTS.md › Robustness). #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] use vectorcraft_color::{Color, Paint}; use vectorcraft_doc::{AppearanceItem, CharStyle, Dash, Document, LineCap, LineJoin, Node, NodeKind, StrokeLayer, TextObject, TextRun}; use vectorcraft_geom::Point; use vectorcraft_svg::{ExportOptions, export, import}; fn text_doc(t: TextObject, items: Vec) -> Document { let mut d = Document::new(300.0, 200.0); let mut n = Node::new(d.alloc_id(), NodeKind::Text(Box::new(t))); n.appearance.items = items; let l = d.layers[0].id; d.insert(Some(l), 0, n).unwrap(); d } fn stroked() -> CharStyle { CharStyle { size: 40.0, stroke: Paint::solid(Color::BLACK), stroke_width: 2.0, stroke_cap: LineCap::Round, stroke_join: LineJoin::Round, stroke_dash: Some(Dash { pattern: vec![3.0, 1.0], ..Default::default() }), ..Default::default() } } #[test] fn an_object_stroke_on_type_is_written_with_its_dashes() { let mut st = StrokeLayer::new(Paint::solid(Color::rgb8(255, 0, 0)), 3.0); st.dash = Some(Dash { pattern: vec![4.0, 2.0], ..Default::default() }); st.opacity = 0.5; let t = TextObject::point(Point::new(20.0, 100.0), "Dashed", CharStyle { size: 40.0, ..Default::default() }); for outline_text in [false, true] { let svg = export(&text_doc(t.clone(), vec![AppearanceItem::Stroke(st.clone())]), &ExportOptions { outline_text, ..Default::default() }); assert!(svg.contains("stroke-dasharray=\"4 2\""), "{svg}"); assert!(svg.contains("stroke-opacity=\"0.5\""), "{svg}"); assert_eq!(svg.contains("").unwrap()]; assert!(!text.contains("stroke-width=\"4\""), "the live text doesn't stroke the aligned run: {text}"); assert!(text.contains("stroke-width=\"2\""), "a centred run keeps its stroke on the text: {text}"); assert!(svg[svg.find("").unwrap()..].contains("stroke-width=\"4\""), "the aligned stroke lies over the text"); } } } }