SVGPDF/Text.pm

filter: Statementstmt 69.1% 85 / 123 Branchbran 46.8% 30 / 64 Conditioncond 23.0% 9 / 39 MC/DCmcdc 8.3% 2 / 24 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 51.1% 131 / 256 CC 51 SCAR 57.4
CC
51
Cov
55%
process
336.6
BEGIN
1.0
BEGIN
1.0
CRAP 312.2
« SVGPDF/FontManager.pm ↑ Summary SVGPDF/Contrib/PathExtract.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 28 ▶method process () {
Subroutine process: called CC=51 SCAR=58.2
Pod undocumented
11 28 my $atts = $self->atts;
12 28 my $xo = $self->xo;
13 28 ▶ return if $atts->{omit}; # for testing/debugging.
Branch: 1 branch
BranchTrueFalseTotal
if $atts->{"omit"} 0 28 28
14  
15 28 my ( $x, $y, $dx, $dy, $tf ) =
16 $self->get_params( $atts, qw( x:s y:s dx:U dy:U transform:s ) );
17 28 my $style = $self->style;
18 28 $_ = 0+$self->u($_) for $style->{'font-size'};
19 28 my $text = "";
20  
21 28 my $color = $style->{fill};
22 28 ▶ $color = $style->{color} if $color && $color eq "currentColor";
Branch: 1 branch
BranchTrueFalseTotal
if $color and $color eq "currentColor" 24 4 28
Condition66%2/3
$color and $color eq "currentColor"
!ll&&!rl&&r
0424
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 28 ▶ my $anchor = $style->{'text-anchor'} || "left";
Condition100%2/2
$style->{'text-anchor'} || 'left'
l!l
820
MC/DC100%1/1
$style->{'text-anchor'} || 'left'
$style->{'text-anchor'}
Truth table100%2/2
A
A= $style->{'text-anchor'}
Aresult
11
00
24 28 $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 28 ▶ defined($style->{"transform"}) #???
Branch: 6 branches
BranchTrueFalseTotal
defined $atts->{'x'} ? : 28 0 28
defined $atts->{'y'} ? : 28 0 28
defined $atts->{'dx'} ? : 2 26 28
defined $atts->{'dy'} ? : 1 27 28
defined $style->{'text-anchor'} ? : 8 20 28
defined $style->{'transform'} ? : 0 28 28
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 28 my @c = $self->get_children;
41  
42 28 ▶ if ( $x =~ /,/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /,/u) { } 0 28 28
43 0 ▶ if ( @c > 1 || ref($c[0]) ne "SVGPDF::TextElement" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@c > 1 or ref $c[0] ne "SVGPDF::TextElement") 0 0 0
Condition0%0/3
@c > 1 or ref $c[0] ne "SVGPDF::TextElement"
l!l&&r!l&&!r
000
MC/DC0%0/2
@c > 1 or ref $c[0] ne "SVGPDF::TextElement"
@c > 1 ref $c[0] ne "SVGPDF::TextElement"
Truth table0%0/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 0 $x = [ $self->getargs($x) ];
47 0 $y = [ $self->getargs($y) ];
48 0 $text = [ split( //, $c[0]->content ) ];
49 0 ▶ die( "\"", $self->get_cdata, "\" ", 0+@$x, " ", 0+@$y, " ", 0+@$text )
Branch: 1 branch
BranchTrueFalseTotal
unless @$x == @$y and @$y == @$text 0 0 0
Condition0%0/3
@$x == @$y and @$y == @$text
!ll&&!rl&&r
000
MC/DC0%0/2
@$x == @$y and @$y == @$text
@$x == @$y @$y == @$text
Truth table0%0/3
A and B
A= @$x == @$yB= @$y == @$text
ABresult
0X0
100
111
50 unless @$x == @$y && @$y == @$text;
51 }
52 else {
53 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
54 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
55 }
56  
57 28 $self->_dbg( "+ xo save" );
58 28 $xo->save;
59 28 my $ix = $x->[0];
60 28 my $iy = $y->[0];
61 28 my ( $ex, $ey );
62  
63 28 my $scalex = 1;
64 28 my $scaley = 1;
65 28 ▶ if ( $tf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tf) 0 28 28
66 0 ▶ ( $dx, $dy ) = $self->getargs($1)
Branch: 1 branch
BranchTrueFalseTotal
if $tf =~ /translate\((.*?)\)/u 0 0 0
67 if $tf =~ /translate\((.*?)\)/;
68 0 ▶ ( $scalex, $scaley ) = $self->getargs($1)
Branch: 1 branch
BranchTrueFalseTotal
if $tf =~ /scale\((.*?)\)/u 0 0 0
69 if $tf =~ /scale\((.*?)\)/;
70 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
71 0 $self->_dbg("TF: $dx, $dy, $scalex, $scaley")
72 }
73 # NOTE: rotate applies to the individual characters, not the text
74 # as a whole.
75  
76 28 ▶ if ( @$x > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$x > 1) { } 0 28 28
77 0 for ( @$x ) {
78 0 ▶ if ( $tf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tf) 0 0 0
79 0 $self->_dbg( "X %.2f = %.2f + %.2f",
80 $dx + $_, $dx, $_ );
81 0 $self->_dbg( "Y %.2f = - %.2f - %.2f",
82 $dy + $y->[0], $dy, $y->[0] );
83 }
84 0 my $x = $dx + $_;
85 0 my $y = $dy + shift(@$y);
86 0 ▶ $self->_dbg( "txt* translate( %.2f, %.2f )%s %x",
Branch: 1 branch
BranchTrueFalseTotal
$scalex != 1 || $scaley != -1 ? : 0 0 0
Condition0%0/3
$scalex != 1 or $scaley != -1
l!l&&r!l&&!r
000
MC/DC0%0/2
$scalex != 1 or $scaley != -1
$scalex != 1 $scaley != -1
Truth table0%0/3
A or B
A= $scalex != 1B= $scaley != -1
ABresult
1X1
011
000
87 $x, $y,
88 ( $scalex != 1 || $scaley != -1 )
89 ? sprintf(" scale( %.1f, %.1f )", $scalex, -$scaley ) : "",
90 ord($text->[0]));
91 # $xo-> translate( $x, $y );
92 0 $xo->save;
93 0 ▶ $xo->transform( translate => [ $x, $y ],
Branch: 1 branch
BranchTrueFalseTotal
$scalex != 1 || $scaley != -1 ? : 0 0 0
Condition0%0/3
$scalex != 1 or $scaley != -1
l!l&&r!l&&!r
000
MC/DC0%0/2
$scalex != 1 or $scaley != -1
$scalex != 1 $scaley != -1
Truth table0%0/3
A or B
A= $scalex != 1B= $scaley != -1
ABresult
1X1
011
000
94 ($scalex != 1 || $scaley != -1 )
95 ? ( scale => [ $scalex, -$scaley ] ) : (),
96 );
97 0 my %o = ();
98 0 ▶ $o{align} = $anchor eq "end"
Branch: 2 branches
BranchTrueFalseTotal
$anchor eq 'end' ? : 0 0 0
$anchor eq 'middle' ? : 0 0 0
99 ? "right"
100 : $anchor eq "middle" ? "center" : "left";
101 0 $xo->textstart;
102 0 $self->set_font( $xo, $style );
103 0 $xo->text( shift(@$text), %o );
104 0 $xo->textend;
105 0 $xo->restore;
106 }
107 }
108 else {
109 28 $_ = $x->[0];
110 28 ▶ if ( $tf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tf) 0 28 28
111 0 $self->_dbg( "X %.2f = %.2f + %.2f",
112 $dx + $_, $dx, $_ );
113 0 $self->_dbg( "Y %.2f = - %.2f - %.2f",
114 - $dy - $y->[0], $dy, $y->[0] );
115 }
116 28 my $x = $dx + $_;
117 28 my $y = $dy + shift(@$y);
118 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
119 $x, $y,
120 ($scalex != 1 || $scaley != -1 )
121 ? sprintf(" scale( %.2f %.2f )", $scalex, -$scaley ) : "" );
122 28 my %o = ();
123 28 ▶ $o{align} = $anchor eq "end"
Branch: 2 branches
BranchTrueFalseTotal
$anchor eq 'end' ? : 0 28 28
$anchor eq 'middle' ? : 8 20 28
124 ? "right"
125 : $anchor eq "middle" ? "center" : "left";
126 28 my $tc = $self->root->tc;
127 28 my $fc = $self->root->fc;
128 28 for my $c ( @c ) {
129 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
130 36 $self->_dbg( "+ xo save" );
131 36 $xo->save;
132 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
133 ($scalex != 1 || $scaley != -1 )
134 ? ( scale => [ $scalex, -$scaley ] ) : ()
135 );
136 36 $scalex = $scaley = 1; # no more scaling.
137  
138 36 $xo->textstart;
139 36 ▶ if ( $tc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tc) { } 0 36 36
140 0 $x += $tc->( $self, xo => $xo, pdf => $self->root->pdf,
141 style => $style, text => $c->content, %o );
142 }
143 else {
144 36 $self->set_font( $xo, $style );
145 36 $x += $xo->text( $c->content, %o );
146 }
147 36 $xo->textend;
148 36 ▶ if ( $style->{'outline-style'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($style->{"outline-style"}) 0 36 36
149 # BEEP BEEP TRICKERY.
150 0 my $fn = $xo->{" font"};
151 0 my $sz = $xo->{" fontsize"};
152 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
153 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
154 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
155 0 $xo->rectangle( -$d,
156 -$d+$sz*$fn->descender/1000,
157 $x-$ix+2*$d,
158 2*$d+$sz*$fn->ascender/1000 );
159 0 $xo->stroke;
160 }
161 36 $self->_dbg( "- xo restore" );
162 36 $xo->restore;
163 36 $ex = $x; $ey = $y;
164 }
165 elsif ( ref($c) eq 'SVGPDF::Tspan' ) {
166 8 $self->_dbg( "+ xo save" );
167 8 $xo->save;
168 8 ▶ if ( defined($c->atts->{x}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c->atts->{"x"}) 4 4 8
169 4 $x = 0;
170 }
171 8 ▶ if ( defined($c->atts->{'y'}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c->atts->{"y"}) 0 8 8
172 0 $y = 0;
173 }
174 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
175 ( $scalex != 1 || $scaley != -1 )
176 ? ( scale => [ $scalex, -$scaley ] ) : (),
177 );
178 8 $scalex = $scaley = 1; # no more scaling.
179 8 my ( $x0, $y0 ) = $c->process();
180 8 $x += $x0; $y += $y0;
181 8 $self->_dbg("tspan moved to $x, $y");
182 8 $self->_dbg( "- xo restore" );
183 8 $xo->restore;
184 8 $ex = $x; $ey = $y;
185 }
186 else {
187 0 $self->nfi( $c->name . " in text" );
188 }
189 }
190 }
191  
192 28 $self->_dbg( "- xo restore" );
193 28 $xo->restore;
194 28 $self->css_pop;
195 2 }
196  
197 2 1;
« SVGPDF/FontManager.pm ↑ Summary SVGPDF/Contrib/PathExtract.pm »