| 1 | #! perl | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use v5.26; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use Object::Pad; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use utf8; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | class SVGPDF::Text :isa(SVGPDF::Element); | ||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | method process () { | ||||||||||||||||||||||||||||
|
Subroutine
process: not called CC=51 SCAR=78.7
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 11 | 0 | my $atts = $self->atts; | |||||||||||||||||||||||||||||
| 12 | 0 | my $xo = $self->xo; | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | return if $atts->{omit}; # for testing/debugging. | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | 0 | my ( $x, $y, $dx, $dy, $tf ) = | |||||||||||||||||||||||||||||
| 16 | $self->get_params( $atts, qw( x:s y:s dx:U dy:U transform:s ) ); | ||||||||||||||||||||||||||||||
| 17 | 0 | my $style = $self->style; | |||||||||||||||||||||||||||||
| 18 | 0 | $_ = 0+$self->u($_) for $style->{'font-size'}; | |||||||||||||||||||||||||||||
| 19 | 0 | my $text = ""; | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | 0 | my $color = $style->{fill}; | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $color = $style->{color} if $color && $color eq "currentColor"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$color and $color eq "currentColor"
MC/DC0%0/2
$color and $color eq "currentColor"
$color
$color eq "currentColor"
Truth table0%0/3
A and B
A= $colorB= $color eq "currentColor"
| |||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $anchor = $style->{'text-anchor'} || "left"; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$style->{'text-anchor'} || 'left'
MC/DC0%0/1
$style->{'text-anchor'} || 'left'
$style->{'text-anchor'}
Truth table0%0/2
A
A= $style->{'text-anchor'}
| |||||||||||||||||||||||||||||||
| 24 | 0 | $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 | 0 | ▶ | defined($style->{"transform"}) #??? | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 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 | 0 | my @c = $self->get_children; | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ( $x =~ /,/ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ( @c > 1 || ref($c[0]) ne "SVGPDF::TextElement" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@c > 1 or ref $c[0] ne "SVGPDF::TextElement"
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"
| |||||||||||||||||||||||||||||||
| 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
Condition0%0/3
@$x == @$y and @$y == @$text
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
| |||||||||||||||||||||||||||||||
| 50 | unless @$x == @$y && @$y == @$text; | ||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||
| 52 | else { | ||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $x = [ $self->u($x||0) ]; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$x || 0
MC/DC0%0/1
$x || 0
$x
Truth table0%0/2
A
A= $x
| |||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $y = [ $self->u($y||0) ]; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$y || 0
MC/DC0%0/1
$y || 0
$y
Truth table0%0/2
A
A= $y
| |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||
| 57 | 0 | $self->_dbg( "+ xo save" ); | |||||||||||||||||||||||||||||
| 58 | 0 | $xo->save; | |||||||||||||||||||||||||||||
| 59 | 0 | my $ix = $x->[0]; | |||||||||||||||||||||||||||||
| 60 | 0 | my $iy = $y->[0]; | |||||||||||||||||||||||||||||
| 61 | 0 | my ( $ex, $ey ); | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | 0 | my $scalex = 1; | |||||||||||||||||||||||||||||
| 64 | 0 | my $scaley = 1; | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $tf ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | ( $dx, $dy ) = $self->getargs($1) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 67 | if $tf =~ /translate\((.*?)\)/; | ||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | ( $scalex, $scaley ) = $self->getargs($1) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 69 | if $tf =~ /scale\((.*?)\)/; | ||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $scaley ||= $scalex; | ||||||||||||||||||||||||||||
|
Condition0%0/3
$scaley ||= $scalex
MC/DC0%0/2
$scaley ||= $scalex
$scaley
$scalex
Truth table0%0/3
A ||= B
A= $scaleyB= $scalex
| |||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | if ( @$x > 1 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 77 | 0 | for ( @$x ) { | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( $tf ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$scalex != 1 or $scaley != -1
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
| |||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$scalex != 1 or $scaley != -1
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
| |||||||||||||||||||||||||||||||
| 94 | ($scalex != 1 || $scaley != -1 ) | ||||||||||||||||||||||||||||||
| 95 | ? ( scale => [ $scalex, -$scaley ] ) : (), | ||||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||||
| 97 | 0 | my %o = (); | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $o{align} = $anchor eq "end" | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 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 | 0 | $_ = $x->[0]; | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ( $tf ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 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 | 0 | my $x = $dx + $_; | |||||||||||||||||||||||||||||
| 117 | 0 | my $y = $dy + shift(@$y); | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $self->_dbg( "txt translate( %.2f, %.2f )%s", | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$scalex != 1 or $scaley != -1
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
| |||||||||||||||||||||||||||||||
| 119 | $x, $y, | ||||||||||||||||||||||||||||||
| 120 | ($scalex != 1 || $scaley != -1 ) | ||||||||||||||||||||||||||||||
| 121 | ? sprintf(" scale( %.2f %.2f )", $scalex, -$scaley ) : "" ); | ||||||||||||||||||||||||||||||
| 122 | 0 | my %o = (); | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $o{align} = $anchor eq "end" | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 124 | ? "right" | ||||||||||||||||||||||||||||||
| 125 | : $anchor eq "middle" ? "center" : "left"; | ||||||||||||||||||||||||||||||
| 126 | 0 | my $tc = $self->root->tc; | |||||||||||||||||||||||||||||
| 127 | 0 | my $fc = $self->root->fc; | |||||||||||||||||||||||||||||
| 128 | 0 | for my $c ( @c ) { | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if ( ref($c) eq 'SVGPDF::TextElement' ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 130 | 0 | $self->_dbg( "+ xo save" ); | |||||||||||||||||||||||||||||
| 131 | 0 | $xo->save; | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $xo->transform( translate => [ $x, $y ], | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$scalex != 1 or $scaley != -1
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
| |||||||||||||||||||||||||||||||
| 133 | ($scalex != 1 || $scaley != -1 ) | ||||||||||||||||||||||||||||||
| 134 | ? ( scale => [ $scalex, -$scaley ] ) : () | ||||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||||
| 136 | 0 | $scalex = $scaley = 1; # no more scaling. | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||
| 138 | 0 | $xo->textstart; | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ( $tc ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 140 | 0 | $x += $tc->( $self, xo => $xo, pdf => $self->root->pdf, | |||||||||||||||||||||||||||||
| 141 | style => $style, text => $c->content, %o ); | ||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||
| 144 | 0 | $self->set_font( $xo, $style ); | |||||||||||||||||||||||||||||
| 145 | 0 | $x += $xo->text( $c->content, %o ); | |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||
| 147 | 0 | $xo->textend; | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ( $style->{'outline-style'} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$style->{'outline-width'} || 1
$style->{'outline-width'}
Truth table0%0/2
A
A= $style->{'outline-width'}
| |||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $xo->stroke_color( $style->{'outline-color'} || 'black' ); | ||||||||||||||||||||||||||||
|
Condition0%0/2
$style->{'outline-color'} || 'black'
MC/DC0%0/1
$style->{'outline-color'} || 'black'
$style->{'outline-color'}
Truth table0%0/2
A
A= $style->{'outline-color'}
| |||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my $d = $self->u($style->{'outline-offset'}) || 1; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->u($style->{'outline-offset'}) || 1
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'})
| |||||||||||||||||||||||||||||||
| 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 | 0 | $self->_dbg( "- xo restore" ); | |||||||||||||||||||||||||||||
| 162 | 0 | $xo->restore; | |||||||||||||||||||||||||||||
| 163 | 0 | $ex = $x; $ey = $y; | |||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||
| 165 | elsif ( ref($c) eq 'SVGPDF::Tspan' ) { | ||||||||||||||||||||||||||||||
| 166 | 0 | $self->_dbg( "+ xo save" ); | |||||||||||||||||||||||||||||
| 167 | 0 | $xo->save; | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if ( defined($c->atts->{x}) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 169 | 0 | $x = 0; | |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ( defined($c->atts->{'y'}) ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 172 | 0 | $y = 0; | |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $xo->transform( translate => [ $x, $y ], | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$scalex != 1 or $scaley != -1
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
| |||||||||||||||||||||||||||||||
| 175 | ( $scalex != 1 || $scaley != -1 ) | ||||||||||||||||||||||||||||||
| 176 | ? ( scale => [ $scalex, -$scaley ] ) : (), | ||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||
| 178 | 0 | $scalex = $scaley = 1; # no more scaling. | |||||||||||||||||||||||||||||
| 179 | 0 | my ( $x0, $y0 ) = $c->process(); | |||||||||||||||||||||||||||||
| 180 | 0 | $x += $x0; $y += $y0; | |||||||||||||||||||||||||||||
| 181 | 0 | $self->_dbg("tspan moved to $x, $y"); | |||||||||||||||||||||||||||||
| 182 | 0 | $self->_dbg( "- xo restore" ); | |||||||||||||||||||||||||||||
| 183 | 0 | $xo->restore; | |||||||||||||||||||||||||||||
| 184 | 0 | $ex = $x; $ey = $y; | |||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||
| 186 | else { | ||||||||||||||||||||||||||||||
| 187 | 0 | $self->nfi( $c->name . " in text" ); | |||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||
| 192 | 0 | $self->_dbg( "- xo restore" ); | |||||||||||||||||||||||||||||
| 193 | 0 | $xo->restore; | |||||||||||||||||||||||||||||
| 194 | 0 | $self->css_pop; | |||||||||||||||||||||||||||||
| 195 | 12 | } | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||
| 197 | 12 | 1; | |||||||||||||||||||||||||||||