File Coverage

blib/lib/SVGPDF/Tspan.pm
Criterion Covered Total %
statement 55 58 94.8
branch 25 32 78.1
condition 8 9 88.8
subroutine 5 5 100.0
pod 0 1 0.0
total 93 105 88.5


line stmt bran cond sub pod time code
1             #! perl
2              
3 2     2   954 use v5.26;
  2         7  
4 2     2   13 use Object::Pad;
  2         3  
  2         15  
5 2     2   253 use utf8;
  2         4  
  2         27  
6 2     2   64 use Carp;
  2         4  
  2         557  
7              
8             class SVGPDF::Tspan :isa(SVGPDF::Element);
9              
10 9     9 0 12 method process () {
  9         38  
  9         12  
11 9         21 my $atts = $self->atts;
12 9         26 my $xo = $self->xo;
13 9 50       21 return if $atts->{omit}; # for testing/debugging.
14              
15 9         24 my ( $x, $y, $dx, $dy ) =
16             $self->get_params( $atts, qw( x:H y:V dx:s dy:s ) );
17 9         24 my $style = $self->style;
18              
19             # Scale dx/dy to font size, if using em units.
20 9         17 $style->{'font-size'} = 0+$self->u($style->{'font-size'});
21 9 50       17 if ( $dx =~ /^([.\d]+)em$/ ) {
22 0         0 $dx = $1 * $style->{'font-size'};
23             }
24             else {
25 9   100     29 $dx = $self->u($dx||0);
26             }
27 9 50       18 if ( $dy =~ /^([.\d]+)em$/ ) {
28 0         0 $dy = $1 * $style->{'font-size'};
29             }
30             else {
31 9   100     23 $dy = $self->u($dy||0);
32             }
33              
34 9         13 my $text = "";
35              
36 9         12 my $color = $style->{fill};
37 9 100 66     32 $color = $style->{color} if $color && $color eq "currentColor";
38 9   100     33 my $anchor = $style->{'text-anchor'} || "left";
39 9         25 $self->set_graphics;
40              
41             $self->_dbg( $self->name, " ",
42             defined($atts->{x}) ? ( " x=$x" ) : (),
43             defined($atts->{y}) ? ( " y=$y" ) : (),
44             defined($atts->{dx}) ? ( " dx=$dx" ) : (),
45             defined($atts->{dy}) ? ( " dy=$dy" ) : (),
46 9 100       24 defined($style->{"text-anchor"})
    50          
    100          
    100          
    100          
47             ? ( " anchor=\"$anchor\"" ) : (),
48             );
49              
50 9         26 my @c = $self->get_children;
51              
52             {
53 9         11 my $x = $dx + $x;
  9         18  
54 9         13 my $y = $dy + $y;
55              
56 9         30 my %o = ();
57 9 100       31 $o{align} = $anchor eq "end"
    50          
58             ? "right"
59             : $anchor eq "middle" ? "center" : "left";
60              
61 9 100       29 if ( 0 && $x && !$y && $o{align} eq "left" ) {
62             $o{indent} = $x;
63             $self->_dbg( "txt indent %.2f", $x );
64             }
65 0 100       0 elsif ( $x || $y ) {
66 5         11 $self->_dbg( "txt translate( %.2f, %.2f )", $x, $y );
67             }
68              
69 9         19 for my $c ( @c ) {
70 10         49 $self->_dbg( "+ xo save" );
71 10         43 $xo->save;
72 10         434 $xo->transform( translate => [ $x, -$y ] );
73 10 100       3236 if ( ref($c) eq 'SVGPDF::TextElement' ) {
    50          
74 9         22 $xo->textstart;
75 9         474 $self->set_font( $xo, $style );
76 9         20 $x += $xo->text( $c->content, %o );
77 9         3145 $xo->textend;
78             }
79             elsif ( ref($c) eq 'SVGPDF::Tspan' ) {
80 1         6 my ( $x0, $y0 ) = $c->process;
81 1         3 $x += $x0; $y += $y0;
  1         2  
82 1         9 $self->_dbg("tspan moved to $x, $y");
83             }
84 10         257 $self->_dbg( "- xo restore" );
85 10         28 $xo->restore;
86             }
87              
88 9         285 $self->css_pop;
89 9 50       74 return wantarray ? ( $x, $y ) : $x;
90              
91             }
92             }
93              
94             1;