本文整理汇总了Python中simpletransform.parseTransform函数的典型用法代码示例。如果您正苦于以下问题:Python parseTransform函数的具体用法?Python parseTransform怎么用?Python parseTransform使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseTransform函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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))
示例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)
示例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))
示例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
示例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])
示例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)
示例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)
示例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()
示例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()
示例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
示例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)
示例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
示例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)