From 6c84f392b27d2a1a5a3e1867a741286c554c7167 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 26 Mar 2025 18:05:44 +0100 Subject: [PATCH] Pick correct PDF version automatically based on substandard --- crates/typst-pdf/src/lib.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/typst-pdf/src/lib.rs b/crates/typst-pdf/src/lib.rs index c7bae57ac..2123586d3 100644 --- a/crates/typst-pdf/src/lib.rs +++ b/crates/typst-pdf/src/lib.rs @@ -105,16 +105,20 @@ impl PdfStandards { } } - let version = version.unwrap_or(PdfVersion::Pdf17); - let validator = validator.unwrap_or_default(); - - let config = Configuration::new_with(validator, version).ok_or_else(|| { - eco_format!( - "{} is not compatible with {}", - version.as_str(), - validator.as_str() - ) - })?; + let config = match (version, validator) { + (Some(version), Some(validator)) => { + Configuration::new_with(validator, version).ok_or_else(|| { + eco_format!( + "{} is not compatible with {}", + version.as_str(), + validator.as_str() + ) + })? + } + (Some(version), None) => Configuration::new_with_version(version), + (None, Some(validator)) => Configuration::new_with_validator(validator), + (None, None) => Configuration::new_with_version(PdfVersion::Pdf17), + }; Ok(Self { config }) }