From 0372243ef2f09dad111493ae00f2a468e4e5b92b Mon Sep 17 00:00:00 2001 From: Marco Arnulfo <103679419+marcoarnulfo@users.noreply.github.com> Date: Tue, 13 Oct 2026 06:49:39 +0200 Subject: [PATCH] fix(ui): the PDF/A dialog shows a declared PDF/UA (#1309) (#1438) The declaration line was built from the PDF/A identification alone, so a document that declares only PDF/UA-1 read "Declared conformance: none". It now lists PDF/UA next to PDF/A, and still says none when neither is declared. pdfa_dialog_shows_a_declared_pdfua fails before the change. --- crates/ui-egui/src/standards_ui.rs | 4 ++- crates/ui-egui/tests/compare.rs | 48 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/standards_ui.rs b/crates/ui-egui/src/standards_ui.rs index 55f64349..1d409f20 100644 --- a/crates/ui-egui/src/standards_ui.rs +++ b/crates/ui-egui/src/standards_ui.rs @@ -50,7 +50,9 @@ pub(crate) fn body(ui: &mut egui::Ui, app: &mut PdfCraftApp, t: &Tokens) -> bool ui.label(egui::RichText::new("PDF/A").font(theme::semibold(18.0))); ui.add_space(6.0); let declared = app.active_ids().and_then(|(_, id)| app.session.get(id)).map(|d| d.standards()).unwrap_or_default(); - let shown = declared.pdfa.as_ref().map_or(tl!("none").to_string(), |(p, c)| format!("PDF/A-{p}{}", c.to_lowercase())); + let mut standards: Vec = declared.pdfa.iter().map(|(p, c)| format!("PDF/A-{p}{}", c.to_lowercase())).collect(); + standards.extend(declared.pdfua.map(|p| format!("PDF/UA-{p}"))); + let shown = if standards.is_empty() { tl!("none").to_string() } else { standards.join(", ") }; ui.label(crate::i18n::fmt(tl!("Declared conformance: {shown}"), &[("shown", &shown)])); if !declared.output_intents.is_empty() { ui.label( diff --git a/crates/ui-egui/tests/compare.rs b/crates/ui-egui/tests/compare.rs index e2536c6d..089d3b88 100644 --- a/crates/ui-egui/tests/compare.rs +++ b/crates/ui-egui/tests/compare.rs @@ -90,6 +90,54 @@ fn pdfa_dialog_verifies_and_converts() { assert_eq!(h.state().session.get(id).unwrap().can_undo(), Some("Save as PDF/A-2b")); } +/// A one-page PDF whose XMP declares the given `pdfaid`/`pdfuaid` attributes. +fn declaring(ids: &str) -> Vec { + let xmp = format!( + "" + ); + let objects = [ + "<< /Type /Catalog /Pages 2 0 R /Metadata 4 0 R >>".to_string(), + "<< /Type /Pages /Kids [3 0 R] /Count 1 >>".to_string(), + "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 300] /Resources << >> >>".to_string(), + format!("<< /Type /Metadata /Subtype /XML /Length {} >>\nstream\n{xmp}\nendstream", xmp.len()), + ]; + let mut pdf = b"%PDF-1.7\n".to_vec(); + let mut offsets = Vec::new(); + for (i, o) in objects.iter().enumerate() { + offsets.push(pdf.len()); + pdf.extend_from_slice(format!("{} 0 obj\n{o}\nendobj\n", i + 1).as_bytes()); + } + let xref = pdf.len(); + pdf.extend_from_slice(b"xref\n0 5\n0000000000 65535 f \n"); + for o in offsets { + pdf.extend_from_slice(format!("{o:010} 00000 n \n").as_bytes()); + } + pdf.extend_from_slice(format!("trailer\n<< /Size 5 /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n").as_bytes()); + pdf +} + +#[test] +fn pdfa_dialog_shows_a_declared_pdfua() { + // The dialog read only the PDF/A identification, so a PDF/UA-1 document showed "none" (#1309). + for (ids, shown) in [ + ("pdfuaid:part=\"1\"", "Declared conformance: PDF/UA-1"), + ("pdfaid:part=\"2\" pdfaid:conformance=\"B\" pdfuaid:part=\"1\"", "Declared conformance: PDF/A-2b, PDF/UA-1"), + ] { + let doc = declaring(ids); + let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| { + let mut app = PdfCraftApp::new(); + app.set_option("language", "en").unwrap(); + app.open_bytes("ua.pdf", None, doc.clone()).unwrap(); + app + }); + h.run_steps(4); + assert!(h.state_mut().execute("standards.pdfa")); + h.run_steps(2); + h.get_by_label(shown); + } +} + #[test] fn export_to_word_html_and_rtf() { let doc = Session::new().create_from_text("t", "Exported words").unwrap().to_vec();