mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-28 09:21:55 +01:00
Images: Embed leaves images placed from DCS files linked
links.embed refuses an image placed from a DCS file and then embeds nothing, so Embed on a selection that held one DCS image and other linked images left all of them linked. The several-images Embed now sends only the linked images that are not DCS images, and is offered only when one of those is selected. With one DCS image selected, the Properties panel and the Control bar offer Edit Original and no Embed.
This commit is contained in:
1 parent
c472749a87
commit
6ed4a4511e
3 files changed
+100
-11
No files matched your search
@@ -32,7 +32,7 @@ pub(super) fn image_section(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
Text::new(details.clone()).shade(Shade::Muted).show(ui);
|
||||
Grid::new(&HALVES).show(ui, |ui, _| {
|
||||
// PLAN: assumed `crate::place::LinkAction::{shown(linked) -> &'static [LinkAction], label(self), run(self, app, id, &name)}` (files-w14, fl.A18)
|
||||
for action in crate::place::LinkAction::shown(linked) {
|
||||
for action in crate::place::LinkAction::shown(linked, crate::place::is_dcs_image(app, id)) {
|
||||
if Button::new(action.label()).sizing(Sizing::FillWidth).show(ui).clicked() {
|
||||
action.run(app, id, &name);
|
||||
}
|
||||
|
||||
@@ -767,6 +767,77 @@ fn several_mixed_images_offer_embed_and_unembed() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A single-file DCS 2.0 file with one Cyan plate, a 2 × 2 grayscale image on a 20 × 10 pt page,
|
||||
/// made from scratch as http://www.telegraphics.net/doc/DCS.txt describes it; without a clipping
|
||||
/// path it places as a plain linked image.
|
||||
fn dcs_file() -> Vec<u8> {
|
||||
let plate = "%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 20 10\n%%EndComments\n20 10 scale\n2 2 8 [2 0 0 -2 0 2] <0000ffff> image\nshowpage\n%%Trailer\n%%EOF\n";
|
||||
let header = |at: usize| {
|
||||
format!(
|
||||
"%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 20 10\n%%PlateFile: (Cyan) EPS #{at:010} {:010}\n%%EndComments\n20 10 scale 2 2 8 [2 0 0 -2 0 2] <808080808080808080808080> false 3 colorimage showpage\n%%EOF\n",
|
||||
plate.len()
|
||||
)
|
||||
};
|
||||
let mut out = header(header(0).len()).into_bytes();
|
||||
out.extend(plate.as_bytes());
|
||||
out
|
||||
}
|
||||
|
||||
/// Images placed from DCS files stay linked (`links.embed` refuses them): with one selected,
|
||||
/// neither surface offers Embed; with a DCS image and a linked image selected, Embed embeds the
|
||||
/// linked one and leaves the DCS image linked; with a DCS image and an embedded one, only
|
||||
/// Unembed… is offered.
|
||||
#[test]
|
||||
fn several_images_leave_dcs_images_out_of_embed() {
|
||||
let dir = Folder::new("dcs-several");
|
||||
let placed = Cell::new(0);
|
||||
let setup = |with: &'static str| {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
placed.set(placed.get() + 1);
|
||||
let dcs = dir.file(&format!("plates-{}.eps", placed.get()), &dcs_file());
|
||||
let r = app.run("file.place", json!({"path": dcs, "at": [50, 50]})).unwrap();
|
||||
let dcs = r["ids"][0].as_u64().unwrap();
|
||||
let png = dir.file(&format!("other-{}.png", placed.get()), &png(30, 20));
|
||||
let other = match with {
|
||||
"linked" => Some(app.run("file.place", json!({"path": png, "at": [200, 50]})).unwrap()["ids"][0].as_u64().unwrap()),
|
||||
"embedded" => Some(app.run("file.place", json!({"path": png, "at": [200, 50], "link": false})).unwrap()["ids"][0].as_u64().unwrap()),
|
||||
_ => None,
|
||||
};
|
||||
let ids: Vec<u64> = [Some(dcs), other].into_iter().flatten().collect();
|
||||
app.run("select.set", json!({"ids": ids})).unwrap();
|
||||
(app, dcs, other)
|
||||
};
|
||||
let alone = || setup("alone").0;
|
||||
{
|
||||
let app = alone();
|
||||
let st = app.session.active().unwrap();
|
||||
let id = st.selection.objects[0];
|
||||
assert!(matches!(st.doc.node(id).unwrap().kind, vectorcraft_doc::NodeKind::Image(_)), "placed as one image");
|
||||
}
|
||||
for (surface, h) in image_surfaces(alone) {
|
||||
assert!(h.shows("Edit Original") && !h.shows("Embed"), "{surface}: one DCS image");
|
||||
}
|
||||
let ids = RefCell::new(vec![]);
|
||||
let with_linked = || {
|
||||
let (app, dcs, other) = setup("linked");
|
||||
ids.borrow_mut().push((dcs, other.unwrap()));
|
||||
app
|
||||
};
|
||||
// Each surface draws its own app, made in this order.
|
||||
for (n, (surface, mut h)) in image_surfaces(with_linked).into_iter().enumerate() {
|
||||
let (dcs, linked) = ids.borrow()[n];
|
||||
assert_eq!(selected(&h.app()).len(), 2, "{surface}");
|
||||
h.click("Embed");
|
||||
let mut app = h.app();
|
||||
assert!(is_embedded(&mut app, linked), "{surface}: the linked image is embedded");
|
||||
assert!(!is_embedded(&mut app, dcs), "{surface}: the DCS image stays linked");
|
||||
}
|
||||
for (surface, h) in image_surfaces(|| setup("embedded").0) {
|
||||
assert!(h.shows("Unembed…") && !h.shows("Embed"), "{surface}: a DCS image and an embedded one");
|
||||
}
|
||||
}
|
||||
|
||||
/// Unembed… acts on several selected embedded images: it asks for one folder, writes a file for
|
||||
/// each image there and links each one to its file; with no folder picked, nothing changes.
|
||||
#[test]
|
||||
|
||||
+28
-10
@@ -1095,9 +1095,14 @@ pub(crate) enum LinkAction {
|
||||
}
|
||||
|
||||
impl LinkAction {
|
||||
/// The actions that apply to an image, `linked` or embedded.
|
||||
pub(crate) fn shown(linked: bool) -> &'static [LinkAction] {
|
||||
if linked { &[LinkAction::Embed, LinkAction::EditOriginal] } else { &[LinkAction::Unembed] }
|
||||
/// The actions that apply to an image, `linked` or embedded. An image placed from a DCS file
|
||||
/// (`dcs`) stays linked, as `links.embed` refuses it, so it has no Embed.
|
||||
pub(crate) fn shown(linked: bool, dcs: bool) -> &'static [LinkAction] {
|
||||
match (linked, dcs) {
|
||||
(true, false) => &[LinkAction::Embed, LinkAction::EditOriginal],
|
||||
(true, true) => &[LinkAction::EditOriginal],
|
||||
(false, _) => &[LinkAction::Unembed],
|
||||
}
|
||||
}
|
||||
|
||||
/// The action's label in the interface language.
|
||||
@@ -1119,11 +1124,19 @@ impl LinkAction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Several selected objects that are all images: the ids of the linked ones and of the embedded
|
||||
/// ones, in selection order.
|
||||
/// Is image `id` of the active document placed from a DCS file (its pixels hold plates), which
|
||||
/// `links.embed` refuses?
|
||||
pub(crate) fn is_dcs_image(app: &VectorcraftApp, id: u64) -> bool {
|
||||
let Some(st) = app.session.active() else { return false };
|
||||
let Some(NodeKind::Image(im)) = st.doc.node(vectorcraft_doc::NodeId(id)).map(|n| &n.kind) else { return false };
|
||||
im.link.is_some() && st.doc.images.get(&im.key).is_some_and(vectorcraft_doc::ImageBlob::is_separated)
|
||||
}
|
||||
|
||||
/// Several selected objects that are all images: the ids of the linked ones that can be embedded
|
||||
/// and of the embedded ones, in selection order. Images placed from DCS files are in neither.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub(crate) struct SeveralImages {
|
||||
/// The linked images.
|
||||
/// The linked images, except those placed from DCS files.
|
||||
pub(crate) linked: Vec<u64>,
|
||||
/// The embedded images.
|
||||
pub(crate) embedded: Vec<u64>,
|
||||
@@ -1140,13 +1153,18 @@ impl SeveralImages {
|
||||
let mut out = SeveralImages::default();
|
||||
for id in &st.selection.objects {
|
||||
let NodeKind::Image(im) = &st.doc.node(*id)?.kind else { return None };
|
||||
if im.link.is_some() { out.linked.push(id.0) } else { out.embedded.push(id.0) }
|
||||
match &im.link {
|
||||
None => out.embedded.push(id.0),
|
||||
Some(_) if st.doc.images.get(&im.key).is_some_and(vectorcraft_doc::ImageBlob::is_separated) => {}
|
||||
Some(_) => out.linked.push(id.0),
|
||||
}
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// The actions that apply to these images: Embed while one of them is linked, and Unembed…
|
||||
/// while one is embedded and they can be written out. Edit Original opens one file, so the
|
||||
/// The actions that apply to these images: Embed while one of them is linked and not placed
|
||||
/// from a DCS file, and Unembed… while one is embedded and they can be written out. Edit
|
||||
/// Original opens one file, so the
|
||||
/// surfaces offer it for one image only.
|
||||
pub(crate) fn shown(&self, app: &VectorcraftApp) -> Vec<LinkAction> {
|
||||
let mut shown = vec![];
|
||||
@@ -1234,7 +1252,7 @@ pub fn control_bar_details(app: &mut VectorcraftApp, ui: &mut egui::Ui) -> bool
|
||||
if app.session.tool_id() == vectorcraft_tools::cropimage::ID {
|
||||
return true;
|
||||
}
|
||||
for action in LinkAction::shown(linked) {
|
||||
for action in LinkAction::shown(linked, is_dcs_image(app, id)) {
|
||||
let at = if *action == LinkAction::EditOriginal { rank::DETAIL } else { rank::GROUP };
|
||||
Row::new().fit_rank(at).show(ui, |ui, _| {
|
||||
if clicked(&Button::new(action.label().to_string()).show(ui)) {
|
||||
|
||||
Reference in new issue
Block a user