本文整理汇总了Python中simpletransform.parseTransform函数的典型用法代码示例。如果您正苦于以下问题:Python parseTransform函数的具体用法?Python parseTransform怎么用?Python parseTransform使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseTransform函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: match
def match( p1, p2, a1, a2 ):
x = 0
y = 1
# distances
dp = [ p2[x]-p1[x], p2[y]-p1[y] ]
da = [ a2[x]-a1[x], a2[y]-a1[y] ]
# angles
angle_p = math.atan2( dp[x], dp[y] )
angle_a = math.atan2( da[x], da[y] )
# radians
#rp = math.sqrt( dp[x]*dp[x] + dp[y]*dp[y] )
#ra = math.sqrt( da[x]*da[x] + da[y]*da[y] )
rp = math.hypot( dp[x], dp[y] )
ra = math.hypot( da[x], da[y] )
# scale
scale = ra / rp
# transforms in the order they are applied
t1 = simpletransform.parseTransform( "translate(%f,%f)"%(-p1[x],-p1[y]) )
#t2 = simpletransform.parseTransform( "rotate(%f)"%(-angle_p) )
#t3 = simpletransform.parseTransform( "scale(%f,%f)"%(scale,scale) )
#t4 = simpletransform.parseTransform( "rotate(%f)"%angle_a )
t2 = rotateTransform(-angle_p)
t3 = scaleTransform( scale, scale )
t4 = rotateTransform( angle_a )
t5 = simpletransform.parseTransform( "translate(%f,%f)"%(a1[x],a1[y]) )
# transforms in the order they are multiplied
t = t5
t = simpletransform.composeTransform( t, t4 )
t = simpletransform.composeTransform( t, t3 )
t = simpletransform.composeTransform( t, t2 )
t = simpletransform.composeTransform( t, t1 )
# return the combined transform
return t
开发者ID:shlomif,项目名称:Bezier-Envelope-for-Inkscape,代码行数:33,代码来源:bezierenvelope.py
示例2: getHpgl
def getHpgl(self):
# dryRun to find edges
groupmat = [[self.mirrorX * self.scaleX * self.viewBoxTransformX, 0.0, 0.0], [0.0, self.mirrorY * self.scaleY * self.viewBoxTransformY, 0.0]]
groupmat = simpletransform.composeTransform(groupmat, simpletransform.parseTransform('rotate(' + self.options.orientation + ')'))
self.vData = [['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0]]
self.processGroups(self.doc, groupmat)
if self.divergenceX == 'False' or self.divergenceY == 'False' or self.sizeX == 'False' or self.sizeY == 'False':
raise Exception('NO_PATHS')
# live run
self.dryRun = False
if self.options.center:
self.divergenceX += (self.sizeX - self.divergenceX) / 2
self.divergenceY += (self.sizeY - self.divergenceY) / 2
elif self.options.useToolOffset:
self.options.offsetX += self.options.toolOffset
self.options.offsetY += self.options.toolOffset
groupmat = [[self.mirrorX * self.scaleX * self.viewBoxTransformX, 0.0, - self.divergenceX + self.options.offsetX],
[0.0, self.mirrorY * self.scaleY * self.viewBoxTransformY, - self.divergenceY + self.options.offsetY]]
groupmat = simpletransform.composeTransform(groupmat, simpletransform.parseTransform('rotate(' + self.options.orientation + ')'))
self.vData = [['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0], ['', -1.0, -1.0]]
# store first hpgl commands
self.hpgl = 'IN;SP%d' % self.options.pen
# add precut
if self.options.useToolOffset and self.options.precut:
self.processOffset('PU', 0, 0)
self.processOffset('PD', 0, self.options.toolOffset * 8)
# start conversion
self.processGroups(self.doc, groupmat)
# shift an empty node in in order to process last node in cache
self.processOffset('PU', 0, 0)
# add return to zero point
self.hpgl += ';PU0,0;'
return self.hpgl
开发者ID:zanqi,项目名称:inkscape,代码行数:33,代码来源:hpgl_encoder.py
示例3: _merge_transform
def _merge_transform(self, node, transform):
"""Propagate style and transform to remove inheritance
Originally from
https://github.com/nikitakit/svg2sif/blob/master/synfig_prepare.py#L370
"""
# Compose the transformations
if node.tag == addNS("svg", "svg") and node.get("viewBox"):
vx, vy, vw, vh = [self._get_dimension(x)
for x in node.get("viewBox").split()]
dw = self._get_dimension(node.get("width", vw))
dh = self._get_dimension(node.get("height", vh))
t = ("translate(%f, %f) scale(%f, %f)" %
(-vx, -vy, dw / vw, dh / vh))
this_transform = simpletransform.parseTransform(
t, transform)
this_transform = simpletransform.parseTransform(
node.get("transform"), this_transform)
del node.attrib["viewBox"]
else:
this_transform = simpletransform.parseTransform(node.get(
"transform"), transform)
# Set the node's transform attrib
node.set("transform",
simpletransform.formatTransform(this_transform))
开发者ID:brentini,项目名称:inkscape-ungroup-deep,代码行数:26,代码来源:ungroup_deep.py
示例4: parse_gradient
def parse_gradient(self, node, d):
if node.tag == addNS("linearGradient", "svg"):
gradient_id = node.get("id", str(id(node)))
x1 = float(node.get("x1", "0.0"))
x2 = float(node.get("x2", "0.0"))
y1 = float(node.get("y1", "0.0"))
y2 = float(node.get("y2", "0.0"))
mtx = simpletransform.parseTransform(node.get("gradientTransform"))
link = node.get(addNS("href", "xlink"), "#")[1:]
spread_method = node.get("spreadMethod", "pad")
if link == "":
stops = self.parse_stops(node, d)
d.add_linear_gradient(gradient_id, [x1, y1], [x2, y2], mtx, stops=stops, spread_method=spread_method)
else:
d.add_linear_gradient(gradient_id, [x1, y1], [x2, y2], mtx, link=link, spread_method=spread_method)
elif node.tag == addNS("radialGradient", "svg"):
gradient_id = node.get("id", str(id(node)))
cx = float(node.get("cx", "0.0"))
cy = float(node.get("cy", "0.0"))
r = float(node.get("r", "0.0"))
fx = float(node.get("fx", "0.0"))
fy = float(node.get("fy", "0.0"))
mtx = simpletransform.parseTransform(node.get("gradientTransform"))
link = node.get(addNS("href", "xlink"), "#")[1:]
spread_method = node.get("spreadMethod", "pad")
if link == "":
stops = self.parse_stops(node, d)
d.add_radial_gradient(gradient_id, [cx, cy], r, [fx, fy], mtx, stops=stops, spread_method=spread_method)
else:
d.add_radial_gradient(gradient_id, [cx, cy], r, [fx, fy], mtx, link=link, spread_method=spread_method)
开发者ID:Grandrogue,项目名称:inkscape_metal,代码行数:34,代码来源:synfig_output.py
示例5: effect
def effect(self):
self.getselected()
if self.selected:
for id, shape in self.selected.items():
self.recursiveFuseTransform(shape, parseTransform(None))
else:
self.recursiveFuseTransform(self.document.getroot(), parseTransform(None))
开发者ID:Klowner,项目名称:inkscape-applytransforms,代码行数:8,代码来源:applytransform.py
示例6: recursivelyTraverseSvg
def recursivelyTraverseSvg(self, nodeList=None, matCurrent=[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]], parent_visibility='visible' ):
""" Based on the Eggbot extension for Inkscape.
Recursively traverse the svg file to plot out all the paths. Keeps track of the composite transformation that should be applied to each path.
Handles path, group.
Doesn't yet handle line, text, rect, polyline, polygon, circle, ellipse and use (clone) elements.
Unhandled elements should be converted to paths in Inkscape.
Probably want to avoid paths with holes inside.
"""
if not nodeList:
nodeList = self.svgRoot
# get svg document width and height
width, units_width = self.parseLengthAndUnits(nodeList.get("width"))
height, units_height = self.parseLengthAndUnits(nodeList.get("height"))
if units_width != units_height:
print "Weird, units for SVG root document width and height differ..."
print nodeList.get("width")
print nodelist.get("height")
sys.exit(1)
# set initial viewbox from document root
viewbox = nodeList.get("viewBox")
print "Document size: %f x %f (%s)" % (width, height, units_width)
if viewbox:
vinfo = viewbox.strip().replace(',', ' ').split(' ')
if (vinfo[2] != 0) and (vinfo[3] != 0):
sx = width / float(vinfo[2])
sy = height / float(vinfo[3])
matCurrent = simpletransform.parseTransform("scale(%f, %f) translate(%f, %f)" % (sx, sy, -float(vinfo[0]), -float(vinfo[1])))
print "Initial transformation matrix:", matCurrent
for node in nodeList:
# Ignore invisible nodes
v = node.get('visibility', parent_visibility)
if v == 'inherit':
v = parent_visibility
if v == 'hidden' or v == 'collapse':
pass
# first apply the current matrix transform to this node's transform
matNew = simpletransform.composeTransform( matCurrent, simpletransform.parseTransform(node.get("transform")) )
if node.tag in [self.svgQName("g"), "g"]:
print "group tag - Might not be handled right!"
self.recursivelyTraverseSvg( list(node), matNew, v )
elif node.tag in [self.svgQName("path")]:
self.plotPath( node, matNew )
else:
print "Other tag: '%s'" % node.tag
开发者ID:wayneandlayne,项目名称:svg2kicadmod,代码行数:56,代码来源:SvgParser.py
示例7: effect
def effect(self):
object2path.ObjectToPath.effect(self)
transformMatrix = [[1,0,0],[0,1,0]]
dims = self.determine_dims(transformMatrix)
[x,y,X,Y] = dims
width = X - x
height = Y - y
# Longest side is vertical
if width > height:
scale = 480.0 / height
if scale * width > 999.0:
inkex.errormsg("Plot area is to large (%f > 999)." % scale*height)
exit()
transformMatrix = parseTransform('translate(%f,%f)' % (-x,-y))
transformMatrix = composeTransform(parseTransform('rotate(-90)'), transformMatrix)
transformMatrix = composeTransform(parseTransform('scale(%f,%f)' % (scale,scale)), transformMatrix)
else:
scale = 480.0 / width
if scale * height > 999.0:
inkex.errormsg("Plot area is to large (%f > 999)." % scale*height)
exit()
transformMatrix = parseTransform('translate(%f,%f)' % (-x,-y))
transformMatrix = composeTransform(parseTransform('rotate(180)'), transformMatrix)
transformMatrix = composeTransform(parseTransform('translate(%f,0)' % width), transformMatrix)
transformMatrix = composeTransform(parseTransform('scale(%f,%f)' % (-scale,scale)), transformMatrix)
transformMatrix = composeTransform(parseTransform('translate(480,0)'), transformMatrix)
paths = []
for [path, node] in self.processPaths(transformMatrix):
color = (0, 0, 0)
style = node.get('style')
if style:
style = simplestyle.parseStyle(style)
if 'stroke' in style:
if style['stroke'] and style['stroke'] != 'none':
color = simplestyle.parseColor(style['stroke'])
points = []
for point in self.processPath(path):
points.append(point)
paths.append({'color':color, 'points':points})
dims = self.determine_dims(transformMatrix)
if self.options.debug:
print >>sys.stderr, "VC1520 debug info"
print >>sys.stderr, "-----------------"
print >>sys.stderr, "plot area: minX:%d, minY:%d, maxX:%d, maxY:%d" % tuple(dims)
print >>sys.stderr, "nr paths: %d" % len(paths)
i = 0
print >>sys.stderr, "path;color;points"
for path in paths:
print >>sys.stderr, "%d;%s;%d" % (i,self.find_color(path['color']),len(path['points']))
i += 1
for path in paths:
print >>sys.stderr, path
else:
self.plot(paths, dims[1])
开发者ID:nanoflite,项目名称:inkscape-VC1520,代码行数:59,代码来源:sendto_vc1520.py
示例8: translateElement
def translateElement(self, node, x, y, relative=False):
# Grab transform attribute if it exists.
transform = node.get("transform", "")
# Compute the nodes bounding box
box = list(simpletransform.computeBBox([node]))
pos_x = box[0]
pos_y = box[2]
# rotation center is not a breeze to calculate from the matrix, so thanks inkscape ;)
origin_x = float(node.get(inkex.addNS("transform-center-x", "inkscape"), 0))
origin_y = float(node.get(inkex.addNS("transform-center-y", "inkscape"), 0))
origin_x = origin_x + (box[1] / 2)
origin_y = (origin_y * -1) + (box[3] / 2)
if transform == "":
# If there is no transform attribute on the node we add one
node.attrib["transform"] = ""
# simpletransform returns a multi dim array of matrix values
transform = simpletransform.parseTransform(transform)
transformObject = self.normalizeMatrix(transform)
inkex.debug(transformObject)
# offset_x = (transform[0][2]-pos_x)
# offset_y = (transform[1][2]-pos_y)
offset_x = pos_x * -1
offset_y = pos_y * -1
inkex.debug([offset_x, offset_y])
transform = simpletransform.parseTransform(
("translate(" + str(offset_x) + " " + str(offset_y) + ")"), transform
)
transformObject = self.normalizeMatrix(transform)
inkex.debug(transformObject)
inkex.debug(transform)
if relative == False:
matrix = simpletransform.formatTransform(transform)
node.set("transform", matrix)
inkex.debug(matrix)
else:
simpletransform.applyTransformToNode(transform, node)
开发者ID:brentini,项目名称:ExtractElements,代码行数:48,代码来源:larscwallin.inx.extractelements.py
示例9: _merge_clippath
def _merge_clippath(self, node, clippathurl):
if (clippathurl):
node_transform = simpletransform.parseTransform(
node.get("transform"))
if (node_transform):
# Clip-paths on nodes with a transform have the transform
# applied to the clipPath as well, which we don't want. So, we
# create new clipPath element with references to all existing
# clippath subelements, but with the inverse transform applied
inverse_node_transform = simpletransform.formatTransform(
self._invert_transform(node_transform))
new_clippath = inkex.etree.SubElement(
self.xpathSingle('//svg:defs'), 'clipPath',
{'clipPathUnits': 'userSpaceOnUse',
'id': self.uniqueId("clipPath")})
clippath = self.getElementById(clippathurl[5:-1])
for c in (clippath.iterchildren()):
inkex.etree.SubElement(
new_clippath, 'use',
{inkex.addNS('href', 'xlink'): '#' + c.get("id"),
'transform': inverse_node_transform,
'id': self.uniqueId("use")})
# Set the clippathurl to be the one with the inverse transform
clippathurl = "url(#" + new_clippath.get("id") + ")"
# Reference the parent clip-path to keep clipping intersection
# Find end of clip-path chain and add reference there
node_clippathurl = node.get("clip-path")
while (node_clippathurl):
node = self.getElementById(node_clippathurl[5:-1])
node_clippathurl = node.get("clip-path")
node.set("clip-path", clippathurl)
开发者ID:sapphire008,项目名称:Python,代码行数:31,代码来源:inkscape_deep_ungroup_all.py
示例10: process_clone
def process_clone(self, node):
trans = node.get('transform')
x = node.get('x')
y = node.get('y')
mat = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
if trans:
mat = simpletransform.composeTransform(mat, simpletransform.parseTransform(trans))
if x:
mat = simpletransform.composeTransform(mat, [[1.0, 0.0, float(x)], [0.0, 1.0, 0.0]])
if y:
mat = simpletransform.composeTransform(mat, [[1.0, 0.0, 0.0], [0.0, 1.0, float(y)]])
# push transform
if trans or x or y:
self.groupmat.append(simpletransform.composeTransform(self.groupmat[-1], mat))
# get referenced node
refid = node.get(inkex.addNS('href','xlink'))
refnode = self.getElementById(refid[1:])
if refnode is not None:
if refnode.tag == inkex.addNS('g','svg'):
self.process_group(refnode)
elif refnode.tag == inkex.addNS('use', 'svg'):
self.process_clone(refnode)
else:
self.process_shape(refnode, self.groupmat[-1])
# pop transform
if trans or x or y:
self.groupmat.pop()
开发者ID:Drooids,项目名称:inkscape,代码行数:27,代码来源:print_win32_vector.py
示例11: process_group
def process_group(self, group):
if group.get(inkex.addNS('groupmode', 'inkscape')) == 'layer':
style = group.get('style')
if style:
style = simplestyle.parseStyle(style)
if style.has_key('display'):
if style['display'] == 'none' and self.options.layer_option and self.options.layer_option=='visible':
return
layer = group.get(inkex.addNS('label', 'inkscape'))
if self.options.layer_name and self.options.layer_option and self.options.layer_option=='name' and not layer.lower() in self.options.layer_name:
return
layer = layer.replace(' ', '_')
if layer in self.layers:
self.layer = layer
trans = group.get('transform')
if trans:
self.groupmat.append(simpletransform.composeTransform(self.groupmat[-1], simpletransform.parseTransform(trans)))
for node in group:
if node.tag == inkex.addNS('g','svg'):
self.process_group(node)
elif node.tag == inkex.addNS('use', 'svg'):
self.process_clone(node)
else:
self.process_shape(node, self.groupmat[-1])
if trans:
self.groupmat.pop()
开发者ID:AakashDabas,项目名称:inkscape,代码行数:27,代码来源:dxf_outlines.py
示例12: mergeTransform
def mergeTransform(self, doc, matrix):
# get and merge two matrixes into one
trans = doc.get('transform')
if trans:
return simpletransform.composeTransform(matrix, simpletransform.parseTransform(trans))
else:
return matrix
开发者ID:AakashDabas,项目名称:inkscape,代码行数:7,代码来源:hpgl_encoder.py
示例13: effect
def effect(self):
pts = []
for node in self.selected.itervalues():
if node.tag == inkex.addNS('path','svg'):
guide = node
pts = get_n_points_from_path(node, 2)
if len(pts) == 2:
(x0, y0), (x1, y1) = pts
theta = atan2(y1-y0, x1-x0)*180./pi
length = ((x1-x0)**2 + (y1-y0)**2)**0.5
label = inkex.etree.SubElement(self.current_layer, 'g')
labeltag = inkex.etree.SubElement(label, 'g')
if theta <= -90.0 or theta > 90.0:
text, tw, th = self.make_text(anchor='end')
applyTransformToNode(parseTransform('rotate(180.0)'), text)
else:
text, tw, th = self.make_text(anchor='start')
fs = float(self.options.font_size)
kh = 1.05
h = kh*fs
pad = (h - fs)*0.5 + 0.04*tw
w = tw + pad*2
x = -pad + 0.07*fs
y = -0.5*h
box = self.make_box(x, y, w, h, r=0.25*min(w, h))
labeltag.append(box)
labeltag.append(text)
transform = 'translate(%f, 0.0)'% (length,)
applyTransformToNode(parseTransform(transform), labeltag)
leader = self.make_double_line(length+x)
label.append(leader)
transform = 'translate(%f, %f) rotate(%f)'%(x0, y0, theta)
applyTransformToNode(parseTransform(transform), label)
guide.getparent().remove(guide)
开发者ID:brentini,项目名称:inkscape-label,代码行数:46,代码来源:label.py
示例14: get_transform
def get_transform(self):
data = self.node.get("transform")
if not data:
return
matrix = parseTransform(data)
m11, m21, dx = matrix[0]
m12, m22, dy = matrix[1]
return m11, m12, m21, m22, dx, dy
开发者ID:jonata,项目名称:Ink2canvas,代码行数:8,代码来源:svg.py
示例15: recursiveFuseTransform
def recursiveFuseTransform(self, node, transf=[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]):
transf = composeTransform(transf, parseTransform(node.get("transform", None)))
if 'transform' in node.attrib:
del node.attrib['transform']
if 'style' in node.attrib:
style = node.attrib.get('style')
style = simplestyle.parseStyle(style)
update = False
if 'stroke-width' in style:
try:
stroke_width = self.unittouu(style.get('stroke-width').strip())
# pixelsnap ext assumes scaling is similar in x and y
# and uses the x scale...
# let's try to be a bit smarter
stroke_width *= math.sqrt(transf[0][0]**2 + transf[1][1]**2)
style['stroke-width'] = str(stroke_width)
update = True
except AttributeError:
pass
if update:
style = simplestyle.formatStyle(style)
node.attrib['style'] = style
node = ApplyTransform.objectToPath(node)
if 'd' in node.attrib:
d = node.get('d')
p = cubicsuperpath.parsePath(d)
applyTransformToPath(transf, p)
node.set('d', cubicsuperpath.formatPath(p))
elif node.tag in [inkex.addNS('polygon', 'svg'),
inkex.addNS('polyline', 'svg')]:
points = node.get('points')
points = points.strip().split(' ')
for k,p in enumerate(points):
if ',' in p:
p = p.split(',')
p = [float(p[0]),float(p[1])]
applyTransformToPoint(transf, p)
p = [str(p[0]),str(p[1])]
p = ','.join(p)
points[k] = p
points = ' '.join(points)
node.set('points', points)
elif node.tag in [inkex.addNS('rect', 'svg'),
inkex.addNS('text', 'svg'),
inkex.addNS('image', 'svg'),
inkex.addNS('use', 'svg')]:
node.set('transform', formatTransform(transf))
for child in node.getchildren():
self.recursiveFuseTransform(child, transf)
开发者ID:Klowner,项目名称:inkscape-applytransforms,代码行数:58,代码来源:applytransform.py
示例16: effect
def effect(self):
""" This method is called first, and sets up the self.commands list for later output. """
svg = self.document.getroot()
# find document width and height, used to scale down
self.doc_width = inkex.unittouu(svg.get('width'))
self.doc_height = inkex.unittouu(svg.get('height'))
# add header
self.commands.append("^DF;")
self.commands.append("! 1;")
self.commands.append("H;")
self.commands.append("@ %d %d;" % (self.options.z_down, self.options.z_up))
self.commands.append("V {0};F {0};\n".format(self.options.feed_rate_moving))
self.commands.append("Z 0 0 %d;" % self.options.z_up)
# mostly borrowed from hgpl_output.py
lastX = 0
lastY = 0
# find paths in layers
i = 0
layerPath = '//svg:g[@inkscape:groupmode="layer"]'
for layer in svg.xpath(layerPath, namespaces=inkex.NSS):
i += 1
nodePath = ('//svg:g[@inkscape:groupmode="layer"][%d]/descendant::svg:path') % i
for node in svg.xpath(nodePath, namespaces=inkex.NSS):
# these next lines added from this patch to fix the transformation issues - http://launchpadlibrarian.net/36269154/hpgl_output.py.patch
# possibly also want to try this code: https://bugs.launchpad.net/inkscape/+bug/600472/+attachment/1475310/+files/hpgl_output.py
transforms = node.xpath("./ancestor-or-self::svg:*[@transform]",namespaces=inkex.NSS)
matrix = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
for parenttransform in transforms:
newmatrix = simpletransform.parseTransform(parenttransform.get("transform"))
matrix = simpletransform.composeTransform(matrix, newmatrix)
d = node.get('d')
if len(simplepath.parsePath(d)):
p = cubicsuperpath.parsePath(d)
simpletransform.applyTransformToPath(matrix, p) # this line is also from the transform-fixing patch mentioned above
cspsubdiv.cspsubdiv(p, self.options.flat)
for sp in p:
first = True
for csp in sp:
if first:
x, y = self.conv_coords(csp[1][0], self.doc_height - csp[1][1])
self.commands.append("Z %d %d %d;" % (x, y, self.options.z_up))
self.commands.append("V {0};F {0};".format(self.options.feed_rate_cutting))
first = False
x, y = self.conv_coords(csp[1][0], self.doc_height - csp[1][1])
self.commands.append("Z %d %d %d;" % (x, y, self.options.z_down))
lastX = x
lastY = y
self.commands.append("V {0};F {0};".format(self.options.feed_rate_moving))
self.commands.append("Z %d %d %d;" % (lastX, lastY, self.options.z_up))
self.commands.append("Z 0 0 %d;" % self.options.z_up)
self.commands.append("H;")
开发者ID:matthewbeckler,项目名称:modela_inkscape_extension,代码行数:57,代码来源:modela.py
示例17: parseGroup
def parseGroup(self,node,parent):
#inkex.debug(self.debug_tab + 'Parsing group' + node.get('id'))
self.debug_tab += ' '
matrix_list = []
self.parsing_context = 'g'
transform = node.get('transform','')
id = node.get('id')
if(transform!=''):
transform = simpletransform.parseTransform(node.get('transform',''))
transform = self.matrixToList(transform)
transform = self.normalizeMatrix(transform)
label = str(node.get(inkex.addNS('label', 'inkscape'),''))
elements = node.xpath('./*',namespaces=inkex.NSS)
#box = simpletransform.computeBBox(elements)
#box = list(box) if box != None else []
box =list(simpletransform.computeBBox([node]))
box[1] = (box[1]-box[0])
box[3] = (box[3]-box[2])
origin_x = float(node.get(inkex.addNS('transform-center-x', 'inkscape'),0))
origin_y = float(node.get(inkex.addNS('transform-center-y', 'inkscape'),0))
origin_x = origin_x + ( box[1] / 2)
origin_y = (origin_y * -1) + ( box[3] / 2)
group = {
'id':id,
'name':label,
'label':label,
'svg':'g',
'transform':transform,
'origin':{
'x':origin_x,
'y':origin_y,
},
'box':box,
'elements':[]
}
parent.append(group)
self.parse_stack.append(group)
#inkex.debug('Loop through all grouped elements')
for child in elements:
self.parseElement(child,group["elements"])
self.debug_tab = self.debug_tab[:-4]
self.parsing_context = ''
self.parse_stack.pop()
开发者ID:larscwallin,项目名称:bansai,代码行数:57,代码来源:larscwallin.inx.bansai.py
示例18: get_transforms
def get_transforms(self,g):
root = self.document.getroot()
trans = []
while (g!=root):
if 'transform' in g.keys():
t = g.get('transform')
t = simpletransform.parseTransform(t)
trans = simpletransform.composeTransform(t,trans) if trans != [] else t
g=g.getparent()
return trans
开发者ID:cnc-club,项目名称:unordinary-gears,代码行数:10,代码来源:unordinary-gears.py
示例19: effect
def effect(self):
for id, node in self.selected.iteritems():
if node.tag == '{http://www.w3.org/2000/svg}path':
path=node
break
else:
sys.stderr.write('Need one path selected\n')
return
pts = cubicsuperpath.parsePath(path.get('d'))
if 'transform' in path.keys():
trans = path.get('transform')
trans = simpletransform.parseTransform(trans)
simpletransform.applyTransformToPath(trans, pts[i])
gtext = inkex.etree.SubElement(path.xpath('..')[0], inkex.addNS('g','svg'), {} )
gdots = inkex.etree.SubElement(path.xpath('..')[0], inkex.addNS('g','svg'), {} )
size = 10
if 'style' in path.attrib:
style=path.get('style')
if style!='':
styles=style.split(';')
for i in range(len(styles)):
if styles[i].startswith('stroke-width'):
if ( styles[i].endswith('px') or styles[i].endswith('cm') ) :
size=float(styles[i][len('stroke-width:'):-2])*2
else:
size=float(styles[i][len('stroke-width:'):])*2
# if len(pts[0])>2:
# size = math.sqrt(math.pow(pts[0][0][0][0]-pts[0][1][0][0],2)+math.pow(pts[0][0][0][1]-pts[0][1][0][1],2))/10
it = 0
for sub in pts:
for p in sub:
if it == 0:
style = { 'stroke': 'none', 'fill': 'black' }
x0 = p[0][0]
y0 = p[0][1]
circ_attribs = {'id':'pt0','style':simplestyle.formatStyle(style),'cx':str(x0), 'cy':str(y0),'r':str(size)}
circle = inkex.etree.SubElement(gdots, inkex.addNS('circle','svg'), circ_attribs )
else:
clone_attribs = { 'x':'0', 'y':'0', 'transform':'translate(%f,%f)' % (p[0][0]-x0,p[0][1]-y0) }
clone = inkex.etree.SubElement(gdots, inkex.addNS('use','svg'), clone_attribs )
xlink = inkex.addNS('href','xlink')
clone.set(xlink, '#pt0')
text_style = { 'font-size':'%dpx' % (size*2.4), 'fill':'black', 'font-family':'DejaVu Sans', 'text-anchor':'middle' }
text_attribs = { 'x':str(p[0][0]), 'y':str(p[0][1]-size*1.8), 'style':simplestyle.formatStyle(text_style) }
text = inkex.etree.SubElement(gtext, inkex.addNS('text','svg'), text_attribs)
tspan = inkex.etree.SubElement(text , 'tspan', {inkex.addNS('role','sodipodi'): 'line'})
tspan.text = '%d' % ( it+1 )
it+=1
开发者ID:PoufPoufProduction,项目名称:ppvc,代码行数:55,代码来源:dots.py
示例20: effect
def effect(self):
paths = []
for id, node in self.selected.iteritems():
if node.tag == '{http://www.w3.org/2000/svg}path':
paths.append(node)
if len(paths) == 2:
break
else:
sys.stderr.write('Need 2 paths selected\n')
return
pts = [cubicsuperpath.parsePath(paths[i].get('d'))
for i in (0,1)]
for i in (0,1):
if 'transform' in paths[i].keys():
trans = paths[i].get('transform')
trans = simpletransform.parseTransform(trans)
simpletransform.applyTransformToPath(trans, pts[i])
verts = []
for i in range(0, min(map(len, pts))):
comp = []
for j in range(0, min(len(pts[0][i]), len(pts[1][i]))):
comp.append([pts[0][i][j][1][-2:], pts[1][i][j][1][-2:]])
verts.append(comp)
if self.options.mode.lower() == 'lines':
line = []
for comp in verts:
for n,v in enumerate(comp):
line += [('M', v[0])]
line += [('L', v[1])]
ele = inkex.etree.Element('{http://www.w3.org/2000/svg}path')
paths[0].xpath('..')[0].append(ele)
ele.set('d', simplepath.formatPath(line))
ele.set('style', 'fill:none;stroke:#000000;stroke-opacity:1;stroke-width:1;')
elif self.options.mode.lower() == 'polygons':
g = inkex.etree.Element('{http://www.w3.org/2000/svg}g')
g.set('style', 'fill:#000000;stroke:#000000;fill-opacity:0.3;stroke-width:2;stroke-opacity:0.6;')
paths[0].xpath('..')[0].append(g)
for comp in verts:
for n,v in enumerate(comp):
nn = n+1
if nn == len(comp): nn = 0
line = []
line += [('M', comp[n][0])]
line += [('L', comp[n][1])]
line += [('L', comp[nn][1])]
line += [('L', comp[nn][0])]
line += [('L', comp[n][0])]
ele = inkex.etree.Element('{http://www.w3.org/2000/svg}path')
g.append(ele)
ele.set('d', simplepath.formatPath(line))
开发者ID:step21,项目名称:inkscape-osx-packaging-native,代码行数:55,代码来源:extrude.py
注:本文中的simpletransform.parseTransform函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论