mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 08:26:28 +00:00
AI editing data: write Perceptual gradients with the stops on their curve
A gradient definition in the .ai editing data holds each stop's color, opacity, midpoint and ramp point, and VectorCraft's reader opens it as a Classic gradient. A Perceptual gradient was written with its own stops, so the file opened with different colors between them. The writer now treats a Perceptual gradient as it treats a gradient mixed around the hue wheel, in the art and in the Swatches panel: the colors on its curve become stops of their own in process colors, at most 256, with a warning that names Perceptual gradients. A stop linked to a global process color reports its lost link for both methods. Dither is reported as its own loss. A freeform gradient, or one with more than 256 stops, is still written as its average color whatever its method.
This commit is contained in:
@@ -158,8 +158,9 @@
|
||||
//! art, the character and paragraph attributes the text document doesn't hold, freeform gradients, gradients
|
||||
//! along or across a stroke and gradients without stops, with more than 256 stops or without extent
|
||||
//! as their average color
|
||||
//! (gradients that dither or mix perceptually are written as classic ones, and gradient stops linked
|
||||
//! to global process colors as their colors), pattern fills whose tiles aren't a grid, whose art reaches past
|
||||
//! (gradients that dither are written without dither's noise, Perceptual gradients and gradients
|
||||
//! mixed around the hue wheel as the stops on their curve in process colors, at most 256, and
|
||||
//! gradient stops linked to global process colors as their colors), pattern fills whose tiles aren't a grid, whose art reaches past
|
||||
//! the tile or is painted with patterns, and pattern fills in symbols, as their tiles cut
|
||||
//! to the shape, clipping groups and clipping layers whose clipping object isn't a path,
|
||||
//! and the clipping groups inside them, as their art cut to that object (its fill cut too, its
|
||||
|
||||
@@ -2632,23 +2632,29 @@ fn a_clipping_path_keeps_its_gradient() {
|
||||
|
||||
#[test]
|
||||
fn freeform_gradients_are_written_as_their_average_color() {
|
||||
let mut doc = Document::new(200.0, 100.0);
|
||||
let layer = doc.layers[0].id;
|
||||
let g = ramp(GradientKind::Freeform, &[(0.0, Color::rgb(1.0, 1.0, 1.0), 1.0, 0.5), (1.0, Color::rgb(0.0, 0.0, 0.0), 1.0, 0.5)]);
|
||||
let n = painted(
|
||||
&mut doc,
|
||||
shapes::rectangle(Rect::new(10.0, 10.0, 30.0, 30.0)),
|
||||
vec![AppearanceItem::Fill(FillLayer::new(gradient_paint(g, None, None)))],
|
||||
);
|
||||
doc.insert(Some(layer), usize::MAX, n).unwrap();
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert!(out.warnings.iter().any(|w| w == writer::GRADIENTS), "{:?}", out.warnings);
|
||||
let back = read_back(&doc);
|
||||
assert_eq!(paint(back.layers[0].children().unwrap()[0].appearance.items[0].paint()), paint(&solid(Color::rgb(0.5, 0.5, 0.5))));
|
||||
use vectorcraft_color::gradient::GradientMethod;
|
||||
// The average of its points' colors, whatever its method.
|
||||
for method in [GradientMethod::Classic, GradientMethod::Perceptual, GradientMethod::HueClockwise] {
|
||||
let mut doc = Document::new(200.0, 100.0);
|
||||
let layer = doc.layers[0].id;
|
||||
let mut g = ramp(GradientKind::Freeform, &[(0.0, Color::rgb(1.0, 1.0, 1.0), 1.0, 0.5), (1.0, Color::rgb(0.0, 0.0, 0.0), 1.0, 0.5)]);
|
||||
g.method = method;
|
||||
let n = painted(
|
||||
&mut doc,
|
||||
shapes::rectangle(Rect::new(10.0, 10.0, 30.0, 30.0)),
|
||||
vec![AppearanceItem::Fill(FillLayer::new(gradient_paint(g, None, None)))],
|
||||
);
|
||||
doc.insert(Some(layer), usize::MAX, n).unwrap();
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert_eq!(out.warnings, [writer::GRADIENTS], "{method:?}");
|
||||
let back = read_back(&doc);
|
||||
assert_eq!(paint(back.layers[0].children().unwrap()[0].appearance.items[0].paint()), paint(&solid(Color::rgb(0.5, 0.5, 0.5))), "{method:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A gradient that dithers or mixes perceptually is written as a classic one; a stop linked to a
|
||||
/// global process color is written as its color; each with a warning.
|
||||
/// A gradient that dithers is written without its noise; a Perceptual gradient or one mixed around
|
||||
/// the hue wheel as the stops on its curve; a stop linked to a global process color as its color;
|
||||
/// each with a warning.
|
||||
#[test]
|
||||
fn gradient_options_and_links_the_data_cant_hold_are_reported() {
|
||||
let mut doc = Document::new(200.0, 100.0);
|
||||
@@ -2662,7 +2668,7 @@ fn gradient_options_and_links_the_data_cant_hold_are_reported() {
|
||||
);
|
||||
doc.insert(Some(layer), usize::MAX, n).unwrap();
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert_eq!(out.warnings, [writer::GRADIENT_MIX]);
|
||||
assert_eq!(out.warnings, [writer::GRADIENT_DITHER]);
|
||||
// A swatch of such a gradient that nothing uses.
|
||||
let mut swatch_only = Document::new(200.0, 100.0);
|
||||
let mut dithered = sunset();
|
||||
@@ -2671,7 +2677,7 @@ fn gradient_options_and_links_the_data_cant_hold_are_reported() {
|
||||
swatches.push(Swatch { name: "Dithered".into(), paint: gradient_paint(dithered, None, None), global: false, spot: false });
|
||||
swatch_only.swatches = swatches.into();
|
||||
let out = export_ai_editing(&swatch_only, &opts()).unwrap();
|
||||
assert!(out.warnings.iter().any(|w| w == writer::GRADIENT_MIX), "{:?}", out.warnings);
|
||||
assert!(out.warnings.iter().any(|w| w == writer::GRADIENT_DITHER), "{:?}", out.warnings);
|
||||
// A gradient along a stroke: the stroke's outline in its average color.
|
||||
let mut along = Document::new(200.0, 100.0);
|
||||
let layer = along.layers[0].id;
|
||||
@@ -2698,7 +2704,7 @@ fn gradient_options_and_links_the_data_cant_hold_are_reported() {
|
||||
);
|
||||
doc.insert(Some(layer), usize::MAX, n).unwrap();
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert_eq!(out.warnings, [writer::GRADIENT_MIX, writer::STOP_LINKS]);
|
||||
assert_eq!(out.warnings, [writer::GRADIENT_PERCEPTUAL, writer::STOP_LINKS]);
|
||||
let back = read_back(&doc);
|
||||
let Paint::Gradient(g) = back.layers[0].children().unwrap()[0].appearance.items[0].paint() else { panic!("a gradient") };
|
||||
assert_eq!((color(&g.gradient.stops[0].color), g.gradient.stops[0].swatch.as_deref()), (color(&BRAND), None));
|
||||
@@ -2732,6 +2738,124 @@ fn gradient_options_and_links_the_data_cant_hold_are_reported() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Do `got`'s colors and opacities lie within 0.03 of `want`'s along the whole ramp?
|
||||
fn same_curve(want: &Gradient, got: &Gradient, what: &str) {
|
||||
for k in 0..=100 {
|
||||
let t = k as f32 / 100.0;
|
||||
let ((a, ao), (b, bo)) = (want.sample(t), got.sample(t));
|
||||
let (a, b) = (a.to_rgb(), b.to_rgb());
|
||||
assert!(a.iter().zip(b).all(|(x, y)| (x - y).abs() < 0.03) && (ao - bo).abs() < 0.03, "{what} at {t}: {a:?} {ao} vs {b:?} {bo}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The data's gradients mix their stops' colors directly: a Perceptual gradient swatch is written
|
||||
/// under its name as a classic gradient of the stops on its curve, no more than the reader reads,
|
||||
/// and art painted with it uses that definition; both open with the colors they had, with a
|
||||
/// warning. With Dither, dither's loss is reported as well. A Classic gradient keeps its own stops
|
||||
/// without either warning.
|
||||
#[test]
|
||||
fn perceptual_gradients_are_written_with_the_stops_on_their_curve() {
|
||||
use vectorcraft_color::gradient::GradientMethod;
|
||||
let classic = sunset();
|
||||
let want = Gradient { method: GradientMethod::Perceptual, ..classic.clone() };
|
||||
// The same stops mixed directly stray from the Perceptual curve.
|
||||
assert!(
|
||||
(0..=100).any(|k| {
|
||||
let t = k as f32 / 100.0;
|
||||
want.sample(t).0.to_rgb().iter().zip(classic.sample(t).0.to_rgb()).any(|(a, b)| (a - b).abs() > 0.05)
|
||||
}),
|
||||
"the methods mix alike"
|
||||
);
|
||||
let gradient_names =
|
||||
|doc: &Document| -> Vec<String> { program(doc).lines().filter_map(|l| l.strip_prefix("%AI5_BeginGradient: ")).map(String::from).collect() };
|
||||
let with = |g: &Gradient, swatch: Option<&str>| {
|
||||
let mut doc = Document::new(200.0, 100.0);
|
||||
let layer = doc.layers[0].id;
|
||||
let mut swatches: Vec<Swatch> = doc.swatches.iter().cloned().collect();
|
||||
swatches.push(Swatch { name: "Dusk".into(), paint: gradient_paint(g.clone(), None, None), global: false, spot: false });
|
||||
doc.swatches = swatches.into();
|
||||
let n = painted(
|
||||
&mut doc,
|
||||
shapes::rectangle(Rect::new(10.0, 10.0, 30.0, 30.0)),
|
||||
vec![AppearanceItem::Fill(FillLayer::new(gradient_paint(g.clone(), None, swatch)))],
|
||||
);
|
||||
doc.insert(Some(layer), usize::MAX, n).unwrap();
|
||||
doc
|
||||
};
|
||||
|
||||
let doc = with(&want, Some("Dusk"));
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert_eq!(out.warnings, [writer::GRADIENT_PERCEPTUAL]);
|
||||
let names = gradient_names(&doc);
|
||||
assert!(names.iter().any(|n| n == "(Dusk)") && !names.iter().any(|n| n == "(Gradient)"), "the art uses the swatch's definition: {names:?}");
|
||||
let back = read_back(&doc);
|
||||
let Some(Paint::Gradient(swatch)) = back.swatch("Dusk").map(|s| &s.paint) else { panic!("the swatch is lost") };
|
||||
assert!(swatch.gradient.method.is_classic());
|
||||
let written = swatch.gradient.stops.len();
|
||||
assert!((want.stops.len() + 1..=crate::import::MAX_GRADIENT_STOPS).contains(&written), "{written} stops");
|
||||
same_curve(&want, &swatch.gradient, "the swatch");
|
||||
let Paint::Gradient(fill) = back.layers[0].children().unwrap()[0].appearance.items[0].paint() else { panic!("a gradient") };
|
||||
assert_eq!(fill.gradient.stops.len(), written);
|
||||
same_curve(&want, &fill.gradient, "the fill");
|
||||
|
||||
// Perceptual with Dither: both losses.
|
||||
let dithered = Gradient { dither: true, ..want.clone() };
|
||||
let doc = with(&dithered, None);
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert_eq!(out.warnings, [writer::GRADIENT_PERCEPTUAL, writer::GRADIENT_DITHER]);
|
||||
let back = read_back(&doc);
|
||||
let Paint::Gradient(fill) = back.layers[0].children().unwrap()[0].appearance.items[0].paint() else { panic!("a gradient") };
|
||||
same_curve(&want, &fill.gradient, "the dithered fill");
|
||||
|
||||
// More stops than the reader reads: the average of its own stops, as a classic gradient's.
|
||||
for method in [GradientMethod::Perceptual, GradientMethod::HueClockwise] {
|
||||
let stops = (0..300)
|
||||
.map(|i| GradientStop::new(i as f32 / 299.0, if i % 2 == 0 { Color::rgb(1.0, 0.0, 0.0) } else { Color::rgb(0.0, 0.0, 1.0) }))
|
||||
.collect();
|
||||
let many = Gradient { method, ..Gradient::new(GradientKind::Linear, stops) };
|
||||
let doc = with(&many, None);
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert!(out.warnings.iter().any(|w| w == writer::GRADIENT_SHAPES), "{method:?}: {:?}", out.warnings);
|
||||
assert!(!out.warnings.iter().any(|w| w == writer::GRADIENT_PERCEPTUAL || w == writer::GRADIENT_HUE), "{method:?}: {:?}", out.warnings);
|
||||
let back = read_back(&doc);
|
||||
assert_eq!(paint(back.layers[0].children().unwrap()[0].appearance.items[0].paint()), paint(&solid(Color::rgb(0.5, 0.0, 0.5))), "{method:?}");
|
||||
}
|
||||
|
||||
// Classic: its own stops, under the swatch's name, without a warning.
|
||||
let doc = with(&classic, Some("Dusk"));
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert!(out.warnings.is_empty(), "{:?}", out.warnings);
|
||||
let back = read_back(&doc);
|
||||
let Some(Paint::Gradient(swatch)) = back.swatch("Dusk").map(|s| &s.paint) else { panic!("the swatch is lost") };
|
||||
assert_eq!(swatch.gradient.stops.len(), classic.stops.len());
|
||||
let Paint::Gradient(fill) = back.layers[0].children().unwrap()[0].appearance.items[0].paint() else { panic!("a gradient") };
|
||||
assert_eq!(fill.gradient.stops.len(), classic.stops.len());
|
||||
}
|
||||
|
||||
/// A gradient mixed around the hue wheel whose stop is linked to a global process color loses the
|
||||
/// link with its stops on the curve, and says so.
|
||||
#[test]
|
||||
fn hue_gradients_report_the_links_their_curve_drops() {
|
||||
let mut doc = Document::new(200.0, 100.0);
|
||||
let layer = doc.layers[0].id;
|
||||
let mut swatches: Vec<Swatch> = doc.swatches.iter().cloned().collect();
|
||||
swatches.push(Swatch { name: "Brand".into(), paint: solid(BRAND), global: true, spot: false });
|
||||
doc.swatches = swatches.into();
|
||||
let mut g = sunset();
|
||||
g.method = vectorcraft_color::gradient::GradientMethod::HueClockwise;
|
||||
if let Some(s) = g.stops.first_mut() {
|
||||
s.set_color(BRAND, Some(("Brand".into(), 1.0)));
|
||||
}
|
||||
let n = painted(
|
||||
&mut doc,
|
||||
shapes::rectangle(Rect::new(10.0, 10.0, 30.0, 30.0)),
|
||||
vec![AppearanceItem::Fill(FillLayer::new(gradient_paint(g, None, None)))],
|
||||
);
|
||||
doc.insert(Some(layer), usize::MAX, n).unwrap();
|
||||
let out = export_ai_editing(&doc, &opts()).unwrap();
|
||||
assert_eq!(out.warnings, [writer::GRADIENT_HUE, writer::STOP_LINKS]);
|
||||
}
|
||||
|
||||
/// A pattern whose art reaches past its tile is written as its tiles cut to the shape: a definition
|
||||
/// would cut its art off at the tile's edge.
|
||||
#[test]
|
||||
|
||||
@@ -37,7 +37,9 @@ pub(super) use images::PAYLOAD;
|
||||
#[cfg(test)]
|
||||
pub(super) use images::{IMAGE_DEPTH, IMAGES, LINKS_EMBEDDED};
|
||||
#[cfg(test)]
|
||||
pub(super) use paints::{GRADIENT_HUE, GRADIENT_MIX, GRADIENT_SHAPES, GRADIENTS, STOP_LINKS, SWATCH_PLACEMENT, free_gradient_name};
|
||||
pub(super) use paints::{
|
||||
GRADIENT_DITHER, GRADIENT_HUE, GRADIENT_PERCEPTUAL, GRADIENT_SHAPES, GRADIENTS, STOP_LINKS, SWATCH_PLACEMENT, free_gradient_name,
|
||||
};
|
||||
#[cfg(test)]
|
||||
pub(super) use symbols::{MISSING_SYMBOL, SYMBOL_ART, SYMBOL_COUNT, SYMBOL_OPTIONS};
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -19,8 +19,8 @@ pub(in crate::ai_editing) const GRADIENTS: &str =
|
||||
pub(in crate::ai_editing) const GRADIENT_SHAPES: &str = "gradients without stops or with more than 256, gradients whose ramp has no length and radial gradients flattened to a line are written as their average color in the editing data for other apps";
|
||||
pub(in crate::ai_editing) const SWATCH_PLACEMENT: &str =
|
||||
"the placement of pattern swatches that move, turn or scale their pattern is left out of the editing data for other apps";
|
||||
pub(in crate::ai_editing) const GRADIENT_MIX: &str =
|
||||
"gradients that mix their colors perceptually or dither are written as classic gradients in the editing data for other apps";
|
||||
pub(in crate::ai_editing) const GRADIENT_DITHER: &str = "gradients that dither are written without dither's noise in the editing data for other apps";
|
||||
pub(in crate::ai_editing) const GRADIENT_PERCEPTUAL: &str = "Perceptual gradients are written in process colors, with the colors between their stops as stops of their own (at most 256), in the editing data for other apps";
|
||||
pub(in crate::ai_editing) const GRADIENT_HUE: &str = "gradients mixed around the hue wheel are written in process colors, with the colors between their stops as stops of their own (at most 256), in the editing data for other apps";
|
||||
pub(in crate::ai_editing) const CONIC: &str =
|
||||
"conic gradients are written as linear gradients along their vector, with the same stops, in the editing data for other apps";
|
||||
@@ -57,13 +57,14 @@ fn writable_gradient(g: &Gradient) -> bool {
|
||||
g.kind != GradientKind::Freeform && !g.stops.is_empty() && g.stops.len() <= crate::import::MAX_GRADIENT_STOPS
|
||||
}
|
||||
|
||||
/// `g` as the data holds its colors: one mixed around the hue wheel (the data's gradients mix
|
||||
/// their stops' colors directly) as a classic gradient of the stops on its curve
|
||||
/// ([`Gradient::as_classic_curve`]), no more than the `.ai` reader reads when it pads
|
||||
/// ([`GRADIENT_HUE`]); others as they are.
|
||||
fn hue_as_stops(g: &Gradient) -> std::borrow::Cow<'_, Gradient> {
|
||||
/// `g` as the data holds its colors: one mixed by the Perceptual method or around the hue wheel
|
||||
/// (the data's gradients mix their stops' colors directly) as a classic gradient of the stops on
|
||||
/// its curve in process colors ([`Gradient::as_classic_curve`]), no more than the `.ai` reader
|
||||
/// reads when it pads ([`GRADIENT_PERCEPTUAL`], [`GRADIENT_HUE`]); a classic one, and one the
|
||||
/// data can't hold as a gradient ([`writable_gradient`]), as it is.
|
||||
fn curve_as_stops(g: &Gradient) -> std::borrow::Cow<'_, Gradient> {
|
||||
use std::borrow::Cow;
|
||||
if !g.method.is_hue() {
|
||||
if g.method.is_classic() || !writable_gradient(g) {
|
||||
return Cow::Borrowed(g);
|
||||
}
|
||||
let curve = g.as_classic_curve();
|
||||
@@ -88,6 +89,16 @@ pub(in crate::ai_editing) fn free_gradient_name(next: &mut u64, mut taken: impl
|
||||
}
|
||||
}
|
||||
|
||||
/// Is `stop` linked to a global process color of `doc` (one [`Writer::stop_color`] writes as its
|
||||
/// color, [`STOP_LINKS`])?
|
||||
fn links_global_process(doc: &vectorcraft_doc::Document, stop: &GradientStop) -> bool {
|
||||
stop.swatch
|
||||
.as_deref()
|
||||
.filter(|n| *n != REGISTRATION)
|
||||
.and_then(|name| doc.swatch(name))
|
||||
.is_some_and(|sw| matches!(sw.paint, Paint::Solid { swatch: None, .. }) && !sw.spot && sw.global)
|
||||
}
|
||||
|
||||
/// The stops of `g` in order of their place on the ramp.
|
||||
fn sorted_stops(g: &Gradient) -> Vec<&GradientStop> {
|
||||
let mut stops: Vec<&GradientStop> = g.stops.iter().collect();
|
||||
@@ -100,10 +111,11 @@ impl Writer<'_> {
|
||||
pub(in crate::ai_editing) fn reserve_swatch_gradients(&mut self) {
|
||||
let doc = self.doc;
|
||||
for sw in doc.swatches_iter() {
|
||||
// As `swatch_paint` writes it: one mixed around the hue wheel as the stops on its curve,
|
||||
// and the stops of one that repeats or reflects repeated.
|
||||
// As `swatch_paint` writes it: one mixed by the Perceptual method or around the hue
|
||||
// wheel as the stops on its curve, and the stops of one that repeats or reflects
|
||||
// repeated.
|
||||
if let Paint::Gradient(g) = &sw.paint
|
||||
&& let stops = hue_as_stops(&g.gradient)
|
||||
&& let stops = curve_as_stops(&g.gradient)
|
||||
&& let gradient = stops.unrolled_within(crate::import::MAX_GRADIENT_STOPS)
|
||||
&& writable_gradient(&gradient)
|
||||
&& !self.gradients.iter().any(|d| d.name == sw.name)
|
||||
@@ -165,9 +177,11 @@ impl Writer<'_> {
|
||||
// The data has no spread: a gradient that repeats or reflects is written with its stops
|
||||
// repeated over `area` (a conic one, written linear, around its turn).
|
||||
let mut g: GradientPaint = (**g).clone();
|
||||
if g.gradient.method.is_hue() {
|
||||
self.warn(GRADIENT_HUE);
|
||||
g.gradient = hue_as_stops(&g.gradient).into_owned();
|
||||
// A gradient written as its average color (a freeform one, or one without stops or with
|
||||
// more than the reader reads) keeps its own stops.
|
||||
if !g.gradient.method.is_classic() && writable_gradient(&g.gradient) {
|
||||
self.warn_curve(&g.gradient);
|
||||
g.gradient = curve_as_stops(&g.gradient).into_owned();
|
||||
}
|
||||
if g.gradient.is_spread() {
|
||||
self.warn(SPREAD);
|
||||
@@ -192,6 +206,18 @@ impl Writer<'_> {
|
||||
Paint::Gradient(Box::new(GradientPaint { geom: Some(geom), ..g }))
|
||||
}
|
||||
|
||||
/// The warnings for gradient `g`, mixed by the Perceptual method or around the hue wheel,
|
||||
/// written as the stops on its curve ([`curve_as_stops`]): [`GRADIENT_PERCEPTUAL`] or
|
||||
/// [`GRADIENT_HUE`], and [`STOP_LINKS`] when one of its stops is linked to a global process
|
||||
/// color (the stops on the curve hold no links).
|
||||
fn warn_curve(&mut self, g: &Gradient) {
|
||||
self.warn(if g.method.is_hue() { GRADIENT_HUE } else { GRADIENT_PERCEPTUAL });
|
||||
let doc = self.doc;
|
||||
if g.stops.iter().any(|s| links_global_process(doc, s)) {
|
||||
self.warn(STOP_LINKS);
|
||||
}
|
||||
}
|
||||
|
||||
/// The fills and strokes of `n` that paint (outline `bp`), their gradients placed
|
||||
/// ([`Self::placed`]): a fill's on the shape's bounds, a stroke's on what it paints, the stops
|
||||
/// of one that repeats or reflects repeated over the box the stroke paints, miter spikes
|
||||
@@ -363,8 +389,8 @@ impl Writer<'_> {
|
||||
/// linear gradient's from the last to the first and a radial one's from the first to the last,
|
||||
/// `BD`, `%AI5_EndGradient`.
|
||||
fn gradient_def(&mut self, s: &mut String, d: &GradientDef) {
|
||||
if d.gradient.dither || !d.gradient.method.is_classic() {
|
||||
self.warn(GRADIENT_MIX);
|
||||
if d.gradient.dither {
|
||||
self.warn(GRADIENT_DITHER);
|
||||
}
|
||||
if d.gradient.kind == GradientKind::Conic {
|
||||
self.warn(CONIC);
|
||||
@@ -587,16 +613,17 @@ impl Writer<'_> {
|
||||
/// be written.
|
||||
pub(super) fn swatch_paint(&mut self, s: &mut String, sw: &vectorcraft_color::swatch::Swatch) -> bool {
|
||||
// A swatch has no placement: one that repeats or reflects holds its stops repeated along
|
||||
// its vector, and one mixed around the hue wheel the stops on its curve.
|
||||
// its vector, and one mixed by the Perceptual method or around the hue wheel the stops on
|
||||
// its curve.
|
||||
let stops = match &sw.paint {
|
||||
Paint::Gradient(g) => Some(hue_as_stops(&g.gradient)),
|
||||
Paint::Gradient(g) => Some(curve_as_stops(&g.gradient)),
|
||||
_ => None,
|
||||
};
|
||||
let unrolled = stops.as_deref().map(|g| g.unrolled_within(crate::import::MAX_GRADIENT_STOPS));
|
||||
match &sw.paint {
|
||||
Paint::Gradient(g) if unrolled.as_deref().is_some_and(writable_gradient) => {
|
||||
if g.gradient.method.is_hue() {
|
||||
self.warn(GRADIENT_HUE);
|
||||
if !g.gradient.method.is_classic() {
|
||||
self.warn_curve(&g.gradient);
|
||||
}
|
||||
if g.gradient.is_spread() {
|
||||
self.warn(SPREAD);
|
||||
|
||||
@@ -145,8 +145,9 @@ private editing data. VectorCraft:
|
||||
type with inline graphics, ruby, gradient or pattern paint or an appearance or opacity mask of its own, other patterns, other clipping objects and live
|
||||
objects (placed documents included) are written as plain filled and stroked paths, and freeform gradients, gradients along
|
||||
or across a stroke and gradients without stops, with more than 256 stops or without extent as their average
|
||||
color, each with a warning. Gradients that dither or mix their colors perceptually are written as classic
|
||||
gradients, and gradient stops linked to global process colors as their colors, each with a warning. The opacity
|
||||
color, each with a warning. Gradients that dither are written without dither's noise, Perceptual gradients and
|
||||
gradients mixed around the hue wheel as classic gradients of the stops on their curve in process colors (at most
|
||||
256), and gradient stops linked to global process colors as their colors, each with a warning. The opacity
|
||||
and blending mode of single fills and strokes, opacity masks on layers, the placement of pattern swatches that
|
||||
move, turn or scale their pattern, and the effects of objects written without an art style, other than geometry
|
||||
effects, are left out.
|
||||
|
||||
@@ -2300,6 +2300,14 @@ applies to fills). Tests: `color::gradient::tests` (perceptual midpoint, expansi
|
||||
`pdf::tests::dithered_perceptual_gradients_export_as_images_with_noise_on_the_fill` and the Gradient panel's
|
||||
`the_method_menu_makes_the_gradient_perceptual`. Scores and hours unchanged.
|
||||
|
||||
A saved `.ai`'s editing data writes a Perceptual gradient, in the art and in the Swatches panel, as a classic gradient of
|
||||
the stops on its curve in process colors (at most 256, the stops VectorCraft's reader reads), as it writes a gradient
|
||||
mixed around the hue wheel, so the file opens with the colors between the stops it had; a gradient definition's stops
|
||||
there hold no interpolation method (`crates/eps/src/import/ai/paint.rs:193-245` reads each `Bs` stop's color, opacity,
|
||||
midpoint and ramp point). The warning names Perceptual gradients, and a stop linked to a global process color reports
|
||||
its lost link; Dither's noise is reported as its own loss (VectorCraft's own rules). Test:
|
||||
`ai_editing::tests::perceptual_gradients_are_written_with_the_stops_on_their_curve`.
|
||||
|
||||
PDF export writes a Perceptual linear or radial gradient whose stops are tints of one spot color (and paper white) as a Separation shading in that ink instead of an image, so the ink keeps its plate ([swatches](https://helpx.adobe.com/illustrator/using/using-creating-swatches.html); [separations](https://helpx.adobe.com/illustrator/using/printing-color-separations.html)). Its tints follow the curve's stops, each the tint with the OKLab lightness of the color there (VectorCraft's own rule). A Perceptual gradient that mixes spot colors with each other or with CMYK or gray stops is written as a DeviceN shading of its inks: at each stop on the curve, the inks of the two stops on either side are mixed at the weight where the two colors mixed in display RGB have the OKLab lightness of the color there, or at the stop's mix position between the two colors when that mix's lightness turns back on the way from one color to the other, as from red to blue (VectorCraft's own rule). Dithered fills, freeform gradients, Perceptual gradients that mix a spot color with RGB or Lab stops, and Perceptual gradients whose curve has more than 4,096 stops once expanded (VectorCraft's own limit) are still images, and the export warns that their spot colors are written in process colors. In a CMYK document, or an export that converts colors to a CMYK destination profile, RGB and Lab stops are written in CMYK, so a Perceptual gradient that mixes a spot color with them is a DeviceN shading; an export that converts colors to an RGB destination profile keeps them in RGB. Tests: `color::gradient::tests::ink_tints_follow_the_perceptual_curve`, `ink_mixes_follow_the_perceptual_curve` and `ink_mixes_use_the_mix_position_when_the_lightness_turns_back`, `engine::tests::linked_stops::perceptual_spot_gradients_export_as_separation_shadings`, `perceptual_spot_gradients_mixed_with_other_inks_export_as_device_n_shadings`, `perceptual_spot_gradients_with_rgb_stops_in_a_cmyk_document_export_as_device_n_shadings` and `spot_gradients_drawn_as_images_warn`.
|
||||
|
||||
In these Separation and DeviceN shadings, a white stop linked to a swatch that is not a spot color (a global White swatch, for example) is paper white, 0% of the ink, as an unlinked white stop is, so a gradient of one spot ink and such a stop stays a Separation shading; a stop linked to a white spot color stays a stop of that ink (VectorCraft's own rule). Test: `engine::tests::linked_stops::white_stops_linked_to_process_swatches_are_paper_in_spot_gradients`.
|
||||
|
||||
Reference in New Issue
Block a user