summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 199b6b9)
raw | patch | inline | side by side (parent: 199b6b9)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Wed, 10 Jan 2007 00:17:46 +0000 (00:17 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Wed, 10 Jan 2007 00:17:46 +0000 (00:17 +0000) |
share/extensions/coloreffect.py | patch | blob | history |
index 6881994750e2c767526c76847caf6cf2df67815f..2708b48f3930fc8bad575265db962bbc242eabcc 100644 (file)
\r
import xml.xpath\r
\r
+import random\r
+\r
color_props_fill=('fill:','stop-color:','flood-color:','lighting-color:')\r
color_props_stroke=('stroke:',)\r
color_props = color_props_fill + color_props_stroke\r
styles[i]=color_props[c]+self.process_prop(styles[i][len(color_props[c]):])\r
#inkex.debug('new style:'+';'.join(styles))\r
node.setAttribute('style',';'.join(styles))\r
- '''\r
- def changeStyle(self,node):\r
- if node.hasAttributes():\r
- sa=node.getAttribute('style')\r
- if sa!='':\r
- debug(sa)\r
- styles=simplestyle.parseStyle(sa)\r
- for c in range(len(colortags)):\r
- if colortags[c] in styles.keys():\r
- styles[colortags[c]]=self.process_prop(styles[colortags[c]])\r
- node.setAttribute('style',simplestyle.formatStyle(styles))\r
- ''' \r
+\r
def process_prop(self,col):\r
#debug('got:'+col)\r
if simplestyle.isColor(col):\r
#debug('made:'+col)\r
if col.startswith('url(#'):\r
id = col[len('url(#'):col.find(')')]\r
+ newid = '%s-%d' % (id, int(random.random() * 1000))\r
#inkex.debug('ID:' + id )\r
path = '//*[@id="%s"]' % id\r
for node in xml.xpath.Evaluate(path,self.document):\r
- self.process_gradient(node)\r
+ self.process_gradient(node, newid)\r
+ col = 'url(#%s)' % newid\r
return col\r
\r
- def process_gradient(self, node):\r
- if node.hasAttributes(): \r
- this_id=node.getAttribute('id')\r
- if this_id in self.visited:\r
- # prevent multiple processing of the same gradient if it is used by more than one selected object\r
- #inkex.debug("already had: " + this_id)\r
- return\r
- self.visited.append(this_id)\r
+ def process_gradient(self, node, newid):\r
+ #if node.hasAttributes(): \r
+ #this_id=node.getAttribute('id')\r
+ #if this_id in self.visited:\r
+ ## prevent multiple processing of the same gradient if it is used by more than one selected object\r
+ ##inkex.debug("already had: " + this_id)\r
+ #return\r
+ #self.visited.append(this_id)\r
#inkex.debug("visited: " + str(self.visited))\r
- self.changeStyle(node)\r
- if node.hasChildNodes():\r
- for child in node.childNodes:\r
- self.process_gradient(child)\r
- if node.hasAttributes(): \r
- href=node.getAttribute('xlink:href')\r
+ newnode = node.cloneNode(True)\r
+ newnode.setAttribute('id', newid)\r
+ node.parentNode.appendChild(newnode)\r
+ self.changeStyle(newnode)\r
+ if newnode.hasChildNodes():\r
+ for child in newnode.childNodes:\r
+ self.changeStyle(child)\r
+ if newnode.hasAttributes(): \r
+ href=newnode.getAttribute('xlink:href')\r
if href.startswith('#'):\r
id = href[len('#'):len(href)]\r
#inkex.debug('ID:' + id )\r
+ newhref = '%s-%d' % (id, int(random.random() * 1000))\r
+ newnode.setAttribute('xlink:href', '#%s' % newhref)\r
path = '//*[@id="%s"]' % id\r
for node in xml.xpath.Evaluate(path,self.document):\r
- self.process_gradient(node)\r
+ self.process_gradient(node, newhref)\r
\r
def colmod(self,r,g,b):\r
pass\r