mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
Merge pull request #7365 from dotCooCoo/fix/ai-scatter-brush-art-upright
.ai import and save: Scatter brush art comes in turned over, as Art brush art does
This commit is contained in:
@@ -10255,6 +10255,40 @@ fn brush_art_of_a_straight_line_comes_back_as_the_line() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A Scatter brush's art is written turned over into its section (y up), so the side that is down the
|
||||
/// page in the brush's copies is up in the section: a triangle with its point down comes out with
|
||||
/// its point above its base, and comes back with its point down.
|
||||
#[test]
|
||||
fn a_scatter_brushs_art_is_written_turned_over() {
|
||||
use vectorcraft_brush::{Brush, BrushKind, Scatter};
|
||||
use vectorcraft_geom::{Point, SubPath};
|
||||
let point_down = PathData { subpaths: vec![SubPath::polyline(&[Point::new(0.0, 0.0), Point::new(40.0, 0.0), Point::new(20.0, 10.0)], true)] };
|
||||
let art = Node::path(vectorcraft_doc::NodeId(1), point_down, Appearance::basic(black_fill(), Paint::None, 0.0));
|
||||
let lib = vec![Brush { name: "Wedge".into(), kind: BrushKind::Scatter(Scatter { art, ..Scatter::default() }) }];
|
||||
let mut doc = Document::new(300.0, 200.0);
|
||||
vectorcraft_brush::store(&mut doc, &lib);
|
||||
let text = program(&doc);
|
||||
let start = text.find("%AI8_BeginBrushPattern").unwrap();
|
||||
let end = start + text[start..].find("%AI8_EndBrushPattern").unwrap();
|
||||
// The points of the frame and the triangle: the triangle's point is the one between the
|
||||
// frame's left and right edges.
|
||||
let points: Vec<(f64, f64)> = text[start..end]
|
||||
.lines()
|
||||
.filter_map(|l| l.strip_suffix(" m").or_else(|| l.strip_suffix(" L")))
|
||||
.filter_map(|l| {
|
||||
let mut n = l.split_whitespace().map(|v| v.parse::<f64>().ok());
|
||||
Some((n.next()??, n.next()??))
|
||||
})
|
||||
.collect();
|
||||
let (left, right) = points.iter().fold((f64::INFINITY, f64::NEG_INFINITY), |(l, r), p| (l.min(p.0), r.max(p.0)));
|
||||
let bottom = points.iter().map(|p| p.1).fold(f64::INFINITY, f64::min);
|
||||
let tip: Vec<f64> = points.iter().filter(|p| p.0 > left + 1e-3 && p.0 < right - 1e-3).map(|p| p.1).collect();
|
||||
assert!(!tip.is_empty() && tip.iter().all(|y| (y - bottom - 10.0).abs() < 1e-3), "the point is 10 above the base in the section: {points:?}");
|
||||
let back = vectorcraft_brush::library(&read_back(&doc));
|
||||
let (BrushKind::Scatter(got), BrushKind::Scatter(want)) = (&back[0].kind, &lib[0].kind) else { panic!("{back:?}") };
|
||||
assert!(same_tree(&art_tree(&got.art), &art_tree(&want.art)), "{:#?}", got.art);
|
||||
}
|
||||
|
||||
/// Brush art of a path with several subpaths is written as a compound path, which the reader reads as
|
||||
/// a compound path of one path for each subpath, and is weighed as the reader weighs that against the
|
||||
/// art it copies into one file's brushes: of two Art brushes whose art is a path of 30,000 squares,
|
||||
|
||||
@@ -401,11 +401,12 @@ impl Writer<'_> {
|
||||
fn brush_out(&mut self, b: &Brush) -> Option<BrushOut> {
|
||||
let plugin = crate::import::brush_plugin_name(&b.kind);
|
||||
let section = format!("Brush Art {}", self.brush_set.sections + 1);
|
||||
// The art as the reader reads it: a section is read with y down, and an Art brush's art is
|
||||
// turned over after that (its section's y up is the right of the path).
|
||||
// The art as the reader reads it: a section is read with y down, and a Scatter or Art
|
||||
// brush's art is turned over after that (its section's y up is down the page in each
|
||||
// Scatter copy and the right of the path in Art).
|
||||
let (params, art) = match &b.kind {
|
||||
BrushKind::Calligraphic(c) => (calligraphic_params(c), None),
|
||||
BrushKind::Scatter(s) => (scatter_params(s, §ion)?, Some((s.art.clone(), Affine::FLIP_Y))),
|
||||
BrushKind::Scatter(s) => (scatter_params(s, §ion)?, Some((s.art.clone(), Affine::IDENTITY))),
|
||||
BrushKind::Art(a) => (art_params(a, §ion)?, Some((a.art.clone(), Affine::IDENTITY))),
|
||||
BrushKind::Pattern(_) | BrushKind::Bristle(_) => return None,
|
||||
};
|
||||
|
||||
@@ -63,7 +63,7 @@ use std::sync::Arc;
|
||||
use kurbo::Affine;
|
||||
use vectorcraft_brush::{ArtBrush, ArtScale, Bristle, Brush, BrushKind, Calligraphic, Colorization, Scatter, Variation};
|
||||
use vectorcraft_color::Paint;
|
||||
use vectorcraft_doc::{AppearanceItem, Node, NodeKind};
|
||||
use vectorcraft_doc::{AppearanceItem, Node, NodeKind, Scaling};
|
||||
|
||||
use super::lex::{Lexer, Tok};
|
||||
use super::obj::Names;
|
||||
@@ -475,10 +475,11 @@ pub(super) fn parse_tool_object(kind: Tool, name: &str, params: &str) -> Result<
|
||||
Ok(BrushDraft { name: name.to_string(), kind })
|
||||
}
|
||||
|
||||
/// Turn `art` over (y for -y) with the art of all its opacity masks, those that don't move with
|
||||
/// their objects too: the art changes the space it is in, and no object moves over its mask.
|
||||
/// Turn `art` over (y for -y) with its pattern fills' tiles and the art of all its opacity masks,
|
||||
/// those that don't move with their objects too: the art changes the space it is in, and no object
|
||||
/// moves over its tiles or its mask.
|
||||
pub(crate) fn turn_over(art: &mut Node) {
|
||||
art.transform(Affine::scale_non_uniform(1.0, -1.0), false);
|
||||
art.transform(Affine::scale_non_uniform(1.0, -1.0), Scaling { patterns: true, ..Scaling::default() });
|
||||
turn_unlinked_masks(art);
|
||||
}
|
||||
|
||||
@@ -574,7 +575,12 @@ pub(super) fn finish_brushes_within(
|
||||
let kind = match d.kind {
|
||||
_ if !kept => None,
|
||||
DraftKind::Calligraphic(c) => Some(BrushKind::Calligraphic(c)),
|
||||
DraftKind::Scatter { brush, art: name } => copy(&name).map(|a| BrushKind::Scatter(Scatter { art: a, ..brush })),
|
||||
DraftKind::Scatter { brush, art: name } => copy(&name).map(|mut a| {
|
||||
// Each copy is the section turned over: its side with y up draws down the page
|
||||
// before the copy's rotation, and a brush draws art's y (down here) down the page.
|
||||
turn_over(&mut a);
|
||||
BrushKind::Scatter(Scatter { art: a, ..brush })
|
||||
}),
|
||||
DraftKind::Art { mut brush, art: name, settings } => copy(&name).map(|mut a| {
|
||||
// The side of the section with y up draws on the right of the path, and a brush
|
||||
// draws art's y (down here) on the left of the path.
|
||||
|
||||
@@ -10483,11 +10483,11 @@ fn a_brushs_art_places_a_version_7_patterns_tiles_with_its_operands() {
|
||||
};
|
||||
let plain = placed("0 0 1 1 0 0 0 0 0 [1 0 0 1 0 0]");
|
||||
// The operands and the move they make from the plain placement (a b c d e f): those of
|
||||
// `a_pattern_fill_applies_its_offset_scale_rotation_reflection_and_shear` with y down, as the
|
||||
// art's space has it.
|
||||
// `a_pattern_fill_applies_its_offset_scale_rotation_reflection_and_shear` in the file's own
|
||||
// space (y up), since a Scatter brush's art is turned over with its tiles.
|
||||
let cases = [
|
||||
("10 15 1 1 0 0 0 0 0 [1 0 0 1 0 0]", [1.0, 0.0, 0.0, 1.0, 10.0, -15.0]),
|
||||
("-5 7 2 .5 -45 0 0 -15 45 [1 0 0 1 0 0]", [1.793151, 0.353553, -1.035276, 0.353553, -5.0, -7.0]),
|
||||
("10 15 1 1 0 0 0 0 0 [1 0 0 1 0 0]", [1.0, 0.0, 0.0, 1.0, 10.0, 15.0]),
|
||||
("-5 7 2 .5 -45 0 0 -15 45 [1 0 0 1 0 0]", [1.793151, -0.353553, 1.035276, 0.353553, -5.0, 7.0]),
|
||||
];
|
||||
for (ops, want) in cases {
|
||||
let got = (placed(ops) * plain.inverse()).as_coeffs();
|
||||
@@ -11325,6 +11325,103 @@ fn type_with_an_art_brush_keeps_its_drawn_look() {
|
||||
assert_eq!(brushed, 0, "{:?}", r.warnings);
|
||||
}
|
||||
|
||||
/// Each copy a Scatter brush places is its section's art turned over before the copy's rotation:
|
||||
/// the side of the section with y up goes down the page with the rotation at 0° to the page, and
|
||||
/// to the right of the path's direction when the rotation follows the path. A rotation turns the
|
||||
/// copy counterclockwise on the page, from the page or from the path's direction.
|
||||
#[test]
|
||||
fn a_scatter_brushs_copies_are_its_art_turned_over() {
|
||||
// Size, spacing 100% and scatter 0%, fixed; the rotation 0° or 90°, to the page or following
|
||||
// the path.
|
||||
let still = "2 /Lopsided art/ 5 1 0 0 / 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0";
|
||||
let turned = "2 /Lopsided art/ 5 1 0 0 / 0 1 1 0 1 1 0 0 0 0 90 90 0 0 0";
|
||||
let along = "2 /Lopsided art/ 5 1 0 0 / 0 1 1 0 1 1 0 0 0 0 0 0 0 1 0";
|
||||
let def = format!(
|
||||
"{}{}{}{}",
|
||||
lopsided_art("Lopsided art"),
|
||||
plugin_object(SCATTER, "Still", still),
|
||||
plugin_object(SCATTER, "Turned", turned),
|
||||
plugin_object(SCATTER, "Along", along)
|
||||
);
|
||||
let r = read_ok(&format!("{def}{}", layer(&(rect_path(0.0, 0.0, 10.0, 10.0) + "f\n"))));
|
||||
let lib = vectorcraft_brush::library(&r.doc);
|
||||
let stroke = vectorcraft_doc::StrokeLayer::new(Paint::solid(Color::BLACK), 1.0);
|
||||
// The art is 40 by 8, so copies are 40 apart along a line 100 long, centered at 20, 60 and 100
|
||||
// from its start.
|
||||
let pieces = |name: &str, from: (f64, f64), to: (f64, f64)| {
|
||||
let b = lib.iter().find(|b| b.name == name).unwrap();
|
||||
let line = kurbo::BezPath::from_vec(vec![kurbo::PathEl::MoveTo(Point::new(from.0, from.1)), kurbo::PathEl::LineTo(Point::new(to.0, to.1))]);
|
||||
vectorcraft_brush::stroke_pieces(&r.doc, b, &line, &stroke)
|
||||
};
|
||||
let filled = |pieces: &[Node], x: f64, y: f64| {
|
||||
pieces.iter().any(|n| {
|
||||
let mut hit = false;
|
||||
n.walk(&mut |c| hit |= c.path_data().is_some_and(|p| kurbo::Shape::winding(&p.to_bezpath(), Point::new(x, y)) != 0));
|
||||
hit
|
||||
})
|
||||
};
|
||||
let still = pieces("Still", (0.0, 0.0), (100.0, 0.0));
|
||||
assert_eq!(still.len(), 3, "{still:#?}");
|
||||
// The copy at 60 spans 40 to 80: the narrow block is its first 10, the wide block all of it.
|
||||
assert!(filled(&still, 70.0, -2.0) && !filled(&still, 70.0, 2.0), "the wide block is above the line");
|
||||
assert!(filled(&still, 45.0, 2.0), "the narrow block is below it");
|
||||
// Turned 90° to the page, the copy at 60 stands across the line from 40 above it to 80 below
|
||||
// it: the wide block on the left, the narrow block on the right at its bottom 10.
|
||||
let turned = pieces("Turned", (0.0, 0.0), (100.0, 0.0));
|
||||
assert_eq!(turned.len(), 3, "{turned:#?}");
|
||||
assert!(filled(&turned, 58.0, 0.0) && !filled(&turned, 62.0, 0.0), "the wide block is left of the copy's middle");
|
||||
assert!(filled(&turned, 62.0, 15.0) && !filled(&turned, 62.0, -15.0), "the narrow block is at its bottom");
|
||||
// Right to left with the rotation following the path, the copy at 40 (20 to 60) is turned half
|
||||
// way round: its narrow block is its last 10.
|
||||
let along = pieces("Along", (100.0, 0.0), (0.0, 0.0));
|
||||
assert_eq!(along.len(), 3, "{along:#?}");
|
||||
assert!(filled(&along, 30.0, 2.0) && !filled(&along, 30.0, -2.0), "the wide block is below the line");
|
||||
assert!(filled(&along, 55.0, -2.0), "the narrow block is above it, at the copy's other end");
|
||||
// Up the page with the rotation following the path, the copy at y 40 (20 to 60) is turned a
|
||||
// quarter round: the wide block on the left of the line, the narrow block on its right at its
|
||||
// bottom 10, where the line starts.
|
||||
let up = pieces("Along", (0.0, 100.0), (0.0, 0.0));
|
||||
assert_eq!(up.len(), 3, "{up:#?}");
|
||||
assert!(filled(&up, -2.0, 40.0) && !filled(&up, 2.0, 40.0), "the wide block is left of the line");
|
||||
assert!(filled(&up, 2.0, 55.0) && !filled(&up, 2.0, 25.0), "the narrow block is right of it, at the copy's bottom");
|
||||
}
|
||||
|
||||
/// A pattern fill in a Scatter or Art brush's art is turned over with the art: the tiles keep their
|
||||
/// place on the art. The section fills a 40 by 8 rectangle with an 8-point tile placed with the
|
||||
/// identity, so the tile's top left is at the rectangle's top left in the section (y up).
|
||||
#[test]
|
||||
fn a_pattern_fill_in_brush_art_turns_over_with_the_art() {
|
||||
let still = "2 /Tiled art/ 5 1 0 0 / 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0";
|
||||
let ribbon = "2 / Tiled art/ / / / / 0 0/ 5 0 0 0 / 1 1 1 0 1 0 0 0 1 1 0 0 0 0 1";
|
||||
let section = format!(
|
||||
"%AI8_BeginBrushPattern\n(Tiled art)\n0 A\n(Dots) 0 0 1 1 0 0 0 0 0 [1 0 0 1 0 0] p\n{}f\n%AI8_EndBrushPattern\n",
|
||||
rect_path(0.0, 0.0, 40.0, 8.0)
|
||||
);
|
||||
let def = format!("{DOTS}{section}{}{}", plugin_object(SCATTER, "Spray", still), plugin_object(ART_BRUSH, "Ribbon", ribbon));
|
||||
let r = read_ok(&format!("{def}{}", layer(&(rect_path(0.0, 0.0, 10.0, 10.0) + "f\n"))));
|
||||
let lib = vectorcraft_brush::library(&r.doc);
|
||||
for name in ["Spray", "Ribbon"] {
|
||||
let b = lib.iter().find(|b| b.name == name).unwrap_or_else(|| panic!("{name}: {lib:?}"));
|
||||
let art = match &b.kind {
|
||||
vectorcraft_brush::BrushKind::Scatter(s) => &s.art,
|
||||
vectorcraft_brush::BrushKind::Art(a) => &a.art,
|
||||
k => panic!("{name}: {k:?}"),
|
||||
};
|
||||
let mut found = None;
|
||||
art.walk(&mut |n| {
|
||||
if let (Some(_), Paint::Pattern { xf, .. }) = (n.path_data(), fill(n)) {
|
||||
found = Some((n.geometric_bounds(), xf));
|
||||
}
|
||||
});
|
||||
let Some((Some(bounds), xf)) = found else { panic!("{name}: {art:#?}") };
|
||||
// The art is turned over (y up again): the tile's top left (0, 0) and its dot (4, 4), in
|
||||
// the tile's space with y down, are at the rectangle's top left and 4 below it.
|
||||
assert_eq!(bounds, Rect::new(0.0, 0.0, 40.0, 8.0), "{name}");
|
||||
assert!((xf * Point::ZERO - Point::new(0.0, bounds.y1)).hypot() < 1e-9, "{name}: {xf:?}");
|
||||
assert!((xf * Point::new(4.0, 4.0) - Point::new(4.0, bounds.y1 - 4.0)).hypot() < 1e-9, "{name}: {xf:?}");
|
||||
}
|
||||
}
|
||||
|
||||
use read::{GRAPH_PLAIN, GRAPH_UNENDED};
|
||||
use vectorcraft_doc::{GraphKind, TickLength};
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2021,6 +2021,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
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 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`).
|
||||
In a `.ai` or EPS opened from its editing data, a Scatter brush's art comes in turned over from its section, as an Art brush's does: each copy draws the side of the section with y up down the page before the copy's rotation. The `.ai` writer writes Scatter art back the same way (`crates/eps/src/import/ai/tests.rs`, `crates/eps/src/ai_editing/tests.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`).
|
||||
In a `.ai` or EPS opened from its editing data, a Scatter brush whose last 15 numbers start with 1 comes into the Brushes panel in Tints, and each brush art section is read without its frame, an unnamed, unpainted rectangle with no settings of its own at the art's bounds (within 1/1000 pt). A wider frame stays in the art, and an art group with a state or look of its own (hidden, locked, isolated, knockout, an opacity, a blend mode, a name, a mask, a note or an appearance) stays a group (`crates/eps/src/import/ai/tests.rs`).
|
||||
|
||||
Reference in New Issue
Block a user