home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Inkscape / Inkscape-0.48.2-1-win32.exe / share / extensions / handles.py < prev    next >
Text File  |  2011-07-08  |  2KB  |  59 lines

  1. #!/usr/bin/env python 
  2. '''
  3. Copyright (C) 2005 Aaron Spike, aaron@ekips.org
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. '''
  19. import inkex, simplepath, simplestyle
  20.  
  21. class Handles(inkex.Effect):
  22.     def effect(self):
  23.         for id, node in self.selected.iteritems():
  24.             if node.tag == inkex.addNS('path','svg'):
  25.                 p = simplepath.parsePath(node.get('d'))
  26.                 a =[]
  27.                 pen = None
  28.                 subPathStart = None
  29.                 for cmd,params in p:
  30.                     if cmd == 'C':
  31.                         a.extend([['M', params[:2]], ['L', pen],
  32.                             ['M', params[2:4]], ['L', params[-2:]]])
  33.                     if cmd == 'Q':
  34.                         a.extend([['M', params[:2]], ['L', pen],
  35.                             ['M', params[:2]], ['L', params[-2:]]])
  36.                     
  37.                     if cmd == 'M':
  38.                         subPathStart = params
  39.  
  40.                     if cmd == 'Z':
  41.                         pen = subPathStart
  42.                     else:
  43.                         pen = params[-2:]
  44.                     
  45.                 if len(a) > 0:
  46.                     s = {'stroke-linejoin': 'miter', 'stroke-width': '1.0px', 
  47.                         'stroke-opacity': '1.0', 'fill-opacity': '1.0', 
  48.                         'stroke': '#000000', 'stroke-linecap': 'butt', 
  49.                         'fill': 'none'}
  50.                     attribs = {'style':simplestyle.formatStyle(s),'d':simplepath.formatPath(a)}
  51.                     inkex.etree.SubElement(node.getparent(), inkex.addNS('path','svg'), attribs)
  52.                     
  53. if __name__ == '__main__':
  54.     e = Handles()
  55.     e.affect()
  56.  
  57.  
  58. # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99
  59.