mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 12:21:08 +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.
65 lines
2.6 KiB
Rust
65 lines
2.6 KiB
Rust
//! Save PDF settings: the model, presets, checks and warnings are craft-pdf's (what a preset stores
|
||
//! and `document.exportPdf` takes, in camelCase JSON). This module re-exports them under this
|
||
//! crate's names and keeps the `choice!` macro that the Print settings and the import options use.
|
||
|
||
use crate::PdfError;
|
||
|
||
// Listed by name: a glob would bring `ColorMode` and `ProfileKind`, which `output.rs` and
|
||
// `vectorcraft_color::cms` already name for their own types.
|
||
pub use craft::pdf::settings::{
|
||
AdvancedSettings, BleedSettings, Changes, Choice, ColorConversion, Compatibility, CompressionSettings, DOCUMENT_CMYK, Downsample, Encryption,
|
||
ImageCodec, ImageCompression, JpegQuality, MarkKind, MarkSettings, MonoCodec, MonoCompression, OutputSettings, Overprint, PdfPreset, PdfSettings,
|
||
Printing, ProfileCatalog, ProfileInclusion, SecuritySettings, SettingsError, SettingsWarning, Standard, UNSET_CHOICE, builtin_preset,
|
||
builtin_presets, default_preset_name,
|
||
};
|
||
|
||
/// A closed list of choices: a serde enum (its JSON ids) with a UI label per variant.
|
||
macro_rules! choice {
|
||
($(#[$m:meta])* $name:ident { $($(#[$vm:meta])* $v:ident = $id:literal, $label:literal;)+ } default $d:ident) => {
|
||
$(#[$m])*
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||
pub enum $name {
|
||
$($(#[$vm])* #[serde(rename = $id)] $v,)+
|
||
}
|
||
|
||
impl $crate::Choice for $name {
|
||
const ALL: &'static [Self] = &[$(Self::$v),+];
|
||
const IDS: &'static [&'static str] = &[$($id),+];
|
||
const LABELS: &'static [&'static str] = &[$($label),+];
|
||
}
|
||
|
||
impl $name {
|
||
/// The label shown in the PDF dialogs.
|
||
pub fn label(self) -> &'static str {
|
||
match self {
|
||
$(Self::$v => $label,)+
|
||
}
|
||
}
|
||
|
||
/// The JSON id.
|
||
pub fn id(self) -> &'static str {
|
||
match self {
|
||
$(Self::$v => $id,)+
|
||
}
|
||
}
|
||
}
|
||
|
||
impl Default for $name {
|
||
fn default() -> Self {
|
||
Self::$d
|
||
}
|
||
}
|
||
};
|
||
}
|
||
pub(crate) use choice;
|
||
|
||
/// `v` lies in `lo..=hi` (and is a number). The error names the range with its unit as one value
|
||
/// (`72–2400 ppi`), so a catalog can match the message and translate it.
|
||
pub(crate) fn within(name: &str, v: f64, lo: f64, hi: f64, unit: &str) -> Result<(), PdfError> {
|
||
if (lo..=hi).contains(&v) {
|
||
return Ok(());
|
||
}
|
||
let range = format!("{lo}–{hi}{unit}");
|
||
Err(PdfError::BadSetting(format!("{name} must be {range} (got {v})")))
|
||
}
|