Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docx-core/src/reader/pic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ impl ElementReader for Pic {
pic = pic.id(id)
}
}
AXMLElement::Xfrm => {
if let Some(rotation) = read(&attributes, "rot") {
if let Ok(rotation) = i64::from_str(&rotation) {
const UNITS_PER_DEGREE: i64 = 60_000;
const FULL_TURN_UNITS: i64 = 360 * UNITS_PER_DEGREE;
let normalized = rotation.rem_euclid(FULL_TURN_UNITS);
let degrees = ((normalized + UNITS_PER_DEGREE / 2)
/ UNITS_PER_DEGREE)
% 360;
pic = pic.rotate(degrees as u16);
}
}
}
AXMLElement::Off => {
let mut offset_x: i32 = 0;
let mut offset_y: i32 = 0;
Expand Down Expand Up @@ -70,3 +83,26 @@ impl ElementReader for Pic {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn reads_picture_rotation_from_transform() {
let xml = r#"<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<pic:blipFill><a:blip r:embed="rId1"/></pic:blipFill>
<pic:spPr>
<a:xfrm rot="20933656">
<a:off x="0" y="0"/>
<a:ext cx="4366365" cy="4366365"/>
</a:xfrm>
</pic:spPr>
</pic:pic>"#;
let mut reader = EventReader::new(xml.as_bytes());

let picture = Pic::read(&mut reader, &[]).expect("picture should parse");

assert_eq!(picture.rot, 349);
}
}
Loading