Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
/usr/bin/env python
"""
Copyright (C) 2005 Aaron Spike, aaron@ekips.org
You should have received a copy of the GNU General Public License
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, os, simplepath, cubicsuperpath
from ffgeom import *
import gettext
_ = gettext.gettext
try:
from subprocess import Popen, PIPE
bsubprocess = True
except:
bsubprocess = False
class Project(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
def effect(self):
if len(self.options.ids) < 2:
inkex.errormsg(_("This extension requires two selected paths. \nThe second
path must be exactly four nodes long."))
exit()
if obj.tag == inkex.addNS("path",'svg'):
self.process_path(obj)
if obj.tag == inkex.addNS("g",'svg'):
self.process_group(obj)
else:
if trafo.tag == inkex.addNS('g','svg'):
inkex.errormsg(_("The second selected object is a group, not a
path.\nTry using the procedure Object->Ungroup."))
else:
inkex.errormsg(_("The second selected object is not a path.\nTry using
the procedure Path->Object to Path."))
exit()
else:
inkex.errormsg(_("The first selected object is not a path.\nTry using the
procedure Path->Object to Path."))
exit()
def process_group(self,group):
for node in group:
if node.tag == inkex.addNS('path','svg'):
self.process_path(node)
if node.tag == inkex.addNS('g','svg'):
self.process_group(node)
def process_path(self,path):
d = path.get('d')
p = cubicsuperpath.parsePath(d)
for subs in p:
for csp in subs:
csp[0] = self.trafopoint(csp[0])
csp[1] = self.trafopoint(csp[1])
csp[2] = self.trafopoint(csp[2])
path.set('d',cubicsuperpath.formatPath(p))
def trafopoint(self,(x,y)):
#Transform algorithm thanks to Jose Hevia (freon)
vector = Segment(Point(self.q['x'],self.q['y']),Point(x,y))
xratio = abs(vector.delta_x())/self.q['width']
yratio = abs(vector.delta_y())/self.q['height']
horz = Segment(self.t1.pointAtRatio(xratio),self.t3.pointAtRatio(xratio))
vert = Segment(self.t4.pointAtRatio(yratio),self.t2.pointAtRatio(yratio))
p = intersectSegments(vert,horz)
return [p['x'],p['y']]
if __name__ == '__main__':
e = Project()
e.affect()