blib/lib/SVG/GD.pm

filter: Statementstmt 21.4% 47 / 219 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 19.6% 11 / 56 Podpod 100% 6 / 6 totaltotal 20.5% 64 / 311 CC 15 SCAR 21.2
CC
15
Cov
19%
new
56.0
colorAllocate
12.0
getSVGstyle
6.0
CRAP 8.4
↑ Summary
1 package SVG::GD;
2
3 1 $VERSION = '0.20';
4
5 1 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 1 ▶use SVG;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10
11 =pod
12
13 =head1 Name: SVG::GD
14
15 =head1 Version 0.20
16
17 =head1 Author: Ronan Oger
18
19 =head1 Abstract
20
21 Provide (as seamless as possible) an SVG wrapper to the GD API
22 in order to provide SVG output of images generate with the Perl GD module
23
24 =head1 Synopsis
25
26 use GD;
27 use SVG::GD;
28 $im = new GD::Image(100,50);
29
30 # allocate black -- this will be our background
31 $black = $im->colorAllocate(0, 0, 0);
32
33 # allocate white
34 $white = $im->colorAllocate(255, 255, 255);
35
36 # allocate red
37 $red = $im->colorAllocate(255, 0, 0);
38
39 # allocate blue
40 $blue = $im->colorAllocate(0,0,255);
41
42 #Inscribe an ellipse in the image
43 $im->arc(50, 25, 98, 48, 0, 360, $white);
44
45 # Flood-fill the ellipse. Fill color is red, and will replace the
46 # black interior of the ellipse
47 $im->fill(50, 21, $red);
48
49 binmode STDOUT;
50
51 # print the image to stdout
52 print $im->png;
53
54 =cut
55
56
57 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
58 #first, let's re-map the GD::Image methods to somewhere else safe.
59 #nb we will also have to do this with the GD::Font methods
60 # *SVG::HGD::Image::new = \&GD::Image::new;
61 # *SVG::HGD::gdSmallFont =\&GD::gdSmallFont;
62 # *SVG::HGD::gdLargeFont =\&GD::gdLargeFont;
63 # *SVG::HGD::gdMediumBoldFont =\&GD::gdMediumBoldFont;
64 # *SVG::HGD::gdTinyFont =\&GD::gdTinyFont;
65 # *SVG::HGD::gdGiantFont =\&GD::gdGiantFont;
66 # *SVG::HGD::Image::_make_filehandle =\&GD::Image::_make_filehandle;
67 # *SVG::HGD::Image::new =\&GD::Image::new;
68 # *SVG::HGD::Image::newTrueColor =\&GD::Image::newTrueColor;
69 # *SVG::HGD::Image::newPalette =\&GD::Image::newPalette;
70 # *SVG::HGD::Image::newFromPng =\&GD::Image::newFromPng;
71 # *SVG::HGD::Image::newFromJpeg =\&GD::Image::newFromJpeg;
72 # *SVG::HGD::Image::newFromXbm =\&GD::Image::newFromXbm;
73 # *SVG::HGD::Image::newFromGd =\&GD::Image::newFromGd;
74 # *SVG::HGD::Image::newFromGd2 =\&GD::Image::newFromGd2;
75 # *SVG::HGD::Image::newFromGd2Part =\&GD::Image::newFromGd2Part;
76 # *SVG::HGD::Image::ellipse =\&GD::Image::ellipse;
77 # *SVG::HGD::Image::clone =\&GD::Image::clone;
78 # *SVG::HGD::Polygon::new =\&GD::Polygon::new;
79 # *SVG::HGD::Polygon::DESTROY =\&GD::Polygon::DESTROY;
80 # *SVG::HGD::Polygon::addPt =\&GD::Polygon::addPt;
81 # *SVG::HGD::Polygon::getPt =\&GD::Polygon::getPt;
82 # *SVG::HGD::Polygon::setPt =\&GD::Polygon::setPt;
83 # *SVG::HGD::Polygon::length =\&GD::Polygon::length;
84 # *SVG::HGD::Polygon::vertices =\&GD::Polygon::vertices;
85 # *SVG::HGD::Polygon::bounds =\&GD::Polygon::bounds;
86 # *SVG::HGD::Polygon::deletePt =\&GD::Polygon::deletePt;
87 # *SVG::HGD::Polygon::offset =\&GD::Polygon::offset;
88 # *SVG::HGD::Polygon::map =\&GD::Polygon::map;
89 # *SVG::HGD::Image::polygon =\&GD::Image::polygon;
90 # *SVG::HGD::Polygon::toPt =\&GD::Polygon::toPt;
91 # *SVG::HGD::Polygon::transform =\&GD::Polygon::transform;
92 # *SVG::HGD::Polygon::scale =\&GD::Polygon::scale;
93
94 1 *GD::Font:: = *SVG::GD::Font::;
95 1 *GD::Image:: = *SVG::GD::Image::;
96 }
97
98 1 ▶use vars qw/$VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS/;
Subroutine BEGIN: called CC=1 SCAR=0.0
99
100 1 our $tinyfontsize='5';
101 1 our $smallfontsize='7';
102 1 our $mediumfontsize='10';
103 1 our $largefontsize='12';
104 1 our $giantfontsize='16';
105 1 our $font = {};
106 1 our $fontindex = 0;
107
108 1 @ISA = qw/Exporter/;
109
110 1 @EXPORT = qw/
111 gdBrushed
112 gdDashSize
113 gdMaxColors
114 gdStyled
115 gdStyledBrushed
116 gdTiled
117 gdTransparent
118 gdSmallFont
119 gdMediumBoldFont
120 gdLargeFont
121 gdGiantFont /;
122
123 1 @EXPORT_OK = qw/
124 GD_CMP_IMAGE
125 GD_CMP_NUM_COLORS
126 GD_CMP_COLOR
127 GD_CMP_SIZE_X
128 GD_CMP_SIZE_Y
129 GD_CMP_TRANSPARENT
130 GD_CMP_BACKGROUND
131 GD_CMP_INTERLACE
132 GD_CMP_TRUECOLOR /;
133
134 1 %EXPORT_TAGS = ('cmp' => [ qw/
135 GD_CMP_IMAGE
136 GD_CMP_NUM_COLORS
137 GD_CMP_COLOR
138 GD_CMP_SIZE_X
139 GD_CMP_SIZE_Y
140 GD_CMP_TRANSPARENT
141 GD_CMP_BACKGROUND
142 GD_CMP_INTERLACE
143 GD_CMP_TRUECOLOR / ]
144 );
145
146 =head2 gdTinyFont
147
148 returns SVG::GD::Font::Tiny
149
150 =cut
151
152 #font control
153
154
155 0 ▶sub SVG::GD::gdTinyFont {
Subroutine gdTinyFont: not called CC=1 SCAR=6.9
Pod documented
156 0 return SVG::GD::Font::Tiny();
157 }
158
159 #font control
160
161 =head2 gdSmallFont
162
163 returns SVG::GD::Font::Small();
164
165 =cut
166
167
168 0 ▶sub SVG::GD::gdSmallFont {
Subroutine gdSmallFont: not called CC=1 SCAR=6.9
Pod documented
169 0 return SVG::GD::Font::Small();
170 }
171
172 =head2 gdMediumBoldFont
173
174 returns SVG::GD::Font::Bold();
175
176 =cut
177
178 #font control
179 0 ▶sub SVG::GD::gdMediumBoldFont {
Subroutine gdMediumBoldFont: not called CC=1 SCAR=6.9
Pod documented
180 0 return SVG::GD::Font::MediumBold();
181 }
182
183 =head2 gdLargeFont
184
185 Returns SVG::GD::Font::Large()
186
187 =cut
188
189 #font control
190 0 ▶sub SVG::GD::gdLargeFont {
Subroutine gdLargeFont: not called CC=1 SCAR=6.9
Pod documented
191 0 return SVG::GD::Font::Large();
192 }
193
194
195 =head2 gdGiantFont
196
197 Returns SVG::GD::Font::Giant()
198
199 =cut
200
201
202 #font control
203
204 0 ▶sub SVG::GD::gdGiantFont {
Subroutine gdGiantFont: not called CC=1 SCAR=6.9
Pod documented
205 0 return SVG::GD::Font::Giant();
206 }
207
208 =head2 gdBrushed
209
210 Does nothing at this time
211
212 =cut
213
214 0 ▶sub SVG::GD::gdBrushed {
Subroutine gdBrushed: not called CC=1 SCAR=6.9
Pod documented
215 0 return '';
216 }
217
218 #
219 #
220 # OO font support (encountered in GD::Graph::radar)
221 #
222 #
223
224 package SVG::GD::Font;
225
226 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
227 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
228 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
229
230 0 ▶sub registerFont($) {
Subroutine registerFont: not called CC=1 SCAR=6.9
231 0 my $size = shift;
232 0 $fontindex++;
233 0 $font->{$fontindex}->{fontheight} = $size;
234 0 $font->{$fontindex}->{fontstyle} = {'font-size'=>$size};
235 0 return $fontindex;
236 }
237
238 0 ▶sub Giant {
Subroutine Giant: not called CC=1 SCAR=6.9
239 0 my $class = shift;
240 0 my $size = $giantfontsize;
241 0 SVG::GD::Font::registerFont($size);
242 }
243
244 0 ▶sub Large {
Subroutine Large: not called CC=1 SCAR=6.9
245 0 my $class = shift;
246 0 my $size = $largefontsize;
247 0 SVG::GD::Font::registerFont($size);
248 }
249
250 0 ▶sub Medium {
Subroutine Medium: not called CC=1 SCAR=6.9
251 0 my $class = shift;
252 0 my $size = $mediumfontsize;
253 0 SVG::GD::Font::registerFont($size);
254 }
255
256 0 ▶sub MediumBold {
Subroutine MediumBold: not called CC=1 SCAR=6.9
257 0 my $class = shift;
258 0 my $size = $mediumfontsize;
259 0 SVG::GD::Font::registerFont($size);
260 }
261
262 0 ▶sub Small {
Subroutine Small: not called CC=1 SCAR=6.9
263 0 my $class = shift;
264 0 my $size = $smallfontsize;
265 0 SVG::GD::Font::registerFont($size);
266 }
267
268 0 ▶sub Tiny {
Subroutine Tiny: not called CC=1 SCAR=6.9
269 0 my $class = shift;
270 0 my $size = $tinyfontsize;
271 0 SVG::GD::Font::registerFont($size);
272 }
273
274 0 ▶sub height {
Subroutine height: not called CC=1 SCAR=6.9
275 0 my $id = shift;
276 0 return 10;
277 }
278
279 0 ▶sub width {
Subroutine width: not called CC=1 SCAR=6.9
280 0 my $myfont = shift;
281 0 return 8;
282 }
283
284 =head2 getSVGstyle($font)
285
286 retrieve the style in SVG format for predefined fomts
287
288 =cut
289
290 0 ▶sub getSVGstyle {
Subroutine getSVGstyle: not called CC=2 SCAR=17.9
291 0 my $myfont = shift;
292 0 ▶ if (eval{defined $font->{$myfont}->{fontstyle} eq 'HASH'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { defined $SVG::GD::font->{$myfont}{'fontstyle'} eq 'HASH' } }) { } 0 0 0
293 0 return %{$font->{$myfont}->{fontstyle}};
294 } else {
295 0 return ();
296 }
297
298 }
299 #
300 # SVG::GD::Image
301 #
302
303 package SVG::GD::Image;
304
305 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
306 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
307
308 #constructor
309 0 ▶sub SVG::GD::Image::new {
Subroutine new: not called CC=7 SCAR=40.3
310 0 my $class = shift;
311 0 my $self = {};
312 0 bless $self, $class;
313 #$self->{_GD_} = new SVG::HGD::Image(@_)
314 # || print STDERR "Quitting. Unable to construct new SVG::HGD::Image
315 # object using SVG::GD!: $!\n";
316 #return undef unless defined $self->{_GD_};
317
318 0 my ($val_1,$val_2,$val_3) = @_;
319 #do we have drawing sizes?
320 0 ▶ if ($val_1 =~ /^\d+$/ && $val_2 =~ /^\d+$/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($val_1 =~ /^\d+$/ and $val_2 =~ /^\d+$/) { } 0 0 0
elsif (-r $val_1) { } 0 0 0
elsif (ref $val_1) { } 0 0 0
elsif (defined $val_1) { } 0 0 0
Condition0%0/3
$val_1 =~ /^\d+$/ and $val_2 =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
$val_1 =~ /^\d+$/ and $val_2 =~ /^\d+$/
$val_1 =~ /^\d+$/ $val_2 =~ /^\d+$/
Truth table0%0/3
A and B
A= $val_1 =~ /^\d+$/B= $val_2 =~ /^\d+$/
ABresult
0X0
100
111
321 0 $self->{_ATTRIBUTES_}->{width} = $val_1;
322 0 $self->{_ATTRIBUTES_}->{height} = $val_2;
323 0 ▶ $self->{_ATTRIBUTES_}->{-truecolor} = $val_3
Branch: 1 branch
BranchTrueFalseTotal
if defined $val_3 0 0 0
324 if defined $val_3;
325
326 }
327 #do we have a valid filename?
328 elsif (-r $val_1) {
329 0 $self->{_ATTRIBUTES_}->{FILENAME} = $val_1;
330 }
331 #do we have a file reference?
332 elsif (ref $val_1) {
333 0 $self->{_ATTRIBUTES_}->{FILEHANDLE} = $val_1;
334 }
335 #then we have raw image data.
336 elsif (defined $val_1) {
337 0 $self->{_ATTRIBUTES_}->{IMAGEDATA} = $val_1;
338 }
339 0 else {return undef}
340 #build the svg drawing
341 0 $self->{_SVG_} = SVG->new(%{$self->{_ATTRIBUTES_}});
342 0 $self->{scratch}->{index_colours} = 0;
343 $self->{_COLOUR_}->{named} = {
344 0 white => {svg=>'white',rgb=>'white'},
345 lgray => {svg=>'gray',rgb=>'lgray'},
346 gray => {svg=>'gray',rgb=>'gray'},
347 dgray => {svg=>'gray',rgb=>'dgray'},
348 black =>{svg=>'black',rgb=>'black'},
349 lblue =>{svg=>'lightblue',rgb=>'lblue'},
350 blue => {svg=>'blue',rgb=>'blue'},
351 dblue =>, {svg=>'darkblue',rgb=>'dblue'},
352 gold => {svg=>'gold',rgb=>'gold'},
353 lyellow =>{svg=>'yellow',rgb=>'lyellow'},
354 yellow =>{svg=>'yellow',rgb=>'yellow'},
355 dyellow =>{svg=>'gold',rgb=>'gold'},
356 lgreen =>{svg=>'mintgreen',rgb=>'lgreen'},
357 green =>{svg=>'green',rgb=>'green'},
358 dgreen =>{svg=>'darkgreen',rgb=>'dgreen'},
359 lred =>{svg=>'red',rgb=>'dred'},
360 red => {svg=>'red',rgb=>'red'},
361 dred =>{svg=>'red',rgb=>'dred'},
362 lpurple =>{svg=>'gold',rgb=>'gold'},
363 purple => {svg=>'purple',rgb=>'purple'},
364 dpurple =>{svg=>'dpurple ',rgb=>'dpurple'},
365 lorange =>{svg=>'lorange ',rgb=>'lorange'},
366 orange => {svg=>'orange',rgb=>'orange'},
367 pink => {svg=>'pink',rgb=>'pink'},
368 dpink =>{svg=>'pink',rgb=>'dpink'},
369 marine =>{svg=>'navy',rgb=>'marine'},
370 cyan => {svg=>'cyan',rgb=>'cyan'},
371 lbrown =>{svg=>'brown',rgb=>'lbrown'},
372 dbrown => {svg=>'brown',rgb=>'dbrown'},
373 };
374 0 return $self;
375 }
376
377
378 #--------------------
379 #Wrapper methods
380
381 =head2 setPixel
382
383 set a pixel to a colour
384 Because SVG does not understand pixels, this method has to be faked. We know
385 from the image size what is meant by a pixel, so we create a rectangle of size
386 1x1 and give it a colour
387
388 =cut
389
390 0 ▶sub SVG::GD::Image::setPixel($$$$) {
Subroutine setPixel: not called CC=1 SCAR=6.9
391 0 my $self = shift;
392 0 my ($x,$y,$colour) = @_;
393 0 $self->{_SVG_}->rect(x=>$x,y=>$y,
394 width=>1,height=>1,
395 fill=>$self->getColour($colour));
396 # $self->{_GD_}->setPixel($x,$y,$colour);
397 }
398
399
400 =head2 colorAllocate
401
402 Allocate the colour to a variable (red,green,blue)
403
404 =cut
405
406 0 ▶sub SVG::GD::Image::colorAllocate($$$$) {
Subroutine colorAllocate: not called CC=3 SCAR=24.8
407 0 my $self = shift;
408 0 my ($red,$green,$blue) = @_;
409 # my $code = $self->{_GD_}->colorAllocate($red,$green,$blue);
410 #if we get an rgb triplet, handle as an rgb triplet
411 0 my $code = $self->{index_colour}++;
412
413 0 ▶ if (defined $green && defined $blue) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $green and defined $blue) { } 0 0 0
Condition0%0/3
defined $green and defined $blue
!ll&&!rl&&r
000
MC/DC0%0/2
defined $green and defined $blue
defined $green defined $blue
Truth table0%0/3
A and B
A= defined $greenB= defined $blue
ABresult
0X0
100
111
414 #$code = "$red.$green.$blue" if (defined $green && defined $blue);
415 $self->{_COLOUR_}->{$code}->{svg} =
416 0 $self->{_SVG_}->colorAllocate($red,$green,$blue);
417 0 $self->{_COLOUR_}->{$code}->{rgb} = [$red,$green,$blue];
418 }
419 #otherwise assume this is a named colour.
420 else {
421 0 $code = $red;
422 0 $self->{_COLOUR_}->{$code}->{rgb} = [$code];
423 0 $self->{_COLOUR_}->{$code}->{svg} = [$code];
424 }
425 0 return $code;
426 }
427
428 =head2 colorResolve ($red,$green,$blue)
429
430 for an rbg tripplet, either returns the index for the colour or generates a new
431 index for that colour
432
433 =cut
434
435 1 *SVG::GD::Image::colorResolve = \&SVG::GD::Image::colorAllocate;
436
437 =head2 colorsTotal
438
439 return the number of allocated colors
440
441 =cut
442
443 0 ▶sub SVG::GD::Image::colorsTotal ($) {
Subroutine colorsTotal: not called CC=1 SCAR=6.9
444 0 my $self = shift;
445 0 return scalar(keys %{$self->{_COLOUR_}});
446 }
447
448 =head2 colorExact
449
450 check for the existance of an exact color
451
452 =cut
453
454 0 ▶sub SVG::GD::Image::colorExact ($$) {
Subroutine colorExact: not called CC=2 SCAR=17.9
455 0 my $self = shift;
456 0 my $colour = shift;
457 0 ▶ return 1 if $self->{_COLOUR_}->{$colour};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_COLOUR_"}{$colour} 0 0 0
458 0 return -1;
459 }
460
461 =head2 colorClosest
462
463 returns the closest colour to the RGB triplet being submitted
464
465 =cut
466
467 0 ▶sub SVG::GD::Image::colorClosest ($$$$) {
Subroutine colorClosest: not called CC=1 SCAR=6.9
468 0 my $self = shift;
469 0 my ($red,$green,$blue) = @_;
470 0 my $value = {};
471 map {
472 0 my $cc = $_;
473 #calculate the least-square distance
474 my ($dr,$dg,$db) = (
475 $red * $red -
476 $self->{_COLOUR_}->{$cc}->[0] * $self->{_COLOUR_}->{$cc}->[0],
477 $green * $blue -
478 $self->{_COLOUR_}->{$cc}->[1] * $self->{_COLOUR_}->{$cc}->[1],
479 $blue * $blue -
480 0 $self->{_COLOUR_}->{$cc}->[2] * $self->{_COLOUR_}->{$cc}->[2],
481 );
482
483 0 $value->{$dr+$dg+$db} = $cc;
484
485 0 } keys %{$self->{_COLOUR_}};
486 #
487 0 my @array = sort {$a<=>$b} keys %$value;
488 0 my $leastval = shift @array;
489 0 my $code = $value->{$leastval};
490
491 }
492
493 =head2 line
494
495 Draw a line between 2 points
496
497 =cut
498
499 0 ▶sub SVG::GD::Image::line($$$$$$) {
Subroutine line: not called CC=1 SCAR=6.9
500 0 my $self = shift;
501 0 my ($x1,$y1,$x2,$y2,$colour) = @_;
502 # $self->{_GD_}->line(@_);
503 0 $self->{_SVG_}->line(x1=>$x1,x2=>$x2,y1=>$y1,y2=>$y2,
504 stroke=>$self->getColour($colour));
505 }
506
507 0 ▶sub SVG::GD::Image::dashedLine($$$$$$) {
Subroutine dashedLine: not called CC=1 SCAR=6.9
508 0 my $self = shift;
509 0 my ($x1,$y1,$x2,$y2,$colour) = @_;
510 # $self->{_GD_}->dashedLine(@_);
511 0 $self->{_SVG_}->line(x1=>$x1,x2=>$x2,y1=>$y1,y2=>$y2,
512 stroke=>$self->getColour($colour));
513 }
514
515 =head2 filledRectangle
516
517 Draw a filled rectangle.
518
519 =cut
520
521 0 ▶sub SVG::GD::Image::filledRectangle($$$$$$$) {
Subroutine filledRectangle: not called CC=1 SCAR=6.9
522 0 my $self = shift;
523 0 my ($x1,$y1,$x2,$y2,$colour) = @_;
524 # $self->{_GD_}->filledRectangle(@_);
525 0 $self->{_SVG_}->rect(x=>$x1,y=>$y1,
526 width=>$x2-$x1,height=>$y2-$y1,
527 fill=>$self->getColour($colour),
528 stroke=>$self->getColour($colour));
529 }
530
531 =head2 rectangle
532
533 Draw a rectangle.
534
535 =cut
536
537 0 ▶sub SVG::GD::Image::rectangle($$$$$$$) {
Subroutine rectangle: not called CC=1 SCAR=6.9
538 0 my $self = shift;
539 0 my ($x1,$y1,$x2,$y2,$colour) = @_;
540 # $self->{_GD_}->rectangle(@_);
541 0 $self->{_SVG_}->rect(x=>$x1,y=>$y1,
542 width=>$x2-$x1,height=>$y2-$y1,fill=>'none',
543 stroke=>$self->getColour($colour));
544 }
545 =head2 arc
546
547 Draw an arc. Only supports closed arcs at present.
548 Note that we will ultimately need to differenciate between
549 an arc and a circle.
550
551 =cut
552
553 0 ▶sub SVG::GD::Image::arc($$$$$$$$) {
Subroutine arc: not called CC=1 SCAR=6.9
554 0 my $self = shift;
555 0 my ($cx,$cy,$width,$height,$start,$end,$colour) = @_;
556 0 $self->{_SVG_}->ellipse(cx=>$cx,cy=>$cy,
557 rx=>$width/2,ry=>$height/2,fill=>'none',
558 stroke=>$self->getColour($colour));
559 # return $self->{_GD_}->arc(@_);
560 }
561
562 =head2 SVG::GD::Image::filledPolygon
563
564 Draw a polygon defined by ab SVG::GD::Polygon object
565
566 =cut
567
568 0 ▶sub SVG::GD::Image::filledPolygon ($$$) {
Subroutine filledPolygon: not called CC=2 SCAR=17.9
569 0 my $self = shift;
570 0 my $poly = shift;
571 0 my $fill = shift;
572
573 0 my ($x,$y) = ([],[]);
574 0 foreach my $set (@{$poly->{points}}) {
575 0 my ($myx,$myy) = ($set->[0],$set->[1]);
576 0 push @$x,$myx;
577 0 push @$y,$myy;
578 }
579 my $points = $self->{_SVG_}->
580 0 get_path(x=>$x, y=>$y,
581 -type=>'path',
582 -closed=>'true');
583 0 $self->{_SVG_}->path(%$points,fill=>$self->getColour($fill));
584 }
585
586 =head2 polygon
587
588 Draw an empty polygon
589
590 =cut
591
592 0 ▶sub SVG::GD::Image::polygon ($$$) {
Subroutine polygon: not called CC=2 SCAR=17.9
593 0 my $self = shift;
594 0 my $poly = shift;
595 0 my $stroke = shift;
596
597 0 my ($x,$y) = ([],[]);
598 0 foreach my $set (@{$poly->{points}}) {
599 0 my ($myx,$myy) = ($set->[0],$set->[1]);
600 0 push @$x,$myx;
601 0 push @$y,$myy;
602 }
603 my $points = $self->{_SVG_}->
604 0 get_path(x=>$x, y=>$y,
605 -type=>'path',
606 -closed=>'true');
607 0 $self->{_SVG_}->path(%$points,stroke=>$self->getColour($stroke),fill=>'none');
608 }
609
610
611 #string methods
612
613 =head1 string methods
614
615 =head2 string
616
617 write a text string
618
619 =cut
620
621 0 ▶sub SVG::GD::Image::string ($$$$$$) {
Subroutine string: not called CC=1 SCAR=6.9
622 0 my $self = shift;
623 0 my ($myfont,$x,$y,$text,$colour) = @_;
624 # $self->{_GD_}->string(@_);
625 $self->{_SVG_}->text(
626 0 'baseline-shift'=>'sub',
627 style=>{
628 SVG::GD::Font::getSVGstyle($myfont),
629 fill=>$self->getColour($colour),
630 },
631 x=>$x,
632 y=>$y)->tspan(dy=>'1em') ->cdata($text);
633 }
634
635 =head2 char
636
637 write a character
638
639 =cut
640
641 1 *SVG::GD::Image::char = \&SVG::GD::Image::string;
642
643 =head2 charUp
644
645 write a character upwards
646
647 =cut
648
649 0 ▶sub SVG::GD::Image::stringUp ($$$$$$) {
Subroutine stringUp: not called CC=1 SCAR=6.9
650 0 my $self = shift;
651 0 my ($myfont,$x,$y,$text,$colour) = @_;
652 # $self->{_GD_}->string(@_);
653 $self->{_SVG_}->text(
654 0 style=>{'writing-mode'=>'tb',
655 SVG::GD::Font::getSVGstyle($myfont),
656 fill=>$self->getColour($colour),
657 },
658 x=>$x,y=>$y,
659 )->cdata($text);
660 }
661 1 *SVG::GD::Image::charUp = \&SVG::GD::Image::stringUp;
662
663 #---------------
664 #internal methods
665
666
667 0 ▶sub SVG::GD::Image::getRGB($$) {
Subroutine getRGB: not called CC=1 SCAR=6.9
668 0 my $self = shift;
669 0 my $colour = shift;
670 0 return $self->{_COLOUR_}->{$colour}->{rgb};
671 }
672
673 0 ▶sub SVG::GD::Image::getColour($$) {
Subroutine getColour: not called CC=1 SCAR=6.9
674 0 my $self = shift;
675 0 my $colour = shift;
676 0 return $self->{_COLOUR_}->{$colour}->{svg};
677 }
678
679 =head2 rgb
680
681 Return the red,green,blue array for an allocated colour
682
683 =cut
684
685 0 ▶sub SVG::GD::Image::rgb ($$) {
Subroutine rgb: not called CC=1 SCAR=6.9
686 0 my $self = shift;
687 0 my $col = shift;
688 0 return @{$self->getRBG($col)};
689 }
690
691 =head2 svg
692
693 replace the gif writing request with an svg writing request
694
695 =cut
696
697 0 ▶sub SVG::GD::Image::svg ($) {
Subroutine svg: not called CC=1 SCAR=6.9
698 0 my $self = shift;
699 0 return $self->{_SVG_}->xmlify;
700 }
701
702 =head2 png
703
704 Return the binary image in PNG format
705
706 =cut
707
708 0 ▶sub SVG::GD::Image::png ($) {
Subroutine png: not called CC=1 SCAR=6.9
709 0 my $self = shift;
710 0 return $self->svg;
711 # return $self->{_GD_}->png;
712 }
713
714 =head2 jpg
715
716 Return the binary image in JPEG format
717
718 =cut
719
720 0 ▶sub SVG::GD::Image::wbmp ($$) {
Subroutine wbmp: not called CC=1 SCAR=6.9
721 0 my $self = shift;
722 # return $self->{_GD_}->wbmp(@_);
723 }
724
725 =head2 gif
726
727 Return the binary image in GIF format
728 Note that some versions of SVG::GD do not support this method
729
730 =cut
731
732 0 ▶sub SVG::GD::Image::gif ($) {
Subroutine gif: not called CC=1 SCAR=6.9
733 0 my $self = shift;
734 0 return $self->svg;
735 }
736 #------------------
737 #ignored methods that are meaningless
738 #or too difficult to implement
739
740
741 0 ▶sub SVG::GD::Image::interlaced ($) {
Subroutine interlaced: not called CC=1 SCAR=6.9
742 0 my $self = shift;
743 # $self->{_GD_}->interlaced(@_);
744 }
745
746 0 ▶sub SVG::GD::Image::transparent ($$) {
Subroutine transparent: not called CC=1 SCAR=6.9
747 0 my $self = shift;
748 0 my $colour = shift;
749 # $self->{_GD_}->transparent($colour)
750 }
751
752 0 ▶sub SVG::GD::Image::fill ($$$$) {
Subroutine fill: not called CC=1 SCAR=6.9
753 0 my $self = shift;
754 0 my ($x,$y,$colour) = @_;
755 # $self->{_GD_}->fill(@_);
756 }
757
758 0 ▶sub SVG::GD::Image::fillToBorder ($$$$) {
Subroutine fillToBorder: not called CC=1 SCAR=6.9
759 0 my $self = shift;
760 0 my ($x,$y,$colour) = @_;
761 # $self->{_GD_}->fillToBorder(@_);
762 }
763
764 ############################################################################
765 #
766 # new methods on GD::Image
767 #
768 ############################################################################
769
770 0 ▶sub SVG::GD::Image::polyline ($$$) {
Subroutine polyline: not called CC=2 SCAR=17.9
771 0 my $self = shift; # the GD::Image
772 0 my $p = shift; # the GD::Polyline (or GD::Polygon)
773 0 my $c = shift; # the color
774
775 0 my @points = $p->vertices();
776 0 my $p1 = shift @points;
777 0 my $p2;
778 0 ▶ while ($p2 = shift @points) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p2 = shift @points) 0 0 0
779 0 $self->line(@$p1, @$p2, $c);
780 0 $p1 = $p2;
781 }
782 }
783
784 0 ▶sub GD::Image::polydraw ($$$) {
Subroutine polydraw: not called CC=2 SCAR=17.9
785 0 my $self = shift; # the GD::Image
786 0 my $p = shift; # the GD::Polyline or GD::Polygon
787 0 my $c = shift;
788 # the color return
789 0 ▶ $self->polyline($p, $c) if $p->isa('GD::Polyline');
Branch: 1 branch
BranchTrueFalseTotal
if $p->isa("GD::Polyline") 0 0 0
790 0 return $self->polygon($p, $c);
791 }
792
793 0 ▶sub setBrush ($$) {
Subroutine setBrush: not called CC=1 SCAR=6.9
794 0 my $self = shift;
795 0 my $brush = shift;
796 0 return "Sorry..Ignoring this command. Unable to setBrush with this version
797 of SVG::GD";
798 }
799
800
801
↑ Summary