1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/usr/bin/perl -w
#
# svg_dropshadow
#
# Creates drop shadows for all svg elements specified by --id, or
# whole file if no ids are given.
#
# Authors: Daniel Goude (goude@dtek.chalmers.se)
#
use strict;
use warnings;
use File::Basename();
use lib File::Basename::dirname($0);
use SpSVG;
my $sp = new SpSVG;
# Set the script name, used when displaying --help
$sp->set_name($0);
# Set usage string (options are handled separately).
my $usage = <<EOF;
Creates drop shadows from svg group(s)
EOF
$sp->set_usage($usage);
# Set script specific options and description (used for --help)
# SpSVG will hasdle in/out files, and help
my @opt_vals = (
{
"opt" => "color=s",
"desc" => "Shadow color (default black)",
},
{
"opt" => "opacity=s",
"desc" => "Shadow offset (0-1, default 0.5)",
},
{
"opt" => "offset=s",
"desc" => "Shadow offset, default 10",
},
);
my %opts = $sp->get_opts(@opt_vals);
my $color = $opts{'color'} || 'black';
my $opacity = $opts{'opacity'} || '0.5';
my $offset= $opts{'offset'} || '10';
# Read input file (from --file or STDIN)
$sp->parse;
# Apply make_shadow to selected ids, or whole file
$sp->process_ids(\&make_shadow);
# Dump the file (to --output or STDOUT)
$sp->dump;
# That's it!
# make_shadow takes an svg fragment and returns named fragment
# with a shadow added
sub make_shadow {
my $element = shift;
# Duplicate element
my $shadow = $element;
# Set shadow color
$shadow =~ s/(stroke|fill):[^;]+;/$1:$color;/ig;
my $svg = <<EOF;
<svg:g id="fooz" style="opacity:$opacity;" transform="translate($offset,
$offset)">
$shadow
</svg:g>
$element
EOF
return $svg;
}
|