mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 08:26:28 +00:00
Merge pull request #8080 from dotCooCoo/perf/curved-stroke-edges
Render: wide curved strokes draw their rims closer to the curves
This commit is contained in:
@@ -142,12 +142,15 @@ impl Renderer {
|
||||
}
|
||||
// One paint box for the line and the heads, so a gradient runs on into the heads.
|
||||
let paint_bounds = bounds.inflate(st.width / 2.0, st.width / 2.0);
|
||||
// A width profile's outline is fitted through samples, and fitted again differently when
|
||||
// it is outlined near the view only: its curves are drawn as they are.
|
||||
let fine = st.profile.is_none() && crate::stroke::fine(f.view * xf, f.px);
|
||||
if let Some(g) = st.path_gradient() {
|
||||
self.fill_path_gradient(ctx, f, bp, rule, st, chars, &pieces, width, &g.gradient);
|
||||
self.fill_path_gradient(ctx, f, bp, rule, st, chars, &pieces, width, fine, &g.gradient);
|
||||
} else {
|
||||
let line = match self.cached_stroke(f, chars, bp, &pieces.line, st, width) {
|
||||
let line = match self.cached_stroke(f, chars, bp, &pieces.line, st, width, fine) {
|
||||
Some(o) => o,
|
||||
None => Arc::new(crate::stroke::outline(&pieces.line, st, width, f.px * 0.25)),
|
||||
None => Arc::new(uncached_outline(&pieces.line, st, width, f.px * 0.25, fine)),
|
||||
};
|
||||
// Miters, caps and heads can reach past the paint box: a paint drawn as pixels covers
|
||||
// them too.
|
||||
@@ -191,7 +194,8 @@ impl Renderer {
|
||||
/// piece clips the slices, grown a pixel into each other and each replacing what it covers, so
|
||||
/// neighbours meet without seams and translucent colours paint once. The slices of a stroke
|
||||
/// of `self.cur` are kept in `stroke_slices`, and a moved copy of the object draws the slices
|
||||
/// made before it moved, moved by the same offset ([`Self::moved_slices`]).
|
||||
/// made before it moved, moved by the same offset ([`Self::moved_slices`]). `fine` is passed on
|
||||
/// to [`Self::cached_stroke`].
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn fill_path_gradient(
|
||||
&mut self,
|
||||
@@ -203,6 +207,7 @@ impl Renderer {
|
||||
chars: Option<(&Arc<TextGeom>, usize)>,
|
||||
pieces: &effects::stroke::StrokePieces,
|
||||
width: f64,
|
||||
fine: bool,
|
||||
g: &vectorcraft_color::Gradient,
|
||||
) {
|
||||
let level = (f.px * 0.25).log2().floor() as i32;
|
||||
@@ -255,9 +260,9 @@ impl Renderer {
|
||||
}
|
||||
None => (make(), kurbo::Vec2::ZERO),
|
||||
};
|
||||
let line = match self.cached_stroke(f, chars, bp, &pieces.line, st, width) {
|
||||
let line = match self.cached_stroke(f, chars, bp, &pieces.line, st, width, fine) {
|
||||
Some(o) => o,
|
||||
None => Arc::new(crate::stroke::outline(&pieces.line, st, width, f.px * 0.25)),
|
||||
None => Arc::new(uncached_outline(&pieces.line, st, width, f.px * 0.25, fine)),
|
||||
};
|
||||
ctx.set_fill_rule(peniko::Fill::NonZero);
|
||||
for clip in std::iter::once(&*line).chain(pieces.heads.iter().map(|h| &h.outline)) {
|
||||
@@ -293,6 +298,9 @@ impl Renderer {
|
||||
/// tolerance (vello's 0.25 device px) is bucketed to powers of two, never coarser than needed,
|
||||
/// so zooming reuses outlines until the level changes. Other strokes aren't cached: for them
|
||||
/// this returns `None`. `line` is the line of `st` along `path` ([`effects::stroke::stroke_pieces`]).
|
||||
/// With `fine` ([`crate::stroke::fine`]) a wide stroke's long curves are drawn as lines
|
||||
/// ([`crate::stroke::wide`]); the keys keep the two kinds of outline apart.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn cached_stroke(
|
||||
&mut self,
|
||||
f: &Frame,
|
||||
@@ -301,11 +309,16 @@ impl Renderer {
|
||||
line: &BezPath,
|
||||
st: &StrokeLayer,
|
||||
width: f64,
|
||||
fine: bool,
|
||||
) -> Option<Arc<BezPath>> {
|
||||
let level = (f.px * 0.25).log2().floor() as i32;
|
||||
let expand = || Arc::new(crate::stroke::outline(line, st, width, 2f64.powi(level)));
|
||||
let tol = 2f64.powi(level);
|
||||
// The keys' last field: the tolerance level, and whether long curves are drawn as lines.
|
||||
let slot = level.saturating_mul(2).saturating_add(i32::from(fine));
|
||||
let refined = |outline: BezPath| if fine { crate::stroke::wide(outline, width, tol) } else { outline };
|
||||
let expand = || Arc::new(refined(crate::stroke::outline(line, st, width, tol)));
|
||||
if let Some((g, run)) = chars {
|
||||
let key = (self.stroke_owner(Arc::as_ptr(g) as usize), run, width.to_bits(), level);
|
||||
let key = (self.stroke_owner(Arc::as_ptr(g) as usize), run, width.to_bits(), slot);
|
||||
if let Some((kept, outline)) = self.char_strokes.get(&key, self.stamp)
|
||||
&& Arc::ptr_eq(kept, g)
|
||||
{
|
||||
@@ -316,7 +329,7 @@ impl Renderer {
|
||||
return Some(outline);
|
||||
}
|
||||
let node = self.cur.clone().filter(|n| owns_stroke(n, st))?;
|
||||
let key = (self.stroke_owner(Arc::as_ptr(&node) as usize), st as *const StrokeLayer as usize, width.to_bits(), level);
|
||||
let key = (self.stroke_owner(Arc::as_ptr(&node) as usize), st as *const StrokeLayer as usize, width.to_bits(), slot);
|
||||
let v = f.visible;
|
||||
let holds = |crop: Option<Rect>| crop.is_none_or(|r| r.x0 <= v.x0 && r.y0 <= v.y0 && r.x1 >= v.x1 && r.y1 >= v.y1);
|
||||
if let Some(e) = self.strokes.get_mut(&key)
|
||||
@@ -329,7 +342,7 @@ impl Renderer {
|
||||
// Under its object's id, the stroke's place and the outline's width and tolerance, the key
|
||||
// of the stroke's latest outline is kept, except for art made again in every frame.
|
||||
let place = node.appearance.items.iter().position(|i| matches!(i, AppearanceItem::Stroke(s) if std::ptr::eq(s, st)));
|
||||
let moved = place.filter(|_| !self.made_again).map(|place| (node.id.0, place, width.to_bits(), level));
|
||||
let moved = place.filter(|_| !self.made_again).map(|place| (node.id.0, place, width.to_bits(), slot));
|
||||
let own = moved.is_some() && self.own_path(&node, path);
|
||||
if let Some(mk) = moved
|
||||
&& let Some((outline, crop)) = self.moved_outline(mk, &node, st, line, v)
|
||||
@@ -342,7 +355,6 @@ impl Renderer {
|
||||
// A long stroke is outlined only in and around the view, with a margin of the view's
|
||||
// own size on each side. Width profiles keep their positions on the whole path.
|
||||
let region = v.inflate(v.width(), v.height());
|
||||
let tol = 2f64.powi(level);
|
||||
if crops()
|
||||
&& line.elements().len() > CROP_ELEMENTS
|
||||
&& st.dash.is_none()
|
||||
@@ -364,7 +376,7 @@ impl Renderer {
|
||||
&& st.profile.is_none()
|
||||
&& let Some(outline) = crop_dashed(line, st, width, region, crop_reach(st, width, f.px, tol), tol)
|
||||
{
|
||||
let outline = Arc::new(outline);
|
||||
let outline = Arc::new(refined(outline));
|
||||
self.keep_stroke(key, StrokeEntry { node, outline: outline.clone(), stamp: self.stamp, crop: Some(region), own }, moved);
|
||||
return Some(outline);
|
||||
}
|
||||
@@ -372,7 +384,7 @@ impl Renderer {
|
||||
.then(|| crop_line(line, region, crop_reach(st, width, f.px, tol), width))
|
||||
.flatten();
|
||||
let (outline, crop) = match cropped {
|
||||
Some(part) => (Arc::new(crate::stroke::outline(&part, st, width, tol)), Some(region)),
|
||||
Some(part) => (Arc::new(refined(crate::stroke::outline(&part, st, width, tol))), Some(region)),
|
||||
None => (expand(), None),
|
||||
};
|
||||
self.keep_stroke(key, StrokeEntry { node, outline: outline.clone(), stamp: self.stamp, crop, own }, moved);
|
||||
@@ -619,6 +631,14 @@ fn crops() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// The outline of the line `line` of stroke `st` at `width` and tolerance `tol`, for a stroke that
|
||||
/// [`Renderer::cached_stroke`] does not keep; with `fine`, its long curves drawn as lines
|
||||
/// ([`crate::stroke::wide`]).
|
||||
fn uncached_outline(line: &BezPath, st: &StrokeLayer, width: f64, tol: f64, fine: bool) -> BezPath {
|
||||
let outline = crate::stroke::outline(line, st, width, tol);
|
||||
if fine { crate::stroke::wide(outline, width, tol) } else { outline }
|
||||
}
|
||||
|
||||
/// How far stroke `st` at `width` can paint from its path, at a join or a cap, with two output
|
||||
/// pixels (`px`) and the outline's tolerance `tol` added.
|
||||
pub(crate) fn crop_reach(st: &StrokeLayer, width: f64, px: f64, tol: f64) -> f64 {
|
||||
|
||||
+303
-1
@@ -1,6 +1,8 @@
|
||||
//! Raster-only stroke fitting: preserve thin curved bands through fill flattening.
|
||||
//! Raster-only stroke fitting: preserve thin curved bands through fill flattening, and draw the
|
||||
//! rims of wide curved strokes as lines centered on their curves.
|
||||
|
||||
use crate::effects;
|
||||
use crate::kurbo::{Affine, CubicBez, Line, ParamCurve, ParamCurveDeriv, PathEl, PathSeg, Point, QuadBez, Vec2};
|
||||
use vectorcraft_doc::StrokeLayer;
|
||||
use vectorcraft_geom::BezPath;
|
||||
|
||||
@@ -19,3 +21,303 @@ pub(crate) fn outline(line: &BezPath, st: &StrokeLayer, width: f64, tol: f64) ->
|
||||
vectorcraft_geom::flatten(outline.iter(), fine, |el| flat.push(el));
|
||||
flat
|
||||
}
|
||||
|
||||
/// Strokes at least this many tolerances wide (8 device pixels at a tolerance of 0.25 px) have
|
||||
/// their long curves drawn as lines by [`wide`].
|
||||
const WIDE: f64 = 32.0;
|
||||
/// A curve of a wide stroke's outline is drawn as lines when its control points span at least this
|
||||
/// many tolerances (32 device pixels at 0.25 px) across or down.
|
||||
const SPAN: f64 = 128.0;
|
||||
/// The chords [`wide`] draws a curve with lie within about this many tolerances of it, before
|
||||
/// their ends are moved out.
|
||||
const CHORD: f64 = 0.8;
|
||||
/// The most lines [`wide`] draws one outline's curves with. An outline that would take more is
|
||||
/// drawn as it is.
|
||||
const MAX_LINES: usize = 1 << 20;
|
||||
/// Two curves meet smoothly when the sine of the angle between their tangents where they meet is
|
||||
/// at most this.
|
||||
const SMOOTH: f64 = 0.01;
|
||||
|
||||
/// Whether an outline made in the space `m` maps to device pixels, with a tolerance of at most a
|
||||
/// quarter of `px` (the size of a device pixel in that space, [`crate::frame::Frame::px`]), stays
|
||||
/// within that tolerance on the device: whether `m` stretches no length by more than `1 / px`.
|
||||
/// `false` for a transform that collapses or isn't finite.
|
||||
pub(crate) fn fine(m: Affine, px: f64) -> bool {
|
||||
let [a, b, c, d, _, _] = m.as_coeffs();
|
||||
let (sum, det) = (a * a + b * b + c * c + d * d, a * d - b * c);
|
||||
// The largest singular value of the linear part.
|
||||
let most = ((sum + (sum * sum - 4.0 * det * det).max(0.0).sqrt()) / 2.0).sqrt();
|
||||
det != 0.0 && most.is_finite() && px.is_finite() && px > 0.0 && most * px <= 1.0 + 1e-9
|
||||
}
|
||||
|
||||
/// `outline`, the outline of a stroke `width` wide made at tolerance `tol`, with its long curves
|
||||
/// ([`SPAN`]) drawn as lines that lie within about half of `tol` on either side of the curve, when
|
||||
/// the stroke is at least [`WIDE`] tolerances wide. Vello draws a curve with chords that all lie
|
||||
/// on its inner side, up to 0.25 device pixels in, which leaves a wide stroke's rims too light
|
||||
/// outside and too dark inside. Here each line end is moved out by half the gap between the curve
|
||||
/// and its chords, and the lines cross the curve. Where two such curves meet smoothly the shared
|
||||
/// end moves too; elsewhere (a corner, a line, a short curve) the end stays on the curve and the
|
||||
/// first or last line is half as long. Narrower strokes, outlines with no long curve and outlines
|
||||
/// that would take more than [`MAX_LINES`] lines are returned as they are.
|
||||
pub(crate) fn wide(outline: BezPath, width: f64, tol: f64) -> BezPath {
|
||||
if !(tol > 0.0 && tol.is_finite() && width >= tol * WIDE) {
|
||||
return outline;
|
||||
}
|
||||
lines(&outline, tol).unwrap_or(outline)
|
||||
}
|
||||
|
||||
/// One subpath: where it starts, its segments, each with the most steps it is drawn with as lines
|
||||
/// ([`steps`]; 0: drawn as it is), and whether it is closed.
|
||||
struct Sub {
|
||||
start: Point,
|
||||
segs: Vec<(PathSeg, usize)>,
|
||||
closed: bool,
|
||||
}
|
||||
|
||||
/// `path` with its long curves drawn as lines ([`wide`]); `None` when it has no long curve, would
|
||||
/// take more than [`MAX_LINES`] lines, or does not start each subpath with a move.
|
||||
fn lines(path: &BezPath, tol: f64) -> Option<BezPath> {
|
||||
let chord = tol * CHORD;
|
||||
let subs = subpaths(path.elements(), tol, chord)?;
|
||||
let mut total = 0usize;
|
||||
for (_, steps) in subs.iter().flat_map(|s| &s.segs) {
|
||||
if *steps > 0 {
|
||||
total = total.saturating_add(steps.saturating_add(2));
|
||||
}
|
||||
}
|
||||
if total == 0 || total > MAX_LINES {
|
||||
return None;
|
||||
}
|
||||
let mut out = BezPath::new();
|
||||
for sub in &subs {
|
||||
draw_sub(&mut out, sub, chord);
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// The subpaths of `els`, each segment with its steps ([`steps`]). A close adds a line back to the
|
||||
/// start when the subpath ends elsewhere. `None` when a segment comes before any move or after a
|
||||
/// close without a move.
|
||||
fn subpaths(els: &[PathEl], tol: f64, chord: f64) -> Option<Vec<Sub>> {
|
||||
let mut subs: Vec<Sub> = Vec::new();
|
||||
for el in els {
|
||||
if let PathEl::MoveTo(p) = *el {
|
||||
subs.push(Sub { start: p, segs: Vec::new(), closed: false });
|
||||
continue;
|
||||
}
|
||||
let sub = subs.last_mut()?;
|
||||
if sub.closed {
|
||||
return None;
|
||||
}
|
||||
let last = sub.segs.last().map_or(sub.start, |(s, _)| s.end());
|
||||
let seg = match *el {
|
||||
PathEl::LineTo(p) => PathSeg::Line(Line::new(last, p)),
|
||||
PathEl::QuadTo(a, b) => PathSeg::Quad(QuadBez::new(last, a, b)),
|
||||
PathEl::CurveTo(a, b, c) => PathSeg::Cubic(CubicBez::new(last, a, b, c)),
|
||||
PathEl::ClosePath | PathEl::MoveTo(_) => {
|
||||
if last != sub.start {
|
||||
sub.segs.push((PathSeg::Line(Line::new(last, sub.start)), 0));
|
||||
}
|
||||
sub.closed = true;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
sub.segs.push((seg, steps(seg, tol, chord)));
|
||||
}
|
||||
Some(subs)
|
||||
}
|
||||
|
||||
/// The cubic that draws curve `seg`; `None` for a line.
|
||||
fn cubic(seg: PathSeg) -> Option<CubicBez> {
|
||||
match seg {
|
||||
PathSeg::Cubic(c) => Some(c),
|
||||
PathSeg::Quad(q) => Some(q.raise()),
|
||||
PathSeg::Line(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// How many equal steps of its parameter keep the chords of curve `seg` within `chord` of it (by
|
||||
/// the second differences of its control points), when its control points span at least [`SPAN`]
|
||||
/// times `tol`; 0 for a line, a shorter curve, a curve with a point that isn't finite, and a curve
|
||||
/// that would take more than [`MAX_LINES`] steps.
|
||||
fn steps(seg: PathSeg, tol: f64, chord: f64) -> usize {
|
||||
let Some(c) = cubic(seg) else { return 0 };
|
||||
let pts = [c.p0, c.p1, c.p2, c.p3];
|
||||
if !pts.iter().all(|p| p.is_finite()) {
|
||||
return 0;
|
||||
}
|
||||
let (lo, hi) = pts.iter().fold((Point::new(f64::INFINITY, f64::INFINITY), Point::new(f64::NEG_INFINITY, f64::NEG_INFINITY)), |(lo, hi), p| {
|
||||
(Point::new(lo.x.min(p.x), lo.y.min(p.y)), Point::new(hi.x.max(p.x), hi.y.max(p.y)))
|
||||
});
|
||||
let span = (hi.x - lo.x).max(hi.y - lo.y);
|
||||
if !span.is_finite() || span < tol * SPAN {
|
||||
return 0;
|
||||
}
|
||||
let second = |a: Point, b: Point, c: Point| (a.to_vec2() - b.to_vec2() * 2.0 + c.to_vec2()).hypot();
|
||||
let bend = second(c.p0, c.p1, c.p2).max(second(c.p1, c.p2, c.p3));
|
||||
let n = (0.75 * bend / chord).sqrt().ceil().max(1.0);
|
||||
if !n.is_finite() || n > MAX_LINES as f64 {
|
||||
return 0;
|
||||
}
|
||||
n as usize
|
||||
}
|
||||
|
||||
/// The direction curve `c` leaves its start in, or `None` when all its points are at its start.
|
||||
fn start_tangent(c: &CubicBez) -> Option<Vec2> {
|
||||
[c.p1, c.p2, c.p3].into_iter().map(|p| p - c.p0).find(|v| v.hypot2() > 0.0)
|
||||
}
|
||||
|
||||
/// The direction curve `c` reaches its end in, or `None` when all its points are at its end.
|
||||
fn end_tangent(c: &CubicBez) -> Option<Vec2> {
|
||||
[c.p2, c.p1, c.p0].into_iter().map(|p| c.p3 - p).find(|v| v.hypot2() > 0.0)
|
||||
}
|
||||
|
||||
/// How many pieces of a curve [`params`] measures its bending on.
|
||||
const SAMPLES: usize = 32;
|
||||
|
||||
/// The parameters curve `c` has its line ends at, and whether its first and its last step are
|
||||
/// halves. Each step holds an equal share of the curve's bending (the integral of the square root
|
||||
/// of its curvature along it), and there are as many as keep each chord within about `chord` of the
|
||||
/// curve, at most `most` (its equal steps, [`steps`]). The steps are equal when the bending can't
|
||||
/// be measured (a cusp, or a point that isn't finite) or is 0. The first or last step is halved
|
||||
/// when that end stays on the curve (`pin_start`, `pin_end`); a curve of one step is then drawn
|
||||
/// in two halves.
|
||||
fn params(c: &CubicBez, most: usize, chord: f64, pin_start: bool, pin_end: bool) -> (Vec<f64>, (bool, bool)) {
|
||||
let (d1, d2) = (c.deriv(), c.deriv().deriv());
|
||||
let bend = |u: f64| {
|
||||
let (v, a) = (d1.eval(u).to_vec2(), d2.eval(u).to_vec2());
|
||||
(v.cross(a).abs() / v.hypot()).sqrt()
|
||||
};
|
||||
let mut sums = [0.0; SAMPLES + 1];
|
||||
let mut before = bend(0.0);
|
||||
for j in 1..=SAMPLES {
|
||||
let here = bend(j as f64 / SAMPLES as f64);
|
||||
sums[j] = sums[j - 1] + (before + here) / 2.0;
|
||||
before = here;
|
||||
}
|
||||
let total = sums[SAMPLES];
|
||||
let most = most.max(1);
|
||||
let n = if total.is_finite() && total > 0.0 { ((total / SAMPLES as f64 / (8.0 * chord).sqrt()).ceil() as usize).clamp(1, most) } else { most };
|
||||
// The parameter at which a share `s` (0 to 1) of the bending lies before it.
|
||||
let at = |s: f64| -> f64 {
|
||||
if !(total.is_finite() && total > 0.0) {
|
||||
return s;
|
||||
}
|
||||
let want = s * total;
|
||||
let j = sums.partition_point(|&x| x <= want).clamp(1, SAMPLES);
|
||||
let (lo, hi) = (sums[j - 1], sums[j]);
|
||||
let part = if hi > lo { ((want - lo) / (hi - lo)).clamp(0.0, 1.0) } else { 0.0 };
|
||||
(j as f64 - 1.0 + part) / SAMPLES as f64
|
||||
};
|
||||
if n == 1 && (pin_start || pin_end) {
|
||||
return (vec![0.0, at(0.5), 1.0], (true, true));
|
||||
}
|
||||
let h = 1.0 / n as f64;
|
||||
let mut t = Vec::with_capacity(n + 3);
|
||||
t.push(0.0);
|
||||
if pin_start {
|
||||
t.push(at(h / 2.0));
|
||||
}
|
||||
t.extend((1..n).map(|k| at(k as f64 * h)));
|
||||
if pin_end {
|
||||
t.push(at(1.0 - h / 2.0));
|
||||
}
|
||||
t.push(1.0);
|
||||
(t, (pin_start, pin_end))
|
||||
}
|
||||
|
||||
/// How far the curve `c` lies from the chord between parameters `a` and `b`, at its parameter
|
||||
/// midway: the curve's point there minus the chord's middle.
|
||||
fn bulge(c: &CubicBez, a: f64, b: f64) -> Vec2 {
|
||||
c.eval((a + b) / 2.0) - c.eval(a).midpoint(c.eval(b))
|
||||
}
|
||||
|
||||
/// A curve of a subpath drawn as lines: the curve, its line ends' parameters, whether its first and
|
||||
/// its last step are halves ([`params`]), and how far the curve lies from its first and last
|
||||
/// chords ([`bulge`]).
|
||||
struct Drawn {
|
||||
curve: CubicBez,
|
||||
t: Vec<f64>,
|
||||
halves: (bool, bool),
|
||||
first: Vec2,
|
||||
last: Vec2,
|
||||
}
|
||||
|
||||
/// Draws `sub` into `out`, its curves with steps as lines ([`wide`]) with chords within about
|
||||
/// `chord` of them, and its other segments as they are.
|
||||
fn draw_sub(out: &mut BezPath, sub: &Sub, chord: f64) {
|
||||
let n = sub.segs.len();
|
||||
let curve = |i: usize| sub.segs.get(i).filter(|(_, steps)| *steps > 0).and_then(|(s, _)| cubic(*s));
|
||||
// Whether segment `i` starts where the one before it ends, both drawn as lines and meeting
|
||||
// smoothly: there the shared end moves off the curve with both.
|
||||
let smooth: Vec<bool> = (0..n)
|
||||
.map(|i| {
|
||||
let before = if i == 0 { sub.closed.then(|| n - 1) } else { Some(i - 1) };
|
||||
let (Some(a), Some(b)) = (before.and_then(curve), curve(i)) else { return false };
|
||||
match (end_tangent(&a), start_tangent(&b)) {
|
||||
(Some(u), Some(v)) => u.dot(v) > 0.0 && u.cross(v).abs() <= SMOOTH * u.hypot() * v.hypot(),
|
||||
_ => false,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
// Whether segment `i` ends where the next one starts, as above; the last one's next is the
|
||||
// first, which starts smoothly only on a closed subpath.
|
||||
let meets = |i: usize| smooth.get((i + 1) % n).copied().unwrap_or(false);
|
||||
let drawn: Vec<Option<Drawn>> = (0..n)
|
||||
.map(|i| {
|
||||
let c = curve(i)?;
|
||||
let steps = sub.segs.get(i).map_or(1, |(_, s)| *s);
|
||||
let (t, halves) = params(&c, steps, chord, !smooth.get(i).copied().unwrap_or(false), !meets(i));
|
||||
let (first, last) = match (t.first().zip(t.get(1)), t.len().checked_sub(2).and_then(|k| t.get(k).zip(t.last()))) {
|
||||
(Some((a, b)), Some((c2, d))) => (bulge(&c, *a, *b), bulge(&c, *c2, *d)),
|
||||
_ => (Vec2::ZERO, Vec2::ZERO),
|
||||
};
|
||||
Some(Drawn { curve: c, t, halves, first, last })
|
||||
})
|
||||
.collect();
|
||||
// How far the start of segment `i` moves: half the curve's gap from the chords on either side.
|
||||
let moved = |i: usize| -> Vec2 {
|
||||
if !smooth.get(i).copied().unwrap_or(false) {
|
||||
return Vec2::ZERO;
|
||||
}
|
||||
let before = if i == 0 { n - 1 } else { i - 1 };
|
||||
match (drawn.get(before).and_then(Option::as_ref), drawn.get(i).and_then(Option::as_ref)) {
|
||||
(Some(a), Some(b)) => (a.last + b.first) / 4.0,
|
||||
_ => Vec2::ZERO,
|
||||
}
|
||||
};
|
||||
out.move_to(sub.start + moved(0));
|
||||
for (i, (seg, _)) in sub.segs.iter().enumerate() {
|
||||
let end = seg.end() + moved((i + 1) % n);
|
||||
match (drawn.get(i).and_then(Option::as_ref), seg) {
|
||||
(Some(d), _) => draw_lines(out, d, end),
|
||||
(None, PathSeg::Line(_)) => out.line_to(end),
|
||||
(None, PathSeg::Quad(q)) => out.quad_to(q.p1, end),
|
||||
(None, PathSeg::Cubic(c)) => out.curve_to(c.p1, c.p2, end),
|
||||
}
|
||||
}
|
||||
if sub.closed {
|
||||
out.close_path();
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws curve `d` into `out` as lines to its inner line ends, each moved out by half the curve's
|
||||
/// gap from the chords beside it, and a line to `end`. Beside a halved step, which lies a quarter
|
||||
/// as far from the curve, the whole step's gap is used: half the other chord's gap, or the two
|
||||
/// halves' gaps together.
|
||||
fn draw_lines(out: &mut BezPath, d: &Drawn, end: Point) {
|
||||
let t = &d.t;
|
||||
let last = t.len().saturating_sub(2);
|
||||
for k in 1..t.len().saturating_sub(1) {
|
||||
let (Some(&a), Some(&u), Some(&b)) = (t.get(k - 1), t.get(k), t.get(k + 1)) else { continue };
|
||||
let (before, after) = (bulge(&d.curve, a, u), bulge(&d.curve, u, b));
|
||||
let shift = match (d.halves.0 && k == 1, d.halves.1 && k == last) {
|
||||
(true, true) => before + after,
|
||||
(true, false) => after / 2.0,
|
||||
(false, true) => before / 2.0,
|
||||
(false, false) => (before + after) / 4.0,
|
||||
};
|
||||
out.line_to(d.curve.eval(u) + shift);
|
||||
}
|
||||
out.line_to(end);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ mod cmykblend;
|
||||
mod colorize;
|
||||
mod colrglyphs;
|
||||
mod container;
|
||||
mod curvedstrokeedges;
|
||||
mod dither;
|
||||
pub(super) mod fontchange;
|
||||
mod freeform;
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
//! Wide strokes along curves: both rims cover their edge pixels close to the exact coverage of
|
||||
//! the curves they follow, and narrow strokes, short curves and straight outlines are drawn as
|
||||
//! they were.
|
||||
|
||||
use super::*;
|
||||
use crate::stroke::{fine, wide};
|
||||
use vectorcraft_doc::{AppearanceItem, StrokeGradientMode, StrokeLayer};
|
||||
|
||||
/// The share of pixel (`px`, `py`) inside the circle at `c` with radius `r`, integrated over 512
|
||||
/// columns of the pixel.
|
||||
fn disc_coverage(c: kurbo::Point, r: f64, px: u32, py: u32) -> f64 {
|
||||
const COLUMNS: u32 = 512;
|
||||
let (top, bottom) = (f64::from(py), f64::from(py) + 1.0);
|
||||
(0..COLUMNS)
|
||||
.map(|k| {
|
||||
let x = f64::from(px) + (f64::from(k) + 0.5) / f64::from(COLUMNS);
|
||||
let u = (x - c.x) / r;
|
||||
if u.abs() >= 1.0 {
|
||||
return 0.0;
|
||||
}
|
||||
let h = r * (1.0 - u * u).sqrt();
|
||||
((c.y + h).min(bottom) - (c.y - h).max(top)).max(0.0)
|
||||
})
|
||||
.sum::<f64>()
|
||||
/ f64::from(COLUMNS)
|
||||
}
|
||||
|
||||
/// A circle of radius `r` at `c`, as eight cubics, each an eighth of it, within five millionths
|
||||
/// of `r` of it.
|
||||
fn circle(c: (f64, f64), r: f64) -> BezPath {
|
||||
let c = kurbo::Point::new(c.0, c.1);
|
||||
let at = |a: f64| c + kurbo::Vec2::from_angle(a) * r;
|
||||
let step = std::f64::consts::FRAC_PI_4;
|
||||
let handle = r * 4.0 / 3.0 * (step / 4.0).tan();
|
||||
let mut p = BezPath::new();
|
||||
p.move_to(at(0.0));
|
||||
for k in 0..8 {
|
||||
let (a, b) = (f64::from(k) * step, f64::from(k + 1) * step);
|
||||
let tangent = |a: f64| kurbo::Vec2::from_angle(a + std::f64::consts::FRAC_PI_2) * handle;
|
||||
p.curve_to(at(a) + tangent(a), at(b) - tangent(b), at(b));
|
||||
}
|
||||
p.close_path();
|
||||
p
|
||||
}
|
||||
|
||||
/// A document of 1200 points holding a circle of radius 400 at its middle, stroked 80 pt with
|
||||
/// `paint` at `opacity`. A gradient is laid along the stroke.
|
||||
fn ring(paint: Paint, opacity: f32) -> Document {
|
||||
let mut d = Document::new(1200.0, 1200.0);
|
||||
let path = vectorcraft_geom::PathData::from_bezpath(&circle((600.0, 600.0), 400.0));
|
||||
let mut node = Node::path(d.alloc_id(), path, Appearance::basic(Paint::None, paint, 80.0));
|
||||
for item in &mut node.appearance.items {
|
||||
if let AppearanceItem::Stroke(st) = item {
|
||||
st.opacity = opacity;
|
||||
st.gradient_mode = StrokeGradientMode::Along;
|
||||
}
|
||||
}
|
||||
let l = d.layers[0].id;
|
||||
d.insert(Some(l), 0, node).unwrap();
|
||||
d
|
||||
}
|
||||
|
||||
/// The worst edge pixel of one rim: how many alpha levels it is off, where, and how many edge
|
||||
/// pixels the rim has.
|
||||
#[derive(Debug, Default)]
|
||||
struct Rim {
|
||||
worst: u8,
|
||||
pixels: usize,
|
||||
at: String,
|
||||
}
|
||||
|
||||
/// The rims of the ring of [`ring`] (outer radius 440, inner 360) drawn through `view`, which
|
||||
/// scales by `scale`, at `side`×`side`, with `paint` and `opacity`. An edge pixel is one whose
|
||||
/// exact coverage by the circle of its rim is between 2% and 98%; its alpha is compared with that
|
||||
/// coverage of the alpha the ring paints.
|
||||
fn ring_rims(view: Affine, side: u32, scale: f64, paint: Paint, opacity: f32) -> (Rim, Rim) {
|
||||
let opts = RenderOptions { background: None, artboards: false, ..Default::default() };
|
||||
let got = Renderer::new().render(&ring(paint, opacity), side, side, view, &opts);
|
||||
let c = view * kurbo::Point::new(600.0, 600.0);
|
||||
let full = 255.0 * f64::from(opacity);
|
||||
let (mut outer, mut inner) = (Rim::default(), Rim::default());
|
||||
for y in 0..side {
|
||||
for x in 0..side {
|
||||
let from = (kurbo::Point::new(f64::from(x) + 0.5, f64::from(y) + 0.5) - c).hypot();
|
||||
for (rim, r, outside) in [(&mut outer, 440.0 * scale, true), (&mut inner, 360.0 * scale, false)] {
|
||||
// Only pixels within two pixels of a rim can be crossed by it.
|
||||
if (from - r).abs() >= 2.0 {
|
||||
continue;
|
||||
}
|
||||
let e = disc_coverage(c, r, x, y);
|
||||
if !(0.02..=0.98).contains(&e) {
|
||||
continue;
|
||||
}
|
||||
// Inside the outer rim the ring covers the pixel; inside the inner rim it doesn't.
|
||||
let want = if outside { e } else { 1.0 - e } * full;
|
||||
let alpha = f64::from(got.pixel(x, y)[3]);
|
||||
let diff = (alpha - want).abs().round().min(255.0) as u8;
|
||||
rim.pixels += 1;
|
||||
if diff > rim.worst {
|
||||
rim.worst = diff;
|
||||
rim.at = format!("({x},{y}) {alpha} vs {want:.1}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(outer, inner)
|
||||
}
|
||||
|
||||
/// Most alpha levels an edge pixel of a wide curved stroke may differ from the exact coverage of
|
||||
/// its rim.
|
||||
const EDGE_LEVELS: u8 = 36;
|
||||
|
||||
/// A wide stroke along a curve paints both of its rims within [`EDGE_LEVELS`] of their exact
|
||||
/// coverage: zoomed out and at 1:1, through a turned view, with a gradient laid along it, and
|
||||
/// translucent (within half as many levels).
|
||||
#[test]
|
||||
fn wide_curved_strokes_cover_their_rims_as_the_curves_do() {
|
||||
let turned = Affine::translate((150.0, 150.0)) * Affine::rotate(0.5) * Affine::scale(0.25) * Affine::translate((-600.0, -600.0));
|
||||
let gradient = Paint::Gradient(Box::new(GradientPaint::new(Gradient::default())));
|
||||
let black = || Paint::solid(Color::BLACK);
|
||||
let mut off = vec![];
|
||||
for (name, view, side, scale, paint, opacity) in [
|
||||
("zoomed out", Affine::scale(0.25), 300, 0.25, black(), 1.0),
|
||||
("1:1", Affine::translate((-100.0, -100.0)), 1000, 1.0, black(), 1.0),
|
||||
("turned", turned, 300, 0.25, black(), 1.0),
|
||||
("gradient", Affine::scale(0.25), 300, 0.25, gradient, 1.0),
|
||||
("translucent", Affine::scale(0.25), 300, 0.25, black(), 0.5),
|
||||
] {
|
||||
let (outer, inner) = ring_rims(view, side, scale, paint, opacity);
|
||||
let bound = if opacity < 1.0 { EDGE_LEVELS / 2 + 1 } else { EDGE_LEVELS };
|
||||
for (rim, r) in [("outer", outer), ("inner", inner)] {
|
||||
assert!(r.pixels > 200, "{name}, {rim} rim: {} edge pixels", r.pixels);
|
||||
if r.worst > bound {
|
||||
off.push(format!("{name}, {rim} rim: {} levels off at {} ({} edge pixels)", r.worst, r.at, r.pixels));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(off.is_empty(), "{off:#?}");
|
||||
}
|
||||
|
||||
/// The outline of the 80 pt stroke along a circle of radius 400 about (600, 600), at `tol`.
|
||||
fn ring_outline(tol: f64) -> BezPath {
|
||||
let st = StrokeLayer::new(Paint::solid(Color::BLACK), 80.0);
|
||||
crate::stroke::outline(&circle((600.0, 600.0), 400.0), &st, 80.0, tol)
|
||||
}
|
||||
|
||||
/// How many moves and closes `p` has.
|
||||
fn moves_and_closes(p: &BezPath) -> (usize, usize) {
|
||||
let els = p.elements();
|
||||
(els.iter().filter(|e| matches!(e, kurbo::PathEl::MoveTo(_))).count(), els.iter().filter(|e| matches!(e, kurbo::PathEl::ClosePath)).count())
|
||||
}
|
||||
|
||||
/// A wide stroke's outline has its long curves drawn as lines that cross them: the line ends lie
|
||||
/// outside the circles, the lines' middles inside, all within half of the tolerance, with its
|
||||
/// subpaths kept.
|
||||
#[test]
|
||||
fn wide_outlines_draw_their_curves_as_lines_across_them() {
|
||||
for tol in [1.0, 0.25] {
|
||||
let raw = ring_outline(tol);
|
||||
let lines = wide(raw.clone(), 80.0, tol);
|
||||
assert_eq!(moves_and_closes(&lines), moves_and_closes(&raw), "tolerance {tol}");
|
||||
assert!(lines.elements().iter().all(|e| matches!(e, kurbo::PathEl::MoveTo(_) | kurbo::PathEl::LineTo(_) | kurbo::PathEl::ClosePath)));
|
||||
let c = kurbo::Point::new(600.0, 600.0);
|
||||
// How far a point is outside the rim it is nearest to.
|
||||
let off = |p: kurbo::Point| {
|
||||
let r = (p - c).hypot();
|
||||
if r > 400.0 { r - 440.0 } else { r - 360.0 }
|
||||
};
|
||||
let (mut ends, mut middles) = (vec![], vec![]);
|
||||
for seg in lines.segments() {
|
||||
if let kurbo::PathSeg::Line(l) = seg
|
||||
&& l.p1 != l.p0
|
||||
{
|
||||
ends.push(off(l.p1));
|
||||
middles.push(off(l.p0.midpoint(l.p1)));
|
||||
}
|
||||
}
|
||||
assert!(ends.len() > 100, "tolerance {tol}: {} lines", ends.len());
|
||||
let most = ends.iter().chain(&middles).fold(0.0_f64, |m, d| m.max(d.abs()));
|
||||
assert!(most <= tol / 2.0, "tolerance {tol}: a line {most} from its curve");
|
||||
assert!(ends.iter().filter(|d| **d > tol * 0.1).count() > ends.len() / 2, "tolerance {tol}: line ends outside the curves");
|
||||
assert!(middles.iter().filter(|d| **d < -tol * 0.1).count() > middles.len() / 2, "tolerance {tol}: line middles inside the curves");
|
||||
}
|
||||
}
|
||||
|
||||
/// Outlines of strokes narrower than 32 tolerances, outlines without a curve spanning 128
|
||||
/// tolerances, and outlines that would take more than a million lines are kept as they are.
|
||||
#[test]
|
||||
fn narrow_short_straight_or_huge_outlines_are_kept() {
|
||||
let tol = 0.25;
|
||||
let st = |w: f64| StrokeLayer::new(Paint::solid(Color::BLACK), w);
|
||||
let narrow = crate::stroke::outline(&circle((600.0, 600.0), 400.0), &st(7.0), 7.0, tol);
|
||||
let small = crate::stroke::outline(&circle((50.0, 50.0), 10.0), &st(9.0), 9.0, tol);
|
||||
let straight = crate::stroke::outline(&Rect::new(0.0, 0.0, 400.0, 300.0).to_path(0.1), &st(20.0), 20.0, tol);
|
||||
// Eight curves of about 200,000 lines each.
|
||||
let huge = circle((0.0, 0.0), 1e11);
|
||||
for (name, p, width) in [("narrow", narrow, 7.0), ("small curves", small, 9.0), ("straight", straight, 20.0), ("huge", huge, 20.0)] {
|
||||
assert!(p.elements().len() > 1, "{name}");
|
||||
assert_eq!(wide(p.clone(), width, tol).elements(), p.elements(), "{name}: kept");
|
||||
}
|
||||
for bad in [0.0, -1.0, f64::NAN, f64::INFINITY] {
|
||||
let raw = ring_outline(1.0);
|
||||
assert_eq!(wide(raw.clone(), 80.0, bad).elements(), raw.elements(), "tolerance {bad}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a long curve meets a corner, a line or a curve that isn't finite, its end stays where it
|
||||
/// was, and the segments that aren't long curves are kept as they are.
|
||||
#[test]
|
||||
fn curve_ends_at_corners_lines_and_bad_curves_stay_put() {
|
||||
let mut p = BezPath::new();
|
||||
p.move_to((0.0, 0.0));
|
||||
p.curve_to((0.0, 100.0), (100.0, 200.0), (200.0, 200.0));
|
||||
p.line_to((300.0, 200.0));
|
||||
p.curve_to((300.0, 100.0), (400.0, 0.0), (500.0, 0.0));
|
||||
p.curve_to((f64::NAN, 0.0), (600.0, 0.0), (700.0, 0.0));
|
||||
p.curve_to((700.0, 300.0), (900.0, 300.0), (900.0, 0.0));
|
||||
p.quad_to((905.0, 5.0), (910.0, 0.0));
|
||||
let lines = wide(p.clone(), 40.0, 0.25);
|
||||
let points: Vec<_> = lines.elements().iter().filter_map(|e| e.end_point()).collect();
|
||||
for corner in [(0.0, 0.0), (200.0, 200.0), (300.0, 200.0), (500.0, 0.0), (700.0, 0.0), (900.0, 0.0), (910.0, 0.0)] {
|
||||
assert!(points.contains(&kurbo::Point::from(corner)), "{corner:?} kept: {lines:?}");
|
||||
}
|
||||
let curves: Vec<_> = lines.elements().iter().filter(|e| matches!(e, kurbo::PathEl::CurveTo(..) | kurbo::PathEl::QuadTo(..))).collect();
|
||||
assert_eq!(curves.len(), 2, "the curve that isn't finite and the short curve are kept: {curves:?}");
|
||||
assert!(lines.elements().len() > 40, "{} elements", lines.elements().len());
|
||||
}
|
||||
|
||||
/// An outline is drawn with lines through a view that stretches no length by more than the frame's
|
||||
/// pixel size allows: one that zooms, turns or shrinks the stroke's space, and not one that
|
||||
/// stretches it unevenly, enlarges it beyond the frame's pixels, collapses it or isn't finite.
|
||||
#[test]
|
||||
fn outlines_are_drawn_as_lines_only_through_even_views() {
|
||||
let px = |v: Affine| 1.0 / v.determinant().abs().sqrt();
|
||||
for (name, m, px, want) in [
|
||||
("zoomed out", Affine::scale(0.25), px(Affine::scale(0.25)), true),
|
||||
("turned", Affine::rotate(0.5) * Affine::scale(3.0), px(Affine::scale(3.0)), true),
|
||||
("flipped", Affine::FLIP_X, 1.0, true),
|
||||
("text made smaller", Affine::scale(0.5), 1.0, true),
|
||||
("stretched", Affine::scale_non_uniform(0.25, 0.2), px(Affine::scale_non_uniform(0.25, 0.2)), false),
|
||||
("text made larger", Affine::scale(2.0), 1.0, false),
|
||||
("collapsed", Affine::scale(0.0), 1.0, false),
|
||||
("not a number", Affine::scale(f64::NAN), 1.0, false),
|
||||
("no pixel size", Affine::IDENTITY, f64::INFINITY, false),
|
||||
] {
|
||||
assert_eq!(fine(m, px), want, "{name}");
|
||||
}
|
||||
}
|
||||
@@ -199,6 +199,56 @@ fn a_long_dashed_stroke_draws_the_same_pixels_outlined_near_the_view() {
|
||||
}
|
||||
}
|
||||
|
||||
/// 600 half circles of radius 60 in a row along y = 0, from x = 0, each as two quarter circles and
|
||||
/// alternately above and below the row.
|
||||
fn waves() -> BezPath {
|
||||
let k = 60.0 * 4.0 / 3.0 * (std::f64::consts::FRAC_PI_8).tan();
|
||||
let mut bp = BezPath::new();
|
||||
bp.move_to((0.0, 0.0));
|
||||
for i in 0..600 {
|
||||
let (x, s) = (f64::from(i) * 120.0, if i % 2 == 0 { -1.0 } else { 1.0 });
|
||||
bp.curve_to((x, s * k), (x + 60.0 - k, s * 60.0), (x + 60.0, s * 60.0));
|
||||
bp.curve_to((x + 60.0 + k, s * 60.0), (x + 120.0, s * k), (x + 120.0, 0.0));
|
||||
}
|
||||
bp
|
||||
}
|
||||
|
||||
/// Whether `outline` has a curve whose control points span 32 pt or more across or down.
|
||||
fn has_long_curve(outline: &BezPath) -> bool {
|
||||
outline.segments().any(|s| {
|
||||
let pts = match s {
|
||||
kurbo::PathSeg::Line(_) => return false,
|
||||
kurbo::PathSeg::Quad(q) => vec![q.p0, q.p1, q.p2],
|
||||
kurbo::PathSeg::Cubic(c) => vec![c.p0, c.p1, c.p2, c.p3],
|
||||
};
|
||||
let b = pts.iter().fold(kurbo::Rect::from_points(pts[0], pts[0]), |b, p| b.union_pt(*p));
|
||||
b.width().max(b.height()) >= 32.0
|
||||
})
|
||||
}
|
||||
|
||||
/// A long wide stroke along curves, solid or dashed, outlined near the view has its long curves
|
||||
/// drawn as lines and draws the same pixels as when it is outlined whole. With a width profile,
|
||||
/// the outline made near the view keeps its curves.
|
||||
#[test]
|
||||
fn a_long_wide_curved_stroke_draws_the_same_pixels_outlined_near_the_view() {
|
||||
let at = Point::new(36_030.0, 0.0);
|
||||
let solid = stroke(24.0, LineJoin::Miter, LineCap::Butt);
|
||||
for (what, d) in [("solid", doc(&waves(), solid.clone())), ("dashed", doc(&waves(), dashed(solid.clone(), &[150.0, 40.0], 0.0, false)))] {
|
||||
let mut r = Renderer::new();
|
||||
let near = render(&mut r, &d, at);
|
||||
assert!(r.strokes.values().any(|e| e.crop.is_some()), "{what}: outlined near the view");
|
||||
assert!(r.strokes.values().all(|e| !has_long_curve(&e.outline)), "{what}: its long curves drawn as lines");
|
||||
assert!(near.pixels == whole(&d, at).pixels, "{what}: the same pixels as the whole outline");
|
||||
assert!(near.pixels.chunks(4).any(|p| p[0] < 128), "{what}: the stroke shows");
|
||||
}
|
||||
let mut lens = solid;
|
||||
lens.profile = WidthProfile::preset("lens");
|
||||
let mut r = Renderer::new();
|
||||
render(&mut r, &doc(&waves(), lens), at);
|
||||
assert!(r.strokes.values().any(|e| e.crop.is_some()), "lens profile: outlined near the view");
|
||||
assert!(r.strokes.values().all(|e| has_long_curve(&e.outline)), "lens profile: its curves kept");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_long_dashed_stroke_draws_the_same_pixels_after_its_path_changes() {
|
||||
let st = dashed(stroke(5.0, LineJoin::Miter, LineCap::Butt), &[18.0, 7.0], 3.0, false);
|
||||
|
||||
@@ -769,6 +769,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Smooth widths between width points (#5714):** a variable-width stroke changes width along a smooth curve from one width point to the next, where it used to run in a straight line and turn a corner at each point. The public description is that the path "gradually gets wider or narrower from one point to the next" in "a flowing, continuous curve", and that stacked points make a sharp break ([Peachpit, Expressive Strokes](https://www.peachpit.com/articles/article.aspx?p=2979069)); the exact curve is not documented, so each side follows a monotone cubic (Fritsch–Carlson): no kink at a point, flat where a point is wider or narrower than both neighbours, never past the points either side, points on one line kept on it. The outline samples straight runs between width points closely enough to follow the curve to the drawing tolerance (at most 64 samples per span and 4,096 per piece). Presets with a middle point (Lens, Pinch, Teardrop, Wave) look softer; two-point tapers are unchanged. Tests: `appearance::profile::tests::{widths_run_smoothly_through_width_points, widths_never_pass_the_points_either_side, a_step_ends_the_curve_on_each_side, widest_covers_every_width_along_the_profile}`, `stroke::width::tests::{a_straight_run_follows_the_curve_between_width_points, samples_between_width_points_are_capped}`.
|
||||
- **Stroke gradients where a variable-width stroke meets itself (#5960):** with a gradient along or across a stroke that has a width profile, where the stroke crosses itself the later part paints over the earlier one only where the two overlap, and a narrow part running close beside a wide one leaves its edge alone. Each slice of the gradient reaches as far as the stroke is wide where it sits (for a dashed stroke, as wide as it gets within the reach of a cap or dot, found in one pass along the path, so a densely flattened path costs no more per point), where it used to reach as far as the stroke is wide anywhere and paint a square of its colour over the wider part. Strokes without a profile are unchanged. Tests: `stroke::tests_gradient::a_narrow_pass_over_a_wide_one_paints_only_where_they_overlap`, `a_narrow_pass_beside_a_wide_one_leaves_its_edge_alone`, `a_densely_flattened_dashed_pass_beside_a_wide_one_leaves_its_edge_alone` and `widest_ahead_is_the_widest_within_the_window`, with the existing coverage tests (joins, caps, arrowheads, profiles, dashes, aligned strokes).
|
||||
- **Width strokes zoomed out (#995):** a stroke with a width profile keeps its shape while the view zooms out. The canvas keeps a hairline visible (at least half a device pixel); for a profiled stroke it is the profile's widest point that gets that minimum, not the weight, so a 1 pt stroke with a 6x width point is no longer drawn twice as thick at 25% zoom than at 100%. Plain strokes are unchanged. Test: `render::tests::widthzoom`.
|
||||
- **Wide curved stroke edges:** the canvas and raster exports draw a stroke at least 32 drawing tolerances wide along curves that span 128 tolerances or more with the rims of its outline closer to the curves, so the outer rim no longer draws too light and the inner rim too dark. That is 8 and 32 device pixels at 25% and 1:1, and as little as just over 4 and 16 device pixels at other zooms. At 25% zoom an 80 pt ring's worst edge pixel is 24 levels off the exact coverage at the outer rim and 32 at the inner rim, where it was 54 and 61. Fills, narrower strokes, strokes with a width profile, strokes in an unevenly scaled view and vector exports are unchanged. Tests: `render::tests::curvedstrokeedges`, `render::tests::longstroke::a_long_wide_curved_stroke_draws_the_same_pixels_outlined_near_the_view`.
|
||||
- **Ruler double-click (#5239):** a double-click (both clicks on that ruler) on the top ruler adds a vertical guide at the pointer's x and one on the left ruler a horizontal guide at its y (swapped in a view turned 90°, where the rulers read the other document axis; the nearer axis in between), through `guide.add` in one undo step; the guide is not snapped, is shown even when guides were hidden, and is an artboard guide with the Artboard tool, as a drag from a ruler makes one. The [public page on rulers](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/use-rulers.html) doesn't describe the gesture, so it follows the request in #5239. egui frame tests cover both rulers, a lone click, Undo, a canvas click before a ruler click, and rotated views.
|
||||
- **Rulers (#1212):** drag the intersection to preview and set a document zero point, snapped as a drawn point is (with Smart Guides onto the art's and the artboards' anchors, centres, edges and paths or into line with them, with Snap to Point along the ruler guides, else to pixels or the grid), or double-click it to reset to the active artboard's top-left. Transform, Properties and Control X/Y fields measure from it and convert entered positions back to absolute command coordinates. The origin survives every native format version and compression; geometry, guides and patterns stay in place. Public reference: [Use rulers](https://helpx.adobe.com/ca/illustrator/desktop/measure-and-align/grids-and-guides/use-rulers.html).
|
||||
- **Global and artboard rulers:** View › Rulers › Change to Global / Artboard Rulers (Cmd+Alt+R, `view.globalRulers`). A new document has artboard rulers: the rulers and the Transform, Properties, Control and Info X/Y count from the active artboard's top-left corner, or the zero point dragged out for that artboard, which moves with it; with global rulers one document zero point serves every artboard. Guide readouts and Shift ruler-tick snapping follow the same zero point. The mode is saved with the document; files from before it open with global rulers, as they measured. Regression tests: `engine/tests/it/ruler_origin.rs`, `ui-egui/src/tests/ruler_origin.rs`, `tools/src/rulerguide.rs`. Public reference: [About rulers](https://helpx.adobe.com/illustrator/desktop/measure-and-align/grids-and-guides/about-rulers.html).
|
||||
|
||||
Reference in New Issue
Block a user