Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Merge branch 'upstream/main' into fix/typed-signature-winding

jonathanwxh-cella10c0d89376b
diff --cc crates/annot/src/tests.rs
index 0ccfc6a73,4a4dfb106..7c10f385f
--- a/crates/annot/src/tests.rs
+++ b/crates/annot/src/tests.rs
@@@ -1309,15 -1336,49 +1336,62 @@@ fn text_box_font_size_changes_the_da_an
}
}
+ #[test]
+ fn text_boxes_and_callouts_can_change_fill_and_border() {
+ let mut doc = fixture();
+ let shapes = [
+ Shape::TextBox { rect: [300.0, 600.0, 500.0, 660.0], font_size: 12.0 },
+ Shape::Callout {
+ rect: [300.0, 600.0, 500.0, 660.0],
+ knee: [260.0, 560.0],
+ point: [200.0, 520.0],
+ font_size: 12.0,
+ ending: LineEnding::OpenArrow,
+ },
+ ];
+ for shape in shapes {
+ let index = add_annotation(&mut doc, &new(0, shape), &meta("test")).unwrap();
+ assert!(props(&doc, 0, index).unwrap().fillable);
+ set_fill(&mut doc, 0, index, Some([1.0, 1.0, 1.0]), &meta("test")).unwrap();
+ set_style(&mut doc, 0, index, None, None, Some(3.0), None, &meta("test")).unwrap();
+ let saved = reopen(&doc);
+ let properties = props(&saved, 0, index).unwrap();
+ assert_eq!(properties.fill, Some([1.0; 3]));
+ assert_eq!(properties.width, Some(3.0));
+ let ap = ap_content(&saved, &list(&saved, 0)[index]);
+ assert!(ap.contains("1 1 1 rg") && ap.contains(" re f") && ap.contains("3 w"), "{ap}");
+ set_fill(&mut doc, 0, index, None, &meta("test")).unwrap();
+ assert_eq!(props(&doc, 0, index).unwrap().fill, None);
+ }
+ }
+
+ #[test]
+ fn free_text_properties_show_legacy_or_absent_border_width() {
+ let mut doc = fixture();
+ let index = add_annotation(&mut doc, &new(0, Shape::TextBox { rect: [100.0, 100.0, 200.0, 140.0], font_size: 12.0 }), &meta("test")).unwrap();
+ let (_, reference) = annot_ref(&mut doc, 0, index).unwrap();
+ doc.update_dict(reference, |d| {
+ d.remove(b"BS");
+ d.remove(b"Border");
+ })
+ .unwrap();
+ assert_eq!(props(&doc, 0, index).unwrap().width, Some(0.0));
+ doc.update_dict(reference, |d| {
+ d.set(b"Border".to_vec(), Object::Array([0.0, 0.0, 4.0].into_iter().map(Object::Real).collect()));
+ })
+ .unwrap();
+ assert_eq!(props(&doc, 0, index).unwrap().width, Some(4.0));
+ }
++
+/// #1786: TrueType glyph contours (such as Inter's composite Ђ and ћ) overlap with the same
+/// winding direction where strokes cross, so typed signature appearances must fill with the
+/// non-zero winding operator (`f`), not even-odd (`f*`).
+#[test]
+fn typed_signature_uses_nonzero_winding_fill() {
+ let mut doc = fixture();
+ let contours = vec![vec![[0.4, 0.0], [0.6, 0.0], [0.6, 1.0], [0.4, 1.0]], vec![[0.0, 0.7], [1.0, 0.7], [1.0, 0.85], [0.0, 0.85]]];
+ let idx = add_annotation(&mut doc, &new(0, Shape::TypedSignature { rect: [100.0, 100.0, 200.0, 140.0], contours }), &meta("sig")).unwrap();
+ let ap = ap_content(&doc, &list(&doc, 0)[idx]);
+ assert!(ap.ends_with("h\nf\n"), "expected non-zero winding fill (`f`), got: {ap}");
+ assert!(!ap.contains("f*"), "must not use even-odd fill (`f*`): {ap}");
+}