mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
VectorCraft's UI moves onto the shared craft UI framework in storytold/craft-libs (`next`; the framework side is storytold/craft-libs#2809), as PhotoCraft's did. The app keeps its engine, document model, file formats, commands and automation; its windows, panels, bars, dialogs and canvas are now built and driven by the framework: shell, docking and panels, hosted dialogs, keyboard, focus, IME and pointer routing, and theme tokens. About 264,000 lines of VectorCraft's own egui UI code are removed and about 154,000 added. craft-libs is pinned at bf62d509f (in `next`), the egui fork at f5025284. Tests that drove the old UI were rewritten against the port where only their premise changed, with their assertions kept. The UI tests still failing at merge, and their follow-ups, are listed in the pull request.
100 lines
4.1 KiB
Rust
100 lines
4.1 KiB
Rust
//! Marks and Bleeds: the boxes of each exported page and its printer's marks. The marks' geometry
|
||
//! is the shared [`PrinterMarks`] (print draws the same marks); here it gets the page's bleed,
|
||
//! spot inks and page information.
|
||
|
||
use vectorcraft_color::Paint;
|
||
use vectorcraft_doc::marks::{MarkStyle, PrinterMarks, outset};
|
||
use vectorcraft_doc::setup::{MAX_BLEED, bleed_in_range};
|
||
use vectorcraft_doc::{Document, Node, NodeId};
|
||
use vectorcraft_geom::Rect;
|
||
|
||
use crate::{BleedSettings, MarkKind, MarkSettings, PdfSettings};
|
||
|
||
/// `marks` as the shared mark geometry.
|
||
pub fn printer_marks(marks: &MarkSettings) -> PrinterMarks {
|
||
PrinterMarks {
|
||
trim: marks.trim,
|
||
registration: marks.registration,
|
||
color_bars: marks.color_bars,
|
||
page_info: marks.page_info,
|
||
style: match marks.kind {
|
||
MarkKind::Roman => MarkStyle::Roman,
|
||
MarkKind::Japanese => MarkStyle::Japanese,
|
||
},
|
||
weight: marks.weight,
|
||
offset: marks.offset,
|
||
}
|
||
}
|
||
|
||
/// The bleed of `doc`'s pages, `[top, bottom, left, right]` in points: the document's with
|
||
/// [`BleedSettings::use_document`] (Document Setup; one read from a file is kept to
|
||
/// 0–[`MAX_BLEED`]), else the values of `bleed`.
|
||
pub fn page_bleed(bleed: &BleedSettings, doc: &Document) -> [f64; 4] {
|
||
if bleed.use_document { doc.setup.bleed.map(|b| if b.is_finite() { b.clamp(0.0, MAX_BLEED) } else { 0.0 }) } else { bleed.values() }
|
||
}
|
||
|
||
/// A PDF/X file of `doc` has no bleed on a side where the document's bleed (Document Setup) has
|
||
/// one.
|
||
pub fn leaves_out_bleed(set: &PdfSettings, doc: &Document) -> bool {
|
||
set.standard.is_pdfx()
|
||
&& page_bleed(&set.bleed, doc).into_iter().zip(bleed_in_range(doc.setup.bleed)).any(|(page, document)| page <= 0.0 && document > 0.0)
|
||
}
|
||
|
||
/// The boxes of one page, in document coordinates.
|
||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||
pub(crate) struct PageBoxes {
|
||
/// The artboard: the finished page.
|
||
pub trim: Rect,
|
||
/// The trim box grown by the bleed: the art it holds is kept.
|
||
pub bleed: Rect,
|
||
/// The sheet: the bleed box, grown to hold the printer's marks.
|
||
pub media: Rect,
|
||
}
|
||
|
||
impl PageBoxes {
|
||
pub fn new(trim: Rect, bleed: [f64; 4], marks: &PrinterMarks) -> Self {
|
||
let reach = marks.reach(bleed);
|
||
let most: [f64; 4] = std::array::from_fn(|i| bleed[i].max(reach[i]));
|
||
Self { trim, bleed: outset(trim, bleed), media: outset(trim, most) }
|
||
}
|
||
}
|
||
|
||
/// The page information printed under the marks: the file's title, the artboard (its name and
|
||
/// number) and the date and time of the export (UTC).
|
||
pub(crate) fn page_info(doc: &Document, title: &str, artboard: usize, created: Option<i64>) -> String {
|
||
page_info_of(doc, title, Some(artboard), created)
|
||
}
|
||
|
||
/// [`page_info`] of a page that may show no artboard (print with artboards ignored).
|
||
pub(crate) fn page_info_of(doc: &Document, title: &str, artboard: Option<usize>, created: Option<i64>) -> String {
|
||
let title = if title.trim().is_empty() { "Untitled" } else { title.trim() };
|
||
let mut info = title.to_string();
|
||
if let Some(i) = artboard {
|
||
let name = doc.artboards.get(i).map_or("", |a| a.name.as_str());
|
||
info.push_str(&format!(" · {name} ({} of {})", i + 1, doc.artboards.len()));
|
||
}
|
||
if let Some(t) = created {
|
||
let [y, mo, d, h, mi, _] = vectorcraft_doc::metadata::civil(t);
|
||
info.push_str(&format!(" · {y:04}-{mo:02}-{d:02} {h:02}:{mi:02} UTC"));
|
||
}
|
||
info
|
||
}
|
||
|
||
/// The marks of a page as art (`None` without marks): its spot inks get colour bar patches.
|
||
pub(crate) fn art(doc: &Document, marks: &PrinterMarks, boxes: &PageBoxes, bleed: [f64; 4], info: &str) -> Option<Node> {
|
||
if !marks.any() {
|
||
return None;
|
||
}
|
||
let spots: Vec<Paint> = doc
|
||
.spot_names()
|
||
.into_iter()
|
||
.filter_map(|name| doc.global_color(&name).map(|color| Paint::Solid { color, swatch: Some(name), tint: 1.0 }))
|
||
.collect();
|
||
// The marks are drawn straight from this art, so their ids don't matter.
|
||
let mut next = 0;
|
||
Some(marks.art(boxes.trim, bleed, &spots, info, &mut || {
|
||
next += 1;
|
||
NodeId(next)
|
||
}))
|
||
}
|