FigAnim/ConvertSVG.pm

filter: Statementstmt 3.8% 7 / 181 Branchbran 0.0% 0 / 128 Conditioncond 0.0% 0 / 120 MC/DCmcdc 0.0% 0 / 55 Subroutinesub 13.3% 2 / 15 Podpod n/a totaltotal 1.8% 9 / 499 CC 106 SCAR 68.4
CC
106
Cov
2%
font_flags_to_font
1806.0
area_fill_to_fill
1056.0
arrows_to_markers
156.0
CRAP 937.1
« FigAnim.pm ↑ Summary FigAnim/Polyline.pm »
1 package ConvertSVG;
2  
3 # SVG styles and 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 # returns the min of the values
10 0 ▶sub min {
Subroutine min: not called CC=3 SCAR=24.8
11 0 my $min = $_[0];
12 0 ▶ for (my $i = 0; $i < scalar @_; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
13 0 ▶ if ($_[$i] < $min) { $min = $_[$i]; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i] < $min) 0 0 0
14 }
15 0 return $min;
16 }
17  
18  
19 # return the max of the values
20 0 ▶sub max {
Subroutine max: not called CC=3 SCAR=24.8
21 0 my $max = $_[0];
22 0 ▶ for (my $i = 0; $i < scalar @_; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
23 0 ▶ if ($_[$i] > $max) { $max = $_[$i]; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[$i] > $max) 0 0 0
24 }
25 0 return $max;
26 }
27  
28  
29 # converts paper size into cm/in with viewBox
30 0 ▶sub papersize_to_units {
Subroutine papersize_to_units: not called CC=3 SCAR=24.8
31 0 my ($papersize, $orientation, $magnification, $resolution) = @_;
32  
33 # removes spaces at the end of the string
34 0 $papersize =~ s/\s*$//;
35  
36 0 my %paperdef =
37 ("Letter" => [8.5, 11, 'in'],
38 "Legal" => [8.5, 14, 'in'],
39 "Tabloid" => [11, 17, 'in'],
40 "A" => [8.5, 11, 'in'],
41 "B" => [11, 17, 'in'],
42 "C" => [17, 22, 'in'],
43 "D" => [22, 34, 'in'],
44 "E" => [34, 44, 'in'],
45 "A9" => [37, 52, 'mm'],
46 "A8" => [52, 74, 'mm'],
47 "A7" => [74, 105, 'mm'],
48 "A6" => [105, 148, 'mm'],
49 "A5" => [148, 210, 'mm'],
50 "A4" => [210, 297, 'mm'],
51 "A3" => [297, 420, 'mm'],
52 "A2" => [420, 594, 'mm'],
53 "A1" => [594, 841, 'mm'],
54 "A0" => [841, 1189, 'mm'],
55 "B10" => [32, 45, 'mm'],
56 "B9" => [45, 64, 'mm'],
57 "B8" => [64, 91, 'mm'],
58 "B7" => [91, 128, 'mm'],
59 "B6" => [128, 182, 'mm'],
60 "B5" => [182, 257, 'mm'],
61 "B4" => [257, 364, 'mm'],
62 "B3" => [364, 515, 'mm'],
63 "B2" => [515, 728, 'mm'],
64 "B1" => [728, 1030, 'mm'],
65 "B0" => [1030, 1456, 'mm']);
66  
67 0 my $width = $paperdef{$papersize}[0];
68 0 my $height = $paperdef{$papersize}[1];
69 0 my $unit = $paperdef{$papersize}[2];
70 0 my $w = ($width * $magnification / 100) . $unit;
71 0 my $h = ($height * $magnification / 100) . $unit;
72 0 my $vb_w = $width * $resolution;
73 0 my $vb_h = $height * $resolution;
74 0 ▶ if ($unit eq 'mm') {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq "mm") 0 0 0
75 0 $vb_w = int($vb_w / 25.4);
76 0 $vb_h = int($vb_h / 25.4);
77 }
78  
79 0 ▶ if ($orientation eq "Landscape") { # Landscape
Branch: 1 branch
BranchTrueFalseTotal
if ($orientation eq 'Landscape') { } 0 0 0
80 0 return "width=\"$h\" height=\"$w\" viewBox=\"0 0 $vb_h $vb_w\"";
81 } else { # Portrait
82 0 return "width=\"$w\" height=\"$h\" viewBox=\"0 0 $vb_w $vb_h\"";
83 }
84 }
85  
86 # converts FIG pen and fill colors into SVG value: #rrggbb
87 0 ▶sub pen_fill_colors_to_rgb {
Subroutine pen_fill_colors_to_rgb: not called CC=4 SCAR=30.0
88 0 my ($color, $colors) = @_;
89 0 my %table =
90 (-1 => "#000000", # Default
91 0 => "#000000", # Black
92 1 => "#0000ff", # Blue
93 2 => "#00ff00", # Green
94 3 => "#00ffff", # Cyan
95 4 => "#ff0000", # Red
96 5 => "#ff00ff", # Magenta
97 6 => "#ffff00", # Yellow
98 7 => "#ffffff", # White
99 8 => "#000090", # Blue4
100 9 => "#0000b0", # Blue3
101 10 => "#0000d0", # Blue2
102 11 => "#87ceff", # LtBlue
103 12 => "#009000", # Green4
104 13 => "#00b000", # Green3
105 14 => "#00d000", # Green2
106 15 => "#009090", # Cyan4
107 16 => "#00b0b0", # Cyan3
108 17 => "#00d0d0", # Cyan2
109 18 => "#900000", # Red4
110 19 => "#b00000", # Red3
111 20 => "#d00000", # Red2
112 21 => "#900090", # Magenta4
113 22 => "#b000b0", # Magenta3
114 23 => "#d000d0", # Magenta2
115 24 => "#803000", # Brown4
116 25 => "#a04000", # Brown3
117 26 => "#c06000", # Brown2
118 27 => "#ff8080", # Pink4
119 28 => "#ffa0a0", # Pink3
120 29 => "#ffc0c0", # Pink2
121 30 => "#ffe0e0", # Pink
122 31 => "#ffd700"); # Gold
123  
124 0 ▶ if ($color >= 32) { # user colors
Branch: 1 branch
BranchTrueFalseTotal
if ($color >= 32) { } 0 0 0
125 0 for (0 .. scalar(@$colors)-1) {
126 0 ▶ if (@$colors[$_]->{color_number} == $color) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$colors[$_]->{"color_number"} == $color) 0 0 0
127 0 return @$colors[$_]->{rgb};
128 }
129 }
130 } else {
131 0 return $table{$color};
132 }
133 }
134  
135 # converts FIG area fill into SVG style: fill
136 0 ▶sub area_fill_to_fill {
Subroutine area_fill_to_fill: not called CC=32 SCAR=69.6
137 0 my ($area_fill, $color, $colors) = @_;
138  
139 0 ▶ if ($color == 7) { # White
Branch: 2 branches
BranchTrueFalseTotal
if ($color == 7) { } 0 0 0
elsif ($color == 0 or $color == -1) { } 0 0 0
140 0 ▶ if ($area_fill == -1) { # not filled
Branch: 6 branches
BranchTrueFalseTotal
if ($area_fill == -1) { } 0 0 0
elsif ($area_fill == 0) { } 0 0 0
elsif ($area_fill >= 1 and $area_fill <= 19) { } 0 0 0
elsif ($area_fill == 20) { } 0 0 0
elsif ($area_fill >= 21 and $area_fill <= 40) { } 0 0 0
elsif ($area_fill >= 41 and $area_fill <= 56) { } 0 0 0
141 0 return "fill: none";
142 } elsif ($area_fill == 0) { # black
143 0 return "fill: #000000";
144 ▶ } elsif (($area_fill >= 1) && ($area_fill <= 19)) { # shades
Condition0%0/3
$area_fill >= 1 and $area_fill <= 19
!ll&&!rl&&r
000
MC/DC0%0/2
$area_fill >= 1 and $area_fill <= 19
$area_fill >= 1 $area_fill <= 19
Truth table0%0/3
A and B
A= $area_fill >= 1B= $area_fill <= 19
ABresult
0X0
100
111
145 0 my $c = int((255/20)*$area_fill);
146 0 $c = sprintf "%02x", $c;
147 0 return "fill: #" . $c . $c . $c;
148 } elsif ($area_fill == 20) { # white
149 0 return "fill: #ffffff";
150 ▶ } elsif (($area_fill >= 21) && ($area_fill <= 40)) { # not used
Condition0%0/3
$area_fill >= 21 and $area_fill <= 40
!ll&&!rl&&r
000
MC/DC0%0/2
$area_fill >= 21 and $area_fill <= 40
$area_fill >= 21 $area_fill <= 40
Truth table0%0/3
A and B
A= $area_fill >= 21B= $area_fill <= 40
ABresult
0X0
100
111
151 0 return "fill: none";
152 ▶ } elsif (($area_fill >= 41) && ($area_fill <= 56)) { # patterns
Condition0%0/3
$area_fill >= 41 and $area_fill <= 56
!ll&&!rl&&r
000
MC/DC0%0/2
$area_fill >= 41 and $area_fill <= 56
$area_fill >= 41 $area_fill <= 56
Truth table0%0/3
A and B
A= $area_fill >= 41B= $area_fill <= 56
ABresult
0X0
100
111
153 0 return "fill: #ffffff";
154 }
155  
156 ▶ } elsif (($color == 0) || ($color == -1)) { # Black or Default
Condition0%0/3
$color == 0 or $color == -1
l!l&&r!l&&!r
000
MC/DC0%0/2
$color == 0 or $color == -1
$color == 0 $color == -1
Truth table0%0/3
A or B
A= $color == 0B= $color == -1
ABresult
1X1
011
000
157 0 ▶ if ($area_fill == -1) { # not filled
Branch: 6 branches
BranchTrueFalseTotal
if ($area_fill == -1) { } 0 0 0
elsif ($area_fill == 0) { } 0 0 0
elsif ($area_fill >= 1 and $area_fill <= 19) { } 0 0 0
elsif ($area_fill == 20) { } 0 0 0
elsif ($area_fill >= 21 and $area_fill <= 40) { } 0 0 0
elsif ($area_fill >= 41 and $area_fill <= 56) { } 0 0 0
158 0 return "fill: none";
159 } elsif ($area_fill == 0) { # white
160 0 return "fill: #ffffff";
161 ▶ } elsif (($area_fill >= 1) && ($area_fill <= 19)) { # shades
Condition0%0/3
$area_fill >= 1 and $area_fill <= 19
!ll&&!rl&&r
000
MC/DC0%0/2
$area_fill >= 1 and $area_fill <= 19
$area_fill >= 1 $area_fill <= 19
Truth table0%0/3
A and B
A= $area_fill >= 1B= $area_fill <= 19
ABresult
0X0
100
111
162 0 my $c = int((-255/20)*$area_fill + 255);
163 0 $c = sprintf "%02x", $c;
164 0 return "fill: #" . $c . $c . $c;
165 } elsif ($area_fill == 20) { # black
166 0 return "fill: #000000";
167 ▶ } elsif (($area_fill >= 21) && ($area_fill <= 40)) { # not used
Condition0%0/3
$area_fill >= 21 and $area_fill <= 40
!ll&&!rl&&r
000
MC/DC0%0/2
$area_fill >= 21 and $area_fill <= 40
$area_fill >= 21 $area_fill <= 40
Truth table0%0/3
A and B
A= $area_fill >= 21B= $area_fill <= 40
ABresult
0X0
100
111
168 0 return "fill: none";
169 ▶ } elsif (($area_fill >= 41) && ($area_fill <= 56)) { # patterns
Condition0%0/3
$area_fill >= 41 and $area_fill <= 56
!ll&&!rl&&r
000
MC/DC0%0/2
$area_fill >= 41 and $area_fill <= 56
$area_fill >= 41 $area_fill <= 56
Truth table0%0/3
A and B
A= $area_fill >= 41B= $area_fill <= 56
ABresult
0X0
100
111
170 0 return "fill: #000000";
171 }
172  
173 } else { # other colors
174 0 ▶ if ($area_fill == -1) { # not filled
Branch: 7 branches
BranchTrueFalseTotal
if ($area_fill == -1) { } 0 0 0
elsif ($area_fill == 0) { } 0 0 0
elsif ($area_fill >= 1 and $area_fill <= 19) { } 0 0 0
elsif ($area_fill == 20) { } 0 0 0
elsif ($area_fill >= 21 and $area_fill <= 39) { } 0 0 0
elsif ($area_fill == 40) { } 0 0 0
elsif ($area_fill >= 41 and $area_fill <= 56) { } 0 0 0
175 0 return "fill: none";
176 } elsif ($area_fill == 0) { # black
177 0 return "fill: #000000";
178 ▶ } elsif (($area_fill >= 1) && ($area_fill <= 19)) { # shades
Condition0%0/3
$area_fill >= 1 and $area_fill <= 19
!ll&&!rl&&r
000
MC/DC0%0/2
$area_fill >= 1 and $area_fill <= 19
$area_fill >= 1 $area_fill <= 19
Truth table0%0/3
A and B
A= $area_fill >= 1B= $area_fill <= 19
ABresult
0X0
100
111
179 0 my $c = pen_fill_colors_to_rgb($color, $colors);
180 0 my $r = hex(substr($c, 1, 2));
181 0 my $g = hex(substr($c, 3, 2));
182 0 my $b = hex(substr($c, 5, 2));
183 0 $r = int(($r/20)*$area_fill);
184 0 $g = int(($g/20)*$area_fill);
185 0 $b = int(($b/20)*$area_fill);
186 0 $r = sprintf "%02x", $r;
187 0 $g = sprintf "%02x", $g;
188 0 $b = sprintf "%02x", $b;
189 0 return "fill: #" . $r . $g . $b;
190 } elsif ($area_fill == 20) { # full saturation
191 0 return "fill: " . pen_fill_colors_to_rgb($color, $colors);
192 ▶ } elsif (($area_fill >= 21) && ($area_fill <= 39)) { # tints
Condition0%0/3
$area_fill >= 21 and $area_fill <= 39
!ll&&!rl&&r
000
MC/DC0%0/2
$area_fill >= 21 and $area_fill <= 39
$area_fill >= 21 $area_fill <= 39
Truth table0%0/3
A and B
A= $area_fill >= 21B= $area_fill <= 39
ABresult
0X0
100
111
193 0 my $c = pen_fill_colors_to_rgb($color, $colors);
194 0 my $r = hex(substr($c, 1, 2));
195 0 my $g = hex(substr($c, 3, 2));
196 0 my $b = hex(substr($c, 5, 2));
197 0 $r = int(((255-$r)/20)*$area_fill + (2*$r - 255));
198 0 $g = int(((255-$g)/20)*$area_fill + (2*$g - 255));
199 0 $b = int(((255-$b)/20)*$area_fill + (2*$b - 255));
200 0 $r = sprintf "%02x", $r;
201 0 $g = sprintf "%02x", $g;
202 0 $b = sprintf "%02x", $b;
203 0 return "fill: #" . $r . $g . $b;
204 } elsif ($area_fill == 40) { # white
205 0 return "fill: #ffffff";
206 ▶ } elsif (($area_fill >= 41) && ($area_fill <= 56)) { # patterns
Condition0%0/3
$area_fill >= 41 and $area_fill <= 56
!ll&&!rl&&r
000
MC/DC0%0/2
$area_fill >= 41 and $area_fill <= 56
$area_fill >= 41 $area_fill <= 56
Truth table0%0/3
A and B
A= $area_fill >= 41B= $area_fill <= 56
ABresult
0X0
100
111
207 0 return "fill: " . pen_fill_colors_to_rgb($color, $colors);
208 }
209 }
210 }
211  
212 # converts FIG line styles into SVG styles: stroke, stroke-dasharray
213 0 ▶sub line_style_to_stroke {
Subroutine line_style_to_stroke: not called CC=8 SCAR=42.8
214 0 my ($line_style, $style_val, $color, $colors) = @_;
215 0 ▶ if ($line_style == -1) {
Branch: 7 branches
BranchTrueFalseTotal
if ($line_style == -1) { } 0 0 0
elsif ($line_style == 0) { } 0 0 0
elsif ($line_style == 1) { } 0 0 0
elsif ($line_style == 2) { } 0 0 0
elsif ($line_style == 3) { } 0 0 0
elsif ($line_style == 4) { } 0 0 0
elsif ($line_style == 5) { } 0 0 0
216 0 return "stroke: black";
217  
218 } elsif ($line_style == 0) {
219 0 return "stroke: " . pen_fill_colors_to_rgb($color, $colors);
220  
221 } elsif ($line_style == 1) {
222 return
223 0 "stroke: " .
224 pen_fill_colors_to_rgb($color, $colors) .
225 "; " .
226 "stroke-dasharray: " .
227 thickness_to_value($style_val) . ", " .
228 thickness_to_value($style_val) . "; ";
229  
230 } elsif ($line_style == 2) {
231 return
232 0 "stroke: " .
233 pen_fill_colors_to_rgb($color, $colors) .
234 "; " .
235 "stroke-dasharray: " .
236 1 . ", " .
237 thickness_to_value($style_val) . "; ";
238  
239 } elsif ($line_style == 3) {
240 return
241 0 "stroke: " .
242 pen_fill_colors_to_rgb($color, $colors) .
243 "; " .
244 "stroke-dasharray: " .
245 thickness_to_value($style_val) . ", " .
246 thickness_to_value($style_val) / 2 . ", " .
247 1 . ", " .
248 thickness_to_value($style_val) / 2 . "; ";
249  
250 } elsif ($line_style == 4) {
251 return
252 0 "stroke: " .
253 pen_fill_colors_to_rgb($color, $colors) .
254 "; " .
255 "stroke-dasharray: " .
256 thickness_to_value($style_val) . ", " .
257 thickness_to_value($style_val) / 2 . ", " .
258 1 . ", " .
259 thickness_to_value($style_val) / 2 . ", " .
260 1 . ", " .
261 thickness_to_value($style_val) / 2 . "; ";
262  
263 } elsif ($line_style == 5) {
264 return
265 0 "stroke: " .
266 pen_fill_colors_to_rgb($color, $colors) .
267 "; " .
268 "stroke-dasharray: " .
269 thickness_to_value($style_val) . ", " .
270 thickness_to_value($style_val) / 2 . ", " .
271 1 . ", " .
272 thickness_to_value($style_val) / 2 . ", " .
273 1 . ", " .
274 thickness_to_value($style_val) / 2 . ", " .
275 1 . ", " .
276 thickness_to_value($style_val) / 2 . "; ";
277 }
278 }
279  
280 # converts FIG thickness into SVG value
281 0 ▶sub thickness_to_value {
Subroutine thickness_to_value: not called CC=1 SCAR=6.9
282 0 my ($thickness) = @_;
283 0 return $thickness * 15;
284 }
285  
286 # converts FIG line thickness into SVG style: stroke-width
287 0 ▶sub thickness_to_stroke {
Subroutine thickness_to_stroke: not called CC=1 SCAR=6.9
288 0 my ($thickness) = @_;
289 return
290 0 "stroke-width: " .
291 thickness_to_value($thickness);
292 }
293  
294 # converts FIG join_style into SVG style: stroke-linejoin
295 0 ▶sub join_style_to_linejoin {
Subroutine join_style_to_linejoin: not called CC=4 SCAR=30.0
296 0 my ($join_style) = @_;
297 0 ▶ if ($join_style == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($join_style == 0) { } 0 0 0
elsif ($join_style == 1) { } 0 0 0
elsif ($join_style == 2) { } 0 0 0
298 0 return "stroke-linejoin: miter";
299 } elsif ($join_style == 1) {
300 0 return "stroke-linejoin: round";
301 } elsif ($join_style == 2) {
302 0 return "stroke-linejoin: bevel";
303 }
304 }
305  
306 # converts FIG cap_style into SVG style: stroke-linecap
307 0 ▶sub cap_style_to_linecap {
Subroutine cap_style_to_linecap: not called CC=4 SCAR=30.0
308 0 my ($cap_style) = @_;
309 0 ▶ if ($cap_style == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($cap_style == 0) { } 0 0 0
elsif ($cap_style == 1) { } 0 0 0
elsif ($cap_style == 2) { } 0 0 0
310 0 return "stroke-linecap: butt";
311 } elsif ($cap_style == 1) {
312 0 return "stroke-linecap: round";
313 } elsif ($cap_style == 2) {
314 0 return "stroke-linecap: square";
315 }
316 }
317  
318 # converts rad into deg
319 0 ▶sub rad_to_deg {
Subroutine rad_to_deg: not called CC=1 SCAR=6.9
320 0 my ($rad) = @_;
321 0 return -1 * (180 / 3.14) * $rad;
322 }
323  
324 # converts FIG arrows into SVG markers+paths
325 0 ▶sub arrows_to_markers {
Subroutine arrows_to_markers: not called CC=12 SCAR=50.5
326 0 my ($arrow_name,
327 $direction,
328 $orientation,
329 $arrow_type,
330 $arrow_style,
331 $arrow_thickness,
332 $arrow_width,
333 $arrow_height,
334 $pen_color,
335 $colors) = @_;
336  
337 0 my $width = int($arrow_height);
338 0 my $height = int($arrow_width);
339  
340 0 my $thick = thickness_to_value($arrow_thickness);
341  
342 0 my $id = "id=\"$arrow_name";
343 0 $id .= "\"";
344  
345 0 my $markerUnits = "markerUnits=\"userSpaceOnUse\"";
346 0 my $orient = "orient=\"" . $orientation . "\"";
347  
348 0 my $markerWidth = "markerWidth=\"" . ($width+2*$thick) . "\"";
349 0 my $markerHeight = "markerHeight=\"" . ($height+2*$thick) . "\"";
350  
351 0 my $refX = "";
352 0 my $refY = "";
353  
354 0 ▶ if ($direction == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($direction == 1) { } 0 0 0
355 0 $refX = "refX=\"" . ($thick+$width) . "\"";
356 } else {
357 0 $refX = "refX=\"" . $thick . "\"";
358 }
359  
360 0 $refY = "refY=\"" . ($thick+$height/2) . "\"";
361  
362 0 my $marker =
363 "<marker $id " .
364 "$markerUnits " .
365 "$orient " .
366 "$markerWidth " . "$markerHeight " .
367 "$refX " . "$refY " . ">\n";
368  
369 # converts FIG arrows into SVG paths
370  
371 0 my $d = "d=\"";
372 0 my $style = "style=\"";
373  
374 0 $style .=
375 "stroke: " . pen_fill_colors_to_rgb($pen_color, $colors) .
376 "; " .
377 thickness_to_stroke($arrow_thickness) . "; ";
378  
379 0 ▶ if ($arrow_type == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($arrow_type == 0) { } 0 0 0
elsif ($arrow_type == 1) { } 0 0 0
elsif ($arrow_type == 2) { } 0 0 0
elsif ($arrow_type == 3) { } 0 0 0
380 0 ▶ if ($direction == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($direction == 1) { } 0 0 0
381 0 $d .=
382 "M " . $thick . " " . ($thick+$height) . ", " .
383 "L " . ($thick+$width) . " " . int($thick+$height/2) . ", " .
384 "L " . $thick . " " . $thick;
385 } else {
386 0 $d .=
387 "M " . ($thick+$width) . " " . $thick . ", " .
388 "L " . $thick . " " . int($thick+$height/2) . ", " .
389 "L " . ($thick+$width) . " " . ($thick+$height);
390 }
391  
392 } elsif($arrow_type == 1) {
393 0 ▶ if ($direction == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($direction == 1) { } 0 0 0
394 0 $d .=
395 "M " . $thick . " " . ($thick+$height) . ", " .
396 "L " . ($width+$thick) . " " . int($thick+$height/2) . ", " .
397 "L " . $thick . " " . $thick . ", " .
398 "Z";
399 } else {
400 0 $d .=
401 "M " . ($thick+$width) . " " . $thick . ", " .
402 "L " . $thick . " " . int($thick+$height/2) . ", " .
403 "L " . ($thick+$width) . " " . ($thick+$height) . ", " .
404 "Z";
405 }
406  
407 } elsif($arrow_type == 2) {
408 0 ▶ if ($direction == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($direction == 1) { } 0 0 0
409 0 $d .=
410 "M " . $thick . " " . ($thick+$height) . ", " .
411 "L " . int($width+$thick) . " " . int($thick+$height/2) . ", " .
412 "L " . $thick . " " . $thick . ", " .
413 "L " . ($thick+$width/3) . " " . ($thick+$height/2) . ", " .
414 "Z";
415 } else {
416 0 $d .=
417 "M " . ($thick+$width) . " " . $thick . ", " .
418 "L " . $thick . " " . int($thick + $height/2) . ", " .
419 "L " . ($thick+$width) . " " . ($thick+$height) . ", " .
420 "L " . int($thick+2*$width/3) . " " . int($thick+$height/2) . ", " .
421 "Z";
422 }
423  
424 } elsif($arrow_type == 3) {
425 0 ▶ if ($direction == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($direction == 1) { } 0 0 0
426 0 $d .=
427 "M " . int($thick+$width/3) . " " . ($thick+$height) . ", " .
428 "L " . int($width+$thick) . " " . int($thick+$height/2) . ", " .
429 "L " . int($thick+$width/3) . " " . $thick . ", " .
430 "L " . $thick . " " . int($thick+$height/2) . ", " .
431 "Z";
432 } else {
433 0 $d .=
434 "M " . int($thick+2*$width/3) . " " . $thick . ", " .
435 "L " . $thick . " " . int($thick+$height/2) . ", " .
436 "L " . int($thick+2*$width/3) . " " . ($thick+$height) . ", " .
437 "L " . ($thick+$width) . " " . int($thick+$height/2) . ", " .
438 "Z";
439 }
440 }
441  
442 # fills arrow with pen color
443 0 ▶ if ($arrow_type == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arrow_type == 0) { } 0 0 0
444 0 $style .= "fill: none";
445 } else {
446 0 ▶ if ($arrow_style == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arrow_style == 0) { } 0 0 0
447 0 $style .= "fill: white";
448 } else {
449 0 $style .=
450 "fill: " .
451 pen_fill_colors_to_rgb($pen_color, $colors);
452 }
453 }
454  
455 0 $d .= "\"";
456 0 $style .= "\"";
457  
458 0 $marker .= "\t<path $d $style />\n";
459  
460 0 $marker .= "</marker>\n";
461  
462 0 return $marker;
463 }
464  
465 # converts FIG font into SVG styles
466 0 ▶sub font_flags_to_font {
Subroutine font_flags_to_font: not called CC=42 SCAR=75.0
467 0 my ($font_flags, $font) = @_;
468  
469 0 my %postscript_fonts =
470 (0 => "serif",
471 1 => "serif",
472 2 => "serif",
473 3 => "serif",
474 4 => "'Avant Garde'",
475 5 => "'Avant Garde'",
476 6 => "'Avant Garde'",
477 7 => "'Avant Garde'",
478 8 => "Bookman",
479 9 => "Bookman",
480 10 => "Bookman",
481 11 => "Bookman",
482 12 => "monospace",
483 13 => "monospace",
484 14 => "monospace",
485 15 => "monospace",
486 16 => "sans-serif",
487 17 => "sans-serif",
488 18 => "sans-serif",
489 19 => "sans-serif",
490 20 => "sans-serif",
491 21 => "sans-serif",
492 22 => "sans-serif",
493 23 => "sans-serif",
494 24 => "'new century schoolbook'",
495 25 => "'new century schoolbook'",
496 26 => "'new century schoolbook'",
497 27 => "'new century schoolbook'",
498 28 => "Palatino",
499 29 => "Palatino",
500 30 => "Palatino",
501 31 => "Palatino",
502 32 => "Symbol",
503 33 => "cursive",
504 34 => "cursive");
505  
506 0 my $font_flags_bit0 = $font_flags % 2;
507 0 my $font_flags_bit1 = int($font_flags/2) % 2;
508 0 my $font_flags_bit2 = int($font_flags/(2*2)) % 2;
509 0 my $font_flags_bit3 = int($font_flags/(2*2*2)) % 2;
510  
511 0 my $svg_font = "";
512  
513 0 ▶ if ($font_flags_bit2 == 0) { # LaTeX fonts
Branch: 1 branch
BranchTrueFalseTotal
if ($font_flags_bit2 == 0) { } 0 0 0
514  
515 0 ▶ if ($font == 1) {
Branch: 5 branches
BranchTrueFalseTotal
if ($font == 1) { } 0 0 0
elsif ($font == 2) { } 0 0 0
elsif ($font == 3) { } 0 0 0
elsif ($font == 4) { } 0 0 0
elsif ($font == 5) { } 0 0 0
516 0 $svg_font = "font-family: serif; ";
517 } elsif ($font == 2) {
518 0 $svg_font .= "font-weight: bold";
519 } elsif ($font == 3) {
520 0 $svg_font .= "font-style: italic";
521 } elsif ($font == 4) {
522 0 $svg_font .= "font-family: sans-serif";
523 } elsif ($font == 5) {
524 0 $svg_font .= "font-family: monospace";
525 }
526  
527  
528 } else { # PostScript fonts
529  
530 0 ▶ if (($font >= 1) && ($font <= 34)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($font >= 1 and $font <= 34) 0 0 0
Condition0%0/3
$font >= 1 and $font <= 34
!ll&&!rl&&r
000
MC/DC0%0/2
$font >= 1 and $font <= 34
$font >= 1 $font <= 34
Truth table0%0/3
A and B
A= $font >= 1B= $font <= 34
ABresult
0X0
100
111
531 0 $svg_font = "font-family: " . $postscript_fonts{$font} . "; ";
532 }
533  
534 # Italic
535 0 ▶ if (($font == 1) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($font == 1 or $font == 3 or $font == 9 or $font == 11 or $font == 25 or $font == 27 or $font == 29 or $font == 31 or $font == 33) 0 0 0
Condition0%0/24
$font == 1 or $font == 3 or $font == 9 or $font == 11 or $font == 25 or $font == 27 or $font == 29 or $font == 31 or $font == 33
l!l&&r!l&&!r
000
$font == 1 or $font == 3 or $font == 9 or $font == 11 or $font == 25 or $font == 27 or $font == 29 or $font == 31
l!l&&r!l&&!r
000
$font == 1 or $font == 3 or $font == 9 or $font == 11 or $font == 25 or $font == 27 or $font == 29
l!l&&r!l&&!r
000
$font == 1 or $font == 3 or $font == 9 or $font == 11 or $font == 25 or $font == 27
l!l&&r!l&&!r
000
$font == 1 or $font == 3 or $font == 9 or $font == 11 or $font == 25
l!l&&r!l&&!r
000
$font == 1 or $font == 3 or $font == 9 or $font == 11
l!l&&r!l&&!r
000
$font == 1 or $font == 3 or $font == 9
l!l&&r!l&&!r
000
$font == 1 or $font == 3
l!l&&r!l&&!r
000
MC/DC0%0/9
$font == 1 or $font == 3 or $font == 9 or $font == 11 or $font == 25 or $font == 27 or $font == 29 or $font == 31 or $font == 33
$font == 1 $font == 3 $font == 9 $font == 11 $font == 25 $font == 27 $font == 29 $font == 31 $font == 33
Truth table0%0/10
A or B or C or D or E or F or G or H or I
A= $font == 1B= $font == 3C= $font == 9D= $font == 11E= $font == 25F= $font == 27G= $font == 29H= $font == 31I= $font == 33
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
536 ($font == 3) ||
537 ($font == 9) ||
538 ($font == 11) ||
539 ($font == 25) ||
540 ($font == 27) ||
541 ($font == 29) ||
542 ($font == 31) ||
543 ($font == 33)) {
544 0 $svg_font .= "font-style: italic; ";
545 }
546  
547 # Bold
548 0 ▶ if (($font == 2) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18 or $font == 19 or $font == 22 or $font == 23 or $font == 26 or $font == 27 or $font == 30 or $font == 31) 0 0 0
Condition0%0/33
$font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18 or $font == 19 or $font == 22 or $font == 23 or $font == 26 or $font == 27 or $font == 30 or $font == 31
l!l&&r!l&&!r
000
$font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18 or $font == 19 or $font == 22 or $font == 23 or $font == 26 or $font == 27 or $font == 30
l!l&&r!l&&!r
000
$font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18 or $font == 19 or $font == 22 or $font == 23 or $font == 26 or $font == 27
l!l&&r!l&&!r
000
$font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18 or $font == 19 or $font == 22 or $font == 23 or $font == 26
l!l&&r!l&&!r
000
$font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18 or $font == 19 or $font == 22 or $font == 23
l!l&&r!l&&!r
000
$font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18 or $font == 19 or $font == 22
l!l&&r!l&&!r
000
$font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18 or $font == 19
l!l&&r!l&&!r
000
$font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18
l!l&&r!l&&!r
000
$font == 2 or $font == 3 or $font == 14 or $font == 15
l!l&&r!l&&!r
000
$font == 2 or $font == 3 or $font == 14
l!l&&r!l&&!r
000
$font == 2 or $font == 3
l!l&&r!l&&!r
000
MC/DC0%0/12
$font == 2 or $font == 3 or $font == 14 or $font == 15 or $font == 18 or $font == 19 or $font == 22 or $font == 23 or $font == 26 or $font == 27 or $font == 30 or $font == 31
$font == 2 $font == 3 $font == 14 $font == 15 $font == 18 $font == 19 $font == 22 $font == 23 $font == 26 $font == 27 $font == 30 $font == 31
Truth table0%0/13
A or B or C or D or E or F or G or H or I or J or K or L
A= $font == 2B= $font == 3C= $font == 14D= $font == 15E= $font == 18F= $font == 19G= $font == 22H= $font == 23I= $font == 26J= $font == 27K= $font == 30L= $font == 31
ABCDEFGHIJKLresult
1XXXXXXXXXXX1
01XXXXXXXXXX1
001XXXXXXXXX1
0001XXXXXXXX1
00001XXXXXXX1
000001XXXXXX1
0000001XXXXX1
00000001XXXX1
000000001XXX1
0000000001XX1
00000000001X1
0000000000011
0000000000000
549 ($font == 3) ||
550 ($font == 14) ||
551 ($font == 15) ||
552 ($font == 18) ||
553 ($font == 19) ||
554 ($font == 22) ||
555 ($font == 23) ||
556 ($font == 26) ||
557 ($font == 27) ||
558 ($font == 30) ||
559 ($font == 31)) {
560 0 $svg_font .= "font-weight: bold; ";
561 }
562  
563 # Oblique
564 0 ▶ if (($font == 5) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($font == 5 or $font == 7 or $font == 13 or $font == 15 or $font == 17 or $font == 19 or $font == 21 or $font == 23) 0 0 0
Condition0%0/21
$font == 5 or $font == 7 or $font == 13 or $font == 15 or $font == 17 or $font == 19 or $font == 21 or $font == 23
l!l&&r!l&&!r
000
$font == 5 or $font == 7 or $font == 13 or $font == 15 or $font == 17 or $font == 19 or $font == 21
l!l&&r!l&&!r
000
$font == 5 or $font == 7 or $font == 13 or $font == 15 or $font == 17 or $font == 19
l!l&&r!l&&!r
000
$font == 5 or $font == 7 or $font == 13 or $font == 15 or $font == 17
l!l&&r!l&&!r
000
$font == 5 or $font == 7 or $font == 13 or $font == 15
l!l&&r!l&&!r
000
$font == 5 or $font == 7 or $font == 13
l!l&&r!l&&!r
000
$font == 5 or $font == 7
l!l&&r!l&&!r
000
MC/DC0%0/8
$font == 5 or $font == 7 or $font == 13 or $font == 15 or $font == 17 or $font == 19 or $font == 21 or $font == 23
$font == 5 $font == 7 $font == 13 $font == 15 $font == 17 $font == 19 $font == 21 $font == 23
Truth table0%0/9
A or B or C or D or E or F or G or H
A= $font == 5B= $font == 7C= $font == 13D= $font == 15E= $font == 17F= $font == 19G= $font == 21H= $font == 23
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
565 ($font == 7) ||
566 ($font == 13) ||
567 ($font == 15) ||
568 ($font == 17) ||
569 ($font == 19) ||
570 ($font == 21) ||
571 ($font == 23)) {
572 0 $svg_font .= "font-style: oblique; ";
573 }
574  
575 # Narrow
576 0 ▶ if (($font == 20) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($font == 20 or $font == 21 or $font == 22 or $font == 23) 0 0 0
Condition0%0/9
$font == 20 or $font == 21 or $font == 22 or $font == 23
l!l&&r!l&&!r
000
$font == 20 or $font == 21 or $font == 22
l!l&&r!l&&!r
000
$font == 20 or $font == 21
l!l&&r!l&&!r
000
MC/DC0%0/4
$font == 20 or $font == 21 or $font == 22 or $font == 23
$font == 20 $font == 21 $font == 22 $font == 23
Truth table0%0/5
A or B or C or D
A= $font == 20B= $font == 21C= $font == 22D= $font == 23
ABCDresult
1XXX1
01XX1
001X1
00011
00000
577 ($font == 21) ||
578 ($font == 22) ||
579 ($font == 23)) {
580 0 $svg_font .= "font-stretch: narrower; ";
581 }
582 }
583  
584 0 return $svg_font;
585 }
586  
587  
588 # return
589 1 1;
« FigAnim.pm ↑ Summary FigAnim/Polyline.pm »