mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 20:18:38 -05:00
Import PDF: name Crop To only when it differs from the box it started on
A keyboard preview canceled with Escape restores the starting box, so it no longer counts as a pick.
This commit is contained in:
1 parent
a73dd2ad29
commit
eb6fda20cb
1 file changed
+10
-12
@@ -10,9 +10,9 @@
|
||||
//! for All, off for a range; picking the other of All and Range sets it back to `null`; `linksOn`
|
||||
//! is the effective flag, `__linkable` is false for a file `linkPages` does not take, such as one
|
||||
//! over its size limit), `cropTo` (when opening, it starts on `trim` for a file with editing data,
|
||||
//! else `crop`; OK names the box only when it was picked, so a file with the starting box opens
|
||||
//! as it does without the dialog), `textAs` (`text` | `outlines`; it starts from the `pdfTextAs`
|
||||
//! preference for a PDF (`__pdf`; Editable for a `.ai` or `.ait` file), or from the `textAs` a place
|
||||
//! else `crop`; OK names the box only when it differs from the box it started on, so a file with
|
||||
//! the starting box opens as it does without the dialog), `textAs` (`text` | `outlines`; it starts
|
||||
//! from the `pdfTextAs` preference for a PDF (`__pdf`; Editable for a `.ai` or `.ait` file), or from the `textAs` a place
|
||||
//! gives (`__textAsGiven`), and OK keeps a PDF's choice there; a linked place shows the file's own
|
||||
//! text, so placing linked leaves it as it is, and Outlines clears Import PDF Pages as Links) and
|
||||
//! `password`. `__locked` is set until the password is accepted: OK then unlocks the file, and with
|
||||
@@ -148,9 +148,9 @@ struct State {
|
||||
pages: Vec<usize>,
|
||||
link_pages: Option<bool>,
|
||||
crop: CropTo,
|
||||
/// Whether Crop To was picked. Opening, a box left as it starts ([`opening_crop`]) is not
|
||||
/// named, so a file with editing data opens on its trim boxes, as it opens without the dialog.
|
||||
crop_chosen: bool,
|
||||
/// The box Crop To started on ([`opening_crop`] when opening). OK names the box only when
|
||||
/// it differs from this box.
|
||||
start_crop: CropTo,
|
||||
text_as: TextAs,
|
||||
pdf: bool,
|
||||
password: String,
|
||||
@@ -220,8 +220,9 @@ impl State {
|
||||
let opened = vectorcraft_pdf::open_pdf(&self.file.bytes, self.password().as_deref()).map_err(|e| e.to_string())?;
|
||||
self.locked = false;
|
||||
self.page_count = opened.page_count();
|
||||
if !self.crop_chosen && self.place.is_none() {
|
||||
if self.crop == self.start_crop && self.place.is_none() {
|
||||
self.crop = opening_crop(Some(&opened));
|
||||
self.start_crop = self.crop;
|
||||
}
|
||||
Ok(self.page_count > 1 && !self.password_only)
|
||||
}
|
||||
@@ -278,7 +279,6 @@ impl State {
|
||||
let text = text()?;
|
||||
let i = CropTo::IDS.iter().position(|id| *id == text).ok_or("cropTo is not a crop box")?;
|
||||
self.crop = CropTo::ALL.get(i).copied().unwrap_or_default();
|
||||
self.crop_chosen = true;
|
||||
}
|
||||
"textAs" => {
|
||||
let id = text()?;
|
||||
@@ -468,9 +468,7 @@ fn pages_body(ui: &mut egui::Ui, s: &mut State, preview: Option<&(Revision, Arc<
|
||||
});
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let crops: Vec<Entry<CropTo>> = CropTo::ALL.iter().zip(CropTo::LABELS).map(|(crop, label)| Entry::new(*crop, *label)).collect();
|
||||
let before = s.crop;
|
||||
Field::new(tl!("Crop To")).show(ui, |ui, _| Select::new(tl!("Crop To"), Bind::bound(&mut s.crop), &crops).show(ui));
|
||||
s.crop_chosen |= s.crop != before;
|
||||
let linked = s.places_linked();
|
||||
let texts = [Entry::new(TextAs::Text, tl!("Editable")), Entry::new(TextAs::Outlines, tl!("Outlines"))];
|
||||
Field::new(tl!("Text")).show(ui, |ui, _| Select::new(tl!("Text"), Bind::bound(&mut s.text_as), &texts).enabled(!linked).show(ui));
|
||||
@@ -563,7 +561,7 @@ fn offer_with(app: &mut VectorcraftApp, name: &str, bytes: &[u8], path: Option<S
|
||||
pages: Vec::new(),
|
||||
link_pages: None,
|
||||
crop,
|
||||
crop_chosen: false,
|
||||
start_crop: crop,
|
||||
// The PDF Text preference is for PDFs: a `.ai` or `.ait` file starts from Editable, as it
|
||||
// opens or is placed without the dialog.
|
||||
text_as: if format == "pdf" { preferred_text_as(app) } else { TextAs::Text },
|
||||
@@ -724,7 +722,7 @@ fn confirm(app: &mut VectorcraftApp, s: &State) -> Result<(), String> {
|
||||
let mut p = json!({"password": s.password(), "textAs": s.text_as.id()});
|
||||
// A box left as it starts ([`opening_crop`]) is not named: a file with editing data then
|
||||
// opens on its trim boxes, from its editing layers where it can, as without the dialog.
|
||||
if s.crop_chosen {
|
||||
if s.crop != s.start_crop {
|
||||
p["cropTo"] = json!(s.crop.id());
|
||||
}
|
||||
// An empty range under Range opens every page.
|
||||
|
||||
Reference in new issue
Block a user