Skip to content

Commit 3024363

Browse files
authored
Merge pull request #43 from naitsirch/fix_percental_width_and_height
Fixed wrong handling of percentual height/width of rectangels
2 parents ccc46ef + e148d83 commit 3024363

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Svg/Tag/Rect.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,20 @@ public function start($attributes)
2727
}
2828

2929
if (isset($attributes['width'])) {
30-
$this->width = $attributes['width'];
30+
if ('%' === substr($attributes['width'], -1)) {
31+
$factor = substr($attributes['width'], 0, -1) / 100;
32+
$this->width = $this->document->getWidth() * $factor;
33+
} else {
34+
$this->width = $attributes['width'];
35+
}
3136
}
3237
if (isset($attributes['height'])) {
33-
$this->height = $attributes['height'];
38+
if ('%' === substr($attributes['height'], -1)) {
39+
$factor = substr($attributes['height'], 0, -1) / 100;
40+
$this->height = $this->document->getHeight() * $factor;
41+
} else {
42+
$this->height = $attributes['height'];
43+
}
3444
}
3545

3646
if (isset($attributes['rx'])) {
@@ -42,4 +52,4 @@ public function start($attributes)
4252

4353
$this->document->getSurface()->rect($this->x, $this->y, $this->width, $this->height, $this->rx, $this->ry);
4454
}
45-
}
55+
}

0 commit comments

Comments
 (0)