Type: new art from a redefined style is unlinked, default look keeps type plain

A graphic style picked with nothing selected and then redefined gave new
art and type the look picked with the new definition's isolate and
knockout, still linked to the style. New art now links to the style only
while its fills, strokes, effects, opacity and blend mode match the
style's current definition; otherwise it keeps the look picked without
the link, isolate or knockout. appearance.newArt reports the style the
same way, and undoing the redefinition links new art again.

New type made with the look paint.default gives in a document whose
Default Graphic Style was redefined took that look and lost its
characters' color, which failed
an_open_document_takes_another_profiles_default_fill_stroke_and_font.
That look is the document's default, so new type made with it keeps its
characters' color, as with the shipped default.
This commit is contained in:
dotCooCoo committed 2026-12-05 02:24:07 -08:00
1 parent 5f49ebf6e5
commit 4e463a7621
3 files changed
+67 -11

No files matched your search

+28 -9
View File
@@ -273,6 +273,12 @@ fn unplace_all(mut ap: Appearance) -> Appearance {
ap
}
/// The fills, strokes and effects new art takes from graphic style `g`, placed gradients relative
/// to the unit box.
fn style_look(g: &GraphicStyle) -> Appearance {
if g.unit_box { g.appearance.clone() } else { unplace_all(g.appearance.clone()) }
}
/// How a new object looks ([`Session::new_art_look`]): its appearance and transparency and the
/// graphic style it is linked to.
pub(crate) struct NewArt {
@@ -294,20 +300,29 @@ impl NewArt {
/// Give new object `n` (in `d`) this look: its placed gradients land relative to its bounds, and
/// it links to the style, taking its isolate and knockout too (type keeps its own transparency
/// unless the look is a graphic style's).
/// unless the look is a graphic style's). A look that no longer matches the style's definition
/// (the style was redefined after it was picked) is given unlinked ([`NewArt::linked_style`]).
pub(crate) fn apply(&self, d: &mut vectorcraft_doc::Document, n: &mut Node) {
self.place(n);
if matches!(n.kind, NodeKind::Text(_)) && !self.styled {
return;
}
(n.opacity, n.blend) = (self.opacity, self.blend);
let style = self.style.as_deref().and_then(|name| d.graphic_style_index(name));
let style = self.linked_style(d);
if let Some(g) = style.and_then(|i| d.graphic_styles.get(i)) {
(n.isolate, n.knockout) = (g.isolate, g.knockout);
}
n.extras_mut().graphic_style = style.map(|i| d.graphic_style_id(i));
}
/// The index in `d` of the graphic style this look links to: its style, while the style's
/// fills, strokes, effects, opacity and blend mode are still the ones this look has.
pub(crate) fn linked_style(&self, d: &Document) -> Option<usize> {
let i = d.graphic_style_index(self.style.as_deref()?)?;
let g = d.graphic_styles.get(i)?;
((g.opacity, g.blend) == (self.opacity, self.blend) && style_look(g).approx_eq(&self.appearance)).then_some(i)
}
/// Give `n` this look's appearance, its placed gradients relative to `n`'s bounds now.
pub(crate) fn place(&self, n: &mut Node) {
n.appearance = self.appearance.clone().into();
@@ -353,13 +368,16 @@ impl Session {
/// The look of new type (`text.create`): the template's fills, strokes and effects when it is
/// more than one plain fill and stroke or comes from a graphic style (of this document or
/// another), else none of its own, so the characters' fill and stroke show. The template is
/// not repainted with the fill and stroke proxies.
/// another), else none of its own, so the characters' fill and stroke show. The document's own
/// default look (its redefined Default Graphic Style, which [`reset`] gives new art) leaves type
/// plain as the shipped default does. The template is not repainted with the fill and stroke
/// proxies.
pub(crate) fn new_type_look(&self) -> NewArt {
let plain = || NewArt::plain(Appearance::default());
let Some(t) = self.template() else { return plain() };
let styled = self.new_art_styled();
if t.is_basic() && !styled {
let default_look = || self.active().and_then(|st| redefined_default_style(&st.doc)).is_some_and(|g| style_look(g).approx_eq(&t));
if !styled && (t.is_basic() || default_look()) {
return plain();
}
let (opacity, blend, style) = self.new_art_transparency();
@@ -422,7 +440,7 @@ impl Session {
/// A graphic style clicked with nothing selected: new art takes it (`add`: its fills, strokes
/// and effects on top of the template's, unlinked).
pub(crate) fn new_art_style(&mut self, g: &GraphicStyle, add: bool) {
let ap = if g.unit_box { g.appearance.clone() } else { unplace_all(g.appearance.clone()) };
let ap = style_look(g);
if add {
let t = self.new_art_template_mut();
t.items.extend(ap.items);
@@ -568,7 +586,9 @@ fn set_basic(s: &mut Session, p: &Value) -> Result<Value> {
}
fn describe(s: &mut Session, _: &Value) -> Result<Value> {
let (opacity, blend, style) = s.new_art_transparency();
let (opacity, blend, _) = s.new_art_transparency();
let look = s.new_art_look(s.paint.fill.clone(), s.paint.stroke.clone(), s.paint.stroke_width);
let style = s.doc().ok().and_then(|st| look.linked_style(&st.doc)).and_then(|i| s.doc().ok()?.doc.graphic_styles.get(i)).map(|g| g.name.clone());
Ok(json!({
"basic": s.prefs.new_art_basic,
"appearance": s.new_art(),
@@ -586,8 +606,7 @@ pub(crate) fn reset(s: &mut Session) {
s.paint = PaintDefaults::default();
let style = s.doc().ok().and_then(|st| redefined_default_style(&st.doc)).cloned();
if let Some(g) = style {
let ap = if g.unit_box { g.appearance } else { unplace_all(g.appearance) };
s.take_new_art(ap, 1.0, BlendMode::Normal, None, false);
s.take_new_art(style_look(&g), 1.0, BlendMode::Normal, None, false);
}
}
+35
View File
@@ -665,3 +665,38 @@ fn new_type_in_another_document_takes_a_basic_styles_look_and_transparency() {
assert_eq!((n.opacity, n.blend), (0.5, BlendMode::Multiply), "the style's transparency");
assert_eq!(n.extras().graphic_style, None, "no link to a style of another document");
}
#[test]
fn new_art_and_type_from_a_style_redefined_after_it_was_picked_keep_the_picked_look_unlinked() {
let mut s = session();
fancy(&mut s);
run(&mut s, "graphicStyle.new", json!({"name": "Picked"}));
let other = painted(&mut s, 120.0, "#00ff00", "#000000", 3.0);
run(&mut s, "transparency.set", json!({"knockout": "on", "isolate": true}));
run(&mut s, "select.none", json!({}));
run(&mut s, "graphicStyle.apply", json!({"name": "Picked"}));
let picked = s.new_art();
let redefine = |s: &mut Session| run(s, "graphicStyle.redefine", json!({"name": "Picked", "id": other.0}));
let linked = |s: &mut Session| run(s, "appearance.newArt", json!({}))["graphicStyle"].clone();
let make =
[("shape.rectangle", json!({"x": 200, "y": 200, "width": 40, "height": 30})), ("text.create", json!({"x": 200, "y": 200, "text": "k"}))];
redefine(&mut s);
assert_eq!(linked(&mut s), Value::Null);
// Undone, the style has the picked look again, and new art links to it.
run(&mut s, "edit.undo", json!({}));
assert_eq!(linked(&mut s), json!("Picked"));
for (cmd, p) in &make {
run(&mut s, "select.none", json!({}));
run(&mut s, cmd, p.clone());
assert_eq!(s.selection_graphic_style().map(|(g, linked)| (g.name.clone(), linked)), Some(("Picked".to_string(), true)), "{cmd}");
}
redefine(&mut s);
assert_eq!(linked(&mut s), Value::Null);
for (cmd, p) in &make {
run(&mut s, "select.none", json!({}));
let id = NodeId(run(&mut s, cmd, p.clone())["id"].as_u64().unwrap());
let n = node(&s, id);
assert_eq!((n.extras().graphic_style, n.isolate, n.opacity), (None, false, 0.5), "{cmd}: the picked transparency, unlinked");
assert_eq!((n.appearance.effects.len(), n.appearance.fill_paint()), (1, picked.fill_paint()), "{cmd}: the picked look");
}
}
+4 -2
View File
@@ -11570,12 +11570,14 @@ whole appearance of the last selected object. `appearance.newArt` reports what t
resets it.
New type (`text.create`) takes the template's fills, strokes and effects when the template is more than one plain fill
and stroke or comes from a graphic style; otherwise it has no fills or strokes of its own and its characters keep their
color. With Override Character Color on, its characters lose the fill and stroke the template paints, as when a
color. The look `paint.default` gives in a document whose Default Graphic Style was redefined is the document's default,
and new type made with it keeps its characters' color too. With Override Character Color on, its characters lose the fill and stroke the template paints, as when a
graphic style is applied to type; a `color` given to `text.create` keeps the characters' fill. Type made with a graphic
style's look takes the style's opacity and blend mode and is linked to it; otherwise the type keeps its own opacity and
blend mode. New art and type are linked to the style only in the document the style was picked in, or the selection
it was taken from was in; in another document they take the look, with the style's opacity and blend mode, without
the link. When text wrap moves new area type as it is made (an Auto Size frame below a wrap object grows), the
the link. A style redefined after it was picked gives new art and type the look picked, without the link, its isolate
or its knockout. When text wrap moves new area type as it is made (an Auto Size frame below a wrap object grows), the
template's placed gradients fit the frame the type ends with. Area type made with `text.create` and `area` takes the
template too; Type on a Path and area type made with `text.createInPath` keep the default appearance.
`appearance.setNewArtBasic` rejects an `on` value that is not a boolean. Omitting `on` toggles the current preference.