Skip to content

Commit 2ea1cb6

Browse files
ssddanbrownbsweeney
authored andcommitted
Added percent unit support to previously missed attributes
1 parent 3166f53 commit 2ea1cb6

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

src/Svg/Document.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public function getHeight()
101101
return $this->height;
102102
}
103103

104+
public function getDiagonal()
105+
{
106+
return sqrt(($this->width)**2 + ($this->height)**2) / sqrt(2);
107+
}
108+
104109
public function getDimensions() {
105110
$rootAttributes = null;
106111

src/Svg/Tag/Circle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function start($attributes)
2727
$this->cy = Style::convertSize($attributes['cy'], $height);
2828
}
2929
if (isset($attributes['r'])) {
30-
$this->r = $attributes['r'];
30+
$diagonal = $this->document->getDiagonal();
31+
$this->r = Style::convertSize($attributes['r'], $diagonal);
3132
}
3233

3334
$this->document->getSurface()->circle($this->cx, $this->cy, $this->r);

src/Svg/Tag/Ellipse.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@ public function start($attributes)
2121
{
2222
parent::start($attributes);
2323

24+
$width = $this->document->getWidth();
25+
$height = $this->document->getHeight();
26+
2427
if (isset($attributes['cx'])) {
25-
$width = $this->document->getWidth();
2628
$this->cx = Style::convertSize($attributes['cx'], $width);
2729
}
2830
if (isset($attributes['cy'])) {
29-
$height = $this->document->getHeight();
3031
$this->cy = Style::convertSize($attributes['cy'], $height);
3132
}
3233
if (isset($attributes['rx'])) {
33-
$this->rx = $attributes['rx'];
34+
$this->rx = Style::convertSize($attributes['rx'], $width);
3435
}
3536
if (isset($attributes['ry'])) {
36-
$this->ry = $attributes['ry'];
37+
$this->ry = Style::convertSize($attributes['ry'], $height);
3738
}
3839

3940
$this->document->getSurface()->ellipse($this->cx, $this->cy, $this->rx, $this->ry, 0, 0, 360, false);

src/Svg/Tag/Image.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ protected function before($attributes)
3131
public function start($attributes)
3232
{
3333
$height = $this->document->getHeight();
34+
$width = $this->document->getWidth();
3435
$this->y = $height;
3536

3637
if (isset($attributes['x'])) {
37-
$width = $this->document->getWidth();
3838
$this->x = Style::convertSize($attributes['x'], $width);
3939
}
4040
if (isset($attributes['y'])) {
4141
$this->y = $height - Style::convertSize($attributes['y'], $height);
4242
}
4343

4444
if (isset($attributes['width'])) {
45-
$this->width = $attributes['width'];
45+
$this->width = Style::convertSize($attributes['width'], $width);
4646
}
4747
if (isset($attributes['height'])) {
48-
$this->height = $attributes['height'];
48+
$this->height = Style::convertSize($attributes['height'], $height);
4949
}
5050

5151
if (isset($attributes['xlink:href'])) {

0 commit comments

Comments
 (0)