mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-18 18:15:34 +00:00
test(annot): retain current opacity and review-state semantics (#7721)
* test(annot): retain current opacity and review-state semantics * style: wrap fixture imports at repository width
This commit is contained in:
1 parent
f8211b6aaf
commit
562c428c6f
2 files changed
+14
-8
No files matched your search
@@ -294,15 +294,20 @@ fn reference_loops_terminate_and_a_delete_takes_the_cycle_with_it() {
|
||||
// ── wrong types where the reader wants a number or a name ─────────────────────────────────────
|
||||
|
||||
/// Values of the wrong type in flag, opacity and colour entries: the reader falls back to its
|
||||
/// defaults instead of panicking. NOTE on opacity: reading does **not** clamp, so `/CA 7.5` comes
|
||||
/// back as 7.5 and would hand a nonsense value to a 0–1 slider; writing clamps (`add_annotation`
|
||||
/// refuses non-finite and clamps the range). The asymmetry is recorded here, not endorsed.
|
||||
/// defaults instead of panicking. Opacity is clamped on read to the supported 0-1 range;
|
||||
/// the original malformed dictionary remains unchanged.
|
||||
#[test]
|
||||
fn wrong_typed_flag_opacity_and_colour_entries_fall_back_without_panicking() {
|
||||
let doc = one_annot(b"<< /Type /Annot /Subtype /Text /Rect [10 20 30 40] /CA 7.5 /F /NotAnInt /C [1 2] >>");
|
||||
read_everything(&doc);
|
||||
let p = props(&doc, 0, 0).expect("still a comment");
|
||||
assert_eq!(p.opacity, 7.5, "the out-of-range opacity is passed through as written");
|
||||
assert_eq!(p.opacity, 1.0, "the out-of-range opacity is clamped on read");
|
||||
// Exercise both clamp edges and an unchanged interior value, not just a constant fallback.
|
||||
for (raw, expected) in [("-0.5", 0.0), ("0.4", 0.4), ("1.5", 1.0)] {
|
||||
let bytes = format!("<< /Type /Annot /Subtype /Text /Rect [10 20 30 40] /CA {raw} >>");
|
||||
let probe = one_annot(bytes.as_bytes());
|
||||
assert_eq!(props(&probe, 0, 0).expect("still a comment").opacity, expected, "opacity {raw}");
|
||||
}
|
||||
assert!(!p.locked, "a name where /F belongs reads as no flags at all");
|
||||
assert_eq!(p.color, None, "/C with two components is not a colour");
|
||||
let listed = summaries(&doc);
|
||||
|
||||
@@ -33,8 +33,8 @@ use pdfcraft_cos::{Dict, Document, ObjRef, Object, SaveOptions};
|
||||
|
||||
use support::bytes;
|
||||
use support::fixture::{
|
||||
ALL_SAVES, FLAG_NO_ROTATE, FLAG_NO_ZOOM, FLAG_PRINT, FLAG_READONLY, Save, annot_entries, blank, blank_with_indirect_annots, dict_of, name_of,
|
||||
num, nums, page_object_numbers, pdf, save_and_reopen, str_of,
|
||||
ALL_SAVES, FLAG_HIDDEN, FLAG_NO_ROTATE, FLAG_NO_ZOOM, FLAG_PRINT, FLAG_READONLY, Save, annot_entries, blank, blank_with_indirect_annots, dict_of,
|
||||
name_of, num, nums, page_object_numbers, pdf, save_and_reopen, str_of,
|
||||
};
|
||||
|
||||
/// A deterministic `/M` date and `/NM` id, so nothing here depends on the clock.
|
||||
@@ -658,8 +658,9 @@ fn reply_threads_and_the_delete_cascade_survive_every_save_path() {
|
||||
assert_eq!(str_of(&reopened, &st, b"State").as_deref(), Some("Accepted"), "{path:?}");
|
||||
assert_eq!(str_of(&reopened, &st, b"StateModel").as_deref(), Some("Review"), "{path:?}");
|
||||
assert_eq!(str_of(&reopened, &st, b"Subj").as_deref(), Some("Status"), "{path:?}");
|
||||
// Replies are printed but keep the icon flags of a comment; no Hidden bit here.
|
||||
assert_eq!(st.int(b"F"), Some(FLAG_PRINT | FLAG_NO_ZOOM | FLAG_NO_ROTATE), "{path:?}");
|
||||
// Review-state records are hidden; ordinary text replies retain their visible comment flags.
|
||||
assert_eq!(st.int(b"F"), Some(FLAG_HIDDEN | FLAG_PRINT | FLAG_NO_ZOOM | FLAG_NO_ROTATE), "{path:?}");
|
||||
assert_eq!(annot_at(&reopened, 0, 2, path).int(b"F"), Some(FLAG_PRINT | FLAG_NO_ZOOM | FLAG_NO_ROTATE), "{path:?}: ordinary reply");
|
||||
let listed = summaries(&reopened);
|
||||
assert_eq!(listed.iter().filter(|s| s.in_reply_to.as_deref() == Some("p1")).count(), 2, "{path:?}: both replies name the parent's /NM");
|
||||
assert_eq!(listed.iter().filter(|s| s.state.as_deref() == Some("Accepted")).count(), 1, "{path:?}");
|
||||
|
||||
Reference in new issue
Block a user