[librsvg: 14/17] Tests for height-only ResizeStrategy::ScaleWithMaxSize
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 14/17] Tests for height-only ResizeStrategy::ScaleWithMaxSize
- Date: Thu, 24 Feb 2022 03:22:56 +0000 (UTC)
commit e7d55468aa26a3cc4d9d36883e0340f09dc45f78
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Feb 23 18:45:14 2022 -0600
Tests for height-only ResizeStrategy::ScaleWithMaxSize
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/669>
src/bin/rsvg-convert.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
---
diff --git a/src/bin/rsvg-convert.rs b/src/bin/rsvg-convert.rs
index 692418ab1..4f2547f7a 100644
--- a/src/bin/rsvg-convert.rs
+++ b/src/bin/rsvg-convert.rs
@@ -189,7 +189,22 @@ impl ResizeStrategy {
}
}
- _ => unimplemented!(),
+ (None, Some(max_height), false) => {
+ if scaled.h <= max_height {
+ scaled
+ } else {
+ Size::new(scaled.w, max_height)
+ }
+ }
+
+ (None, Some(max_height), true) => {
+ if scaled.h <= max_height {
+ scaled
+ } else {
+ let factor = max_height / scaled.h;
+ Size::new(scaled.w * factor, max_height)
+ }
+ }
}
}
};
@@ -1366,4 +1381,34 @@ mod sizing_tests {
Size::new(10.0, 40.0),
);
}
+
+ #[test]
+ fn scale_with_max_height_doesnt_fit_non_proportional() {
+ let strategy = ResizeStrategy::ScaleWithMaxSize {
+ scale: Scale { x: 10.0, y: 20.0 },
+ max_width: None,
+ max_height: Some(10.0),
+ keep_aspect_ratio: false,
+ };
+
+ assert_eq!(
+ strategy.apply(&Size::new(5.0, 10.0)).unwrap(),
+ Size::new(50.0, 10.0),
+ );
+ }
+
+ #[test]
+ fn scale_with_max_height_doesnt_fit_proportional() {
+ let strategy = ResizeStrategy::ScaleWithMaxSize {
+ scale: Scale { x: 8.0, y: 20.0 },
+ max_width: None,
+ max_height: Some(10.0),
+ keep_aspect_ratio: true,
+ };
+
+ assert_eq!(
+ strategy.apply(&Size::new(5.0, 10.0)).unwrap(),
+ Size::new(2.0, 10.0),
+ );
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]