mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-30 20:58:00 -06:00
Paint: picking another pattern swatch keeps the pattern transform (#1970)
This commit is contained in:
committed by
bflatastic
parent
6d898558fd
commit
a0f8a88e82
@@ -560,7 +560,7 @@ fn set_item(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
};
|
||||
if let Some(pa) = &paint {
|
||||
*pp = super::gradient::place_paint(pa, p, bounds);
|
||||
*pp = super::gradient::place_paint(&super::paint::keep_pattern_xf(pa, p, Some(&*pp)), p, bounds);
|
||||
}
|
||||
if let Some(o) = p.get("opacity").and_then(Value::as_f64) {
|
||||
*op = percent(o);
|
||||
|
||||
@@ -457,7 +457,8 @@ fn apply_paint(s: &mut Session, p: &Value, paint: Paint, fill: bool) -> Result<V
|
||||
if !fill {
|
||||
restore_unpainted_stroke(&mut n.appearance, index, &paint);
|
||||
}
|
||||
let placed = place_paint(&paint, p, item_paint_bounds(n, index, fill));
|
||||
let new_paint = keep_pattern_xf(&paint, p, n.appearance.paint_at(index, fill));
|
||||
let placed = place_paint(&new_paint, p, item_paint_bounds(n, index, fill));
|
||||
n.appearance.set_paint_at(index, fill, placed);
|
||||
Ok(())
|
||||
},
|
||||
@@ -509,6 +510,17 @@ fn set_run_stroke(style: &mut CharStyle, paint: Paint) {
|
||||
style.stroke = paint;
|
||||
}
|
||||
|
||||
/// `paint` as it replaces `old`: a pattern swatch picked over a pattern keeps the placement that
|
||||
/// pattern already had, so only the pattern changes (#1970).
|
||||
pub(super) fn keep_pattern_xf(paint: &Paint, p: &Value, old: Option<&Paint>) -> Paint {
|
||||
match (paint, old) {
|
||||
(Paint::Pattern { pattern, xf }, Some(Paint::Pattern { xf: kept, .. })) if p.get("swatch").is_some() && *xf == Affine::IDENTITY => {
|
||||
Paint::Pattern { pattern: pattern.clone(), xf: *kept }
|
||||
}
|
||||
_ => paint.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Use the existing 1 pt default when adding paint to an unpainted zero-width stroke.
|
||||
pub(super) fn restore_unpainted_stroke(ap: &mut Appearance, index: Option<usize>, paint: &Paint) {
|
||||
if !paint.is_none()
|
||||
|
||||
Reference in New Issue
Block a user