DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #815: fix(pdf): leave form fields and media out of PDF/A-2b exports (#743)
aiongg8a4dac7faa7d
diff --cc crates/pdf/src/tests.rsindex c2318dc3b,c58c7533b..aa5b3a5f3--- a/crates/pdf/src/tests.rs+++ b/crates/pdf/src/tests.rs@@@ -417,67 -402,32 +417,93 @@@ fn drawn(bytes: &[u8]) -> (Vec<(String(rec.0, rec.1)}+/// The page's paint operations in order: `fill`/`stroke` + ` text`/` path` and the stroke width.+fn paint_order(bytes: &[u8]) -> Vec<(String, f32)> {+ use hayro_interpret::font::Glyph;+ use hayro_interpret::{+ BlendMode, ClipPath, Context, Device, GlyphDrawMode, Image, InterpreterCache, InterpreterSettings, Paint, PathDrawMode, SoftMask,+ interpret_page,+ };+ #[derive(Default)]+ struct Rec(Vec<(String, f32)>);+ impl Device<'_> for Rec {+ fn set_soft_mask(&mut self, _: Option<SoftMask<'_>>) {}+ fn set_blend_mode(&mut self, _: BlendMode) {}+ fn draw_path(&mut self, _: &kurbo::BezPath, _: kurbo::Affine, _: &Paint<'_>, m: &PathDrawMode) {+ self.0.push(match m {+ PathDrawMode::Fill(_) => ("fill path".into(), 0.0),+ PathDrawMode::Stroke(p) => ("stroke path".into(), p.line_width),+ });+ }+ fn push_clip_path(&mut self, _: &ClipPath) {}+ fn push_transparency_group(&mut self, _: f32, _: Option<SoftMask<'_>>, _: BlendMode) {}+ fn draw_glyph(&mut self, _: &Glyph<'_>, _: kurbo::Affine, _: kurbo::Affine, _: &Paint<'_>, m: &GlyphDrawMode) {+ self.0.push(match m {+ GlyphDrawMode::Fill => ("fill text".into(), 0.0),+ GlyphDrawMode::Stroke(p) => ("stroke text".into(), p.line_width),+ GlyphDrawMode::Invisible => ("invisible text".into(), 0.0),+ });+ }+ fn draw_image(&mut self, _: Image<'_, '_>, _: kurbo::Affine) {}+ fn pop_clip_path(&mut self) {}+ fn pop_transparency_group(&mut self) {}+ }+ let pdf = hayro_syntax::Pdf::new(bytes.to_vec()).expect("parse");+ let cache = InterpreterCache::new();+ let page = &pdf.pages()[0];+ let mut ctx = Context::new(kurbo::Affine::IDENTITY, kurbo::Rect::new(0.0, 0.0, 1.0, 1.0), &cache, pdf.xref(), InterpreterSettings::default());+ let mut rec = Rec::default();+ interpret_page(page, &mut ctx, &mut rec);+ rec.0+}++#[test]+fn stroke_behind_fill_strokes_the_run_before_filling_it() {+ let export = |behind: bool| {+ let mut d = doc_with_text("I");+ let sid = *d.stories.keys().next().unwrap();+ d.story_mut(sid).unwrap().format_chars(0..1, |f| {+ f.over.stroke = Some(designcraft_color::swatch::BLACK.into());+ f.over.stroke_weight = Some(4.0);+ f.over.stroke_behind_fill = Some(behind);+ });+ let bytes = export_pdf(&d, &Cache::new(), &PdfOptions::default()).unwrap();+ let ops: Vec<(String, f32)> = paint_order(&bytes).into_iter().filter(|(op, w)| op.ends_with("text") || *w > 0.0).collect();+ (ops, extract_text(&bytes)[0].clone())+ };+ let (over, _) = export(false);+ assert_eq!(over, [("fill text".to_string(), 0.0), ("stroke text".to_string(), 4.0)]);+ let (behind, text) = export(true);+ assert_eq!(behind, [("stroke path".to_string(), 8.0), ("fill text".to_string(), 0.0)], "the double-width stroke goes first");+ assert_eq!(text.trim(), "I", "the text is not duplicated");+}++ #[test]+ fn pdfa_leaves_out_form_fields_added_after_validation() {+ let mut d = doc_with_text("Archive me");+ let lid = d.default_layer();+ let id = ItemId(d.alloc());+ let mut b = Item::new(id, lid, designcraft_doc::Shape::Rectangle, designcraft_geom::shapes::rectangle(Rect::new(36.0, 400.0, 200.0, 430.0)));+ b.form_field = Some(designcraft_doc::FormField {+ kind: designcraft_doc::FieldKind::TextField,+ name: "name".into(),+ value: String::new(),+ options: Vec::new(),+ multiline: false,+ required: false,+ font_size: 0.0,+ });+ d.insert_item(SpreadRef::Doc(0), b, None).unwrap();+ let plain = export_pdf(&d, &Cache::new(), &PdfOptions::default()).unwrap();+ assert!(String::from_utf8_lossy(&plain).contains("/AcroForm"), "control: a plain export has the field");+ let opts = PdfOptions { standard: Standard::PdfA2b, created: Some(1_700_000_000), ..Default::default() };+ let a = export_pdf_with_report(&d, &Cache::new(), &opts).unwrap();+ let text = String::from_utf8_lossy(&a.bytes).to_string();+ assert!(text.contains("pdfaid"));+ assert!(!text.contains("/AcroForm") && !text.contains("NeedAppearances"), "PDF/A must not get the form update");+ assert!(a.warnings.iter().any(|w| w.contains("PDF/A-2b") && w.contains("left out")), "{:?}", a.warnings);+ }+#[test]fn missing_glyphs_print_as_boxes() {// Source Serif 4 lacks 語: its .notdef box is drawn as a path, not as a .notdef glyphdiff --cc docs/target-app-parity.mdindex 9120b7d8f,cbdc17974..118fbddbf--- a/docs/target-app-parity.md+++ b/docs/target-app-parity.md@@@ -362,10 -355,9 +362,10 @@@ It is evidence of breadth: each item ex- Track Changes (`changes.track/list/acceptAll/rejectAll`, Type ▸ Track Changes): typing is marked added (highlighted on screen), deletions are kept but hidden from layout and exports until accepted or rejected. Per-change accept/reject and authors aren't there yet.- Track Changes: per-change Accept / Reject (`changes.accept`, `changes.reject`) and a Track Changes panel listing every change.- Move table rows and columns (`table.moveRow`, `table.moveColumn`, Table panel buttons; with whole rows or columns selected, drag them with the Type tool — `table.dropCells`).+- Cell strokes: with cells selected (or the cursor in a cell) the Stroke panel edits the chosen cell edges, picked on a drawn edge proxy (top, bottom, left, right, inner horizontal, inner vertical); Table › Cell Options › Strokes and Fills… does the same with the cell fill. Weight, every stroke type, colour, tint, gap colour and gap tint draw on screen and in PDF and round-trip through IDML (`table.setCell` `stroke.edges`, `table.getCellStroke`).- Distribute Rows Evenly (`table.distributeRows`, Table menu and panel): selected rows receive equal fixed heights preserving their composed total height, with undo/redo. Row-spanning merges and rows outside the composed frames are rejected; shrinking tall cells can overset their text.- Object States (`states.create/show/rename/release/list`, Object States panel): multi-state objects show one state on screen and in PDF.- - Buttons (`button.set/clear/list`, Buttons and Forms panel): go to page / next / previous / first / last / URL as PDF link annotations. Form fields too (`form.set/clear/list`: text fields, check boxes, combo and list boxes, signature fields; required, multiline, defaults) exported as AcroForm widgets through an incremental update (not in PDF/X).+ - Buttons (`button.set/clear/list`, Buttons and Forms panel): go to page / next / previous / first / last / URL as PDF link annotations. Form fields too (`form.set/clear/list`: text fields, check boxes, combo and list boxes, signature fields; required, multiline, defaults) exported as AcroForm widgets through an incremental update (not in PDF/X or PDF/A).- Power Zoom (Hand tool: press and hold still for half a second, or Alt-press): zoom out to the spread, aim the red view rectangle, release to zoom back in there.- Graphic cells (`table.placeGraphic`, `table.textCell`, Table › Convert Cell Type, Table panel): images in table cells, fitted or filled, clipped to the cell on screen and in PDF.- Live Distribute (Space while dragging a selection handle; `transform.resize {distribute}`): objects keep their size and spread with the bounds.