blib/lib/PostScript/EPSF.pm

filter: Statementstmt 82.7% 96 / 116 Branchbran 66.1% 41 / 62 Conditioncond 47.6% 20 / 42 MC/DCmcdc 12.5% 3 / 24 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 65.8% 168 / 255 CC 50 SCAR 39.9
CC
50
Cov
71%
include_epsf
67.6
color_to_ps
27.8
epsf_prolog
2.0
CRAP 53.9
↑ Summary
1 package PostScript::EPSF;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 $VERSION = "0.01";
7  
8 1 require Exporter;
9 1 *import = \*Exporter::import;
10  
11 1 @EXPORT=qw(include_epsf);
12 1 @EXPORT_OK=qw(epsf_prolog);
13  
14  
15 sub epsf_prolog
16 2 ▶{
Subroutine epsf_prolog: called CC=2 SCAR=6.9
Pod undocumented
17 1 ▶ use vars qw($EPSF_PROLOG_DONE);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ print <<"EOT" unless $EPSF_PROLOG_DONE++;
Branch: 1 branch
BranchTrueFalseTotal
unless $PostScript::EPSF::EPSF_PROLOG_DONE++ 1 1 2
19  
20 /BeginEPSF {
21 /b4_Inc_state save def
22 /dict_count countdictstack def
23 /op_count count 1 sub def
24 userdict begin
25 /showpage {} def
26 0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin
27 10 setmiterlimit [] 0 setdash newpath
28 /languagelevel where
29 {
30 1 ne {
31 false setstrokeadjust
32 false setoverprint
33 } if
34 } if
35 } bind def
36  
37 /EndEPSF {
38 count op_count sub {pop} repeat
39 countdictstack dict_count sub {end} repeat
40 b4_Inc_state restore
41 } bind def
42  
43 EOT
44 }
45  
46  
47 sub include_epsf
48 2 ▶{
Subroutine include_epsf: called CC=42 SCAR=42.1
Pod undocumented
49 2 my %para;
50 2 ▶ while (my($k,$v) = splice(@_, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 13 2 15
51 13 $k =~ s/^-//;
52 13 $para{$k} = $v;
53 }
54  
55 #use Data::Dumper; print STDERR Dumper(\%para);
56  
57 2 ▶ my $file = delete $para{"file"} ||
Condition50%1/2
delete $para{'file'} || die('Mandatory -file argument is missing')
l!l
20
MC/DC0%0/1
delete $para{'file'} || die('Mandatory -file argument is missing')
delete $para{'file'}
Truth table50%1/2
A
A= delete $para{'file'}
Aresult
11
00
58 die "Mandatory -file argument is missing";
59
60  
61 2 local(*EPS);
62 2 ▶ open(EPS, $file) || die "Can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open EPS, $file or die "Can't open ${file}: $!" 2 0 2
63 2 my($llx, $lly, $urx, $ury);
64 2 my @eps;
65 2 ▶ while (<EPS>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline EPS)) 516 2 518
66 516 ▶ if (/^%%BoundingBox:\s*(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^%%BoundingBox:\s*(.*)/) { } 2 514 516
elsif (/^\s*%/ or /^\s*$/) { } 144 370 514
67 2 ($llx, $lly, $urx, $ury) = split(' ', $1);
68 ▶ } elsif (/^\s*%/ || /^\s*$/) {
Condition100%3/3
/^\s*%/ or /^\s*$/
l!l&&r!l&&!r
42102370
MC/DC100%2/2
/^\s*%/ or /^\s*$/
/^\s*%/ /^\s*$/
Truth table100%3/3
A or B
A= /^\s*%/B= /^\s*$/
ABresult
1X1
011
000
69 # always skip other comments and empty lines
70 } else {
71 370 push(@eps, $_);
72 }
73 }
74 2 close(EPS);
75 2 ▶ die "Missing Bounding box in $file" unless defined $ury;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ury 0 2 2
76  
77  
78  
79 2 my $xscale = delete $para{"xscale"};
80 2 my $yscale = delete $para{"yscale"};
81  
82 # Calculate width/height of included file
83 2 my $w = $urx - $llx;
84 2 my $h = $ury - $lly;
85  
86 2 ▶ if (my $width = delete $para{"width"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $width = delete $para{"width"}) 1 1 2
87 1 $xscale = $width / $w;
88 }
89  
90 2 ▶ if (my $height = delete $para{"height"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $height = delete $para{"height"}) 0 2 2
91 0 $yscale = $height / $h;
92 }
93
94 2 ▶ if (my $scale = delete $para{"scale"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $scale = delete $para{"scale"}) 1 1 2
95 1 for ($xscale, $yscale) {
96 2 ▶ $_ = $scale unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 2 0 2
97 }
98 }
99  
100 2 ▶ $xscale = $yscale if $yscale && !$xscale;
Branch: 1 branch
BranchTrueFalseTotal
if $yscale and not $xscale 0 2 2
Condition66%2/3
$yscale and not $xscale
!ll&&!rl&&r
110
MC/DC0%0/2
$yscale and not $xscale
$yscale not $xscale
Truth table66%2/3
A and not(B)
A= $yscaleB= not $xscale
ABresult
0X0
100
111
101 2 ▶ $yscale = $xscale if $xscale && !$yscale;
Branch: 1 branch
BranchTrueFalseTotal
if $xscale and not $yscale 1 1 2
Condition66%2/3
$xscale and not $yscale
!ll&&!rl&&r
011
MC/DC50%1/2
$xscale and not $yscale
$xscale not $yscale
Truth table66%2/3
A and not(B)
A= $xscaleB= not $yscale
ABresult
0X0
100
111
102  
103 2 ▶ if ($xscale) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xscale) 2 0 2
104 2 $w = $w * $xscale;
105 2 $h = $h * $yscale;
106 }
107  
108 2 ▶ if (my $pos = delete $para{"pos"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pos = delete $para{"pos"}) 2 0 2
109 2 $pos =~ s/^\s*//;
110 2 @para{"x", "y"} = split(/\s*[,\s]\s*/, $pos);
111 }
112 2 ▶ my $x = delete $para{"x"} || 0;
Condition50%1/2
delete $para{'x'} || 0
l!l
20
MC/DC0%0/1
delete $para{'x'} || 0
delete $para{'x'}
Truth table50%1/2
A
A= delete $para{'x'}
Aresult
11
00
113 2 ▶ my $y = delete $para{"y"} || 0;
Condition50%1/2
delete $para{'y'} || 0
l!l
20
MC/DC0%0/1
delete $para{'y'} || 0
delete $para{'y'}
Truth table50%1/2
A
A= delete $para{'y'}
Aresult
11
00
114  
115 2 ▶ my $anchor = delete $para{"anchor"} || "c";
Condition50%1/2
delete $para{'anchor'} || 'c'
l!l
20
MC/DC0%0/1
delete $para{'anchor'} || 'c'
delete $para{'anchor'}
Truth table50%1/2
A
A= delete $para{'anchor'}
Aresult
11
00
116 2 ▶ if ($anchor =~ /w/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($anchor =~ /w/) { } 1 1 2
elsif ($anchor =~ /e/) { } 1 0 1
117 # no need to adjust $x
118 } elsif ($anchor =~ /e/) {
119 1 $x -= $w;
120 } else {
121 0 $x -= $w/2;
122 }
123 2 ▶ if ($anchor =~ /s/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($anchor =~ /s/) { } 0 2 2
elsif ($anchor =~ /n/) { } 1 1 2
124 # no need to adjust $y
125 } elsif ($anchor =~ /n/) {
126 1 $y -= $h;
127 } else {
128 1 $y -= $h/2;
129 }
130  
131 2 my $rotate = delete $para{"rotate"};
132  
133 2 my $clip = delete $para{"clip"};
134 2 my $background = delete $para{"background"};
135 2 ▶ my $boarder = delete $para{"boarder"} || 0;
Condition50%1/2
delete $para{'boarder'} || 0
l!l
02
MC/DC0%0/1
delete $para{'boarder'} || 0
delete $para{'boarder'}
Truth table50%1/2
A
A= delete $para{'boarder'}
Aresult
11
00
136  
137 2 ▶ if ($^W && %para) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^W and %para) 0 2 2
Condition33%1/3
$^W and %para
!ll&&!rl&&r
200
MC/DC0%0/2
$^W and %para
$^W %para
Truth table33%1/3
A and B
A= $^WB= %para
ABresult
0X0
100
111
138 0 for (sort keys %para) {
139 0 warn "Unrecognized parameter: -$_ => $para{$_}\n";
140 }
141 }
142  
143 2 epsf_prolog();
144  
145 2 print "\nBeginEPSF\n";
146 2 ▶ if ($rotate || $xscale || $clip || $background) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rotate or $xscale or $clip or $background) { } 2 0 2
Condition44%4/9
$rotate or $xscale or $clip or $background
l!l&&r!l&&!r
200
$rotate or $xscale or $clip
l!l&&r!l&&!r
200
$rotate or $xscale
l!l&&r!l&&!r
110
MC/DC0%0/4
$rotate or $xscale or $clip or $background
$rotate $xscale $clip $background
Truth table40%2/5
A or B or C or D
A= $rotateB= $xscaleC= $clipD= $background
ABCDresult
1XXX1
01XX1
001X1
00011
00000
147 2 print "$x $y translate\n";
148 2 ▶ print "$rotate rotate\n" if $rotate;
Branch: 1 branch
BranchTrueFalseTotal
if $rotate 1 1 2
149 2 ▶ if ($clip || $background) {
Branch: 1 branch
BranchTrueFalseTotal
if ($clip or $background) 2 0 2
Condition33%1/3
$clip or $background
l!l&&r!l&&!r
200
MC/DC0%0/2
$clip or $background
$clip $background
Truth table33%1/3
A or B
A= $clipB= $background
ABresult
1X1
011
000
150 2 my $llx = 0;
151 2 my $lly = 0;
152 2 my $urx = $w;
153 2 my $ury = $h;
154 2 ▶ if ($boarder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($boarder) 0 2 2
155 0 $llx -= $boarder;
156 0 $lly -= $boarder;
157 0 $urx += $boarder;
158 0 $ury += $boarder;
159 }
160 2 print "$llx $lly moveto $urx $lly lineto\n";
161 2 print "$urx $ury lineto $llx $ury lineto closepath\n";
162 2 ▶ print "clip\n" if $clip;
Branch: 1 branch
BranchTrueFalseTotal
if $clip 2 0 2
163 2 ▶ if ($background) {
Branch: 1 branch
BranchTrueFalseTotal
if ($background) 1 1 2
164 1 print "gsave ", color_to_ps($background), " fill grestore\n";
165 }
166 2 print "newpath\n";
167 }
168 2 ▶ print "$xscale $yscale scale\n" if $xscale;
Branch: 1 branch
BranchTrueFalseTotal
if $xscale 2 0 2
169 2 print 0-$llx, " ", 0-$lly, " translate\n";
170 } else {
171 0 print $x-$llx, " ", $y-$lly, " translate\n";
172 }
173  
174 2 print "%%BeginDocument: $file\n";
175 2 print @eps;
176 2 print "%%EndDocument: $file\n";
177 2 print "EndEPSF\n\n";
178  
179 }
180  
181 BEGIN
182 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
183 1 ▶ use vars qw(%color_names);
Subroutine BEGIN: called CC=1 SCAR=0.0
184 1 %color_names = (
185 black => 0,
186 white => 1,
187  
188 red => "#f00",
189 green => "#0f0",
190 blue => "#00f",
191 yellow => "#ff0",
192 magenta => "#f0f",
193 cyan => "#0ff",
194 );
195 }
196  
197  
198 # should probably go into it's own module
199 sub color_to_ps
200 1 ▶{
Subroutine color_to_ps: called CC=8 SCAR=33.3
Pod undocumented
201 1 ▶ my $color = lc(shift || "");
Condition50%1/2
shift() || ''
l!l
10
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
202 1 $color =~ s/^\s+//;
203 1 $color =~ s/\s+$//;
204  
205 1 ▶ $color = $color_names{$color} || $color;
Condition33%1/3
$PostScript::EPSF::color_names{$color} || $color
l!l&&r!l&&!r
100
MC/DC0%0/2
$PostScript::EPSF::color_names{$color} || $color
$PostScript::EPSF::color_names{$color} $color
Truth table33%1/3
A || B
A= $PostScript::EPSF::color_names{$color}B= $color
ABresult
1X1
011
000
206  
207 1 ▶ if ($color =~ /^\d+(?:\.\d+)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color =~ /^\d+(?:\.\d+)?$/) 1 0 1
208 1 ▶ $color = 1 if $color > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $color > 1 0 1 1
209 1 return sprintf "%.3f setgray", $color;
210 }
211  
212 0 ▶ if ($color =~ /^\#([0-9a-f]+)$/ && (length($1) % 3) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color =~ /^\#([0-9a-f]+)$/ and length($1) % 3 == 0) 0 0 0
Condition0%0/3
$color =~ /^\#([0-9a-f]+)$/ and length($1) % 3 == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$color =~ /^\#([0-9a-f]+)$/ and length($1) % 3 == 0
$color =~ /^\#([0-9a-f]+)$/ length($1) % 3 == 0
Truth table0%0/3
A and B
A= $color =~ /^\#([0-9a-f]+)$/B= length($1) % 3 == 0
ABresult
0X0
100
111
213 0 my $len = int(length($1) / 3);
214 0 my $fff = 2 ** ($len*4) - 1;
215 0 $color = $1;
216 0 my @rgb;
217 0 ▶ while (length $color) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $color) 0 0 0
218 0 push(@rgb, hex(substr($color, 0, $len)) / $fff);
219 0 substr($color, 0, $len) = '';
220 }
221 0 return join(" ", map {sprintf "%.3f", $_} @rgb), " setrgbcolor";
222 }
223  
224 0 return; # did not understand
225 }
226  
227 1 1;
↑ Summary