File Coverage

lib/ChordPro/lib/SVGPDF/Tspan.pm
Criterion Covered Total %
statement 11 58 18.9
branch 0 32 0.0
condition 0 9 0.0
subroutine 4 5 80.0
pod 0 1 0.0
total 15 105 14.2


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