def effect(self): # basic style style = { 'stroke': "black", "fill":"none", 'stroke-width': self.options.width } # my group of paths topgroup = etree.SubElement(self.svg.get_current_layer(), 'g' ) lc = self.options.size X = self.options.verti Y = self.options.horiz L = Maze(X,Y,self.options.algo) for i,j,door in L.verticalDoors(): if door: path = points_to_svgd([(lc*(j+1), lc*(i)), (lc*(j+1), lc*(i+1))]) mypath_attribs = { 'style': str(inkex.Style(style)), 'd': path } squiggle = etree.SubElement(topgroup, inkex.addNS('path','svg'), mypath_attribs ) for i,j,door in L.horizontalDoors(): if door: path = points_to_svgd([(lc*(j), lc*(i+1)), (lc*(j+1), lc*(i+1))]) mypath_attribs = { 'style': str(inkex.Style(style)), 'd': path } squiggle = etree.SubElement(topgroup, inkex.addNS('path','svg'), mypath_attribs ) path = points_to_svgd([(0,0),(0,lc*Y),(lc*X,lc*Y),(lc*X,0)], True) mypath_attribs = { 'style': str(inkex.Style(style)), 'd': path } squiggle = etree.SubElement(topgroup, inkex.addNS('path','svg'), mypath_attribs )
def effect(self): self.is_installed() rect = self.svg.selected.first() if rect is None: raise inkex.AbortExtension( _("No object selected. Please select the object you want " "to assign a view to and then press apply.\n")) if not self.options.removeView: view_order = str(self.options.viewOrder) # Remove the view that currently has the requested order number. for node in rect.xpath( "ancestor::svg:g[@inkscape:groupmode='layer']" "/descendant::*[@jessyink:view]"): prop_dict = inkex.Style(node.get("jessyink:view")) if prop_dict["order"] == view_order: node.set("jessyink:view", None) # Set the new view. rect.set( "jessyink:view", inkex.Style( name="view", order=view_order, length=int(self.options.viewDuration * 1000), )) # Remove possible effect arguments. self.attr_remove('effectIn') self.attr_remove('effectOut') else: self.attr_remove('view')
def write_month_header(self, g, m): txt_atts = {'style': str(inkex.Style(self.style_month)), 'x': str(-self.day_w / 3), 'y': str(self.day_h / 5)} try: text = unicode(self.options.month_names[m - 1], self.options.input_encode) if self.options.primary_calendar == "hijri": text = unicode(self.options.hijri_month_names[m - 1], self.options.input_encode) g.add(TextElement(**txt_atts)).text = text except: raise ValueError('You must select a correct system encoding.') gw = g.add(inkex.Group()) week_x = 0 if self.options.start_day == 'sun': day_names = self.options.day_names[:] else: day_names = self.options.day_names[1:] day_names.append(self.options.day_names[0]) if self.options.show_weeknr: day_names.insert(0, self.options.weeknr_name) for wday in day_names: txt_atts = {'style': str(inkex.Style(self.style_day_name)), 'x': str(self.day_w * week_x), 'y': str(self.day_h)} try: gw.add(TextElement(**txt_atts)).text = unicode( wday, self.options.input_encode) except: raise ValueError('You must select a correct system encoding.') week_x += 1
def effect(self): str_stroke = 'rgb(255, 0, 177)' str_strokeWidth = '5px' objarr = [] for id, node in self.svg.selected.items(): if node.tag == (self.svgNS + 'rect'): # rect の場合 node_style = dict(inkex.Style.parse_str(node.get('style'))) node_style['stroke'] = str_stroke node_style['stroke-width'] = self.svg.unittouu(str_strokeWidth) node.set('style', str(inkex.Style(node_style))) for obj_child in node.getchildren(): if obj_child.tag == (self.svgNS + 'rect'): # rect の場合 node_style = dict( inkex.Style.parse_str(obj_child.get('style'))) node_style['stroke'] = str_stroke node_style['stroke-width'] = self.svg.unittouu( str_strokeWidth) obj_child.set('style', str(inkex.Style(node_style))) return
def drawCircles(self, hole_diameter, diameter): # Attributes for the center hole, then create it, if diameter is 0, dont # create it circle_elements = [] attributes = { 'style': str(inkex.Style({'stroke': 'none', 'fill': 'black'})), 'r': str(hole_diameter / 2) } if self.options.hole_diameter > 0: circle_elements.append(attributes) # Attributes for the guide hole in the center hole, then create it attributes = { 'style': str(inkex.Style( {'stroke': 'white', 'fill': 'white', 'stroke-width': '0.1'})), 'r': '1' } circle_elements.append(attributes) # Attributes for the outer rim, then create it attributes = { 'style': str(inkex.Style( {'stroke': 'black', 'stroke-width': '1', 'fill': 'none'})), 'r': str(diameter / 2) } if self.options.diameter > 0: circle_elements.append(attributes) return circle_elements
def check_text_on_path(svg, element, scale_x, scale_y): """Check whether to skip scaling a text put on a path.""" skip = False path = element.find('textPath').href if not is_in_defs(svg, path): if is_sibling(element, path): # skip common element scaling if both text and path are siblings skip = True # scale offset if 'transform' in element.attrib: element.transform.add_scale(scale_x, scale_y) # scale font size mat = inkex.Transform('scale({},{})'.format(scale_x, scale_y)).matrix det = abs(mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]) descrim = math.sqrt(abs(det)) prop = 'font-size' # outer text sdict = dict(inkex.Style.parse_str(element.get('style'))) if prop in sdict: sdict[prop] = float(sdict[prop]) * descrim element.set('style', str(inkex.Style(sdict))) # inner tspans for child in element.iterdescendants(): if isinstance(element, inkex.Tspan): sdict = dict(inkex.Style.parse_str(child.get('style'))) if prop in sdict: sdict[prop] = float(sdict[prop]) * descrim child.set('style', str(inkex.Style(sdict))) return skip
def _update_layer_visibility(self, display): xpath = ".//svg:g[@inkscape:groupmode='layer']" layers = self.document.xpath(xpath, namespaces=inkex.NSS) for layer in layers: display_style = 'display:%s' % display style = inkex.Style(layer.get('style', '')) + inkex.Style(display_style) layer.set('style', style)
def get_blur(self): """Add blur to the svg and return if needed""" if self.options.blur: defs = self.svg.defs # Create new Filter filt = defs.add(Filter(height='3', width='3', x='-0.5', y='-0.5')) # Append Gaussian Blur to that Filter filt.add_primitive('feGaussianBlur', stdDeviation='1.1') return inkex.Style(filter=filt.get_id(as_url=2)) return inkex.Style()
def render_text(self, text, destination_group, variant=None, back_and_forth=True, trim=False): """Render text into an SVG group element.""" self._load_variants() if variant is None: variant = self.default_variant if back_and_forth and self.reversible: glyph_sets = [ self.get_variant(variant), self.get_variant(FontVariant.reversed_variant(variant)) ] else: glyph_sets = [self.get_variant(variant)] * 2 position = Point(0, 0) for i, line in enumerate(text.splitlines()): glyph_set = glyph_sets[i % 2] line = line.strip() letter_group = self._render_line(line, position, glyph_set) if back_and_forth and self.reversible and i % 2 == 1: letter_group[:] = reversed(letter_group) destination_group.append(letter_group) position.x = 0 position.y += self.leading if self.auto_satin and len(destination_group) > 0: self._apply_auto_satin(destination_group, trim) # make sure font stroke styles have always a similar look for element in destination_group.iterdescendants(SVG_PATH_TAG): style = inkex.Style(element.get('style')) if style.get('fill') == 'none': style += inkex.Style("stroke-width:1px") if style.get('stroke-dasharray' ) and style.get('stroke-dasharray') != 'none': style += inkex.Style("stroke-dasharray:3, 1") # Set a smaller width to auto-route running stitches if self.auto_satin or element.get_id().startswith( "autosatinrun"): style += inkex.Style("stroke-width:0.5px") element.set('style', '%s' % style.to_str()) self._ensure_command_symbols(destination_group) return destination_group
def effect(self): str_IdName = 'Arrow1Mend' str_stroke = 'rgb(255, 0, 177)' str_strokeWidth = '5px' marker_node = self.svg.getElement('/svg:svg//svg:marker[@id="%s"]' % str_IdName) if marker_node is None: """Create a marker in the defs of the svg""" marker = inkex.Marker() marker.set('inkscape:isstock', 'true') marker.set('style', str(inkex.Style({'overflow': 'visible'}))) marker.set('id', str_IdName) marker.set('refX', '0.0') marker.set('refY', '0.0') marker.set('orient', 'auto') marker.set('inkscape:stockid', str_IdName) self.svg.defs.append(marker) arrow = inkex.PathElement( d='M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z ') arrow.set( 'transform', 'scale(0.4) rotate(180) translate(10,0)' ) # <- なぜか `matrix(-0.4 4.89843e-17 -4.89843e-17 -0.4 -4 4.89843e-16)` のように変換されてしまう arrow.set( 'style', str( inkex.Style({ 'fill-rule': 'evenodd', 'stroke': '#000000', 'stroke-width': '1pt', 'stroke-opacity': '1', 'fill': '#000000', 'fill-opacity': '1' }))) marker.append(arrow) for id, node in self.svg.selected.items(): node_style = dict(inkex.Style.parse_str(node.get('style'))) node_style['stroke'] = str_stroke node_style['stroke-width'] = self.svg.unittouu(str_strokeWidth) node_style['marker-end'] = ('url(#' + str_IdName + ')') node.set('style', str(inkex.Style(node_style))) return
def to_element(self): node = inkex.PathElement() d = str(inkex.paths.CubicSuperPath(line_strings_to_csp([self.path]))) node.set("d", d) dasharray = inkex.Style("stroke-dasharray:0.5,0.5;") style = inkex.Style(self.original_element.node.get('style', '')) + dasharray node.set("style", str(style)) node.set(INKSTITCH_ATTRIBS['running_stitch_length_mm'], self.running_stitch_length) stroke = Stroke(node) return stroke
def draw_rectangle(self, position, dimension, parent, center): """ Draws a rectangle with the specified parameters. """ rectangle_style = { 'opacity': '1', 'stroke': '#000000', 'stroke-width': str(self.svg.unittouu('2px')), 'fill': '#FFFFFF' } transform = "" if not self.options.wrap_in_group: transform = 'translate' + str(center) rectangle_attributes = { 'transform': transform, 'style': str(inkex.Style(rectangle_style)), inkex.addNS('label', 'inkscape'): "Rectangle " + str(dimension[0]), 'x': str(position[0]), 'y': str(position[1]), 'width': str(dimension[0]), 'height': str(dimension[1]) } etree.SubElement(parent, inkex.addNS('rect', 'svg'), rectangle_attributes)
def generate(self): length = self.svg.unittouu(str(self.options.length) + 'px') spacing = self.svg.unittouu(str(self.options.spacing) + 'px') angle = radians(self.options.angle) # generate points: list of (x, y) pairs points = [] x = 0 tas = tan(angle) * spacing while x < length: # move along path, generating the next 'tooth' points.append((x, 0)) points.append((x + tas, spacing)) points.append((x + spacing, spacing)) points.append((x + spacing + tas, 0)) x += spacing * 2. path = points_to_svgd(points) # Create SVG Path for gear style = { 'stroke': '#000000', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px')) } yield inkex.PathElement(style=str(inkex.Style(style)), d=str(path))
def generate(self): # Let's simplify the variable names ht = int(self.options.height) wt = int(self.options.width) sc = int(self.options.seg_count) cp = self.svg.namedview.center # center point maxx = cp[0] + (wt / 2) maxy = cp[0] + (ht / 2) minx = cp[1] - (wt / 2) miny = cp[1] - (ht / 2) # We need to decide what the maximum length we can draw a line # maxlen is used to seed the random length of the line # It may still be too long, but we'll check on that later! if ht > wt: maxlen = ht else: maxlen = wt style = inkex.Style({ 'stroke-linejoin': 'miter', 'stroke-width': str(self.svg.unittouu('1px')), 'stroke-opacity': '1.0', 'fill-opacity': '1.0', 'stroke': '#000000', 'stroke-linecap': 'butt', 'fill': 'none' }) tur = pturtle.pTurtle() tur.pu() # Pen up tur.setpos(cp) # position to center of window def nextmove(maxlen): randdist = random.randint(0, maxlen) # how far should we draw? tur.forward(randdist) # Let's move the new distance newpos = tur.getpos() # Did we go to far? return newpos, randdist while sc > 0: turpos = tur.getpos() # where are we? randangle = random.randint(1, 360) # Let's Pick a new direction tur.rt(randangle) # Let's turn to face that new direction tur.pu() # We don't want to draw just yet, so pick up the pen/pencil newpos, randdist = nextmove(maxlen) # If we make this move will we go out of bounds? while newpos[0] > maxx or newpos[0] < minx or newpos[1] < miny or newpos[1] > maxy: tur.setpos(turpos) newpos, randdist = nextmove(maxlen) # If it all tests ok, we reset the position # and draw the line for real! tur.setpos(turpos) tur.pd() tur.forward(randdist) sc = sc - 1 return inkex.PathElement(d=tur.getPath(), style=str(style))
def draw_SVG_line( x1, y1, x2, y2, parent): style = { 'stroke': '#000000', 'fill': 'none' } line_attribs = {'style' : str(inkex.Style(style)), 'd' : 'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)} line = etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )
def drawSegment(self, line_style, angle, segment_angle, outer_diameter, width): path = {'style': str(inkex.Style(line_style))} path['d'] = '' outer_radius = outer_diameter / 2 # Go to the first point in the segment path['d'] += self.parsePathData( 'M', calculatePoint(angle, outer_radius - width)) # Go to the second point in the segment path['d'] += self.parsePathData('L', calculatePoint(angle, outer_radius)) # Go to the third point in the segment, draw an arc point = calculatePoint(angle + segment_angle, outer_radius) path['d'] += self.parsePathData('A', [outer_radius, outer_radius]) + \ '0 0 1' + self.parsePathData(' ', point) # Go to the fourth point in the segment point = calculatePoint(angle + segment_angle, outer_radius - width) path['d'] += self.parsePathData('L', point) # Go to the beginning in the segment, draw an arc point = calculatePoint(angle, outer_radius - width) # 'Z' closes the path path['d'] += (self.parsePathData( 'A', [outer_radius - width, outer_radius - width]) + '0 0 0' + self.parsePathData(' ', point) + ' Z') # Return the path return path
def draw_crop_line(self, x1, y1, x2, y2, name, parent): style = {'stroke': '#000000', 'stroke-width': str(self.stroke_width), 'fill': 'none'} line_attribs = {'style': str(inkex.Style(style)), 'id': name, 'd': 'M ' + str(x1) + ',' + str(y1) + ' L ' + str(x2) + ',' + str(y2)} parent.add(inkex.PathElement(**line_attribs))
def write_month_header_secondary(self, g, cal): txt_atts = {'style': str(inkex.Style(self.style_month_secondary)), 'x': str((self.month_w - (self.day_w / 1.5))), 'y': "-1.5"} months_info = [] for week in cal: for day in week: if day != 0: tmp = self.options.hijri_month_names[day[1] - 1] if self.options.primary_calendar == "hijri": tmp = self.options.month_names[day[1] - 1] try: months_info.index((tmp, day[0])) except ValueError: months_info.append((tmp, day[0])) try: g.add(TextElement(**txt_atts)).text = unicode( "{0} - {1}".format( months_info[0][0], months_info[0][1]), self.options.input_encode) if len(months_info) > 1: txt_atts["y"] = "1.5" g.add(TextElement(**txt_atts)).text = unicode( "{0} - {1}".format( months_info[1][0], months_info[1][1]), self.options.input_encode) except: raise ValueError(months_info)
def line(self, points): """ Draw a line from point at (x1, y1) to point at (x2, y2). Style of line is hard coded and specified by 's'. """ # define the motions path = ('M%.4f,%.4fL' % tuple(points[0][:2])) + 'L'.join( [('%f,%f' % tuple(a[:2])) for a in points[1:]]) # define the stroke style s = { 'stroke-linejoin': 'miter', 'stroke-width': self.options.linewidth, 'stroke-opacity': '1.0', 'fill-opacity': '1.0', 'stroke': self.options.linecolor, 'stroke-linecap': 'butt', 'stroke-linejoin': 'butt', 'fill': 'none' } ## Attributes for new element attribs = {'style': str(inkex.Style(s)), 'd': path} ## Add new element etree.SubElement(self.svg.get_current_layer(), inkex.addNS('path', 'svg'), attribs)
def effect(self): path_strings = [] net_strings = ["M"] my_path = etree.Element(inkex.addNS('path', 'svg')) s = { 'stroke-width': self.options.s_width, 'stroke': '#000000', 'fill': 'none' } my_path.set('style', str(inkex.Style(s))) for id, node in self.svg.selected.items(): if node.tag == inkex.addNS('path', 'svg'): d = node.get('d') p = CubicSuperPath(Path(d)) for subpath in p: for i, csp in enumerate(subpath): path_strings.append("%f,%f" % (csp[1][0], csp[1][1])) node.set('d', str(Path(p))) while len(path_strings) > 0: net_strings.append(path_strings.pop(0)) if len(path_strings) > 0: net_strings.append(path_strings.pop()) my_path.set('d', " ".join(net_strings)) self.svg.get_current_layer().append(my_path)
def new_circle(self, parent, x, y, color=None, name=None, fill=True): if color is None: color = '#000000' if name is None: name = name = f"circle{self.txt_i}" self.txt_i += 1 style = { 'stroke': color, 'stroke-width': '0.1px', } if fill: style['fill'] = color style['fill-opacity'] = '1' else: style['fill'] = 'none' style['fill-opacity'] = '1' style_str = str(inkex.Style(style)) attribs = { 'style': style_str, 'id': name, 'cx': str(x), 'cy': str(y), 'rx': '1', 'ry': '1' } line = etree.SubElement(parent, inkex.addNS('ellipse', 'svg'), attribs)
def new_text(self, parent, name, x, y, text, anchor="start", rotate=None, fontsize=None): if not fontsize: # just some estimation fontsize = self.fontsize style = str( inkex.Style({ 'font-size': str(fontsize), 'font-family': 'sans-serif', 'stroke-width': 0.2, })) if name is None: name = f"text{self.txt_i}" self.txt_i += 1 attribs = {'style': style, 'text-anchor': anchor, 'id': name} if rotate: attribs['transform'] = f"translate({x},{y}) rotate({rotate})" else: attribs['x'] = str(x) attribs['y'] = str(y) line = etree.SubElement(parent, inkex.addNS('text', 'svg'), attribs) line.text = text
def add_rounded_rectangle(startx, starty, radius, width, height, style, name, parent, mask=False): line_path = [['M', [startx, starty+radius]]] if radius > 0.0: # rounded corners line_path.append(['c', [0, -radius/2, radius/2, -radius, radius, -radius]]) if mask == "Below": line_path.append(['m', [width-2*radius, 0,]]) else: line_path.append(['c', [radius/2, 0, width-2*radius-radius/2, 0, width-2*radius,0 ]]) # top line line_path.append(['c', [radius/2, 0, radius, radius/2, radius, radius]]) line_path.append(['c', [0, radius/2, 0, height-2*radius-radius/2, 0, height-2*radius]]) # RHS line line_path.append(['c', [0, radius/2, -radius/2, radius, -radius, radius]]) line_path.append(['c', [-radius/2,0, -width+2*radius+radius/2,0, -width+2*radius,0]]) # bottom line line_path.append(['c', [-radius/2, 0, -radius, -radius/2, -radius, -radius]]) if mask == "Right": line_path.append(['m', [0, height]]) else: line_path.append(['c', [0, -radius/2, 0, -height+2*radius+radius/2, 0, -height+2*radius]]) # LHS line else: # square corners if mask == "Below": line_path.append(['m', [width, 0]]) line_path.append(['l', [0, height, -width, 0, 0, -height]]) elif mask == "Right": line_path.append(['l', [width, 0, 0, height, -width, 0,]]) else: # separate line_path.append(['l', [width, 0, 0, height, -width, 0, 0, -height]]) # #sys.stderr.write("%s\n"% line_path) attribs = {'style':str(inkex.Style(style)), inkex.addNS('label','inkscape'):name, 'd':dirtyFormat(line_path)} #sys.stderr.write("%s\n"% attribs) etree.SubElement(parent, inkex.addNS('path','svg'), attribs )
def pack(self, shape): # Pack the individual parts onto the current canvas. line_style = { 'stroke': '#000000', 'stroke-width': str(self.linethickness), 'fill': 'none' } #items = sorted([(p[0].area(),p[0]) for p in shape.parts], reverse=True) items = [(p[0].area(),p[0]) for p in shape.parts] #for p in shape.parts: # inkex.utils.debug(p[0]) rootnode = CutCraftNode(Rectangle(Point(0.0, 0.0), Point(floor(self.docwidth), floor(self.docheight)))) for i, (_, part) in enumerate(items): node = rootnode.insert(part, self) if node is None: self._error("ERROR: Cannot fit parts onto canvas.\n" + "Try a larger canvas and then manually arrange if required.") exit() bbox = part.bbox().expanded() part += -bbox.topleft part += node.rectangle.topleft line_attribs = { 'style' : str(inkex.Style(line_style)), inkex.addNS('label','inkscape') : 'Test ' + str(i), 'd' : part.svg() } _ = etree.SubElement(self.parent, inkex.addNS('path','svg'), line_attribs)
def draw_SVG_circle(parent, r, cx, cy, name, style): " add an SVG circle entity to parent " circ_attribs = {'style': str(inkex.Style(style)), 'cx': str(cx), 'cy': str(cy), 'r': str(r), inkex.addNS('label','inkscape'):name} circle = etree.SubElement(parent, inkex.addNS('circle','svg'), circ_attribs )
def labelFeature(self, node): style = node.get('style') if style: nodeStyle = dict(inkex.Style.parse_str(node.attrib["style"])) nodeColour, labelColour = self.getNodeAndLabelColours( nodeStyle["fill"]) nodeX, nodeY, nodeWidth, nodeHeight = self.getNodeDimensions(node) parent = node.getparent() label = etree.SubElement( parent, inkex.addNS("text", "svg"), { "font-size": str(nodeHeight / 4), "x": str(nodeX + (nodeWidth / 2)), "y": str(nodeY + (nodeHeight / 2)), "dy": "0.5em", "style": str( inkex.Style({ "fill": labelColour, "stroke": "none", "text-anchor": "middle" })) }) labelTextSpan = etree.SubElement(label, inkex.addNS("tspan", "svg"), {}) labelTextSpan.text = nodeColour
def create_pieces(self, jigsaw, gridx, gridy): """ Loop through each row """ # Treat outer edge carefully as border runs around. So special code the edges # Internal lines should be in pairs -with second line reversed and appended to first. Close with a 'z' # Create new group g_attribs = {inkex.addNS('label','inkscape'):'JigsawPieces:X' + \ str( self.pieces_W )+':Y'+str( self.pieces_H ) } jigsaw_pieces = etree.SubElement(jigsaw, 'g', g_attribs) line_style = str(inkex.Style(self.line_style)) # xblocks = self.create_horiz_blocks(jigsaw_pieces, gridy, line_style) #sys.stderr.write("count: %s\n"% dir(gridx)) yblocks = self.create_vert_blocks(jigsaw_pieces, gridx, line_style) # # for each xblock intersect it with each Y block #for x in range(len(xblocks)): # for y in range(len(yblocks)): # delete the paths in xblocks and yblocks # transform them out of the way for now for node in xblocks: node.set('transform', 'translate(%f,%f)' % (self.width, 0)) node.apply_transform() for node in yblocks: node.set('transform', 'translate(%f,%f)' % (self.width, 0)) node.apply_transform()
def line(self, x1, y1, x2, y2): """ Draw a line from point at (x1, y1) to point at (x2, y2). Style of line is hard coded and specified by 's'. """ # define the motions path = 'M %s,%s L %s,%s' % (x1, y1, x2, y2) # define the stroke style s = { 'stroke-linejoin': 'miter', 'stroke-width': self.options.linewidth, 'stroke-opacity': '1.0', 'fill-opacity': '1.0', 'stroke': self.options.linecolor, 'stroke-linecap': 'butt', 'stroke-linejoin': 'butt', 'fill': 'none' } # create attributes from style and path attribs = {'style': str(inkex.Style(s)), 'd': path} # insert path object into current layer etree.SubElement(self.svg.get_current_layer(), inkex.addNS('path', 'svg'), attribs)
def drawS(XYstring): # Draw lines from a list #global parent name='part' style = { 'stroke': '#000000', 'fill': 'none' } drw = {'style':str(inkex.Style(style)),inkex.addNS('label','inkscape'):name,'d':XYstring} #drw = {'style':simplestyle.formatStyle(style),inkex.addNS('label','inkscape'):name,'d':XYstring} etree.SubElement(parent, inkex.addNS('path','svg'), drw )
def effect(self): zoom = self.svg.unittouu(str(self.options.zoom) + 'px') if self.options.randomize: imagelist = generate_random_string(self.options.text, zoom) else: tokens = tokenize(self.options.text) imagelist = randomize_input_string(tokens, zoom) image = layoutstring(imagelist, zoom) if image: s = {'stroke': 'none', 'fill': '#000000'} new = inkex.PathElement(style=str(inkex.Style(s)), d=str(inkex.Path(image))) layer = self.svg.get_current_layer() layer.append(new) # compensate preserved transforms of parent layer if layer.getparent() is not None: mat = ( self.svg.get_current_layer().transform * inkex.Transform([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])).matrix new.transform *= -inkex.Transform(mat)