Files
pdfcraft/crates/ui-egui/tests/compare.rs
T
84a75eae1b M10: Presentation (.pptx) export (#1137) (#1162)
* feat: presentation (.pptx) export (#1137)

- Implement OpenXML PresentationML (.pptx) generator in crates/export/src/pptx.rs:
  - Generate [Content_Types].xml, _rels/.rels, core properties, presentation.xml
  - Build slide master, blank slide layout, and DrawingML theme
  - Render slides per page: largest text block as title shape, remaining paragraphs as body text box with font size, bold, italic, and color formatting
  - Embed images with proper DrawingML picture shapes and relationships
  - Generate DrawingML table shapes with column grid and span merging
- Wire OfficeFormat::Pptx into crates/engine/src/compare.rs and export_office
- Register export.pptx command and mark Presentation (.pptx) Ready in catalog
- Support pptx in automation doc_export_office tool
- Wire export.pptx into UI commands and file save dialog
- Add unit and integration tests across crates/export, engine, automation, and ui-egui
- Update create.export-pptx parity feature evidence and docs

* pptx export: saturating slide positions, matching cell-border tags, theme ea/cs fonts, package test

- Heights and the running vertical position use clamped/saturating arithmetic, so a hostile
  text size or image rectangle (1e300, NaN, inf) can't overflow i64; the item loop uses get().
- The table cells' a:lnR and a:lnT borders were closed with </a:lnL>, which made every slide
  with a table malformed XML; they now close with their own tags.
- The theme's major/minor fonts carry the schema-required a:ea and a:cs children.
- New test walks the produced zip entry by entry (sizes, inflation, central directory), checks
  every XML part's tags balance, the required parts, content-type overrides, relationship
  targets and that no placeholders are used; a hostile-sizes test covers the overflow.
- Test literals gain main's Block/Image rotation and size fields.
- Parity notes say what is still unverified.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: KrzysztofC <[email protected]>
Co-authored-by: Brandon Thomas <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
2026-10-11 21:55:25 -04:00

109 lines
4.6 KiB
Rust

//! Compare files in the real shell (egui_kittest): the dialog, the Compare panel, marks and
//! the report.
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use pdfcraft_engine::Session;
use pdfcraft_ui_egui::{PdfCraftApp, RightPanel};
#[test]
fn compare_two_versions() {
let s = Session::new();
let v1 = s.create_from_text("t", "Delivery within five days. Returns accepted.").unwrap().to_vec();
let v2 = s.create_from_text("t", "Delivery within three days. Returns accepted for a week.").unwrap().to_vec();
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("v1.pdf", None, v1.clone()).unwrap();
app.open_bytes("v2.pdf", None, v2.clone()).unwrap();
app
});
h.run_steps(4);
assert!(h.state_mut().execute("doc.compare"));
h.run_steps(2);
h.get_by_label("Compare Files");
h.get_by_label("Compare").click();
h.run_steps(3);
assert_eq!(h.state().right, Some(RightPanel::Compare));
assert_eq!(h.state().toast.clone().unwrap().0, "2 differences found");
h.get_by_label("2 Replaced");
h.get_by_label("\"five\" → \"three\"").click();
h.run_steps(2);
assert_eq!(h.state().compare.as_ref().unwrap().selected, Some(0));
let id = h.state().active_ids().unwrap().1;
let i = h.state().active_ids().unwrap().0;
assert_eq!(h.state().views[i].compare_marks.len(), 2);
h.get_by_label("Mark as comments").click();
h.run_steps(3);
assert_eq!(h.state().session.get(id).unwrap().info.annotations.len(), 2);
h.get_by_label("Report…").click();
h.run_steps(3);
assert_eq!(h.state().session.get(h.state().active_ids().unwrap().1).unwrap().name, "Compare Report.pdf");
}
/// Writes a screenshot of the Compare panel when PDFCRAFT_SHOT is set (for review).
#[test]
fn compare_panel_screenshot() {
let Ok(out) = std::env::var("PDFCRAFT_SHOT") else { return };
let s = Session::new();
let v1 = s.create_from_text("t", "Delivery within five days. Returns accepted.").unwrap().to_vec();
let v2 = s.create_from_text("t", "Delivery within three days. Returns accepted for a week.").unwrap().to_vec();
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("v1.pdf", None, v1.clone()).unwrap();
app.open_bytes("v2.pdf", None, v2.clone()).unwrap();
app
});
h.run_steps(4);
h.state_mut().compare_old = h.state().views.first().map(|v| v.id);
h.state_mut().run_compare();
for _ in 0..20 {
h.run_steps(2);
std::thread::sleep(std::time::Duration::from_millis(50));
}
h.render().unwrap().save(out).unwrap();
}
#[test]
fn pdfa_dialog_verifies_and_converts() {
let doc = Session::new().create_from_text("t", "Keep forever").unwrap().to_vec();
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("keep.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("Declared conformance: none");
h.get_by_label("Verify").click();
h.run_steps(3);
h.get_by_label("The document has no XMP metadata");
h.get_by_label("Save as PDF/A").click();
h.run_steps(3);
h.get_by_label("Declared conformance: PDF/A-2b");
let issues = h.state().pdfa.issues.clone().unwrap();
assert!(issues.iter().all(|i| !i.fixable), "{issues:?}");
let id = h.state().active_ids().unwrap().1;
assert_eq!(h.state().session.get(id).unwrap().can_undo(), Some("Save as PDF/A-2b"));
}
#[test]
fn export_to_word_html_and_rtf() {
let doc = Session::new().create_from_text("t", "Exported words").unwrap().to_vec();
let dir = std::env::temp_dir().join(format!("pdfcraft-office-ui-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let mut app = PdfCraftApp::new();
app.set_option("language", "en").unwrap();
app.open_bytes("e.pdf", None, doc).unwrap();
for ext in ["docx", "pptx", "html", "rtf"] {
let out = dir.join(format!("e.{ext}"));
app.save_override = Some(out.to_string_lossy().into_owned());
assert!(app.execute(&format!("export.{ext}")));
assert!(std::fs::metadata(&out).unwrap().len() > 40, "{ext}");
}
assert!(std::fs::read_to_string(dir.join("e.html")).unwrap().contains("Exported words"));
}