-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultiscale.py
106 lines (91 loc) · 4.23 KB
/
multiscale.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
"""
Copyright (C) 2010 Blair Bonnett, [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import gettext
_ = gettext.gettext
import inkex
import pathmodifier
import simpletransform
class MultiScaleEffect(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option('-x', '--xstart', action='store',
type='float', dest='xstart',
default=1.0, help='Starting scale for width')
self.OptionParser.add_option('-f', '--xfinish', action='store',
type='float', dest='xfinish',
default=1.0, help='Finishing scale for width')
self.OptionParser.add_option('-p', '--xpos', action='store',
type='string', dest='xpos',
default='scaled', help='X position of scaled objects')
self.OptionParser.add_option('-s', '--ysame', action='store',
type='inkbool', dest='ysame',
default=False, help='Use same scaling for height as width')
self.OptionParser.add_option('-y', '--ystart', action='store',
type='float', dest='ystart',
default=1.0, help='Starting scale for height')
self.OptionParser.add_option('-g', '--yfinish', action='store',
type='float', dest='yfinish',
default=1.0, help='Finishing scale for height')
self.OptionParser.add_option('-q', '--ypos', action='store',
type='string', dest='ypos',
default='scaled', help='Y position of scaled objects')
def effect(self):
# Check we have enough objects selected
count = len(self.selected)
if count < 2:
inkex.errormsg(_("Please select at least two objects."))
# The step in scale between each object
xstep = (self.options.xfinish - self.options.xstart)/(count - 1)
if self.options.ysame:
ystep = xstep
else:
ystep = (self.options.yfinish - self.options.ystart)/(count - 1)
# Starting scales
xscale = self.options.xstart
if self.options.ysame:
yscale = xscale
else:
yscale = self.options.ystart
# Sort selected objects by z order, lowest first
id_list = self.selected.keys()
id_list = pathmodifier.zSort(self.document.getroot(), id_list)
# Scale each object
for id in id_list:
# No scaling actually happening
if xscale == 1.0 and yscale == 1.0:
xscale += xstep
yscale += ystep
continue
# Get node and current transformations
node = self.selected[id]
transform = node.get('transform')
# Scale the object as desired
if transform:
if xscale == yscale:
transform += ' scale(%f)' % (xscale)
else:
transform += ' scale(%f, %f)' % (xscale, yscale)
else:
if xscale == yscale:
transform = 'scale(%f)' % (xscale)
else:
transform = 'scale(%f, %f)' % (xscale, yscale)
node.set('transform', transform)
# Change the scale ready for the next object
xscale += xstep
yscale += ystep
if __name__ == '__main__':
e = MultiScaleEffect()
e.affect()