Type: new type's style link stays in its document, gradients fit the wrapped frame

New art and type took the graphic style picked with nothing selected by
its name, so in another document they were linked to a style of the same
name there, and took its isolate and knockout. The template now records
the document the style came from, and new art elsewhere takes the look
without the link.

New area type that text wrap moves as it is made (an Auto Size frame
below a wrap object grows) had the template's placed gradients fitted to
the frame before the reflow. Both ways of making type now let text wrap
reflow it first and fit the gradients to the frame it ends with; type
whose bounds do not change keeps its placement.

The docs name text.create as the command whose type takes the template,
state that Type on a Path and Area Type keep the default appearance, and
note that a color given to text.create keeps the characters' fill under
Override Character Color.
This commit is contained in:
dotCooCoo
2026-12-04 23:35:05 -08:00
parent e35d10ebbf
commit cdfcef172f
7 changed files with 126 additions and 19 deletions
+25 -1
View File
@@ -174,7 +174,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Create Text",
[],
None,
"{x, y, text, parent?: id (a shown, unlocked layer or group: the type goes on top of its contents, whatever the drawing mode; default: where the Type tools put new type), rotation?: deg clockwise about x, y (0: level), vertical?: bool = false, size?: pt 0.1..1296 (outside it: an error, and no type is made), font?: family, style? (default Regular, or the family's closest style when it has no Regular), color? (#rrggbbaa and #rgba are refused; size, font, style and color left out come from [Normal Character Style], the defaults unless the document redefined it), keepModel?: bool (as paint.setFill), area?: {width, height, fit?: none|autoHeight|shrinkText|block, fitMinPercent?, wordGap?, lineGap? (as text.areaOptions)}, placeholder?: bool (fill it with placeholder text instead, as the Type tools do with prefs placeholderText), justify?: \"auto\" (default: the start of each paragraph's direction)|\"left\"|\"center\"|\"right\"|\"justifyAll\" (point type: aligned on x, so \"center\" centres each line on the point and \"right\" ends it there; text.setStyle changes it later), leadingModel?: \"romanBaseline\"|\"emBoxTop\", charAlign?: \"romanBaseline\"|\"emBoxTop\"|\"emBoxCenter\"|\"emBoxBottom\"|\"icfTop\"|\"icfBottom\" (default: emBoxTop and emBoxCenter while the interface is in Japanese, else romanBaseline)} → {id, bounds: {x, y, width, height} (the new type's box as document.inspect reports it, after justify), overflow?: [id] (area type whose text doesn't fit its frame: the lines past it aren't drawn; left out when it fits), warning?: text (the font or style given isn't available: the type is drawn in the fallback font or the family's closest style)}; new area type gets Auto Size (fit autoHeight) when the autoSizeAreaType preference is on. When new art's template is more than one plain fill and stroke (New Art Has Basic Appearance off) or comes from a graphic style picked with nothing selected, the type takes its fills, strokes and effects, and with Override Character Color on its characters lose the fill and stroke those paint (a `color` given keeps the fill); type with a style's look also takes the style's opacity and blend mode and is linked to it",
"{x, y, text, parent?: id (a shown, unlocked layer or group: the type goes on top of its contents, whatever the drawing mode; default: where the Type tools put new type), rotation?: deg clockwise about x, y (0: level), vertical?: bool = false, size?: pt 0.1..1296 (outside it: an error, and no type is made), font?: family, style? (default Regular, or the family's closest style when it has no Regular), color? (#rrggbbaa and #rgba are refused; size, font, style and color left out come from [Normal Character Style], the defaults unless the document redefined it), keepModel?: bool (as paint.setFill), area?: {width, height, fit?: none|autoHeight|shrinkText|block, fitMinPercent?, wordGap?, lineGap? (as text.areaOptions)}, placeholder?: bool (fill it with placeholder text instead, as the Type tools do with prefs placeholderText), justify?: \"auto\" (default: the start of each paragraph's direction)|\"left\"|\"center\"|\"right\"|\"justifyAll\" (point type: aligned on x, so \"center\" centres each line on the point and \"right\" ends it there; text.setStyle changes it later), leadingModel?: \"romanBaseline\"|\"emBoxTop\", charAlign?: \"romanBaseline\"|\"emBoxTop\"|\"emBoxCenter\"|\"emBoxBottom\"|\"icfTop\"|\"icfBottom\" (default: emBoxTop and emBoxCenter while the interface is in Japanese, else romanBaseline)} → {id, bounds: {x, y, width, height} (the new type's box as document.inspect reports it, after justify), overflow?: [id] (area type whose text doesn't fit its frame: the lines past it aren't drawn; left out when it fits), warning?: text (the font or style given isn't available: the type is drawn in the fallback font or the family's closest style)}; new area type gets Auto Size (fit autoHeight) when the autoSizeAreaType preference is on. When new art's template is more than one plain fill and stroke (New Art Has Basic Appearance off) or comes from a graphic style picked with nothing selected, the type takes its fills, strokes and effects, and with Override Character Color on its characters lose the fill and stroke those paint (a `color` given keeps the fill); type with a style's look also takes the style's opacity and blend mode and is linked to it (in the document the style was picked in; elsewhere it is not linked), and its placed gradients fit the frame text wrap gives it",
has_doc,
text_create
),
@@ -255,6 +255,7 @@ fn insert_look_turned(
}
n.name = name;
n.bbox_angle = bbox_angle;
let pre = wrap_snapshot(d, &n, &look);
let mut into = None;
match (mode, inside) {
(crate::DrawMode::Inside, Some(target)) if d.node(target).is_some() => {
@@ -274,6 +275,7 @@ fn insert_look_turned(
d.insert(parent, usize::MAX, n)?;
}
}
place_after_wrap(d, pre, id, &look);
if select {
sel.set([id]);
}
@@ -995,13 +997,35 @@ fn insert_text_into(s: &mut Session, parent: NodeId, kind: NodeKind, look: NewAr
look.apply(d, &mut n);
super::object::align_new_object(d, &mut n);
n.bbox_angle = bbox_angle;
let pre = wrap_snapshot(d, &n, &look);
d.insert(Some(parent), usize::MAX, n)?;
place_after_wrap(d, pre, id, &look);
sel.set([id]);
Ok(id)
})?;
Ok(json!({ "id": id.0 }))
}
/// The document before new type `n` goes in, when `look` places gradients on it: text wrap can
/// reflow the type once it is in ([`place_after_wrap`]).
fn wrap_snapshot(d: &vectorcraft_doc::Document, n: &Node, look: &NewArt) -> Option<vectorcraft_doc::Document> {
(matches!(n.kind, NodeKind::Text(_)) && look.places_gradients()).then(|| d.clone())
}
/// New type `id` just inserted into `d` (`pre`: `d` before, from [`wrap_snapshot`]): text wrap
/// reflows it now, and when that changes its bounds (an Auto Size frame below a wrap object grows),
/// `look`'s gradients are placed on the bounds it ends with.
fn place_after_wrap(d: &mut vectorcraft_doc::Document, pre: Option<vectorcraft_doc::Document>, id: NodeId, look: &NewArt) {
let Some(pre) = pre else { return };
let placed_on = d.node(id).and_then(Node::geometric_bounds);
super::textwrap::refresh(&pre, d);
if let Some(n) = d.node_mut(id)
&& n.geometric_bounds() != placed_on
{
look.place(n);
}
}
fn text_create(s: &mut Session, p: &Value) -> Result<Value> {
let parent = text_parent(s, p)?;
let x = f64_req(p, "x", "text.create")?;
+29 -11
View File
@@ -294,13 +294,7 @@ impl NewArt {
/// it links to the style, taking its isolate and knockout too (type keeps its own transparency
/// unless the look is a graphic style's).
pub(crate) fn apply(&self, d: &mut vectorcraft_doc::Document, n: &mut Node) {
n.appearance = self.appearance.clone().into();
if self.unit_box
&& n.appearance.has_placed_gradient()
&& let Some(b) = n.geometric_bounds()
{
n.appearance.rebase_gradients(GraphicStyle::UNIT_BOX, b);
}
self.place(n);
if matches!(n.kind, NodeKind::Text(_)) && self.style.is_none() {
return;
}
@@ -311,6 +305,21 @@ impl NewArt {
}
n.extras_mut().graphic_style = style.map(|i| d.graphic_style_id(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();
if self.places_gradients()
&& let Some(b) = n.geometric_bounds()
{
n.appearance.rebase_gradients(GraphicStyle::UNIT_BOX, b);
}
}
/// Does this look place gradients on the bounds of the object it is given to?
pub(crate) fn places_gradients(&self) -> bool {
self.unit_box && self.appearance.has_placed_gradient()
}
}
impl Session {
@@ -360,9 +369,16 @@ impl Session {
self.new_art_look(self.paint.fill.clone(), self.paint.stroke.clone(), self.paint.stroke_width).appearance
}
/// The opacity, blend mode and graphic style (name) of the next object drawn.
/// The opacity, blend mode and graphic style (name) of the next object drawn. The style is
/// left out in a document other than the one it was taken from, so new art there is not
/// linked to a style of the same name.
pub fn new_art_transparency(&self) -> (f32, BlendMode, Option<&str>) {
if self.basic_only() { (1.0, BlendMode::Normal, None) } else { (self.paint.opacity, self.paint.blend, self.paint.style.as_deref()) }
if self.basic_only() {
return (1.0, BlendMode::Normal, None);
}
let here = self.active().map(|st| st.uid);
let style = self.paint.style.as_deref().filter(|_| self.paint.style_doc.is_some() && self.paint.style_doc == here);
(self.paint.opacity, self.paint.blend, style)
}
/// The stroke of the next object drawn (the Stroke panel shows it with nothing selected).
@@ -409,14 +425,16 @@ impl Session {
}
/// Make `ap` (placed gradients relative to the unit box) and this transparency the template,
/// and its top fill, stroke and weight the proxies.
/// and its top fill, stroke and weight the proxies. `style` is a graphic style of the
/// document in front.
fn take_new_art(&mut self, ap: Appearance, opacity: f32, blend: BlendMode, style: Option<String>, inherited: bool) {
let style_doc = style.as_ref().and_then(|_| self.active().map(|st| st.uid));
let p = &mut self.paint;
(p.fill, p.stroke) = (unplaced(&ap.fill_paint()), unplaced(&ap.stroke_paint()));
if let Some(st) = ap.stroke() {
p.stroke_width = st.width;
}
(p.appearance, p.opacity, p.blend, p.style, p.inherited) = (Some(ap), opacity, blend, style, inherited);
(p.appearance, p.opacity, p.blend, p.style, p.style_doc, p.inherited) = (Some(ap), opacity, blend, style, style_doc, inherited);
}
/// After each command: with New Art Has Basic Appearance off, new art takes the appearance of
+6 -4
View File
@@ -414,7 +414,7 @@ impl Session {
// parts it left alone keep the interaction's. The pattern lists every field, so a field
// added to `PaintDefaults` does not compile until it is handled here. The paints a preview
// took its new-art paints over from take the change as well.
let vectorcraft_tools::PaintDefaults { fill, stroke, stroke_width, appearance, opacity, blend, style, inherited } = &self.paint;
let vectorcraft_tools::PaintDefaults { fill, stroke, stroke_width, appearance, opacity, blend, style, style_doc, inherited } = &self.paint;
for start in std::iter::once(&mut it.paint).chain(it.inherited_preview_paint.as_mut()) {
if *fill != paint.fill {
start.fill.clone_from(fill);
@@ -434,8 +434,9 @@ impl Session {
if *blend != paint.blend {
start.blend = *blend;
}
if *style != paint.style {
if *style != paint.style || *style_doc != paint.style_doc {
start.style.clone_from(style);
start.style_doc = *style_doc;
}
if *inherited != paint.inherited {
start.inherited = *inherited;
@@ -917,7 +918,7 @@ fn take_changed_paints(
left: &vectorcraft_tools::PaintDefaults,
now: &vectorcraft_tools::PaintDefaults,
) {
let vectorcraft_tools::PaintDefaults { fill, stroke, stroke_width, appearance, opacity, blend, style, inherited } = now;
let vectorcraft_tools::PaintDefaults { fill, stroke, stroke_width, appearance, opacity, blend, style, style_doc, inherited } = now;
if left.fill != *fill {
target.fill.clone_from(fill);
}
@@ -936,8 +937,9 @@ fn take_changed_paints(
if left.blend != *blend {
target.blend = *blend;
}
if left.style != *style {
if left.style != *style || left.style_doc != *style_doc {
target.style.clone_from(style);
target.style_doc = *style_doc;
}
if left.inherited != *inherited {
target.inherited = *inherited;
+57
View File
@@ -592,3 +592,60 @@ fn a_basic_graphic_style_picked_with_basic_appearance_off_styles_each_new_type()
run(&mut s, "select.none", json!({}));
}
}
#[test]
fn new_type_that_text_wrap_moves_takes_the_styles_gradient_on_the_frame_it_ends_with() {
let mut s = session();
let group = run(&mut s, "object.newGroup", json!({}))["id"].as_u64().unwrap();
run(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 100, "height": 80}));
// A placed vertical gradient, top to bottom of the rectangle.
let stops = json!([{"offset": 0, "color": "#ffffff"}, {"offset": 1, "color": "#000000"}]);
run(&mut s, "paint.setFill", json!({"gradient": {"stops": stops, "start": [50, 0], "end": [50, 80]}}));
let name = run(&mut s, "graphicStyle.new", json!({"name": "Vertical"}))["name"].as_str().unwrap().to_string();
run(&mut s, "object.textWrap.make", json!({"offset": 0}));
let style = s.doc().unwrap().doc.graphic_styles.iter().find(|g| g.name == name).unwrap().clone();
assert!(style.unit_box && style.appearance.has_placed_gradient());
let area = json!({"width": 100, "height": 20, "fit": "autoHeight"});
// Drawn behind the wrap object, and placed into a group below it.
for p in [
json!({"x": 0, "y": 0, "text": "a", "size": 12, "area": area}),
json!({"x": 0, "y": 0, "text": "a", "size": 12, "area": area, "parent": group}),
] {
run(&mut s, "select.none", json!({}));
run(&mut s, "view.drawMode", json!({"mode": if p.get("parent").is_some() { "normal" } else { "behind" }}));
run(&mut s, "graphicStyle.apply", json!({"name": name}));
let n = new_type(&mut s, p.clone());
let b = n.geometric_bounds().unwrap();
assert!(b.height() > 80.0, "the frame grows below the wrap object: {b:?} ({p})");
let mut placed = style.appearance.clone();
placed.rebase_gradients(vectorcraft_doc::GraphicStyle::UNIT_BOX, b);
assert_eq!(*n.appearance, placed, "{p}");
}
}
#[test]
fn new_art_in_another_document_is_not_linked_to_a_style_of_the_same_name() {
let mut s = session();
fancy(&mut s);
run(&mut s, "transparency.set", json!({"knockout": "on", "isolate": true}));
run(&mut s, "graphicStyle.new", json!({"name": "Shared"}));
run(&mut s, "select.none", json!({}));
run(&mut s, "graphicStyle.apply", json!({"name": "Shared"}));
run(&mut s, "file.new", json!({"width": 400, "height": 300}));
rect(&mut s, 20.0);
run(&mut s, "graphicStyle.new", json!({"name": "Shared"}));
for (make, p) in
[("shape.rectangle", json!({"x": 200, "y": 200, "width": 40, "height": 30})), ("text.create", json!({"x": 200, "y": 200, "text": "k"}))]
{
run(&mut s, "select.none", json!({}));
let id = NodeId(run(&mut s, make, p)["id"].as_u64().unwrap());
let n = node(&s, id);
assert_eq!((n.extras().graphic_style, n.isolate), (None, false), "{make}");
assert_eq!(n.appearance.effects.len(), 1, "{make} keeps the template's look");
}
// Back in the document the style came from, new art is linked to it again.
s.set_active(0);
run(&mut s, "select.none", json!({}));
run(&mut s, "text.create", json!({"x": 200, "y": 200, "text": "k"}));
assert_eq!(s.selection_graphic_style().map(|(g, linked)| (g.name.clone(), linked)), Some(("Shared".to_string(), true)));
}
+3
View File
@@ -25,6 +25,8 @@ pub struct PaintDefaults {
pub blend: vectorcraft_color::BlendMode,
/// The graphic style the template came from (by name): new art is linked to it.
pub style: Option<String>,
/// The document `style` is in (its session id): new art in another document is not linked.
pub style_doc: Option<u64>,
/// The template is the last selection's appearance (New Art Has Basic Appearance off): with
/// the option on again, new art takes only its basic fill and stroke.
pub inherited: bool,
@@ -41,6 +43,7 @@ impl Default for PaintDefaults {
opacity: 1.0,
blend: Default::default(),
style: None,
style_doc: None,
inherited: false,
}
}
+4 -1
View File
@@ -11564,7 +11564,10 @@ and stroke or comes from a graphic style; otherwise it has no fills or strokes o
color. 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.
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 without the link. 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. Type on a Path and Area Type (`text.createInPath`) keep the default appearance.
`appearance.setNewArtBasic` rejects an `on` value that is not a boolean. Omitting `on` toggles the current preference.
`appearance.setNewArt {fill?, stroke?, weight?, cap?, join?, miterLimit?, dash?, dashOffset?, fillOverprint?,
strokeOverprint?}` sets new art's fill, stroke and stroke options whatever is selected, and leaves the selection, its
File diff suppressed because one or more lines are too long