mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 04:56:27 +00:00
Packaging Tools: Make … Line gives paths a fold line role that their swatch carries
Object › Plug-ins › Packaging Tools is a new built-in add-on for the dielines of boxes and other folded packaging. A path, compound path or live shape is a fold line when its top stroke is painted with the swatch of a line role: Cut, Crease, Partial Cut or Perforation. Each document has a role table (`packagingRoles`) that names the swatch of each role. By default the swatches are named after the roles. Native files keep the table and the strokes. PDF prints a role line on its swatch's separation when the swatch is a spot color, as the default role swatches are. SVG, DXF and HP-GL keep the stroke's color, so the default role swatches come out as four colors. - `addon.packaging.setRole` (Make Cut Line, Make Crease Line, Make Partial Cut Line, Make Perforation Line) paints the top stroke of each path among the objects with the role's swatch at 100%, through groups and clip groups. Locked and hidden objects are left out, also when named by id. A path without a stroke gets a 1 pt stroke, a hidden stroke is shown, and the stroke overprints unless `overprint` is false. A missing role swatch is made as a global spot swatch in the document's color mode (Cut 100% magenta, Crease 100% cyan, Partial Cut 100% yellow, Perforation 50% magenta and 50% cyan). When a color group or a swatch that can't carry a role has that name, the swatch is made as "Cut 2" and so on. `none` takes the role away and keeps the color. One undo step, none when nothing changes. - `addon.packaging.roles` counts each role in the selection, or in the document while nothing is selected, locked and hidden lines included. The Fold Lines panel shows these counts, gives the selected paths a role when a row is clicked, and says when nothing is selected. - `addon.packaging.setRoleSwatch` (the panel menu's Role Swatches…) makes another global or spot color swatch carry a role. It refuses missing, gradient, pattern, process, tint, [None] and [Registration] swatches and a swatch another role has. When `swatch.edit` renames a role swatch, the role stays with it under the new name. When it turns Global off, the role moves to a new swatch name that the next Make … Line makes. When `swatch.merge` merges a role swatch into a global swatch that carries no role, the kept swatch takes the role. Docs: docs/mcp.md (Packaging Tools add-on) and ROADMAP.
This commit is contained in:
@@ -8,6 +8,7 @@ mod contour;
|
||||
mod cutting;
|
||||
mod document;
|
||||
mod image;
|
||||
mod packaging;
|
||||
mod pathtools;
|
||||
mod pen;
|
||||
mod select;
|
||||
@@ -15,6 +16,7 @@ mod shapes;
|
||||
mod typetools;
|
||||
|
||||
pub(crate) use image::{DecodedImages, refresh_color_masks};
|
||||
pub(crate) use packaging::{role_swatch_edited, role_swatches_merged};
|
||||
|
||||
use super::CommandSpec;
|
||||
|
||||
@@ -27,6 +29,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
v.extend(cutting::specs());
|
||||
v.extend(document::specs());
|
||||
v.extend(image::specs());
|
||||
v.extend(packaging::specs());
|
||||
v.extend(pathtools::specs());
|
||||
v.extend(pen::specs());
|
||||
v.extend(select::specs());
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//! Packaging Tools (`addon.packaging.*`), a built-in add-on for the dielines of boxes and other
|
||||
//! folded packaging. A path is a fold line when its top stroke is painted with the swatch of a line
|
||||
//! role: Cut, Crease, Partial Cut or Perforation ([`roles`]). The document's role table maps each
|
||||
//! role to its swatch, so every format that keeps the stroke's swatch keeps the role. Its submenu
|
||||
//! (Object › Plug-ins › Packaging Tools) and its Fold Lines panel are the UI's.
|
||||
|
||||
mod roles;
|
||||
|
||||
pub(crate) use roles::{role_swatch_edited, role_swatches_merged};
|
||||
|
||||
use super::super::CommandSpec;
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
roles::specs()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,454 @@
|
||||
//! Fold line roles (`addon.packaging.setRole`, `addon.packaging.roles`,
|
||||
//! `addon.packaging.setRoleSwatch`). A path, compound path or live shape has a role when its top
|
||||
//! stroke is painted with the swatch the document's role table gives that role, at any tint. The
|
||||
//! table lives in [`Document::unknown`] under [`ROLES_KEY`], `{cut, crease, partialCut,
|
||||
//! perforation}` each naming a swatch; a role it leaves out, or names with something other than a
|
||||
//! string, takes its default swatch, named after the role.
|
||||
|
||||
use serde_json::{Map, Value, json};
|
||||
use vectorcraft_color::swatch::REGISTRATION;
|
||||
use vectorcraft_color::{Color, Paint, Swatch};
|
||||
use vectorcraft_doc::{Document, Node, NodeId, NodeKind};
|
||||
|
||||
use super::super::super::overprint::edit_counted;
|
||||
use super::super::super::{CommandSpec, bad, checked_ids_or_selection, cmd, has_doc, has_selection, switch_or, text_param};
|
||||
use crate::{Result, Session};
|
||||
|
||||
/// Document unknown key: the role table, `{role id: swatch name}`.
|
||||
pub(crate) const ROLES_KEY: &str = "packagingRoles";
|
||||
|
||||
const SET_ROLE: &str = "addon.packaging.setRole";
|
||||
const ROLES: &str = "addon.packaging.roles";
|
||||
const SET_ROLE_SWATCH: &str = "addon.packaging.setRoleSwatch";
|
||||
|
||||
/// What a fold line does when the blank is cut and folded.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Role {
|
||||
/// Separates the material.
|
||||
Cut,
|
||||
/// A fold.
|
||||
Crease,
|
||||
/// A fold cut part way through the board.
|
||||
PartialCut,
|
||||
/// A fold along a line of cuts.
|
||||
Perforation,
|
||||
}
|
||||
|
||||
impl Role {
|
||||
pub(crate) const ALL: [Role; 4] = [Role::Cut, Role::Crease, Role::PartialCut, Role::Perforation];
|
||||
|
||||
/// The role's id in params and in the role table.
|
||||
pub(crate) fn id(self) -> &'static str {
|
||||
match self {
|
||||
Role::Cut => "cut",
|
||||
Role::Crease => "crease",
|
||||
Role::PartialCut => "partialCut",
|
||||
Role::Perforation => "perforation",
|
||||
}
|
||||
}
|
||||
|
||||
/// The role's name, which is also its default swatch's name.
|
||||
pub(crate) fn name(self) -> &'static str {
|
||||
match self {
|
||||
Role::Cut => "Cut",
|
||||
Role::Crease => "Crease",
|
||||
Role::PartialCut => "Partial Cut",
|
||||
Role::Perforation => "Perforation",
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_id(id: &str) -> Option<Role> {
|
||||
Role::ALL.into_iter().find(|r| r.id() == id)
|
||||
}
|
||||
|
||||
/// The color a missing role swatch is made with (VectorCraft's own values): Cut 100% magenta,
|
||||
/// Crease 100% cyan, Partial Cut 100% yellow, Perforation 50% magenta and 50% cyan.
|
||||
fn color(self) -> Color {
|
||||
match self {
|
||||
Role::Cut => Color::cmyk(0.0, 1.0, 0.0, 0.0),
|
||||
Role::Crease => Color::cmyk(1.0, 0.0, 0.0, 0.0),
|
||||
Role::PartialCut => Color::cmyk(0.0, 0.0, 1.0, 0.0),
|
||||
Role::Perforation => Color::cmyk(0.5, 0.5, 0.0, 0.0),
|
||||
}
|
||||
}
|
||||
|
||||
fn index(self) -> usize {
|
||||
Role::ALL.iter().position(|r| *r == self).unwrap_or(0)
|
||||
}
|
||||
}
|
||||
|
||||
/// The swatch each role is carried by, in [`Role::ALL`] order.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct RoleTable([String; 4]);
|
||||
|
||||
impl RoleTable {
|
||||
/// The document's role table, with each missing or damaged entry at its default. When a damaged
|
||||
/// table names one swatch for two roles, the later role takes its default name instead, or
|
||||
/// "Crease 2" and so on when an earlier role has that.
|
||||
pub(crate) fn of(d: &Document) -> RoleTable {
|
||||
let stored = d.unknown.get(ROLES_KEY).and_then(Value::as_object);
|
||||
let mut names: Vec<String> = Vec::with_capacity(Role::ALL.len());
|
||||
for r in Role::ALL {
|
||||
let name = match stored.and_then(|m| m.get(r.id())).and_then(Value::as_str) {
|
||||
Some(name) if !name.is_empty() && !names.iter().any(|n| n == name) => name.to_string(),
|
||||
_ => {
|
||||
let base = r.name();
|
||||
std::iter::once(base.to_string())
|
||||
.chain((2..).map(|i| format!("{base} {i}")))
|
||||
.find(|n| !names.contains(n))
|
||||
.unwrap_or_else(|| base.to_string())
|
||||
}
|
||||
};
|
||||
names.push(name);
|
||||
}
|
||||
RoleTable(Role::ALL.map(|r| names.get(r.index()).cloned().unwrap_or_else(|| r.name().to_string())))
|
||||
}
|
||||
|
||||
/// The swatch of `role`.
|
||||
pub(crate) fn swatch(&self, role: Role) -> &str {
|
||||
self.0.get(role.index()).map_or("", String::as_str)
|
||||
}
|
||||
|
||||
/// The role swatch `name` carries.
|
||||
pub(crate) fn role_of_swatch(&self, name: &str) -> Option<Role> {
|
||||
Role::ALL.into_iter().find(|r| self.swatch(*r) == name)
|
||||
}
|
||||
|
||||
/// The role of object `n`: the role of the swatch its top stroke is painted with.
|
||||
pub(crate) fn role_of(&self, n: &Node) -> Option<Role> {
|
||||
if !can_carry(n) {
|
||||
return None;
|
||||
}
|
||||
match &n.appearance.stroke()?.paint {
|
||||
Paint::Solid { swatch: Some(name), .. } => self.role_of_swatch(name),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Object(Role::ALL.into_iter().map(|r| (r.id().to_string(), json!(self.swatch(r)))).collect::<Map<_, _>>())
|
||||
}
|
||||
}
|
||||
|
||||
/// Swatch `from` of `d` is now named `to`, and `global` says whether it is still a global color.
|
||||
/// A role it carried keeps it under the new name, as the strokes linked to it do; when it stopped
|
||||
/// being global, which unlinks those strokes, the role moves to a new name that `setRole` makes a
|
||||
/// swatch for. Another role that named `to` without such a swatch moves to a new name too, so no
|
||||
/// two roles share a swatch.
|
||||
pub(crate) fn role_swatch_edited(d: &mut Document, from: &str, to: &str, global: bool) {
|
||||
let before = RoleTable::of(d);
|
||||
let mut table = before.clone();
|
||||
for r in Role::ALL {
|
||||
let name = table.swatch(r).to_string();
|
||||
let moved = if name == from && global {
|
||||
Some(to.to_string())
|
||||
} else if name == from || (name == to && from != to) {
|
||||
Some(free_role_name(d, &table, r))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let (Some(new), Some(slot)) = (moved, table.0.get_mut(r.index())) {
|
||||
*slot = new;
|
||||
}
|
||||
}
|
||||
if table != before {
|
||||
d.unknown.insert(ROLES_KEY.to_string(), table.to_value());
|
||||
}
|
||||
}
|
||||
|
||||
/// Swatches `merged` of `d` were merged into swatch `kept`, and `linked` says whether their strokes
|
||||
/// now link to it (it is a global color). When `kept` carries no role, it takes the role of the
|
||||
/// first merged swatch that carried one, so the lines of that role keep it; a merged swatch's other
|
||||
/// role keeps its name, which the next `setRole` makes a swatch for.
|
||||
pub(crate) fn role_swatches_merged(d: &mut Document, merged: &[String], kept: &str, linked: bool) {
|
||||
let mut table = RoleTable::of(d);
|
||||
if !linked || table.role_of_swatch(kept).is_some() {
|
||||
return;
|
||||
}
|
||||
let Some(role) = merged.iter().find_map(|m| table.role_of_swatch(m)) else { return };
|
||||
if let Some(slot) = table.0.get_mut(role.index()) {
|
||||
*slot = kept.to_string();
|
||||
}
|
||||
d.unknown.insert(ROLES_KEY.to_string(), table.to_value());
|
||||
}
|
||||
|
||||
/// A name for `role`'s swatch that no swatch, color group or other role of `table` uses: the
|
||||
/// role's name, else "Cut 2", "Cut 3"… The document holds finitely many names, so the search
|
||||
/// always ends at a free one.
|
||||
fn free_role_name(d: &Document, table: &RoleTable, role: Role) -> String {
|
||||
let free = |n: &str| !d.swatch_name_taken(n) && Role::ALL.into_iter().all(|r| r == role || table.swatch(r) != n);
|
||||
let base = role.name();
|
||||
if free(base) {
|
||||
return base.to_string();
|
||||
}
|
||||
(2usize..).map(|i| format!("{base} {i}")).find(|n| free(n)).unwrap_or_else(|| base.to_string())
|
||||
}
|
||||
|
||||
/// Whether `n` can carry a role: a path (a live shape too) that is neither a clipping path nor a
|
||||
/// guide, or a compound path.
|
||||
fn can_carry(n: &Node) -> bool {
|
||||
match &n.kind {
|
||||
NodeKind::Path { clipping, guide, .. } => !clipping && !guide,
|
||||
NodeKind::Compound { .. } => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The objects under the outermost objects `roots` that can carry a role, through groups and clip
|
||||
/// groups, each once, and
|
||||
/// how many of `roots` and their members can't (text, images, symbol instances and other objects).
|
||||
/// With `editable`, objects that are locked or hidden, are in a locked or hidden group or layer, or
|
||||
/// are on a locked artboard are left out and counted as skipped.
|
||||
fn role_targets(d: &Document, roots: &[NodeId], editable: bool) -> (Vec<NodeId>, usize) {
|
||||
fn walk(n: &Node, out: &mut Vec<NodeId>, skipped: &mut usize) {
|
||||
match &n.kind {
|
||||
NodeKind::Group { children, .. } => {
|
||||
for c in children {
|
||||
// A group's clipping path draws no stroke: it is skipped.
|
||||
if matches!(c.kind, NodeKind::Path { clipping: true, .. }) {
|
||||
*skipped += 1;
|
||||
} else {
|
||||
walk(c, out, skipped);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ if can_carry(n) => out.push(n.id),
|
||||
_ => *skipped += 1,
|
||||
}
|
||||
}
|
||||
let (mut out, mut skipped) = (vec![], 0);
|
||||
// A path of a compound path is painted with the compound's appearance: the compound takes the
|
||||
// role. `roots` come from `checked_ids_or_selection`, which keeps only outermost objects, so a
|
||||
// group and its member are never both roots.
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
let compound_of = |id: NodeId| d.parent_of(id).filter(|p| matches!(d.node(*p).map(|n| &n.kind), Some(NodeKind::Compound { .. })));
|
||||
for n in roots.iter().map(|id| compound_of(*id).unwrap_or(*id)).filter(|id| seen.insert(*id)).filter_map(|id| d.node(id)) {
|
||||
walk(n, &mut out, &mut skipped);
|
||||
}
|
||||
if editable {
|
||||
// Named directly or not, a locked or hidden object, or one in a locked or hidden group or
|
||||
// layer or on a locked artboard, stays as it is.
|
||||
let ok = d.editable();
|
||||
let before = out.len();
|
||||
out.retain(|id| ok(*id));
|
||||
skipped += before - out.len();
|
||||
}
|
||||
(out, skipped)
|
||||
}
|
||||
|
||||
/// Every object of the document that can carry a role, through layers and groups.
|
||||
fn document_targets(d: &Document) -> Vec<NodeId> {
|
||||
fn walk(n: &Node, out: &mut Vec<NodeId>) {
|
||||
match &n.kind {
|
||||
NodeKind::Layer { children, .. } | NodeKind::Group { children, .. } => children.iter().for_each(|c| walk(c, out)),
|
||||
_ if can_carry(n) => out.push(n.id),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut out = vec![];
|
||||
d.layers.iter().for_each(|l| walk(l, &mut out));
|
||||
out
|
||||
}
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![
|
||||
cmd!(
|
||||
"addon.packaging.setRole",
|
||||
"Make Fold Line",
|
||||
["Object", "Plug-ins", "Packaging Tools"],
|
||||
None,
|
||||
"{role: cut|crease|partialCut|perforation|none, ids?: [id…] (default: the selection), overprint?: bool (true)} give each path, compound path and live shape among the objects (through groups and clip groups; objects that are locked or hidden, in a locked or hidden group or layer, or on a locked artboard are left out and counted as skipped, even when named in ids) a fold line role: its top stroke is painted with the role's swatch (addon.packaging.roles) at 100% and shown, a path without a stroke gets a 1 pt stroke, and the stroke overprints, or with overprint: false does not. A missing role swatch is made as a global spot swatch (Cut 100% magenta, Crease 100% cyan, Partial Cut 100% yellow, Perforation 50% magenta and 50% cyan, in the document's color mode; named \"Cut 2\" and so on, in the role table too, when a color group or a swatch that can't carry a role, such as a process color that is not global, has the name). none takes the role away: a role stroke keeps the color it shows, no longer linked to the swatch, and stops overprinting. Text, images, symbol instances and other objects are skipped and counted. One undo step, none when nothing changes → {ids (the objects that can carry a role), changed, skipped}",
|
||||
has_selection,
|
||||
set_role
|
||||
),
|
||||
cmd!(
|
||||
query "addon.packaging.roles",
|
||||
"Fold Lines",
|
||||
[],
|
||||
None,
|
||||
"{ids?: [id…] (default: the selection)} the fold line roles → {roles: [{role: cut|crease|partialCut|perforation, name, swatch (the swatch that carries it), exists (the document has the swatch), count}], scope: ids|selection|document, selected (objects given or selected)}; count is how many of the paths, compound paths and live shapes among the objects (through groups, locked and hidden members included, each object once) have the role, or among every object of the document while nothing is selected and ids is left out",
|
||||
has_doc,
|
||||
roles
|
||||
),
|
||||
cmd!(
|
||||
"addon.packaging.setRoleSwatch",
|
||||
"Role Swatches…",
|
||||
["Object", "Plug-ins", "Packaging Tools"],
|
||||
None,
|
||||
"{role: cut|crease|partialCut|perforation, swatch: a global or spot color swatch's name} make the swatch carry the role, in the document's role table, as one undo step (none when it already does). Objects stroked with the role's old swatch keep their color and no longer have the role. Refused: a missing swatch, a gradient or pattern swatch, a process color that is not global, a tint swatch, [None], [Registration], and a swatch another role has → {role, swatch, changed}",
|
||||
has_doc,
|
||||
set_role_swatch
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
/// The role `p` gives: `Some(None)` for `none` when `none` is allowed.
|
||||
fn role_param(p: &Value, cmd: &str, none: bool) -> Result<Option<Role>> {
|
||||
let id = text_param(p, "role", cmd)?.ok_or_else(|| bad(cmd, "missing `role`"))?;
|
||||
match Role::from_id(id) {
|
||||
Some(r) => Ok(Some(r)),
|
||||
None if none && id == "none" => Ok(None),
|
||||
None if none => Err(bad(cmd, format!("unknown role `{id}`: cut, crease, partialCut, perforation or none"))),
|
||||
None => Err(bad(cmd, format!("unknown role `{id}`: cut, crease, partialCut or perforation"))),
|
||||
}
|
||||
}
|
||||
|
||||
/// Why swatch `name` of `d` can't carry a role, if it can't.
|
||||
fn unfit_swatch(d: &Document, name: &str) -> Option<String> {
|
||||
if name == REGISTRATION || name == "[None]" {
|
||||
return Some(format!("`{name}` can't carry a role"));
|
||||
}
|
||||
let Some(sw) = d.swatch(name) else { return Some(format!("no swatch `{name}`")) };
|
||||
match &sw.paint {
|
||||
Paint::Solid { swatch: Some(_), .. } => Some(format!("`{name}` is a tint swatch: pick its base or another global or spot color")),
|
||||
Paint::Solid { .. } if sw.global => None,
|
||||
Paint::Solid { .. } => Some(format!("`{name}` is a process color: pick a global or spot color")),
|
||||
_ => Some(format!("`{name}` isn't a color swatch")),
|
||||
}
|
||||
}
|
||||
|
||||
/// `role`'s swatch in `d`, made as a global spot swatch in the document's color mode when `d`
|
||||
/// lacks it → its paint at 100%. When a color group or a swatch that can't carry a role (a process
|
||||
/// color that is not global, a tint, a gradient) has the swatch's name, the swatch is made under a
|
||||
/// free name, which the role table then gives the role.
|
||||
fn role_paint(d: &mut Document, role: Role) -> Result<Paint> {
|
||||
let mut table = RoleTable::of(d);
|
||||
let current = table.swatch(role);
|
||||
let taken = match d.swatch(current) {
|
||||
Some(_) => unfit_swatch(d, current).is_some(),
|
||||
None => d.swatch_name_taken(current),
|
||||
};
|
||||
if taken {
|
||||
let free = free_role_name(d, &table, role);
|
||||
if let Some(slot) = table.0.get_mut(role.index()) {
|
||||
*slot = free;
|
||||
}
|
||||
d.unknown.insert(ROLES_KEY.to_string(), table.to_value());
|
||||
}
|
||||
let name = table.swatch(role);
|
||||
if d.swatch(name).is_none() {
|
||||
let model = d.color_mode.model();
|
||||
let color = role.color();
|
||||
let color = if color.model() == model {
|
||||
color
|
||||
} else {
|
||||
let cms = vectorcraft_color::cms::active();
|
||||
cms.convert(&color, model, cms.settings().intent)
|
||||
};
|
||||
d.swatches.push(Swatch { name: name.to_string(), paint: Paint::solid(color), global: true, spot: true });
|
||||
}
|
||||
if let Some(why) = unfit_swatch(d, name) {
|
||||
return Err(bad(SET_ROLE, format!("{why} (the {} role's swatch; addon.packaging.setRoleSwatch picks another)", role.name())));
|
||||
}
|
||||
d.tint_paint(name, 1.0).ok_or_else(|| bad(SET_ROLE, format!("`{name}` isn't a global or spot color")))
|
||||
}
|
||||
|
||||
/// Gives object `id` of `d` `role`'s `paint` (`None`: takes its role away) → whether it changed.
|
||||
fn give_role(d: &mut Document, table: &RoleTable, id: NodeId, paint: Option<&Paint>, overprint: bool) -> bool {
|
||||
let Some(n) = d.node_mut(id) else { return false };
|
||||
let had = table.role_of(n);
|
||||
let mut a = (*n.appearance).clone();
|
||||
match paint {
|
||||
Some(paint) => {
|
||||
a.set_stroke(paint.clone());
|
||||
if let Some(st) = a.stroke_mut() {
|
||||
if st.width <= 0.0 {
|
||||
st.width = 1.0;
|
||||
}
|
||||
// A hidden stroke would carry the role without drawing or printing the line.
|
||||
st.visible = true;
|
||||
st.overprint = overprint;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
if had.is_none() {
|
||||
return false;
|
||||
}
|
||||
if let Some(st) = a.stroke_mut() {
|
||||
if let Paint::Solid { color, .. } = st.paint {
|
||||
st.paint = Paint::solid(color);
|
||||
}
|
||||
st.overprint = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if a == *n.appearance {
|
||||
return false;
|
||||
}
|
||||
n.appearance = vectorcraft_doc::Shared::new(a);
|
||||
true
|
||||
}
|
||||
|
||||
fn set_role(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let role = role_param(p, SET_ROLE, true)?;
|
||||
let overprint = switch_or(p, "overprint", true, SET_ROLE)?;
|
||||
let roots = checked_ids_or_selection(s, p, SET_ROLE)?;
|
||||
let (ids, skipped) = role_targets(&s.doc()?.doc, &roots, true);
|
||||
if ids.is_empty() {
|
||||
return Err(bad(SET_ROLE, "select a path that is neither locked nor hidden: text, images and symbol instances can't have a fold line role"));
|
||||
}
|
||||
let label = role.map_or("Remove Fold Line Role", |_| "Make Fold Line");
|
||||
let mut changed = 0;
|
||||
edit_counted(s, label, |d| {
|
||||
let before = (d.swatches.len(), d.unknown.get(ROLES_KEY).cloned());
|
||||
let paint = role.map(|r| role_paint(d, r)).transpose()?;
|
||||
// A role swatch made again (its strokes may still name it) is a change of its own.
|
||||
let made = (d.swatches.len(), d.unknown.get(ROLES_KEY).cloned()) != before;
|
||||
let table = RoleTable::of(d);
|
||||
changed = ids.iter().filter(|id| give_role(d, &table, **id, paint.as_ref(), overprint)).count();
|
||||
Ok(changed + usize::from(made))
|
||||
})?;
|
||||
Ok(json!({ "ids": ids.iter().map(|i| i.0).collect::<Vec<_>>(), "changed": changed, "skipped": skipped }))
|
||||
}
|
||||
|
||||
fn roles(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let given = p.get("ids").is_some_and(|v| !v.is_null());
|
||||
let roots = checked_ids_or_selection(s, p, ROLES)?;
|
||||
let d = &s.doc()?.doc;
|
||||
let (scope, ids) = match (given, roots.is_empty()) {
|
||||
(true, _) => ("ids", role_targets(d, &roots, false).0),
|
||||
(false, false) => ("selection", role_targets(d, &roots, false).0),
|
||||
(false, true) => ("document", document_targets(d)),
|
||||
};
|
||||
let table = RoleTable::of(d);
|
||||
let mut counts = [0usize; 4];
|
||||
for r in ids.iter().filter_map(|id| d.node(*id)).filter_map(|n| table.role_of(n)) {
|
||||
if let Some(c) = counts.get_mut(r.index()) {
|
||||
*c += 1;
|
||||
}
|
||||
}
|
||||
let rows: Vec<Value> = Role::ALL
|
||||
.into_iter()
|
||||
.zip(counts)
|
||||
.map(|(r, count)| {
|
||||
let swatch = table.swatch(r);
|
||||
json!({ "role": r.id(), "name": r.name(), "swatch": swatch, "exists": d.swatch(swatch).is_some(), "count": count })
|
||||
})
|
||||
.collect();
|
||||
Ok(json!({ "roles": rows, "scope": scope, "selected": roots.len() }))
|
||||
}
|
||||
|
||||
fn set_role_swatch(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let Some(role) = role_param(p, SET_ROLE_SWATCH, false)? else { return Err(bad(SET_ROLE_SWATCH, "missing `role`")) };
|
||||
let name = text_param(p, "swatch", SET_ROLE_SWATCH)?.ok_or_else(|| bad(SET_ROLE_SWATCH, "missing `swatch`"))?;
|
||||
let d = &s.doc()?.doc;
|
||||
if let Some(why) = unfit_swatch(d, name) {
|
||||
return Err(bad(SET_ROLE_SWATCH, why));
|
||||
}
|
||||
let mut table = RoleTable::of(d);
|
||||
if let Some(other) = Role::ALL.into_iter().find(|r| *r != role && table.swatch(*r) == name) {
|
||||
return Err(bad(SET_ROLE_SWATCH, format!("`{name}` already carries the {} role", other.name())));
|
||||
}
|
||||
if let Some(slot) = table.0.get_mut(role.index()) {
|
||||
*slot = name.to_string();
|
||||
}
|
||||
let value = table.to_value();
|
||||
let changed = RoleTable::of(d) != table;
|
||||
if changed {
|
||||
s.edit("Role Swatches", |d, _| {
|
||||
d.unknown.insert(ROLES_KEY.to_string(), value);
|
||||
Ok(())
|
||||
})?;
|
||||
}
|
||||
Ok(json!({ "role": role.id(), "swatch": name, "changed": changed }))
|
||||
}
|
||||
@@ -0,0 +1,540 @@
|
||||
//! Tests for Packaging Tools: fold line roles, their swatches and the role table.
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_doc::{AppearanceItem, Node, NodeKind};
|
||||
|
||||
use crate::*;
|
||||
|
||||
fn session(mode: &str) -> Session {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 600, "height": 400, "colorMode": mode})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
fn id_of(v: &Value) -> NodeId {
|
||||
NodeId(v["id"].as_u64().unwrap())
|
||||
}
|
||||
|
||||
fn rect(s: &mut Session, x: f64) -> NodeId {
|
||||
id_of(&s.execute("shape.rectangle", &json!({"x": x, "y": 20, "width": 40, "height": 40})).unwrap())
|
||||
}
|
||||
|
||||
fn node(s: &Session, id: NodeId) -> Node {
|
||||
s.doc().unwrap().doc.node(id).cloned().unwrap()
|
||||
}
|
||||
|
||||
fn steps(s: &Session) -> usize {
|
||||
s.doc().unwrap().history.undo.len()
|
||||
}
|
||||
|
||||
fn set_role(s: &mut Session, p: Value) -> Value {
|
||||
s.execute("addon.packaging.setRole", &p).unwrap()
|
||||
}
|
||||
|
||||
fn err(s: &mut Session, cmd: &str, p: Value) -> String {
|
||||
s.execute(cmd, &p).unwrap_err().to_string()
|
||||
}
|
||||
|
||||
fn b64(v: &Value) -> Vec<u8> {
|
||||
vectorcraft_format::base64_decode(v["dataBase64"].as_str().expect("dataBase64")).unwrap()
|
||||
}
|
||||
|
||||
/// The `roles` query's counts, in role order.
|
||||
fn counts(s: &mut Session, p: Value) -> Vec<u64> {
|
||||
let r = s.execute("addon.packaging.roles", &p).unwrap();
|
||||
r["roles"].as_array().unwrap().iter().map(|r| r["count"].as_u64().unwrap()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_role_makes_the_spot_swatch_and_links_the_top_stroke() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
assert!(s.doc().unwrap().doc.swatch("Cut").is_none());
|
||||
let before = steps(&s);
|
||||
let r = set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
assert_eq!((r["changed"].as_u64(), r["skipped"].as_u64()), (Some(1), Some(0)));
|
||||
assert_eq!(steps(&s), before + 1, "one undo step");
|
||||
let d = &s.doc().unwrap().doc;
|
||||
let sw = d.swatch("Cut").unwrap();
|
||||
assert!(sw.global && sw.spot, "{sw:?}");
|
||||
assert_eq!(sw.paint, Paint::solid(Color::cmyk(0.0, 1.0, 0.0, 0.0)), "100% magenta in a CMYK document");
|
||||
let st = node(&s, a).appearance.stroke().cloned().unwrap();
|
||||
assert!(matches!(&st.paint, Paint::Solid { swatch: Some(n), tint, .. } if n == "Cut" && *tint == 1.0), "{:?}", st.paint);
|
||||
assert!(st.overprint, "role strokes overprint by default");
|
||||
// Again: nothing changes, and no undo step is recorded.
|
||||
let r = set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
assert_eq!(r["changed"].as_u64(), Some(0));
|
||||
assert_eq!(steps(&s), before + 1);
|
||||
// Undo takes the swatch away with the role.
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert!(s.doc().unwrap().doc.swatch("Cut").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_role_gets_its_own_swatch_color_in_the_document_s_mode() {
|
||||
let mut s = session("rgb");
|
||||
for (i, role) in ["cut", "crease", "partialCut", "perforation"].into_iter().enumerate() {
|
||||
let id = rect(&mut s, 20.0 + 60.0 * i as f64);
|
||||
set_role(&mut s, json!({"role": role, "ids": [id.0]}));
|
||||
}
|
||||
let d = &s.doc().unwrap().doc;
|
||||
let colors: Vec<Color> = ["Cut", "Crease", "Partial Cut", "Perforation"].iter().map(|n| d.swatch(n).unwrap().paint.color().unwrap()).collect();
|
||||
assert!(colors.iter().all(|c| matches!(c, Color::Rgb { .. })), "an RGB document's swatches are RGB: {colors:?}");
|
||||
assert_eq!(colors.iter().map(|c| c.to_hex()).collect::<BTreeSet<_>>().len(), 4, "four colors: {colors:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_path_without_a_stroke_gets_one_and_overprint_can_be_left_off() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
s.edit("strip", |d, _| {
|
||||
let n = d.node_mut(a).unwrap();
|
||||
n.appearance.items.retain(AppearanceItem::is_fill);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
assert!(node(&s, a).appearance.stroke().is_none());
|
||||
set_role(&mut s, json!({"role": "crease", "ids": [a.0], "overprint": false}));
|
||||
let st = node(&s, a).appearance.stroke().cloned().unwrap();
|
||||
assert_eq!(st.width, 1.0, "a 1 pt stroke");
|
||||
assert!(!st.overprint);
|
||||
assert!(matches!(&st.paint, Paint::Solid { swatch: Some(n), .. } if n == "Crease"));
|
||||
assert!(err(&mut s, "addon.packaging.setRole", json!({"role": "cut", "ids": [a.0], "overprint": "yes"})).contains("overprint"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn none_takes_the_role_away_and_keeps_the_color() {
|
||||
let mut s = session("cmyk");
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 100.0));
|
||||
set_role(&mut s, json!({"role": "perforation", "ids": [a.0]}));
|
||||
let shown = node(&s, a).appearance.stroke().unwrap().paint.color().unwrap();
|
||||
let before = steps(&s);
|
||||
let r = set_role(&mut s, json!({"role": "none", "ids": [a.0, b.0]}));
|
||||
assert_eq!(r["changed"].as_u64(), Some(1), "the plain rectangle has no role to take away");
|
||||
assert_eq!(steps(&s), before + 1);
|
||||
let st = node(&s, a).appearance.stroke().cloned().unwrap();
|
||||
assert_eq!(st.paint, Paint::solid(shown));
|
||||
assert!(!st.overprint);
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0, b.0]})), [0, 0, 0, 0]);
|
||||
// Nothing left with a role: no undo step.
|
||||
set_role(&mut s, json!({"role": "none", "ids": [a.0, b.0]}));
|
||||
assert_eq!(steps(&s), before + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_roles_and_targets_are_refused() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
assert!(err(&mut s, "addon.packaging.setRole", json!({"role": "fold", "ids": [a.0]})).contains("unknown role"));
|
||||
assert!(err(&mut s, "addon.packaging.setRole", json!({"ids": [a.0]})).contains("role"));
|
||||
assert!(err(&mut s, "addon.packaging.setRole", json!({"role": 3, "ids": [a.0]})).contains("role"));
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
assert!(s.execute("addon.packaging.setRole", &json!({"role": "cut"})).is_err(), "nothing selected");
|
||||
let t = id_of(&s.execute("text.create", &json!({"x": 20, "y": 200, "text": "Lid", "size": 20})).unwrap());
|
||||
let before = steps(&s);
|
||||
assert!(err(&mut s, "addon.packaging.setRole", json!({"role": "cut", "ids": [t.0]})).contains("select a path"));
|
||||
assert_eq!(steps(&s), before);
|
||||
assert!(s.doc().unwrap().doc.swatch("Cut").is_none(), "a refused run makes no swatch");
|
||||
// Text beside a path is skipped and counted.
|
||||
let r = set_role(&mut s, json!({"role": "cut", "ids": [a.0, t.0]}));
|
||||
assert_eq!((r["changed"].as_u64(), r["skipped"].as_u64()), (Some(1), Some(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn groups_are_walked_and_their_locked_and_hidden_members_left_out() {
|
||||
let mut s = session("cmyk");
|
||||
let (a, b, c) = (rect(&mut s, 20.0), rect(&mut s, 100.0), rect(&mut s, 180.0));
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0, c.0]})).unwrap();
|
||||
let g = id_of(&s.execute("object.group", &json!({})).unwrap());
|
||||
s.edit("lock", |d, _| {
|
||||
d.node_mut(b).unwrap().locked = true;
|
||||
d.node_mut(c).unwrap().visible = false;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let r = set_role(&mut s, json!({"role": "crease", "ids": [g.0]}));
|
||||
assert_eq!(r["ids"], json!([a.0]));
|
||||
assert_eq!(r["skipped"].as_u64(), Some(2), "the locked and the hidden member");
|
||||
assert_eq!(counts(&mut s, json!({"ids": [g.0]})), [0, 1, 0, 0]);
|
||||
// Named directly, a locked or hidden path is left out too.
|
||||
let r = set_role(&mut s, json!({"role": "cut", "ids": [a.0, b.0, c.0]}));
|
||||
assert_eq!((r["ids"].clone(), r["skipped"].as_u64()), (json!([a.0]), Some(2)));
|
||||
let before = steps(&s);
|
||||
assert!(err(&mut s, "addon.packaging.setRole", json!({"role": "cut", "ids": [b.0]})).contains("locked"));
|
||||
assert_eq!(steps(&s), before);
|
||||
assert_eq!(counts(&mut s, json!({"ids": [b.0, c.0]})), [0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_clip_group_s_clipping_path_is_skipped_and_counted() {
|
||||
let mut s = session("cmyk");
|
||||
let (art, mask) = (rect(&mut s, 20.0), rect(&mut s, 30.0));
|
||||
s.execute("select.set", &json!({"ids": [art.0, mask.0]})).unwrap();
|
||||
let g = id_of(&s.execute("object.clippingMask.make", &json!({})).unwrap());
|
||||
let r = set_role(&mut s, json!({"role": "cut", "ids": [g.0]}));
|
||||
assert_eq!((r["ids"].clone(), r["skipped"].as_u64()), (json!([art.0]), Some(1)), "the clipping path is left out and counted");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_group_and_its_member_count_once_and_locked_lines_count_in_every_scope() {
|
||||
let mut s = session("cmyk");
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 100.0));
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [b.0]}));
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
let g = id_of(&s.execute("object.group", &json!({})).unwrap());
|
||||
let r = set_role(&mut s, json!({"role": "crease", "ids": [g.0, a.0]}));
|
||||
assert_eq!(r["ids"], json!([a.0, b.0]), "each path once");
|
||||
assert_eq!(counts(&mut s, json!({"ids": [g.0, a.0]})), [0, 2, 0, 0]);
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [b.0]}));
|
||||
s.edit("lock", |d, _| {
|
||||
d.node_mut(b).unwrap().locked = true;
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
// A locked line keeps its role and is counted, whether its group is selected or not.
|
||||
assert_eq!(counts(&mut s, json!({"ids": [g.0]})), [1, 1, 0, 0]);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
assert_eq!(counts(&mut s, json!({})), [1, 1, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_process_swatch_named_like_a_role_swatch_keeps_its_name() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
s.execute("swatch.new", &json!({"name": "Cut", "color": "#ff0000"})).unwrap();
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
let d = &s.doc().unwrap().doc;
|
||||
assert_eq!(d.unknown.get("packagingRoles").unwrap()["cut"], json!("Cut 2"));
|
||||
assert!(d.swatch("Cut 2").is_some_and(|w| w.spot), "the role swatch is made beside it");
|
||||
assert!(d.swatch("Cut").is_some_and(|w| !w.global), "the process swatch is left as it was");
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [1, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_free_role_swatch_name_is_searched_past_ten_thousand() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
let taken = std::iter::once("Cut".to_string()).chain((2..10_000).map(|i| format!("Cut {i}"))).chain(["Cut 10004".to_string()]);
|
||||
let process = |name: String| vectorcraft_color::Swatch { name, paint: Paint::solid(Color::rgb(1.0, 0.0, 0.0)), global: false, spot: false };
|
||||
Arc::make_mut(&mut s.doc_mut().unwrap().doc).swatches.extend(taken.map(process));
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
let d = &s.doc().unwrap().doc;
|
||||
assert_eq!(d.unknown.get("packagingRoles").unwrap()["cut"], json!("Cut 10000"));
|
||||
assert!(d.swatch("Cut 10000").is_some_and(|w| w.spot), "the role swatch is made under the first free name");
|
||||
assert!(d.swatch("Cut 10004").is_some_and(|w| !w.global), "a taken name is left as it was");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_merged_role_swatch_hands_its_role_to_the_kept_swatch() {
|
||||
let mut s = session("cmyk");
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 100.0));
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
set_role(&mut s, json!({"role": "crease", "ids": [b.0]}));
|
||||
s.execute("swatch.new", &json!({"name": "Die", "color": {"model": "cmyk", "c": 0, "m": 0.8, "y": 0.2, "k": 0}, "spot": true})).unwrap();
|
||||
s.execute("swatch.merge", &json!({"names": ["Die", "Cut"]})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.unknown.get("packagingRoles").unwrap()["cut"], json!("Die"));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [1, 0, 0, 0], "the cut line is still a cut line");
|
||||
// A kept swatch that already carries a role keeps it; the merged role's lines take it.
|
||||
s.execute("swatch.merge", &json!({"names": ["Crease", "Die"]})).unwrap();
|
||||
let table = s.doc().unwrap().doc.unknown.get("packagingRoles").cloned().unwrap();
|
||||
assert_eq!((&table["cut"], &table["crease"]), (&json!("Die"), &json!("Crease")), "{table}");
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0, b.0]})), [0, 2, 0, 0]);
|
||||
// The next Make Cut Line makes the Cut role's swatch again.
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
assert!(s.doc().unwrap().doc.swatch("Die").is_some_and(|w| w.spot));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0, b.0]})), [1, 1, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_global_process_swatch_can_carry_a_role() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
s.execute("swatch.new", &json!({"name": "Die", "color": {"model": "cmyk", "c": 0, "m": 0.8, "y": 0.2, "k": 0}, "global": true})).unwrap();
|
||||
s.execute("addon.packaging.setRoleSwatch", &json!({"role": "partialCut", "swatch": "Die"})).unwrap();
|
||||
set_role(&mut s, json!({"role": "partialCut", "ids": [a.0]}));
|
||||
assert!(matches!(&node(&s, a).appearance.stroke().unwrap().paint, Paint::Solid { swatch: Some(n), .. } if n == "Die"));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [0, 0, 1, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roles_counts_the_selection_or_the_whole_document() {
|
||||
let mut s = session("cmyk");
|
||||
let (a, b, c) = (rect(&mut s, 20.0), rect(&mut s, 100.0), rect(&mut s, 180.0));
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0, b.0]}));
|
||||
set_role(&mut s, json!({"role": "partialCut", "ids": [c.0]}));
|
||||
s.execute("select.set", &json!({"ids": [a.0, c.0]})).unwrap();
|
||||
let r = s.execute("addon.packaging.roles", &json!({})).unwrap();
|
||||
assert_eq!((r["scope"].as_str(), r["selected"].as_u64()), (Some("selection"), Some(2)));
|
||||
assert_eq!(counts(&mut s, json!({})), [1, 0, 1, 0]);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
let r = s.execute("addon.packaging.roles", &json!({})).unwrap();
|
||||
assert_eq!((r["scope"].as_str(), r["selected"].as_u64()), (Some("document"), Some(0)));
|
||||
assert_eq!(counts(&mut s, json!({})), [2, 0, 1, 0]);
|
||||
let rows = r["roles"].as_array().unwrap();
|
||||
assert_eq!(rows[0], json!({"role": "cut", "name": "Cut", "swatch": "Cut", "exists": true, "count": 2}));
|
||||
assert_eq!(rows[1]["exists"], json!(false), "no Crease swatch yet");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn role_swatches_maps_a_role_to_another_swatch() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
s.execute("swatch.new", &json!({"name": "Die", "color": {"model": "cmyk", "c": 0, "m": 0.8, "y": 0.2, "k": 0}, "spot": true})).unwrap();
|
||||
let before = steps(&s);
|
||||
let r = s.execute("addon.packaging.setRoleSwatch", &json!({"role": "cut", "swatch": "Die"})).unwrap();
|
||||
assert_eq!(r["changed"], json!(true));
|
||||
assert_eq!(steps(&s), before + 1);
|
||||
assert_eq!(s.doc().unwrap().doc.unknown.get("packagingRoles").unwrap()["cut"], json!("Die"));
|
||||
// The old swatch's objects keep their color and lose the role.
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [0, 0, 0, 0]);
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
assert!(matches!(&node(&s, a).appearance.stroke().unwrap().paint, Paint::Solid { swatch: Some(n), .. } if n == "Die"));
|
||||
// The same mapping again changes nothing.
|
||||
let steps_now = steps(&s);
|
||||
let r = s.execute("addon.packaging.setRoleSwatch", &json!({"role": "cut", "swatch": "Die"})).unwrap();
|
||||
assert_eq!((r["changed"].clone(), steps(&s)), (json!(false), steps_now));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_renamed_role_swatch_keeps_its_role() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
set_role(&mut s, json!({"role": "crease", "ids": [a.0]}));
|
||||
s.execute("swatch.edit", &json!({"name": "Crease", "newName": "Score"})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.unknown.get("packagingRoles").unwrap()["crease"], json!("Score"));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [0, 1, 0, 0]);
|
||||
// A swatch that carries no role leaves the table alone.
|
||||
s.execute("swatch.new", &json!({"name": "Ink", "color": {"model": "cmyk", "c": 0, "m": 1, "y": 1, "k": 0}, "spot": true})).unwrap();
|
||||
s.execute("swatch.edit", &json!({"name": "Ink", "newName": "Red Ink"})).unwrap();
|
||||
let table = s.doc().unwrap().doc.unknown.get("packagingRoles").cloned().unwrap();
|
||||
assert_eq!(table, json!({"cut": "Cut", "crease": "Score", "partialCut": "Partial Cut", "perforation": "Perforation"}));
|
||||
// Undo puts the old name back in the table with the swatch.
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert!(s.doc().unwrap().doc.unknown.get("packagingRoles").is_none());
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [0, 1, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_role_swatch_renamed_to_another_role_s_name_leaves_each_role_its_own_swatch() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
// No Crease swatch exists yet, so the name is free for the Cut swatch.
|
||||
s.execute("swatch.edit", &json!({"name": "Cut", "newName": "Crease"})).unwrap();
|
||||
let table = s.doc().unwrap().doc.unknown.get("packagingRoles").cloned().unwrap();
|
||||
assert_eq!((&table["cut"], &table["crease"]), (&json!("Crease"), &json!("Crease 2")), "{table}");
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [1, 0, 0, 0], "the line is still a cut line");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_role_swatch_that_stops_being_global_hands_its_role_to_a_new_swatch() {
|
||||
let mut s = session("cmyk");
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 100.0));
|
||||
set_role(&mut s, json!({"role": "perforation", "ids": [a.0]}));
|
||||
s.execute("swatch.edit", &json!({"name": "Perforation", "spot": false, "global": false})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.unknown.get("packagingRoles").unwrap()["perforation"], json!("Perforation 2"));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [0, 0, 0, 0], "the unlinked stroke has no role");
|
||||
set_role(&mut s, json!({"role": "perforation", "ids": [b.0]}));
|
||||
assert!(s.doc().unwrap().doc.swatch("Perforation 2").is_some_and(|w| w.spot));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [b.0]})), [0, 0, 0, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_color_group_named_like_a_role_swatch_keeps_its_name() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
s.execute("swatch.newGroup", &json!({"name": "Cut", "colors": ["#ff0000"]})).unwrap();
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
let d = &s.doc().unwrap().doc;
|
||||
assert_eq!(d.unknown.get("packagingRoles").unwrap()["cut"], json!("Cut 2"));
|
||||
assert!(d.swatch("Cut 2").is_some_and(|w| w.spot) && d.swatch("Cut").is_none());
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [1, 0, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_role_makes_a_deleted_role_swatch_again_for_strokes_that_still_name_it() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
s.execute("swatch.delete", &json!({"name": "Cut", "unlink": false})).unwrap();
|
||||
assert!(s.doc().unwrap().doc.swatch("Cut").is_none());
|
||||
let before = steps(&s);
|
||||
let r = set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
assert_eq!(r["changed"].as_u64(), Some(0), "the stroke already names the swatch");
|
||||
assert!(s.doc().unwrap().doc.swatch("Cut").is_some_and(|w| w.spot), "the swatch is back");
|
||||
assert_eq!(steps(&s), before + 1, "as one undo step");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hidden_stroke_is_shown_when_it_takes_a_role() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
s.edit("hide", |d, _| {
|
||||
if let Some(AppearanceItem::Stroke(st)) = d.node_mut(a).unwrap().appearance.items.iter_mut().find(|i| !i.is_fill()) {
|
||||
st.visible = false;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
assert!(node(&s, a).appearance.stroke().unwrap().visible);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn role_swatches_refuses_swatches_that_cannot_carry_a_role() {
|
||||
let mut s = session("cmyk");
|
||||
let ramp = json!({"type": "linear", "stops": [{"offset": 0, "color": "#000000"}, {"offset": 1, "color": "#ffffff"}]});
|
||||
s.execute("swatch.new", &json!({"name": "Ramp", "gradient": ramp})).unwrap();
|
||||
s.execute("swatch.new", &json!({"name": "Plain", "color": "#336699"})).unwrap();
|
||||
s.execute("swatch.new", &json!({"name": "Ink", "color": {"model": "cmyk", "c": 0, "m": 1, "y": 1, "k": 0}, "spot": true})).unwrap();
|
||||
s.execute("swatch.new", &json!({"name": "Ink Tint", "swatch": "Ink", "tint": 0.5})).unwrap();
|
||||
s.execute("swatch.new", &json!({"name": "Crease", "color": {"model": "cmyk", "c": 1, "m": 0, "y": 0, "k": 0}, "spot": true})).unwrap();
|
||||
let before = steps(&s);
|
||||
for (swatch, says) in [
|
||||
("Nope", "no swatch"),
|
||||
("Ramp", "isn't a color swatch"),
|
||||
("Plain", "process color"),
|
||||
("Ink Tint", "tint swatch"),
|
||||
("[None]", "can't carry a role"),
|
||||
("[Registration]", "can't carry a role"),
|
||||
("Crease", "already carries the Crease role"),
|
||||
] {
|
||||
let e = err(&mut s, "addon.packaging.setRoleSwatch", json!({"role": "cut", "swatch": swatch}));
|
||||
assert!(e.contains(says), "{swatch}: {e}");
|
||||
}
|
||||
assert!(err(&mut s, "addon.packaging.setRoleSwatch", json!({"role": "none", "swatch": "Ink"})).contains("unknown role"));
|
||||
assert!(err(&mut s, "addon.packaging.setRoleSwatch", json!({"role": "cut"})).contains("swatch"));
|
||||
assert_eq!(steps(&s), before, "no refusal records an undo step");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_damaged_role_table_reads_as_the_defaults() {
|
||||
let mut s = session("cmyk");
|
||||
s.edit("damage", |d, _| {
|
||||
d.unknown.insert("packagingRoles".into(), json!({"cut": 5, "crease": "", "partialCut": null, "extra": "x"}));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let r = s.execute("addon.packaging.roles", &json!({})).unwrap();
|
||||
let swatches: Vec<&str> = r["roles"].as_array().unwrap().iter().map(|r| r["swatch"].as_str().unwrap()).collect();
|
||||
assert_eq!(swatches, ["Cut", "Crease", "Partial Cut", "Perforation"]);
|
||||
s.edit("not an object", |d, _| {
|
||||
d.unknown.insert("packagingRoles".into(), json!("Cut"));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let a = rect(&mut s, 20.0);
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [a.0]})), [1, 0, 0, 0]);
|
||||
// One swatch named for two roles: the later role takes its own default.
|
||||
s.edit("duplicate", |d, _| {
|
||||
d.unknown.insert("packagingRoles".into(), json!({"cut": "Crease", "crease": "Crease", "partialCut": "Cut"}));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let r = s.execute("addon.packaging.roles", &json!({})).unwrap();
|
||||
let swatches: Vec<&str> = r["roles"].as_array().unwrap().iter().map(|r| r["swatch"].as_str().unwrap()).collect();
|
||||
assert_eq!(swatches, ["Crease", "Crease 2", "Cut", "Perforation"]);
|
||||
let b = rect(&mut s, 100.0);
|
||||
set_role(&mut s, json!({"role": "crease", "ids": [b.0]}));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [b.0]})), [0, 1, 0, 0], "the crease line is a crease line");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn native_save_and_open_keep_the_role_table_and_the_roles() {
|
||||
let mut s = session("cmyk");
|
||||
let a = rect(&mut s, 20.0);
|
||||
s.execute("swatch.new", &json!({"name": "Die", "color": {"model": "cmyk", "c": 0, "m": 0.8, "y": 0.2, "k": 0}, "spot": true})).unwrap();
|
||||
s.execute("addon.packaging.setRoleSwatch", &json!({"role": "cut", "swatch": "Die"})).unwrap();
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
let saved = s.execute("document.export", &json!({"format": "vectorcraft"})).unwrap();
|
||||
s.execute("document.open", &json!({"name": "box.vectorcraft", "dataBase64": saved["dataBase64"]})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.unknown.get("packagingRoles").unwrap()["cut"], json!("Die"));
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
assert_eq!(counts(&mut s, json!({})), [1, 0, 0, 0]);
|
||||
}
|
||||
|
||||
/// A document with one rectangle of each of Cut and Crease.
|
||||
fn two_roles() -> Session {
|
||||
let mut s = session("cmyk");
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 100.0));
|
||||
set_role(&mut s, json!({"role": "cut", "ids": [a.0]}));
|
||||
set_role(&mut s, json!({"role": "crease", "ids": [b.0]}));
|
||||
s
|
||||
}
|
||||
|
||||
fn export(s: &mut Session, format: &str) -> String {
|
||||
String::from_utf8_lossy(&b64(&s.execute("document.export", &json!({"format": format})).unwrap())).into_owned()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pdf_prints_each_role_on_its_swatch_s_separation_and_overprints_it() {
|
||||
let mut s = two_roles();
|
||||
let c = rect(&mut s, 180.0);
|
||||
set_role(&mut s, json!({"role": "partialCut", "ids": [c.0]}));
|
||||
let bytes = vectorcraft_pdf::export(
|
||||
&s.doc().unwrap().doc,
|
||||
&vectorcraft_pdf::PdfOptions { created: Some(0), ..vectorcraft_pdf::PdfOptions::uncompressed() },
|
||||
)
|
||||
.unwrap();
|
||||
let pdf = String::from_utf8_lossy(&bytes);
|
||||
assert!(pdf.contains("/Separation/Cut"), "the Cut line prints on the Cut plate");
|
||||
assert!(pdf.contains("/Separation/Crease"));
|
||||
assert!(pdf.contains("/Separation/Partial#20Cut"), "a name with a space");
|
||||
assert!(pdf.contains("/OP true"), "the role strokes overprint");
|
||||
// Without overprint, nothing in the file overprints.
|
||||
let mut plain = session("cmyk");
|
||||
let (a, b) = (rect(&mut plain, 20.0), rect(&mut plain, 100.0));
|
||||
set_role(&mut plain, json!({"role": "cut", "ids": [a.0], "overprint": false}));
|
||||
set_role(&mut plain, json!({"role": "crease", "ids": [b.0], "overprint": false}));
|
||||
let bytes = vectorcraft_pdf::export(
|
||||
&plain.doc().unwrap().doc,
|
||||
&vectorcraft_pdf::PdfOptions { created: Some(0), ..vectorcraft_pdf::PdfOptions::uncompressed() },
|
||||
)
|
||||
.unwrap();
|
||||
assert!(!String::from_utf8_lossy(&bytes).contains("/OP true"));
|
||||
assert!(!export(&mut s, "pdf").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn svg_dxf_and_hpgl_keep_the_default_role_swatches_apart() {
|
||||
let mut s = two_roles();
|
||||
let svg = export(&mut s, "svg");
|
||||
let strokes: BTreeSet<&str> = svg.split("stroke=\"").skip(1).filter_map(|t| t.split('"').next()).filter(|c| c.starts_with('#')).collect();
|
||||
let strokes = if strokes.is_empty() {
|
||||
svg.split("stroke:").skip(1).filter_map(|t| t.split([';', '"', '}']).next()).filter(|c| c.starts_with('#')).collect()
|
||||
} else {
|
||||
strokes
|
||||
};
|
||||
assert_eq!(strokes.len(), 2, "two stroke colors: {svg}");
|
||||
let dxf = export(&mut s, "dxf");
|
||||
let lines: Vec<&str> = dxf.lines().map(str::trim).collect();
|
||||
// The rectangles' white fills come out as true colors too.
|
||||
let colors: BTreeSet<&str> = lines.windows(2).filter(|w| w[0] == "420" && w[1] != "16777215").map(|w| w[1]).collect();
|
||||
assert_eq!(colors.len(), 2, "two stroke true colors: {colors:?}");
|
||||
let plot = s.execute("document.export", &json!({"format": "hpgl", "hpglVersion": "hpgl2"})).unwrap();
|
||||
let plot = String::from_utf8_lossy(&b64(&plot)).into_owned();
|
||||
assert!(plot.contains("SP1") && plot.contains("SP2"), "a pen per role swatch color: {plot}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compound_paths_carry_a_role() {
|
||||
let mut s = session("cmyk");
|
||||
let (a, b) = (rect(&mut s, 20.0), rect(&mut s, 30.0));
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
|
||||
let c = id_of(&s.execute("object.compoundPath.make", &json!({})).unwrap());
|
||||
assert!(matches!(node(&s, c).kind, NodeKind::Compound { .. }));
|
||||
let r = set_role(&mut s, json!({"role": "cut", "ids": [c.0]}));
|
||||
assert_eq!(r["ids"], json!([c.0]));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [c.0]})), [1, 0, 0, 0]);
|
||||
// A member named by id gives its compound the role.
|
||||
let r = set_role(&mut s, json!({"role": "crease", "ids": [a.0, b.0]}));
|
||||
assert_eq!((r["ids"].clone(), r["changed"].as_u64()), (json!([c.0]), Some(1)));
|
||||
assert_eq!(counts(&mut s, json!({"ids": [c.0]})), [0, 1, 0, 0]);
|
||||
}
|
||||
@@ -40,6 +40,9 @@ pub(super) const ALLOWED: &[&str] = &[
|
||||
"addon.image.colorMask",
|
||||
"addon.image.removeBackground",
|
||||
"addon.image.removeColorMask",
|
||||
"addon.packaging.roles",
|
||||
"addon.packaging.setRole",
|
||||
"addon.packaging.setRoleSwatch",
|
||||
"addon.pathtools.addPoints",
|
||||
"addon.pathtools.close",
|
||||
"addon.pathtools.corner",
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Swatch Options",
|
||||
["Window", "Swatches"],
|
||||
None,
|
||||
"{name, newName?, color? (e.g. {l, a, b} for a Lab colour; #rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill; the swatch's own color and a color given with mode keep their model), mode?: \"gray\"|\"rgb\"|\"hsb\"|\"lab\"|\"cmyk\"|\"web\" (convert the colour), global?, spot? (spot colours are always global), paint?: paint.setFill params ({color}, {gradient} or {swatch}) or {pattern: name} replacing the swatch's colour; gradient or pattern with one of the same kind (stored as swatch.new stores it: a gradient keeps its aspect with or without start/end and holds no swatch link; a pattern is untransformed)} edit a swatch in any colour group, as one undo step. Fills, strokes, text, gradient stops and tint swatches linked to a global swatch take its new colour (at their own tint) and name; turning Global off unlinks them (they keep their colour). Colour, mode and spot apply to solid colours only; a tint swatch only takes a new name (edit its base) → {name, relinked: paints changed}",
|
||||
"{name, newName?, color? (e.g. {l, a, b} for a Lab colour; #rrggbbaa and #rgba are refused), keepModel?: bool (as paint.setFill; the swatch's own color and a color given with mode keep their model), mode?: \"gray\"|\"rgb\"|\"hsb\"|\"lab\"|\"cmyk\"|\"web\" (convert the colour), global?, spot? (spot colours are always global), paint?: paint.setFill params ({color}, {gradient} or {swatch}) or {pattern: name} replacing the swatch's colour; gradient or pattern with one of the same kind (stored as swatch.new stores it: a gradient keeps its aspect with or without start/end and holds no swatch link; a pattern is untransformed)} edit a swatch in any colour group, as one undo step. Fills, strokes, text, gradient stops and tint swatches linked to a global swatch take its new colour (at their own tint) and name; turning Global off unlinks them (they keep their colour). A fold line role the swatch carries (addon.packaging.roles) stays with it under its new name, and moves to a new swatch name when Global is turned off. Colour, mode and spot apply to solid colours only; a tint swatch only takes a new name (edit its base) → {name, relinked: paints changed}",
|
||||
has_doc,
|
||||
swatch_edit
|
||||
),
|
||||
@@ -93,7 +93,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Merge Swatches",
|
||||
["Window", "Swatches"],
|
||||
None,
|
||||
"{names: [two or more solid-colour swatches], name?: the merged swatch's name (one swatch kept)} keep the first (its name and colour) and delete the others; paints linked to them take its colour and link to it (or unlink when it isn't global), as one undo step → {name, merged: [deleted names], relinked}",
|
||||
"{names: [two or more solid-colour swatches], name?: the merged swatch's name (one swatch kept)} keep the first (its name and colour) and delete the others; paints linked to them take its colour and link to it (or unlink when it isn't global), as one undo step. When the kept swatch is global and carries no fold line role (addon.packaging.roles), it takes the role of the first merged swatch that carried one → {name, merged: [deleted names], relinked}",
|
||||
has_doc,
|
||||
swatch_merge
|
||||
),
|
||||
@@ -932,6 +932,8 @@ fn swatch_edit(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
}
|
||||
let relinked = map_swatch_links(d, &mut |c, l, t| relink.apply(c, l, t));
|
||||
// A fold line role carried by the swatch follows its new name, as the strokes do.
|
||||
super::addons::role_swatch_edited(d, &name, &to, global);
|
||||
super::paint::check_colorized_kept(colorized_ok, d).map_err(|e| bad(C, e))?;
|
||||
Ok(relinked)
|
||||
})?;
|
||||
@@ -1128,6 +1130,8 @@ fn swatch_merge(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let relinked = s.edit("Merge Swatches", |d, _| {
|
||||
take_swatches(d, merged, |_| true);
|
||||
let relinked = map_swatch_links(d, &mut relink);
|
||||
// The lines of a merged role swatch link to the kept swatch, which takes that role.
|
||||
super::addons::role_swatches_merged(d, merged, keep, link.is_some());
|
||||
super::paint::check_colorized_kept(colorized_ok, d).map_err(|e| bad(C, e))?;
|
||||
Ok(relinked)
|
||||
})?;
|
||||
|
||||
@@ -993,6 +993,13 @@ fn structured_junk() {
|
||||
("addon.document.symbolsFromLayers", json!({"layers": "x", "replace": 3})),
|
||||
("addon.document.symbolsFromLayers", json!({"layers": [1e308, -1, null, u64::MAX], "replace": true})),
|
||||
("addon.document.symbolsFromLayers", json!({"layers": [], "replace": true})),
|
||||
// Packaging Tools add-on.
|
||||
("addon.packaging.setRole", json!({"role": "cut", "ids": [u64::MAX], "overprint": "no"})),
|
||||
("addon.packaging.setRole", json!({"role": ["crease"], "ids": "all"})),
|
||||
("addon.packaging.setRole", json!({"role": "none", "overprint": null})),
|
||||
("addon.packaging.roles", json!({"ids": [-1, 1e300]})),
|
||||
("addon.packaging.setRoleSwatch", json!({"role": "perforation", "swatch": "[Registration]"})),
|
||||
("addon.packaging.setRoleSwatch", json!({"role": "cut", "swatch": 5})),
|
||||
// Smart Pen add-on.
|
||||
("addon.pen.append", json!({"id": 2, "x": 1e308, "y": 0, "in": [1e308, -1e308]})),
|
||||
("addon.pen.append", json!({"id": 2, "subpath": u64::MAX, "x": 0, "y": 0, "segment": "curved"})),
|
||||
|
||||
Reference in New Issue
Block a user