DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
PDF: apply an explicit all-on layer choice and keep an unrewritable one failing closed
skylar taylor-barrick2927861b3275
diff --git a/crates/pdf/src/export.rs b/crates/pdf/src/export.rsindex d06fdde0c..00248bbab 100644--- a/crates/pdf/src/export.rs+++ b/crates/pdf/src/export.rs@@ -1008,7 +1008,10 @@ impl Exporter<'_> {let g = &if it.media.is_some() { it.drawn_graphic(&self.doc.assets).unwrap_or_else(|| g.clone()) } else { g.clone() };if let Some(p) = &path {s.push_clip_path(p, &FillRule::NonZero);- self.graphic(s, g, (!it.pdf_hidden_layers.is_empty()).then_some(it.pdf_hidden_layers.as_slice()));+ // An explicit all-on choice is `Some(&[])`, not the file's defaults: passing+ // `None` would embed the source's default-hidden layers and skip the rewrite+ // error that a stale choice must raise.+ self.graphic(s, g, it.has_pdf_layer_override().then_some(it.pdf_hidden_layers.as_slice()));s.pop();}}diff --git a/crates/pdf/src/optional_content.rs b/crates/pdf/src/optional_content.rsindex 3a9e09289..ceb302adb 100644--- a/crates/pdf/src/optional_content.rs+++ b/crates/pdf/src/optional_content.rs@@ -254,8 +254,10 @@ pub(crate) fn prepare(bytes: &Arc<Vec<u8>>, choice: Option<&[String]>) -> Resultif is_hidden {effective.push(id);}- // Unmarked groups are visible when registered in the output catalog.- if !is_hidden && name.is_some() {+ // Unmarked groups are visible when registered in the output catalog. An explicit choice+ // writes every group's state, so the catalog rewrite is attempted (and a file whose+ // history cannot take one fails closed) even when the choice happens to change nothing.+ if !is_hidden && name.is_some() && choice.is_none() {continue;}let marker = is_hidden.to_string();