pub enum WidgetRotation {
None,
Quarter,
Half,
ThreeQuarter,
}Expand description
A widget annotation’s /MK /R, normalized to one of the four quadrants.
ISO 32000-1 Table 189 defines /R as “the number of degrees by which the
widget annotation shall be rotated counterclockwise relative to the page”,
and says it “shall be a multiple of 90”. Neither clause is a guarantee
about real files, so WidgetRotation::from_degrees rules on both: a
negative or out-of-range angle is the same quadrant it names modulo a
full turn, and an angle that is not a multiple of 90 names no quadrant at
all and is upright.
This is the one normalization both readers of the key share — the
appearance builder, which needs the box, and pdfrum-form’s routing,
which needs the map. They used to fold it separately and disagreed.
Variants§
None
Upright.
Quarter
A quarter turn counterclockwise.
Half
A half turn.
ThreeQuarter
Three quarters counterclockwise.
Implementations§
Source§impl WidgetRotation
impl WidgetRotation
Sourcepub fn from_degrees(degrees: i64) -> WidgetRotation
pub fn from_degrees(degrees: i64) -> WidgetRotation
The quadrant /MK /R n names, or WidgetRotation::None when it
names none.
The fold is rem_euclid(360), so -90 is 270 — a quarter turn
clockwise is three quarters counterclockwise, which is what a
counterclockwise angle of -90 means. A value that is not a multiple
of 90 is upright.
[oracle-bug] A negative multiple of 90 keeps its sign through the
fold, so /R -90 draws and hit-tests as a three-quarter turn — the
specification’s “counterclockwise” reading, and pdf.js’s.
use pdfrum_doc::geom::WidgetRotation;
assert_eq!(WidgetRotation::from_degrees(90), WidgetRotation::Quarter);
// `-90` counterclockwise is three quarters, and folds there.
assert_eq!(WidgetRotation::from_degrees(-90), WidgetRotation::ThreeQuarter);
// Not a multiple of 90: no quadrant at all.
assert_eq!(WidgetRotation::from_degrees(45), WidgetRotation::None);Sourcepub fn swaps_axes(self) -> bool
pub fn swaps_axes(self) -> bool
Whether this rotation exchanges the widget’s width and height.
use pdfrum_doc::geom::WidgetRotation;
assert!(WidgetRotation::Quarter.swaps_axes());
assert!(!WidgetRotation::Half.swaps_axes());