index 7e5407e6a05d52c82f2fd72b0fee588248a1d107..1b28f1bffd9a97dfa1e02d6f1e1bef3735e7f1c6 100755 (executable)
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
-import inkex, cubicsuperpath, simplestyle, copy, math, re, bezmisc
+import inkex, cubicsuperpath, simplestyle, copy, math, bezmisc
-uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'pc':15.0}
def numsegs(csp):
return sum([len(p)-1 for p in csp])
def interpcoord(v1,v2,p):
lengths[-1].append(l)
total += l
return lengths, total
-def styleunittouu(string):
- unit = re.compile('(%s)$' % '|'.join(uuconv.keys()))
- param = re.compile(r'(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)')
-
- p = param.match(string)
- u = unit.search(string)
- if p:
- retval = float(p.string[p.start():p.end()])
- else:
- retval = 0.0
- if u:
- try:
- return retval * uuconv[u.string[u.start():u.end()]]
- except KeyError:
- pass
- return retval
def tweenstylefloat(property, start, end, time):
sp = float(start[property])
ep = float(end[property])
return str(sp + (time * (ep - sp)))
def tweenstyleunit(property, start, end, time):
- sp = styleunittouu(start[property])
- ep = styleunittouu(end[property])
+ sp = inkex.unittouu(start[property])
+ ep = inkex.unittouu(end[property])
return str(sp + (time * (ep - sp)))
def tweenstylecolor(property, start, end, time):
sr,sg,sb = parsecolor(start[property])
styles = {}
for id in self.options.ids:
node = self.selected[id]
- if node.tagName =='path':
- paths[id] = cubicsuperpath.parsePath(node.attributes.getNamedItem('d').value)
- styles[id] = simplestyle.parseStyle(node.attributes.getNamedItem('style').value)
+ if node.tag ==inkex.addNS('path','svg'):
+ paths[id] = cubicsuperpath.parsePath(node.get('d'))
+ styles[id] = simplestyle.parseStyle(node.get('style'))
else:
self.options.ids.remove(id)
if self.options.dup:
steps = [0] + steps + [1]
#create an interpolated path for each interval
- group = self.document.createElement('svg:g')
- self.document.documentElement.appendChild(group)
+ group = inkex.etree.SubElement(self.current_layer,inkex.addNS('g','svg'))
for time in steps:
interp = []
#process subpaths
#remove final subpath if empty.
if not interp[-1]:
del interp[-1]
- new = self.document.createElement('svg:path')
#basic style tweening
if self.options.style:
if dofill:
basestyle['fill-opacity'] = tweenstylefloat('fill-opacity',sst,est,time)
basestyle['fill'] = tweenstylecolor('fill',sst,est,time)
- new.setAttribute('style', simplestyle.formatStyle(basestyle))
- new.setAttribute('d', cubicsuperpath.formatPath(interp))
- group.appendChild(new)
+ attribs = {'style':simplestyle.formatStyle(basestyle),'d':cubicsuperpath.formatPath(interp)}
+ new = inkex.etree.SubElement(group,inkex.addNS('path','svg'), attribs)
e = Interp()
e.affect()