comparison pyink/tween.py @ 1284:cbcb91b196fa

Use svg:use to duplicate the key frame. The current inkscape will not keep the extra attributes when we break the reference. Therefore, we may modify the inkscape directly or implemnet a break by ourself. In addition, we may need to improve the duplication to sync the new-added objects to an existed group.
author wycc
date Sat, 15 Jan 2011 02:43:20 +0800
parents ccbf0c5d01d1
children 7f0a16125eeb
comparison
equal deleted inserted replaced
1283:a6aba785656e 1284:cbcb91b196fa
243 obj.appendChild(top) 243 obj.appendChild(top)
244 else: 244 else:
245 top = newobj 245 top = newobj
246 newobj = newobj.firstChild() 246 newobj = newobj.firstChild()
247 pass 247 pass
248 248 print s.name()
249 if s.name() == 'svg:g': 249 if s.name() == 'svg:g' or s.name() == 'svg:use':
250 # Parse the translate or matrix 250 # Parse the translate or matrix
251 # 251 #
252 # D = B inv(A) 252 # D = B inv(A)
253 try: 253 try:
254 (ox,oy) = s.spitem.getCenter() 254 (ox,oy) = s.spitem.getCenter()
276 sm = self.parseTransform(s) 276 sm = self.parseTransform(s)
277 ss = self.decomposition(sm) 277 ss = self.decomposition(sm)
278 dm = self.parseTransform(d) 278 dm = self.parseTransform(d)
279 dd = self.decomposition(dm) 279 dd = self.decomposition(dm)
280 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] 280 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0]
281 sy = (ss[1]*(1-p)+dd[1]*p)/ss[0] 281 sy = (ss[1]*(1-p)+dd[1]*p)/ss[1]
282 a = ss[2]*(1-p)+dd[2]*p-ss[2] 282 a = ss[2]*(1-p)+dd[2]*p-ss[2]
283 tx = ox*(1-p)+dx*p 283 tx = ox*(1-p)+dx*p
284 ty = oy*(1-p)+dy*p 284 ty = oy*(1-p)+dy*p
285 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] 285 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0]
286 m = self.mulA([sx,0,0,sy,0,0],m) 286 m = self.mulA([sx,0,0,sy,0,0],m)
288 m = self.mulA([1,0,0,1,tx,self.height-ty],m) 288 m = self.mulA([1,0,0,1,tx,self.height-ty],m)
289 289
290 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) 290 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5]))
291 else: 291 else:
292 try: 292 try:
293 try: 293 if d.name() == "svg:use":
294 sw = float(s.getAttribute("width"))
295 except:
296 sw = 1 294 sw = 1
297 try:
298 sh = float(s.getAttribute("height"))
299 except:
300 sh = 1 295 sh = 1
301 try:
302 dw = float(d.getAttribute("width"))
303 except:
304 dw = 1 296 dw = 1
305 try:
306 dh = float(d.getAttribute("height"))
307 except:
308 dh = 1 297 dh = 1
298 else:
299 try:
300 sw = float(s.getAttribute("width"))
301 except:
302 sw = 1
303 try:
304 sh = float(s.getAttribute("height"))
305 except:
306 sh = 1
307
308 try:
309 dw = float(d.getAttribute("width"))
310 except:
311 dw = 1
312 try:
313 dh = float(d.getAttribute("height"))
314 except:
315 dh = 1
316 pass
317
309 try: 318 try:
310 start_opacity = parse_opacity(s) 319 start_opacity = parse_opacity(s)
311 except: 320 except:
312 start_opacity = 1 321 start_opacity = 1
322 pass
313 323
314 try: 324 try:
315 end_opacity =parse_opacity( d) 325 end_opacity =parse_opacity( d)
326 if d.name() == "svg:use":
327 end_opacity = end_opacity * start_opacity
328 pass
329 pass
316 except: 330 except:
317 end_opacity = 1 331 if d.name() == "svg:use":
332 end_opacity = start_opacity
333 else:
334 end_opacity = 1
335 pass
336
318 cur_opacity = start_opacity*(1-p)+end_opacity*p 337 cur_opacity = start_opacity*(1-p)+end_opacity*p
319 change_opacity(newobj,cur_opacity) 338 change_opacity(newobj,cur_opacity)
320 339
321 try: 340 try:
322 (ox,oy) = s.spitem.getCenter() 341 (ox,oy) = s.spitem.getCenter()