SVGPDF/Text.pm

filter: Statementstmt 84.8% 106 / 125 Branchbran 63.2% 43 / 68 Conditioncond 41.6% 20 / 48 MC/DCmcdc 20.0% 6 / 30 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 64.9% 180 / 277 CC 56 SCAR 49.7
CC
56
Cov
70%
process
154.8
BEGIN
1.0
BEGIN
1.0
CRAP 144.5
« SVGPDF/Contrib/PathExtract.pm ↑ Summary SVGPDF/Svg.pm »
1 #! perl
2  
3 2 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 class SVGPDF::Text :isa(SVGPDF::Element);
9  
10 31 ▶method process () {
Subroutine process: called CC=56 SCAR=50.4
Pod undocumented
11 31 my $atts = $self->atts;
12 31 my $xo = $self->xo;
13 31 ▶ return if $atts->{omit}; # for testing/debugging.
Branch: 1 branch
BranchTrueFalseTotal
if $atts->{"omit"} 0 31 31
14  
15 31 my ( $x, $y, $dx, $dy, $tf ) =
16 $self->get_params( $atts, qw( x:s y:s dx:U dy:U transform:s ) );
17 31 my $style = $self->style;
18 31 $_ = 0+$self->u($_) for $style->{'font-size'};
19 31 my $text = "";
20  
21 31 my $color = $style->{fill};
22 31 ▶ $color = $style->{color} if $color && $color eq "currentColor";
Branch: 1 branch
BranchTrueFalseTotal
if $color and $color eq "currentColor" 27 4 31
Condition66%2/3
$color and $color eq "currentColor"
!ll&&!rl&&r
0427
MC/DC50%1/2
$color and $color eq "currentColor"
$color $color eq "currentColor"
Truth table66%2/3
A and B
A= $colorB= $color eq "currentColor"
ABresult
0X0
100
111
23 31 ▶ my $anchor = $style->{'text-anchor'} || "left";
Condition100%2/2
$style->{'text-anchor'} || 'left'
l!l
823
MC/DC100%1/1
$style->{'text-anchor'} || 'left'
$style->{'text-anchor'}
Truth table100%2/2
A
A= $style->{'text-anchor'}
Aresult
11
00
24 31 $self->set_graphics;
25  
26 $self->_dbg( $self->name, " ",
27 defined($atts->{x}) ? ( " x=$x" ) : (),
28 defined($atts->{y}) ? ( " y=$y" ) : (),
29 defined($atts->{dx}) ? ( " dx=$dx" ) : (),
30 defined($atts->{dy}) ? ( " dy=$dy" ) : (),
31 defined($style->{"text-anchor"})
32 ? ( " anchor=\"$anchor\"" ) : (),
33 31 ▶ defined($style->{"transform"}) #???
Branch: 6 branches
BranchTrueFalseTotal
defined $atts->{'x'} ? : 31 0 31
defined $atts->{'y'} ? : 31 0 31
defined $atts->{'dx'} ? : 2 29 31
defined $atts->{'dy'} ? : 1 30 31
defined $style->{'text-anchor'} ? : 8 23 31
defined $style->{'transform'} ? : 0 31 31
34 ? ( " transform=\"$tf\"" ) : (),
35 );
36  
37 # We assume that if there is an x/y list, there is one single text
38 # argument.
39  
40 31 my @c = $self->get_children;
41  
42 31 ▶ if ( $x =~ /,/ || $y =~ /,/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /,/u or $y =~ /,/u) { } 3 28 31
Condition100%3/3
$x =~ /,/u or $y =~ /,/u
l!l&&r!l&&!r
2128
MC/DC100%2/2
$x =~ /,/u or $y =~ /,/u
$x =~ /,/u $y =~ /,/u
Truth table100%3/3
A or B
A= $x =~ /,/uB= $y =~ /,/u
ABresult
1X1
011
000
43 3 ▶ if ( @c > 1 || ref($c[0]) ne "SVGPDF::TextElement" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@c > 1 or ref $c[0] ne "SVGPDF::TextElement") 0 3 3
Condition33%1/3
@c > 1 or ref $c[0] ne "SVGPDF::TextElement"
l!l&&r!l&&!r
003
MC/DC0%0/2
@c > 1 or ref $c[0] ne "SVGPDF::TextElement"
@c > 1 ref $c[0] ne "SVGPDF::TextElement"
Truth table33%1/3
A or B
A= @c > 1B= ref $c[0] ne "SVGPDF::TextElement"
ABresult
1X1
011
000
44 0 die("text: Cannot combine coordinate list with multiple elements\n");
45 }
46 3 $x = [ $self->getargs($x) ];
47 3 $y = [ $self->getargs($y) ];
48 3 ▶ $x = [ ($x->[0]) x @$y ] if @$x == 1 && @$y > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$x == 1 and @$y > 1 1 2 3
Condition66%2/3
@$x == 1 and @$y > 1
!ll&&!rl&&r
201
MC/DC50%1/2
@$x == 1 and @$y > 1
@$x == 1 @$y > 1
Truth table66%2/3
A and B
A= @$x == 1B= @$y > 1
ABresult
0X0
100
111
49 3 ▶ $y = [ ($y->[0]) x @$x ] if @$x > 1 && @$y == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$x > 1 and @$y == 1 1 2 3
Condition66%2/3
@$x > 1 and @$y == 1
!ll&&!rl&&r
021
MC/DC50%1/2
@$x > 1 and @$y == 1
@$x > 1 @$y == 1
Truth table66%2/3
A and B
A= @$x > 1B= @$y == 1
ABresult
0X0
100
111
50 3 $text = [ split( //, $c[0]->content ) ];
51 3 ▶ die( "\"", $self->get_cdata, "\" ", 0+@$x, " ", 0+@$y, " ", 0+@$text )
Branch: 1 branch
BranchTrueFalseTotal
unless @$x == @$y and @$y == @$text 0 3 3
Condition33%1/3
@$x == @$y and @$y == @$text
!ll&&!rl&&r
003
MC/DC0%0/2
@$x == @$y and @$y == @$text
@$x == @$y @$y == @$text
Truth table33%1/3
A and B
A= @$x == @$yB= @$y == @$text
ABresult
0X0
100
111
52 unless @$x == @$y && @$y == @$text;
53 }
54 else {
55 28 ▶ $x = [ $self->u($x||0) ];
Condition50%1/2
$x || 0
l!l
280
MC/DC0%0/1
$x || 0
$x
Truth table50%1/2
A
A= $x
Aresult
11
00
56 28 ▶ $y = [ $self->u($y||0) ];
Condition50%1/2
$y || 0
l!l
280
MC/DC0%0/1
$y || 0
$y
Truth table50%1/2
A
A= $y
Aresult
11
00
57 }
58  
59 31 $self->_dbg( "+ xo save" );
60 31 $xo->save;
61 31 my $ix = $x->[0];
62 31 my $iy = $y->[0];
63 31 my ( $ex, $ey );
64  
65 31 my $scalex = 1;
66 31 my $scaley = 1;
67 31 ▶ if ( $tf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tf) 0 31 31
68 0 ▶ ( $dx, $dy ) = $self->getargs($1)
Branch: 1 branch
BranchTrueFalseTotal
if $tf =~ /translate\((.*?)\)/u 0 0 0
69 if $tf =~ /translate\((.*?)\)/;
70 0 ▶ ( $scalex, $scaley ) = $self->getargs($1)
Branch: 1 branch
BranchTrueFalseTotal
if $tf =~ /scale\((.*?)\)/u 0 0 0
71 if $tf =~ /scale\((.*?)\)/;
72 0 ▶ $scaley ||= $scalex;
Condition0%0/3
$scaley ||= $scalex
l!l&&r!l&&!r
000
MC/DC0%0/2
$scaley ||= $scalex
$scaley $scalex
Truth table0%0/3
A ||= B
A= $scaleyB= $scalex
ABresult
1X1
011
000
73 0 $self->_dbg("TF: $dx, $dy, $scalex, $scaley")
74 }
75 # NOTE: rotate applies to the individual characters, not the text
76 # as a whole.
77  
78 31 ▶ if ( @$x > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$x > 1) { } 3 28 31
79 3 for ( @$x ) {
80 6 ▶ if ( $tf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tf) 0 6 6
81 0 $self->_dbg( "X %.2f = %.2f + %.2f",
82 $dx + $_, $dx, $_ );
83 0 $self->_dbg( "Y %.2f = - %.2f - %.2f",
84 $dy + $y->[0], $dy, $y->[0] );
85 }
86 6 my $x = $dx + $_;
87 6 my $y = $dy + shift(@$y);
88 6 ▶ $self->_dbg( "txt* translate( %.2f, %.2f )%s %x",
Branch: 1 branch
BranchTrueFalseTotal
$scalex != 1 || $scaley != -1 ? : 6 0 6
Condition33%1/3
$scalex != 1 or $scaley != -1
l!l&&r!l&&!r
060
MC/DC0%0/2
$scalex != 1 or $scaley != -1
$scalex != 1 $scaley != -1
Truth table33%1/3
A or B
A= $scalex != 1B= $scaley != -1
ABresult
1X1
011
000
89 $x, $y,
90 ( $scalex != 1 || $scaley != -1 )
91 ? sprintf(" scale( %.1f, %.1f )", $scalex, -$scaley ) : "",
92 ord($text->[0]));
93 # $xo-> translate( $x, $y );
94 6 $xo->save;
95 6 ▶ $xo->transform( translate => [ $x, $y ],
Branch: 1 branch
BranchTrueFalseTotal
$scalex != 1 || $scaley != -1 ? : 6 0 6
Condition33%1/3
$scalex != 1 or $scaley != -1
l!l&&r!l&&!r
060
MC/DC0%0/2
$scalex != 1 or $scaley != -1
$scalex != 1 $scaley != -1
Truth table33%1/3
A or B
A= $scalex != 1B= $scaley != -1
ABresult
1X1
011
000
96 ($scalex != 1 || $scaley != -1 )
97 ? ( scale => [ $scalex, -$scaley ] ) : (),
98 );
99 6 my %o = ();
100 6 ▶ $o{align} = $anchor eq "end"
Branch: 2 branches
BranchTrueFalseTotal
$anchor eq 'end' ? : 0 6 6
$anchor eq 'middle' ? : 0 6 6
101 ? "right"
102 : $anchor eq "middle" ? "center" : "left";
103 6 $xo->textstart;
104 6 $self->set_font( $xo, $style );
105 6 $xo->text( shift(@$text), %o );
106 6 $xo->textend;
107 6 $xo->restore;
108 }
109 }
110 else {
111 28 $_ = $x->[0];
112 28 ▶ if ( $tf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tf) 0 28 28
113 0 $self->_dbg( "X %.2f = %.2f + %.2f",
114 $dx + $_, $dx, $_ );
115 0 $self->_dbg( "Y %.2f = - %.2f - %.2f",
116 - $dy - $y->[0], $dy, $y->[0] );
117 }
118 28 my $x = $dx + $_;
119 28 my $y = $dy + shift(@$y);
120 28 ▶ $self->_dbg( "txt translate( %.2f, %.2f )%s",
Branch: 1 branch
BranchTrueFalseTotal
$scalex != 1 || $scaley != -1 ? : 28 0 28
Condition33%1/3
$scalex != 1 or $scaley != -1
l!l&&r!l&&!r
0280
MC/DC0%0/2
$scalex != 1 or $scaley != -1
$scalex != 1 $scaley != -1
Truth table33%1/3
A or B
A= $scalex != 1B= $scaley != -1
ABresult
1X1
011
000
121 $x, $y,
122 ($scalex != 1 || $scaley != -1 )
123 ? sprintf(" scale( %.2f %.2f )", $scalex, -$scaley ) : "" );
124 28 my %o = ();
125 28 ▶ $o{align} = $anchor eq "end"
Branch: 2 branches
BranchTrueFalseTotal
$anchor eq 'end' ? : 0 28 28
$anchor eq 'middle' ? : 8 20 28
126 ? "right"
127 : $anchor eq "middle" ? "center" : "left";
128 28 my $tc = $self->root->tc;
129 28 my $fc = $self->root->fc;
130 28 for my $c ( @c ) {
131 44 ▶ if ( ref($c) eq 'SVGPDF::TextElement' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $c eq 'SVGPDF::TextElement') { } 36 8 44
elsif (ref $c eq 'SVGPDF::Tspan') { } 8 0 8
132 36 $self->_dbg( "+ xo save" );
133 36 $xo->save;
134 36 ▶ $xo->transform( translate => [ $x, $y ],
Branch: 1 branch
BranchTrueFalseTotal
$scalex != 1 || $scaley != -1 ? : 36 0 36
Condition33%1/3
$scalex != 1 or $scaley != -1
l!l&&r!l&&!r
0360
MC/DC0%0/2
$scalex != 1 or $scaley != -1
$scalex != 1 $scaley != -1
Truth table33%1/3
A or B
A= $scalex != 1B= $scaley != -1
ABresult
1X1
011
000
135 ($scalex != 1 || $scaley != -1 )
136 ? ( scale => [ $scalex, -$scaley ] ) : ()
137 );
138 36 $scalex = $scaley = 1; # no more scaling.
139  
140 36 $xo->textstart;
141 36 ▶ if ( $tc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tc) { } 0 36 36
142 0 $x += $tc->( $self, xo => $xo, pdf => $self->root->pdf,
143 style => $style, text => $c->content, %o );
144 }
145 else {
146 36 $self->set_font( $xo, $style );
147 36 $x += $xo->text( $c->content, %o );
148 }
149 36 $xo->textend;
150 36 ▶ if ( $style->{'outline-style'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($style->{"outline-style"}) 0 36 36
151 # BEEP BEEP TRICKERY.
152 0 my $fn = $xo->{" font"};
153 0 my $sz = $xo->{" fontsize"};
154 0 ▶ $xo->line_width( $self->u($style->{'outline-width'} || 1 ));
Condition0%0/2
$style->{'outline-width'} || 1
l!l
00
MC/DC0%0/1
$style->{'outline-width'} || 1
$style->{'outline-width'}
Truth table0%0/2
A
A= $style->{'outline-width'}
Aresult
11
00
155 0 ▶ $xo->stroke_color( $style->{'outline-color'} || 'black' );
Condition0%0/2
$style->{'outline-color'} || 'black'
l!l
00
MC/DC0%0/1
$style->{'outline-color'} || 'black'
$style->{'outline-color'}
Truth table0%0/2
A
A= $style->{'outline-color'}
Aresult
11
00
156 0 ▶ my $d = $self->u($style->{'outline-offset'}) || 1;
Condition0%0/2
$self->u($style->{'outline-offset'}) || 1
l!l
00
MC/DC0%0/1
$self->u($style->{'outline-offset'}) || 1
$self->u($style->{'outline-offset'})
Truth table0%0/2
A
A= $self->u($style->{'outline-offset'})
Aresult
11
00
157 0 $xo->rectangle( -$d,
158 -$d+$sz*$fn->descender/1000,
159 $x-$ix+2*$d,
160 2*$d+$sz*$fn->ascender/1000 );
161 0 $xo->stroke;
162 }
163 36 $self->_dbg( "- xo restore" );
164 36 $xo->restore;
165 36 $ex = $x; $ey = $y;
166 }
167 elsif ( ref($c) eq 'SVGPDF::Tspan' ) {
168 8 $self->_dbg( "+ xo save" );
169 8 $xo->save;
170 8 ▶ if ( defined($c->atts->{x}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c->atts->{"x"}) 4 4 8
171 4 $x = 0;
172 }
173 8 ▶ if ( defined($c->atts->{'y'}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c->atts->{"y"}) 0 8 8
174 0 $y = 0;
175 }
176 8 ▶ $xo->transform( translate => [ $x, $y ],
Branch: 1 branch
BranchTrueFalseTotal
$scalex != 1 || $scaley != -1 ? : 8 0 8
Condition33%1/3
$scalex != 1 or $scaley != -1
l!l&&r!l&&!r
080
MC/DC0%0/2
$scalex != 1 or $scaley != -1
$scalex != 1 $scaley != -1
Truth table33%1/3
A or B
A= $scalex != 1B= $scaley != -1
ABresult
1X1
011
000
177 ( $scalex != 1 || $scaley != -1 )
178 ? ( scale => [ $scalex, -$scaley ] ) : (),
179 );
180 8 $scalex = $scaley = 1; # no more scaling.
181 8 my ( $x0, $y0 ) = $c->process();
182 8 $x += $x0; $y += $y0;
183 8 $self->_dbg("tspan moved to $x, $y");
184 8 $self->_dbg( "- xo restore" );
185 8 $xo->restore;
186 8 $ex = $x; $ey = $y;
187 }
188 else {
189 0 $self->nfi( $c->name . " in text" );
190 }
191 }
192 }
193  
194 31 $self->_dbg( "- xo restore" );
195 31 $xo->restore;
196 31 $self->css_pop;
197 2 }
198  
199 2 1;
« SVGPDF/Contrib/PathExtract.pm ↑ Summary SVGPDF/Svg.pm »