center text within it's bbox
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 9 Nov 2017 14:33:24 +0000 (15:33 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 9 Nov 2017 14:33:24 +0000 (15:33 +0100)
gpio.pl

diff --git a/gpio.pl b/gpio.pl
index c432c43..564e423 100755 (executable)
--- a/gpio.pl
+++ b/gpio.pl
@@ -228,7 +228,9 @@ foreach my $i ( 0 .. $#line_parts ) {
                my $x_pos = $x;
                foreach my $i ( @cols_order ) {
                        next unless $line->[$i];
-                       $tspan .= qq{<tspan x="$x_pos"}.svg_style($line->[$i],$x_pos,$y,$i).sprintf( '>%' . $cols_align[$i] . $max_len[$i] . 's</tspan>', $line->[$i]);
+                       my $text_anchor = 'middle';
+                       my $x2 = $x_pos + ( $max_len[$i] * $font_w ) / 2;
+                       $tspan .= qq{<tspan x="$x2" text-anchor="$text_anchor"}.svg_style($line->[$i],$x_pos,$y,$i).sprintf( '>%' . $cols_align[$i] . $max_len[$i] . 's</tspan>', $line->[$i]);
                        $x_pos += $max_len[$i] * $font_w;
                }