WMF/Image.pm

filter: Statementstmt 50.8% 240 / 472 Branchbran 40.9% 45 / 110 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 53.7% 43 / 80 Podpod 0.0% 0 / 72 totaltotal 44.3% 330 / 744 CC 58 SCAR 27.0
CC
58
Cov
49%
extTextOut
132.0
createFile
30.0
createFont
12.0
CRAP 14.8
« WMF/Colour.pm ↑ Summary WMF/Polygon.pm »
1 package Image::WMF::Image;
2 # Copyright 2001 Tony Cox. See accompanying README file for
3 # usage information
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Image::WMF::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Image::WMF::Colour;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Image::WMF::Font;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Image::WMF::Rectangle;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Image::WMF::Polygon;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use vars qw($VERSION @ISA @EXPORT $AUTOLOAD $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 $VERSION = "1.00";
13 #$DEBUG = 1;
14  
15 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
16 1 my ($class, $filename) = @_;
17 1 my $obj = bless {
18 _filename => $filename,
19 _handles => [],
20 _word => [],
21 _maxobjectsize => 0,
22 _wmf => '',
23 _header => '',
24 _fhandle => undef,
25 }, $class;
26  
27 1 $obj->_initialise($filename);
28 1 return $obj;
29 }
30  
31 1 ▶sub _initialise {
Subroutine _initialise: called CC=2 SCAR=8.4
32 1 my ($self, $filename) = @_;
33 1 ▶ if (defined $filename){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename) 0 1 1
34 0 $self->{'_filename'} = $filename;
35 0 $self->createFile();
36 }
37 1 $self->escape("PerlWMF, v$VERSION (c) Tony Cox, 2003");
38 }
39  
40 0 ▶sub translateFontName {
Subroutine translateFontName: not called CC=2 SCAR=17.9
Pod undocumented
41 0 my ($self,$fontname) = @_;
42 0 ▶ if (defined $FONTNAME{lc($fontname)}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Image::WMF::Image::FONTNAME{lc $fontname}) { } 0 0 0
43 0 return($FONTNAME{lc($fontname)});
44 } else {
45 0 print STDERR "Unsupported font (\"$fontname\") using Arial\n";
46 0 return ($FONTNAME{'arial'});
47 }
48 }
49  
50 0 ▶sub setTranslateFontNames {
Subroutine setTranslateFontNames: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my ($self) = shift;
52 0 %FONTNAME = @_;
53 }
54  
55 0 ▶sub getTranslateFontNames {
Subroutine getTranslateFontNames: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my ($self) = shift;
57 0 return (\%FONTNAME);
58 }
59  
60 0 ▶sub createFont {
Subroutine createFont: not called CC=3 SCAR=24.8
Pod undocumented
61 0 my ($self,$font,$escapement,$is_underline,$is_strikeout) = @_;
62 0 ▶ unless ($font->isa("Font")){
Branch: 1 branch
BranchTrueFalseTotal
unless ($font->isa("Font")) 0 0 0
63 0 die("Invalid font object in createFont!");
64 }
65 0 my $c = $self->toByte(0x0190);
66 0 ▶ if($font->isBold()){
Branch: 1 branch
BranchTrueFalseTotal
if ($font->isBold) 0 0 0
67 0 my $c = $self->toByte(0x01BC);
68 }
69 0 return($self->createFontIndirect(
70 $font->getSize(),0,$escapement,0,$c, #int
71 $font->isItalic(),$is_underline,$is_strikeout, #bool
72 $self->toByte(0),$self->toByte(0),$self->toByte(0), #byte
73 $self->toByte(0),$self->toByte(0), #byte
74 $self->translateFontName($font->getFace())) #string
75 )
76 }
77
78 1 ▶sub createFontIndirect {
Subroutine createFontIndirect: called CC=8 SCAR=21.1
Pod undocumented
79 1 my ($self,$i,$j,$k,$l,$i1, #int
80 $is_italic,$is_underline,$is_strikeout, #bool
81 $charset,$outprecision,$clipprecision,$quality,$pitchandfamily, #byte
82 $facename) = @_; #string
83 1 $self->metaRecord(763,9 + (length($facename)+2)/2);
84 1 $self->writeWord($i);
85 1 $self->writeWord($j);
86 1 $self->writeWord($k);
87 1 $self->writeWord($l);
88 1 $self->writeWord($i1);
89 1 my $j1 = 0;
90 1 ▶ if($is_italic){
Branch: 1 branch
BranchTrueFalseTotal
if ($is_italic) 0 1 1
91 0 $j1=1;
92 }
93 1 ▶ if($is_underline){
Branch: 1 branch
BranchTrueFalseTotal
if ($is_underline) 0 1 1
94 0 $j1+=256;
95 }
96 1 $self->writeWord($j1);
97 1 $j1 = $charset << 8 & 0xFF00;
98 1 ▶ if($is_strikeout){
Branch: 1 branch
BranchTrueFalseTotal
if ($is_strikeout) 0 1 1
99 0 $j1++;
100 }
101 1 $self->writeWord($j1);
102 1 $self->writeWord($outprecision | $clipprecision << 8 & 0xFF00);
103 1 $self->writeWord($quality | $pitchandfamily << 8 & 0xFF00);
104  
105 1 my @abytes0 = ();
106 1 my @text = split(//,reverse($facename));
107 #print STDERR "Packing string: \"$facename\"\n";
108 1 ▶ while (@text){
Branch: 1 branch
BranchTrueFalseTotal
if (@text) 2 1 3
109 2 my $c = shift(@text);
110 2 $c = $self->toByte($c);
111 2 unshift (@abytes0, $c);
112 }
113 1 unshift (@abytes0, $self->toByte(0)); # add padding byte
114 1 ▶ for (my $k=0;$k < scalar(@abytes0)/2;$k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k < scalar(@abytes0) / 2) 2 1 3
115 2 ▶ if (!defined $abytes0[$k*2+1]){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $abytes0[$k * 2 + 1]) { } 1 1 2
116 1 $self->writeWord($abytes0[$k*2] | $self->toByte(0) << 8 & 0xFF00);
117 } else {
118 1 $self->writeWord($abytes0[$k*2] | $abytes0[$k*2+1] << 8 & 0xFF00);
119 }
120 }
121 1 my $h = $self->addHandle();
122 1 ▶ print STDERR "Added Font handle at stack position: $h\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 1 1
123 1 return($h);
124 }
125  
126 5 ▶sub writeColour {
Subroutine writeColour: called CC=1 SCAR=0.0
Pod undocumented
127 5 my ($self, $c) = @_;
128 5 $self->writeInteger(
129 $c->red() & 0xFF
130 | $c->green() << 8 & 0xFF00
131 | $c->blue() << 16 & 0xFF0000
132 );
133 #print STDERR "Wrote packed RGB colour structure: ";
134 #print STDERR $c->red()," ",$c->green()," ",$c->blue(),"\n";
135 }
136  
137 2 ▶sub createPenIndirect {
Subroutine createPenIndirect: called CC=2 SCAR=7.0
Pod undocumented
138 2 my ($self, $i, $j, $c) = @_;
139 2 $self->metaRecord(762,5);
140 2 $self->writeWord($i);
141 2 $self->writeInteger($j);
142 2 $self->writeColour($c); # need to write a color object
143 2 my $h = $self->addHandle();
144 2 ▶ print STDERR "Added PenIndirect handle at stack position: $h\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 2 2
145 2 return ($h);
146 }
147  
148 2 ▶sub createBrushIndirect {
Subroutine createBrushIndirect: called CC=2 SCAR=7.0
Pod undocumented
149 2 my ($self, $i, $c, $j) = @_;
150 2 $self->metaRecord(764,4);
151 2 $self->writeWord($i);
152 2 $self->writeColour($c); # need to write a color object
153 2 $self->writeWord($j);
154 2 my $h = $self->addHandle();
155 2 ▶ print STDERR "Added BrushIndirect handle at stack position: $h\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 2 2
156 2 return ($h);
157 }
158  
159 0 ▶sub roundRect {
Subroutine roundRect: not called CC=1 SCAR=6.9
Pod undocumented
160 0 my ($self, $i, $j, $k, $l, $m, $n) = @_;
161 0 $self->metaRecord(1564,6);
162 0 $self->writeWord($n);
163 0 $self->writeWord($m);
164 0 $self->writeWord($l);
165 0 $self->writeWord($k);
166 0 $self->writeWord($j);
167 0 $self->writeWord($i);
168 }
169  
170 0 ▶sub pie {
Subroutine pie: not called CC=1 SCAR=6.9
Pod undocumented
171 0 my ($self, $i, $j, $k, $l, $m, $n, $o, $p) = @_;
172 0 $self->metaRecord(2078,8);
173 0 $self->writeWord($p);
174 0 $self->writeWord($o);
175 0 $self->writeWord($n);
176 0 $self->writeWord($m);
177 0 $self->writeWord($l);
178 0 $self->writeWord($k);
179 0 $self->writeWord($j);
180 0 $self->writeWord($i);
181 }
182  
183 0 ▶sub arc {
Subroutine arc: not called CC=1 SCAR=6.9
Pod undocumented
184 0 my ($self, $i, $j, $k, $l, $m, $n, $o, $p) = @_;
185 0 $self->metaRecord(2071,8);
186 0 $self->writeWord($p);
187 0 $self->writeWord($o);
188 0 $self->writeWord($n);
189 0 $self->writeWord($m);
190 0 $self->writeWord($l);
191 0 $self->writeWord($k);
192 0 $self->writeWord($j);
193 0 $self->writeWord($i);
194 }
195  
196 0 ▶sub chord {
Subroutine chord: not called CC=1 SCAR=6.9
Pod undocumented
197 0 my ($self, $i, $j, $k, $l, $m, $n, $o, $p) = @_;
198 0 $self->metaRecord(2096,8);
199 0 $self->writeWord($p);
200 0 $self->writeWord($o);
201 0 $self->writeWord($n);
202 0 $self->writeWord($m);
203 0 $self->writeWord($l);
204 0 $self->writeWord($k);
205 0 $self->writeWord($j);
206 0 $self->writeWord($i);
207 }
208  
209 0 ▶sub ellipse {
Subroutine ellipse: not called CC=1 SCAR=6.9
Pod undocumented
210 0 my ($self, $i, $j, $k, $l) = @_;
211 0 $self->metaRecord(1048,4);
212 0 $self->writeWord($l);
213 0 $self->writeWord($k);
214 0 $self->writeWord($j);
215 0 $self->writeWord($i);
216 }
217  
218 1 ▶sub rectangle {
Subroutine rectangle: called CC=1 SCAR=0.0
Pod undocumented
219 1 my ($self, $i, $j, $k, $l) = @_;
220 1 $self->metaRecord(1051,4);
221 1 $self->writeWord($l);
222 1 $self->writeWord($k);
223 1 $self->writeWord($j);
224 1 $self->writeWord($i);
225 }
226  
227 0 ▶sub setPolyFillMode {
Subroutine setPolyFillMode: not called CC=1 SCAR=6.9
Pod undocumented
228 0 my ($self, $i) = @_;
229 0 $self->metaRecord(262,1);
230 0 $self->writeWord($i);
231 }
232  
233 1 ▶sub setMapMode {
Subroutine setMapMode: called CC=1 SCAR=0.0
Pod undocumented
234 1 my ($self, $i) = @_;
235 1 $self->metaRecord(259,1);
236 1 $self->writeWord($i);
237 }
238  
239 1 ▶sub setROP2 {
Subroutine setROP2: called CC=1 SCAR=0.0
Pod undocumented
240 1 my ($self, $i) = @_;
241 1 $self->metaRecord(260,1);
242 1 $self->writeWord($i);
243 }
244  
245 1 ▶sub setBKMode {
Subroutine setBKMode: called CC=1 SCAR=0.0
Pod undocumented
246 1 my ($self, $i) = @_;
247 1 $self->metaRecord(258,1);
248 1 $self->writeWord($i);
249 }
250  
251 0 ▶sub setBKColour {
Subroutine setBKColour: not called CC=1 SCAR=6.9
Pod undocumented
252 0 my ($self, $c) = @_;
253 0 $self->metaRecord(513,2);
254 0 $self->writeColour($c);
255 }
256  
257 1 ▶sub setTextColour {
Subroutine setTextColour: called CC=1 SCAR=0.0
Pod undocumented
258 1 my ($self, $c) = @_;
259 1 $self->metaRecord(521,2);
260 1 $self->writeColour($c);
261 }
262  
263 1 ▶sub setTextAlign {
Subroutine setTextAlign: called CC=1 SCAR=0.0
Pod undocumented
264 1 my ($self, $i) = @_;
265 1 $self->metaRecord(302,1);
266 1 $self->writeWord($i);
267 }
268  
269 0 ▶sub setTextCharacterExtra {
Subroutine setTextCharacterExtra: not called CC=1 SCAR=6.9
Pod undocumented
270 0 my ($self, $i) = @_;
271 0 $self->metaRecord(264,1);
272 0 $self->writeWord($i);
273 }
274  
275 0 ▶sub setStretchBltMode {
Subroutine setStretchBltMode: not called CC=1 SCAR=6.9
Pod undocumented
276 0 my ($self, $i) = @_;
277 0 $self->metaRecord(263,1);
278 0 $self->writeWord($i);
279 }
280  
281 0 ▶sub setTextJustification {
Subroutine setTextJustification: not called CC=1 SCAR=6.9
Pod undocumented
282 0 my ($self, $i, $j) = @_;
283 0 $self->metaRecord(522,2);
284 0 $self->writeWord($j);
285 0 $self->writeWord($i);
286 }
287  
288 0 ▶sub setPixel {
Subroutine setPixel: not called CC=1 SCAR=6.9
Pod undocumented
289 0 my ($self, $i, $j, $c) = @_;
290 0 $self->metaRecord(1055,4);
291 0 $self->writeColour($c);
292 0 $self->writeWord($j);
293 0 $self->writeWord($i);
294 }
295  
296 0 ▶sub floodFill {
Subroutine floodFill: not called CC=1 SCAR=6.9
Pod undocumented
297 0 my ($self, $i, $j, $c) = @_;
298 0 $self->metaRecord(1049,4);
299 0 $self->writeColour($c);
300 0 $self->writeWord($j);
301 0 $self->writeWord($i);
302 }
303  
304 0 ▶sub extFloodFill {
Subroutine extFloodFill: not called CC=1 SCAR=6.9
Pod undocumented
305 0 my ($self, $i, $j, $c, $k) = @_;
306 0 $self->metaRecord(1352,5);
307 0 $self->writeWord($k);
308 0 $self->writeColour($c);
309 0 $self->writeWord($j);
310 0 $self->writeWord($i);
311 }
312  
313 0 ▶sub lineTo {
Subroutine lineTo: not called CC=1 SCAR=6.9
Pod undocumented
314 0 my ($self, $i, $j) = @_;
315 0 $self->metaRecord(531,2);
316 0 $self->writeWord($j);
317 0 $self->writeWord($i);
318 }
319  
320 0 ▶sub moveTo {
Subroutine moveTo: not called CC=1 SCAR=6.9
Pod undocumented
321 0 my ($self, $i, $j) = @_;
322 0 $self->metaRecord(532,2);
323 0 $self->writeWord($j);
324 0 $self->writeWord($i);
325 }
326  
327 1 ▶sub setWindowOrg {
Subroutine setWindowOrg: called CC=1 SCAR=0.0
Pod undocumented
328 1 my ($self, $i, $j) = @_;
329 1 $self->metaRecord(523,2);
330 1 $self->writeWord($j);
331 1 $self->writeWord($i);
332 }
333  
334 0 ▶sub setViewportOrg {
Subroutine setViewportOrg: not called CC=1 SCAR=6.9
Pod undocumented
335 0 my ($self, $i, $j) = @_;
336 0 $self->metaRecord(525,2);
337 0 $self->writeWord($j);
338 0 $self->writeWord($i);
339 }
340  
341 0 ▶sub offsetViewportOrg {
Subroutine offsetViewportOrg: not called CC=1 SCAR=6.9
Pod undocumented
342 0 my ($self, $i, $j) = @_;
343 0 $self->metaRecord(529,2);
344 0 $self->writeWord($j);
345 0 $self->writeWord($i);
346 }
347  
348 0 ▶sub setViewportExt {
Subroutine setViewportExt: not called CC=1 SCAR=6.9
Pod undocumented
349 0 my ($self, $i, $j) = @_;
350 0 $self->metaRecord(526,2);
351 0 $self->writeWord($j);
352 0 $self->writeWord($i);
353 }
354  
355 0 ▶sub scaleWindowExt {
Subroutine scaleWindowExt: not called CC=1 SCAR=6.9
Pod undocumented
356 0 my ($self, $i, $j, $k, $l) = @_;
357 0 $self->metaRecord(1024,4);
358 0 $self->writeWord($l);
359 0 $self->writeWord($k);
360 0 $self->writeWord($j);
361 0 $self->writeWord($i);
362 }
363  
364 0 ▶sub scaleViewportExt {
Subroutine scaleViewportExt: not called CC=1 SCAR=6.9
Pod undocumented
365 0 my ($self, $i, $j, $k, $l) = @_;
366 0 $self->metaRecord(1042,4);
367 0 $self->writeWord($l);
368 0 $self->writeWord($k);
369 0 $self->writeWord($j);
370 0 $self->writeWord($i);
371 }
372  
373 0 ▶sub patBlt {
Subroutine patBlt: not called CC=1 SCAR=6.9
Pod undocumented
374 0 my ($self, $i, $j, $k, $l, $m) = @_;
375 0 $self->metaRecord(1565,4);
376 0 $self->writeInteger($m);
377 0 $self->writeWord($l);
378 0 $self->writeWord($k);
379 0 $self->writeWord($j);
380 0 $self->writeWord($i);
381 }
382  
383 0 ▶sub offsetWindowOrg {
Subroutine offsetWindowOrg: not called CC=1 SCAR=6.9
Pod undocumented
384 0 my ($self, $i, $j) = @_;
385 0 $self->metaRecord(527,2);
386 0 $self->writeWord($j);
387 0 $self->writeWord($i);
388 }
389  
390 1 ▶sub setWindowExt {
Subroutine setWindowExt: called CC=1 SCAR=0.0
Pod undocumented
391 1 my ($self, $i, $j) = @_;
392 1 $self->metaRecord(524,2);
393 1 $self->writeWord($j);
394 1 $self->writeWord($i);
395 }
396  
397 1 ▶sub polygon {
Subroutine polygon: called CC=2 SCAR=6.9
Pod undocumented
398 1 my ($self, $arrayref, $arrayref2, $i) = @_;
399 1 $self->metaRecord(804,1+2*$i);
400 1 $self->writeWord($i);
401 1 ▶ for (my $k=0;$k<$i;$k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k < $i) 3 1 4
402 3 $self->writeWord($arrayref->[$k]);
403 3 $self->writeWord($arrayref2->[$k]);
404 }
405 }
406  
407 0 ▶sub polyline {
Subroutine polyline: not called CC=2 SCAR=17.9
Pod undocumented
408 0 my ($self, $arrayref, $arrayref2, $i) = @_;
409 0 $self->metaRecord(805,1+2*$i);
410 0 $self->writeWord($i);
411 0 ▶ for (my $k=0;$k<$i;$k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k < $i) 0 0 0
412 0 $self->writeWord($arrayref->[$k]);
413 0 $self->writeWord($arrayref2->[$k]);
414 }
415 }
416  
417 # Add a WMF comment to the file.
418 # Some byte fixing required here. Have to pad with a null
419 # byte if using a string with odd number of characters??
420 1 ▶sub escape {
Subroutine escape: called CC=7 SCAR=20.0
Pod undocumented
421 1 my ($self, $text) = @_;
422 1 my @abytes0 = ();
423
424 1 my @text = split(//,reverse($text));
425 1 ▶ print STDERR "Embedded comment: \"$text\" (",length($text)," chars)\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 1 1
426 1 ▶ while (@text){
Branch: 1 branch
BranchTrueFalseTotal
if (@text) 33 1 34
427 33 my $c = shift(@text);
428 33 $c = $self->toByte($c);
429 33 unshift (@abytes0, $c);
430 }
431 1 ▶ if(length($text) % 2 == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (length($text) % 2 == 0) 0 1 1
432 0 unshift (@abytes0, $self->toByte(0)); # add padding byte
433 0 ▶ print STDERR "Adding padding byte\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 0 0
434 }
435 1 $self->metaRecord(1574, 2+(scalar(@abytes0)+1)/2);
436 1 $self->writeWord(scalar(@abytes0));
437
438 1 my $newArrayLen = ((scalar(@abytes0)+1)/2)*2;
439 1 $self->writeWord(length($text)/2);
440
441 1 ▶ for (my $j=0;$j < $newArrayLen;$j+=2){
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $newArrayLen) 17 1 18
442 17 ▶ if (!defined $abytes0[$j+1]){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $abytes0[$j + 1]) { } 1 16 17
443 1 $self->writeWord($abytes0[$j] | $self->toByte(0) << 8 & 0xFF00);
444 } else {
445 16 $self->writeWord($abytes0[$j] | $abytes0[$j+1] << 8 & 0xFF00);
446 }
447 }
448
449 }
450  
451 1 ▶sub textOut {
Subroutine textOut: called CC=5 SCAR=16.1
Pod undocumented
452 1 my ($self, $i, $j, $text) = @_;
453 1 $self->metaRecord(1313, 3+(length($text)+1)/2);
454 1 $self->writeWord(length($text));
455
456 1 my @abytes0 = ();
457 1 my @text = split(//,reverse($text));
458 1 ▶ print STDERR "Packing string: \"$text\"\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 1 1
459 1 ▶ while (@text){
Branch: 1 branch
BranchTrueFalseTotal
if (@text) 13 1 14
460 13 my $c = shift(@text);
461 13 $c = $self->toByte($c);
462 13 unshift (@abytes0, $c);
463 }
464 1 ▶ for (my $k=0;$k < scalar(@abytes0)/2;$k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k < scalar(@abytes0) / 2) 7 1 8
465 7 my $l = 0;
466 7 ▶ if (!defined $abytes0[$k*2+1]){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $abytes0[$k * 2 + 1]) { } 1 6 7
467 1 $l = $abytes0[$k*2] | $self->toByte(0) << 8 & 0xFF00;
468 } else {
469 6 $l = $abytes0[$k*2] | $abytes0[$k*2+1] << 8 & 0xFF00;
470 }
471 7 $self->writeWord($l);
472 }
473 1 $self->writeWord($j);
474 1 $self->writeWord($i);
475 }
476  
477 0 ▶sub extTextOut {
Subroutine extTextOut: not called CC=11 SCAR=48.8
Pod undocumented
478 0 my ($self, $i, $j, $k, $rect, $text, $spacing_arrayref) = @_;
479 0 my @spaces = ();
480 0 ▶ if (defined ($spacing_arrayref)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spacing_arrayref) 0 0 0
481 0 ▶ print STDERR "Setting spacing array\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 0 0
482 0 @spaces = @$spacing_arrayref;
483 }
484 0 my $l = 4 + (length($text)+1)/2;
485 0 ▶ if ($k != 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($k != 0) 0 0 0
486 0 $l += 4;
487 }
488 0 ▶ if (defined $spacing_arrayref){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spacing_arrayref) 0 0 0
489 0 $l += length($text);
490 }
491 0 $self->metaRecord(2610,$l);
492 0 $self->writeWord($j);
493 0 $self->writeWord($i);
494 0 $self->writeWord(length($text));
495 0 $self->writeWord($k);
496 0 ▶ if($k != 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($k != 0) 0 0 0
497 0 $self->writeWord($rect->x());
498 0 $self->writeWord($rect->y());
499 0 $self->writeWord($rect->width());
500 0 $self->writeWord($rect->height());
501 }
502 0 my @abytes0 = ();
503 0 my @text = split(//,reverse($text));
504 #print STDERR "Packing string: \"$text\"\n";
505 0 ▶ while (@text){
Branch: 1 branch
BranchTrueFalseTotal
if (@text) 0 0 0
506 0 my $c = shift(@text);
507 0 $c = $self->toByte($c);
508 0 unshift (@abytes0, $c);
509 }
510 0 ▶ print STDERR "Packing ",scalar(@abytes0)/2," bytes\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 0 0
511 0 ▶ for (my $k=0;$k < scalar(@abytes0)/2;$k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k < scalar(@abytes0) / 2) 0 0 0
512 0 my $l = 0;
513 0 $l = @abytes0[$k*2] | @abytes0[$k*2+1] << 8 & 0xFF00;
514 0 $self->writeWord($l);
515 }
516 0 ▶ if ($spacing_arrayref){
Branch: 1 branch
BranchTrueFalseTotal
if ($spacing_arrayref) 0 0 0
517 0 ▶ for (my $k=0;$k < length($text);$k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k < length $text) 0 0 0
518 0 $self->writeWord($spaces[$k]);
519 }
520 }
521 }
522  
523 5 ▶sub selectObject {
Subroutine selectObject: called CC=3 SCAR=12.0
Pod undocumented
524 5 my ($self, $i) = @_;
525 5 my $handles = $self->{'_handles'};
526 5 ▶ if ($i < scalar(@$handles) && $handles->[$i] == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$handles and $handles->[$i] == 1) { } 5 0 5
Condition33%1/3
$i < scalar @$handles and $handles->[$i] == 1
!ll&&!rl&&r
005
MC/DC0%0/2
$i < scalar @$handles and $handles->[$i] == 1
$i < scalar @$handles $handles->[$i] == 1
Truth table33%1/3
A and B
A= $i < scalar @$handlesB= $handles->[$i] == 1
ABresult
0X0
100
111
527 5 $self->metaRecord(301, 1);
528 5 $self->writeWord($i);
529 5 return;
530 } else {
531 0 die "GDI object handle (select) exception: array out of bounds ($i)\n"
532 }
533 }
534  
535 5 ▶sub deleteObject {
Subroutine deleteObject: called CC=4 SCAR=15.0
Pod undocumented
536 5 my ($self, $i) = @_;
537 5 my $handles = $self->{'_handles'};
538 5 ▶ if ($i < scalar(@$handles) && $handles->[$i] == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$handles and $handles->[$i] == 1) { } 5 0 5
Condition33%1/3
$i < scalar @$handles and $handles->[$i] == 1
!ll&&!rl&&r
005
MC/DC0%0/2
$i < scalar @$handles and $handles->[$i] == 1
$i < scalar @$handles $handles->[$i] == 1
Truth table33%1/3
A and B
A= $i < scalar @$handlesB= $handles->[$i] == 1
ABresult
0X0
100
111
539 5 $self->metaRecord(496, 1);
540 5 $self->writeWord($i);
541 5 $handles->[$i] = 0;
542 5 ▶ print STDERR "Removed GDI object handle at stack position: $i\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 5 5
543 5 return;
544 } else {
545 0 die "GDI object handles (delete) exception: can't remove object $i\n"
546 }
547 }
548  
549 1 ▶sub deleteObjects {
Subroutine deleteObjects: called CC=4 SCAR=16.4
Pod undocumented
550 1 my ($self) = @_;
551 1 my $handles = $self->{'_handles'};
552 1 ▶ for (my $i=0;$i < scalar(@$handles);$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$handles) 2 1 3
553 2 ▶ if($handles->[$i] == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($handles->[$i] == 1) 0 2 2
554 0 $self->deleteObject($i);
555 0 ▶ print STDERR "GDI handle stack cleanup: $i\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 0 0
556 }
557 }
558 }
559  
560 5 ▶sub addHandle {
Subroutine addHandle: called CC=3 SCAR=11.0
Pod undocumented
561 5 my ($self) = @_;
562 5 my $handles = $self->{'_handles'};
563 5 ▶ for (my $i=0; $i < scalar(@$handles); $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$handles) 5 2 7
564 5 ▶ if ($handles->[$i] == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($handles->[$i] == 0) 3 2 5
565 3 $handles->[$i] = 1;
566 3 return($i)
567 }
568 }
569 2 push (@$handles,1);
570 2 return (scalar(@$handles) - 1);
571 }
572  
573 27 ▶sub metaRecord {
Subroutine metaRecord: called CC=1 SCAR=0.0
Pod undocumented
574 27 my ($self, $i, $j) = @_;
575 27 my $k = $j + 3;
576 27 $self->writeInteger($k);
577 27 $self->writeWord($i);
578 27 $self->maxObjectSize($k);
579 }
580  
581 27 ▶sub maxObjectSize {
Subroutine maxObjectSize: called CC=2 SCAR=6.9
Pod undocumented
582 27 my ($self, $i) = @_;
583 27 ▶ if ($i > $self->{'_maxobjectsize'}){
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $self->{"_maxobjectsize"}) 1 26 27
584 1 $self->{'_maxobjectsize'} = $i;
585 }
586 }
587  
588 1 ▶sub getBodySize {
Subroutine getBodySize: called CC=1 SCAR=0.0
Pod undocumented
589 1 my ($self) = @_;
590 1 return (length($self->{'_wmf'})/2);
591 }
592  
593 1 ▶sub makePlaceableHeader {
Subroutine makePlaceableHeader: called CC=1 SCAR=0.0
Pod undocumented
594 1 my ($self,$i,$j,$k,$l,$i1) = @_;
595 1 $self->outputHeaderInteger(0x9ac6cdd7);
596 1 $self->outputHeaderWord(0);
597 1 $self->outputHeaderWord($i);
598 1 $self->outputHeaderWord($j);
599 1 $self->outputHeaderWord($k);
600 1 $self->outputHeaderWord($l);
601 1 $self->outputHeaderWord($i1);
602 1 $self->outputHeaderInteger(0);
603 1 $self->outputHeaderWord($self->calcChecksum($i1,$i,$j,$k,$l));
604 1 $self->makeHeader();
605 }
606  
607 1 ▶sub makeHeader {
Subroutine makeHeader: called CC=3 SCAR=11.2
Pod undocumented
608 1 my ($self) = @_;
609 1 $self->outputHeaderWord(1);
610 1 $self->outputHeaderWord(9);
611 1 $self->outputHeaderWord(768);
612 1 $self->outputHeaderInteger($self->getBodySize()+9);
613 1 $self->outputHeaderWord(scalar(@{$self->{'_handles'}}));
614 1 $self->outputHeaderInteger($self->{'_maxobjectsize'});
615 1 $self->outputHeaderWord(0);
616
617 1 ▶ print STDERR "Header words: ", $self->getBodySize(), "\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 1 1
618 0 ▶ print STDERR "GDI stack size: ", scalar(@{$self->{'_handles'}}), "\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Image::WMF::Image::DEBUG 0 1 1
619 }
620  
621 1 ▶sub calcChecksum {
Subroutine calcChecksum: called CC=1 SCAR=0.0
Pod undocumented
622 1 my ($self, $i, $j, $k, $l, $i1) = @_;
623 1 my $j1 = 39622;
624 1 $j1 ^= 0xcdd7;
625 1 $j1 ^= $i;
626 1 $j1 ^= $j;
627 1 $j1 ^= $k;
628 1 $j1 ^= $l;
629 1 $j1 ^= $i1;
630 1 return $j1;
631 }
632  
633 0 ▶sub writeBody {
Subroutine writeBody: not called CC=2 SCAR=17.9
Pod undocumented
634 0 my ($self) = @_;
635 0 ▶ if (defined $self->{'_fhandle'}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_fhandle'}) { } 0 0 0
636 0 my $fh = $self->{'_fhandle'};
637 0 print $fh $self->{'_wmf'};
638 0 $self->closeFile($self->{'_filename'})
639 } else {
640 0 die "Tried to print WMF body to a non-existent file handle!\n";
641 }
642 }
643  
644 0 ▶sub writeHeader {
Subroutine writeHeader: not called CC=2 SCAR=17.9
Pod undocumented
645 0 my ($self) = @_;
646 0 $self->makeHeader();
647 0 ▶ if (defined $self->{'_fhandle'}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_fhandle'}) { } 0 0 0
648 0 my $fh = $self->{'_fhandle'};
649 0 print $fh $self->{'_header'};
650 } else {
651 0 die "Tried to print WMF header to a non-existent file handle!\n";
652 }
653 }
654  
655 0 ▶sub writePlaceableHeader {
Subroutine writePlaceableHeader: not called CC=2 SCAR=17.9
Pod undocumented
656 0 my ($self,$i,$j,$k,$l,$i1) = @_;
657 0 $self->makePlaceableHeader($i,$j,$k,$l,$i1);
658 0 ▶ if (defined $self->{'_fhandle'}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_fhandle'}) { } 0 0 0
659 0 my $fh = $self->{'_fhandle'};
660 0 print $fh $self->{'_header'};
661 } else {
662 0 die "Tried to print WMF header to a non-existent file handle!\n";
663 }
664 }
665  
666 0 ▶sub finalise {
Subroutine finalise: not called CC=1 SCAR=6.9
Pod undocumented
667 0 my ($self) = @_;
668 0 $self->deleteObjects(); # clean up undeleted GDI objects
669 0 $self->metaRecord(0,0);
670 }
671  
672 57 ▶sub toByte {
Subroutine toByte: called CC=1 SCAR=0.0
Pod undocumented
673 57 my ($self, $byte) = @_;
674 57 $byte = unpack("C*", $byte);
675 57 return($byte);
676 }
677  
678 38 ▶sub loWord {
Subroutine loWord: called CC=1 SCAR=0.0
Pod undocumented
679 38 my ($self, $word) = @_;
680 38 return ($word & 0xFFFF)
681 }
682  
683 38 ▶sub hiWord {
Subroutine hiWord: called CC=1 SCAR=0.0
Pod undocumented
684 38 my ($self, $word) = @_;
685 38 return ($word & 0xFFFF0000) >> 16;
686 }
687  
688 170 ▶sub writeWord {
Subroutine writeWord: called CC=1 SCAR=0.0
Pod undocumented
689 170 my ($self, $int) = @_;
690 170 $self->outputWord($int);
691 }
692  
693 0 ▶sub writeHeaderWord {
Subroutine writeHeaderWord: not called CC=1 SCAR=6.9
Pod undocumented
694 0 my ($self, $int) = @_;
695 0 $self->outputHeaderWord($int);
696 }
697  
698 170 ▶sub outputWord {
Subroutine outputWord: called CC=1 SCAR=0.0
Pod undocumented
699 170 my ($self, $int) = @_;
700 170 $self->{'_wmf'} .= pack ("C", ($int & 0xFF));
701 170 $self->{'_wmf'} .= pack ("C", (($int & 0xFF00)>>8));
702 }
703  
704 20 ▶sub outputHeaderWord {
Subroutine outputHeaderWord: called CC=1 SCAR=0.0
Pod undocumented
705 20 my ($self, $int) = @_;
706 20 $self->{'_header'} .= pack ("C", ($int & 0xFF));
707 20 $self->{'_header'} .= pack ("C", (($int & 0xFF00)>>8));
708 }
709  
710 0 ▶sub outputInteger {
Subroutine outputInteger: not called CC=1 SCAR=6.9
Pod undocumented
711 0 my ($self, $int) = @_;
712 0 $self->outputWord($self->loWord($int));
713 0 $self->outputWord($self->hiWord($int));
714 }
715  
716 4 ▶sub outputHeaderInteger {
Subroutine outputHeaderInteger: called CC=1 SCAR=0.0
Pod undocumented
717 4 my ($self, $int) = @_;
718 4 $self->outputHeaderWord($self->loWord($int));
719 4 $self->outputHeaderWord($self->hiWord($int));
720 }
721  
722 34 ▶sub writeInteger {
Subroutine writeInteger: called CC=1 SCAR=0.0
Pod undocumented
723 34 my ($self, $int) = @_;
724 34 $self->writeWord($self->loWord($int));
725 34 $self->writeWord($self->hiWord($int));
726 }
727  
728 0 ▶sub writeHeaderInteger {
Subroutine writeHeaderInteger: not called CC=1 SCAR=6.9
Pod undocumented
729 0 my ($self, $int) = @_;
730 0 $self->writeHeaderWord($self->loWord($int));
731 0 $self->writeHeaderWord($self->hiWord($int));
732 }
733  
734 1 ▶sub wmf {
Subroutine wmf: called CC=2 SCAR=7.4
Pod undocumented
735 1 my ($self, $x, $y, $resolution) = @_;
736 # $resolution is number of metafile units per inch (optional argument)
737 1 ▶ if (defined $resolution){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resolution) { } 1 0 1
738 1 $self->makePlaceableHeader(0,0,$x,$y,$resolution);
739 } else {
740 0 $self->makePlaceableHeader(0,0,$x,$y,96);
741 }
742 1 return($self->{'_header'} . $self->{'_wmf'});
743 }
744  
745 0 ▶sub createFile {
Subroutine createFile: not called CC=5 SCAR=34.0
Pod undocumented
746 0 my ($self, $filename) = @_;
747 0 ▶ if ($filename) {
Branch: 2 branches
BranchTrueFalseTotal
if ($filename) { } 0 0 0
elsif (defined $self->{'_filename'}) { } 0 0 0
748 0 $self->{'_filename'} = $filename;
749 0 ▶ open (OUT, ">$filename") or die "Cannot open WMF file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">$filename" or die "Cannot open WMF file: $!\n" 0 0 0
750 0 $self->{'_fhandle'} = \*OUT;
751 } elsif (defined $self->{'_filename'}){
752 0 my $filename = $self->{'_filename'};
753 0 ▶ open (OUT, ">$filename") or die "Cannot open WMF file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">$filename" or die "Cannot open WMF file: $!\n" 0 0 0
754 0 $self->{'_fhandle'} = \*OUT;
755 } else {
756 0 die "Trying to open a file with no name!\n";
757 }
758
759 0 return $self->{'_fhandle'};
760 }
761  
762 0 ▶sub closeFile {
Subroutine closeFile: not called CC=2 SCAR=17.9
Pod undocumented
763 0 my ($self, $filename) = @_;
764 0 ▶ if ($filename eq $self->{'_filename'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename eq $self->{"_filename"}) 0 0 0
765 0 close($self->{'_fhandle'});
766 0 $self->{'_fhandle'} = undef;
767 0 return 1;
768 }
769 }
770  
771  
772 1 1;
773  
« WMF/Colour.pm ↑ Summary WMF/Polygon.pm »