Skip to content

Commit bbf6f9e

Browse files
committed
Merge pull request #2 from Orken/master
Fix text-anchor=end
2 parents e30f8e9 + 8db6350 commit bbf6f9e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Svg/Tag/Text.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @package php-svg-lib
44
* @link http://github.com/PhenX/php-svg-lib
5-
* @author Fabien Ménager <[email protected]>
5+
* @author Fabien Ménager <[email protected]>
66
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
77
*/
88

@@ -36,10 +36,14 @@ public function end()
3636
$x = $this->x;
3737
$y = $this->y;
3838

39+
$width = $surface->measureText($this->text);
40+
3941
if ($surface->getStyle()->textAnchor == "middle") {
40-
$width = $surface->measureText($this->getText());
4142
$x -= $width / 2;
4243
}
44+
if ($surface->getStyle()->textAnchor == "end") {
45+
$x -= $width;
46+
}
4347

4448
$surface->fillText($this->getText(), $x, $y);
4549
}
@@ -58,4 +62,4 @@ public function getText()
5862
{
5963
return trim($this->text);
6064
}
61-
}
65+
}

0 commit comments

Comments
 (0)