export-w5: net change of 2 commits

- export-w5: written from its sheet
- export-w5: repair 1
This commit is contained in:
bflatastic
2026-11-21 21:27:54 +07:00
parent 05f254cf65
commit 12b620a244
3 changed files with 73 additions and 26 deletions
@@ -208,13 +208,7 @@ impl Sections<'_> {
destinations.extend(profiles.iter().map(|name| (name.clone(), Label::from(name.clone()))));
name_row(ui, "destination", &words.destination, &mut output.destination, destinations, converting);
// A standard decides whether colours are tagged.
// P3(export-w5): ex.P2 -- an unset `profiles` shows the default choice and stays unset until picked.
let before = output.profiles.unwrap_or_default();
let mut profile_choice = before;
pick(ui, "profiles", "profileInclusion", &words.profile_inclusion, words, &mut profile_choice, standard == Standard::None);
if profile_choice != before {
output.profiles = Some(profile_choice);
}
pick_or_unset(ui, "profiles", "profileInclusion", &words.profile_inclusion, words, &mut output.profiles, standard == Standard::None);
if cmyk_only {
note(ui, &words.note_cmyk_only);
} else if standard != Standard::None {
@@ -401,8 +395,13 @@ fn flag(ui: &mut Ui, id: &'static str, label: &Label, value: &mut bool, enabled:
}
}
/// Every choice of `T` with its words.
fn entries<T: Choice + Copy>(kind: &str, words: &PdfExportWords) -> Vec<(T, Label)> {
T::ALL.iter().zip(T::IDS).zip(T::LABELS).map(|((choice, choice_id), choice_label)| (*choice, words.choice(kind, choice_id, choice_label))).collect()
}
/// A list of the choices of `T`, worded through `words`.
fn pick<T: Choice + PartialEq + Send + Sync>(
fn pick<T: Choice + Copy + PartialEq + Send + Sync>(
ui: &mut Ui,
id: &'static str,
kind: &str,
@@ -411,12 +410,7 @@ fn pick<T: Choice + PartialEq + Send + Sync>(
value: &mut T,
enabled: bool,
) {
let entries: Vec<Entry<T>> = T::ALL
.iter()
.zip(T::IDS)
.zip(T::LABELS)
.map(|((choice, choice_id), choice_label)| Entry::new(*choice, words.choice(kind, choice_id, choice_label)))
.collect();
let entries: Vec<Entry<T>> = entries::<T>(kind, words).into_iter().map(|(choice, text)| Entry::new(choice, text)).collect();
field(ui, id, label, enabled, |ui| {
let chosen = Select::new(label.clone(), Bind::given(*value), &entries).show(ui);
if let Some(next) = chosen.value().cloned() {
@@ -425,20 +419,25 @@ fn pick<T: Choice + PartialEq + Send + Sync>(
});
}
/// A list of the choices of `T` with a first entry `unset` that stands for `None`.
#[allow(dead_code, clippy::too_many_arguments)] // P3(export-w5): ex.P13
fn pick_or_unset<T: Choice + PartialEq + Send + Sync>(
/// A list of the choices of `T` with a first entry, `words.profile_default`, that stands for `None`.
// PLAN: the contract's `unset: &Label` argument is dropped (it only ever is `words.profile_default`); it kept the fn over clippy's argument limit.
fn pick_or_unset<T: Choice + Copy + PartialEq + Send + Sync>(
ui: &mut Ui,
id: &'static str,
kind: &str,
label: &Label,
words: &PdfExportWords,
value: &mut Option<T>,
unset: &Label,
enabled: bool,
) {
let _ = (ui, id, kind, label, words, value, unset, enabled);
todo!("ex.P13")
let mut entries = vec![Entry::new(None, words.profile_default.clone())];
entries.extend(entries::<T>(kind, words).into_iter().map(|(choice, text)| Entry::new(Some(choice), text)));
field(ui, id, label, enabled, |ui| {
let chosen = Select::new(label.clone(), Bind::given(*value), &entries).show(ui);
if let Some(next) = chosen.value().cloned() {
*value = next;
}
});
}
/// A list of names (`value`, `label`); a current value that is not among them is added.
@@ -1,7 +1,9 @@
//! Stories of `PdfExportDialog`.
use super::PdfExportDialog;
use crate::contract::Bind;
use super::{HostedPdfExport, PdfArtboards, PdfExportDialog, PdfExportMode, PresetDraft};
use crate::buttons::Button;
use crate::contract::{Bind, Show as _, clicked};
use crate::dialog::stories::hosted_with;
use crate::testing::{Drive, StoryData, StoryOutput, story};
use craft_pdf::settings::{PdfSettings, builtin_preset};
use egui::Ui;
@@ -25,3 +27,40 @@ fn pdf_export_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
}
PdfExportDialog::new("Story", Bind::bound(settings)).opened(Bind::bound(open)).artboard_count(ARTBOARDS).show(ui).into()
}
#[story(PdfExportDialog<'static>, covers = [], drive = Drive::Never)]
fn pdf_export_art_bounds(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let (settings, open) = data.value("pdf-art-bounds", (PdfSettings::default(), true));
PdfExportDialog::new("Story", Bind::bound(settings)).opened(Bind::bound(open)).artboards(PdfArtboards::ArtBounds).show(ui).into()
}
#[story(PdfExportDialog<'static>, covers = [], drive = Drive::Never)]
fn pdf_export_preset_editor(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let (settings, open, draft) = data.value("pdf-editor", (PdfSettings::default(), true, PresetDraft::default()));
PdfExportDialog::new("Story", Bind::bound(settings))
.opened(Bind::bound(open))
.mode(PdfExportMode::PresetEditor)
.preset_draft(Bind::bound(draft))
.show(ui)
.into()
}
#[story(PdfExportDialog<'static>, covers = [], drive = Drive::Never)]
fn pdf_export_custom_flattener(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let (settings, open) = data.value("pdf-custom", (PdfSettings::default(), true));
PdfExportDialog::new("Story", Bind::bound(settings))
.opened(Bind::bound(open))
.artboard_count(ARTBOARDS)
.custom_flattener(true)
.show(ui)
.into()
}
#[story(PdfExportDialog<'static>, covers = [], drive = Drive::Never)]
fn hosted_pdf_export(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
// The dialog starts closed; the button opens the real one.
if clicked(&Button::new("Save PDF…").show(ui)) {
*data.value("open", false) = true;
}
hosted_with(ui, data, (), || HostedPdfExport::new("Story", PdfSettings::default()).artboard_count(ARTBOARDS), |_| {})
}
@@ -3,7 +3,7 @@
use super::PdfSection;
use super::words::PdfExportWords;
use crate::runtime::env::Label;
use craft_pdf::settings::{Choice, ImageCompression, PdfSettings};
use craft_pdf::settings::{Choice, ImageCompression, PdfSettings, UNSET_CHOICE};
/// The value of one setting as the Summary compares and words it.
#[derive(Clone, Debug, PartialEq)]
@@ -22,8 +22,12 @@ enum Shown {
/// The Summary's lines for `settings` against `base`, then the `warnings`, with LF line breaks (CR and CRLF in values
/// become LF) and a final LF: what the Summary section shows and Save Summary… writes.
pub fn summary_text(words: &PdfExportWords, settings: &PdfSettings, base: &PdfSettings, warnings: &[String]) -> String {
let _ = (words, settings, base, warnings);
todo!("ex.P14")
let mut text = String::new();
for line in differences(words, settings, base).iter().chain(warnings) {
text.push_str(&line.replace("\r\n", "\n").replace('\r', "\n"));
text.push('\n');
}
text
}
fn choice<T: Choice + PartialEq>(kind: &'static str, value: T) -> Shown {
@@ -107,7 +111,12 @@ fn leaves(settings: &PdfSettings) -> Vec<(&'static str, Shown)> {
out.extend([
("output.conversion", choice("colorConversion", output.conversion)),
("output.destination", Shown::Text(output.destination.clone())),
("output.profiles", choice("profileInclusion", output.profiles.unwrap_or_default())), // P3(export-w5): ex.P2
(
"output.profiles",
output.profiles.map_or(Shown::Choice { kind: "profileInclusion", id: UNSET_CHOICE, label: "Default" }, |profiles| {
choice("profileInclusion", profiles)
}),
),
("output.outputIntent", Shown::Text(output.output_intent.clone())),
("output.outputCondition", Shown::Text(output.output_condition.clone())),
("output.outputConditionId", Shown::Text(output.output_condition_id.clone())),