| 1 | package ConvertSMIL; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | # SMIL tags generator | ||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub smil { | ||||||||||||||||||||||||||||
|
Subroutine
smil: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | if ($_[0][0] == 1) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 11 | 0 | return changeThickness($_[0][1], # from | |||||||||||||||||||||||||||||
| 12 | $_[0][2], # to | ||||||||||||||||||||||||||||||
| 13 | $_[0][3], # begin | ||||||||||||||||||||||||||||||
| 14 | $_[0][4]); # dur | ||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | ▶ | } elsif (($_[0][0] >= 11) && ($_[0][0] <= 16)) { | |||||||||||||||||||||||||||||
|
Condition0%0/3
$_[0][0] >= 11 and $_[0][0] <= 16
MC/DC0%0/2
$_[0][0] >= 11 and $_[0][0] <= 16
$_[0][0] >= 11
$_[0][0] <= 16
Truth table0%0/3
A and B
A= $_[0][0] >= 11B= $_[0][0] <= 16
| |||||||||||||||||||||||||||||||
| 17 | 0 | return translate($_[0][1], $_[0][2], # begin, dur | |||||||||||||||||||||||||||||
| 18 | $_[0][3], $_[0][4], # x, y | ||||||||||||||||||||||||||||||
| 19 | $_[0][5]); # unit | ||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | ▶ | } elsif (($_[0][0] >= 21) && ($_[0][0] <= 26)) { | |||||||||||||||||||||||||||||
|
Condition0%0/3
$_[0][0] >= 21 and $_[0][0] <= 26
MC/DC0%0/2
$_[0][0] >= 21 and $_[0][0] <= 26
$_[0][0] >= 21
$_[0][0] <= 26
Truth table0%0/3
A and B
A= $_[0][0] >= 21B= $_[0][0] <= 26
| |||||||||||||||||||||||||||||||
| 22 | 0 | return rotate($_[0][1], $_[0][2], # begin, dur | |||||||||||||||||||||||||||||
| 23 | $_[0][3], # angle | ||||||||||||||||||||||||||||||
| 24 | $_[0][4], $_[0][5], # x, y | ||||||||||||||||||||||||||||||
| 25 | $_[0][6]); # unit | ||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | ▶ | } elsif (($_[0][0] >= 31) && ($_[0][0] <= 36)) { | |||||||||||||||||||||||||||||
|
Condition0%0/3
$_[0][0] >= 31 and $_[0][0] <= 36
MC/DC0%0/2
$_[0][0] >= 31 and $_[0][0] <= 36
$_[0][0] >= 31
$_[0][0] <= 36
Truth table0%0/3
A and B
A= $_[0][0] >= 31B= $_[0][0] <= 36
| |||||||||||||||||||||||||||||||
| 28 | 0 | return scale($_[0][1], $_[0][2], # begin, dur | |||||||||||||||||||||||||||||
| 29 | $_[0][3], # factor | ||||||||||||||||||||||||||||||
| 30 | $_[0][4], $_[0][5]); # x, y | ||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | } elsif ($_[0][0] == 2) { | ||||||||||||||||||||||||||||||
| 33 | 0 | return changeFillIntensity($_[0][1], $_[0][2], # begin, dur | |||||||||||||||||||||||||||||
| 34 | $_[0][3], $_[0][4], # from, to | ||||||||||||||||||||||||||||||
| 35 | $_[0][5], $_[0][6]); # color, colors | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | } elsif ($_[0][0] == 0) { | ||||||||||||||||||||||||||||||
| 38 | 0 | return setAttributeValue($_[0][1], $_[0][2], # begin, dur | |||||||||||||||||||||||||||||
| 39 | $_[0][3], $_[0][4]); # attribute, value | ||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||||
| 42 | 0 | return ""; | |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub setAttributeValue { | ||||||||||||||||||||||||||||
|
Subroutine
setAttributeValue: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||
| 48 | 0 | my ($begin, $dur, $attribute, $value, $colors) = @_; | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | 0 | my $attributeType; | |||||||||||||||||||||||||||||
| 51 | my $attributeName; | ||||||||||||||||||||||||||||||
| 52 | 0 | my $to; | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($attribute eq "visibility") { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 55 | 0 | $attributeType = "CSS"; | |||||||||||||||||||||||||||||
| 56 | 0 | $attributeName = "visibility"; | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($value == 0) { $to = "hidden"; } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 58 | 0 | else { $to = "visible"; } | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | } elsif ($attribute eq "pen_color") { | ||||||||||||||||||||||||||||||
| 61 | 0 | $attributeType = "CSS"; | |||||||||||||||||||||||||||||
| 62 | 0 | $attributeName = "stroke"; | |||||||||||||||||||||||||||||
| 63 | 0 | $to = ConvertSVG::pen_fill_colors_to_rgb($value, $colors); | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | } elsif ($attribute eq "fill_color") { | ||||||||||||||||||||||||||||||
| 66 | 0 | $attributeType = "CSS"; | |||||||||||||||||||||||||||||
| 67 | 0 | $attributeName = "fill"; | |||||||||||||||||||||||||||||
| 68 | 0 | $to = ConvertSVG::pen_fill_colors_to_rgb($value, $colors); | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | } else { | ||||||||||||||||||||||||||||||
| 71 | # error | ||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($attributeName) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 75 | return | ||||||||||||||||||||||||||||||
| 76 | 0 | "<set attributeName=\"" . $attributeName . "\" " . | |||||||||||||||||||||||||||||
| 77 | "attributeType=\"" . $attributeType . "\" " . | ||||||||||||||||||||||||||||||
| 78 | "to=\"" . $to . "\" " . | ||||||||||||||||||||||||||||||
| 79 | "begin=\"" . $begin . "s\" " . | ||||||||||||||||||||||||||||||
| 80 | "dur=\"0s\" " . | ||||||||||||||||||||||||||||||
| 81 | "fill=\"freeze\" " . | ||||||||||||||||||||||||||||||
| 82 | "/>"; | ||||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||||
| 84 | # error | ||||||||||||||||||||||||||||||
| 85 | 0 | return ""; | |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub changeThickness { | ||||||||||||||||||||||||||||
|
Subroutine
changeThickness: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 90 | 0 | my ($from, $to, $begin, $dur) = @_; | |||||||||||||||||||||||||||||
| 91 | return | ||||||||||||||||||||||||||||||
| 92 | 0 | "<animate attributeName=\"stroke-width\" attributeType=\"CSS\" " . | |||||||||||||||||||||||||||||
| 93 | "from=\"" . ConvertSVG::thickness_to_value($from) . "\" " . | ||||||||||||||||||||||||||||||
| 94 | "to=\"" . ConvertSVG::thickness_to_value($to) . "\" " . | ||||||||||||||||||||||||||||||
| 95 | "begin=\"" . $begin . "s\" " . | ||||||||||||||||||||||||||||||
| 96 | "dur=\"" . $dur . "s\" " . | ||||||||||||||||||||||||||||||
| 97 | "fill=\"freeze\" " . | ||||||||||||||||||||||||||||||
| 98 | "/>"; | ||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub changeFillIntensity { | ||||||||||||||||||||||||||||
|
Subroutine
changeFillIntensity: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 102 | 0 | my ($begin, $dur, $from, $to, $color, $colors) = @_; | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | 0 | $from = ConvertSVG::area_fill_to_fill($from, $color, $colors); | |||||||||||||||||||||||||||||
| 105 | 0 | $to = ConvertSVG::area_fill_to_fill($to, $color, $colors); | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||
| 107 | 0 | $from =~ s/fill: //; | |||||||||||||||||||||||||||||
| 108 | 0 | $to =~ s/fill: //; | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | return | ||||||||||||||||||||||||||||||
| 111 | 0 | "<animateColor attributeName=\"fill\" attributeType=\"CSS\" " . | |||||||||||||||||||||||||||||
| 112 | "begin=\"" . $begin . "s\" " . | ||||||||||||||||||||||||||||||
| 113 | "dur=\"" . $dur . "s\" " . | ||||||||||||||||||||||||||||||
| 114 | "from=\"" . $from . "\" " . | ||||||||||||||||||||||||||||||
| 115 | "to=\"" . $to . "\" " . | ||||||||||||||||||||||||||||||
| 116 | "fill=\"freeze\" " . | ||||||||||||||||||||||||||||||
| 117 | "/>"; | ||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub translate { | ||||||||||||||||||||||||||||
|
Subroutine
translate: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||
| 121 | 0 | my ($begin, $dur, $x, $y, $unit) = @_; | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($unit eq 'in') { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 124 | 0 | $x = 1200 * $x; | |||||||||||||||||||||||||||||
| 125 | 0 | $y = 1200 * $y; | |||||||||||||||||||||||||||||
| 126 | } elsif ($unit eq 'cm') { | ||||||||||||||||||||||||||||||
| 127 | 0 | $x = 450 * $x; | |||||||||||||||||||||||||||||
| 128 | 0 | $y = 450 * $y; | |||||||||||||||||||||||||||||
| 129 | } elsif ($unit eq 'px') { | ||||||||||||||||||||||||||||||
| 130 | 0 | $x = 15 * $x; | |||||||||||||||||||||||||||||
| 131 | 0 | $y = 15 * $y; | |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||
| 134 | return | ||||||||||||||||||||||||||||||
| 135 | 0 | "<animateTransform attributeType=\"XML\" " . | |||||||||||||||||||||||||||||
| 136 | "attributeName=\"transform\" type=\"translate\" " . | ||||||||||||||||||||||||||||||
| 137 | "from=\"0 0\" " . | ||||||||||||||||||||||||||||||
| 138 | "to=\"" . $x . " " . $y . "\" " . | ||||||||||||||||||||||||||||||
| 139 | "begin=\"" . $begin . "s\" " . | ||||||||||||||||||||||||||||||
| 140 | "dur=\"" . $dur . "s\" " . | ||||||||||||||||||||||||||||||
| 141 | "fill=\"freeze\" " . | ||||||||||||||||||||||||||||||
| 142 | "additive=\"sum\" " . | ||||||||||||||||||||||||||||||
| 143 | "/>"; | ||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub rotate { | ||||||||||||||||||||||||||||
|
Subroutine
rotate: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||
| 147 | 0 | my ($begin, $dur, $angle, $x, $y, $unit) = @_; | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if ($unit eq 'in') { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 150 | 0 | $x = 1200 * $x; | |||||||||||||||||||||||||||||
| 151 | 0 | $y = 1200 * $y; | |||||||||||||||||||||||||||||
| 152 | } elsif ($unit eq 'cm') { | ||||||||||||||||||||||||||||||
| 153 | 0 | $x = 450 * $x; | |||||||||||||||||||||||||||||
| 154 | 0 | $y = 450 * $y; | |||||||||||||||||||||||||||||
| 155 | } elsif ($unit eq 'px') { | ||||||||||||||||||||||||||||||
| 156 | 0 | $x = 15 * $x; | |||||||||||||||||||||||||||||
| 157 | 0 | $y = 15 * $y; | |||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||
| 160 | return | ||||||||||||||||||||||||||||||
| 161 | 0 | "<animateTransform attributeType=\"XML\" " . | |||||||||||||||||||||||||||||
| 162 | "attributeName=\"transform\" type=\"rotate\" " . | ||||||||||||||||||||||||||||||
| 163 | "from=\"0 " . $x . " " . $y . "\" " . | ||||||||||||||||||||||||||||||
| 164 | "to=\"" . $angle . " " .$x . " " . $y . "\" " . | ||||||||||||||||||||||||||||||
| 165 | "begin=\"" . $begin . "s\" " . | ||||||||||||||||||||||||||||||
| 166 | "dur=\"" . $dur . "s\" " . | ||||||||||||||||||||||||||||||
| 167 | "fill=\"freeze\" " . | ||||||||||||||||||||||||||||||
| 168 | "additive=\"sum\" " . | ||||||||||||||||||||||||||||||
| 169 | "/>"; | ||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub scale { | ||||||||||||||||||||||||||||
|
Subroutine
scale: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 173 | 0 | my ($begin, $dur, $factor, $x, $y) = @_; | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||
| 175 | return | ||||||||||||||||||||||||||||||
| 176 | 0 | translate($begin, $dur, -$x*($factor-1), -$y*($factor-1), '') . | |||||||||||||||||||||||||||||
| 177 | "<animateTransform attributeType=\"XML\" " . | ||||||||||||||||||||||||||||||
| 178 | "attributeName=\"transform\" type=\"scale\" " . | ||||||||||||||||||||||||||||||
| 179 | "from=\"1 1\" " . | ||||||||||||||||||||||||||||||
| 180 | "to=\"" . $factor . " " . $factor . "\" " . | ||||||||||||||||||||||||||||||
| 181 | "begin=\"" . $begin . "s\" " . | ||||||||||||||||||||||||||||||
| 182 | "dur=\"" . $dur . "s\" " . | ||||||||||||||||||||||||||||||
| 183 | "fill=\"freeze\" " . | ||||||||||||||||||||||||||||||
| 184 | "additive=\"sum\" " . | ||||||||||||||||||||||||||||||
| 185 | "/>"; | ||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||
| 189 | 1 | 1; | |||||||||||||||||||||||||||||