.ai graphs: Draw Filled Lines and its Line Width open live and save through the Gy record

A line graph whose style record draws its lines as shapes now opens as a
live graph with Draw Filled Lines on, and its lineShapeWidth becomes the
Line Width (3 pt reads as the default). The flag is ignored when the
points are not connected, as the published file format specification
says (printed pp. 147-148). Saving writes both values in the Gy record.

- Widths from 0.01 to 100 pt are kept. A wider Line Width, a width under
  0.01 pt with filled lines, and filled lines without connected points
  are saved as the graph's art with the existing warning.
- In a filled-line series, a filled path with the thin black band
  outline is read as a band and does not set the series stroke. A
  filled path with another outline must be a square marker or legend
  swatch; otherwise the graph keeps its art as plain objects.
- The reader in crates/eps/src/import/ai/read/graph.rs reads each value
  the writer in crates/eps/src/ai_graph.rs writes; the save-then-open
  tests cover the default, 8 pt and 150 pt widths in both .ai forms.
This commit is contained in:
dotCooCoo
2026-11-16 03:32:59 -08:00
parent ed6f22a84c
commit f8fe5f06e1
9 changed files with 356 additions and 49 deletions
+3
View File
@@ -575,6 +575,9 @@ pub const DEFAULT_FILLED_LINE_WIDTH: f64 = 3.0;
pub const MIN_FILLED_LINE_WIDTH: f64 = 0.01;
pub const MAX_FILLED_LINE_WIDTH: f64 = 1000.0;
/// The weight of the black outline Draw Filled Lines draws around each band, in points.
pub const FILLED_LINE_OUTLINE_WIDTH: f64 = 0.25;
impl GraphSpec {
/// How wide Draw Filled Lines draws a line, in points: [`Self::line_width`], else [`DEFAULT_FILLED_LINE_WIDTH`]. A
/// width a file gives outside [`MIN_FILLED_LINE_WIDTH`] to [`MAX_FILLED_LINE_WIDTH`], or not finite, draws the
+3 -2
View File
@@ -96,8 +96,9 @@ pub use compound_shape::ShapeMode;
pub use corners::LiveCorners;
pub use depth::{MAX_DEPTH, MAX_SYMBOL_NODES};
pub use graph::{
ColumnDesign, ColumnType, DEFAULT_FILLED_LINE_WIDTH, Fractions, GraphDesign, GraphKind, GraphSpec, LabelRows, LabelStyles, MAX_FILLED_LINE_WIDTH,
MAX_GRAPH_CATEGORIES, MAX_GRAPH_SERIES, MIN_FILLED_LINE_WIDTH, PiePosition, PieSort, SeriesPaint, TickLength, ValueAxisSide,
ColumnDesign, ColumnType, DEFAULT_FILLED_LINE_WIDTH, FILLED_LINE_OUTLINE_WIDTH, Fractions, GraphDesign, GraphKind, GraphSpec, LabelRows,
LabelStyles, MAX_FILLED_LINE_WIDTH, MAX_GRAPH_CATEGORIES, MAX_GRAPH_SERIES, MIN_FILLED_LINE_WIDTH, PiePosition, PieSort, SeriesPaint, TickLength,
ValueAxisSide,
};
pub use hit::{Hit, HitKind};
pub use links::{LinkInfo, PlacementOptions};
+1 -1
View File
@@ -244,7 +244,7 @@ impl Gen<'_> {
let slot = g.series_paints.get(s);
let fill =
slot.and_then(|p| p.fill.clone().or_else(|| p.stroke.clone().filter(|st| !st.is_none()))).unwrap_or_else(|| default_series_paint(s));
return self.path(band, fill, Paint::solid(Color::BLACK), 0.25);
return self.path(band, fill, Paint::solid(Color::BLACK), vectorcraft_doc::FILLED_LINE_OUTLINE_WIDTH);
}
let (fill, stroke, w) = series_marks(g, s, false, default_series_paint(s), 1.0);
self.path(pd, fill, stroke, w)
+43
View File
@@ -9505,6 +9505,49 @@ fn a_drawn_graph_saved_as_ai_opens_as_a_graph_unless_the_save_warns() {
}
}
/// A line graph the graph tools draw with Draw Filled Lines, saved as `.ai` in either form, opens again as the same graph
/// with its filled lines and Line Width, the default 3 pt included, and without a warning about graphs. A Line Width past
/// the records' 100 pt is saved as the graph's art, with the warning.
#[test]
fn a_drawn_graph_with_filled_lines_saved_as_ai_opens_with_them() {
let dir = vectorcraft_testkit::temp_dir("graph-ai-filled");
for (width, live) in [(None, true), (Some(8.0), true), (Some(150.0), false)] {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap();
let csv = ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,1,6";
let id = s.execute("graph.create", &json!({"type": "line", "x": 100, "y": 100, "width": 300, "height": 200, "csv": csv})).unwrap()["id"]
.as_u64()
.unwrap();
let mut options = json!({"id": id, "filledLines": true});
if let Some(w) = width {
options["lineWidth"] = json!(w);
}
s.execute("graph.setType", &options).unwrap();
let written = spec(&s, NodeId(id));
assert_eq!((written.filled_lines, written.line_width), (true, width));
for (name, version) in [("v7.ai", Some("7")), ("pdf.ai", None)] {
let path = dir.join(format!("{width:?}-{name}"));
let mut p = json!({"path": path, "format": "ai"});
if let Some(v) = version {
p["aiVersion"] = json!(v);
}
let r = s.execute("file.saveAs", &p).unwrap();
let notes = r["warnings"].as_array().cloned().unwrap_or_default();
let warned = notes.iter().any(|w| w.as_str().is_some_and(|w| w.starts_with("graphs are written as their art")));
assert_eq!(warned, !live, "{width:?} {name}: {r}");
let mut again = Session::new();
again.execute("document.open", &json!({"path": path})).unwrap();
let mut graphs = vec![];
again.doc().unwrap().doc.walk(|n| graphs.extend(n.extras().graph.as_deref().cloned()));
assert_eq!(graphs.len(), usize::from(live), "{width:?} {name}");
if let Some(g) = graphs.first() {
assert_eq!((g.kind, g.cells(), g.filled_lines, g.line_width), (written.kind, written.cells(), true, width), "{width:?} {name}");
assert_eq!(g.filled_line_width(), written.filled_line_width(), "{width:?} {name}");
}
}
}
}
/// A default legend swatch has the stroke paint and weight of its series' marks, beside the plot or across the top: the
/// thin white line of stacked columns and bars, areas and pie wedges, and none on columns and bars. A stroke color kept
/// on the series, with or without a weight of its own, is on the swatch too.
+147 -25
View File
@@ -17,8 +17,8 @@ use std::fmt::Write;
use kurbo::{PathSeg, Point};
use vectorcraft_color::{BlendMode, Paint};
use vectorcraft_doc::{
Appearance, AppearanceItem, GraphKind, GraphSpec, LabelStyles, MAX_GRAPH_CATEGORIES, MAX_GRAPH_SERIES, Node, NodeId, NodeKind, PiePosition,
PieSort, TickLength, ValueAxisSide,
Appearance, AppearanceItem, DEFAULT_FILLED_LINE_WIDTH, FILLED_LINE_OUTLINE_WIDTH, GraphKind, GraphSpec, LabelStyles, MAX_GRAPH_CATEGORIES,
MAX_GRAPH_SERIES, MIN_FILLED_LINE_WIDTH, Node, NodeId, NodeKind, PiePosition, PieSort, TickLength, ValueAxisSide,
};
use vectorcraft_effects::stroke;
use vectorcraft_geom::{Affine, Rect};
@@ -46,6 +46,9 @@ const EDGE: f64 = 0.01;
/// Most values one `Gc` takes.
const CELLS_PER_RECORD: usize = 15;
/// Widest `lineShapeWidth` the records give, in points (appendix A, `Gy`).
const MAX_LINE_WIDTH: f64 = 100.0;
/// A graph's records: what goes before its group (`%_Gs` to `%_GC`), and the `Go` line that follows
/// each series' group, by the group's id. `%_GS` follows the group.
pub(crate) struct Records {
@@ -89,7 +92,8 @@ pub(crate) fn records(n: &Node, to_art: Affine) -> Option<Records> {
(r.is_finite() && r.width() > 0.0 && r.height() > 0.0).then_some(())?;
let plot = to_art.transform_rect_bbox(r);
(plot.is_finite() && plot.width() > 0.0 && plot.height() > 0.0).then_some(())?;
let tags = series_groups(children, width, first_col, g.kind == GraphKind::Line)?;
let line = g.kind == GraphKind::Line;
let tags = series_groups(children, width, first_col, line, line && g.filled_lines)?;
draws_axes(n, r).then_some(())?;
let placed = n.geometric_bounds()?;
(r.x0 >= placed.x0 - EDGE && r.y0 >= placed.y0 - EDGE && r.x1 <= placed.x1 + EDGE && r.y1 <= placed.y1 + EDGE).then_some(())?;
@@ -97,14 +101,17 @@ pub(crate) fn records(n: &Node, to_art: Affine) -> Option<Records> {
let mut head = String::from("%_Gs\n");
let _ = writeln!(head, "%_{} {} {} {} Gb", real(plot.x0), real(plot.y1), real(plot.x1), real(plot.y0));
let flag = |b: bool| u8::from(b);
// `lineShapeWidth`: the width filled lines are drawn at, the graph's default included.
let _ = writeln!(
head,
"%_{ty} {} {} 14 {} {} 0 {} 6 44 Gy",
"%_{ty} {} {} 14 {} {} {} {} {} 44 Gy",
flag(g.drop_shadow),
flag(g.first_row_in_front),
flag(g.mark_points),
flag(g.connect_points),
flag(g.legend_across_top)
flag(g.filled_lines),
flag(g.legend_across_top),
real(g.line_width.unwrap_or(DEFAULT_FILLED_LINE_WIDTH))
);
let _ =
writeln!(head, "%_10 2 {} 0 {} {} {} Gd", flag(g.first_column_in_front), real(g.column_width), real(g.cluster_width), flag(g.edge_to_edge));
@@ -233,10 +240,11 @@ fn tick(t: TickLength) -> u8 {
}
/// Whether `g`'s settings are ones the records give and the reader keeps: a legend beside or across
/// the top, every series of the graph's type, one value axis on the left, lines not filled and no
/// Line Width of their own, no graph
/// designs, label formatting or pie settings, column and cluster widths of 1% to 1000%, and at most
/// [`MAX_TICK_MARKS`] tick marks a division.
/// the top, every series of the graph's type, one value axis on the left, lines filled only where
/// they connect the points (the records ignore the setting otherwise), a Line Width of 0.01 to
/// [`MAX_LINE_WIDTH`] points, with filled lines no series stroked as the bands' outline
/// ([`band_outline`]), which the reader reads as bands, no graph designs, label formatting or pie settings, column and
/// cluster widths of 1% to 1000%, and at most [`MAX_TICK_MARKS`] tick marks a division.
fn settings_kept(g: &GraphSpec) -> bool {
let percent = |p: f64| (1.0..=1000.0).contains(&p);
g.legend
@@ -244,8 +252,9 @@ fn settings_kept(g: &GraphSpec) -> bool {
&& g.value_axis == ValueAxisSide::Left
&& !g.separate_scales
&& g.right_series.is_empty()
&& !g.filled_lines
&& g.line_width.is_none()
&& (g.connect_points || !g.filled_lines)
&& g.line_width.is_none_or(|w| (MIN_FILLED_LINE_WIDTH..=MAX_LINE_WIDTH).contains(&w))
&& !(g.kind == GraphKind::Line && g.filled_lines && g.series_paints.iter().any(|p| band_outline(&p.stroke.clone().zip(p.stroke_width))))
&& g.series_markers.iter().all(Option::is_none)
&& g.series_columns.iter().all(Option::is_none)
&& g.label_styles == LabelStyles::default()
@@ -320,10 +329,13 @@ fn plain_paint(p: &Node) -> Option<(Option<Paint>, Option<(Paint, f64)>)> {
/// The `Go` line of each series' group among `children`: a group whose series index is one of the
/// `series` the table has, each once, of paths [`as_drawn`] with one fill and one line alike
/// ([`plain_paint`]), every path filled unless the graph draws lines (`line`). Its column is the
/// ([`plain_paint`]), every path filled unless the graph draws lines (`line`). With filled lines
/// (`bands`), a filled path outlined as [`band_outline`] says is a band, any other filled path is a
/// [`square`] marker or swatch, and the line of the paths that are not bands is the series' line,
/// as the reader reads it. Its column is the
/// table's: after the label column when there is one (`first_col`). `None` when a series has no
/// such group.
fn series_groups(children: &[std::sync::Arc<Node>], series: usize, first_col: usize, line: bool) -> Option<HashMap<NodeId, String>> {
fn series_groups(children: &[std::sync::Arc<Node>], series: usize, first_col: usize, line: bool, bands: bool) -> Option<HashMap<NodeId, String>> {
let mut tags = HashMap::new();
let mut seen = vec![false; series];
for c in children {
@@ -334,21 +346,63 @@ fn series_groups(children: &[std::sync::Arc<Node>], series: usize, first_col: us
*slot = true;
let NodeKind::Group { children: paths, clip: false } = &c.kind else { return None };
(as_drawn(c) && *c.appearance == Appearance::default() && !paths.is_empty()).then_some(())?;
let mut paints = vec![];
let (mut paints, mut strokes) = (vec![], vec![]);
for p in paths {
as_drawn(p).then_some(())?;
paints.push(plain_paint(p)?);
let (fill, outline) = plain_paint(p)?;
if bands && fill.is_some() && band_outline(&outline) {
// A band, or a mark outlined as one, which the reader reads as a band.
} else if bands && fill.is_some() && !square(p) {
return None;
} else {
strokes.push(outline);
}
paints.push(fill);
}
let fill = paints.iter().find_map(|(f, _)| f.clone());
paints.iter().all(|(f, _)| f.is_none() || *f == fill).then_some(())?;
(line || paints.iter().all(|(f, _)| f.is_some())).then_some(())?;
let stroke = paints.first().and_then(|(_, s)| s.clone());
paints.iter().all(|(_, s)| *s == stroke).then_some(())?;
let fill = paints.iter().find_map(Clone::clone);
paints.iter().all(|f| f.is_none() || *f == fill).then_some(())?;
(line || paints.iter().all(Option::is_some)).then_some(())?;
let stroke = strokes.first().cloned().flatten();
strokes.iter().all(|s| *s == stroke).then_some(())?;
tags.insert(c.id, format!("%_2 {} 0 0 Go", s + first_col));
}
seen.iter().all(|s| *s).then_some(tags)
}
/// Whether `stroke`, a path's line and its weight, is the thin black outline Draw Filled Lines
/// draws around a band, whatever the series' own line.
pub(crate) fn band_outline(stroke: &Option<(Paint, f64)>) -> bool {
stroke
.as_ref()
.is_some_and(|(paint, width)| *width == FILLED_LINE_OUTLINE_WIDTH && paint.color().is_some_and(|c| c.to_rgb_uncalibrated() == [0.0; 3]))
}
/// Whether path `p` is a square with sides along the page's axes, as a data point's default
/// marker and a legend swatch are: four straight sides, closed, as wide as it is tall. In a series
/// with filled lines, every other filled path is a band.
pub(crate) fn square(p: &Node) -> bool {
let NodeKind::Path { path, .. } = &p.kind else { return false };
if path.subpaths.iter().filter(|sp| !sp.anchors.is_empty()).count() != 1 {
return false;
}
let near = |a: f64, b: f64| (a - b).abs() <= EDGE;
let mut sides = vec![];
for s in path.to_bezpath().segments() {
let PathSeg::Line(l) = s else { return false };
if !(near(l.p0.x, l.p1.x) && near(l.p0.y, l.p1.y)) {
sides.push(l);
}
}
let [first, _, _, last] = sides.as_slice() else { return false };
let (x0, x1) = sides.iter().fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), l| (lo.min(l.p0.x), hi.max(l.p0.x)));
let (y0, y1) = sides.iter().fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), l| (lo.min(l.p0.y), hi.max(l.p0.y)));
near(last.p1.x, first.p0.x)
&& near(last.p1.y, first.p0.y)
&& sides.iter().all(|l| near(l.p0.x, l.p1.x) || near(l.p0.y, l.p1.y))
&& x1 - x0 > EDGE
&& near(x1 - x0, y1 - y0)
}
/// Whether `art` draws plot `plot`'s left edge and its bottom edge (the document's y runs down) as
/// straight lines, each a shown path of one subpath with a plain line ([`plain_paint`]) in a shown
/// group, as the reader finds the axes.
@@ -409,7 +463,8 @@ pub(crate) mod sample {
}
/// Graph `g` drawn as a group: a group of each series' marks (a line graph's series as an unfilled
/// line, the others' as filled columns), its axes on the plot's left and bottom edges, and a
/// line, or with filled lines as an outlined band and its markers, the others' as filled
/// columns), its axes on the plot's left and bottom edges, and a
/// legend of a swatch for each series; its series groups named after the series.
pub(crate) fn graph(doc: &mut Document, g: GraphSpec) -> Node {
let r = g.rect;
@@ -430,7 +485,27 @@ pub(crate) mod sample {
row.get(s).copied().flatten().map(|v| Point::new(r.x0 + 20.0 + 60.0 * c as f64 + 15.0 * s as f64, r.y1 - v * 10.0))
})
.collect();
let marks: Vec<Arc<Node>> = if g.kind == GraphKind::Line {
let marks: Vec<Arc<Node>> = if g.kind == GraphKind::Line && g.filled_lines {
// A band around the line, as wide as the Line Width, with the thin black outline, and a
// marker on each point.
let half = g.filled_line_width() / 2.0;
let mut bp = kurbo::BezPath::new();
for (i, p) in points.iter().enumerate() {
if i == 0 { bp.move_to((p.x, p.y - half)) } else { bp.line_to((p.x, p.y - half)) }
}
for p in points.iter().rev() {
bp.line_to((p.x, p.y + half));
}
bp.close_path();
let band = Node::path(
doc.alloc_id(),
PathData::from_bezpath(&bp),
Appearance::basic(gray.clone(), Paint::solid(Color::BLACK), super::FILLED_LINE_OUTLINE_WIDTH),
);
let mut marks = vec![Arc::new(band)];
marks.extend(points.iter().map(|p| path(doc, shapes::rectangle(Rect::from_center_size(*p, (5.0, 5.0))), gray.clone(), Paint::None)));
marks
} else if g.kind == GraphKind::Line {
let mut bp = kurbo::BezPath::new();
for (i, p) in points.iter().enumerate() {
if i == 0 { bp.move_to(*p) } else { bp.line_to(*p) }
@@ -472,7 +547,7 @@ pub(crate) mod sample {
/// Graphs whose records read back whole: each type the records give, every setting they keep
/// changed, labels with parentheses, backslashes and non-ASCII characters, a label of 255 bytes,
/// and a table without labels.
/// a table without labels, and line graphs with filled lines and Line Widths the records give.
pub(crate) fn kept() -> Vec<(&'static str, Document)> {
let mut cases = vec![
("column", document(spec(GraphKind::Column))),
@@ -497,6 +572,18 @@ pub(crate) mod sample {
let mut g = spec(GraphKind::Column);
(g.series, g.categories) = (vec![], vec![]);
cases.push(("no labels", document(g)));
let line = |f: &dyn Fn(&mut GraphSpec)| {
let mut g = spec(GraphKind::Line);
f(&mut g);
document(g)
};
cases.extend([
("filled lines", line(&|g| g.filled_lines = true)),
("filled lines 8 pt wide", line(&|g| (g.filled_lines, g.line_width) = (true, Some(8.0)))),
("filled lines 100 pt wide", line(&|g| (g.filled_lines, g.line_width) = (true, Some(100.0)))),
("filled lines 0.01 pt wide", line(&|g| (g.filled_lines, g.line_width) = (true, Some(0.01)))),
("a Line Width without filled lines", line(&|g| g.line_width = Some(8.0))),
]);
cases
}
@@ -515,8 +602,20 @@ pub(crate) mod sample {
.collect();
cases.extend([
("no legend", with(&|g| g.legend = false)),
("filled lines", with(&|g| (g.kind, g.filled_lines) = (GraphKind::Line, true))),
("a filled line width", with(&|g| (g.kind, g.line_width) = (GraphKind::Line, Some(8.0)))),
("a Line Width past 100 pt", with(&|g| (g.kind, g.filled_lines, g.line_width) = (GraphKind::Line, true, Some(150.0)))),
("a Line Width under 0.01 pt", with(&|g| (g.kind, g.filled_lines, g.line_width) = (GraphKind::Line, true, Some(0.001)))),
("filled lines without connected points", with(&|g| (g.kind, g.filled_lines, g.connect_points) = (GraphKind::Line, true, false))),
(
"filled lines with series stroked as their outline",
with(&|g| {
(g.kind, g.filled_lines) = (GraphKind::Line, true);
g.series_paints = vec![vectorcraft_doc::SeriesPaint {
stroke: Some(Paint::solid(Color::BLACK)),
stroke_width: Some(super::FILLED_LINE_OUTLINE_WIDTH),
..Default::default()
}];
}),
),
("a series of another type", with(&|g| g.series_kinds = vec![None, Some(GraphKind::Line)])),
("a marker design", with(&|g| g.series_markers = vec![Some("Star".into())])),
("a column design", with(&|g| g.series_columns = vec![Some(Default::default())])),
@@ -645,6 +744,29 @@ mod tests {
assert_eq!(marks, ["1", "1", "1"], "{head}");
}
/// A marker or swatch is a square along the page's axes; a band, a rotated square, a rectangle
/// of other proportions and an open path are not.
#[test]
fn markers_are_squares_and_bands_are_not() {
use vectorcraft_geom::shapes;
let node = |p: vectorcraft_geom::PathData| Node::path(NodeId(1), p, Appearance::default());
assert!(square(&node(shapes::rectangle(Rect::new(10.0, 10.0, 15.0, 15.0)))), "a 5 pt marker");
assert!(!square(&node(shapes::rectangle(Rect::new(10.0, 10.0, 60.0, 13.0)))), "a band along a level line");
let mut diamond = kurbo::BezPath::new();
diamond.move_to((0.0, 5.0));
diamond.line_to((5.0, 0.0));
diamond.line_to((10.0, 5.0));
diamond.line_to((5.0, 10.0));
diamond.close_path();
assert!(!square(&node(vectorcraft_geom::PathData::from_bezpath(&diamond))), "a rotated square");
let mut open = kurbo::BezPath::new();
open.move_to((0.0, 0.0));
for p in [(5.0, 0.0), (5.0, 5.0), (0.0, 5.0), (0.0, 1.0)] {
open.line_to(p);
}
assert!(!square(&node(vectorcraft_geom::PathData::from_bezpath(&open))), "an open path");
}
/// A table's cells go fifteen to a record, with one string at most in each.
#[test]
fn cells_go_fifteen_to_a_record_with_one_string_each() {
+92 -16
View File
@@ -14,10 +14,14 @@ use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use kurbo::{PathSeg, Point};
use vectorcraft_doc::{Appearance, GraphKind, GraphSpec, MAX_GRAPH_CATEGORIES, MAX_GRAPH_SERIES, SeriesPaint, TickLength};
use vectorcraft_doc::{
Appearance, DEFAULT_FILLED_LINE_WIDTH, GraphKind, GraphSpec, MAX_GRAPH_CATEGORIES, MAX_GRAPH_SERIES, MIN_FILLED_LINE_WIDTH, SeriesPaint,
TickLength,
};
use super::types::{GRAPH_OPS, GRAPH_PLAIN, GRAPH_UNENDED, Kind};
use super::{Affine, AppearanceItem, BlendMode, Node, NodeId, NodeKind, Paint, Reader, Rect, V, obj};
use crate::ai_graph::{band_outline, square};
/// Most cells of a graph's table, its label row and column included.
const MAX_CELLS: usize = 2_600_000;
@@ -293,11 +297,20 @@ impl Records {
self.spec.legend = true;
self.spec.mark_points = flag(marks)?;
self.spec.connect_points = flag(lines)?;
// Lines drawn as shapes have a width the model doesn't keep.
(!flag(shapes)?).then_some(())?;
self.spec.filled_lines = false;
// Lines drawn as shapes (Draw Filled Lines); without connected points the flag is ignored.
self.spec.filled_lines = flag(shapes)? && self.spec.connect_points;
self.spec.legend_across_top = flag(across)?;
finite(width).filter(|w| (0.0..=100.0).contains(w))?;
// `lineShapeWidth`, in points from 0 to 100. The model holds widths from 0.01 points, 3 points
// being its default; a smaller width is left out while the lines aren't filled, and keeps
// filled lines plain.
let width = finite(width).filter(|w| (0.0..=100.0).contains(w))?;
self.spec.line_width = if width == DEFAULT_FILLED_LINE_WIDTH {
None
} else if width >= MIN_FILLED_LINE_WIDTH {
Some(width)
} else {
(!self.spec.filled_lines).then_some(None)?
};
// 44: the series are measured against the left axis; 45 (right) isn't kept per series.
(int(axis)? == 44).then_some(())?;
if let Some([percentage, digits]) = pie {
@@ -471,9 +484,13 @@ fn as_drawn(n: &Node) -> bool {
/// Each series' fill and stroke, read from its group (`tags`), which holds paths only, one at
/// least: the paths with a fill share it, and every path has the same stroke or none. Only a line
/// graph (`line`) has paths without a fill: its lines. `None` when they differ, or the group, its
/// own appearance or a path is drawn otherwise than [`as_drawn`].
fn series_paints(art: &Node, tags: &HashMap<NodeId, u32>, line: bool) -> Option<Vec<SeriesPaint>> {
/// graph (`line`) has paths without a fill: its lines. With filled lines (`bands`), a filled path
/// outlined as [`band_outline`] says is a band or a mark drawn like one and gives no stroke; any
/// other filled path but a [`square`] marker or legend swatch is a band outlined otherwise. The
/// other paths give the series' stroke, and without them the series has none. `None` when they
/// differ, a band has another outline, or the group, its own appearance or a path is drawn
/// otherwise than [`as_drawn`].
fn series_paints(art: &Node, tags: &HashMap<NodeId, u32>, line: bool, bands: bool) -> Option<Vec<SeriesPaint>> {
let mut paints = vec![SeriesPaint::default(); tags.len()];
for group in art.children().into_iter().flatten() {
let Some(slot) = tags.get(&group.id).and_then(|i| paints.get_mut(usize::try_from(*i).ok()?)) else { continue };
@@ -483,8 +500,17 @@ fn series_paints(art: &Node, tags: &HashMap<NodeId, u32>, line: bool) -> Option<
let (mut fills, mut strokes) = (vec![], vec![]);
for p in &paths {
as_drawn(p).then_some(())?;
fills.extend(shown(p, true).ok()?);
strokes.push(shown(p, false).ok()?);
let filled = shown(p, true).ok()?;
let outline = shown(p, false).ok()?;
if bands && filled.is_some() && band_outline(&outline) {
// A band, or a mark outlined as one: the graph keeps no stroke for a series that draws bands.
} else if bands && filled.is_some() && !square(p) {
// A band outlined otherwise: the graph draws it again with the thin black outline only.
return None;
} else {
strokes.push(outline);
}
fills.extend(filled);
}
let fill = fills.first().map(|(paint, _)| paint.clone());
fills.iter().all(|(paint, _)| Some(paint) == fill.as_ref()).then_some(())?;
@@ -628,7 +654,8 @@ impl<'a> Reader<'a> {
if r.x0 < placed.x0 - EDGE || r.y0 < placed.y0 - EDGE || r.x1 > placed.x1 + EDGE || r.y1 > placed.y1 + EDGE {
return false;
}
let Some(paints) = series_paints(art, &tags, spec.kind == GraphKind::Line) else { return false };
let line = spec.kind == GraphKind::Line;
let Some(paints) = series_paints(art, &tags, line, line && spec.filled_lines) else { return false };
spec.series_paints = paints;
spec.placed = Some(placed);
spec.placed_art = art.children().and_then(|c| vectorcraft_doc::graph::graph_art_without_type(c));
@@ -646,6 +673,7 @@ impl<'a> Reader<'a> {
mod tests {
use super::*;
use vectorcraft_color::Color;
use vectorcraft_doc::FILLED_LINE_OUTLINE_WIDTH;
use vectorcraft_geom::shapes;
/// A graph's art: one series group (id 2) holding one mark painted `ap`, the group changed by
@@ -665,9 +693,57 @@ mod tests {
let mut two = one.clone();
two.items.extend(one.items.iter().find(|i| i.is_fill()).cloned());
let tags = HashMap::from([(NodeId(2), 0)]);
let kept = series_paints(&art(one, |_| {}), &tags, false).expect("one fill");
let kept = series_paints(&art(one, |_| {}), &tags, false, false).expect("one fill");
assert_eq!((kept[0].fill.as_ref(), kept[0].stroke.as_ref()), (Some(&red), Some(&Paint::None)));
assert!(series_paints(&art(two, |_| {}), &tags, false).is_none());
assert!(series_paints(&art(two, |_| {}), &tags, false, false).is_none());
}
/// With filled lines, a band's thin black outline is not the series' stroke: its markers' stroke
/// is, or none. A band outlined otherwise than its markers has no one stroke.
#[test]
fn a_filled_line_bands_outline_is_not_its_series_stroke() {
let red = Paint::solid(Color::rgb(1.0, 0.0, 0.0));
let series = |band: Appearance, marker: Appearance| {
let band = Arc::new(Node::path(NodeId(3), shapes::rectangle(Rect::new(0.0, 0.0, 50.0, 3.0)), band));
let marker = Arc::new(Node::path(NodeId(4), shapes::rectangle(Rect::new(0.0, 0.0, 5.0, 5.0)), marker));
Node::group(NodeId(1), vec![Arc::new(Node::group(NodeId(2), vec![band, marker]))])
};
let tags = HashMap::from([(NodeId(2), 0)]);
let outlined = Appearance::basic(red.clone(), Paint::solid(Color::cmyk(0.0, 0.0, 0.0, 1.0)), FILLED_LINE_OUTLINE_WIDTH);
let marker = Appearance::basic(red.clone(), Paint::None, 0.0);
let kept = series_paints(&series(outlined.clone(), marker.clone()), &tags, true, true).expect("a band and a marker");
assert_eq!((kept[0].fill.as_ref(), kept[0].stroke.as_ref(), kept[0].stroke_width), (Some(&red), Some(&Paint::None), None));
let blue = Paint::solid(Color::rgb(0.0, 0.0, 1.0));
let stroked = Appearance::basic(red.clone(), blue.clone(), 2.0);
let kept = series_paints(&series(outlined.clone(), stroked), &tags, true, true).expect("a band and a stroked marker");
assert_eq!((kept[0].stroke.as_ref(), kept[0].stroke_width), (Some(&blue), Some(2.0)));
let bands_only = Node::group(
NodeId(1),
vec![Arc::new(Node::group(
NodeId(2),
vec![Arc::new(Node::path(NodeId(3), shapes::rectangle(Rect::new(0.0, 0.0, 50.0, 3.0)), outlined.clone()))],
))],
);
let kept = series_paints(&bands_only, &tags, true, true).expect("a band alone");
assert_eq!((kept[0].stroke.as_ref(), kept[0].stroke_width), (Some(&Paint::None), None), "a band alone");
// A band as long as it is wide is a square, and still a band: its outline is not the series' stroke.
let square_band = |marker: Appearance| {
let band = Arc::new(Node::path(NodeId(3), shapes::rectangle(Rect::new(0.0, 0.0, 3.0, 3.0)), outlined.clone()));
let marker = Arc::new(Node::path(NodeId(4), shapes::rectangle(Rect::new(10.0, 0.0, 15.0, 5.0)), marker));
Node::group(NodeId(1), vec![Arc::new(Node::group(NodeId(2), vec![band, marker]))])
};
let kept = series_paints(&square_band(marker.clone()), &tags, true, true).expect("a square band and a marker");
assert_eq!((kept[0].stroke.as_ref(), kept[0].stroke_width), (Some(&Paint::None), None), "a square band");
assert!(series_paints(&series(outlined, marker.clone()), &tags, true, false).is_none(), "lines not filled");
let thick = Appearance::basic(red.clone(), Paint::solid(Color::BLACK), 1.0);
assert!(series_paints(&series(thick, marker), &tags, true, true).is_none(), "a 1 pt outline");
// A band outlined as its markers are stroked is drawn again with the thin black outline.
assert!(series_paints(&series(stroked_like(&blue), stroked_like(&blue)), &tags, true, true).is_none(), "a band outlined in blue");
}
/// A red mark stroked 2 pt in `paint`.
fn stroked_like(paint: &Paint) -> Appearance {
Appearance::basic(Paint::solid(Color::rgb(1.0, 0.0, 0.0)), paint.clone(), 2.0)
}
/// A series group that is hidden, see-through or in another blending mode is not drawn again so.
@@ -675,8 +751,8 @@ mod tests {
fn a_series_group_drawn_otherwise_has_no_series_paint() {
let ap = || Appearance::basic(Paint::solid(Color::rgb(1.0, 0.0, 0.0)), Paint::None, 0.0);
let tags = HashMap::from([(NodeId(2), 0)]);
assert!(series_paints(&art(ap(), |g| g.visible = false), &tags, false).is_none(), "hidden");
assert!(series_paints(&art(ap(), |g| g.opacity = 0.5), &tags, false).is_none(), "50% opaque");
assert!(series_paints(&art(ap(), |g| g.blend = BlendMode::Multiply), &tags, false).is_none(), "Multiply");
assert!(series_paints(&art(ap(), |g| g.visible = false), &tags, false, false).is_none(), "hidden");
assert!(series_paints(&art(ap(), |g| g.opacity = 0.5), &tags, false, false).is_none(), "50% opaque");
assert!(series_paints(&art(ap(), |g| g.blend = BlendMode::Multiply), &tags, false, false).is_none(), "Multiply");
}
}
+63 -1
View File
@@ -11381,6 +11381,68 @@ fn a_graphs_type_and_settings_come_from_its_records() {
assert!(art(&r.doc)[0].extras().graph.is_some());
}
/// A series of a line graph drawn with filled lines at `x`: a band filled with the series' color and
/// outlined in a thin black line, and a marker filled alike with no outline.
fn band_series(x: f64) -> String {
format!("0.5 0 0 0 k\n0 0 0 1 K\n0.25 w\n{}B\n1 w\n{}f\n", rect_path(x, 120.0, x + 40.0, 128.0), rect_path(x + 18.0, 122.0, x + 23.0, 127.0))
}
/// [`live_graph`] as a line graph with style record `style`, each series drawn by [`band_series`].
fn band_graph(style: &str) -> String {
live_graph().replace(LIVE_STYLE, style).replace(&series_bar(110.0), &band_series(110.0)).replace(&series_bar(140.0), &band_series(140.0))
}
/// A line graph whose lines are drawn as shapes (`drawLinesAsShapes` 1 with `drawLines` 1) keeps
/// Draw Filled Lines and its Line Width (`lineShapeWidth`, in points): 3 points is the graph's
/// default. Its series keep their bands' fill, and the bands' thin black outline is not taken as the
/// series' stroke. With `drawLines` 0 the flag is ignored, and the width is kept for later.
#[test]
fn a_line_graph_drawn_with_filled_lines_keeps_them_and_their_width() {
let live = |text: String| {
let r = read(stream7(&layer7("Graph", &text)).as_bytes()).unwrap();
assert!(r.warnings.is_empty(), "{text}: {:?}", r.warnings);
let a = art(&r.doc);
let g = a[0].extras().graph.clone().unwrap_or_else(|| panic!("{text}: a live graph"));
(g, live_graphs(&r.doc).1)
};
let (g, tagged) = live(band_graph("%_7 0 0 14 1 1 1 0 8 44 Gy\n"));
assert_eq!((g.kind, g.filled_lines, g.line_width, tagged), (GraphKind::Line, true, Some(8.0), 2));
let fill = Some(Paint::solid(Color::cmyk(0.5, 0.0, 0.0, 0.0)));
assert!(g.series_paints.iter().all(|p| p.fill == fill && p.stroke == Some(Paint::None) && p.stroke_width.is_none()), "{:?}", g.series_paints);
assert_eq!(live(band_graph("%_7 0 0 14 1 1 1 0 3 44 Gy\n")).0.line_width, None, "3 pt");
assert_eq!(live(band_graph("%_7 0 0 14 1 1 1 0 6 44 Gy\n")).0.line_width, Some(6.0), "6 pt");
assert_eq!(live(band_graph("%_7 0 0 14 1 1 1 0 100 44 Gy\n")).0.line_width, Some(100.0), "100 pt");
assert_eq!(live(band_graph("%_7 0 0 14 1 1 1 0 0.01 44 Gy\n")).0.line_width, Some(0.01), "0.01 pt");
// Without filled lines, the series are drawn as the graph's columns are.
let (g, _) = live(live_graph().replace(LIVE_STYLE, "%_7 0 0 14 1 0 1 0 8 44 Gy\n"));
assert_eq!((g.connect_points, g.filled_lines, g.line_width), (false, false, Some(8.0)), "points not connected");
let (g, _) = live(live_graph().replace(LIVE_STYLE, "%_7 0 0 14 1 1 0 0 0 44 Gy\n"));
assert_eq!((g.filled_lines, g.line_width), (false, None), "lines not filled, 0 pt");
}
/// A graph with filled lines whose Line Width the model doesn't hold (0, under 0.01 points, or out of
/// the records' 0 to 100), or with a lines-as-shapes value other than 0 and 1, keeps its drawn art
/// as plain objects, with one note.
#[test]
fn filled_lines_of_a_width_the_model_cant_hold_stay_plain_art() {
for style in [
"%_7 0 0 14 1 1 1 0 0 44 Gy\n",
"%_7 0 0 14 1 1 1 0 0.001 44 Gy\n",
"%_7 0 0 14 1 1 1 0 101 44 Gy\n",
"%_7 0 0 14 1 1 1 0 -2 44 Gy\n",
"%_7 0 0 14 1 1 1 0 1e999 44 Gy\n",
"%_7 0 0 14 1 1 0 0 101 44 Gy\n",
"%_7 0 0 14 1 1 2 0 8 44 Gy\n",
] {
let r = read(stream7(&layer7("Graph", &band_graph(style))).as_bytes()).unwrap_or_else(|e| panic!("{style}: {e}"));
assert_eq!(r.warnings, [GRAPH_PLAIN], "{style}");
assert_eq!(live_graphs(&r.doc), (vec![], 0), "{style}");
let mut kept = false;
r.doc.walk(|n| kept |= n.children().is_some_and(|c| c.len() == 3));
assert!(kept, "{style}: the drawn art is kept");
}
}
/// A graph keeps its drawn art and stays plain, with one note, when a record has a shape or value
/// appendix A doesn't give, sets what the model doesn't keep, or the table, the series tags or the
/// art don't fit the graph.
@@ -11396,7 +11458,7 @@ fn graphs_the_model_cant_keep_stay_plain_art() {
("type 11", live_graph().replace("%_5 0 0 14", "%_11 0 0 14")),
("legends in wedges", live_graph().replace("%_5 0 0 14", "%_5 0 0 15")),
("the right axis", live_graph().replace("6 44 Gy", "6 45 Gy")),
("lines as shapes", live_graph().replace("%_5 0 0 14 0 1 0", "%_5 0 0 14 0 1 1")),
("lines as shapes 0 pt wide", live_graph().replace("%_5 0 0 14 0 1 0 0 6", "%_5 0 0 14 0 1 1 0 0")),
("both axes alike", live_graph().replace(LIVE_DIALOG, "%_10 2 0 1 90 80 0 Gd\n")),
("a subscription", live_graph().replace(LIVE_DIALOG, &format!("{LIVE_DIALOG}%_0 0 1 1 1 Gj\n"))),
("a customization", live_graph().replace("GC\n", "GC\n%_2 Gt\n%_(Bars) GD\n%_GT\n")),
+3 -3
View File
@@ -2075,9 +2075,9 @@ were. `graph.setType` refuses `` `columnWidth` must be a number, not "50" `` for
`lineWidth`, the Line Width of Draw Filled Lines in points (3 when the graph sets none), takes a number from 0.01 to
1000 (VectorCraft's own range); `"4"` is refused with `` `lineWidth` must be a number, not "4" ``, and a width below
0.01 or past 1000 with `` `lineWidth` must be from 0.01 to 1000 pt, not 0 ``. The graph stores a width only when it is
not 3, so a graph without one is saved and drawn as before. A graph with a width of its own is written to `.ai` as its
art, without the editable graph records. `graph.setType` with options that leave the graph as it is
records no undo step.
not 3, so a graph without one is saved and drawn as before. In `.ai` the graph records carry Draw Filled Lines and
widths up to 100 pt; a graph with a wider Line Width is written to `.ai` as its art, without the editable graph
records. `graph.setType` with options that leave the graph as it is records no undo step.
`axisMin`, `axisMax`, `rightAxisMin` and `rightAxisMax` take a number, or null to go back to the value calculated from
the data; any other value is refused with `` `axisMin` must be a number or null, not "10" ``. `graph.setData` and
`graph.create` refuse a `csv` that is not a string, `series` or `categories` that are not lists, and `rows` that are not
+1 -1
View File
@@ -1882,7 +1882,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
A `.ai` opened from its editing data opens its Objects on Path groups live, with their path, their objects in order along it, Pivot and Rotate, and their art where the file draws it; a group whose spacing has been dragged, or with options an Objects on Path group doesn't hold, opens as a plain group (`crates/eps/src/import/ai/tests.rs`).
`.ai` symbol definitions and placed instances open as live symbols, in the Symbols panel's order; an instance of a symbol that isn't read, or whose appearance differs from its symbol's, comes in as the page draws it (`crates/eps/src/import/ai/tests.rs`).
In a `.ai` opened from its editing data, an object in a pattern's art or a brush's art with an art style VectorCraft reads opens as itself with its effects live, as an object on a layer does, and an object in a pattern's art keeps the id of a graphic style in the file's list (`crates/eps/src/import/ai/tests.rs`).
A graph in a `.ai` whose records have the shape and values the published version 7 specification gives ([the specification](https://13thmonkey.org/documentation/fonts/AI7FileFormat.pdf), printed pp. 109–112 and 146–158) opens as a live grouped column, stacked column, line or area graph with its saved art, table, axes and settings, and Graph Data edits it ([the help page](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/add-graph-data.html)); other graphs keep their art as plain objects with a note. Saving to `.ai` writes these records for a graph that reads back as the same graph, and warns that any other graph's data and settings aren't written (`crates/eps/src/import/ai/tests.rs`, `crates/engine/src/cmd/graph/tests.rs`).
A graph in a `.ai` whose records have the shape and values the published version 7 specification gives ([the specification](https://13thmonkey.org/documentation/fonts/AI7FileFormat.pdf), printed pp. 109–112 and 146–158) opens as a live grouped column, stacked column, line or area graph with its saved art, table, axes and settings, and Graph Data edits it ([the help page](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/add-graph-data.html)); other graphs keep their art as plain objects with a note. Saving to `.ai` writes these records for a graph that reads back as the same graph, and warns that any other graph's data and settings aren't written (`crates/eps/src/import/ai/tests.rs`, `crates/engine/src/cmd/graph/tests.rs`). A line graph drawn with Draw Filled Lines, which draws thicker filled lines when the points are connected ([the help page](https://helpx.adobe.com/illustrator/desktop/automate-visualize-data/visualize-data/format-columns-bars-and-lines.html)), opens and saves live with its Line Width through the style record's `drawLinesAsShapes` and `lineShapeWidth` (the specification, printed pp. 147–148: points from 0 to 100, ignored when the lines aren't drawn); widths from 0.01 to 100 pt are kept, and a graph with a wider Line Width is saved as its art with the warning.
Blends and envelopes in the definitions of a `.ai`'s symbols, patterns and brushes' art count against the same per-file limits on blend layout and envelope checks as the layers' art, so a file with many definitions does not get those limits again for each one (`crates/eps/src/import/ai/read/directives.rs`).
A `.ai` or EPS whose editing data has brushes opens with the file's Calligraphic, Scatter, Art and Bristle brushes in the Brushes panel in place of the default ones, in the file's order: the Calligraphic size, roundness and angle with their variation, the Scatter size, spacing, scatter and rotation, the Bristle settings, and the Scatter and Art brushes' art (Art brushes in the older and newer forms of their objects). A brush library `.ai` (brushes and no layers) opens from its PDF part with its brushes, so Other Library lists them. An Art brush in None or Tints keeps that colorization, and one in the newer form also keeps its fixed width, Flip Along and Flip Across, and Scale Proportionately, Stretch to Fit Stroke Length or Stretch Between Guides with its guides ([Art brush options](https://web.archive.org/web/20220911143322/https://helpx.adobe.com/pdf/cs6/illustrator_reference.pdf), printed page 193). Pattern brushes and brushes that can't be read are left out with a note. Paths with a Calligraphic brush, and paths with an Art brush in the newer form that bends art of solid-filled paths with those options, open as the path with the brush on its stroke, except paths whose brush scales its art proportionately. Paths with an Art brush in the older form, and other brushed paths, still come in as their drawn look (part of #372 and #637; `crates/eps/src/import/ai/tests.rs`, `crates/eps/src/import/tests_native.rs`).
In a `.ai` opened from its editing data, a path or type object with Offset Path, Outline Object or Outline Stroke on the whole object opens as itself with those effects live, in their order and shown or hidden; on a fill or stroke of type they stay on that fill or stroke. Offset Path keeps its Offset, Joins and Miter Limit, and Outline Stroke takes its width from the stroke. An Offset Path with a setting missing, out of range or not read keeps the drawn art, as does a path with a Path effect on one fill or stroke (`crates/eps/src/import/ai/style/tests.rs`, `crates/eps/src/import/ai/tests.rs`, `crates/eps/src/import/tests_native.rs`).