[librsvg: 1/2] (#763) Add auto width/height for rect element
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/2] (#763) Add auto width/height for rect element
- Date: Mon, 12 Jul 2021 19:20:57 +0000 (UTC)
commit 6ab5f9beba5f9260d88f81a0f71c3f626f264efd
Author: Madds H <madds hollandart io>
Date: Thu Jul 8 17:21:23 2021 -0500
(#763) Add auto width/height for rect element
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/566>
src/shapes.rs | 15 +++++++++++----
tests/src/reference.rs | 13 +++++++++++++
2 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/src/shapes.rs b/src/shapes.rs
index aee7dc4d..731c433c 100644
--- a/src/shapes.rs
+++ b/src/shapes.rs
@@ -407,8 +407,8 @@ impl BasicShape for Line {
pub struct Rect {
x: Length<Horizontal>,
y: Length<Vertical>,
- width: ULength<Horizontal>,
- height: ULength<Vertical>,
+ width: LengthOrAuto<Horizontal>,
+ height: LengthOrAuto<Vertical>,
// Radiuses for rounded corners
rx: Option<Length<Horizontal>>,
@@ -440,8 +440,15 @@ impl BasicShape for Rect {
fn make_shape(&self, params: &NormalizeParams) -> ShapeDef {
let x = self.x.to_user(params);
let y = self.y.to_user(params);
- let w = self.width.to_user(params);
- let h = self.height.to_user(params);
+
+ let w = match self.width {
+ LengthOrAuto::Length(l) => l.to_user(¶ms),
+ LengthOrAuto::Auto => 0.0,
+ };
+ let h = match self.height {
+ LengthOrAuto::Length(l) => l.to_user(¶ms),
+ LengthOrAuto::Auto => 0.0,
+ };
let specified_rx = self.rx.map(|l| l.to_user(params));
let specified_ry = self.ry.map(|l| l.to_user(params));
diff --git a/tests/src/reference.rs b/tests/src/reference.rs
index 3efa3db5..658f9ccb 100644
--- a/tests/src/reference.rs
+++ b/tests/src/reference.rs
@@ -335,3 +335,16 @@ test_compare_render_output!(
<rect x="10" y="10" width="10" height="10" fill="lime"/>
</svg>"##,
);
+
+test_compare_render_output!(
+ rect_auto_width_height,
+ 30,
+ 30,
+ br##"<?xml version="1.0" encoding="UTF-8"?>
+ <svg xmlns="http://www.w3.org/2000/svg" width="30" height="30">
+ <rect x="10" y="10" width="auto" height="auto" fill="lime"/>
+ </svg>"##,
+ br##"<?xml version="1.0" encoding="UTF-8"?>
+ <svg xmlns="http://www.w3.org/2000/svg" width="30" height="30">
+ </svg>"##
+);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]