diff --git a/crates/measure/src/lib.rs b/crates/measure/src/lib.rs index ebe30797de..55b35e0c8b 100644 --- a/crates/measure/src/lib.rs +++ b/crates/measure/src/lib.rs @@ -572,8 +572,8 @@ fn scale_of(doc: &Document, d: &Dict, scales: &mut Scales) -> Result { } fn read_measurement(doc: &Document, d: &Dict, kind: Kind, page: usize, index: usize, scales: &mut Scales) -> Result { - // An angle saved without `/Measure` takes its decimal mark from the scale at its first point, - // as it was given when drawn. + // An angle saved without `/Measure` takes its decimal mark from the scale in force at its first + // point when it is read, which a viewport added since can change. let saved = if kind == Kind::Angle && !d.contains(b"Measure") { None } else { Some(scale_of(doc, d, scales)?) }; let key = if kind == Kind::Distance { &b"L"[..] } else { b"Vertices" }; let o = doc.resolve(d.get(key).ok_or_else(|| invalid("measurement has no vertices"))?); diff --git a/crates/measure/src/tests.rs b/crates/measure/src/tests.rs index 2184f0c408..2b1321dc5d 100644 --- a/crates/measure/src/tests.rs +++ b/crates/measure/src/tests.rs @@ -785,6 +785,7 @@ fn an_angle_saves_reopens_and_lists_with_its_three_points() { assert!(add(&mut d, &new(Kind::Angle, vec![[200.0, 100.0], [100.0, 100.0], [100.0, 200.0], [100.0, 100.0]]), &meta).is_err()); assert!(list(&d).measurements.is_empty()); } + #[test] fn an_angle_is_saved_without_a_scale() { let mut d = fixture("", "", &[]); @@ -793,10 +794,12 @@ fn an_angle_is_saved_without_a_scale() { let (_, dict) = annot(&d, 0, 0).unwrap(); assert_eq!((dict.get(b"Measure"), dict.name(b"PCMeasureKind")), (None, Some(&b"Angle"[..]))); } + #[test] fn an_angle_saved_without_a_scale_reads_back_in_degrees() { // A polyline marked as an angle and carrying no `/Measure`, as another writer saves one. - let angle = "<< /Type /Annot /Subtype /PolyLine /Rect [90 90 210 210] /PCMeasureKind /Angle /Vertices [200 100 100 100 100 200 120 100 100 120] >>"; + let angle = + "<< /Type /Annot /Subtype /PolyLine /Rect [90 90 210 210] /PCMeasureKind /Angle /Vertices [200 100 100 100 100 200 120 100 100 120] >>"; let d = fixture("", "/Annots [5 0 R]", &[angle]); let listing = list(&d); assert_eq!(listing.unsupported, vec![]); @@ -804,6 +807,7 @@ fn an_angle_saved_without_a_scale_reads_back_in_degrees() { assert_eq!((m.reading.kind, &m.points), (Kind::Angle, &vec![[200.0, 100.0], [100.0, 100.0], [100.0, 200.0]])); close(m.reading.value, 90.0); } + #[test] fn an_angle_saved_without_a_scale_keeps_its_points() { let mut d = fixture("", "", &[]); @@ -813,3 +817,19 @@ fn an_angle_saved_without_a_scale_keeps_its_points() { assert!(moved.is_err(), "{moved:?}"); close(list(&d).measurements[0].reading.value, 90.0); } + +#[test] +fn an_angle_saved_without_a_scale_takes_the_decimal_mark_of_the_viewport_at_its_first_point() { + // A two-unit format keeps its separators (a single-unit decimal scale is read for its + // precision alone), so the viewport's comma reaches the angle. + let m_cm = "[<< /U (m) /C 0.000352778 /RD (,) >> << /U (cm) /C 100 /D 10 /RD (,) >>]"; + let measure = format!("<< /Type /Measure /Subtype /RL /R (1:1) /X {m_cm} /D {m_cm} /A [<< /U (sq m) /C 1 /RD (,) >>] >>"); + let viewport = format!("/VP [<< /Type /Viewport /BBox [0 0 300 300] /Measure {measure} >>]"); + let angle = "<< /Type /Annot /Subtype /PolyLine /Rect [90 90 210 210] /PCMeasureKind /Angle /Vertices [200 100 100 100 100 200] >>"; + let inside = fixture("", &format!("/Annots [5 0 R] {viewport}"), &[angle]); + let listing = list(&inside); + let [m] = &listing.measurements[..] else { panic!("{listing:?}") }; + assert_eq!(m.reading.label, "90,0\u{b0}"); + let outside = fixture("", "/Annots [5 0 R]", &[angle]); + assert_eq!(list(&outside).measurements[0].reading.label, "90.0\u{b0}"); +} diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml index 496ba9514c..e4b7d94a4f 100644 --- a/parity/acrobat-features.toml +++ b/parity/acrobat-features.toml @@ -4496,8 +4496,8 @@ milestone = "M12" status = "partial" commands = [] tools = ["measure_angle"] -evidence = ["crates/automation/tests/it/automation.rs::measure_angle_draws_saves_reopens_and_ignores_the_scale", "crates/measure/src/tests.rs::an_angle_is_read_the_short_way_in_either_order_and_ignores_the_scale", "crates/measure/src/tests.rs::an_angle_path_draws_both_arms_and_an_arc_inside_the_wedge", "crates/measure/src/tests.rs::an_angle_saves_reopens_and_lists_with_its_three_points", "crates/measure/src/tests.rs::an_angle_too_small_to_label_is_refused_by_name"] -notes = "The angle at an apex between two arms, in degrees with one decimal and the scale's decimal mark; the scale's units and factors are not applied. Saved as a PolyLine with the measured points first, then the arc (3-degree steps, always in the smaller wedge; an optional fourth point sets its radius by its distance from the apex, else half the shorter arm and at least 20 user units); an angle under 0.05 degrees, which would be labelled 0.0, is refused; measure_list and measure_info read it. Partial: automation only (no panel tool yet), no arrowheads on the arc, no angular precision or degree-minute-second option. The PDF standard names no angle intent, so the annotation has no /IT and is marked /PCMeasureKind /Angle: other readers show the drawing and caption but not a measurement." +evidence = ["crates/automation/tests/it/automation.rs::measure_angle_draws_saves_reopens_and_ignores_the_scale", "crates/measure/src/tests.rs::an_angle_is_read_the_short_way_in_either_order_and_ignores_the_scale", "crates/measure/src/tests.rs::an_angle_path_draws_both_arms_and_an_arc_inside_the_wedge", "crates/measure/src/tests.rs::an_angle_saves_reopens_and_lists_with_its_three_points", "crates/measure/src/tests.rs::an_angle_too_small_to_label_is_refused_by_name", "crates/measure/src/tests.rs::an_angle_is_saved_without_a_scale", "crates/measure/src/tests.rs::an_angle_saved_without_a_scale_reads_back_in_degrees", "crates/measure/src/tests.rs::an_angle_saved_without_a_scale_keeps_its_points", "crates/measure/src/tests.rs::an_angle_saved_without_a_scale_takes_the_decimal_mark_of_the_viewport_at_its_first_point"] +notes = "The angle at an apex between two arms, in degrees with one decimal and the scale's decimal mark; the scale's units and factors are not applied. Saved as a PolyLine with the measured points first, then the arc (3-degree steps, always in the smaller wedge; an optional fourth point sets its radius by its distance from the apex, else half the shorter arm and at least 20 user units); no /Measure is saved, so read back an angle takes its decimal mark from the scale at its first point; an angle under 0.05 degrees, which would be labelled 0.0, is refused; measure_list and measure_info read it. Partial: automation only (no panel tool yet), no arrowheads on the arc, no angular precision or degree-minute-second option. The PDF standard names no angle intent, so the annotation has no /IT and is marked /PCMeasureKind /Angle: other readers show the drawing and caption but not a measurement." [[feature]] id = "comment.measure-scale"