File Coverage

blib/lib/SVGPDF/Tspan.pm
Criterion Covered Total %
statement 55 58 94.8
branch 22 32 68.7
condition 7 9 77.7
subroutine 5 5 100.0
pod 0 1 0.0
total 89 105 84.7


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