mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 20:46:22 +01:00
Merge pull request #7103 from dotCooCoo/feat/stylus-wheel
Brushes: an airbrush pen's stylus wheel varies brush size and width
This commit is contained in:
63 files changed
+732
-229
No files matched your search
@@ -1,4 +1,5 @@
|
||||
//! macOS: a drawing tablet's pen pressure (#852), tilt and barrel rotation (#764). winit 0.30
|
||||
//! macOS: a drawing tablet's pen pressure (#852), tilt and barrel rotation (#764), and an airbrush
|
||||
//! pen's finger wheel. winit 0.30
|
||||
//! hands a pen to the window there as a mouse, without them, so the app reads them from AppKit
|
||||
//! itself and writes them into the UI's [`StylusFeed`] (`Services::stylus`), which the canvas
|
||||
//! reads, as on X11 ([`crate::tablet`]).
|
||||
@@ -14,8 +15,9 @@
|
||||
//! (−1..1 on each axis, ±[`TILT_DEGREES`] at the ends) and its `rotation` go into the feed as the
|
||||
//! pen's pose, kept for that move too. AppKit gives a rotation of 0 for a pen that does not read
|
||||
//! one and a tilt of 0 for an upright pen, so one event cannot tell a pen without tilt or rotation
|
||||
//! from one held upright and unturned. Each reads as none until the pen reports a value other
|
||||
//! than 0 after it comes near ([`Pen`]).
|
||||
//! from one held upright and unturned. Its `tangentialPressure` (−1..1, an airbrush pen's finger
|
||||
//! wheel) goes into the pose as the wheel, 0 for a pen without one as well. Each reads as none
|
||||
//! until the pen reports a value other than 0 after it comes near ([`Pen`]).
|
||||
//! A mouse event of any other subtype is a mouse's or a trackpad's: the feed is set to `None`.
|
||||
//! - An `NSEventTypeTabletPoint` event carries the same pressure, tilt and rotation without a move.
|
||||
//! - A tablet proximity event (`NSEventTypeTabletProximity`, or a mouse event of that subtype) says
|
||||
@@ -68,6 +70,8 @@ struct RawEvent {
|
||||
tilt: (f64, f64),
|
||||
/// `rotation`, in degrees (the same events as `pressure`).
|
||||
rotation: f32,
|
||||
/// `tangentialPressure`, −1..1 (the same events as `pressure`).
|
||||
tangential: f32,
|
||||
/// `pointingDeviceType` (proximity events only).
|
||||
device: usize,
|
||||
/// `isEnteringProximity` (proximity events only).
|
||||
@@ -107,18 +111,42 @@ impl RawEvent {
|
||||
/// and the pen's rotation is taken the same way. [`PenPose`]'s rotation runs clockwise, so the
|
||||
/// angle is negated and brought into 0..360.
|
||||
///
|
||||
/// The tilt is left out unless `tilts`, and the rotation unless `turns` ([`Pen`]).
|
||||
fn pose(&self, tilts: bool, turns: bool) -> PenPose {
|
||||
/// AppKit's `tangentialPressure` is −1.0..1.0, the finger wheel of an airbrush pen on the
|
||||
/// devices that have one (<https://developer.apple.com/documentation/appkit/nsevent/tangentialpressure>).
|
||||
/// It becomes [`PenPose`]'s wheel of 0..1, −1.0 at 0 and 1.0 at 1; a value past either end is
|
||||
/// clamped.
|
||||
///
|
||||
/// The tilt is left out unless `read.tilts`, the rotation unless `read.turns`, and the wheel
|
||||
/// unless `read.wheels` ([`Pen`]).
|
||||
fn pose(&self, read: Reads) -> PenPose {
|
||||
let degrees = |v: f64| (v.clamp(-1.0, 1.0) * TILT_DEGREES) as f32;
|
||||
// `0.0 - r` rather than `-r`: a rotation of 0 gives 0, not −0.
|
||||
let rotation = turns.then(|| (0.0 - self.rotation).rem_euclid(360.0));
|
||||
PenPose { tilt: tilts.then(|| [degrees(self.tilt.0), degrees(self.tilt.1)]), rotation }
|
||||
let rotation = read.turns.then(|| (0.0 - self.rotation).rem_euclid(360.0));
|
||||
let wheel = read.wheels.then(|| (self.tangential.clamp(-1.0, 1.0) + 1.0) / 2.0);
|
||||
PenPose { tilt: read.tilts.then(|| [degrees(self.tilt.0), degrees(self.tilt.1)]), rotation, wheel }
|
||||
}
|
||||
|
||||
/// Whether the event reports a tilt other than 0, and a rotation other than 0.
|
||||
fn reads(&self) -> (bool, bool) {
|
||||
/// Whether the event reports a tilt other than 0, a rotation other than 0, and a tangential
|
||||
/// pressure other than 0.
|
||||
fn reads(&self) -> Reads {
|
||||
let read = |v: f64| v.is_finite() && v != 0.0;
|
||||
(read(self.tilt.0) || read(self.tilt.1), read(f64::from(self.rotation)))
|
||||
Reads { tilts: read(self.tilt.0) || read(self.tilt.1), turns: read(f64::from(self.rotation)), wheels: read(f64::from(self.tangential)) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Which of a pen's tilt, rotation and finger wheel it has reported.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
struct Reads {
|
||||
tilts: bool,
|
||||
turns: bool,
|
||||
wheels: bool,
|
||||
}
|
||||
|
||||
impl Reads {
|
||||
fn add(&mut self, other: Reads) {
|
||||
self.tilts |= other.tilts;
|
||||
self.turns |= other.turns;
|
||||
self.wheels |= other.wheels;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,14 +176,14 @@ impl Update {
|
||||
}
|
||||
}
|
||||
|
||||
/// Which end of the pen is near the tablet, and whether it has reported a tilt or a rotation other
|
||||
/// than 0 since it came near: until it has, its tilt or rotation reads as none, since AppKit gives
|
||||
/// 0 for a pen without one and for one held upright or unturned.
|
||||
/// Which end of the pen is near the tablet, and whether it has reported a tilt, a rotation or a
|
||||
/// tangential pressure other than 0 since it came near: until it has, that value reads as none,
|
||||
/// since AppKit gives 0 for a pen without one and for one held upright, unturned or with its
|
||||
/// wheel half way.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
struct Pen {
|
||||
eraser: bool,
|
||||
tilts: bool,
|
||||
turns: bool,
|
||||
read: Reads,
|
||||
}
|
||||
|
||||
impl Pen {
|
||||
@@ -163,16 +191,14 @@ impl Pen {
|
||||
if e.proximity() {
|
||||
// Entering with the tip or the eraser end: it hovers. A puck, or leaving, is a mouse.
|
||||
self.eraser = e.entering && e.device == device::ERASER;
|
||||
(self.tilts, self.turns) = (false, false);
|
||||
self.read = Reads::default();
|
||||
let pen = e.entering && e.device != device::CURSOR;
|
||||
return Update::Set(pen.then_some(PenSample { pressure: 0.0, eraser: self.eraser, ..PenSample::default() }));
|
||||
}
|
||||
if e.point() {
|
||||
let (tilts, turns) = e.reads();
|
||||
self.tilts |= tilts;
|
||||
self.turns |= turns;
|
||||
self.read.add(e.reads());
|
||||
}
|
||||
let sample = PenSample { pressure: e.pressure, eraser: self.eraser, pose: e.pose(self.tilts, self.turns) };
|
||||
let sample = PenSample { pressure: e.pressure, eraser: self.eraser, pose: e.pose(self.read) };
|
||||
match (e.point(), e.mouse()) {
|
||||
(true, true) => Update::Move(sample),
|
||||
(true, false) => Update::Set(Some(sample)),
|
||||
@@ -246,6 +272,7 @@ mod monitor {
|
||||
let tilt = e.tilt();
|
||||
raw.tilt = (tilt.x, tilt.y);
|
||||
raw.rotation = e.rotation();
|
||||
raw.tangential = e.tangentialPressure();
|
||||
}
|
||||
if raw.proximity() {
|
||||
raw.device = e.pointingDeviceType().0;
|
||||
@@ -326,26 +353,44 @@ mod tests {
|
||||
let sample = |pressure, pose| PenSample { pressure, eraser: false, pose };
|
||||
assert_eq!(p.handle(&pen(DRAG, 0.5)), Update::Move(tip(0.5)), "no tilt or rotation reported yet");
|
||||
let leaning = RawEvent { tilt: (0.5, -0.25), rotation: 30.0, ..pen(DRAG, 0.5) };
|
||||
let pose = PenPose { tilt: Some([30.0, -15.0]), rotation: Some(330.0) };
|
||||
let pose = PenPose { tilt: Some([30.0, -15.0]), rotation: Some(330.0), wheel: None };
|
||||
assert_eq!(p.handle(&leaning), Update::Move(sample(0.5, pose)));
|
||||
let past_the_ends = RawEvent { tilt: (-4.0, 1.5), rotation: 270.0, ..pen(event_type::TABLET_POINT, 0.8) };
|
||||
let pose = PenPose { tilt: Some([-60.0, 60.0]), rotation: Some(90.0) };
|
||||
let pose = PenPose { tilt: Some([-60.0, 60.0]), rotation: Some(90.0), wheel: None };
|
||||
assert_eq!(p.handle(&past_the_ends), Update::Set(Some(sample(0.8, pose))), "clamped");
|
||||
let pose = PenPose { tilt: Some([0.0, 0.0]), rotation: Some(0.0) };
|
||||
let pose = PenPose { tilt: Some([0.0, 0.0]), rotation: Some(0.0), wheel: None };
|
||||
let Update::Move(upright) = p.handle(&pen(DRAG, 0.6)) else { panic!("a pen's drag is a move") };
|
||||
assert_eq!(upright, sample(0.6, pose), "once reported, 0 is upright and unturned");
|
||||
assert!(upright.pose.rotation.is_some_and(f32::is_sign_positive), "{upright:?}");
|
||||
let feed = StylusFeed::default();
|
||||
p.handle(&RawEvent { tilt: (f64::NAN, 0.0), rotation: -90.0, ..pen(DRAG, 0.3) }).apply(&feed);
|
||||
assert_eq!(feed.pose(), Some(PenPose { tilt: None, rotation: Some(90.0) }), "a tilt that is not a number is left out");
|
||||
assert_eq!(feed.pose(), Some(PenPose { rotation: Some(90.0), ..PenPose::default() }), "a tilt that is not a number is left out");
|
||||
p.handle(&proximity(1, true));
|
||||
let tilted = RawEvent { tilt: (0.0, 0.5), ..pen(event_type::TABLET_POINT, 0.8) };
|
||||
let pose = PenPose { tilt: Some([0.0, 30.0]), rotation: None };
|
||||
let pose = PenPose { tilt: Some([0.0, 30.0]), ..PenPose::default() };
|
||||
assert_eq!(p.handle(&tilted), Update::Set(Some(sample(0.8, pose))), "no rotation reported since the pen came near");
|
||||
p.handle(&RawEvent { kind: DRAG, ..Default::default() }).apply(&feed);
|
||||
assert_eq!(feed.pose(), None, "a mouse moved");
|
||||
}
|
||||
|
||||
/// An airbrush pen's finger wheel (AppKit's `tangentialPressure`, −1..1) reaches the feed as
|
||||
/// 0..1, once the pen has reported a value other than 0 since it came near.
|
||||
#[test]
|
||||
fn an_airbrush_wheel_goes_into_the_feed() {
|
||||
let mut p = Pen::default();
|
||||
let wheel = |p: &mut Pen, tangential: f32| match p.handle(&RawEvent { tangential, ..pen(DRAG, 0.5) }) {
|
||||
Update::Move(s) => s.pose.wheel,
|
||||
u => panic!("a pen's drag is a move: {u:?}"),
|
||||
};
|
||||
assert_eq!(wheel(&mut p, 0.0), None, "no wheel reported yet");
|
||||
assert_eq!(wheel(&mut p, -1.0), Some(0.0));
|
||||
assert_eq!(wheel(&mut p, 0.5), Some(0.75));
|
||||
assert_eq!(wheel(&mut p, 0.0), Some(0.5), "once reported, 0 is half way");
|
||||
assert_eq!(wheel(&mut p, 3.0), Some(1.0), "clamped");
|
||||
p.handle(&proximity(1, true));
|
||||
assert_eq!(wheel(&mut p, 0.0), None, "not reported since the pen came near");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_feed_gets_each_moves_pressure_within_0_to_1() {
|
||||
let feed = StylusFeed::default();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Linux: a drawing tablet's pen pressure, tilt and barrel rotation under X11, XWayland included
|
||||
//! Linux: a drawing tablet's pen pressure, tilt, barrel rotation and airbrush finger wheel under
|
||||
//! X11, XWayland included
|
||||
//! (#764). winit 0.30 hands a pen to the window there as a mouse, without any of them, so the app
|
||||
//! reads them from XInput2 itself and writes them into the UI's [`StylusFeed`]
|
||||
//! (`Services::stylus`), which the canvas reads.
|
||||
@@ -14,11 +15,17 @@
|
||||
//! - "Abs Tilt X" and "Abs Tilt Y" (a pen that has both), in degrees as they are when the range
|
||||
//! fits in ±90, otherwise scaled to ±[`TILT_DEGREES`];
|
||||
//! - "Abs Rotary Z" (the barrel rotation of an Art Pen), scaled to a turn with the middle of the
|
||||
//! range at 0°.
|
||||
//! range at 0°;
|
||||
//! - "Abs Wheel" (the finger wheel of an airbrush pen), scaled from the valuator's range to 0..1.
|
||||
//! XWayland also sends an Art Pen's barrel rotation on this valuator
|
||||
//! (<https://github.com/mirror/xserver/blob/master/hw/xwayland/xwayland-input.c>), so under
|
||||
//! XWayland it reads as the wheel. A tablet pad's wheel is on a device without a pressure axis,
|
||||
//! which is not read.
|
||||
//!
|
||||
//! Any other pointer device moving sets the feed to `None`. Raw events carry only the valuators
|
||||
//! that changed, so the last value of each axis of each pen is kept; an axis the pen has that no
|
||||
//! event has carried yet reads 0 (upright, unturned), and an axis it lacks reads nothing.
|
||||
//! event has carried yet reads 0 (upright, unturned), and an axis it lacks reads nothing. The
|
||||
//! wheel reads nothing until an event carries it.
|
||||
//!
|
||||
//! The X server lists a pen's eraser end as a device of its own, whose name or XInput type contains
|
||||
//! "eraser" (xf86-input-wacom's "… Pen eraser" of type `ERASER`, xf86-input-libinput's
|
||||
@@ -60,6 +67,7 @@ enum AxisKind {
|
||||
TiltX,
|
||||
TiltY,
|
||||
Rotation,
|
||||
Wheel,
|
||||
}
|
||||
|
||||
impl AxisKind {
|
||||
@@ -70,6 +78,7 @@ impl AxisKind {
|
||||
"Abs Tilt X" => Some(Self::TiltX),
|
||||
"Abs Tilt Y" => Some(Self::TiltY),
|
||||
"Abs Rotary Z" => Some(Self::Rotation),
|
||||
"Abs Wheel" => Some(Self::Wheel),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -81,6 +90,7 @@ impl AxisKind {
|
||||
Self::TiltX => 1,
|
||||
Self::TiltY => 2,
|
||||
Self::Rotation => 3,
|
||||
Self::Wheel => 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,18 +105,22 @@ struct Axis {
|
||||
}
|
||||
|
||||
impl Axis {
|
||||
/// A raw value of this valuator as a pressure of 0..1, a tilt in degrees (−90..90) or a
|
||||
/// rotation in degrees (−180..180, the middle of the range at 0). A value that is not a number
|
||||
/// is a mouse's pressure, 1, or a tilt or rotation of 0.
|
||||
/// A raw value of this valuator as a pressure of 0..1, a tilt in degrees (−90..90), a rotation
|
||||
/// in degrees (−180..180, the middle of the range at 0) or a wheel of 0..1. A value that is not
|
||||
/// a number is a mouse's pressure, 1, a tilt or rotation of 0, or a wheel half way.
|
||||
fn map(&self, v: f64) -> f32 {
|
||||
if !v.is_finite() {
|
||||
return if self.kind == AxisKind::Pressure { 1.0 } else { 0.0 };
|
||||
return match self.kind {
|
||||
AxisKind::Pressure => 1.0,
|
||||
AxisKind::Wheel => 0.5,
|
||||
_ => 0.0,
|
||||
};
|
||||
}
|
||||
let span = self.max - self.min;
|
||||
let unit = if span.is_finite() && span > 0.0 { (v - self.min) / span } else { v };
|
||||
let unit = unit.clamp(0.0, 1.0);
|
||||
match self.kind {
|
||||
AxisKind::Pressure => unit as f32,
|
||||
AxisKind::Pressure | AxisKind::Wheel => unit as f32,
|
||||
AxisKind::TiltX | AxisKind::TiltY if self.min >= -90.0 && self.max <= 90.0 && span > 0.0 => v.clamp(-90.0, 90.0) as f32,
|
||||
AxisKind::TiltX | AxisKind::TiltY => ((unit * 2.0 - 1.0) * TILT_DEGREES) as f32,
|
||||
AxisKind::Rotation => ((unit - 0.5) * 360.0) as f32,
|
||||
@@ -173,7 +187,7 @@ enum Update {
|
||||
#[derive(Debug, Default)]
|
||||
struct Pens {
|
||||
devices: HashMap<u16, Device>,
|
||||
last: HashMap<u16, [Option<f32>; 4]>,
|
||||
last: HashMap<u16, [Option<f32>; 5]>,
|
||||
}
|
||||
|
||||
impl Pens {
|
||||
@@ -200,10 +214,12 @@ impl Pens {
|
||||
}
|
||||
}
|
||||
}
|
||||
// An axis the pen has reads 0 until an event carries it; one it lacks reads nothing.
|
||||
// An axis the pen has reads 0 until an event carries it; one it lacks reads nothing. The
|
||||
// wheel reads nothing until an event carries it: XWayland lists the axis for every pen.
|
||||
let value = |kind: AxisKind| device.axis(kind).map(|_| last.get(kind.slot()).copied().flatten().unwrap_or(0.0));
|
||||
let tilt = value(AxisKind::TiltX).zip(value(AxisKind::TiltY)).map(|(x, y)| [x, y]);
|
||||
let pose = PenPose { tilt, rotation: value(AxisKind::Rotation) };
|
||||
let wheel = device.axis(AxisKind::Wheel).and_then(|_| last.get(AxisKind::Wheel.slot()).copied().flatten());
|
||||
let pose = PenPose { tilt, rotation: value(AxisKind::Rotation), wheel };
|
||||
Update::Set(Some(PenSample { pressure: value(AxisKind::Pressure).unwrap_or(0.0), eraser: device.eraser, pose }))
|
||||
}
|
||||
|
||||
@@ -430,7 +446,7 @@ mod tests {
|
||||
let mut pens = Pens::default();
|
||||
pens.set_devices([pen(9), Device::new(10, "Wacom Intuos Pro M Pen eraser", Some("ERASER"), pen_valuators()), mouse(12)]);
|
||||
let feed = StylusFeed::default();
|
||||
let pose = PenPose { tilt: Some([0.0, 0.0]), rotation: Some(0.0) };
|
||||
let pose = PenPose { tilt: Some([0.0, 0.0]), rotation: Some(0.0), wheel: None };
|
||||
pens.raw_event(&feed, 9, &[0b100], &[32767.5]);
|
||||
assert_eq!(pens.handle(9, []), Update::Set(Some(PenSample { pressure: 0.5, eraser: false, pose })));
|
||||
assert_eq!(feed.eraser(), Some(false));
|
||||
@@ -479,10 +495,36 @@ mod tests {
|
||||
// A pen whose tilt and rotation no event has carried yet is upright and unturned.
|
||||
let mut fresh = Pens::default();
|
||||
fresh.set_devices([pen(9)]);
|
||||
let upright = PenPose { tilt: Some([0.0, 0.0]), rotation: Some(0.0) };
|
||||
let upright = PenPose { tilt: Some([0.0, 0.0]), rotation: Some(0.0), wheel: None };
|
||||
assert_eq!(fresh.handle(9, [(2, 0.0)]), Update::Set(Some(PenSample { pressure: 0.0, eraser: false, pose: upright })));
|
||||
}
|
||||
|
||||
/// An airbrush pen's "Abs Wheel" valuator goes into the feed as 0..1 of its range, once an
|
||||
/// event carries it; a pen that lists it but has not moved it reads no wheel, and a device
|
||||
/// without a pressure axis (a tablet pad's wheel) is not a pen.
|
||||
#[test]
|
||||
fn an_airbrush_wheel_goes_into_the_feed() {
|
||||
let mut valuators = pen_valuators();
|
||||
valuators.push((6, "Abs Wheel".to_string(), 0.0, 1023.0));
|
||||
let airbrush = Device::new(9, "Wacom Intuos Pro M Pen stylus", Some("STYLUS"), valuators);
|
||||
let pad = Device::new(13, "Wacom Intuos Pro M Pad pad", Some("PAD"), [(6, "Abs Wheel".to_string(), 0.0, 71.0)]);
|
||||
let mut pens = Pens::default();
|
||||
pens.set_devices([airbrush, pad, pen(10)]);
|
||||
let feed = StylusFeed::default();
|
||||
pens.raw_event(&feed, 9, &[0b100], &[32767.5]);
|
||||
assert_eq!(feed.pose().and_then(|q| q.wheel), None, "no event has carried the wheel yet");
|
||||
pens.raw_event(&feed, 9, &[0b100_0000], &[255.75]);
|
||||
assert_eq!(feed.pose().and_then(|q| q.wheel), Some(0.25));
|
||||
pens.raw_event(&feed, 9, &[0b100_0000], &[5000.0]);
|
||||
assert_eq!(feed.pose().and_then(|q| q.wheel), Some(1.0), "clamped to the range");
|
||||
pens.raw_event(&feed, 9, &[0b100], &[100.0]);
|
||||
assert_eq!(feed.pose().and_then(|q| q.wheel), Some(1.0), "kept while other valuators move");
|
||||
pens.raw_event(&feed, 13, &[0b100_0000], &[30.0]);
|
||||
assert_eq!((feed.held(), feed.pose()), (None, None), "the pad is not a pen");
|
||||
pens.raw_event(&feed, 10, &[0b100_0000], &[512.0]);
|
||||
assert_eq!(feed.pose().and_then(|q| q.wheel), None, "a pen without the valuator");
|
||||
}
|
||||
|
||||
/// A device listed again unchanged keeps its last tilt and rotation; another device listed
|
||||
/// under the same id starts upright and unturned.
|
||||
#[test]
|
||||
@@ -495,7 +537,7 @@ mod tests {
|
||||
assert_eq!(pose.tilt, Some([-30.0, 45.0]));
|
||||
let other = Device::new(9, "HUION Kamvas Pen Pen (0x1)", Some("STYLUS"), pen_valuators());
|
||||
pens.set_devices([other]);
|
||||
let upright = PenPose { tilt: Some([0.0, 0.0]), rotation: Some(0.0) };
|
||||
let upright = PenPose { tilt: Some([0.0, 0.0]), rotation: Some(0.0), wheel: None };
|
||||
assert_eq!(pens.handle(9, [(2, 0.0)]), Update::Set(Some(PenSample { pressure: 0.0, eraser: false, pose: upright })));
|
||||
}
|
||||
|
||||
|
||||
@@ -133,12 +133,13 @@ fn pen_sample(pressure: u32, pen_mask: u32, pen_flags: u32, in_contact: bool, po
|
||||
|
||||
/// How a pen whose `POINTER_PEN_INFO` holds `pen_mask`, `tilt_x`, `tilt_y` and `rotation` is
|
||||
/// held: the tilt when the pen reports it along either axis (0 along an axis it doesn't), the
|
||||
/// rotation when it reports one, each kept within [`PenPose`]'s ranges.
|
||||
/// rotation when it reports one, each kept within [`PenPose`]'s ranges. `POINTER_PEN_INFO` has no
|
||||
/// field for an airbrush pen's finger wheel, so the pose has none.
|
||||
fn pen_pose(pen_mask: u32, tilt_x: i32, tilt_y: i32, rotation: u32) -> PenPose {
|
||||
let along = |mask: u32, t: i32| if pen_mask & mask != 0 { t as f32 } else { 0.0 };
|
||||
let tilt = (pen_mask & (PEN_MASK_TILT_X | PEN_MASK_TILT_Y) != 0).then(|| [along(PEN_MASK_TILT_X, tilt_x), along(PEN_MASK_TILT_Y, tilt_y)]);
|
||||
let rotation = (pen_mask & PEN_MASK_ROTATION != 0).then_some(rotation as f32);
|
||||
PenPose { tilt, rotation }.sanitized()
|
||||
PenPose { tilt, rotation, wheel: None }.sanitized()
|
||||
}
|
||||
|
||||
/// Whether a mouse message with this extra information (`GetMessageExtraInfo`) comes from a mouse,
|
||||
@@ -426,12 +427,12 @@ mod tests {
|
||||
#[test]
|
||||
fn a_pens_tilt_and_rotation_come_where_it_reports_them() {
|
||||
let all = PEN_MASK_TILT_X | PEN_MASK_TILT_Y | PEN_MASK_ROTATION;
|
||||
assert_eq!(pen_pose(all, 30, -45, 90), PenPose { tilt: Some([30.0, -45.0]), rotation: Some(90.0) });
|
||||
assert_eq!(pen_pose(all, 30, -45, 90), PenPose { tilt: Some([30.0, -45.0]), rotation: Some(90.0), wheel: None });
|
||||
assert_eq!(pen_pose(PEN_MASK_PRESSURE, 30, -45, 90), PenPose::default(), "a pen that reports neither");
|
||||
assert_eq!(pen_pose(PEN_MASK_TILT_X, 30, -45, 90), PenPose { tilt: Some([30.0, 0.0]), rotation: None }, "one axis");
|
||||
assert_eq!(pen_pose(PEN_MASK_ROTATION, 0, 0, 359), PenPose { tilt: None, rotation: Some(359.0) }, "a 6D Art Pen's barrel");
|
||||
assert_eq!(pen_pose(PEN_MASK_TILT_X, 30, -45, 90), PenPose { tilt: Some([30.0, 0.0]), ..PenPose::default() }, "one axis");
|
||||
assert_eq!(pen_pose(PEN_MASK_ROTATION, 0, 0, 359), PenPose { rotation: Some(359.0), ..PenPose::default() }, "a 6D Art Pen's barrel");
|
||||
let wild = pen_pose(all, 400, i32::MIN, 720);
|
||||
assert_eq!(wild, PenPose { tilt: Some([90.0, -90.0]), rotation: Some(0.0) }, "kept within the ranges");
|
||||
assert_eq!(wild, PenPose { tilt: Some([90.0, -90.0]), rotation: Some(0.0), wheel: None }, "kept within the ranges");
|
||||
let pose = pen_pose(all, 10, 20, 180);
|
||||
assert_eq!(pen_sample(512, PEN_MASK_PRESSURE | all, 0, true, pose).pose, pose);
|
||||
}
|
||||
|
||||
+34
-12
@@ -160,7 +160,7 @@ impl Calligraphic {
|
||||
pub fn uses_pressure(&self) -> bool {
|
||||
self.modes().contains(&Variation::Pressure)
|
||||
}
|
||||
/// Does the pen (its pressure, tilt, bearing or rotation) change the nib?
|
||||
/// Does the pen (its pressure, tilt, bearing, rotation or wheel) change the nib?
|
||||
pub fn uses_pen(&self) -> bool {
|
||||
self.modes().iter().any(|m| m.follows_pen())
|
||||
}
|
||||
@@ -202,11 +202,25 @@ pub enum Variation {
|
||||
/// The value plus the variation times the pen barrel's rotation over 180°, counter-clockwise
|
||||
/// from where the pen reports 0° round to ±180°.
|
||||
Rotation,
|
||||
/// From the value less the variation with an airbrush pen's finger wheel at one end of its
|
||||
/// travel to the value plus the variation at the other (the value itself half way).
|
||||
StylusWheel,
|
||||
}
|
||||
|
||||
impl Variation {
|
||||
pub const ALL: [Variation; 6] =
|
||||
pub const ALL: [Variation; 7] =
|
||||
[Variation::Fixed, Variation::Random, Variation::Pressure, Variation::Tilt, Variation::Bearing, Variation::Rotation, Variation::StylusWheel];
|
||||
/// The modes Brush Options offers for a value other than a size (a Calligraphic brush's Angle
|
||||
/// and Roundness, a Scatter brush's Spacing, Scatter and Rotation): all but
|
||||
/// [`Variation::StylusWheel`], which drives a Calligraphic or Scatter brush's Size and an Art
|
||||
/// brush's Width.
|
||||
pub const OTHER: [Variation; 6] =
|
||||
[Variation::Fixed, Variation::Random, Variation::Pressure, Variation::Tilt, Variation::Bearing, Variation::Rotation];
|
||||
/// The modes Brush Options offers for a size (`true`: [`Self::ALL`]) or another value
|
||||
/// ([`Self::OTHER`]).
|
||||
pub fn offered(size: bool) -> &'static [Variation] {
|
||||
if size { &Self::ALL } else { &Self::OTHER }
|
||||
}
|
||||
/// The name brush definitions use.
|
||||
pub fn id(self) -> &'static str {
|
||||
match self {
|
||||
@@ -216,6 +230,7 @@ impl Variation {
|
||||
Variation::Tilt => "tilt",
|
||||
Variation::Bearing => "bearing",
|
||||
Variation::Rotation => "rotation",
|
||||
Variation::StylusWheel => "stylusWheel",
|
||||
}
|
||||
}
|
||||
pub fn label(self) -> &'static str {
|
||||
@@ -226,15 +241,16 @@ impl Variation {
|
||||
Variation::Tilt => "Tilt",
|
||||
Variation::Bearing => "Bearing",
|
||||
Variation::Rotation => "Rotation",
|
||||
Variation::StylusWheel => "Stylus Wheel",
|
||||
}
|
||||
}
|
||||
pub fn parse(id: &str) -> Option<Self> {
|
||||
Self::ALL.into_iter().find(|v| v.id() == id)
|
||||
}
|
||||
/// Does the value follow something the pen records along a stroke (Pressure, Tilt, Bearing,
|
||||
/// Rotation)?
|
||||
/// Rotation, Stylus Wheel)?
|
||||
pub fn follows_pen(self) -> bool {
|
||||
matches!(self, Variation::Pressure | Variation::Tilt | Variation::Bearing | Variation::Rotation)
|
||||
matches!(self, Variation::Pressure | Variation::Tilt | Variation::Bearing | Variation::Rotation | Variation::StylusWheel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,12 +267,14 @@ pub(crate) struct PenAt {
|
||||
bearing: f64,
|
||||
/// ½ plus the counter-clockwise barrel rotation over 360°.
|
||||
rotation: f64,
|
||||
/// Where the airbrush finger wheel was set, 0 at one end of its travel to 1 at the other.
|
||||
wheel: f64,
|
||||
}
|
||||
|
||||
impl PenAt {
|
||||
/// Every input at `c`.
|
||||
pub(crate) fn uniform(c: f64) -> Self {
|
||||
Self { pressure: c, tilt: c, bearing: c, rotation: c }
|
||||
Self { pressure: c, tilt: c, bearing: c, rotation: c, wheel: c }
|
||||
}
|
||||
/// What `stroke` recorded at `f` (the fraction of its path's length).
|
||||
pub(crate) fn of(stroke: &StrokeLayer, f: f64) -> Self {
|
||||
@@ -267,6 +285,7 @@ impl PenAt {
|
||||
tilt: 1.0 - stroke.tilt.as_ref().map_or(mid, |p| p.at(f)),
|
||||
bearing: turn(stroke.bearing.as_ref()),
|
||||
rotation: turn(stroke.rotation.as_ref()),
|
||||
wheel: stroke.wheel.as_ref().map_or(mid, |p| p.at(f)),
|
||||
}
|
||||
}
|
||||
/// The 0..1 a value on `mode` takes, or `None` for a mode that doesn't follow the pen.
|
||||
@@ -277,6 +296,7 @@ impl PenAt {
|
||||
Variation::Tilt => self.tilt,
|
||||
Variation::Bearing => self.bearing,
|
||||
Variation::Rotation => self.rotation,
|
||||
Variation::StylusWheel => self.wheel,
|
||||
};
|
||||
Some(if c.is_finite() { c.clamp(0.0, 1.0) } else { 0.5 })
|
||||
}
|
||||
@@ -307,9 +327,10 @@ pub struct Scatter {
|
||||
/// How size, spacing, scatter and rotation vary between their two values: Fixed takes the
|
||||
/// first, Random any value between them, Pressure the first at the lightest pen pressure and
|
||||
/// the second at the heaviest, Tilt the first with the pen lying flat and the second upright,
|
||||
/// Bearing and Rotation the first at −180° and the second at 180° (half way at 0°). `None`
|
||||
/// (brushes saved before there were modes): Random where the two differ, else Fixed (see
|
||||
/// [`Scatter::modes`]).
|
||||
/// Bearing and Rotation the first at −180° and the second at 180° (half way at 0°), and Stylus
|
||||
/// Wheel (the size's only) the first at one end of an airbrush pen's finger wheel and the
|
||||
/// second at the other. `None` (brushes saved before there were modes): Random where the two
|
||||
/// differ, else Fixed (see [`Scatter::modes`]).
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub modes: Option<[Variation; 4]>,
|
||||
}
|
||||
@@ -384,11 +405,12 @@ pub struct ArtBrush {
|
||||
/// How the width varies along a stroke: `None` (Fixed) always `width`; a mode that follows the
|
||||
/// pen goes from `width` to [`Self::width_max`] over the ranges [`Variation`] gives: Pressure
|
||||
/// from the lightest pressure to the heaviest, Tilt from the pen lying flat to upright, Bearing
|
||||
/// and Rotation from −180° to 180° (half way at 0°).
|
||||
/// and Rotation from −180° to 180° (half way at 0°), Stylus Wheel from one end of an airbrush
|
||||
/// pen's finger wheel to the other.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub width_mode: Option<Variation>,
|
||||
/// The second width (%) of a mode that follows the pen: at the heaviest pressure, upright, or
|
||||
/// at 180° (`width` without one).
|
||||
/// The second width (%) of a mode that follows the pen: at the heaviest pressure, upright, at
|
||||
/// 180° or at the wheel's far end (`width` without one).
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub width_max: Option<f64>,
|
||||
pub flip_along: bool,
|
||||
@@ -732,7 +754,7 @@ impl Brush {
|
||||
}
|
||||
BrushKind::Art(a) => {
|
||||
a.width = within(a.width, ArtBrush::WIDTH_RANGE, 100.0);
|
||||
// The width follows the pen (its pressure, tilt, bearing or rotation) or stays fixed.
|
||||
// The width follows the pen (its pressure, tilt, bearing, rotation or wheel) or stays fixed.
|
||||
if !a.width_mode.is_some_and(Variation::follows_pen) {
|
||||
a.width_mode = None;
|
||||
}
|
||||
|
||||
@@ -1545,6 +1545,64 @@ fn pressure_varies_angle_and_roundness() {
|
||||
assert!(near(h, expected, 0.05), "{h} vs {expected}");
|
||||
}
|
||||
|
||||
/// A stroke that recorded an airbrush pen's finger wheel going from `from` to `to` along it.
|
||||
fn wheeled(from: f64, to: f64) -> StrokeLayer {
|
||||
StrokeLayer { wheel: Some(vectorcraft_doc::PressureProfile { points: vec![(0.0, from), (1.0, to)] }), ..stroke(1.0) }
|
||||
}
|
||||
|
||||
/// Stylus Wheel: a Calligraphic brush's size goes from size − variation at one end of the finger
|
||||
/// wheel to size + variation at the other, a Scatter brush's size from its first value to its
|
||||
/// second, and an Art brush's width from Width to the second width. Each reads only the wheel: the
|
||||
/// pressure, tilt, bearing or rotation recorded instead leaves the value half way.
|
||||
#[test]
|
||||
fn the_stylus_wheel_varies_sizes_and_widths() {
|
||||
let doc = Document::new(1.0, 1.0);
|
||||
let bp = line(0.0, 0.0, 100.0, 0.0);
|
||||
let c = Calligraphic {
|
||||
size: 6.0,
|
||||
variation: [0.0, 0.0, 4.0],
|
||||
modes: Some([Variation::Fixed, Variation::Fixed, Variation::StylusWheel]),
|
||||
..Default::default()
|
||||
};
|
||||
let nib = Brush { name: "w".into(), kind: BrushKind::Calligraphic(c) };
|
||||
let out = stroke_pieces(&doc, &nib, &bp, &wheeled(0.0, 1.0));
|
||||
// Round nib: 2 pt across at the start, 10 pt at the end, 6 pt half way.
|
||||
assert!(near(half_width(&out, 0.5, 1.5), 1.0, 0.1), "{}", half_width(&out, 0.5, 1.5));
|
||||
assert!(near(half_width(&out, 98.5, 99.5), 5.0, 0.1), "{}", half_width(&out, 98.5, 99.5));
|
||||
assert!(near(half_width(&out, 49.5, 50.5), 3.0, 0.1), "{}", half_width(&out, 49.5, 50.5));
|
||||
let others = [
|
||||
pressed(vec![(0.0, 0.0), (1.0, 1.0)]),
|
||||
StrokeLayer { tilt: Some(vectorcraft_doc::PressureProfile { points: vec![(0.0, 0.0), (1.0, 1.0)] }), ..stroke(1.0) },
|
||||
posed(None, Some(90.0), Some(-90.0)),
|
||||
];
|
||||
for st in &others {
|
||||
let h = bounds(&stroke_pieces(&doc, &nib, &bp, st)).height();
|
||||
assert!(near(h, 6.0, 0.05), "{st:?}: {h}");
|
||||
}
|
||||
// Scatter size 50 % to 300 % of 4 pt art: 2 pt at one end of the wheel, 12 pt at the other.
|
||||
let spray = sized_scatter(50.0, 300.0, Variation::StylusWheel);
|
||||
let h: Vec<f64> =
|
||||
stroke_pieces(&doc, &spray, &line(0.0, 0.0, 400.0, 0.0), &wheeled(1.0, 0.0)).iter().map(|n| n.geometric_bounds().unwrap().height()).collect();
|
||||
assert!(near(h[0], 12.0, 0.2) && h[h.len() - 1] < 3.0, "{h:?}");
|
||||
// Art width 50 % to 300 % of 4 pt art.
|
||||
let mut ribbon = art_brush(rect_art(10.0, 4.0), ArtScale::Stretch);
|
||||
if let BrushKind::Art(a) = &mut ribbon.kind {
|
||||
(a.width, a.width_mode, a.width_max) = (50.0, Some(Variation::StylusWheel), Some(300.0));
|
||||
}
|
||||
let out = stroke_pieces(&doc, &ribbon, &bp, &wheeled(1.0, 0.0));
|
||||
assert!(near(half_width(&out, 0.0, 1.0), 6.0, 0.1), "{}", half_width(&out, 0.0, 1.0));
|
||||
assert!(near(half_width(&out, 99.0, 100.0), 1.0, 0.1), "{}", half_width(&out, 99.0, 100.0));
|
||||
for st in &others {
|
||||
let h = bounds(&stroke_pieces(&doc, &ribbon, &bp, st)).height();
|
||||
assert!(near(h, 7.0, 1e-6), "{st:?}: {h}");
|
||||
}
|
||||
// A definition keeps the mode by name.
|
||||
let lib = parse_library(&serde_json::json!([
|
||||
{"name": "a", "type": "art", "art": rect_art(10.0, 4.0), "width_mode": "stylusWheel", "width_max": 300.0},
|
||||
]));
|
||||
assert!(matches!(&lib[0].kind, BrushKind::Art(a) if a.width_mode == Some(Variation::StylusWheel)));
|
||||
}
|
||||
|
||||
/// A stroke that recorded the pen's tilt (`tilt`: 0 upright to 1 flat), bearing and barrel
|
||||
/// rotation (degrees counter-clockwise), each the same all along it where given.
|
||||
fn posed(tilt: Option<f64>, bearing: Option<f64>, rotation: Option<f64>) -> StrokeLayer {
|
||||
@@ -1611,7 +1669,7 @@ fn bearing_and_rotation_turn_the_nib() {
|
||||
#[test]
|
||||
fn pen_modes_without_a_recording_draw_the_value_itself() {
|
||||
let horizontal = line(0.0, 0.0, 100.0, 0.0);
|
||||
for mode in [Variation::Tilt, Variation::Bearing, Variation::Rotation] {
|
||||
for mode in [Variation::Tilt, Variation::Bearing, Variation::Rotation, Variation::StylusWheel] {
|
||||
let c = Calligraphic { angle: 90.0, roundness: 50.0, size: 10.0, variation: [90.0, 50.0, 6.0], modes: Some([mode; 3]) };
|
||||
let b = Brush { name: "n".into(), kind: BrushKind::Calligraphic(c) };
|
||||
let h = bounds(&stroke_pieces(&Document::new(1.0, 1.0), &b, &horizontal, &stroke(1.0))).height();
|
||||
@@ -1658,7 +1716,7 @@ fn a_mouse_stroke_draws_pen_modes_as_pressure_did() {
|
||||
};
|
||||
let (calli_before, scatter_before) = (calli(Variation::Pressure), scattered(Variation::Pressure));
|
||||
assert!(!calli_before.is_empty() && !scatter_before.is_empty());
|
||||
for mode in [Variation::Tilt, Variation::Bearing, Variation::Rotation] {
|
||||
for mode in [Variation::Tilt, Variation::Bearing, Variation::Rotation, Variation::StylusWheel] {
|
||||
assert_eq!(calli(mode), calli_before, "{mode:?}");
|
||||
assert_eq!(scattered(mode), scatter_before, "{mode:?}");
|
||||
}
|
||||
@@ -1726,8 +1784,12 @@ fn brushes_without_modes_vary_randomly_as_before() {
|
||||
stroke_pieces(&Document::new(1.0, 1.0), &old, &bp, &pressed(vec![(0.0, 0.0), (1.0, 1.0)]))
|
||||
);
|
||||
// Modes are saved by name.
|
||||
assert_eq!(serde_json::to_value(Variation::ALL).unwrap(), serde_json::json!(["fixed", "random", "pressure", "tilt", "bearing", "rotation"]));
|
||||
assert!(Variation::ALL.iter().all(|v| Variation::parse(v.id()) == Some(*v)));
|
||||
assert_eq!(
|
||||
serde_json::to_value(Variation::ALL).unwrap(),
|
||||
serde_json::json!(["fixed", "random", "pressure", "tilt", "bearing", "rotation", "stylusWheel"])
|
||||
);
|
||||
assert!(Variation::ALL.iter().all(|v| Variation::parse(v.id()) == Some(*v) && serde_json::to_value(v).unwrap() == v.id()));
|
||||
assert!(!Variation::offered(false).contains(&Variation::StylusWheel) && Variation::offered(true).contains(&Variation::StylusWheel));
|
||||
}
|
||||
|
||||
/// Junk definitions and pressure never panic and never draw non-finite art.
|
||||
|
||||
@@ -127,8 +127,8 @@ impl Appearance {
|
||||
pub fn stroke_mut(&mut self) -> Option<&mut StrokeLayer> {
|
||||
self.items.iter_mut().rev().find_map(|i| if let AppearanceItem::Stroke(s) = i { Some(s) } else { None })
|
||||
}
|
||||
/// This appearance for other art: the pen pressure, tilt, bearing and rotation its strokes
|
||||
/// were drawn with stay with them.
|
||||
/// This appearance for other art: the pen pressure, tilt, bearing, rotation and wheel its
|
||||
/// strokes were drawn with stay with them.
|
||||
pub fn without_pressure(mut self) -> Self {
|
||||
for it in &mut self.items {
|
||||
if let AppearanceItem::Stroke(s) = it {
|
||||
@@ -136,6 +136,7 @@ impl Appearance {
|
||||
s.tilt = None;
|
||||
s.bearing = None;
|
||||
s.rotation = None;
|
||||
s.wheel = None;
|
||||
}
|
||||
}
|
||||
self
|
||||
|
||||
@@ -113,6 +113,11 @@ pub struct StrokeLayer {
|
||||
/// pressure, it stays with this path.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub rotation: Option<AngleProfile>,
|
||||
/// Where the finger wheel of an airbrush pen was set along the stroke: 0 at one end of its
|
||||
/// travel to 1 at the other. Brushes with Stylus Wheel variation vary with it. Like the
|
||||
/// pressure, it stays with this path.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub wheel: Option<PressureProfile>,
|
||||
}
|
||||
|
||||
/// How a gradient on a stroke is laid out (the Gradient panel's Stroke buttons). Saved by variant
|
||||
@@ -187,6 +192,7 @@ impl StrokeLayer {
|
||||
tilt: None,
|
||||
bearing: None,
|
||||
rotation: None,
|
||||
wheel: None,
|
||||
}
|
||||
}
|
||||
/// Weight of the start (`end == false`) or end arrowhead: stroke weight × its scale, at least
|
||||
|
||||
@@ -130,8 +130,9 @@ impl WidthProfile {
|
||||
|
||||
/// Pen pressure recorded along a stroke (the Paintbrush with a graphics tablet): (position 0..1
|
||||
/// along the path, pressure 0..1) samples in order, positions measured as a [`WidthProfile`]'s
|
||||
/// are. The pen's tilt is kept the same way ([`StrokeLayer::tilt`]). Calligraphic and Scatter
|
||||
/// brushes with Pressure or Tilt variation read them; everything else ignores them.
|
||||
/// are. The pen's tilt and an airbrush pen's finger wheel are kept the same way
|
||||
/// ([`StrokeLayer::tilt`], [`StrokeLayer::wheel`]). Brushes with Pressure, Tilt or Stylus Wheel
|
||||
/// variation read them; everything else ignores them.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PressureProfile {
|
||||
pub points: Vec<(f64, f64)>,
|
||||
|
||||
@@ -188,7 +188,7 @@ fn angle_profiles_join_samples_the_shorter_way_round() {
|
||||
#[test]
|
||||
fn strokes_without_pressure_round_trip_unchanged() {
|
||||
let json = serde_json::to_value(StrokeLayer::new(Paint::None, 2.0)).unwrap();
|
||||
for key in ["pressure", "tilt", "bearing", "rotation"] {
|
||||
for key in ["pressure", "tilt", "bearing", "rotation", "wheel"] {
|
||||
assert!(json.get(key).is_none(), "{key}");
|
||||
}
|
||||
let st: StrokeLayer = serde_json::from_value(json).unwrap();
|
||||
@@ -199,19 +199,21 @@ fn strokes_without_pressure_round_trip_unchanged() {
|
||||
let mut ap = Appearance::basic(Paint::None, Paint::None, 1.0);
|
||||
ap.stroke_mut().unwrap().pressure = Some(PressureProfile::sample());
|
||||
assert_eq!(ap.without_pressure().stroke().unwrap().pressure, None);
|
||||
// The pen's tilt, bearing and rotation load, save and stay behind the same way.
|
||||
// The pen's tilt, bearing, rotation and wheel load, save and stay behind the same way.
|
||||
let posed = StrokeLayer {
|
||||
tilt: Some(PressureProfile::sample()),
|
||||
bearing: Some(AngleProfile::sample()),
|
||||
rotation: Some(AngleProfile { points: vec![(0.0, -45.0)] }),
|
||||
wheel: Some(PressureProfile { points: vec![(0.0, 0.25), (1.0, 0.75)] }),
|
||||
..back
|
||||
};
|
||||
assert_eq!(serde_json::to_value(&posed).unwrap()["wheel"], serde_json::json!({"points": [[0.0, 0.25], [1.0, 0.75]]}));
|
||||
let again: StrokeLayer = serde_json::from_value(serde_json::to_value(&posed).unwrap()).unwrap();
|
||||
assert_eq!(again, posed);
|
||||
let mut ap = Appearance::basic(Paint::None, Paint::None, 1.0);
|
||||
*ap.stroke_mut().unwrap() = posed;
|
||||
let st = ap.without_pressure().stroke().cloned().unwrap();
|
||||
assert_eq!((st.pressure, st.tilt, st.bearing, st.rotation), (None, None, None, None));
|
||||
assert_eq!((st.pressure, st.tilt, st.bearing, st.rotation, st.wheel), (None, None, None, None, None));
|
||||
}
|
||||
|
||||
/// The Lens profile's widths at its middle, a quarter of the way along and past its end.
|
||||
|
||||
+52
-9
@@ -6,7 +6,7 @@
|
||||
//! tool clicked.
|
||||
//! - **Paint**: colours, gradients (stops resampled to a common set when their counts differ),
|
||||
//! opacity, stroke weight, dashes, miter limit, width profiles and the pen pressure, tilt,
|
||||
//! bearing and rotation that brushes read interpolate; what can't
|
||||
//! bearing, rotation and wheel that brushes read interpolate; what can't
|
||||
//! (caps, joins, brushes, fonts, symbols, text content) switches halfway.
|
||||
//! - **Groups** pair their children in stacking order; the children one group has more of grow
|
||||
//! out of the other group's centre. Compound paths stay compound paths.
|
||||
@@ -429,8 +429,8 @@ fn lerp_angle(x: Option<&AngleProfile>, y: Option<&AngleProfile>, t: f64) -> Opt
|
||||
}
|
||||
|
||||
/// Interpolate a stroke's paint, weight, opacity, miter limit, dashes, arrowhead scale, width
|
||||
/// profile and the pen pressure, tilt, bearing and rotation its brush reads into `o` (a copy of
|
||||
/// the nearer stroke, so caps, joins, alignment, arrowheads and brushes switch halfway).
|
||||
/// profile and the pen pressure, tilt, bearing, rotation and wheel its brush reads into `o` (a
|
||||
/// copy of the nearer stroke, so caps, joins, alignment, arrowheads and brushes switch halfway).
|
||||
fn lerp_stroke(o: &mut StrokeLayer, x: &StrokeLayer, y: &StrokeLayer, t: f64) {
|
||||
let tf = t as f32;
|
||||
o.paint = lerp_paint(&x.paint, &y.paint, tf);
|
||||
@@ -444,6 +444,7 @@ fn lerp_stroke(o: &mut StrokeLayer, x: &StrokeLayer, y: &StrokeLayer, t: f64) {
|
||||
o.tilt = lerp_pressure(x.tilt.as_ref(), y.tilt.as_ref(), t);
|
||||
o.bearing = lerp_angle(x.bearing.as_ref(), y.bearing.as_ref(), t);
|
||||
o.rotation = lerp_angle(x.rotation.as_ref(), y.rotation.as_ref(), t);
|
||||
o.wheel = lerp_pressure(x.wheel.as_ref(), y.wheel.as_ref(), t);
|
||||
}
|
||||
|
||||
/// Interpolate appearance stacks: item by item when their structure matches, else the top fill
|
||||
@@ -755,9 +756,9 @@ fn reorient_dash(d: &mut Dash, o: Orient, lens: &[f64]) {
|
||||
}
|
||||
|
||||
/// A key's stroke read along its subpaths turned as `o` says (`lens`: their lengths): its width
|
||||
/// profile (whose sides swap when reversed), pen pressure, tilt, bearing and rotation, its dashes,
|
||||
/// a gradient along the path or across it (whose sides swap when reversed). Its arrowheads stay as
|
||||
/// they are.
|
||||
/// profile (whose sides swap when reversed), pen pressure, tilt, bearing, rotation and wheel, its
|
||||
/// dashes, a gradient along the path or across it (whose sides swap when reversed). Its arrowheads
|
||||
/// stay as they are.
|
||||
fn reorient_stroke(s: &mut StrokeLayer, o: Orient, lens: &[f64]) {
|
||||
if o.is_identity() {
|
||||
return;
|
||||
@@ -805,7 +806,7 @@ fn reorient_stroke(s: &mut StrokeLayer, o: Orient, lens: &[f64]) {
|
||||
let out = reoriented(&pts, o, |f| p.at(f), |v| v, |(l, r)| (r, l));
|
||||
p.points = out.into_iter().map(|(t, (l, r))| (t, l, r)).collect();
|
||||
}
|
||||
for p in [&mut s.pressure, &mut s.tilt].into_iter().flatten() {
|
||||
for p in [&mut s.pressure, &mut s.tilt, &mut s.wheel].into_iter().flatten() {
|
||||
let out = reoriented(&p.points, o, |f| p.at(f), same, same);
|
||||
p.points = out;
|
||||
}
|
||||
@@ -842,8 +843,8 @@ fn reorient_strokes(n: &mut Node, o: Orient) {
|
||||
|
||||
/// Turn the strokes of path or compound path `n` for Reverse Path Direction, before its subpaths
|
||||
/// flagged in `reversed` are reversed with [`SubPath::reverse`] (a closed one then starts at its
|
||||
/// last anchor): each stroke's width profile (sides swapped), pen pressure, tilt, bearing and
|
||||
/// rotation then run the new way, so the stroke draws as it did. A compound path's subpaths are
|
||||
/// last anchor): each stroke's width profile (sides swapped), pen pressure, tilt, bearing,
|
||||
/// rotation and wheel then run the new way, so the stroke draws as it did. A compound path's subpaths are
|
||||
/// its members' subpaths in order. A stroke reads one profile along every subpath, so it turns
|
||||
/// only when all of them turn alike. Arrowheads stay at the path's start and end.
|
||||
pub fn reverse_stroke_records(n: &mut Node, reversed: &[bool]) {
|
||||
@@ -3014,6 +3015,48 @@ mod tests {
|
||||
assert!((rot(0.5, 0.499) - rot(0.5, 0.501)).abs() < 1.0, "no jump where the key started: {:?}", stroke(&blend.at(0.5)).rotation);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_stylus_wheel_recording_turns_with_the_gradient_and_dashes_of_its_stroke() {
|
||||
let keyed = |path: PathData, edit: &dyn Fn(&mut StrokeLayer)| {
|
||||
let mut ap = Appearance::default();
|
||||
ap.set_stroke(Paint::solid(Color::BLACK));
|
||||
if let Some(s) = ap.stroke_mut() {
|
||||
edit(s);
|
||||
}
|
||||
Node::path(NodeId(1), path, ap)
|
||||
};
|
||||
let stroke = |n: &Node| n.appearance.stroke().cloned().unwrap_or_else(|| panic!("a stroke"));
|
||||
let wheel = |s: &StrokeLayer, f: f64| s.wheel.as_ref().map_or(PressureProfile::MID, |p| p.at(f));
|
||||
let light = |s: &StrokeLayer, u: f32| match &s.paint {
|
||||
Paint::Gradient(g) => g.gradient.sample(u).0.to_rgb().iter().sum::<f32>(),
|
||||
p => panic!("a gradient: {p:?}"),
|
||||
};
|
||||
let recorded = |s: &mut StrokeLayer| {
|
||||
s.wheel = Some(PressureProfile { points: vec![(0.0, 0.0), (1.0, 1.0)] });
|
||||
s.paint = Paint::Gradient(Box::new(GradientPaint::new(Gradient::default())));
|
||||
s.gradient_mode = StrokeGradientMode::Along;
|
||||
s.dash = Some(Dash { pattern: vec![1.0, 2.0, 3.0, 1.5], offset: 0.75, align_corners: false });
|
||||
};
|
||||
// An open key clicked at its last anchor: the wheel runs the other way with the gradient
|
||||
// along it, and the dashes are read from its end.
|
||||
let line = |x: f64| PathData::single(SubPath::polyline(&[Point::new(x, 0.0), Point::new(x + 13.0, 0.0)], false));
|
||||
let key = keyed(line(100.0), &recorded);
|
||||
let s = stroke(&Lerp::new(&keyed(line(0.0), &|_| {}), &key, (None, Some(1))).at(1.0));
|
||||
assert!((wheel(&s, 0.0) - 1.0).abs() < 1e-9 && wheel(&s, 1.0).abs() < 1e-9, "{:?}", s.wheel);
|
||||
assert!(light(&s, 0.0) < 0.01 && light(&s, 1.0) > 2.99, "{:?}", s.paint);
|
||||
assert_ne!(s.dash, stroke(&key).dash, "the dashes turn too");
|
||||
// A closed key started half way round starts its wheel recording there, stepping where its
|
||||
// own start was, as its gradient does.
|
||||
let square = |x: f64| shapes::rectangle(Rect::new(x, 0.0, x + 10.0, 10.0));
|
||||
let key = keyed(square(100.0), &recorded);
|
||||
let s = stroke(&Lerp::new(&keyed(square(0.0), &|_| {}), &key, (Some(0), Some(2))).at(1.0));
|
||||
assert!((wheel(&s, 0.25) - 0.75).abs() < 1e-9 && (wheel(&s, 0.75) - 0.25).abs() < 1e-9, "{:?}", s.wheel);
|
||||
assert!((light(&s, 0.25) - 0.75).abs() < 0.02 && (light(&s, 0.75) - 2.25).abs() < 0.02, "{:?}", s.paint);
|
||||
// Half way through, a key without a recording counts as the wheel half way.
|
||||
let s = stroke(&Lerp::new(&keyed(square(0.0), &|_| {}), &key, (Some(0), Some(2))).at(0.5));
|
||||
assert!((wheel(&s, 0.25) - 0.625).abs() < 1e-9, "{:?}", s.wheel);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stroke_gradients_and_dashes_turn_with_a_key_path_started_elsewhere() {
|
||||
let keyed = |path: PathData, edit: &dyn Fn(&mut StrokeLayer)| {
|
||||
|
||||
+23
-1
@@ -354,7 +354,8 @@ pub fn appearance_heap_bytes(a: &Appearance) -> usize {
|
||||
AppearanceItem::Stroke(s) => {
|
||||
s.dash.as_ref().map_or(0, |d| vec_bytes(&d.pattern))
|
||||
+ s.profile.as_ref().map_or(0, |p| vec_bytes(&p.points))
|
||||
+ s.pressure.as_ref().map_or(0, |p| vec_bytes(&p.points))
|
||||
+ [&s.pressure, &s.tilt, &s.wheel].into_iter().flatten().map(|p| vec_bytes(&p.points)).sum::<usize>()
|
||||
+ [&s.bearing, &s.rotation].into_iter().flatten().map(|p| vec_bytes(&p.points)).sum::<usize>()
|
||||
+ s.brush.as_ref().map_or(0, String::capacity)
|
||||
}
|
||||
_ => 0,
|
||||
@@ -425,6 +426,27 @@ mod tests {
|
||||
d
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_pen_recording_of_a_stroke_counts() {
|
||||
use crate::{AngleProfile, PressureProfile};
|
||||
let plain = Appearance::default_art();
|
||||
let base = appearance_heap_bytes(&plain);
|
||||
let ramp = || PressureProfile { points: (0..100).map(|i| (f64::from(i) / 99.0, 0.5)).collect() };
|
||||
let turn = || AngleProfile { points: (0..100).map(|i| (f64::from(i) / 99.0, 10.0)).collect() };
|
||||
for i in 0..5 {
|
||||
let mut a = plain.clone();
|
||||
let s = a.stroke_mut().unwrap();
|
||||
match i {
|
||||
0 => s.pressure = Some(ramp()),
|
||||
1 => s.tilt = Some(ramp()),
|
||||
2 => s.bearing = Some(turn()),
|
||||
3 => s.rotation = Some(turn()),
|
||||
_ => s.wheel = Some(ramp()),
|
||||
}
|
||||
assert!(appearance_heap_bytes(&a) >= base + 100 * size_of::<(f64, f64)>(), "recording {i}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unchanged_copy_keeps_nothing_of_its_own() {
|
||||
let d = doc_with_rects(10);
|
||||
|
||||
@@ -165,7 +165,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Brush Options…",
|
||||
[],
|
||||
None,
|
||||
"{name, params?: {…fields to change (brush.get shows them; values outside their ranges are clamped). calligraphic: angle −180..180° (counter-clockwise from level), roundness 0..100%, size 0..1296 pt, variation: [angle°, roundness%, size pt], modes: [fixed|random|pressure|tilt|bearing|rotation for angle, roundness, size] (pressure goes from value − variation at the lightest pen pressure to value + variation at the heaviest; tilt from value − variation with the pen lying flat to value + variation with it upright; bearing and rotation add variation × the pen's bearing (which way it leans, counter-clockwise from leaning right) or its barrel's counter-clockwise rotation over 180°; the angle turns on past ±180°). scatter: size [a, b] 1..10000%, spacing [a, b] 1..10000%, scatter [a, b] −1000..1000%, rotation [a, b] −180..180° (counter-clockwise), modes: [fixed|random|pressure|tilt|bearing|rotation for size, spacing, scatter, rotation] (fixed: a; random: between a and b; pressure: a at the lightest pen pressure to b at the heaviest; tilt: a with the pen lying flat to b upright; bearing and rotation: a at −180° to b at 180°), rotation_relative_to_path, hue_jitter 0..180° (each copy turns the hue of its solid colors, after the colorization, by its own amount up to this far either way, the same on every redraw; colors without a hue stay; 0: off). art: width 1..1000%, width_mode: null (fixed)|pressure|tilt|bearing|rotation, width_max 1..1000% (pressure: width at the lightest pen pressure to width_max at the heaviest; tilt: width with the pen lying flat to width_max upright; bearing and rotation: width at −180° to width_max at 180°; half way on a stroke drawn without that input), scale: {mode: proportional|stretch|betweenGuides, start, end: 0..1 of the art length}, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flip_along, flip_across, overlap. pattern: scale 1..10000%, spacing 0..10000%, fit: stretch|addSpace|approximate, flip_along, flip_across, outer_corner and inner_corner: corner tile art (drawn as the corner that joins a side tile on its right to one below it) or null, outer_source and inner_source: what that kind of corner draws without its art: none|autoCentered|autoBetween|autoSliced|autoOverlap (a tile made from the side tile), or null (the other kind of corner's art); side_tile, outer_corner_tile, inner_corner_tile, start_tile, end_tile: a document pattern name, original, or none (side refuses none); corner tiles also take autoCentered|autoBetween|autoSliced|autoOverlap. Each tile also accepts {pattern: name} to select a swatch whose name is a reserved choice. scatter, art and pattern: colorization: {method: none|tints|tintsAndShades|hueShift, key: colour (hueShift: the art colour that becomes the stroke colour; without a key: the solid color the art's fills and strokes use most, black when they use none)}; colorization and the art brush's scale change only the fields given}, newName? (trimmed; blank: the name is kept; a new bristle brush name has at most 31 characters, and a longer name the brush has is kept)} edit a brush definition (strokes using it update) → {name}",
|
||||
"{name, params?: {…fields to change (brush.get shows them; values outside their ranges are clamped). calligraphic: angle −180..180° (counter-clockwise from level), roundness 0..100%, size 0..1296 pt, variation: [angle°, roundness%, size pt], modes: [fixed|random|pressure|tilt|bearing|rotation|stylusWheel for angle, roundness, size] (pressure goes from value − variation at the lightest pen pressure to value + variation at the heaviest; tilt from value − variation with the pen lying flat to value + variation with it upright; bearing and rotation add variation × the pen's bearing (which way it leans, counter-clockwise from leaning right) or its barrel's counter-clockwise rotation over 180°; stylusWheel from value − variation at one end of an airbrush pen's finger wheel to value + variation at the other; the angle turns on past ±180°). scatter: size [a, b] 1..10000%, spacing [a, b] 1..10000%, scatter [a, b] −1000..1000%, rotation [a, b] −180..180° (counter-clockwise), modes: [fixed|random|pressure|tilt|bearing|rotation|stylusWheel for size, spacing, scatter, rotation] (fixed: a; random: between a and b; pressure: a at the lightest pen pressure to b at the heaviest; tilt: a with the pen lying flat to b upright; bearing and rotation: a at −180° to b at 180°; stylusWheel: a at one end of an airbrush pen's finger wheel to b at the other), rotation_relative_to_path, hue_jitter 0..180° (each copy turns the hue of its solid colors, after the colorization, by its own amount up to this far either way, the same on every redraw; colors without a hue stay; 0: off). art: width 1..1000%, width_mode: null (fixed)|pressure|tilt|bearing|rotation|stylusWheel, width_max 1..1000% (pressure: width at the lightest pen pressure to width_max at the heaviest; tilt: width with the pen lying flat to width_max upright; bearing and rotation: width at −180° to width_max at 180°; stylusWheel: width at one end of the finger wheel to width_max at the other; half way on a stroke drawn without that input), scale: {mode: proportional|stretch|betweenGuides, start, end: 0..1 of the art length}, direction: leftToRight|rightToLeft|topToBottom|bottomToTop, flip_along, flip_across, overlap. pattern: scale 1..10000%, spacing 0..10000%, fit: stretch|addSpace|approximate, flip_along, flip_across, outer_corner and inner_corner: corner tile art (drawn as the corner that joins a side tile on its right to one below it) or null, outer_source and inner_source: what that kind of corner draws without its art: none|autoCentered|autoBetween|autoSliced|autoOverlap (a tile made from the side tile), or null (the other kind of corner's art); side_tile, outer_corner_tile, inner_corner_tile, start_tile, end_tile: a document pattern name, original, or none (side refuses none); corner tiles also take autoCentered|autoBetween|autoSliced|autoOverlap. Each tile also accepts {pattern: name} to select a swatch whose name is a reserved choice. scatter, art and pattern: colorization: {method: none|tints|tintsAndShades|hueShift, key: colour (hueShift: the art colour that becomes the stroke colour; without a key: the solid color the art's fills and strokes use most, black when they use none)}; colorization and the art brush's scale change only the fields given}, newName? (trimmed; blank: the name is kept; a new bristle brush name has at most 31 characters, and a longer name the brush has is kept)} edit a brush definition (strokes using it update) → {name}",
|
||||
has_doc,
|
||||
brush_options
|
||||
),
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Pencil",
|
||||
[],
|
||||
None,
|
||||
"{points: [[x,y]…] or [[x,y,pressure]…] or [[x,y,pressure,tiltX,tiltY,rotation]…] (pen pressure 0..1: the stroke keeps it, for Calligraphic and Scatter brushes with Pressure variation; a point without one presses fully. Pen tilt in degrees, each −90..90, x positive leaning right and y leaning down the page, and barrel rotation in degrees clockwise, 0..360: the stroke keeps how far the pen leaned, which way and how far its barrel turned, for brushes with Tilt, Bearing and Rotation variation; null for what a point lacks. A pressure, tilt or rotation outside its range, or a point array of more than six numbers, is an error), fidelity?: pt (1.5; from 0.000015625 (0.01 / 640) to 100 / 0.0313 (about 3194.89), the Pencil's and the Paintbrush's 0.01 to 100 px Fidelity at the highest and the lowest zoom; a value outside that range is an error. The tools send their Fidelity in pixels divided by the zoom, kept within the range), fit?: bool (true; false: the points are joined by straight segments, as the Pencil previews a stroke with Live curve fitting off), closed?, style?: \"pencil\" (default) | \"brush\", fill?: bool, keepSelected?: bool (true: the drawn or continued path is selected; false: a new path leaves nothing selected, and a continued or redrawn one is deselected while the rest of the selection stays), extend?: {id, end?: \"end\" (default) | \"start\"}, connect?: {id, end: \"start\"|\"end\"} (only with extend), redraw?: {id, within?: pt (12)}} fit a freehand stroke → {id}. extend continues the path from that end, and closes it when `closed` is true (left out, when the stroke ends within four Fidelities of the path's other end, 6 to 400 pt); with connect, the stroke ends on that end of another path's last open subpath and joins it on, in one path with the extended path's appearance (the other path is removed when nothing of it is left); redraw (Edit Selected Paths) replaces the section of the path between where the stroke starts and ends, each within `within` of one subpath (the shorter way round a closed one), and draws a new path when the stroke doesn't end on it. Any other style, extend end or connect end, connect without extend, and a connect that names no other path with an open end are errors, a stroke of one point included, and nothing changes",
|
||||
"{points: [[x,y]…] or [[x,y,pressure]…] or [[x,y,pressure,tiltX,tiltY,rotation,wheel]…] (pen pressure 0..1: the stroke keeps it, for Calligraphic and Scatter brushes with Pressure variation; a point without one presses fully. Pen tilt in degrees, each −90..90, x positive leaning right and y leaning down the page, and barrel rotation in degrees clockwise, 0..360: the stroke keeps how far the pen leaned, which way and how far its barrel turned, for brushes with Tilt, Bearing and Rotation variation. An airbrush pen's finger wheel 0..1: the stroke keeps it for brushes with Stylus Wheel variation, a point without one half way; null for what a point lacks. A pressure, tilt, rotation or wheel outside its range, or a point array of more than seven numbers, is an error), fidelity?: pt (1.5; from 0.000015625 (0.01 / 640) to 100 / 0.0313 (about 3194.89), the Pencil's and the Paintbrush's 0.01 to 100 px Fidelity at the highest and the lowest zoom; a value outside that range is an error. The tools send their Fidelity in pixels divided by the zoom, kept within the range), fit?: bool (true; false: the points are joined by straight segments, as the Pencil previews a stroke with Live curve fitting off), closed?, style?: \"pencil\" (default) | \"brush\", fill?: bool, keepSelected?: bool (true: the drawn or continued path is selected; false: a new path leaves nothing selected, and a continued or redrawn one is deselected while the rest of the selection stays), extend?: {id, end?: \"end\" (default) | \"start\"}, connect?: {id, end: \"start\"|\"end\"} (only with extend), redraw?: {id, within?: pt (12)}} fit a freehand stroke → {id}. extend continues the path from that end, and closes it when `closed` is true (left out, when the stroke ends within four Fidelities of the path's other end, 6 to 400 pt); with connect, the stroke ends on that end of another path's last open subpath and joins it on, in one path with the extended path's appearance (the other path is removed when nothing of it is left); redraw (Edit Selected Paths) replaces the section of the path between where the stroke starts and ends, each within `within` of one subpath (the shorter way round a closed one), and draws a new path when the stroke doesn't end on it. Any other style, extend end or connect end, connect without extend, and a connect that names no other path with an open end are errors, a stroke of one point included, and nothing changes",
|
||||
has_doc,
|
||||
freehand
|
||||
),
|
||||
@@ -92,7 +92,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Eraser",
|
||||
[],
|
||||
None,
|
||||
"{points: [[x,y]…] or [[x,y,pressure]…] or [[x,y,pressure,tiltX,tiltY,rotation]…] (pen pressure 0..1, tilt −90..90°, barrel rotation 0..360° clockwise; pen values are checked as path.freehand checks them), size?: pt (10; from 0.1 to 1000), angle?: ° (0, −180–180: the tip's long axis counter-clockwise from level), roundness?: % (100, 1–100), angleMode?, roundnessMode?, sizeMode?: \"fixed\" (default) | \"random\" | \"pressure\" | \"tilt\" | \"bearing\" | \"rotation\" (Eraser Tool Options' variation menus; a varied angle turns either way, clockwise or counter-clockwise), angleVariation?: ° (0–180, default 0, either way: clockwise or counter-clockwise), roundnessVariation?: % (0–100, default 0), sizeVariation?: pt (0–1000, default 0)} or {rect: [x, y, width, height] (pt; the Eraser's Alt-drag marquee)} erase the stroke of an elliptical tip from paths (selected, or all) → {ids}. The tip is `size` across its long axis, which runs at `angle` counter-clockwise from horizontal; its short axis is `roundness` percent of the long one. A value whose mode is not fixed varies by up to its variation either way: random draws one value for the drag; pressure goes from the value less the variation where the pen presses lightest to the value plus it where it presses hardest (size on pressure as path.blob); tilt from less with the pen lying flat to more with it upright; bearing and rotation from less at −180° to more at 180° of the pen's lean direction or barrel turn. A drag without that pen reading (a mouse) erases at the value itself. An angle or roundness outside its range, an unknown mode, or a variation below 0 or past its range is refused with an error and erases nothing. `rect` in place of `points` erases everything inside the rectangle: closed paths and filled open paths without a visible painted stroke lose its area, and other open paths are cut where they cross its edges; the tip's size, angle, roundness and variations do not apply. A width or height of 0 or less, a value that is not a finite number, or `points` and `rect` together is an error. When nothing is erased, no undo step is added",
|
||||
"{points: [[x,y]…] or [[x,y,pressure]…] or [[x,y,pressure,tiltX,tiltY,rotation]…] or [[x,y,pressure,tiltX,tiltY,rotation,wheel]…] (pen pressure 0..1, tilt −90..90°, barrel rotation 0..360° clockwise, finger wheel 0..1; pen values are checked as path.freehand checks them), size?: pt (10; from 0.1 to 1000), angle?: ° (0, −180–180: the tip's long axis counter-clockwise from level), roundness?: % (100, 1–100), angleMode?, roundnessMode?, sizeMode?: \"fixed\" (default) | \"random\" | \"pressure\" | \"tilt\" | \"bearing\" | \"rotation\" | \"stylusWheel\" (Eraser Tool Options' variation menus; a varied angle turns either way, clockwise or counter-clockwise), angleVariation?: ° (0–180, default 0, either way: clockwise or counter-clockwise), roundnessVariation?: % (0–100, default 0), sizeVariation?: pt (0–1000, default 0)} or {rect: [x, y, width, height] (pt; the Eraser's Alt-drag marquee)} erase the stroke of an elliptical tip from paths (selected, or all) → {ids}. The tip is `size` across its long axis, which runs at `angle` counter-clockwise from horizontal; its short axis is `roundness` percent of the long one. A value whose mode is not fixed varies by up to its variation either way: random draws one value for the drag; pressure goes from the value less the variation where the pen presses lightest to the value plus it where it presses hardest (size on pressure as path.blob); tilt from less with the pen lying flat to more with it upright; bearing and rotation from less at −180° to more at 180° of the pen's lean direction or barrel turn; stylusWheel from less at one end of an airbrush pen's finger wheel travel to more at the other. A drag without that pen reading (a mouse) erases at the value itself. An angle or roundness outside its range, an unknown mode, or a variation below 0 or past its range is refused with an error and erases nothing. `rect` in place of `points` erases everything inside the rectangle: closed paths and filled open paths without a visible painted stroke lose its area, and other open paths are cut where they cross its edges; the tip's size, angle, roundness and variations do not apply. A width or height of 0 or less, a value that is not a finite number, or `points` and `rect` together is an error. When nothing is erased, no undo step is added",
|
||||
has_doc,
|
||||
erase_region
|
||||
),
|
||||
|
||||
@@ -22,15 +22,17 @@ pub(super) struct Sample {
|
||||
tilt: Option<[f64; 2]>,
|
||||
/// Barrel rotation, degrees clockwise.
|
||||
rotation: Option<f64>,
|
||||
/// The airbrush finger wheel, 0..1.
|
||||
wheel: Option<f64>,
|
||||
}
|
||||
|
||||
/// The keys of a point's pen values, in the order a point given as an array holds them after its
|
||||
/// x and y.
|
||||
const PEN_KEYS: [&str; 4] = ["pressure", "tiltX", "tiltY", "rotation"];
|
||||
const PEN_KEYS: [&str; 5] = ["pressure", "tiltX", "tiltY", "rotation", "wheel"];
|
||||
|
||||
/// The range each of [`PEN_KEYS`] takes: pressure 0..1, each tilt −90..90 degrees and rotation
|
||||
/// 0..360 degrees (360 is the same direction as 0).
|
||||
const PEN_RANGES: [(f64, f64); PEN_KEYS.len()] = [(0.0, 1.0), (-90.0, 90.0), (-90.0, 90.0), (0.0, 360.0)];
|
||||
/// The range each of [`PEN_KEYS`] takes: pressure 0..1, each tilt −90..90 degrees, rotation
|
||||
/// 0..360 degrees (360 is the same direction as 0) and the wheel 0..1.
|
||||
const PEN_RANGES: [(f64, f64); PEN_KEYS.len()] = [(0.0, 1.0), (-90.0, 90.0), (-90.0, 90.0), (0.0, 360.0), (0.0, 1.0)];
|
||||
|
||||
/// Blob Brush and Eraser Tool Options' Size, in points.
|
||||
pub(super) const SIZES: (f64, f64) = (0.1, 1000.0);
|
||||
@@ -61,11 +63,11 @@ pub(super) fn point_entry(v: &Value, cmd: &str) -> Result<Point> {
|
||||
}
|
||||
|
||||
/// [`points_param`] with what a pen read at each point, as far as it is given:
|
||||
/// `[[x,y,pressure,tiltX,tiltY,rotation]…]` or `[{x,y,pressure,tiltX,tiltY,rotation}…]`. Pressure
|
||||
/// is 0..1; tilt in degrees, each −90..90 (one of the two without the other is 0); rotation in
|
||||
/// degrees clockwise, 0..360. A point whose x or y is not a number, whose pressure, tilt or
|
||||
/// rotation is neither a number nor null or is outside its range, or an array of more than six
|
||||
/// numbers, is an error.
|
||||
/// `[[x,y,pressure,tiltX,tiltY,rotation,wheel]…]` or `[{x,y,pressure,tiltX,tiltY,rotation,wheel}…]`.
|
||||
/// Pressure is 0..1; tilt in degrees, each −90..90 (one of the two without the other is 0);
|
||||
/// rotation in degrees clockwise, 0..360; the wheel 0..1. A point whose x or y is not a number,
|
||||
/// whose pressure, tilt, rotation or wheel is neither a number nor null or is outside its range,
|
||||
/// or an array of more than seven numbers, is an error.
|
||||
pub(super) fn samples_param(p: &Value, key: &str, cmd: &str) -> Result<Vec<Sample>> {
|
||||
let a = p.get(key).and_then(Value::as_array).ok_or_else(|| bad(cmd, format!("missing array `{key}`")))?;
|
||||
let pts: Vec<Sample> = a
|
||||
@@ -79,7 +81,7 @@ pub(super) fn samples_param(p: &Value, key: &str, cmd: &str) -> Result<Vec<Sampl
|
||||
let key = format!("{key}[{at}]");
|
||||
return Err(bad(cmd, format!("`{key}` must be an array of at most {MAX_ITEMS} entries")));
|
||||
}
|
||||
let mut pen = [None; 4];
|
||||
let mut pen = [None; PEN_KEYS.len()];
|
||||
for (i, ((key, range), slot)) in PEN_KEYS.iter().zip(PEN_RANGES).zip(&mut pen).enumerate() {
|
||||
let given = match v {
|
||||
Value::Array(xy) => xy.get(i + 2),
|
||||
@@ -91,9 +93,9 @@ pub(super) fn samples_param(p: &Value, key: &str, cmd: &str) -> Result<Vec<Sampl
|
||||
Some(v) => return Err(bad(cmd, format!("`{key}` must be a number, not {v}"))),
|
||||
};
|
||||
}
|
||||
let [pressure, tx, ty, rotation] = pen;
|
||||
let [pressure, tx, ty, rotation, wheel] = pen;
|
||||
let tilt = (tx.is_some() || ty.is_some()).then(|| [tx, ty].map(|t| t.unwrap_or(0.0)));
|
||||
Ok(Sample { pt: point_entry(v, cmd)?, pressure, tilt, rotation })
|
||||
Ok(Sample { pt: point_entry(v, cmd)?, pressure, tilt, rotation, wheel })
|
||||
})
|
||||
.collect::<Result<_>>()?;
|
||||
if pts.is_empty() {
|
||||
@@ -126,6 +128,15 @@ fn stroke_pressure(samples: &[Sample]) -> Option<PressureProfile> {
|
||||
PressureProfile::from_samples(along(samples).into_iter().zip(samples).map(|(t, s)| (t, s.pressure.unwrap_or(1.0))))
|
||||
}
|
||||
|
||||
/// Where an airbrush pen's finger wheel was set along a freehand stroke, when any of its samples
|
||||
/// has it; samples without it count as the middle of its travel, which draws a brush's own value.
|
||||
fn stroke_wheel(samples: &[Sample]) -> Option<PressureProfile> {
|
||||
if samples.iter().all(|s| s.wheel.is_none()) {
|
||||
return None;
|
||||
}
|
||||
PressureProfile::from_samples(along(samples).into_iter().zip(samples).map(|(t, s)| (t, s.wheel.unwrap_or(PressureProfile::MID))))
|
||||
}
|
||||
|
||||
/// A pen that leans less than this many degrees from upright leans no way in particular: its
|
||||
/// bearing is the one before it.
|
||||
const UPRIGHT: f64 = 1.0;
|
||||
@@ -165,24 +176,31 @@ fn stroke_pose(samples: &[Sample]) -> (Option<PressureProfile>, Option<AngleProf
|
||||
(tilt.flatten(), bearing.flatten(), rotation.flatten())
|
||||
}
|
||||
|
||||
/// What a pen recorded along a stroke ([`StrokeLayer`]'s `pressure`, `tilt`, `bearing` and
|
||||
/// `rotation`).
|
||||
/// What a pen recorded along a stroke ([`StrokeLayer`]'s `pressure`, `tilt`, `bearing`,
|
||||
/// `rotation` and `wheel`).
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub(super) struct PenRecord {
|
||||
pressure: Option<PressureProfile>,
|
||||
tilt: Option<PressureProfile>,
|
||||
bearing: Option<AngleProfile>,
|
||||
rotation: Option<AngleProfile>,
|
||||
wheel: Option<PressureProfile>,
|
||||
}
|
||||
|
||||
impl PenRecord {
|
||||
/// What a freehand stroke's samples recorded.
|
||||
pub(super) fn of_samples(samples: &[Sample]) -> Self {
|
||||
let (tilt, bearing, rotation) = stroke_pose(samples);
|
||||
Self { pressure: stroke_pressure(samples), tilt, bearing, rotation }
|
||||
Self { pressure: stroke_pressure(samples), tilt, bearing, rotation, wheel: stroke_wheel(samples) }
|
||||
}
|
||||
pub(super) fn of(st: &StrokeLayer) -> Self {
|
||||
Self { pressure: st.pressure.clone(), tilt: st.tilt.clone(), bearing: st.bearing.clone(), rotation: st.rotation.clone() }
|
||||
Self {
|
||||
pressure: st.pressure.clone(),
|
||||
tilt: st.tilt.clone(),
|
||||
bearing: st.bearing.clone(),
|
||||
rotation: st.rotation.clone(),
|
||||
wheel: st.wheel.clone(),
|
||||
}
|
||||
}
|
||||
pub(super) fn is_empty(&self) -> bool {
|
||||
*self == Self::default()
|
||||
@@ -195,6 +213,7 @@ impl PenRecord {
|
||||
tilt: PressureProfile::extended(self.tilt.as_ref(), old_len, added.tilt.as_ref(), added_len),
|
||||
bearing: AngleProfile::extended(self.bearing.as_ref(), old_len, added.bearing.as_ref(), added_len),
|
||||
rotation: AngleProfile::extended(self.rotation.as_ref(), old_len, added.rotation.as_ref(), added_len),
|
||||
wheel: PressureProfile::extended(self.wheel.as_ref(), old_len, added.wheel.as_ref(), added_len),
|
||||
}
|
||||
}
|
||||
/// The record along the path reversed.
|
||||
@@ -204,6 +223,7 @@ impl PenRecord {
|
||||
tilt: self.tilt.as_ref().map(PressureProfile::reversed),
|
||||
bearing: self.bearing.as_ref().map(AngleProfile::reversed),
|
||||
rotation: self.rotation.as_ref().map(AngleProfile::reversed),
|
||||
wheel: self.wheel.as_ref().map(PressureProfile::reversed),
|
||||
}
|
||||
}
|
||||
/// Keep the record on stroke `st`.
|
||||
@@ -212,6 +232,7 @@ impl PenRecord {
|
||||
st.tilt = self.tilt;
|
||||
st.bearing = self.bearing;
|
||||
st.rotation = self.rotation;
|
||||
st.wheel = self.wheel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -438,7 +438,7 @@ fn erase_rect(s: &mut Session, r: Rect) -> Result<Value> {
|
||||
|
||||
/// The variation modes `path.eraseRegion` takes for each of `angleMode`, `roundnessMode` and
|
||||
/// `sizeMode`.
|
||||
const ERASER_MODES: &str = "\"fixed\", \"random\", \"pressure\", \"tilt\", \"bearing\" or \"rotation\"";
|
||||
const ERASER_MODES: &str = "\"fixed\", \"random\", \"pressure\", \"tilt\", \"bearing\", \"rotation\" or \"stylusWheel\"";
|
||||
|
||||
/// Eraser Tool Options' Angle, Roundness and Size variations: for each of angle (`angleMode` with
|
||||
/// `angleVariation` in degrees, at most 180), roundness (`roundnessMode` with `roundnessVariation`
|
||||
|
||||
@@ -746,8 +746,8 @@ fn give_appearance(a: &Appearance, b: &Appearance, m: &Appearance, n: &mut Share
|
||||
}
|
||||
|
||||
/// Give the member's fill or stroke `n` the settings of the model's that changed from `a` to `b`,
|
||||
/// with the values of `m` (`b` placed on the member). A stroke's pen pressure, tilt, bearing and
|
||||
/// rotation stay its own.
|
||||
/// with the values of `m` (`b` placed on the member). A stroke's pen pressure, tilt, bearing,
|
||||
/// rotation and wheel stay its own.
|
||||
fn give_item(a: &AppearanceItem, b: &AppearanceItem, m: &AppearanceItem, n: &mut AppearanceItem) {
|
||||
use AppearanceItem::{Fill, Stroke};
|
||||
match (a, b, m, n) {
|
||||
@@ -781,6 +781,7 @@ fn give_item(a: &AppearanceItem, b: &AppearanceItem, m: &AppearanceItem, n: &mut
|
||||
tilt: _,
|
||||
bearing: _,
|
||||
rotation: _,
|
||||
wheel: _,
|
||||
} = m;
|
||||
give_fields!(a, b, n: paint, width, cap, join, miter_limit, align, dash, start_arrow, end_arrow, arrow_scale, profile, brush, brush_options, opacity, blend, visible, effects, arrow_align, overprint, gradient_mode);
|
||||
// A stroke's own brush settings go with the brush they set: a new brush takes the model's.
|
||||
|
||||
@@ -1572,6 +1572,79 @@ fn freehand_points_record_the_pens_tilt_bearing_and_rotation() {
|
||||
assert_eq!(tilt.unwrap().at(0.9), vectorcraft_doc::PressureProfile::MID, "half way over without one");
|
||||
}
|
||||
|
||||
/// The airbrush finger wheel recorded on the stroke `id`.
|
||||
fn wheel_of(s: &Session, id: NodeId) -> Option<PressureProfile> {
|
||||
node(s, id).appearance.stroke().and_then(|st| st.wheel.clone())
|
||||
}
|
||||
|
||||
/// `path.freehand` points carry an airbrush pen's finger wheel seventh (or as `wheel`), 0..1; the
|
||||
/// stroke keeps it, a continued or reversed stroke keeps it in step, a wheel that is not a number
|
||||
/// or is outside 0..1 is refused, and the Paintbrush records it from the pen. A Calligraphic brush with
|
||||
/// Size on Stylus Wheel draws it, and it lasts through saving, new art leaving it behind.
|
||||
#[test]
|
||||
fn freehand_points_record_the_stylus_wheel() {
|
||||
let mut s = session();
|
||||
let draw = |s: &mut Session, points: Value| {
|
||||
NodeId(s.execute("path.freehand", &json!({"points": points, "style": "brush"})).unwrap()["id"].as_u64().unwrap())
|
||||
};
|
||||
let id = draw(&mut s, json!([[0, 50, null, null, null, null, 0], [100, 50, null, null, null, null, 1]]));
|
||||
let w = wheel_of(&s, id).unwrap();
|
||||
assert!(w.at(0.0) < 1e-6 && (w.at(1.0) - 1.0).abs() < 1e-6, "{w:?}");
|
||||
assert_eq!(pose_of(&s, id), (None, None, None), "the wheel alone");
|
||||
assert_eq!(pressure_of(&s, id), None);
|
||||
// As keys; a point without one is half way.
|
||||
let id = draw(&mut s, json!([{"x": 0, "y": 150, "wheel": 0}, {"x": 50, "y": 150}, {"x": 100, "y": 150, "wheel": 1}]));
|
||||
let w = wheel_of(&s, id).unwrap();
|
||||
assert!(w.at(0.0) < 1e-6 && (w.at(0.5) - 0.5).abs() < 1e-6 && (w.at(1.0) - 1.0).abs() < 1e-6, "{w:?}");
|
||||
// No wheel given: none recorded.
|
||||
let id = draw(&mut s, json!([[0, 250, 0.5, 30, 0, 90], [100, 250, 0.5, 30, 0, 90]]));
|
||||
assert_eq!(wheel_of(&s, id), None);
|
||||
// Not a number: refused, and nothing drawn.
|
||||
let before = s.doc().unwrap().doc.clone();
|
||||
let err = s.execute("path.freehand", &json!({"points": [[0, 0, null, null, null, null, "0.5"], [10, 0]], "style": "brush"}));
|
||||
assert!(err.unwrap_err().to_string().contains("`wheel` must be a number"));
|
||||
assert_eq!(s.doc().unwrap().doc.layers, before.layers, "the document is unchanged");
|
||||
// Outside 0..1: refused, and nothing drawn.
|
||||
for points in [json!([{"x": 0, "y": 0, "wheel": -2}, {"x": 10, "y": 0}]), json!([[0, 0], [10, 0, null, null, null, null, 9]])] {
|
||||
let err = s.execute("path.freehand", &json!({"points": points, "style": "brush"}));
|
||||
assert!(err.unwrap_err().to_string().contains("`wheel` must be from 0 to 1"));
|
||||
assert_eq!(s.doc().unwrap().doc.layers, before.layers, "the document is unchanged");
|
||||
}
|
||||
// Continued at its end by a stroke without a wheel: the old part keeps it, the new one is half way.
|
||||
let id = draw(&mut s, json!([[0, 350, null, null, null, null, 1], [100, 350, null, null, null, null, 1]]));
|
||||
s.execute("path.freehand", &json!({"points": [[100, 350], [200, 350]], "style": "brush", "extend": {"id": id.0, "end": "end"}})).unwrap();
|
||||
let w = wheel_of(&s, id).unwrap();
|
||||
assert!((w.at(0.25) - 1.0).abs() < 1e-6 && (w.at(0.9) - 0.5).abs() < 1e-6, "{w:?}");
|
||||
// The Paintbrush records it, and a brush with Size on Stylus Wheel draws it.
|
||||
let params = json!({"angle": 0, "roundness": 100, "size": 6, "variation": [0, 0, 4], "modes": ["fixed", "fixed", "stylusWheel"]});
|
||||
s.execute("brush.options", &json!({"name": "3 pt. Round", "params": params})).unwrap();
|
||||
s.execute("brush.setCurrent", &json!({"name": "3 pt. Round"})).unwrap();
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("paintbrush", v).unwrap();
|
||||
let strokes = |s: &mut Session, y: f64, wheel: Option<f32>| {
|
||||
let pen = wheel.map(|w| PenPose { wheel: Some(w), ..PenPose::default() });
|
||||
for (k, x) in [(PointerKind::Down, 20.0), (PointerKind::Drag, 120.0), (PointerKind::Drag, 220.0), (PointerKind::Up, 320.0)] {
|
||||
s.pointer(&PointerEvent { pen, ..PointerEvent::new(k, x, y) }, v).unwrap();
|
||||
}
|
||||
let id = s.doc().unwrap().selection.objects[0];
|
||||
select(s, &[]);
|
||||
id
|
||||
};
|
||||
let far = strokes(&mut s, 500.0, Some(1.0));
|
||||
let near = strokes(&mut s, 600.0, Some(0.0));
|
||||
let mouse = strokes(&mut s, 700.0, None);
|
||||
assert_eq!(wheel_of(&s, far).map(|w| w.at(0.5)), Some(1.0));
|
||||
assert_eq!(wheel_of(&s, mouse), None, "a mouse has no wheel");
|
||||
let height = |s: &Session, id| brushed_bounds(s, id).height();
|
||||
assert!((height(&s, far) - 10.0).abs() < 0.1 && (height(&s, near) - 2.0).abs() < 0.1, "{} {}", height(&s, far), height(&s, near));
|
||||
assert!((height(&s, mouse) - 6.0).abs() < 0.1, "the brush's own size: {}", height(&s, mouse));
|
||||
// Saved and reopened as it was; new art takes the look without the wheel.
|
||||
let doc: Document = (*s.doc().unwrap().doc).clone();
|
||||
let back = vectorcraft_format::load(&vectorcraft_format::save(&doc, false)).unwrap();
|
||||
assert_eq!(back.node(far).unwrap().appearance.stroke(), doc.node(far).unwrap().appearance.stroke());
|
||||
assert!(vectorcraft_doc::Appearance::clone(&doc.node(far).unwrap().appearance).without_pressure().stroke().is_some_and(|st| st.wheel.is_none()));
|
||||
}
|
||||
|
||||
/// #764: a stroke that connects two paths joins the pen's tilt, bearing and rotation of both, the
|
||||
/// connected path's after the stroke's.
|
||||
#[test]
|
||||
@@ -1611,7 +1684,7 @@ fn paintbrush_records_the_pens_tilt_on_the_stroke() {
|
||||
select(s, &[]);
|
||||
id
|
||||
};
|
||||
let pen = strokes(&mut s, 60.0, Some(PenPose { tilt: Some([0.0, 0.0]), rotation: Some(30.0) }));
|
||||
let pen = strokes(&mut s, 60.0, Some(PenPose { tilt: Some([0.0, 0.0]), rotation: Some(30.0), wheel: None }));
|
||||
let (tilt, bearing, rotation) = pose_of(&s, pen);
|
||||
assert_eq!(tilt.as_ref().map(|t| t.at(0.5)), Some(0.0), "upright");
|
||||
assert!(bearing.is_some() && (rotation.unwrap().at(0.5) + 30.0).abs() < 1e-6);
|
||||
|
||||
@@ -751,14 +751,14 @@ fn eraser_size_follows_the_pen_pressure() {
|
||||
assert!(err.to_string().contains("sizeMode"), "{err}");
|
||||
}
|
||||
|
||||
/// Eraser Tool Options' Angle, Roundness and Size variation menus: a value on Rotation, Bearing,
|
||||
/// Tilt or Pressure takes what the pen read along the drag, Random stays within its Variation, a
|
||||
/// Eraser Tool Options' Angle, Roundness and Size variation menus: a value on Stylus Wheel, Rotation,
|
||||
/// Bearing, Tilt or Pressure takes what the pen read along the drag, Random stays within its Variation, a
|
||||
/// drag without the reading erases at the value itself, an open path is cut where the varied tip
|
||||
/// covers it, and an unknown mode or a variation out of its range is refused with nothing erased.
|
||||
#[test]
|
||||
fn the_eraser_tip_varies_with_its_modes() {
|
||||
// Which of `probes` a level drag through the middle of a 400 by 200 rectangle erases, each of
|
||||
// its points `[x, 100]` followed by `pen` ([pressure, tiltX, tiltY, rotation]).
|
||||
// its points `[x, 100]` followed by `pen` ([pressure, tiltX, tiltY, rotation, wheel]).
|
||||
let erased = |tip: serde_json::Value, pen: serde_json::Value, probes: &[(f64, f64)]| -> Vec<bool> {
|
||||
let mut s = session();
|
||||
rect(&mut s, 0.0, 0.0, 400.0, 200.0);
|
||||
@@ -785,6 +785,10 @@ fn the_eraser_tip_varies_with_its_modes() {
|
||||
// The barrel turned half way round reads the most, which turns the tip upright.
|
||||
assert_eq!(erased(on_rotation.clone(), json!([none, none, none, 180]), &probes), [true, true], "Rotation");
|
||||
assert_eq!(erased(on_rotation.clone(), json!([]), &probes), [true, false], "Rotation without a reading");
|
||||
// The finger wheel at the far end of its travel reads the most; without a wheel the tip lies level.
|
||||
let on_wheel = with(&level, json!({"angleMode": "stylusWheel", "angleVariation": 90}));
|
||||
assert_eq!(erased(on_wheel.clone(), json!([none, none, none, none, 1.0]), &probes), [true, true], "Stylus Wheel");
|
||||
assert_eq!(erased(on_wheel, json!([none, none, none, none, none]), &probes), [true, false], "Stylus Wheel without a reading");
|
||||
// Leaning to the left (a bearing of 180°) reads the most too.
|
||||
let on_bearing = with(&level, json!({"angleMode": "bearing", "angleVariation": 90}));
|
||||
assert_eq!(erased(on_bearing.clone(), json!([none, -45, 0, none]), &probes), [true, true], "Bearing");
|
||||
@@ -831,11 +835,11 @@ fn the_eraser_tip_varies_with_its_modes() {
|
||||
let id = rect(&mut s, 0.0, 0.0, 100.0, 100.0);
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
let stroke = json!({"points": [[-10, 50], [110, 50]]});
|
||||
let modes = "\"fixed\", \"random\", \"pressure\", \"tilt\", \"bearing\" or \"rotation\"";
|
||||
let modes = "\"fixed\", \"random\", \"pressure\", \"tilt\", \"bearing\", \"rotation\" or \"stylusWheel\"";
|
||||
for (extra, want) in [
|
||||
(json!({"angleMode": "wheel"}), format!("angleMode is one of {modes}, not `wheel`")),
|
||||
(json!({"roundnessMode": 3}), format!("roundnessMode is one of {modes}, not 3")),
|
||||
(json!({"sizeMode": "stylusWheel"}), format!("sizeMode is one of {modes}, not `stylusWheel`")),
|
||||
(json!({"sizeMode": "Pressure"}), format!("sizeMode is one of {modes}, not `Pressure`")),
|
||||
(json!({"angleVariation": 181}), "angleVariation must be at most 180".to_string()),
|
||||
(json!({"roundnessVariation": 101}), "roundnessVariation must be at most 100".to_string()),
|
||||
(json!({"roundnessVariation": -1}), "roundnessVariation must be 0 or more".to_string()),
|
||||
@@ -3171,8 +3175,9 @@ fn drawing_commands_refuse_a_point_or_pressure_given_as_text() {
|
||||
}
|
||||
|
||||
/// The drawing tools' commands refuse a pen pressure outside 0 to 1, a tiltX or tiltY outside -90
|
||||
/// to 90 and a rotation outside 0 to 360, naming the key, and a point array of more than six
|
||||
/// numbers, naming the point; the document, the selection and the undo history stay as they were.
|
||||
/// to 90, a rotation outside 0 to 360 and a stylus wheel outside 0 to 1, naming the key, and a
|
||||
/// point array of more than seven numbers, naming the point; the document, the selection and the
|
||||
/// undo history stay as they were.
|
||||
/// The ends of each range, null, one tilt axis alone and a mouse point `[x, y]` still draw.
|
||||
#[test]
|
||||
fn pen_values_outside_their_ranges_are_refused() {
|
||||
@@ -3194,7 +3199,8 @@ fn pen_values_outside_their_ranges_are_refused() {
|
||||
let tilt_x = "`tiltX` must be from -90 to 90";
|
||||
let tilt_y = "`tiltY` must be from -90 to 90";
|
||||
let rotation = "`rotation` must be from 0 to 360";
|
||||
let entries = "`points[3]` must be an array of at most 6 entries";
|
||||
let wheel = "`wheel` must be from 0 to 1";
|
||||
let entries = "`points[3]` must be an array of at most 7 entries";
|
||||
for cmd in cmds {
|
||||
for (bad, want) in [
|
||||
(json!([150, 150, -0.01]), pressure),
|
||||
@@ -3208,8 +3214,11 @@ fn pen_values_outside_their_ranges_are_refused() {
|
||||
(json!([150, 150, null, null, null, -1]), rotation),
|
||||
(json!({"x": 150, "y": 150, "rotation": 360.5}), rotation),
|
||||
(json!([150, 150, null, null, null, 720]), rotation),
|
||||
(json!([150, 150, 0.5, 0, 0, 0, 1]), entries),
|
||||
(json!([150, 150, null, null, null, null, null]), entries),
|
||||
(json!([150, 150, null, null, null, null, -0.01]), wheel),
|
||||
(json!([150, 150, 0.5, 0, 0, 0, 1.5]), wheel),
|
||||
(json!({"x": 150, "y": 150, "wheel": 1e300}), wheel),
|
||||
(json!([150, 150, 0.5, 0, 0, 0, 1, 0]), entries),
|
||||
(json!([150, 150, null, null, null, null, null, null]), entries),
|
||||
] {
|
||||
let points: Vec<_> = good.iter().cloned().chain([bad]).collect();
|
||||
let sel = s.doc().unwrap().selection.clone();
|
||||
@@ -3220,8 +3229,8 @@ fn pen_values_outside_their_ranges_are_refused() {
|
||||
for (row, cmd) in ["path.freehand", "brush.freehand", "path.blob", "path.eraseRegion"].into_iter().enumerate() {
|
||||
let y = 300.0 + 50.0 * row as f64;
|
||||
let points = json!([
|
||||
[100, y, 0, -90, 90, 0],
|
||||
[150, y, 1, 90, -90, 360],
|
||||
[100, y, 0, -90, 90, 0, 0],
|
||||
[150, y, 1, 90, -90, 360, 1],
|
||||
[200, y, 0.5, null, 30],
|
||||
{"x": 250, "y": y, "tiltX": -45, "pressure": null},
|
||||
[300, y],
|
||||
|
||||
@@ -10636,8 +10636,9 @@ fn a_brushs_mask_art_isnt_written_as_a_styled_object_with_its_id() {
|
||||
}
|
||||
|
||||
/// Settings the other tests don't use come back: a Calligraphic brush varying with tilt and bearing,
|
||||
/// a Scatter brush keeping its art's colors whose rotation doesn't follow the path, and brushes whose
|
||||
/// modes aren't given (the reader gives them, the same ones).
|
||||
/// a Scatter brush keeping its art's colors whose rotation doesn't follow the path, a Calligraphic
|
||||
/// and a Scatter brush whose size follows an airbrush pen's finger wheel, and brushes whose modes
|
||||
/// aren't given (the reader gives them, the same ones).
|
||||
#[test]
|
||||
fn more_brush_settings_are_read_back() {
|
||||
use vectorcraft_brush::{Brush, BrushKind, Calligraphic, Colorization, Scatter, Variation};
|
||||
@@ -10662,8 +10663,20 @@ fn more_brush_settings_are_read_back() {
|
||||
let lib = vec![
|
||||
Brush { name: "Tilted".into(), kind: BrushKind::Calligraphic(tilted.clone()) },
|
||||
Brush { name: "Still".into(), kind: BrushKind::Scatter(scatter.clone()) },
|
||||
Brush { name: "Unset nib".into(), kind: BrushKind::Calligraphic(Calligraphic { modes: None, ..tilted }) },
|
||||
Brush { name: "Unset spray".into(), kind: BrushKind::Scatter(Scatter { modes: None, ..scatter }) },
|
||||
Brush { name: "Unset nib".into(), kind: BrushKind::Calligraphic(Calligraphic { modes: None, ..tilted.clone() }) },
|
||||
Brush { name: "Unset spray".into(), kind: BrushKind::Scatter(Scatter { modes: None, ..scatter.clone() }) },
|
||||
Brush {
|
||||
name: "Wheel nib".into(),
|
||||
kind: BrushKind::Calligraphic(Calligraphic { modes: Some([Variation::Fixed, Variation::Fixed, Variation::StylusWheel]), ..tilted }),
|
||||
},
|
||||
Brush {
|
||||
name: "Wheel spray".into(),
|
||||
kind: BrushKind::Scatter(Scatter {
|
||||
size: (40.0, 160.0),
|
||||
modes: Some([Variation::StylusWheel, Variation::Fixed, Variation::Fixed, Variation::Fixed]),
|
||||
..scatter
|
||||
}),
|
||||
},
|
||||
];
|
||||
let mut doc = Document::new(300.0, 200.0);
|
||||
vectorcraft_brush::store(&mut doc, &lib);
|
||||
|
||||
@@ -96,6 +96,7 @@ fn code(v: Variation) -> f64 {
|
||||
Variation::Fixed => 0.0,
|
||||
Variation::Random => 1.0,
|
||||
Variation::Pressure => 2.0,
|
||||
Variation::StylusWheel => 3.0,
|
||||
Variation::Tilt => 4.0,
|
||||
Variation::Bearing => 5.0,
|
||||
Variation::Rotation => 6.0,
|
||||
|
||||
@@ -209,12 +209,13 @@ fn numbers(s: &str) -> Option<Vec<f64>> {
|
||||
s.split_whitespace().map(|w| w.parse::<f64>().ok().filter(|v| v.is_finite())).collect()
|
||||
}
|
||||
|
||||
/// How a value varies, by its code: `None` for the stylus wheel and codes that aren't known.
|
||||
/// How a value varies, by its code: `None` for codes that aren't known.
|
||||
fn variation(code: f64) -> Option<Variation> {
|
||||
match code {
|
||||
0.0 => Some(Variation::Fixed),
|
||||
1.0 => Some(Variation::Random),
|
||||
2.0 => Some(Variation::Pressure),
|
||||
3.0 => Some(Variation::StylusWheel),
|
||||
4.0 => Some(Variation::Tilt),
|
||||
5.0 => Some(Variation::Bearing),
|
||||
6.0 => Some(Variation::Rotation),
|
||||
|
||||
@@ -11161,11 +11161,11 @@ fn a_gradients_br_is_not_a_brush() {
|
||||
|
||||
/// The Brush Options codes for how a Calligraphic brush's values vary: Tilt, Bearing and Rotation
|
||||
/// are the pen's other channels (#372: a 6D Art Pen brush varies its diameter with the pressure,
|
||||
/// its roundness with the bearing and its angle with the barrel's rotation). The stylus wheel isn't
|
||||
/// read: it varies at random, as an unknown code does.
|
||||
/// its roundness with the bearing and its angle with the barrel's rotation), and code 3 is an
|
||||
/// airbrush pen's finger wheel. An unknown code varies at random.
|
||||
#[test]
|
||||
fn a_calligraphic_brushs_pen_channels_come_in_by_their_codes() {
|
||||
use vectorcraft_brush::Variation::{Bearing, Fixed, Pressure, Random, Rotation, Tilt};
|
||||
use vectorcraft_brush::Variation::{Bearing, Fixed, Pressure, Random, Rotation, StylusWheel, Tilt};
|
||||
let modes = |params: &str| {
|
||||
let d = brush::parse_tool_object(brush::Tool::Calligraphic, "Pen", params).unwrap();
|
||||
let brush::DraftKind::Calligraphic(c) = d.kind else { panic!("{d:?}") };
|
||||
@@ -11173,8 +11173,9 @@ fn a_calligraphic_brushs_pen_channels_come_in_by_their_codes() {
|
||||
};
|
||||
assert_eq!(modes("1 51 69 13 57 -346 14 2 5 6 0"), [Rotation, Bearing, Pressure]);
|
||||
assert_eq!(modes("1 2 6 40 60 -30 10 4 4 4 0"), [Tilt, Tilt, Tilt]);
|
||||
assert_eq!(modes("1 2 6 40 60 -30 10 3 3 3 0"), [Random, Random, Random], "the stylus wheel");
|
||||
assert_eq!(modes("1 4 4 50 50 10 10 3 9 9 0"), [Fixed, Fixed, Fixed], "nothing to vary");
|
||||
assert_eq!(modes("1 2 6 40 60 -30 10 3 3 3 0"), [StylusWheel, StylusWheel, StylusWheel], "the stylus wheel");
|
||||
assert_eq!(modes("1 2 6 40 60 -30 10 7 9 7 0"), [Random, Random, Random], "unknown codes");
|
||||
assert_eq!(modes("1 4 4 50 50 10 10 7 9 9 0"), [Fixed, Fixed, Fixed], "nothing to vary");
|
||||
}
|
||||
|
||||
/// A 6D Art Pen brush: diameter 4 to 8 with the pressure, roundness 30 to 50 with the bearing and
|
||||
|
||||
@@ -219,6 +219,7 @@ pub fn tool_definitions() -> Vec<Value> {
|
||||
"tiltX": num("Pen tilt in degrees −90..90, positive leaning right (document axes); with tiltY, the tilt the Paintbrush records for Tilt and Bearing brushes. One without the other is 0"),
|
||||
"tiltY": num("Pen tilt in degrees −90..90, positive leaning down the page"),
|
||||
"rotation": num("Pen barrel rotation in degrees clockwise: the rotation the Paintbrush records for Rotation brushes"),
|
||||
"wheel": num("Airbrush pen finger wheel 0..1 (clamped): the wheel the Paintbrush records for Stylus Wheel brushes"),
|
||||
"holdMs": num("Milliseconds the pointer then holds still, button down (0..60000): Twirl, Pucker and Bloat keep applying"),
|
||||
}), &["kind", "x", "y"]),
|
||||
},
|
||||
|
||||
@@ -360,8 +360,8 @@ fn same_but_anchors(a: &Node, b: &Node) -> bool {
|
||||
}
|
||||
|
||||
/// Does `n` paint each pixel from the segments near it alone: no effects, every visible fill and
|
||||
/// stroke a solid color, and no stroke with dashes, a width profile, pressure, tilt, bearing or
|
||||
/// rotation, arrowheads, a brush or effects?
|
||||
/// stroke a solid color, and no stroke with dashes, a width profile, pressure, tilt, bearing,
|
||||
/// rotation or wheel, arrowheads, a brush or effects?
|
||||
fn local_paint(n: &Node) -> bool {
|
||||
use vectorcraft_doc::AppearanceItem;
|
||||
let solid = |p: &vectorcraft_color::Paint| matches!(p, vectorcraft_color::Paint::Solid { .. } | vectorcraft_color::Paint::None);
|
||||
@@ -379,6 +379,7 @@ fn local_paint(n: &Node) -> bool {
|
||||
&& s.tilt.is_none()
|
||||
&& s.bearing.is_none()
|
||||
&& s.rotation.is_none()
|
||||
&& s.wheel.is_none()
|
||||
&& s.start_arrow.is_none()
|
||||
&& s.end_arrow.is_none()
|
||||
&& s.brush.is_none()
|
||||
|
||||
@@ -102,17 +102,18 @@ pub(crate) fn pen_bearing(q: PenPose) -> Option<f64> {
|
||||
(from_upright >= 1.0).then(|| (-y).atan2(x).to_degrees())
|
||||
}
|
||||
|
||||
/// The 0..1 that each of the Eraser's variation modes Pressure, Tilt, Bearing and Rotation reads
|
||||
/// from a pen at `pressure` (0..1) held as `pose`, leaning toward `bearing` (degrees, from
|
||||
/// [`pen_bearing`]): 0 gives the value less its variation and 1 the value plus it, as
|
||||
/// `path.eraseRegion` reads a stroke's points. Tilt reads 1 upright and 0 lying flat; Bearing and
|
||||
/// Rotation read ½ plus the angle over 360°, the rotation turned counter-clockwise. What the pen
|
||||
/// does not give reads ½, the value itself.
|
||||
pub(crate) fn pen_controls(pressure: f64, pose: Option<PenPose>, bearing: Option<f64>) -> [f64; 4] {
|
||||
/// The 0..1 that each of the Eraser's variation modes Pressure, Tilt, Bearing, Rotation and Stylus
|
||||
/// Wheel reads, in that order, from a pen at `pressure` (0..1) held as `pose`, leaning toward
|
||||
/// `bearing` (degrees, from [`pen_bearing`]): 0 gives the value less its variation and 1 the value
|
||||
/// plus it, as `path.eraseRegion` reads a stroke's points. Tilt reads 1 upright and 0 lying flat;
|
||||
/// Bearing and Rotation read ½ plus the angle over 360°, the rotation turned counter-clockwise;
|
||||
/// Stylus Wheel reads the pen's wheel (0..1). What the pen does not give reads ½, the value itself.
|
||||
pub(crate) fn pen_controls(pressure: f64, pose: Option<PenPose>, bearing: Option<f64>) -> [f64; 5] {
|
||||
let tilt = pose.and_then(|q| q.tilt).map_or(0.5, |t| 1.0 - pen_lean(t).1 / 90.0);
|
||||
let rotation = pose.and_then(|q| q.rotation).map_or(0.5, |r| 0.5 + vectorcraft_geom::normalize_deg(-f64::from(r)) / 360.0);
|
||||
let bearing = bearing.map_or(0.5, |b| 0.5 + b / 360.0);
|
||||
[pressure, tilt, bearing, rotation].map(|c| if c.is_finite() { c.clamp(0.0, 1.0) } else { 0.5 })
|
||||
let wheel = pose.and_then(|q| q.wheel).map_or(0.5, f64::from);
|
||||
[pressure, tilt, bearing, rotation, wheel].map(|c| if c.is_finite() { c.clamp(0.0, 1.0) } else { 0.5 })
|
||||
}
|
||||
|
||||
/// Create a drawing tool by id (None = not one of ours).
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
//! Guides and Snap to Point: it shows no Smart Guides, hovering or drawing, and its ends follow the
|
||||
//! hand. Snap to Grid and Snap to Pixel still move its ends (`grid_snaps`). The Paintbrush records the pen pressure of each point (a stroke a pen
|
||||
//! pressed less than fully on sends `[x, y, pressure]` points) for pressure-sensitive brushes, and
|
||||
//! the pen's tilt and barrel rotation where the pen reads them (`[x, y, pressure, tiltX, tiltY,
|
||||
//! rotation]` points, `null` for what a point lacks) for brushes that vary with them. The Blob
|
||||
//! the pen's tilt, barrel rotation and airbrush finger wheel where the pen reads them (`[x, y,
|
||||
//! pressure, tiltX, tiltY, rotation, wheel]` points, `null` for what a point lacks) for brushes
|
||||
//! that vary with them. The Blob
|
||||
//! Brush and Eraser also record pressure when their Size varies with Pressure, and the Eraser
|
||||
//! records the pressure, tilt and rotation that its Angle, Roundness and Size variations follow;
|
||||
//! while it erases, its tip outline at the pointer takes the angle, roundness and size the pen
|
||||
@@ -104,8 +105,8 @@ pub struct GestureTool {
|
||||
/// The pen pressure of each of `points` (the Paintbrush, the Blob Brush with Size on Pressure,
|
||||
/// and the Eraser with any of its variations on Pressure).
|
||||
pressures: Vec<f32>,
|
||||
/// The pen's tilt and rotation at each of `points` (the Paintbrush, and the Eraser with any of
|
||||
/// its variations on Tilt, Bearing or Rotation).
|
||||
/// The pen's tilt, rotation and wheel at each of `points` (the Paintbrush, and the Eraser with
|
||||
/// any of its variations on Tilt, Bearing or Rotation).
|
||||
poses: Vec<Option<PenPose>>,
|
||||
active: bool,
|
||||
began: bool,
|
||||
@@ -962,7 +963,8 @@ impl GestureTool {
|
||||
self.id != "pencil" || self.live_preview
|
||||
}
|
||||
|
||||
/// Add a stroke sample, with the pen's pressure, tilt and rotation of the event `ev` there.
|
||||
/// Add a stroke sample, with the pen's pressure, tilt, rotation and wheel of the event `ev`
|
||||
/// there.
|
||||
fn push(&mut self, p: Point, ev: &PointerEvent) {
|
||||
if let Some(last) = self.points.last() {
|
||||
self.length += last.distance(p);
|
||||
@@ -970,7 +972,8 @@ impl GestureTool {
|
||||
self.points.push(p);
|
||||
let modes = self.tip_modes();
|
||||
// The poses go out beside the pressures (`stroke_json`), so a stroke that keeps one keeps both.
|
||||
let posed = self.id == "paintbrush" || modes.iter().any(|m| matches!(m, Variation::Tilt | Variation::Bearing | Variation::Rotation));
|
||||
let posed = self.id == "paintbrush"
|
||||
|| modes.iter().any(|m| matches!(m, Variation::Tilt | Variation::Bearing | Variation::Rotation | Variation::StylusWheel));
|
||||
if posed || modes.contains(&Variation::Pressure) {
|
||||
self.pressures.push(ev.pressure);
|
||||
self.light |= ev.pressure < 1.0;
|
||||
@@ -1122,7 +1125,7 @@ impl GestureTool {
|
||||
let Some(name) = vectorcraft_brush::current(cx.doc) else { return vec![] };
|
||||
let Some(brush) = vectorcraft_brush::find(cx.doc, &name) else { return vec![] };
|
||||
let BrushKind::Bristle(bristle) = brush.kind else { return vec![] };
|
||||
let [pressure, tilt, bearing, rotation] = super::pen_controls(pressure, Some(pose), super::pen_bearing(pose));
|
||||
let [pressure, tilt, bearing, rotation, _] = super::pen_controls(pressure, Some(pose), super::pen_bearing(pose));
|
||||
let size = bristle.size.max(0.1) * cx.paint.stroke_width.max(0.0) * (0.5 + pressure) * (1.25 - 0.5 * tilt);
|
||||
if size <= 0.0 {
|
||||
return vec![];
|
||||
@@ -1274,6 +1277,7 @@ impl GestureTool {
|
||||
Variation::Tilt => posed && self.poses.iter().flatten().any(|q| q.tilt.is_some()),
|
||||
Variation::Bearing => posed && self.bearings.iter().any(Option::is_some),
|
||||
Variation::Rotation => posed && self.poses.iter().flatten().any(|q| q.rotation.is_some()),
|
||||
Variation::StylusWheel => posed && self.poses.iter().flatten().any(|q| q.wheel.is_some()),
|
||||
Variation::Fixed | Variation::Random => false,
|
||||
};
|
||||
if self.smoothing {
|
||||
@@ -1314,7 +1318,7 @@ impl GestureTool {
|
||||
let (a, b) = ((a - 0.5) * 360.0, (b - 0.5) * 360.0);
|
||||
0.5 + vectorcraft_geom::normalize_deg(a + vectorcraft_geom::normalize_deg(b - a) / 2.0) / 360.0
|
||||
};
|
||||
self.tip_of_controls([(a[0] + b[0]) / 2.0, (a[1] + b[1]) / 2.0, turn(a[2], b[2]), turn(a[3], b[3])])
|
||||
self.tip_of_controls([(a[0] + b[0]) / 2.0, (a[1] + b[1]) / 2.0, turn(a[2], b[2]), turn(a[3], b[3]), (a[4] + b[4]) / 2.0])
|
||||
}
|
||||
|
||||
/// What each of the variation modes Pressure, Tilt, Bearing and Rotation reads at point `i` of
|
||||
@@ -1323,7 +1327,7 @@ impl GestureTool {
|
||||
/// the bearing of the last point up to it that the pen leaned 1° or more at, or before the
|
||||
/// first such point the bearing of that first one. What the release does not read
|
||||
/// ([`Self::reads_pressures`], [`Self::reads_poses`]) reads ½, the values themselves.
|
||||
fn controls_of_point(&self, i: usize) -> [f64; 4] {
|
||||
fn controls_of_point(&self, i: usize) -> [f64; 5] {
|
||||
let pressure = if self.reads_pressures() { self.pressures.get(i).map_or(0.5, |p| f64::from(*p)) } else { 0.5 };
|
||||
let (pose, bearing) = if self.reads_poses() {
|
||||
(self.poses.get(i).copied().flatten(), self.bearings.get(i).copied().flatten().or(self.first_bearing))
|
||||
@@ -1352,7 +1356,7 @@ impl GestureTool {
|
||||
/// The Eraser's angle, roundness and size where its tip outline shows: while it erases, each
|
||||
/// value on a mode that follows the pen goes from the value less its Variation to the value
|
||||
/// plus it as the pen reads now (the pressure once the pen has pressed less than fully, the
|
||||
/// tilt and rotation of the last point, and the bearing of the last point the pen leaned 1° or
|
||||
/// tilt, rotation and wheel of the last point, and the bearing of the last point the pen leaned 1° or
|
||||
/// more at), as `path.eraseRegion` reads the stroke; before a press, and for Random, Fixed and a
|
||||
/// pen that gives no reading, the values themselves. The Blob Brush's are its own values.
|
||||
fn tip_now(&self) -> [f64; 3] {
|
||||
@@ -1373,7 +1377,7 @@ impl GestureTool {
|
||||
|
||||
/// The tip's angle, roundness and size where the modes Pressure, Tilt, Bearing and Rotation
|
||||
/// read `controls` (0..1 each, [`super::pen_controls`]).
|
||||
fn tip_of_controls(&self, controls: [f64; 4]) -> [f64; 3] {
|
||||
fn tip_of_controls(&self, controls: [f64; 5]) -> [f64; 3] {
|
||||
let base = [self.angle, self.roundness, self.size];
|
||||
let variations = [self.angle_variation, self.roundness_variation, self.size_variation];
|
||||
let mut out = base;
|
||||
@@ -1383,6 +1387,7 @@ impl GestureTool {
|
||||
Variation::Tilt => controls[1],
|
||||
Variation::Bearing => controls[2],
|
||||
Variation::Rotation => controls[3],
|
||||
Variation::StylusWheel => controls[4],
|
||||
Variation::Fixed | Variation::Random => continue,
|
||||
};
|
||||
// The size goes past a nib's 1296 pt, as `path.eraseRegion` sweeps it.
|
||||
@@ -1392,20 +1397,28 @@ impl GestureTool {
|
||||
[angle, roundness.clamp(1.0, 100.0), size.max(super::MIN_BRUSH_SIZE)]
|
||||
}
|
||||
|
||||
/// The stroke's points: `[x, y, pressure, tiltX, tiltY, rotation]` when a pen read its tilt or
|
||||
/// rotation anywhere along it (`null` for what a point lacks, and for the pressure of a stroke
|
||||
/// The stroke's points: `[x, y, pressure, tiltX, tiltY, rotation, wheel]` when a pen read its
|
||||
/// wheel anywhere along it, else `[x, y, pressure, tiltX, tiltY, rotation]` when it read its
|
||||
/// tilt or rotation anywhere (`null` for what a point lacks, and for the pressure of a stroke
|
||||
/// pressed fully all along), else `[x, y, pressure]` when a pen pressed less than fully
|
||||
/// anywhere (a mouse always presses fully), else `[x, y]`.
|
||||
fn stroke_json(&self) -> Value {
|
||||
let n = self.points.len();
|
||||
let pressed = self.pressures.len() == n && self.pressures.iter().any(|p| *p < 1.0);
|
||||
let posed = self.poses.len() == n && self.poses.iter().flatten().any(|q| q.tilt.is_some() || q.rotation.is_some());
|
||||
let poses = || self.poses.iter().flatten();
|
||||
let wheeled = self.poses.len() == n && poses().any(|q| q.wheel.is_some());
|
||||
let posed = wheeled || (self.poses.len() == n && poses().any(|q| q.tilt.is_some() || q.rotation.is_some()));
|
||||
let round = |v: f32, k: f64| (f64::from(v) * k).round() / k;
|
||||
if posed {
|
||||
let points = self.points.iter().zip(&self.pressures).zip(&self.poses).map(|((p, f), q)| {
|
||||
let q = q.unwrap_or_default();
|
||||
let (tilt, rotation) = (q.tilt.map(|t| t.map(|v| round(v, 100.0))), q.rotation.map(|r| round(r, 100.0)));
|
||||
json!([p.x, p.y, pressed.then(|| round(*f, 1000.0)), tilt.map(|t| t[0]), tilt.map(|t| t[1]), rotation])
|
||||
let pressure = pressed.then(|| round(*f, 1000.0));
|
||||
if wheeled {
|
||||
json!([p.x, p.y, pressure, tilt.map(|t| t[0]), tilt.map(|t| t[1]), rotation, q.wheel.map(|w| round(w, 1000.0))])
|
||||
} else {
|
||||
json!([p.x, p.y, pressure, tilt.map(|t| t[0]), tilt.map(|t| t[1]), rotation])
|
||||
}
|
||||
});
|
||||
Value::Array(points.collect())
|
||||
} else if pressed {
|
||||
|
||||
@@ -124,7 +124,7 @@ fn paintbrush_sends_pen_tilt_and_rotation() {
|
||||
let Some(Action::Preview(_, v)) = last.first() else { panic!("{last:?}") };
|
||||
v["points"].clone()
|
||||
};
|
||||
let leaning = |x: f32, r: Option<f32>| Some(PenPose { tilt: Some([x, -10.0]), rotation: r });
|
||||
let leaning = |x: f32, r: Option<f32>| Some(PenPose { tilt: Some([x, -10.0]), rotation: r, wheel: None });
|
||||
assert_eq!(
|
||||
stroke("paintbrush", 0.5, [leaning(30.0, Some(45.0)), leaning(40.0, Some(-90.0)), None]),
|
||||
json!([[0.0, 0.0, 0.5, 30.0, -10.0, 45.0], [40.0, 0.0, 0.5, 40.0, -10.0, 270.0], [80.0, 0.0, 0.5, null, null, null]])
|
||||
@@ -134,6 +134,12 @@ fn paintbrush_sends_pen_tilt_and_rotation() {
|
||||
// A pose that reads nothing is a mouse's.
|
||||
assert_eq!(stroke("paintbrush", 1.0, [Some(PenPose::default()); 3]), json!([[0.0, 0.0], [40.0, 0.0], [80.0, 0.0]]));
|
||||
assert_eq!(stroke("pencil", 0.5, [leaning(30.0, Some(45.0)); 3]), json!([[0.0, 0.0], [40.0, 0.0], [80.0, 0.0]]));
|
||||
// An airbrush pen's finger wheel comes seventh, and a point without it sends null.
|
||||
let wheel = |w: f32| Some(PenPose { wheel: Some(w), ..PenPose::default() });
|
||||
assert_eq!(
|
||||
stroke("paintbrush", 1.0, [wheel(0.0), wheel(0.25), None]),
|
||||
json!([[0.0, 0.0, null, null, null, null, 0.0], [40.0, 0.0, null, null, null, null, 0.25], [80.0, 0.0, null, null, null, null, null]])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -3059,8 +3065,10 @@ fn bristle_tip_annotator_follows_a_rotation_capable_pen() {
|
||||
Some(vectorcraft_geom::Shape::bounding_box(path))
|
||||
};
|
||||
let mut tool = GestureTool::new("paintbrush");
|
||||
let at =
|
||||
|rotation| PointerEvent { pen: Some(PenPose { tilt: Some([30.0, 0.0]), rotation }), ..PointerEvent::new(PointerKind::Move, 100.0, 50.0) };
|
||||
let at = |rotation| PointerEvent {
|
||||
pen: Some(PenPose { tilt: Some([30.0, 0.0]), rotation, wheel: None }),
|
||||
..PointerEvent::new(PointerKind::Move, 100.0, 50.0)
|
||||
};
|
||||
assert!(bounds(&tool, &view).is_none());
|
||||
tool.pointer(&view, &PointerEvent::new(PointerKind::Move, 100.0, 50.0));
|
||||
assert!(bounds(&tool, &view).is_none(), "mouse");
|
||||
@@ -3193,7 +3201,7 @@ fn the_eraser_tip_follows_its_variation_modes() {
|
||||
assert_eq!(t.check_option(k, &json!(mode.id())), Ok(()), "{k} {mode:?}");
|
||||
}
|
||||
}
|
||||
let modes = "must be one of `fixed`, `random`, `pressure`, `tilt`, `bearing`, `rotation`";
|
||||
let modes = "must be one of `fixed`, `random`, `pressure`, `tilt`, `bearing`, `rotation`, `stylusWheel`";
|
||||
assert_eq!(t.check_option("angleMode", &json!("wheel")), Err(format!("`angleMode` {modes}")));
|
||||
assert_eq!(t.check_option("angleVariation", &json!(181)), Err("`angleVariation` must be a number from 0 to 180".into()));
|
||||
assert_eq!(t.check_option("roundnessVariation", &json!(500)), Err("`roundnessVariation` must be a number from 0 to 100".into()));
|
||||
@@ -3208,7 +3216,7 @@ fn the_eraser_tip_follows_its_variation_modes() {
|
||||
near(tip(&t), (90.0, 47.5, 110.0, 52.5));
|
||||
// Erasing with the barrel turned half way round and the pen upright, the tip stands upright and
|
||||
// is 28 by 7 pt; Random leaves the roundness as set.
|
||||
let pen = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: Some(180.0) });
|
||||
let pen = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: Some(180.0), wheel: None });
|
||||
t.pointer(&cx, &PointerEvent { pen, pressure: 0.5, ..PointerEvent::new(PointerKind::Down, 100.0, 50.0) });
|
||||
t.pointer(&cx, &PointerEvent { pen, pressure: 0.5, ..PointerEvent::new(PointerKind::Drag, 200.0, 50.0) });
|
||||
near(tip(&t), (196.5, 36.0, 203.5, 64.0));
|
||||
@@ -3245,6 +3253,43 @@ fn the_eraser_tip_follows_its_variation_modes() {
|
||||
assert_eq!(b.options()["sizeMode"], json!("pressure"));
|
||||
}
|
||||
|
||||
/// An Eraser value on Stylus Wheel follows the wheel the pen recorded, in the tip outline while it
|
||||
/// erases and in the points the release sends; a pen that gives no wheel reads half way, the value
|
||||
/// itself.
|
||||
#[test]
|
||||
fn the_eraser_tip_follows_the_stylus_wheel() {
|
||||
let (d, _) = doc_with_rect();
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let cx = cx(&d, &s, &p);
|
||||
let tip = |t: &GestureTool| match &t.overlays(&cx)[..] {
|
||||
[.., Overlay::Path { path, color: [0, 0, 0], width: 1.0, .. }] => vectorcraft_geom::Shape::bounding_box(path),
|
||||
o => panic!("{o:?}"),
|
||||
};
|
||||
let near = |b: vectorcraft_geom::Rect, want: (f64, f64, f64, f64)| {
|
||||
assert!([b.x0 - want.0, b.y0 - want.1, b.x1 - want.2, b.y1 - want.3].iter().all(|e| e.abs() < 0.01), "{b:?} vs {want:?}");
|
||||
};
|
||||
let mut t = GestureTool::new("eraser");
|
||||
for (k, v) in [("size", json!(20)), ("roundness", json!(25)), ("angleMode", json!("stylusWheel")), ("angleVariation", json!(90))] {
|
||||
t.set_option(k, &v);
|
||||
}
|
||||
assert_eq!(t.options()["angleMode"], json!("stylusWheel"));
|
||||
// The wheel at the far end of its travel turns the 20 by 5 pt tip upright.
|
||||
let wheel = |w: Option<f32>| Some(PenPose { tilt: None, rotation: None, wheel: w });
|
||||
t.pointer(&cx, &PointerEvent { pen: wheel(Some(1.0)), ..PointerEvent::new(PointerKind::Down, 100.0, 50.0) });
|
||||
t.pointer(&cx, &PointerEvent { pen: wheel(Some(1.0)), ..PointerEvent::new(PointerKind::Drag, 200.0, 50.0) });
|
||||
near(tip(&t), (197.5, 40.0, 202.5, 60.0));
|
||||
let acts = t.pointer(&cx, &PointerEvent { pen: wheel(Some(1.0)), ..PointerEvent::new(PointerKind::Up, 200.0, 50.0) });
|
||||
let Some(Action::Exec(c, v)) = acts.first() else { panic!("{acts:?}") };
|
||||
assert_eq!((c.as_str(), &v["angleMode"]), ("path.eraseRegion", &json!("stylusWheel")));
|
||||
assert_eq!(v["points"], json!([[100.0, 50.0, null, null, null, null, 1.0], [200.0, 50.0, null, null, null, null, 1.0]]));
|
||||
// A pen without a wheel keeps the tip lying level.
|
||||
t.pointer(&cx, &PointerEvent { pen: wheel(None), ..PointerEvent::new(PointerKind::Down, 100.0, 50.0) });
|
||||
t.pointer(&cx, &PointerEvent { pen: wheel(None), ..PointerEvent::new(PointerKind::Drag, 200.0, 50.0) });
|
||||
near(tip(&t), (190.0, 47.5, 210.0, 52.5));
|
||||
t.pointer(&cx, &PointerEvent { pen: wheel(None), ..PointerEvent::new(PointerKind::Up, 200.0, 50.0) });
|
||||
}
|
||||
|
||||
/// The Eraser's tip outline follows a pen turned in place, which adds no stroke point, and the
|
||||
/// release erases with that reading; and its size passes 1296 pt as `path.eraseRegion` sweeps it.
|
||||
#[test]
|
||||
@@ -3264,8 +3309,8 @@ fn the_eraser_tip_turns_in_place_and_passes_a_nib_size() {
|
||||
for (k, v) in [("size", json!(20)), ("roundness", json!(25)), ("angleMode", json!("rotation")), ("angleVariation", json!(90))] {
|
||||
t.set_option(k, &v);
|
||||
}
|
||||
let level = Some(PenPose { tilt: None, rotation: Some(0.0) });
|
||||
let turned = Some(PenPose { tilt: None, rotation: Some(180.0) });
|
||||
let level = Some(PenPose { tilt: None, rotation: Some(0.0), wheel: None });
|
||||
let turned = Some(PenPose { tilt: None, rotation: Some(180.0), wheel: None });
|
||||
t.pointer(&cx, &PointerEvent { pen: level, pressure: 0.5, ..PointerEvent::new(PointerKind::Down, 100.0, 50.0) });
|
||||
t.pointer(&cx, &PointerEvent { pen: level, pressure: 0.5, ..PointerEvent::new(PointerKind::Drag, 200.0, 50.0) });
|
||||
near(tip(&t), (190.0, 47.5, 210.0, 52.5));
|
||||
@@ -3290,8 +3335,8 @@ fn the_eraser_tip_turns_in_place_and_passes_a_nib_size() {
|
||||
// With Angle on Bearing, a pen that leaned only at the last point and stands up there again
|
||||
// leaves no bearing: the tip lies level, as set.
|
||||
t.set_option("angleMode", &json!("bearing"));
|
||||
let upright = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: None });
|
||||
let leaning = Some(PenPose { tilt: Some([0.0, 45.0]), rotation: None });
|
||||
let upright = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: None, wheel: None });
|
||||
let leaning = Some(PenPose { tilt: Some([0.0, 45.0]), rotation: None, wheel: None });
|
||||
t.pointer(&cx, &PointerEvent { pen: upright, pressure: 0.5, ..PointerEvent::new(PointerKind::Down, 100.0, 50.0) });
|
||||
t.pointer(&cx, &PointerEvent { pen: leaning, pressure: 0.5, ..PointerEvent::new(PointerKind::Drag, 200.0, 50.0) });
|
||||
assert!(tip(&t).height() > 6.0, "{:?}", tip(&t));
|
||||
@@ -3303,7 +3348,7 @@ fn the_eraser_tip_turns_in_place_and_passes_a_nib_size() {
|
||||
for (k, v) in [("size", json!(1000)), ("sizeMode", json!("tilt")), ("sizeVariation", json!(1000))] {
|
||||
t.set_option(k, &v);
|
||||
}
|
||||
let upright = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: None });
|
||||
let upright = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: None, wheel: None });
|
||||
t.pointer(&cx, &PointerEvent { pen: upright, pressure: 0.5, ..PointerEvent::new(PointerKind::Down, 100.0, 50.0) });
|
||||
t.pointer(&cx, &PointerEvent { pen: upright, pressure: 0.5, ..PointerEvent::new(PointerKind::Drag, 200.0, 50.0) });
|
||||
near(tip(&t), (-800.0, -950.0, 1200.0, 1050.0));
|
||||
@@ -3339,9 +3384,9 @@ fn the_eraser_drag_area_follows_its_variation_modes() {
|
||||
t.set_option(k, v);
|
||||
}
|
||||
};
|
||||
let upright = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: None });
|
||||
let turned = Some(PenPose { tilt: None, rotation: Some(180.0) });
|
||||
let level = Some(PenPose { tilt: None, rotation: Some(0.0) });
|
||||
let upright = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: None, wheel: None });
|
||||
let turned = Some(PenPose { tilt: None, rotation: Some(180.0), wheel: None });
|
||||
let level = Some(PenPose { tilt: None, rotation: Some(0.0), wheel: None });
|
||||
let press = |t: &mut GestureTool, pen: Option<PenPose>, kind: PointerKind, x: f64| {
|
||||
t.pointer(&cx, &PointerEvent { pen, pressure: 0.5, ..PointerEvent::new(kind, x, 150.0) });
|
||||
};
|
||||
@@ -3380,7 +3425,7 @@ fn the_eraser_drag_area_follows_its_variation_modes() {
|
||||
// lying flat the tip is 25% round and stands upright.
|
||||
let mut t = GestureTool::new("eraser");
|
||||
set(&mut t, &[("size", json!(20)), ("angle", json!(90)), ("roundnessMode", json!("tilt")), ("roundnessVariation", json!(75))]);
|
||||
let flat = Some(PenPose { tilt: Some([90.0, 0.0]), rotation: None });
|
||||
let flat = Some(PenPose { tilt: Some([90.0, 0.0]), rotation: None, wheel: None });
|
||||
press(&mut t, flat, PointerKind::Down, 50.0);
|
||||
press(&mut t, flat, PointerKind::Drag, 150.0);
|
||||
near(bounds(&t), (47.5, 140.0, 152.5, 160.0));
|
||||
@@ -3430,8 +3475,8 @@ fn the_eraser_drag_area_matches_the_release_when_pressure_or_a_mode_starts_durin
|
||||
let near = |b: vectorcraft_geom::Rect, want: (f64, f64, f64, f64)| {
|
||||
assert!([b.x0 - want.0, b.y0 - want.1, b.x1 - want.2, b.y1 - want.3].iter().all(|e| e.abs() < 0.01), "{b:?} vs {want:?}");
|
||||
};
|
||||
let upright = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: None });
|
||||
let leaning = Some(PenPose { tilt: Some([45.0, 0.0]), rotation: None });
|
||||
let upright = Some(PenPose { tilt: Some([0.0, 0.0]), rotation: None, wheel: None });
|
||||
let leaning = Some(PenPose { tilt: Some([45.0, 0.0]), rotation: None, wheel: None });
|
||||
let press = |t: &mut GestureTool, pen: Option<PenPose>, pressure: f32, kind: PointerKind, x: f64| {
|
||||
t.pointer(&cx, &PointerEvent { pen, pressure, ..PointerEvent::new(kind, x, 150.0) });
|
||||
};
|
||||
@@ -3521,14 +3566,14 @@ fn the_eraser_drag_area_gives_the_first_lean_to_the_points_before_it() {
|
||||
let mut shown = vec![];
|
||||
for (i, (tilt, x)) in poses.into_iter().zip([50.0, 100.0, 150.0, 200.0, 250.0]).enumerate() {
|
||||
let kind = if i == 0 { PointerKind::Down } else { PointerKind::Drag };
|
||||
let pen = Some(PenPose { tilt: Some(tilt), rotation: Some(30.0) });
|
||||
let pen = Some(PenPose { tilt: Some(tilt), rotation: Some(30.0), wheel: None });
|
||||
t.pointer(&cx, &PointerEvent { pen, pressure: 1.0, ..PointerEvent::new(kind, x, 150.0) });
|
||||
if i > 0 {
|
||||
shown.push(bounds(&t));
|
||||
}
|
||||
}
|
||||
if let Some(tilt) = in_place {
|
||||
let pen = Some(PenPose { tilt: Some(tilt), rotation: Some(30.0) });
|
||||
let pen = Some(PenPose { tilt: Some(tilt), rotation: Some(30.0), wheel: None });
|
||||
t.pointer(&cx, &PointerEvent { pen, pressure: 1.0, ..PointerEvent::new(PointerKind::Drag, 250.2, 150.0) });
|
||||
shown.push(bounds(&t));
|
||||
}
|
||||
|
||||
+34
-14
@@ -46,8 +46,8 @@ pub struct PointerEvent {
|
||||
pub backquote: bool,
|
||||
#[serde(default = "one")]
|
||||
pub pressure: f32,
|
||||
/// The pen's tilt and barrel rotation, when the pointer is a pen that reads either (a mouse:
|
||||
/// `None`).
|
||||
/// The pen's tilt, barrel rotation and finger wheel, when the pointer is a pen that reads any of
|
||||
/// them (a mouse: `None`).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub pen: Option<PenPose>,
|
||||
}
|
||||
@@ -58,23 +58,27 @@ fn one() -> f32 {
|
||||
|
||||
/// How a pen is held, as far as it reads it. Tilt is in degrees, each −90..90 as Pointer Events
|
||||
/// give it, in document axes: `[x, y]`, x positive when the pen leans to the right and y positive
|
||||
/// when it leans down the page. Rotation is the barrel's, in degrees clockwise (0..360).
|
||||
/// when it leans down the page. Rotation is the barrel's, in degrees clockwise (0..360). The wheel
|
||||
/// is where an airbrush pen's finger wheel is set, 0..1 from one end of its travel to the other.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PenPose {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub tilt: Option<[f32; 2]>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub rotation: Option<f32>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub wheel: Option<f32>,
|
||||
}
|
||||
|
||||
impl PenPose {
|
||||
/// Within its ranges: each tilt is clamped to −90..90 and the rotation brought into 0..360; a
|
||||
/// tilt or rotation that is not a number is left out.
|
||||
/// Within its ranges: each tilt is clamped to −90..90, the rotation brought into 0..360 and the
|
||||
/// wheel clamped to 0..1; a tilt, rotation or wheel that is not a number is left out.
|
||||
pub fn sanitized(self) -> Self {
|
||||
let tilt = self.tilt.filter(|t| t.iter().all(|v| v.is_finite())).map(|t| t.map(|v| v.clamp(-90.0, 90.0)));
|
||||
// `rem_euclid` can round a tiny negative angle up to 360 itself.
|
||||
let rotation = self.rotation.filter(|r| r.is_finite()).map(|r| r.rem_euclid(360.0)).map(|r| if r >= 360.0 { 0.0 } else { r });
|
||||
Self { tilt, rotation }
|
||||
let wheel = self.wheel.filter(|w| w.is_finite()).map(|w| w.clamp(0.0, 1.0));
|
||||
Self { tilt, rotation, wheel }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,14 +96,15 @@ impl PointerEvent {
|
||||
}
|
||||
/// The pen's tilt and rotation of a pointer event given as JSON (control channel, MCP):
|
||||
/// `tiltX` and `tiltY` (degrees, −90..90, in document axes; one without the other is 0) and
|
||||
/// `rotation` (degrees clockwise, brought into 0..360). Values that are not numbers are left
|
||||
/// out; `None` without any.
|
||||
/// `rotation` (degrees clockwise, brought into 0..360) and `wheel` (an airbrush pen's finger
|
||||
/// wheel, clamped to 0..1). Values that are not numbers are left out; `None` without any.
|
||||
pub fn json_pen(e: &Value) -> Option<PenPose> {
|
||||
let num = |k: &str| e.get(k).and_then(Value::as_f64).filter(|f| f.is_finite());
|
||||
let tilt = |v: Option<f64>| v.map_or(0.0, |v| v.clamp(-90.0, 90.0) as f32);
|
||||
let (tx, ty) = (num("tiltX"), num("tiltY"));
|
||||
let tilt = (tx.is_some() || ty.is_some()).then(|| [tilt(tx), tilt(ty)]);
|
||||
let pose = PenPose { tilt, rotation: num("rotation").map(|r| r.rem_euclid(360.0) as f32) }.sanitized();
|
||||
let rotation = num("rotation").map(|r| r.rem_euclid(360.0) as f32);
|
||||
let pose = PenPose { tilt, rotation, wheel: num("wheel").map(|w| w.clamp(0.0, 1.0) as f32) }.sanitized();
|
||||
(pose != PenPose::default()).then_some(pose)
|
||||
}
|
||||
/// How long the pointer then holds still, in seconds, from a JSON pointer event's `holdMs`
|
||||
@@ -113,11 +118,13 @@ impl PointerEvent {
|
||||
v.get("backquote").map_or(Ok(default), |b| b.as_bool().ok_or_else(|| "`backquote` must be a boolean".to_owned()))
|
||||
}
|
||||
/// Checks the optional keys of a JSON pointer event (control channel, MCP): `pressure`,
|
||||
/// `holdMs`, `tiltX`, `tiltY` and `rotation` must be numbers, and `space` must be `doc` or
|
||||
/// `screen`. A key that is absent or null keeps its default.
|
||||
/// `holdMs`, `tiltX`, `tiltY`, `rotation` and `wheel` must be numbers, and `space` must be
|
||||
/// `doc` or `screen`. A key that is absent or null keeps its default.
|
||||
pub fn json_check(e: &Value) -> Result<(), String> {
|
||||
let given = |k: &str| e.get(k).filter(|v| !v.is_null());
|
||||
if let Some(k) = ["pressure", "holdMs", "tiltX", "tiltY", "rotation"].into_iter().find(|k| given(k).is_some_and(|v| v.as_f64().is_none())) {
|
||||
if let Some(k) =
|
||||
["pressure", "holdMs", "tiltX", "tiltY", "rotation", "wheel"].into_iter().find(|k| given(k).is_some_and(|v| v.as_f64().is_none()))
|
||||
{
|
||||
return Err(format!("`{k}` must be a number"));
|
||||
}
|
||||
if given("space").is_some_and(|v| !matches!(v.as_str(), Some("doc" | "screen"))) {
|
||||
@@ -157,13 +164,13 @@ mod tests {
|
||||
use serde_json::json;
|
||||
for ok in [
|
||||
json!({}),
|
||||
json!({"pressure": 0.5, "holdMs": 10, "tiltX": -5, "tiltY": 5, "rotation": 400, "space": "screen"}),
|
||||
json!({"pressure": 0.5, "holdMs": 10, "tiltX": -5, "tiltY": 5, "rotation": 400, "wheel": 0.25, "space": "screen"}),
|
||||
json!({"pressure": null, "space": null}),
|
||||
json!({"space": "doc"}),
|
||||
] {
|
||||
assert_eq!(PointerEvent::json_check(&ok), Ok(()), "{ok}");
|
||||
}
|
||||
for k in ["pressure", "holdMs", "tiltX", "tiltY", "rotation"] {
|
||||
for k in ["pressure", "holdMs", "tiltX", "tiltY", "rotation", "wheel"] {
|
||||
for bad in [json!("1"), json!(true), json!([1])] {
|
||||
assert_eq!(PointerEvent::json_check(&json!({k: bad})), Err(format!("`{k}` must be a number")), "{k}: {bad}");
|
||||
}
|
||||
@@ -172,6 +179,19 @@ mod tests {
|
||||
assert_eq!(PointerEvent::json_check(&json!({"space": bad})), Err("`space` must be doc or screen".to_owned()), "{bad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn json_pen_reads_the_wheel_within_its_range() {
|
||||
use serde_json::json;
|
||||
let wheel = |v: Value| PointerEvent::json_pen(&json!({"wheel": v})).and_then(|q| q.wheel);
|
||||
assert_eq!(wheel(json!(0.25)), Some(0.25));
|
||||
assert_eq!(wheel(json!(-3)), Some(0.0));
|
||||
assert_eq!(wheel(json!(7)), Some(1.0));
|
||||
assert_eq!(wheel(json!(null)), None);
|
||||
assert_eq!(PointerEvent::json_pen(&json!({"wheel": 0.5})), Some(PenPose { wheel: Some(0.5), ..PenPose::default() }));
|
||||
assert_eq!(PenPose { wheel: Some(f32::NAN), ..PenPose::default() }.sanitized(), PenPose::default());
|
||||
assert_eq!(PenPose { wheel: Some(1.5), ..PenPose::default() }.sanitized().wheel, Some(1.0));
|
||||
}
|
||||
}
|
||||
|
||||
/// Keys tools care about.
|
||||
|
||||
@@ -10985,8 +10985,8 @@ fn frame_moves_stop_at_the_button_up() {
|
||||
let up = egui::Event::PointerButton { pos: b, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() };
|
||||
let events = vec![egui::Event::PointerMoved(a), egui::Event::PointerMoved(b), up, egui::Event::PointerMoved(c), egui::Event::PointerMoved(d)];
|
||||
let feed = StylusFeed::default();
|
||||
let at_b = PenPose { tilt: Some([20.0, 0.0]), rotation: None };
|
||||
let after = PenPose { tilt: Some([50.0, 0.0]), rotation: None };
|
||||
let at_b = PenPose { tilt: Some([20.0, 0.0]), ..PenPose::default() };
|
||||
let after = PenPose { tilt: Some([50.0, 0.0]), ..PenPose::default() };
|
||||
for (p, pose) in [(0.4, PenPose::default()), (0.6, at_b), (0.7, after), (0.8, after)] {
|
||||
feed.set_move(crate::stylus::PenSample { pressure: p, pose, ..Default::default() });
|
||||
}
|
||||
@@ -11011,7 +11011,7 @@ fn frame_moves_keep_the_last_move_when_the_button_went_up_elsewhere() {
|
||||
let up = egui::Event::PointerButton { pos: up_at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() };
|
||||
let events = vec![egui::Event::PointerMoved(a), egui::Event::PointerMoved(b), up, egui::Event::PointerMoved(c)];
|
||||
let feed = StylusFeed::default();
|
||||
let at_b = PenPose { tilt: Some([20.0, 0.0]), rotation: None };
|
||||
let at_b = PenPose { tilt: Some([20.0, 0.0]), ..PenPose::default() };
|
||||
for (p, pose) in [(0.4, PenPose::default()), (0.6, at_b), (0.7, PenPose::default())] {
|
||||
feed.set_move(crate::stylus::PenSample { pressure: p, pose, ..Default::default() });
|
||||
}
|
||||
@@ -11037,7 +11037,7 @@ fn frame_moves_keeps_touch_feed_and_mouse_samples_with_their_pressure() {
|
||||
assert_eq!(mouse, [(a, None, None), (b, None, None)], "the last move follows the normal pointer path");
|
||||
// A macOS pen: the feed kept a pressure and a pose for each move, the last for the last.
|
||||
let feed = StylusFeed::default();
|
||||
let leaning = PenPose { tilt: Some([30.0, 0.0]), rotation: None };
|
||||
let leaning = PenPose { tilt: Some([30.0, 0.0]), ..PenPose::default() };
|
||||
for (p, pose) in [(0.9, leaning), (0.3, leaning), (0.0, PenPose::default()), (0.5, leaning)] {
|
||||
feed.set_move(crate::stylus::PenSample { pressure: p, pose, ..Default::default() });
|
||||
}
|
||||
@@ -11556,7 +11556,7 @@ fn the_hosts_pen_tilt_and_rotation_reach_the_paintbrush() {
|
||||
assert_eq!(cmd, "path.freehand");
|
||||
p["points"].as_array().unwrap().iter().map(|s| [3, 4, 5].map(|i| s.get(i).and_then(serde_json::Value::as_f64))).collect()
|
||||
};
|
||||
let leaning = PenPose { tilt: Some([30.0, 0.0]), rotation: Some(45.0) };
|
||||
let leaning = PenPose { tilt: Some([30.0, 0.0]), rotation: Some(45.0), wheel: None };
|
||||
let points = stroke(&mut app, 260.0, Some(leaning));
|
||||
assert!(!points.is_empty() && points.iter().all(|p| *p == [Some(30.0), Some(0.0), Some(45.0)]), "{points:?}");
|
||||
// With the view rotated 90° clockwise, a pen leaning to the right of the screen leans up the
|
||||
@@ -11587,7 +11587,7 @@ fn moves_in_the_release_frame_reach_the_paintbrush_with_their_tilt() {
|
||||
let moved = |tilt: f32| {
|
||||
feed.set_move(crate::stylus::PenSample {
|
||||
pressure: 0.5,
|
||||
pose: PenPose { tilt: Some([tilt, 0.0]), rotation: Some(0.0) },
|
||||
pose: PenPose { tilt: Some([tilt, 0.0]), rotation: Some(0.0), wheel: None },
|
||||
..Default::default()
|
||||
})
|
||||
};
|
||||
@@ -11630,8 +11630,11 @@ fn the_last_move_of_a_frame_keeps_its_own_tilt() {
|
||||
let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
|
||||
let at = |x: f64| xf.to_screen(Point::new(x, 300.0));
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
let sample =
|
||||
|tilt: f32| crate::stylus::PenSample { pressure: 0.5, pose: PenPose { tilt: Some([tilt, 0.0]), rotation: Some(0.0) }, ..Default::default() };
|
||||
let sample = |tilt: f32| crate::stylus::PenSample {
|
||||
pressure: 0.5,
|
||||
pose: PenPose { tilt: Some([tilt, 0.0]), rotation: Some(0.0), wheel: None },
|
||||
..Default::default()
|
||||
};
|
||||
feed.set_move(sample(10.0));
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at(300.0)), button(at(300.0), true)]);
|
||||
feed.set_move(sample(20.0));
|
||||
|
||||
@@ -255,7 +255,8 @@ fn scatter_mode(d: &Dialog, key: &str) -> Variation {
|
||||
Variation::parse(&d.str(&mode_key(key))).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// How an art brush's width varies: Fixed, or with the pen's pressure, tilt, bearing or rotation.
|
||||
/// How an art brush's width varies: Fixed, or with the pen's pressure, tilt, bearing, rotation or
|
||||
/// wheel.
|
||||
fn art_width_mode(d: &Dialog) -> Variation {
|
||||
Variation::parse(&d.str("widthMode")).filter(|m| m.follows_pen()).unwrap_or(Variation::Fixed)
|
||||
}
|
||||
@@ -436,7 +437,6 @@ fn flips(ui: &mut egui::Ui, d: &mut Dialog) {
|
||||
|
||||
fn scatter_body(ui: &mut egui::Ui, d: &mut Dialog) {
|
||||
let labels = [tl!("Size:"), tl!("Spacing:"), tl!("Scatter:"), tl!("Rotation:")];
|
||||
let modes = Variation::ALL.map(Variation::label);
|
||||
egui::Grid::new("brush-options-scatter").num_columns(4).spacing([8.0, 8.0]).show(ui, |ui| {
|
||||
for (((key, suffix), range), text) in SCATTER.into_iter().zip(Scatter::RANGES).zip(labels) {
|
||||
super::swatch_options::label(ui, text);
|
||||
@@ -450,7 +450,9 @@ fn scatter_body(ui: &mut egui::Ui, d: &mut Dialog) {
|
||||
}
|
||||
});
|
||||
}
|
||||
if let Some(m) = widgets::dropdown(ui, ("brush-scatter-mode", key), mode.label(), &modes, 104.0).and_then(|i| Variation::ALL.get(i)) {
|
||||
let offered = Variation::offered(key == "size");
|
||||
let modes: Vec<&str> = offered.iter().map(|m| m.label()).collect();
|
||||
if let Some(m) = widgets::dropdown(ui, ("brush-scatter-mode", key), mode.label(), &modes, 104.0).and_then(|i| offered.get(i)) {
|
||||
d.fields.insert(mode_key(key), json!(m.id()));
|
||||
}
|
||||
ui.end_row();
|
||||
@@ -472,7 +474,7 @@ fn art_body(ui: &mut egui::Ui, d: &mut Dialog) {
|
||||
super::form::slider_field_named(ui, d, "width", tl!("Width:"), range.0..=range.1, "%", &|_| rail);
|
||||
let mode = art_width_mode(d);
|
||||
number(ui, d, "widthMax", range, "%", mode.follows_pen());
|
||||
let modes = [Variation::Fixed, Variation::Pressure, Variation::Tilt, Variation::Bearing, Variation::Rotation];
|
||||
let modes = [Variation::Fixed, Variation::Pressure, Variation::Tilt, Variation::Bearing, Variation::Rotation, Variation::StylusWheel];
|
||||
if let Some(m) = widgets::dropdown(ui, "brush-art-width-mode", mode.label(), &modes.map(Variation::label), 104.0).and_then(|i| modes.get(i)) {
|
||||
d.fields.insert("widthMode".into(), json!(m.id()));
|
||||
}
|
||||
|
||||
@@ -454,8 +454,9 @@ fn calligraphic_body(app: &VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) {
|
||||
d.fields.insert(key.into(), json!(v));
|
||||
}
|
||||
let mode = Variation::parse(&d.str(&mode_key(key))).unwrap_or_default();
|
||||
let labels = Variation::ALL.map(Variation::label);
|
||||
if let Some(m) = widgets::dropdown(ui, ("brush-mode", key), mode.label(), &labels, 104.0).and_then(|i| Variation::ALL.get(i)) {
|
||||
let offered = Variation::offered(key == "size");
|
||||
let labels: Vec<&str> = offered.iter().map(|m| m.label()).collect();
|
||||
if let Some(m) = widgets::dropdown(ui, ("brush-mode", key), mode.label(), &labels, 104.0).and_then(|i| offered.get(i)) {
|
||||
d.fields.insert(mode_key(key), json!(m.id()));
|
||||
}
|
||||
label(ui, tl!("Variation:"));
|
||||
|
||||
@@ -2244,6 +2244,7 @@ font-technology Variable Променливи
|
||||
Pressure Натиск
|
||||
Tilt Наклон
|
||||
Bearing Азимут
|
||||
Stylus Wheel Колелце на писалката
|
||||
Shape: Форма:
|
||||
Bristle Length: Дължина на косъма:
|
||||
Bristle Density: Плътност на косъмчетата:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3420,6 +3420,7 @@ antiAlias Sharp Oštro
|
||||
Pressure Pritisak
|
||||
Tilt Nagib
|
||||
Bearing Smjer
|
||||
Stylus Wheel Kotačić olovke
|
||||
Random Nasumično
|
||||
Scatter Raspršeno
|
||||
Color Burn Tamnjenje boje
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -490,6 +490,7 @@ antiAlias Sharp Nítid
|
||||
Batch Lot
|
||||
Batch… Lot…
|
||||
Bearing Orientació
|
||||
Stylus Wheel Roda del llapis
|
||||
Before Last: Abans de l’últim:
|
||||
Begin Recording Comença a enregistrar
|
||||
Exclude from playback Exclou de la reproducció
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3507,6 +3507,7 @@ antiAlias Sharp Ostré
|
||||
# Command labels and other interface strings
|
||||
Art Obrazový
|
||||
Bearing Azimut
|
||||
Stylus Wheel Kolečko pera
|
||||
Bristle Štětinový
|
||||
Calligraphic Kaligrafický
|
||||
Dots Body
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -5971,6 +5971,7 @@ antiAlias Sharp Skarp
|
||||
Width Point Edit Redigér breddepunkt
|
||||
Art Kunst
|
||||
Bearing Retning
|
||||
Stylus Wheel Pennehjul
|
||||
Bristle Borst
|
||||
Calligraphic Kalligrafisk
|
||||
Dots Prikker
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2297,6 +2297,7 @@ file-filter Templates Vorlagen
|
||||
Pressure Druck
|
||||
Tilt Neigung
|
||||
Bearing Richtung
|
||||
Stylus Wheel Stiftrad
|
||||
Shape: Form:
|
||||
Bristle Length: Borstenlänge:
|
||||
Bristle Density: Borstendichte:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -1976,6 +1976,7 @@ font-technology Variable Μεταβλητές
|
||||
Pressure Πίεση
|
||||
Tilt Κλίση
|
||||
Bearing Αζιμούθιο
|
||||
Stylus Wheel Τροχός γραφίδας
|
||||
Shape: Σχήμα:
|
||||
New Brush… Νέο πινέλο…
|
||||
New Brush Νέο πινέλο
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2341,6 +2341,7 @@ font-technology Variable Variables
|
||||
Pressure Presión
|
||||
Tilt Inclinación
|
||||
Bearing Orientación
|
||||
Stylus Wheel Rueda del lápiz
|
||||
Shape: Forma:
|
||||
Bristle Length: Longitud de cerdas:
|
||||
Bristle Density: Densidad de cerdas:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3447,6 +3447,7 @@ antiAlias Sharp Terävä
|
||||
Width Point Edit Leveyspisteen muokkaus
|
||||
Art Kuvitus
|
||||
Bearing Suunta
|
||||
Stylus Wheel Kynän rulla
|
||||
Bristle Harjas
|
||||
Calligraphic Kalligrafinen
|
||||
Dots Pisteet
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -2329,6 +2329,7 @@ font-technology Variable Variables
|
||||
Pressure Pression
|
||||
Tilt Inclinaison
|
||||
Bearing Orientation
|
||||
Stylus Wheel Molette du stylet
|
||||
Shape: Forme :
|
||||
Bristle Length: Longueur des soies :
|
||||
Bristle Density: Densité des soies :
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -843,6 +843,7 @@ antiAlias Sharp शार्प
|
||||
Batch Trace Folder फ़ोल्डर बैच ट्रेस करें
|
||||
Batch… बैच…
|
||||
Bearing दिशा
|
||||
Stylus Wheel स्टाइलस व्हील
|
||||
Before Last: अंत के पहले:
|
||||
Begin Recording रिकॉर्डिंग शुरू करें
|
||||
Begin Undo Group पूर्ववत समूह शुरू करें
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -417,6 +417,7 @@ font-technology Variable Változó
|
||||
Basic Latin Alap latin
|
||||
Batch Kötegelt feldolgozás
|
||||
Bearing Irány
|
||||
Stylus Wheel Tollkerék
|
||||
Begin Recording Felvétel indítása
|
||||
Exclude from playback Kizárás a lejátszásból
|
||||
Include in playback Bevonás a lejátszásba
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3188,6 +3188,7 @@ antiAlias Sharp Tajam
|
||||
Width Point Edit Edit titik lebar
|
||||
Art Seni
|
||||
Bearing Arah
|
||||
Stylus Wheel Roda stylus
|
||||
Bristle Bristle
|
||||
Calligraphic Kaligrafis
|
||||
Dots Titik
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2563 and column 5.
|
@@ -2382,6 +2382,7 @@ file-filter Templates Modelli
|
||||
Pressure Pressione
|
||||
Tilt Inclinazione
|
||||
Bearing Orientamento
|
||||
Stylus Wheel Rotella dello stilo
|
||||
Shape: Forma:
|
||||
Bristle Length: Lunghezza setole:
|
||||
Bristle Density: Densità setole:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2581,6 +2581,7 @@ antiAlias Sharp シャープ
|
||||
Pressure 筆圧
|
||||
Tilt 傾き
|
||||
Bearing 方位
|
||||
Stylus Wheel スタイラスホイール
|
||||
Shape: 形状:
|
||||
Bristle Length: 毛の長さ:
|
||||
Bristle Density: 毛の密度:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -5276,6 +5276,7 @@ antiAlias Sharp მკვეთრი
|
||||
Width Point Edit სიგანის წერტილის რედაქტირება
|
||||
Art ნახატი
|
||||
Bearing აზიმუტი
|
||||
Stylus Wheel სტილუსის ბორბალი
|
||||
Bristle ჯაგრისი
|
||||
Calligraphic კალიგრაფიული
|
||||
Dots წერტილები
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2571,6 +2571,7 @@ antiAlias Sharp 날카롭게
|
||||
Pressure 필압
|
||||
Tilt 기울기
|
||||
Bearing 방위
|
||||
Stylus Wheel 스타일러스 휠
|
||||
Shape: 모양:
|
||||
Bristle Length: 강모 길이:
|
||||
Bristle Density: 강모 밀도:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3842,6 +3842,7 @@ antiAlias Sharp Scherp
|
||||
Width Point Edit Breedtepunt bewerken
|
||||
Art Illustratie
|
||||
Bearing Richting
|
||||
Stylus Wheel Pennenwiel
|
||||
Bristle Borstel
|
||||
Calligraphic Kalligrafisch
|
||||
Dots Stippen
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3386,6 +3386,7 @@ antiAlias Sharp Ostre
|
||||
Width Point Edit Edycja punktu szerokości
|
||||
Art Artystyczny
|
||||
Bearing Kierunek
|
||||
Stylus Wheel Kółko pióra
|
||||
Bristle Włosiankowy
|
||||
Calligraphic Kaligraficzny
|
||||
Dots Kropki
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -5512,6 +5512,7 @@ variable-list-end {0}, {1} {0} e {1}
|
||||
Pressure Pressão
|
||||
Tilt Inclinação
|
||||
Bearing Orientação
|
||||
Stylus Wheel Roda da caneta
|
||||
Bristle Length: Comprimento das Cerdas:
|
||||
Bristle Density: Densidade das Cerdas:
|
||||
Bristle Thickness: Espessura das Cerdas:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2366,6 +2366,7 @@ file-filter Templates Шаблоны
|
||||
Pressure Нажим
|
||||
Tilt Наклон
|
||||
Bearing Азимут
|
||||
Stylus Wheel Колесико пера
|
||||
Shape: Форма:
|
||||
Bristle Length: Длина щетинок:
|
||||
Bristle Density: Плотность щетинок:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2268,6 +2268,7 @@ font-technology Variable Variabla
|
||||
Pressure Tryck
|
||||
Tilt Lutning
|
||||
Bearing Riktning
|
||||
Stylus Wheel Pennhjul
|
||||
Shape: Form:
|
||||
Bristle Length: Borstlängd:
|
||||
Bristle Density: Borsttäthet:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2147,6 +2147,7 @@ font-technology Variable Değişken
|
||||
Pressure Basınç
|
||||
Tilt Eğim
|
||||
Bearing Yön
|
||||
Stylus Wheel Kalem tekerleği
|
||||
Shape: Şekil:
|
||||
Bristle Length: Kıl Uzunluğu:
|
||||
Bristle Density: Kıl Yoğunluğu:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2374,6 +2374,7 @@ file-filter Templates Шаблони
|
||||
Pressure Натиск
|
||||
Tilt Нахил
|
||||
Bearing Азимут
|
||||
Stylus Wheel Коліщатко пера
|
||||
Shape: Форма:
|
||||
Bristle Length: Довжина щетинок:
|
||||
Bristle Density: Щільність щетинок:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -341,6 +341,7 @@ font-technology Variable Biến thiên
|
||||
Basic Latin Latin cơ bản
|
||||
Batch Hàng loạt
|
||||
Bearing Hướng
|
||||
Stylus Wheel Bánh xe bút
|
||||
Begin Recording Bắt đầu ghi
|
||||
Exclude from playback Loại khỏi phát lại
|
||||
Include in playback Đưa vào phát lại
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -2239,6 +2239,7 @@ file-filter Templates 模板
|
||||
Pressure 压力
|
||||
Tilt 倾斜
|
||||
Bearing 方位
|
||||
Stylus Wheel 光笔滚轮
|
||||
Shape: 形状:
|
||||
Bristle Length: 鬃毛长度:
|
||||
Bristle Density: 鬃毛密度:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -3581,6 +3581,7 @@ liquify-list-end {0}, {1} {0}和{1}
|
||||
Pressure 壓力
|
||||
Tilt 傾斜
|
||||
Bearing 方位
|
||||
Stylus Wheel 光筆滾輪
|
||||
Shape: 形狀:
|
||||
Bristle Length: 鬃毛長度:
|
||||
Bristle Density: 鬃毛密度:
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -109,8 +109,9 @@ fn preview(ui: &Ui, doc: &Document, def: &Value, key: u64, size: egui::Vec2) ->
|
||||
/// What a stroke preview of brush definition `def`, `w` × `h` pt, renders: a copy of `resources`
|
||||
/// (a document whose patterns, symbols, swatches and images the brush art may use) without its art,
|
||||
/// and a stroke painted with the brush across it. The stroke goes from light to heavy pen pressure
|
||||
/// and back, from an upright pen to one lying flat and back, and once round every bearing and barrel
|
||||
/// rotation, so brushes that vary with the pen show how they vary.
|
||||
/// and back, from an upright pen to one lying flat and back, once round every bearing and barrel
|
||||
/// rotation, and from one end of an airbrush pen's finger wheel to the other and back, so brushes
|
||||
/// that vary with the pen show how they vary.
|
||||
fn preview_doc(resources: &Document, def: &Value, w: f64, h: f64) -> Option<Document> {
|
||||
let mut doc = resources.clone();
|
||||
let layer = doc.alloc_id();
|
||||
@@ -124,6 +125,7 @@ fn preview_doc(resources: &Document, def: &Value, w: f64, h: f64) -> Option<Docu
|
||||
st.tilt = Some(PressureProfile::sample());
|
||||
st.bearing = Some(AngleProfile::sample());
|
||||
st.rotation = Some(AngleProfile::sample());
|
||||
st.wheel = Some(PressureProfile::sample());
|
||||
// A gentle S-curve across the swatch (square tiles keep a quarter of it either side).
|
||||
let mut bp = vectorcraft_geom::BezPath::new();
|
||||
let margin = (h * 0.5).min(w * 0.25);
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
//! where winit drops which end of the pen is down, the app reads the pressure and the end from
|
||||
//! each pointer message of a pen before winit handles it. The canvas uses the pressure when a
|
||||
//! frame's events carry no touch force, and the tilt and rotation for each press, drag and release.
|
||||
//! An airbrush pen's finger wheel comes with the tilt and rotation ([`PenPose::wheel`]) where the
|
||||
//! host reads it: from XInput2 on X11 and from AppKit on macOS. The app does not read it on
|
||||
//! Windows, whose pointer messages have no field for it, or in the web build.
|
||||
//!
|
||||
//! The feed also says which end of the pen moved. Turning the pen to its eraser end selects the
|
||||
//! Eraser tool, and turning it back to the tip selects the tool used before
|
||||
@@ -48,7 +51,7 @@ pub struct PenSample {
|
||||
pub pressure: f32,
|
||||
/// The pen is turned to its eraser end.
|
||||
pub eraser: bool,
|
||||
/// The tilt and rotation the pen read, if any.
|
||||
/// The tilt, rotation and finger wheel the pen read, if any.
|
||||
pub pose: PenPose,
|
||||
}
|
||||
|
||||
@@ -342,19 +345,22 @@ mod tests {
|
||||
let feed = StylusFeed::default();
|
||||
assert_eq!(feed.pose(), None);
|
||||
let pen = |pose| Some(PenSample { pressure: 0.4, pose, ..PenSample::default() });
|
||||
let leaning = PenPose { tilt: Some([-120.0, 30.0]), rotation: Some(-90.0) };
|
||||
let leaning = PenPose { tilt: Some([-120.0, 30.0]), rotation: Some(-90.0), wheel: None };
|
||||
feed.set_sample(pen(leaning));
|
||||
assert_eq!(feed.pose(), Some(PenPose { tilt: Some([-90.0, 30.0]), rotation: Some(270.0) }));
|
||||
assert_eq!(feed.pose(), Some(PenPose { tilt: Some([-90.0, 30.0]), rotation: Some(270.0), wheel: None }));
|
||||
assert_eq!(feed.held(), Some(0.4), "the pressure as before");
|
||||
// Not a number: left out. A tiny negative rotation is 0, not 360.
|
||||
feed.set_sample(pen(PenPose { tilt: Some([f32::NAN, 0.0]), rotation: Some(-1e-9) }));
|
||||
assert_eq!(feed.pose(), Some(PenPose { tilt: None, rotation: Some(0.0) }));
|
||||
feed.set_sample(pen(PenPose { tilt: None, rotation: Some(f32::INFINITY) }));
|
||||
assert_eq!(feed.pose(), None, "a pen that reads neither");
|
||||
feed.set_sample(pen(PenPose { tilt: Some([f32::NAN, 0.0]), rotation: Some(-1e-9), wheel: None }));
|
||||
assert_eq!(feed.pose(), Some(PenPose { rotation: Some(0.0), ..PenPose::default() }));
|
||||
feed.set_sample(pen(PenPose { rotation: Some(f32::INFINITY), wheel: Some(f32::NAN), ..PenPose::default() }));
|
||||
assert_eq!(feed.pose(), None, "a pen that reads none of them");
|
||||
assert!(PenPose { rotation: Some(725.0), ..Default::default() }.sanitized().rotation == Some(5.0));
|
||||
// An airbrush pen's finger wheel, clamped to 0..1.
|
||||
feed.set_sample(pen(PenPose { wheel: Some(1.25), ..PenPose::default() }));
|
||||
assert_eq!(feed.pose(), Some(PenPose { wheel: Some(1.0), ..PenPose::default() }));
|
||||
// The eraser end reads them too.
|
||||
feed.set_sample(Some(PenSample { pressure: 0.4, eraser: true, pose: leaning }));
|
||||
assert_eq!((feed.eraser(), feed.pose()), (Some(true), Some(PenPose { tilt: Some([-90.0, 30.0]), rotation: Some(270.0) })));
|
||||
assert_eq!((feed.eraser(), feed.pose()), (Some(true), Some(PenPose { tilt: Some([-90.0, 30.0]), rotation: Some(270.0), wheel: None })));
|
||||
// A pen that reads no tilt (`set`), or a mouse: none.
|
||||
feed.set_sample(pen(leaning));
|
||||
feed.set(Some(0.5));
|
||||
@@ -383,7 +389,7 @@ mod tests {
|
||||
#[test]
|
||||
fn the_feed_keeps_the_pressure_of_each_move() {
|
||||
let feed = StylusFeed::default();
|
||||
let leaning = PenPose { tilt: Some([20.0, -10.0]), rotation: Some(400.0) };
|
||||
let leaning = PenPose { tilt: Some([20.0, -10.0]), rotation: Some(400.0), wheel: Some(0.75) };
|
||||
for (p, pose) in [(0.2, PenPose::default()), (1.5, leaning), (0.4, PenPose::default())] {
|
||||
feed.set_move(PenSample { pressure: p, pose, ..PenSample::default() });
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ private editing data. VectorCraft:
|
||||
|
||||
### Illustrator's private editing data
|
||||
|
||||
The app's own editing copy of a file (an EPS after its `%%EOF`, a `.ai`'s `AIPrivateData` streams, a PDF's `AIPDFPrivateData` streams when it was saved with the editing data (#868), Zstandard or zlib, the EPS's in ASCII85) is not documented as a whole. VectorCraft reads its structure: layers and sublayers (names, order, visibility, lock, printing, preview, dimming, colour), groups as they were nested, compound paths (painted by their last path, or the last painted one, with the paths of groups inside them kept as their paths: #1410), clipping groups and layer clipping (several clipping paths in a clipping group, a layer or an opacity mask's art clip to their intersection, and a compound path of clipping paths stays one clip, its clipping paths grouped in it, at any depth, included; a filled clipping path keeps its fill, which paints under the art it clips, except the path of a mask that covers several layers, whose fill is read as a path of its own in the layer that holds the mask's path, and a compound clipping path whose subpaths paint differently, whose filled subpaths are read as a compound path of their own under the art it clips; clipping paths that would nest the art past the document's 32 levels stop the editing data from being read: #5789), object names, hidden and locked objects, fills and strokes (grey, CMYK, RGB, named and spot colours, spot colours defined in Lab with their Lab values (#1032), global process colours as global swatches at their tint; a stroke of width 0, `0 w`, on a path, a gradient-filled path, legacy type or in an art style comes in as a 0.25 pt hairline, as from PDF: #1671), linear and radial gradients, pattern fills with their patterns as pattern swatches (#1025), gradient and pattern names in the file up to their first newline (a name that another swatch, or a gradient or pattern defined earlier, already has is numbered "Sky 2"; a name without a newline is kept, and when another swatch has it, the pattern's swatch, or a named color sharing a gradient or pattern swatch's name, is numbered the same way), opacity, blend modes, isolation and knockout, embedded images where their matrix puts them, rotated ones too (#2269), with their alpha channel (CMYK images keep their ink amounts, as they do when a `.ai` opens from its PDF part, and an alpha channel that hides part of a CMYK image becomes a grayscale opacity mask), placed (linked) files as linked images in their place, each showing the low-resolution preview the file keeps of it until its file is found or relinked in the Links panel (#1264), with the folder the file keeps relative to the document's, where the link is looked for when its path is gone, placed PDF and `.ai` pages as placed documents of the [page and Crop to box](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-other-file-types/adobe-pdf-placement-options.html) their dictionary names (`AI11 PlacedPDFPageIndex`, `AI11 PlacedPDFCropTo`; a value VectorCraft doesn't read, or a binding to an image variable, leaves a linked image), guides, and every artboard where it is, with its center mark, cross hairs, video safe areas and video ruler pixel aspect ratio. VectorCraft reads `CropAreaActive`, an `/Int` in the dictionary that holds the artboard array, as the index of the active artboard in that array, and the file opens with that artboard active; without it, or when it names no artboard that opens, the first artboard is active. It also reads the Document Raster Effects Settings (resolution, color model, background, anti-alias, clipping mask, Add Around Object and Preserve Spot Colors), the author from the header's `%%For` (an EPS's own header when the editing data's has none), swatches for the header's `%%CMYKCustomColor` and `%%RGBCustomColor` colors that the document has none of, and `%%TemplateBox` in older files; a setting with a value of another type or out of range keeps its default. Objects on Path groups open live, with their path, their objects in order along it, Pivot and Rotate; one with a dragged spacing or other options opens as a plain group. A gradient with stops in the middle runs its whole ramp across its shape, and a gradient object does not pass its fill to the next path (#1390). An object whose art style is one fill and one stroke at most (solid colours, its own gradient, a variable-width profile on a Stroke Offset stroke or written as each side's widths) with Drop Shadow, Inner Glow, Outer Glow, Feather, Round Corners, Scribble, Offset Path, Outline Object, Outline Stroke, Convert to Shape, Tweak (only when it moves nothing), Pucker & Bloat at 0 or Bas Relief (read from its settings block: [raster effects reference](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-filter-effects/raster-effects-reference.html), [layered image file format specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/), [scripting the filter gallery](https://community.adobe.com/questions-712/scripting-supporLine truncated
|
||||
The app's own editing copy of a file (an EPS after its `%%EOF`, a `.ai`'s `AIPrivateData` streams, a PDF's `AIPDFPrivateData` streams when it was saved with the editing data (#868), Zstandard or zlib, the EPS's in ASCII85) is not documented as a whole. VectorCraft reads its structure: layers and sublayers (names, order, visibility, lock, printing, preview, dimming, colour), groups as they were nested, compound paths (painted by their last path, or the last painted one, with the paths of groups inside them kept as their paths: #1410), clipping groups and layer clipping (several clipping paths in a clipping group, a layer or an opacity mask's art clip to their intersection, and a compound path of clipping paths stays one clip, its clipping paths grouped in it, at any depth, included; a filled clipping path keeps its fill, which paints under the art it clips, except the path of a mask that covers several layers, whose fill is read as a path of its own in the layer that holds the mask's path, and a compound clipping path whose subpaths paint differently, whose filled subpaths are read as a compound path of their own under the art it clips; clipping paths that would nest the art past the document's 32 levels stop the editing data from being read: #5789), object names, hidden and locked objects, fills and strokes (grey, CMYK, RGB, named and spot colours, spot colours defined in Lab with their Lab values (#1032), global process colours as global swatches at their tint; a stroke of width 0, `0 w`, on a path, a gradient-filled path, legacy type or in an art style comes in as a 0.25 pt hairline, as from PDF: #1671), linear and radial gradients, pattern fills with their patterns as pattern swatches (#1025), gradient and pattern names in the file up to their first newline (a name that another swatch, or a gradient or pattern defined earlier, already has is numbered "Sky 2"; a name without a newline is kept, and when another swatch has it, the pattern's swatch, or a named color sharing a gradient or pattern swatch's name, is numbered the same way), opacity, blend modes, isolation and knockout, embedded images where their matrix puts them, rotated ones too (#2269), with their alpha channel (CMYK images keep their ink amounts, as they do when a `.ai` opens from its PDF part, and an alpha channel that hides part of a CMYK image becomes a grayscale opacity mask), placed (linked) files as linked images in their place, each showing the low-resolution preview the file keeps of it until its file is found or relinked in the Links panel (#1264), with the folder the file keeps relative to the document's, where the link is looked for when its path is gone, placed PDF and `.ai` pages as placed documents of the [page and Crop to box](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/import-other-file-types/adobe-pdf-placement-options.html) their dictionary names (`AI11 PlacedPDFPageIndex`, `AI11 PlacedPDFCropTo`; a value VectorCraft doesn't read, or a binding to an image variable, leaves a linked image), guides, and every artboard where it is, with its center mark, cross hairs, video safe areas and video ruler pixel aspect ratio. VectorCraft reads `CropAreaActive`, an `/Int` in the dictionary that holds the artboard array, as the index of the active artboard in that array, and the file opens with that artboard active; without it, or when it names no artboard that opens, the first artboard is active. It also reads the Document Raster Effects Settings (resolution, color model, background, anti-alias, clipping mask, Add Around Object and Preserve Spot Colors), the author from the header's `%%For` (an EPS's own header when the editing data's has none), swatches for the header's `%%CMYKCustomColor` and `%%RGBCustomColor` colors that the document has none of, and `%%TemplateBox` in older files; a setting with a value of another type or out of range keeps its default. Objects on Path groups open live, with their path, their objects in order along it, Pivot and Rotate; one with a dragged spacing or other options opens as a plain group. A gradient with stops in the middle runs its whole ramp across its shape, and a gradient object does not pass its fill to the next path (#1390). An object whose art style is one fill and one stroke at most (solid colours, its own gradient, a variable-width profile on a Stroke Offset stroke or written as each side's widths) with Drop Shadow, Inner Glow, Outer Glow, Feather, Round Corners, Scribble, Offset Path, Outline Object, Outline Stroke, Convert to Shape, Tweak (only when it moves nothing), Pucker & Bloat at 0 or Bas Relief (read from its settings block: [raster effects reference](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/apply-filter-effects/raster-effects-reference.html), [layered image file format specification](https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/), [scripting the filter gallery](https://community.adobe.com/questions-712/scripting-supporLine truncated
|
||||
|
||||
A run of type in the editing data whose baseline direction is 1 opens with Standard Vertical Roman Alignment (https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html) on, which is VectorCraft's own mapping: its half-width characters stand upright in vertical type, and horizontal type keeps the mark with no change to its layout. A run whose baseline direction is 2 or 3 (Tate-chu-yoko), or that names none in the run, its character style or the document's defaults, opens with it off. The scripting reference lists 1, 2 and 3 as the Standard, vertical rotated and Tate-chu-yoko baseline directions (https://web.archive.org/web/20170621180804/https://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2015_3/Illustrator%20VBScript%20Reference.pdf, page 256).
|
||||
A Scatter brush in the editing data whose last 15 numbers start with 1 comes into the Brushes panel in Tints. A Scatter brush's art comes in turned over from its section, as an Art brush's does: in each copy the side of the section with y up goes down the page before the copy's rotation, and the writer writes the art back the same way. 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), closed, or open with its first corner again at the end. 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.
|
||||
|
||||
+34
-21
@@ -713,8 +713,8 @@ ends the wait, so the sampler can be shown again. The BSDs and headless sessions
|
||||
| `inspect_document` | `{depth?, childLimit?, ids?, kind?, limit?, offset?}` | Artboards (with `color`, `#rrggbb`, for one with a background color), layer tree (ids, kinds, bounds, paint), selection, history, tool. A type node's `fill`, `stroke` and `strokeWidth` are the paint its characters show (its first run's); fills and strokes of the type object itself come as `objectFill`, `objectStroke` and `objectStrokeWidth`. Paint comes as a label (`"#ff0000"`, `"None"`, `"G1 40% (#ff9999)"` for a swatch at a tint); `paint.proxies` gives it as an object. |
|
||||
| `inspect_ui` | `{}` | UI state. Remote mode only. |
|
||||
| `select_tool` | `{tool}` | `selection`, `directSelection`, `pen`, `rectangle`, `ellipse`, `polygon`, `star`, `lineSegment`, … |
|
||||
| `pointer_gesture` | `{events:[{kind,x,y,mods?,backquote?,pressure?,tiltX?,tiltY?,rotation?,holdMs?}], tool?, mods?, backquote?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`, `tripleclick` (`doubleclick` follows the second click's `up`, and `tripleclick` the third's). `backquote` is the held state for each event; the top-level value supplies its default, and a `backquote` that is not a boolean is an error. Events go through the same path as the mouse. Headless, a `move` replies after the tool's highlight under the pointer is ready, including the Shape Builder's and the Live Paint Bucket's regions of a large selection, which the desktop app finds off the UI thread and highlights after the reply. The release of a Shape Builder click or drag over such a selection replies once the merge is applied, headless and in the desktop app, which computes the merge off the UI thread. In the desktop app, a gesture sent before then is made after the merge, and its reply comes once it is made; a command that can edit, select, save or redraw the documents (a preference, the proof and separations views), sent before then, waits for the merge and runs after it. |
|
||||
| `pointer_gesture` | `{events:[{kind,x,y,mods?,backquote?,pressure?,tiltX?,tiltY?,rotation?,holdMs?}], tool?, mods?, backquote?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`, `tripleclick` (`doubleclick` follows the second click's `up`, and `tripleclick` the third's). `backquote` is the held state for each event; the top-level value supplies its default. Events go through the same path as the mouse. Headless, a `move` replies after the tool's highlight under the pointer is ready, including the Shape Builder's and the Live Paint Bucket's regions of a large selection, which the desktop app finds off the UI thread and highlights after the reply. Remote, the events wait until the keys and other input sent before them (`press_key`, `type_text`) have reached the app, so a key pressed between two calls of one drag applies before the release. When that input is dropped because the document, a dialog or the focus changed first, the call fails and its events are not sent. The release of a Shape Builder click or drag over such a selection replies once the merge is applied, headless and in the desktop app, which computes the merge off the UI thread. In the desktop app, a gesture sent before then is made after the merge, and its reply comes once it is made; a command that can edit, select, save or redraw the documents (a preference, the proof and separations views), sent before then, waits for the merge and runs after it. |
|
||||
| `pointer_gesture` | `{events:[{kind,x,y,mods?,backquote?,pressure?,tiltX?,tiltY?,rotation?,wheel?,holdMs?}], tool?, mods?, backquote?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`, `tripleclick` (`doubleclick` follows the second click's `up`, and `tripleclick` the third's). `backquote` is the held state for each event; the top-level value supplies its default, and a `backquote` that is not a boolean is an error. Events go through the same path as the mouse. Headless, a `move` replies after the tool's highlight under the pointer is ready, including the Shape Builder's and the Live Paint Bucket's regions of a large selection, which the desktop app finds off the UI thread and highlights after the reply. The release of a Shape Builder click or drag over such a selection replies once the merge is applied, headless and in the desktop app, which computes the merge off the UI thread. In the desktop app, a gesture sent before then is made after the merge, and its reply comes once it is made; a command that can edit, select, save or redraw the documents (a preference, the proof and separations views), sent before then, waits for the merge and runs after it. |
|
||||
| `pointer_gesture` | `{events:[{kind,x,y,mods?,backquote?,pressure?,tiltX?,tiltY?,rotation?,wheel?,holdMs?}], tool?, mods?, backquote?}` | `kind` is one of `down`, `drag`, `up`, `move`, `doubleclick`, `tripleclick` (`doubleclick` follows the second click's `up`, and `tripleclick` the third's). `backquote` is the held state for each event; the top-level value supplies its default. Events go through the same path as the mouse. Headless, a `move` replies after the tool's highlight under the pointer is ready, including the Shape Builder's and the Live Paint Bucket's regions of a large selection, which the desktop app finds off the UI thread and highlights after the reply. Remote, the events wait until the keys and other input sent before them (`press_key`, `type_text`) have reached the app, so a key pressed between two calls of one drag applies before the release. When that input is dropped because the document, a dialog or the focus changed first, the call fails and its events are not sent. The release of a Shape Builder click or drag over such a selection replies once the merge is applied, headless and in the desktop app, which computes the merge off the UI thread. In the desktop app, a gesture sent before then is made after the merge, and its reply comes once it is made; a command that can edit, select, save or redraw the documents (a preference, the proof and separations views), sent before then, waits for the merge and runs after it. |
|
||||
| `draw_path` | `{points \| d, closed?, fill?, stroke?, strokeWidth?, dash?, cap?, join?, opacity?, name?, effects?}` | `points` is `[[x,y],…]` or `[{x,y,in?,out?,smooth?},…]`. `d` is SVG path data. The options are below. |
|
||||
| `draw_shape` | `{shape, …geometry, fill?, stroke?, strokeWidth?, dash?, cap?, join?, opacity?, name?, effects?}` | `rectangle`/`ellipse`: `x,y,width,height` (plus `radius` for corners; an ellipse takes `anchors`, 2–1000, default 4). `polygon`: `cx,cy,radius,sides`. `star`: `cx,cy,radius1,radius2,points`. Polygons and stars take `rotation` in degrees clockwise (0: a corner or point straight up). `line`: `x1,y1,x2,y2`. |
|
||||
| `set_paint` | `{fill?, stroke?, strokeWidth?, ids?}` | Applies to the selection (or `ids`) and becomes the default for new art. Returns `{applied, objects}`: `objects` is the number of objects painted, as the `objects` of the `paint.setFill`, `paint.setStroke` and `stroke.set` replies (the largest of them): a selected group counts the objects inside it. When it is 0, a `note` says that only the paint for new art changed. |
|
||||
@@ -2002,7 +2002,7 @@ control channel's `ui.key`, `ui.move`, `ui.wheel`, `ui.click`, `ui.drag`, `ui.po
|
||||
`ui.render` and `ui.set` for their numbers, switches and `mods`, and the headless session's key, pointer and screenshot
|
||||
calls. Omitting a param or giving null keeps its default, with two exceptions: `ui.click`'s `count` and `ui.drag`'s
|
||||
`count` and `steps` refuse null, and a headless pointer event needs its `x` and `y`. A pointer event's `pressure`,
|
||||
`holdMs`, `tiltX`, `tiltY` and `rotation` must be numbers and its `space` must be `doc` or `screen`. A pointer packet
|
||||
`holdMs`, `tiltX`, `tiltY`, `rotation` and `wheel` must be numbers and its `space` must be `doc` or `screen`. A pointer packet
|
||||
with one malformed event sends none of its events:
|
||||
|
||||
```json
|
||||
@@ -3953,6 +3953,18 @@ already walks Image Trace. Short agent entry points:
|
||||
Tilt goes from its first value with the pen lying flat to its second upright, and on Bearing or Rotation from its
|
||||
first value at −180° to its second at 180°. A stroke without that input draws the brush's own value (a Scatter
|
||||
brush's value half way between the two).
|
||||
- Airbrush finger wheel: `path.freehand` and `brush.freehand` take a point's wheel seventh,
|
||||
`[x, y, pressure, tiltX, tiltY, rotation, wheel]`, or as `{…, wheel?}`, and a `pointer_gesture` event takes `wheel`,
|
||||
which the Paintbrush records. The wheel is 0..1 from one end of the wheel's travel to the other. In a point, a
|
||||
value outside it, or one that is neither a number nor null, is refused; a `pointer_gesture` event's wheel outside
|
||||
it is clamped, as its pressure is. The stroke keeps it as `wheel` (a point without
|
||||
one counts as half way). Calligraphic and Scatter `modes` and an Art brush's `width_mode` take `stylusWheel`: the
|
||||
value goes from the value less the variation (a Scatter brush's first value, an Art brush's `width`) at 0 to the
|
||||
value plus the variation (the second value, `width_max`) at 1, and a stroke without a wheel draws the value half
|
||||
way. Brush Options offers Stylus Wheel for a Calligraphic or Scatter brush's Size and an Art brush's Width. The
|
||||
desktop app reads the wheel from XInput2 (`Abs Wheel`) under X11 and from AppKit (`tangentialPressure`) on macOS;
|
||||
it does not read it on Windows or in the web build. `.ai` brush definitions read and write the wheel as variation
|
||||
code 3.
|
||||
- Freehand Fidelity: the `fidelity` of `path.freehand` and `brush.freehand` is in points, 1.5 pt when left out. A
|
||||
value must be from 0.000015625 pt (0.01 / 640) to 100 / 0.0313 pt (about 3194.89 pt), and a value outside that range
|
||||
is rejected with an error. The Pencil and the Paintbrush give Fidelity in screen pixels, 0.01 to 100 px, and send it
|
||||
@@ -6255,7 +6267,7 @@ objects differ) and `recentUrls`. `attributes.set {overprintFill?, overprintStro
|
||||
note?, ids?}` sets them in one undo step; `path.setFillRule {rule: "nonZero"|"evenOdd"}` sets the fill rule of the
|
||||
paths and compound paths, and `path.reverse {reversed?}` makes subpaths run counter-clockwise (true) or clockwise
|
||||
(false). When every subpath of a path or compound path turns alike, its strokes' width profiles (left and right swapped) and pen
|
||||
pressure, tilt, bearing and rotation turn with it, so the strokes draw as before. SVG export wraps an object with a URL in `<a xlink:href>`, and SVG import reads `<a href>` links back.
|
||||
pressure, tilt, bearing, rotation and wheel turn with it, so the strokes draw as before. SVG export wraps an object with a URL in `<a xlink:href>`, and SVG import reads `<a href>` links back.
|
||||
|
||||
`recentUrls` keeps the 30 newest distinct URLs given in the session, newest first. The panel's URL menu lists the
|
||||
first 10 of them by default; the panel menu's Panel Options… opens the `attributesPanelOptions` dialog (field `count`),
|
||||
@@ -6502,16 +6514,16 @@ focal points stay highlighted where it left them; Escape during a drag puts the
|
||||
switching to another tool clears them.
|
||||
|
||||
`path.freehand`, `brush.freehand`, `path.knife`, `path.eraseRegion`, `path.eraseSegments`, `path.smoothRegion`,
|
||||
`path.joinScrub` and `path.blob` refuse a pen `pressure` outside 0 to 1, a `tiltX` or `tiltY` outside -90 to 90 and a
|
||||
`rotation` outside 0 to 360 with an error such as `` `tiltX` must be from -90 to 90 ``, naming the key, and a point
|
||||
given as an array of more than six numbers with `` `points[3]` must be an array of at most 6 entries ``, naming the
|
||||
point. `path.blob` and `path.eraseRegion` refuse a `size` outside 0.1 to 1000 pt with
|
||||
`path.joinScrub` and `path.blob` refuse a pen `pressure` outside 0 to 1, a `tiltX` or `tiltY` outside -90 to 90, a
|
||||
`rotation` outside 0 to 360 and a stylus `wheel` outside 0 to 1 with an error such as
|
||||
`` `tiltX` must be from -90 to 90 ``, naming the key, and a point given as an array of more than seven numbers with
|
||||
`` `points[3]` must be an array of at most 7 entries ``, naming the point. `path.blob` and `path.eraseRegion` refuse a `size` outside 0.1 to 1000 pt with
|
||||
`` `size` must be from 0.1 to 1000 `` and a `sizeVariation` over 1000 pt with
|
||||
`` `sizeVariation` must be from 0 to 1000 ``, in every `sizeMode` and when it is left out. `path.blob` refuses a
|
||||
negative `sizeVariation` with the same message, and `path.eraseRegion` with "sizeVariation must be 0 or more". The
|
||||
document and the selection do not change and no undo step is recorded. A null is read as a key left out, and a point given as `[x, y]`
|
||||
has no pen values. The pressure and tilt ranges are those of
|
||||
[Pointer Events](https://www.w3.org/TR/pointerevents3/); the rotation, size and size variation ranges are
|
||||
[Pointer Events](https://www.w3.org/TR/pointerevents3/); the rotation, wheel, size and size variation ranges are
|
||||
VectorCraft's own values.
|
||||
|
||||
`path.eraseRegion` (the Eraser) takes a variation mode for each of its tip's values, as the variation menus of
|
||||
@@ -6519,13 +6531,14 @@ Eraser Tool Options set them ([Erase paths using the Eraser
|
||||
tool](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-paths/erase-paths-using-eraser-tool.html)):
|
||||
`angleMode` with `angleVariation` (degrees, 0 to 180), `roundnessMode` with `roundnessVariation` (percent, 0 to 100)
|
||||
and `sizeMode` with `sizeVariation` (points, 0 to 1000), each `"fixed"` (the default), `"random"`, `"pressure"`,
|
||||
`"tilt"`, `"bearing"` or `"rotation"`. A value that varies takes up to its variation either way. Random draws one
|
||||
value for the drag. Pressure goes from the value less the variation where the pen presses lightest to the value plus
|
||||
it where the pen presses hardest. Tilt goes from less with the pen lying flat to more with it upright. Bearing and
|
||||
Rotation go from less at −180° to more at 180° of the way the pen leans or its barrel turns. The tip at each point of
|
||||
the drag takes what the pen read there (the points' pressure, tilt and rotation, as `path.freehand` takes them); a
|
||||
drag without that reading, such as a mouse drag, erases at the value itself. One Random value per drag, which way
|
||||
Tilt, Bearing and Rotation run, and the value itself without a reading are VectorCraft's own rules.
|
||||
`"tilt"`, `"bearing"`, `"rotation"` or `"stylusWheel"`. A value that varies takes up to its variation either way.
|
||||
Random draws one value for the drag. Pressure goes from the value less the variation where the pen presses lightest to
|
||||
the value plus it where the pen presses hardest. Tilt goes from less with the pen lying flat to more with it upright.
|
||||
Bearing and Rotation go from less at −180° to more at 180° of the way the pen leans or its barrel turns. Stylus Wheel
|
||||
goes from less at 0 to more at 1 of an airbrush pen's finger wheel. The tip at each point of the drag takes what the
|
||||
pen read there (the points' pressure, tilt, rotation and wheel, as `path.freehand` takes them); a drag without that
|
||||
reading, such as a mouse drag, erases at the value itself. One Random value per drag, which way Tilt, Bearing,
|
||||
Rotation and Stylus Wheel run, and the value itself without a reading are VectorCraft's own rules.
|
||||
The command refuses another mode, and a variation below 0 or past its range, and erases nothing. In the desktop app
|
||||
the Eraser's tip outline at the pointer takes the angle, roundness and size the pen gives while it erases, and the
|
||||
outline of the area a drag covers takes, at each step, the tip the pen's readings give halfway along it. A Random
|
||||
@@ -6553,9 +6566,9 @@ and `dx`, `dy`, `tol` and `radius` in `path.reshape`. A null is read as a key le
|
||||
an `x` without a `y`, or a `y` without an `x`, with "x and y must be given together". `path.freehand`,
|
||||
`path.curvature`, `path.knife`, `path.eraseRegion`, `path.eraseSegments`, `path.smoothRegion`, `path.joinScrub` and
|
||||
`path.blob` refuse a point in `points` whose x or y is not a number, such as `["10", 10]` or a point written as a
|
||||
string, with "x and y must both be numbers". All of them except `path.curvature` refuse a pen pressure, tilt or
|
||||
rotation that is neither a number nor null with `` `pressure` must be a number, not "0.5" ``, naming the key
|
||||
(`pressure`, `tiltX`, `tiltY` or `rotation`). `path.close` refuses an `at`, `in` or `out` that is not `[x, y]`
|
||||
string, with "x and y must both be numbers". All of them except `path.curvature` refuse a pen pressure, tilt,
|
||||
rotation or wheel that is neither a number nor null with `` `pressure` must be a number, not "0.5" ``, naming the key
|
||||
(`pressure`, `tiltX`, `tiltY`, `rotation` or `wheel`). `path.close` refuses an `at`, `in` or `out` that is not `[x, y]`
|
||||
with `` `in` must be [x, y] ``, naming the key.
|
||||
|
||||
`path.eraseRegion` refuses an `angle` outside -180° to 180° with `` `angle` must be from -180 to 180 degrees `` and a
|
||||
@@ -12981,8 +12994,8 @@ step, and `press_key` Escape or a switch to another tool during it puts the valu
|
||||
|
||||
How blends interpolate: closed shapes start where they twist least unless `starts` picks the anchors; strokes
|
||||
interpolate weight, dashes (a solid stroke counts as the dashed one with its gaps closed), miter limit, arrowhead scale,
|
||||
width profiles and the pen pressure, tilt, bearing and rotation recorded with the Paintbrush (a stroke without a
|
||||
recording counts as half pressure, half tilt and 0°, as brushes read it; angles turn the shorter way round; a key's
|
||||
width profiles and the pen pressure, tilt, bearing, rotation and wheel recorded with the Paintbrush (a stroke without
|
||||
a recording counts as half pressure, half tilt, 0° and the wheel half way, as brushes read it; angles turn the shorter way round; a key's
|
||||
profiles, recordings, arrowheads, dashes and gradient along or across the stroke turn with its path when the blend
|
||||
starts it at another anchor), while caps, joins, alignment, arrowheads and brushes switch halfway; gradients of one
|
||||
kind with different stop counts resample to a common set of stops, keeping each step (two stops at one offset). Groups pair their members in stacking order (members only
|
||||
|
||||
@@ -1948,14 +1948,15 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
With a gradient stop or a freeform gradient point selected, Alt-clicking a color swatch in the Swatches panel recolors it instead of the inactive Fill or Stroke.
|
||||
- **Freeform gradient colors in their own model:** Object ▸ Expand and Object ▸ Create Gradient Mesh (`object.mesh.create`) mix a freeform gradient's points in the color model they share: points of C50 M20 Y0 K10 give mesh points of C50 M20 Y0 K10, and RGB points keep their values in a working RGB space other than sRGB. The canvas, the gradient chips and the SVG, PDF, EPS and EMF writers mix the points in that model too. PDF and EPS write a gradient whose points are all CMYK, or all Gray in a CMYK file, as a CMYK image, which PDF's Output settings convert as they convert any CMYK image. Points in different models mix in display RGB (on the canvas in a CMYK document that shows transparency, as the inks of each point), and a CMYK document stores the result of Expand as CMYK through the color settings. Points colored along CMYK stops (`paint.editGradient {stops}`, or a CMYK gradient switched to freeform) are CMYK, and so are a point `paint.freeform.splitLine` adds between CMYK points and a point `paint.freeform.addPoint` adds without `color` to CMYK points. Public reference: [Gradients](https://web.archive.org/web/20250714042311/https://helpx.adobe.com/illustrator/using/gradients.html) and [Meshes](https://web.archive.org/web/20250812201019/https://helpx.adobe.com/illustrator/using/meshes.html), which do not state how colors in different models mix; the rule is VectorCraft's own.
|
||||
- **Strokes:** one stroke-geometry module shared by the canvas, SVG, PDF and Outline Stroke; dotted lines (zero-length dashes draw dots or squares); arrowheads with hollow outlines, tip-on-end or extend-past-end alignment and one opacity for line and head. SVG and PDF export arrowheads, width profiles, brushes and aligned strokes exactly as the canvas draws them; Outline Stroke and the live Outline Stroke effect outline every stroke item as drawn (dashes, heads, profiles, alignment); dashes can be fitted to corners and path ends; width profiles carry through dashes, and their corners take the join. The Stroke panel edits type's character strokes, follows the stroke units (its weight presets are round values in that unit: `0.25 mm`, `0.0625 in`, `1 px`, #426; fields show four decimals in mm, cm and inches, three in points), shows mixed values blank and opens from the Control bar. A width profile library, thirty-one more arrowheads (among them Line Arrow: two arms of the head's weight (stroke weight × arrowhead scale, at least 0.25 pt: the line's weight at 100 % for lines of 0.25 pt or more) at right angles, cut square, #5421), and Width Point Edit with multi-select and discontinuous points. Visual bounds and clicks cover the whole painted stroke. Scale Strokes & Effects, Scale Corners and Use Preview Bounds work everywhere, and new art inherits stroke options, a graphic style or the whole last appearance. A width profile's sides run as a smooth C1 curve between the width points (a monotone cubic Hermite, Fritsch–Carlson, with the one-sided three-point PCHIP slope at the profile's ends and flat either side of a step), sampled adaptively along the path (two samples per profile segment, refined where the width bends, and leaning on dense path flattening) so straight runs draw it too; added samples offset along the source curve's exact tangent, not the flattened chord, so high zoom follows the true width; the sampled edges are fitted with G1 cubics within a tenth of the flattening tolerance (0.001 pt at the default 0.01 pt) rather than one cubic per flatten step, so exports stay close to a uniform stroke's path data; a point reshapes the curve as far as its neighbours' neighbours (their slopes depend on it), and coincident points still step.
|
||||
- **Brushes (part of #852):** double-clicking a brush in the Brushes panel (or the panel menu's Brush Options…) opens Calligraphic Brush Options (Name; Angle, Roundness and Size, each Fixed, Random, Pressure, Tilt, Bearing or Rotation with its Variation; live previews of the nib and of a light–heavy–light stroke) or Bristle Brush Options (Shape and the bristle sliders); OK edits the brush and every stroke painted with it. The Paintbrush records the pen pressure along each stroke (kept with the path, saved, and joined when a stroke continues a path); a Calligraphic value on Pressure goes from value − variation at the lightest pressure to value + variation at the heaviest, on the canvas and in SVG, PDF and the other exports. Brushes saved before keep their look. Scatter Brush Options (Size, Spacing, Scatter and Rotation, each Fixed, Random between two values, Pressure from the first at the lightest pressure to the second at the heaviest, Tilt, Bearing or Rotation; Rotation relative to Page or Path), Art Brush Options (Width, Scale Proportionately, Stretch to Fit Stroke Length or Stretch Between Guides with the guides' start and end, the four Directions, Flip Along and Across, Overlap) and Pattern Brush Options (Scale, Spacing, the five tiles shown, Flip Along and Across, Stretch to fit, Add space to fit or Approximate path) each have Colorization (None, Tints, Tints and Shades, Hue Shift with its Key Color picked from the art's colours) and a live stroke preview; values from files and commands are clamped to their ranges. Art Brush Options › Overlap places art on each run between sharp corners so folds do not overlap (`ArtBrush.overlap`; `art_brush_overlap_splits_at_corners`). Still to come: Stylus Wheel, pen pressure on macOS where the windowing layer reports none, and tilt, bearing and rotation for Pattern and Bristle brushes and on native Wayland and the web.
|
||||
- **Brushes (part of #852):** double-clicking a brush in the Brushes panel (or the panel menu's Brush Options…) opens Calligraphic Brush Options (Name; Angle, Roundness and Size, each Fixed, Random, Pressure, Tilt, Bearing or Rotation with its Variation; live previews of the nib and of a light–heavy–light stroke) or Bristle Brush Options (Shape and the bristle sliders); OK edits the brush and every stroke painted with it. The Paintbrush records the pen pressure along each stroke (kept with the path, saved, and joined when a stroke continues a path); a Calligraphic value on Pressure goes from value − variation at the lightest pressure to value + variation at the heaviest, on the canvas and in SVG, PDF and the other exports. Brushes saved before keep their look. Scatter Brush Options (Size, Spacing, Scatter and Rotation, each Fixed, Random between two values, Pressure from the first at the lightest pressure to the second at the heaviest, Tilt, Bearing or Rotation; Rotation relative to Page or Path), Art Brush Options (Width, Scale Proportionately, Stretch to Fit Stroke Length or Stretch Between Guides with the guides' start and end, the four Directions, Flip Along and Across, Overlap) and Pattern Brush Options (Scale, Spacing, the five tiles shown, Flip Along and Across, Stretch to fit, Add space to fit or Approximate path) each have Colorization (None, Tints, Tints and Shades, Hue Shift with its Key Color picked from the art's colours) and a live stroke preview; values from files and commands are clamped to their ranges. Art Brush Options › Overlap places art on each run between sharp corners so folds do not overlap (`ArtBrush.overlap`; `art_brush_overlap_splits_at_corners`). Still to come: Stylus Wheel for Pattern brushes and on Windows and the web, pen pressure on macOS where the windowing layer reports none, and tilt, bearing and rotation for Pattern and Bristle brushes and on native Wayland and the web.
|
||||
Under Tints and Tints and Shades, art in black ink alone goes by its ink amount, and a process or gray stroke color's tints and shades stay in that color's model; these are VectorCraft's own rules.
|
||||
Scale Proportionately art is scaled across by the stroke weight and the Width, as Stretch to Fit Stroke Length and Stretch Between Guides art is, on top of the scale the path length gives it, so a 3 pt stroke draws the art three times as wide as a 1 pt stroke. The [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page says Scale Proportionately keeps the art's proportions and does not say how the stroke weight applies; that rule is VectorCraft's own. Evidence: `tests::art_brush_proportional_grows_with_weight` (vectorcraft-brush).
|
||||
Type in a scatter brush's art takes the brush's colorization as its paths do: Tints, Tints and Shades and Hue Shift recolor the characters' solid fills and strokes in each copy the brush draws, and Brush Options' Key Color list, whose first color is Hue Shift's default key, counts the characters' fills and their strokes wider than 0. The Brushes page says that a scatter, art or pattern brush takes its colors from the current stroke color and the brush's colorization method (<https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html>) and does not mention type there; recoloring the characters' paints like the art's fills and strokes is VectorCraft's own rule. The Symbol Stainer mixes the characters' strokes of type toward the stain as it mixes their fills. Evidence: `tests::scatter_colorization_recolors_type`, `tests::art_colors_list_the_most_used_first`, `tests::stain_mixes_type_strokes_too` (vectorcraft-brush).
|
||||
Scatter Brush Options has Hue Jitter (0° to 180°, 0 by default), VectorCraft's own option: each copy turns the hue of its solid colors, after the colorization, by its own amount up to that far either way. The stroke's path and the brush name fix the amounts, so a stroke draws the same colors every time, and the copies' places, sizes and rotations stay as they are without it. Evidence: `tests::hue_jitter_turns_each_copy_the_same_every_time`, `tests::hue_jitter_of_zero_changes_nothing`, `tests::hue_jitter_turns_after_the_colorization` (vectorcraft-brush), `tests::brushsym::scatter_hue_jitter_saves_and_exports` (vectorcraft-engine).
|
||||
- **Pen tilt, bearing and rotation (part of #764):** Calligraphic and Scatter Brush Options offer Tilt, Bearing and Rotation beside Fixed, Random and Pressure. The Paintbrush records along each stroke how far the pen leans, which way, and how far its barrel is turned (kept with the path, saved, and joined when a stroke continues a path). A Calligraphic value on Tilt goes from value − variation with the pen lying flat to value + variation upright; on Bearing or Rotation it adds variation × the angle over 180°, so Angle on Bearing with a Variation of 180° turns the nib with the way the pen leans. A Scatter value goes from its first value to its second over the same ranges. A stroke without that input draws the brush's own value. On Linux under X11 and XWayland the app reads the tilt and an Art Pen's barrel rotation from XInput2, on macOS it reads them from AppKit's tablet events, and `path.freehand` points and `pointer_gesture` events carry them on every platform. The [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page defines the three options and does not say which way each one runs; that mapping is VectorCraft's own rule. Evidence: `tests::tilt_maps_to_roundness_along_the_stroke`, `tests::bearing_and_rotation_turn_the_nib`, `tests::scatter_values_follow_tilt_and_bearing` (vectorcraft-brush), `tests_brushsym::paintbrush_records_the_pens_tilt_on_the_stroke` (vectorcraft-engine), `tablet::tests::a_pens_tilt_and_rotation_go_into_the_feed` and `mac_tablet::tests::a_pens_tilt_and_rotation_go_into_the_feed` (vectorcraft).
|
||||
Art Brush Options' Width (1% to 1000%) and Pattern Brush Options' Scale (1% to 10000%) each have a slider beside the field, over the same range in whole percents; screen readers name the slider as its row and read the field's value.
|
||||
Art Brush Options' Width has a Fixed or Pressure menu, from the pen tablet options of the Width pop-up menu on the [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page (archived copy). With Pressure, the art is Width wide at the lightest pen pressure and the second width at the heaviest, following the pressure the Paintbrush recorded along the stroke, and half way between them on a stroke without recorded pressure (`brush.options` `width_mode` and `width_max`); a stroke inside the art takes the width at the middle of its object. The page does not say how the pressure maps to the width; taking the Scatter brush's minimum and maximum rule and the stroke rule are VectorCraft's own. The menu also offers Tilt, Bearing and Rotation: the art goes from Width with the pen lying flat to the second width upright, and from Width at −180° to the second width at 180° of the pen's bearing or barrel rotation, as Scatter Brush Options' modes do, and half way on a stroke without that input; the page does not say which way each runs, so that mapping is VectorCraft's own. Evidence: `tests::art_brush_width_follows_tilt_bearing_and_rotation` (vectorcraft-brush). Stylus Wheel is not built.
|
||||
Art Brush Options' Width has a Fixed or Pressure menu, from the pen tablet options of the Width pop-up menu on the [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page (archived copy). With Pressure, the art is Width wide at the lightest pen pressure and the second width at the heaviest, following the pressure the Paintbrush recorded along the stroke, and half way between them on a stroke without recorded pressure (`brush.options` `width_mode` and `width_max`); a stroke inside the art takes the width at the middle of its object. The page does not say how the pressure maps to the width; taking the Scatter brush's minimum and maximum rule and the stroke rule are VectorCraft's own. The menu also offers Tilt, Bearing and Rotation: the art goes from Width with the pen lying flat to the second width upright, and from Width at −180° to the second width at 180° of the pen's bearing or barrel rotation, as Scatter Brush Options' modes do, and half way on a stroke without that input; the page does not say which way each runs, so that mapping is VectorCraft's own. Evidence: `tests::art_brush_width_follows_tilt_bearing_and_rotation` (vectorcraft-brush). The menu also offers Stylus Wheel (next item).
|
||||
- **Airbrush stylus wheel:** Calligraphic and Scatter Brush Options offer Stylus Wheel for Size, and Art Brush Options for Width, as the help page lists it (<https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html>). The Paintbrush records where an airbrush pen's finger wheel is set along each stroke (kept with the path, saved, joined when a stroke continues a path, and interpolated by blends). A Calligraphic Size goes from size − variation at one end of the wheel's travel to size + variation at the other, a Scatter Size from its first value to its second, and an Art Width from Width to the second width; a stroke without a wheel draws the value half way. The direction of travel and the half-way value for a stroke without a wheel are VectorCraft's own rules. On Linux under X11 and XWayland the app reads the wheel from XInput2's `Abs Wheel` valuator, and on macOS from AppKit's `tangentialPressure`; Windows pointer messages have no field for it, and the web build does not read it yet. `path.freehand` points take it seventh and `pointer_gesture` events take `wheel`, and `.ai` brush definitions read and write it as variation code 3. Evidence: `tests::the_stylus_wheel_varies_sizes_and_widths` (vectorcraft-brush), `tests_brushsym::freehand_points_record_the_stylus_wheel` (vectorcraft-engine), `more_brush_settings_are_read_back` and `a_calligraphic_brushs_pen_channels_come_in_by_their_codes` (vectorcraft-eps), `tablet::tests::an_airbrush_wheel_goes_into_the_feed` and `mac_tablet::tests::an_airbrush_wheel_goes_into_the_feed` (vectorcraft).
|
||||
Scatter, Art and Pattern Brush Options have the Tips button for Colorization that the [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page (archived copy) describes, beside Method. It opens Colorization Tips, which shows each method's name and what it does beside a sample of the brush, as OK would make it, painted with that method on a blue stroke; Hue Shift's sample uses the dialog's Key Color. `ui.dialog.set {field: "tips", value: true}` opens it. Screen readers name the button, the popover and each sample.
|
||||
Hue Shift set by `brush.new` or `brush.options` without a key color takes the color the art's fills and strokes use most, as Brush Options already offers it, following the Brushes page, where the key color defaults to the color that stands out most in the art (<https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html>). The page does not state how prominence is measured. Counting the fills and strokes that use each solid color, with the first one found winning a tie and black for art with no solid color, is VectorCraft's own rule. A `brush.options` edit that gives only the method keeps the brush's key color, and one that gives only an art brush's start guide keeps its end guide. Evidence: `tests_brushsym::hue_shift_without_a_key_takes_the_most_used_art_color`, `tests_brushsym::art_brush_options_keep_the_scale_fields_an_edit_leaves_out`.
|
||||
Bristle Brush Options and `brush.new` take a bristle brush name of at most 31 characters, as the Brushes page states for the Bristle Brush Options. The Name field stops taking characters at 31, and `brush.new` and `brush.options` refuse a longer new name with an error that names the limit. The page does not say how the limit counts characters or what happens to longer names already saved; counting characters and the number added to a taken name, keeping longer saved names, and leaving `brush.duplicate` unlimited are VectorCraft's own rules. A bristle brush that a document or a saved file already holds under a longer name keeps it, and the other brush types take a name of any length. Test: `bristle_brush_names_have_at_most_31_characters` in `tests/brushsym.rs`. Public reference: [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) (archived copy).
|
||||
|
||||
Reference in new issue
Block a user