mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 12:27:37 +00:00
New Document: a profile's redefined Default Graphic Style sets the starting fill and stroke
When a New Document profile's Default Graphic Style differs from the shipped one (white fill, 1 pt black stroke), file.new resets new art in documents from that profile to the style's fills, strokes and effects, not linked to the style. Default Fill and Stroke (paint.default, D) gives the defaults and the selected art the same look in those documents; type still gets a black fill and no stroke. A profile with the shipped style leaves the current fill and stroke as they were. Part of #8350
This commit is contained in:
@@ -7,12 +7,16 @@
|
||||
//! panel's New Art Has Basic Appearance off, the whole appearance of the last selection. With the
|
||||
//! option on (the default) an inherited appearance gives new art its top stroke's options only,
|
||||
//! and a change of selection loads only the proxies. `paint.default` resets it.
|
||||
//!
|
||||
//! A document whose Default Graphic Style no longer has the shipped look (a New Document profile
|
||||
//! redefined it) gives the reset that style's fills, strokes and effects instead, and `file.new`
|
||||
//! resets new art when it opens such a document.
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::{BlendMode, Paint};
|
||||
use vectorcraft_doc::{Appearance, AppearanceItem, FillLayer, GraphicStyle, Node, NodeKind, StrokeLayer};
|
||||
use vectorcraft_doc::{Appearance, AppearanceItem, ColorMode, DEFAULT_GRAPHIC_STYLE, Document, FillLayer, GraphicStyle, Node, NodeKind, StrokeLayer};
|
||||
use vectorcraft_tools::PaintDefaults;
|
||||
|
||||
use super::gradient::unplaced;
|
||||
@@ -263,7 +267,35 @@ fn describe(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
}))
|
||||
}
|
||||
|
||||
/// The defaults for new art reset (`paint.default`): white fill, 1 pt black stroke, no template.
|
||||
/// The defaults for new art reset (`paint.default`): white fill, 1 pt black stroke, no template;
|
||||
/// in a document whose Default Graphic Style was redefined, that style's fills, strokes and effects
|
||||
/// at full opacity, not linked to the style.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// `d`'s Default Graphic Style when its fills, strokes, effects or transparency differ from the
|
||||
/// shipped style's (white fill, 1 pt black stroke), the shipped colors converted to `d`'s color mode
|
||||
/// as a New Document profile's are.
|
||||
pub(crate) fn redefined_default_style(d: &Document) -> Option<&GraphicStyle> {
|
||||
let g = d.graphic_styles.iter().find(|g| g.name == DEFAULT_GRAPHIC_STYLE)?;
|
||||
let same =
|
||||
|o: &GraphicStyle| (&o.appearance, o.opacity, o.blend, o.isolate, o.knockout) == (&g.appearance, g.opacity, g.blend, g.isolate, g.knockout);
|
||||
if same(&GraphicStyle::new(DEFAULT_GRAPHIC_STYLE, Appearance::default_art())) {
|
||||
return None;
|
||||
}
|
||||
if d.color_mode != ColorMode::Rgb {
|
||||
let mut shipped = Document::new_with_mode(1.0, 1.0, ColorMode::Rgb);
|
||||
shipped.graphic_styles.retain(|o| o.name == DEFAULT_GRAPHIC_STYLE);
|
||||
super::colormgmt::set_color_mode(&mut shipped, d.color_mode, true, None, super::colormgmt::Grays::Profile);
|
||||
if shipped.graphic_styles.first().is_some_and(same) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some(g)
|
||||
}
|
||||
|
||||
@@ -814,6 +814,10 @@ pub(crate) fn file_new(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// The profile's links keep their relative paths, which name places from the profile's file, as
|
||||
// a new document from a history state keeps its source's.
|
||||
s.doc_mut()?.links_from = links_from;
|
||||
// A profile whose Default Graphic Style was redefined gives new art in the document that style.
|
||||
if super::newart::redefined_default_style(&s.doc()?.doc).is_some() {
|
||||
super::newart::reset(s);
|
||||
}
|
||||
// Overprint Preview is the engine's (the UI turns Pixel Preview on from `previewMode`). Both
|
||||
// are views of the whole app, so Default leaves them as they are.
|
||||
if settings.preview_mode == PreviewMode::Overprint {
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Default Fill and Stroke",
|
||||
[],
|
||||
Some("D"),
|
||||
"{ids?|id?} white fill and 1 pt black stroke for the selection and the defaults; type gets black fill and no stroke. On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke, and on a graph label the black fill and no stroke of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (exceptions: docs/mcp.md)",
|
||||
"{ids?|id?} white fill and 1 pt black stroke for the selection and the defaults (in a document whose Default Graphic Style differs from the shipped one, as a New Document profile can redefine it: that style's fills, strokes and effects, without its opacity or a link to it); type gets black fill and no stroke. On a path directly in a graph series, the graph also stores the paint, weight, opacity and blend mode of the topmost visible fill and stroke, and on a graph label the black fill and no stroke of its characters for every label of its kind, and on a graph's axis line, tick mark or radar ring its rows for every line of its kind (exceptions: docs/mcp.md)",
|
||||
has_doc,
|
||||
default_paint
|
||||
),
|
||||
@@ -1035,6 +1035,8 @@ fn default_paint(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if !ids.is_empty() {
|
||||
// When every object comes out as it was, the document and its undo history stay as they are.
|
||||
let before = s.doc()?.doc.clone();
|
||||
// A redefined Default Graphic Style gives other art its fills, strokes and effects, placed on each object.
|
||||
let style = super::newart::redefined_default_style(&before).cloned();
|
||||
super::overprint::edit_counted(s, "Default Fill and Stroke", |d| {
|
||||
for id in &ids {
|
||||
let Some(n) = d.node_mut(*id) else { continue };
|
||||
@@ -1045,7 +1047,12 @@ fn default_paint(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
r.style.stroke = Paint::None;
|
||||
}
|
||||
}
|
||||
_ => n.appearance = Appearance::default_art().into(),
|
||||
_ => {
|
||||
n.appearance = match &style {
|
||||
Some(g) => g.appearance_on(n).into_owned().into(),
|
||||
None => Appearance::default_art().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let kept = super::appearance::capture_series_writes(&before, d, &ids, (true, true), (true, true), false, false);
|
||||
|
||||
@@ -637,6 +637,69 @@ fn an_edited_profile_starts_the_documents_of_its_category() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// The fill, stroke and weight of `id` in the active document.
|
||||
fn look(s: &Session, id: u64) -> (vectorcraft_color::Paint, vectorcraft_color::Paint, Option<f64>) {
|
||||
let n = s.doc().unwrap().doc.node(vectorcraft_doc::NodeId(id)).cloned().unwrap();
|
||||
(n.appearance.fill_paint(), n.appearance.stroke_paint(), n.appearance.stroke().map(|st| st.width))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_redefined_default_graphic_style_in_a_profile_is_the_default_fill_and_stroke() {
|
||||
use vectorcraft_color::Paint;
|
||||
let (mut s, dir) = with_profiles("default-style");
|
||||
// The Print profile's Default Graphic Style becomes no fill and a 0.25 pt red stroke.
|
||||
s.execute("file.newProfiles.edit", &json!({"name": "Print"})).unwrap();
|
||||
s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap();
|
||||
s.execute("paint.setFill", &json!({"none": true})).unwrap();
|
||||
s.execute("paint.setStroke", &json!({"color": "#ff0000"})).unwrap();
|
||||
s.execute("stroke.set", &json!({"weight": 0.25})).unwrap();
|
||||
s.execute("graphicStyle.redefine", &json!({"name": "Default Graphic Style"})).unwrap();
|
||||
s.execute("document.save", &json!({})).unwrap();
|
||||
let style = s.doc().unwrap().doc.graphic_styles[0].clone();
|
||||
let red = style.appearance.stroke_paint();
|
||||
assert!(matches!(red, Paint::Solid { .. }), "{red:?}");
|
||||
assert_eq!(style.appearance.stroke().map(|st| st.width), Some(0.25), "{style:?}");
|
||||
// The Mobile profile is saved as shipped.
|
||||
s.execute("file.newProfiles.edit", &json!({"name": "Mobile"})).unwrap();
|
||||
s.execute("document.save", &json!({})).unwrap();
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
s.execute("paint.setFill", &json!({"color": "#00ff00"})).unwrap();
|
||||
let green = s.paint.fill.clone();
|
||||
|
||||
// A document from the Print profile starts with the style's fill, stroke and weight, and its art takes them.
|
||||
s.execute("file.new", &json!({"profile": "Print", "colorMode": "cmyk"})).unwrap();
|
||||
assert_eq!((s.paint.fill.clone(), s.paint.stroke.clone(), s.paint.stroke_width), (Paint::None, red.clone(), 0.25));
|
||||
let id = s.execute("shape.rectangle", &json!({"x": 20, "y": 20, "width": 60, "height": 60})).unwrap()["id"].as_u64().unwrap();
|
||||
assert_eq!(look(&s, id), (Paint::None, red.clone(), Some(0.25)));
|
||||
// Default Fill and Stroke gives the selection and the defaults that look again, as one undo step.
|
||||
s.execute("paint.setFill", &json!({"color": "#0000ff"})).unwrap();
|
||||
s.execute("stroke.set", &json!({"weight": 3})).unwrap();
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
s.execute("paint.default", &json!({})).unwrap();
|
||||
assert_eq!(look(&s, id), (Paint::None, red.clone(), Some(0.25)));
|
||||
assert_eq!((s.paint.fill.clone(), s.paint.stroke_width), (Paint::None, 0.25));
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1);
|
||||
// Nothing to change: no undo step.
|
||||
let step = s.doc().unwrap().history.step();
|
||||
s.execute("paint.default", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().history.step(), step);
|
||||
// The new art is not linked to the style.
|
||||
assert!(s.doc().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap().extras().graphic_style.is_none());
|
||||
|
||||
// A profile with the shipped style, here converted to CMYK, leaves the fill and stroke the user chose.
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
s.execute("paint.setFill", &json!({"color": "#00ff00", "keepModel": true})).unwrap();
|
||||
s.execute("file.new", &json!({"profile": "Mobile", "colorMode": "cmyk"})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.color_mode, ColorMode::Cmyk);
|
||||
assert_eq!(s.paint.fill, green);
|
||||
// So does a document without a profile, and Default Fill and Stroke there gives white and 1 pt black.
|
||||
s.execute("file.new", &json!({})).unwrap();
|
||||
assert_eq!(s.paint.fill, green);
|
||||
s.execute("paint.default", &json!({})).unwrap();
|
||||
assert_eq!(s.paint, vectorcraft_tools::PaintDefaults::default());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_profile_follows_the_preset_access_and_reset() {
|
||||
let (mut s, dir) = with_profiles("choice");
|
||||
|
||||
@@ -7512,6 +7512,15 @@ starts with one empty layer. The grid comes from Preferences › Guides & Grid,
|
||||
preset's color mode differs from the profile's, the profile's colors are converted as `file.documentColorMode`
|
||||
converts them.
|
||||
|
||||
A profile also sets the default fill and stroke of its documents (VectorCraft's own rule). When the profile's Default
|
||||
Graphic Style differs from the shipped one (white fill, 1 pt black stroke, with the shipped colors converted to the
|
||||
document's color mode), `file.new` resets new art to that style's fills, strokes and effects, at full opacity and not
|
||||
linked to the style, and `paint.default` (Default Fill and Stroke) gives the defaults and the selected art the same
|
||||
look; type still gets a black fill and no stroke. With the shipped style, `file.new` leaves the fill and stroke as they
|
||||
were. For example, to start with no fill and a 0.25 pt red stroke: edit the profile with `file.newProfiles.edit`, draw a
|
||||
path with that fill and stroke, select it, run `graphicStyle.redefine {name: "Default Graphic Style"}`, delete the
|
||||
path and save.
|
||||
|
||||
A built-in preset names its category's profile in `file.newPresets` (`profile`). Saved and Recent presets keep the
|
||||
profile of the preset they were made from. `file.new {profile: "Print"}` picks a profile for any settings, and
|
||||
`profile: null` starts with the defaults. A document made without a preset starts with the defaults.
|
||||
|
||||
@@ -820,6 +820,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **New Document's units:** the dialog opens in Preferences › Units › General, also on a Recent entry made in other units (an entry in pixels, or a saved preset in the units it was saved in, keeps its units), so File › New and New Without Dialog make documents in the General unit. Units chosen in the Units menu stay when another tab or preset is chosen and when a card is clicked or double-clicked; without such a choice, clicking another Recent or Saved card brings back the units that card was made in (#7944). These are VectorCraft's own rules. Tests: `the_dialog_opens_in_the_general_units_over_a_recent_entry`, `a_recent_saved_preset_keeps_its_units_and_name`, `units_chosen_in_the_menu_survive_tabs_and_presets` and `units_set_over_a_popup_stay_chosen` in `dialogs/new_document.rs`; `a_recent_card_keeps_the_units_chosen_in_the_menu` and `a_double_clicked_card_keeps_the_units_chosen_in_the_menu` in `panels/tests_units.rs`.
|
||||
- **New Document's More Settings and Save Preset:** More Settings opens a pop-up over New Document with only Number of Artboards, the artboard layout, Change to Right-to-Left Layout, Spacing and Columns; Done, Escape or a click outside closes it and keeps the values. Save Preset turns the top of Preset Details into a Save Document Preset heading with the preset's name, Cancel and Save, and hides the document's name, Close and Create until the preset is saved or canceled; nothing in that mode creates a document. Save Preset's default name is the first "Preset N" no saved preset has. VectorCraft's own layout. Harness tests in `dialogs/new_document.rs` cover both.
|
||||
- **New Document profiles:** each built-in category's presets start documents from that category's profile, a native document holding the starting swatches, graphic styles, brushes, symbols and other assets, the ruler and Document Setup options and the print settings ([Create a custom new document profile](https://helpx.adobe.com/illustrator/desktop/add-and-import-files/start-a-new-file/create-a-custom-new-document-profile.html)). New Document's Manage Profiles pop-up opens a profile to edit and resets one to the shipped profile (`file.newProfiles`, `file.newProfiles.edit`, `file.newProfiles.reset`; `file.new {profile}`). The profiles live in VectorCraft's own `New Document Profiles` folder next to the preferences; a profile that cannot be read or is larger than 64 MiB leaves the defaults and is reported. Tests: `tests::newdoc::an_edited_profile_starts_the_documents_of_its_category`, `the_profile_follows_the_preset_access_and_reset`, `profile_errors_name_the_file_by_its_name_outside_the_read_roots`, `a_damaged_or_oversized_profile_leaves_the_defaults_and_is_reported`, `profile_names_are_checked_and_editing_needs_the_folder`, `dialogs::new_document::tests::manage_profiles_edits_and_resets_the_profiles`.
|
||||
- **Default fill and stroke from a profile:** when a New Document profile's Default Graphic Style is redefined (for example no fill and a 0.25 pt red stroke), documents from that profile start new art with that style's fills, strokes and effects, and Default Fill and Stroke (`paint.default`, D) gives the defaults and the selection the same look in those documents (VectorCraft's own rule). Test: `tests::newdoc::a_redefined_default_graphic_style_in_a_profile_is_the_default_fill_and_stroke`.
|
||||
- **Control bar with the Artboard tool:** while the Artboard tool is in use, the Control bar shows the active artboard's controls in place of the object controls: Preset, Portrait and Landscape, New Artboard, Delete Artboard, the Name field, Artboard Options, Rearrange All Artboards, the Transform link, Move and Scale Artwork with Artboard and, while the bar has room, the reference point with X and Y, and W and H with the Constrain Width and Height Proportions link. Each runs the command its Properties or Transform panel counterpart runs (`artboard.setProps`, `artboard.new`, `artboard.delete`, `tool.options {tool: "artboard"}`), and the reference point is the one the Transform panel uses. In an 800-point window the controls up to the Transform link fit, Move and Scale Artwork with Artboard show as their boxes alone with their names in tooltips, and the link opens the Transform panel with the artboard's position and size. Pointer and key tests in `panels/artboards.rs` cover the controls, W about the reference point, the orientation and the name. Public reference: [Using multiple artboards](https://web.archive.org/web/20210925094818/https://helpx.adobe.com/illustrator/using/using-multiple-artboards.html) (archived copy).
|
||||
- **Names of new and renamed artboards, brushes and patterns:** `artboard.new` and `artboard.setProps` trim the white space around the name they are given, as the Artboards panel's rename does, and a blank name gives the artboard its default name, Artboard N for the Nth artboard. `brush.new`, `brush.duplicate`, `brush.options`, `object.pattern.make`, `object.pattern.saveCopy` and `pattern.options` trim the name as the Brush Options dialog and the Pattern Options panel do, and compare the trimmed name with the names there are; a blank name gives the name each command gives when there is none, and Brush Options and Pattern Options keep the name. Tests in `tests/panelcmds.rs`, `tests/brushsym.rs` and `tests/pattern.rs` cover each command. Public references: [Using multiple artboards](https://web.archive.org/web/20210925094818/https://helpx.adobe.com/illustrator/using/using-multiple-artboards.html), [Brushes](https://web.archive.org/web/20251018101754/https://helpx.adobe.com/illustrator/using/brushes.html) and [Create and edit patterns](https://web.archive.org/web/20211031180358/https://helpx.adobe.com/illustrator/using/create-edit-patterns.html) (archived copies).
|
||||
- **Repeated brush names in a file:** a document or brush library file whose brushes repeat a name opens with the first brush of that name as stored and each later one numbered, as "Name 2", "Name 3" and so on, skipping names the file already has. Strokes that name the brush keep drawing the first one, and `brush.list`, `brush.options`, `brush.delete`, `brush.library` and the Brushes panel then reach each brush by its own name. This numbering is VectorCraft's own rule. Tests in `crates/brush/src/tests.rs`, `tests/brushsym.rs` and `tests/brushlib.rs` cover it.
|
||||
|
||||
Reference in New Issue
Block a user