| 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::Svg :isa(SVGPDF::Element); | ||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | method process () { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=34 SCAR=47.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 11 | 1 | my $atts = $self->atts; | |||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | return if $atts->{omit}; # for testing/debugging. | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my $xo = $self->xo; | |||||||||||||||||||||||||||||||||||||
| 15 | 1 | my $xoforms = $self->root->xoforms; | |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | 1 | delete $atts->{$_} for qw( xmlns:xlink xmlns:svg xmlns version ); | |||||||||||||||||||||||||||||||||||||
| 18 | 1 | my ( $x, $y, $vwidth, $vheight, $vbox, $par, $tf ) = | |||||||||||||||||||||||||||||||||||||
| 19 | $self->get_params( $atts, qw( x:U y:U width:s height:s viewBox preserveAspectRatio:s transform:s ) ); | ||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | $self->nfi("nested svg transform") if $tf; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | $self->nfi("preserveAspectRatio") if $par; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 22 | 1 | my $style = $self->style; | |||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | 1 | my $parent; | |||||||||||||||||||||||||||||||||||||
| 25 | 1 | for ( @{ $self->root->xoforms } ) { | |||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | next unless $_->{xo} eq $xo; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 27 | 1 | $parent = $_; | |||||||||||||||||||||||||||||||||||||
| 28 | 1 | last; | |||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | croak("I feel like a motherless child") unless $parent; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $pwidth = $parent->{width}; | |||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $pheight = $parent->{height}; | |||||||||||||||||||||||||||||||||||||
| 34 | 1 | for ( $vwidth ) { | |||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | $_ = $self->u( $_ || $pwidth, width => $pwidth ); | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_ || $pwidth
MC/DC0%0/2
$_ || $pwidth
$_
$pwidth
Truth table33%1/3
A || B
A= $_B= $pwidth
| |||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||
| 37 | 1 | for ( $vheight ) { | |||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | $_ = $self->u( $_ || $pheight, width => $pheight ); | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_ || $pheight
MC/DC0%0/2
$_ || $pheight
$_
$pheight
Truth table33%1/3
A || B
A= $_B= $pheight
| |||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | 1 | $self->_dbg("pp w=$pwidth h=$pheight vw=$vwidth vh=$vheight"); | |||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my @vb; # viewBox: llx lly width height | |||||||||||||||||||||||||||||||||||||
| 44 | my @bb; # bbox: llx lly urx ury | ||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my $width; # width of the vbox | |||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $height; # height of the vbox | |||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if ( $vbox ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | 1 | @vb = $self->getargs($vbox); | |||||||||||||||||||||||||||||||||||||
| 50 | 1 | $width = $self->u( $vb[2], | |||||||||||||||||||||||||||||||||||||
| 51 | width => $pwidth ); | ||||||||||||||||||||||||||||||||||||||
| 52 | 1 | $height = $self->u( $vb[3], | |||||||||||||||||||||||||||||||||||||
| 53 | width => $height ); | ||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $width = $vwidth; | |||||||||||||||||||||||||||||||||||||
| 57 | 0 | $height = $vheight; | |||||||||||||||||||||||||||||||||||||
| 58 | 0 | @vb = ( 0, 0, $width, $height ); | |||||||||||||||||||||||||||||||||||||
| 59 | 0 | $vbox = "@vb"; | |||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||
| 62 | # Get llx lly urx ury bounding box rectangle. | ||||||||||||||||||||||||||||||||||||||
| 63 | 1 | @bb = $self->root->vb2bb_noflip(@vb); | |||||||||||||||||||||||||||||||||||||
| 64 | 1 | $self->_dbg( "vb $vbox => bb %.2f %.2f %.2f %.2f", @bb ); | |||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | warn( sprintf("vb $vbox => bb %.2f %.2f %.2f %.2f\n", @bb )) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->root->verbose and not $self->root->debug
MC/DC0%0/2
$self->root->verbose and not $self->root->debug
$self->root->verbose
not $self->root->debug
Truth table33%1/3
A and not(B)
A= $self->root->verboseB= not $self->root->debug
| |||||||||||||||||||||||||||||||||||||||
| 66 | if $self->root->verbose && !$self->root->debug; | ||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | 1 | my $new_xo = $self->root->pdf->xo_form; | |||||||||||||||||||||||||||||||||||||
| 69 | 1 | $new_xo->bbox(@bb); | |||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | # Set up result forms. | ||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | push( @$xoforms, | ||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$vwidth || $vb[2]
$vheight || $vb[3]
MC/DC0%0/2
$vwidth || $vb[2]
$vwidth
$vb[2]
MC/DC0%0/2
$vheight || $vb[3]
$vheight
$vb[3]
Truth table33%1/3
A || B
A= $vwidthB= $vb[2]
Truth table33%1/3
A || B
A= $vheightB= $vb[3]
| |||||||||||||||||||||||||||||||||||||||
| 73 | { xo => $new_xo, | ||||||||||||||||||||||||||||||||||||||
| 74 | # Design (desired) width and height. | ||||||||||||||||||||||||||||||||||||||
| 75 | vwidth => $vwidth || $vb[2], | ||||||||||||||||||||||||||||||||||||||
| 76 | vheight => $vheight || $vb[3], | ||||||||||||||||||||||||||||||||||||||
| 77 | # viewBox (SVG coordinates) | ||||||||||||||||||||||||||||||||||||||
| 78 | vbox => [ @vb ], | ||||||||||||||||||||||||||||||||||||||
| 79 | width => $vb[2], | ||||||||||||||||||||||||||||||||||||||
| 80 | height => $vb[3], | ||||||||||||||||||||||||||||||||||||||
| 81 | diag => sqrt( $vb[2]**2 + $vb[3]**2 ) / sqrt(2), | ||||||||||||||||||||||||||||||||||||||
| 82 | # bbox (PDF coordinates) | ||||||||||||||||||||||||||||||||||||||
| 83 | bbox => [ @bb ], | ||||||||||||||||||||||||||||||||||||||
| 84 | yflip => 0, | ||||||||||||||||||||||||||||||||||||||
| 85 | } ); | ||||||||||||||||||||||||||||||||||||||
| 86 | 1 | $self->_dbg("XObject #", scalar(@$xoforms) ); | |||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | 1 | $self->traverse; | |||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $scalex = 1; | |||||||||||||||||||||||||||||||||||||
| 91 | 1 | my $scaley = 1; | |||||||||||||||||||||||||||||||||||||
| 92 | 1 | my $dx = 0; | |||||||||||||||||||||||||||||||||||||
| 93 | 1 | my $dy = 0; | |||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | if ( $vbox ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my @pbb = $xo->bbox; # parent | |||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | if ( $vwidth ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $scalex = $vwidth / $vb[2]; | |||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||
| 99 | 1 | ▶ | if ( $vheight ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $scaley = $vheight / $vb[3]; | |||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||
| 102 | # warn("pbbx @pbb\n"); | ||||||||||||||||||||||||||||||||||||||
| 103 | # warn("bbox @bb scale=$scalex/$scaley\n"); | ||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | if ( $par =~ /none/i ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $par = ""; | |||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||||||||||||
| 108 | # Uniform scale. | ||||||||||||||||||||||||||||||||||||||
| 109 | # $scalex = $scaley = min( $scalex, $scaley ); | ||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | if ( $par =~ /xM(ax|id|in)/i && $scalex > $scaley ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$par =~ /xM(ax|id|in)/iu and $scalex > $scaley
MC/DC0%0/2
$par =~ /xM(ax|id|in)/iu and $scalex > $scaley
$par =~ /xM(ax|id|in)/iu
$scalex > $scaley
Truth table33%1/3
A and B
A= $par =~ /xM(ax|id|in)/iuB= $scalex > $scaley
| |||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( $1 eq "ax" ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $dx = max($pbb[0],$pbb[2]) - max($bb[0],$bb[2]); | |||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||
| 115 | elsif ( $1 eq "id" ) { | ||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $dx = (($pbb[2]-$pbb[0])/2) - (($bb[2]-$bb[0])/2); | |||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $dx = min($pbb[0],$pbb[2]) - min($bb[0],$bb[2]); | |||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | if ( $par =~ /yM(in|id|ax)/i && $scaley > $scalex ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$par =~ /yM(in|id|ax)/iu and $scaley > $scalex
MC/DC0%0/2
$par =~ /yM(in|id|ax)/iu and $scaley > $scalex
$par =~ /yM(in|id|ax)/iu
$scaley > $scalex
Truth table33%1/3
A and B
A= $par =~ /yM(in|id|ax)/iuB= $scaley > $scalex
| |||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ( $1 eq "ax" ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $dy = max($pbb[1],$pbb[3]) - max($bb[1],$bb[3]); | |||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||
| 126 | elsif ( $1 eq "id" ) { | ||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $dy = | |||||||||||||||||||||||||||||||||||||
| 128 | ((max($pbb[1],$pbb[3])-min($pbb[1],$pbb[3]))/2) | ||||||||||||||||||||||||||||||||||||||
| 129 | - ((max($bb[1],$bb[3])-min($bb[1],$bb[3]))/2) | ||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||
| 131 | else { | ||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $dy = min($pbb[1],$pbb[3]) - min($bb[1],$bb[3]); | |||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | if ( $par ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $scalex = $scaley = min( $scalex, $scaley ); | |||||||||||||||||||||||||||||||||||||
| 137 | 0 | $dx *= $scalex; | |||||||||||||||||||||||||||||||||||||
| 138 | 0 | $dy *= $scaley; | |||||||||||||||||||||||||||||||||||||
| 139 | 0 | warn("disp dx=$dx, dy=$dy\n"); | |||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | $self->_dbg( "xo object( %.2f%+.2f %.2f%+.2f %.3f %.3f ) %s", | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$par // ""
MC/DC0%0/1
$par // ""
$par
Truth table50%1/2
A
A= $par
| |||||||||||||||||||||||||||||||||||||||
| 143 | $x, $dx, $y, $dy, $scalex, $scaley, $par//"" ); | ||||||||||||||||||||||||||||||||||||||
| 144 | 1 | ▶ | warn(sprintf("xo object( %.2f%+.2f %.2f%+.2f %.3f %.3f ) %s\n", | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$self->root->verbose and not $self->root->debug
$par // ""
MC/DC0%0/2
$self->root->verbose and not $self->root->debug
$self->root->verbose
not $self->root->debug
MC/DC0%0/1
$par // ""
$par
Truth table33%1/3
A and not(B)
A= $self->root->verboseB= not $self->root->debug
Truth table0%0/2
A
A= $par
| |||||||||||||||||||||||||||||||||||||||
| 145 | $x, $dx, $y, $dy, $scalex, $scaley, $par//"" )) | ||||||||||||||||||||||||||||||||||||||
| 146 | if $self->root->verbose && !$self->root->debug; | ||||||||||||||||||||||||||||||||||||||
| 147 | 1 | $xo->object( $new_xo, $x+$dx, $y+$dy, $scalex, $scaley ); | |||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||
| 149 | 1 | pop( @$xoforms ); | |||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $self->css_pop; | |||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||
| 153 | 2 | } | |||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub min ( $x, $y ) { $x < $y ? $x : $y } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
min: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub max ( $x, $y ) { $x > $y ? $x : $y } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
max: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | 2 | 1; | |||||||||||||||||||||||||||||||||||||