Ejemplo n.º 1
0
    def effect(self):

        # document or selection
        target = self.options.target

        # getting parent tag of the guides
        namedview = self.document.xpath('/svg:svg/sodipodi:namedview',
                                        namespaces=inkex.NSS)[0]

        # getting the main SVG document element (canvas)
        svg = self.document.getroot()

        # getting the width and height attributes of the canvas
        canvas_width = self.svg.unittouu(svg.get('width'))
        canvas_height = self.svg.unittouu(svg.attrib['height'])

        # If a selected object exists, set guides to that object.
        # Otherwise, use document center guides
        if (target == "selection"):

            # check if there is any selection
            if not self.options.ids:
                inkex.errormsg(_("Please select an object first"))
                exit()

            # query bounding box, UPPER LEFT corner (?)
            q = {'x': 0, 'y': 0, 'width': 0, 'height': 0}
            for query in q.keys():
                p = Popen(
                    'inkscape --query-%s --query-id=%s "%s"' % (
                        query,
                        self.options.ids[0],
                        self.args[-1],
                    ),
                    shell=True,
                    stdout=PIPE,
                    stderr=PIPE,
                )
                p.wait()
                q[query] = p.stdout.read()

            # get width, height, center of bounding box
            obj_width = float(q['width'])
            obj_height = float(q['height'])
            center_x = float(q['x']) + obj_width / 2
            center_y = (canvas_height - float(q['y']) -
                        obj_height) + obj_height / 2

        else:

            # Pick document center
            center_x = canvas_width / 2
            center_y = canvas_height / 2

        # call the function. Output.
        guidetools.drawGuide(center_x, "vertical", namedview)
        guidetools.drawGuide(center_y, "horizontal", namedview)
	def effect(self):

		# document or selection
		target = self.options.target

		# getting parent tag of the guides
		namedview = self.document.xpath('/svg:svg/sodipodi:namedview',namespaces=inkex.NSS)[0]

		# getting the main SVG document element (canvas)
		svg = self.document.getroot()

		# getting the width and height attributes of the canvas
		canvas_width  = self.unittouu(svg.get('width'))
		canvas_height = self.unittouu(svg.attrib['height'])

		# If a selected object exists, set guides to that object. 
		# Otherwise, use document center guides		
		if (target == "selection"):

			# check if there is any selection
			if not self.options.ids:
				inkex.errormsg(_("Please select an object first"))
				exit()

			# query bounding box, UPPER LEFT corner (?)
			q = {'x':0, 'y':0, 'width':0, 'height':0}
			for query in q.keys():
				p = Popen(
					'inkscape --query-%s --query-id=%s "%s"' % (query, self.options.ids[0], self.args[-1], ),
					shell=True,
					stdout=PIPE,
					stderr=PIPE,
					)
				p.wait()
				q[query] = p.stdout.read()

			# get width, height, center of bounding box 
			obj_width = float(q['width'])
			obj_height = float(q['height'])
			center_x = float(q['x']) + obj_width/2
			center_y = ( canvas_height - float(q['y']) - obj_height ) + obj_height/2

		else:

			# Pick document center 
			center_x = canvas_width/2 
			center_y = canvas_height/2

		# call the function. Output.
		guidetools.drawGuide(center_x, "vertical", namedview)
		guidetools.drawGuide(center_y, "horizontal", namedview)
    def effect(self):

        # document or selection
        target = self.options.target

        # getting parent tag of the guides
        namedview = self.document.xpath('/svg:svg/sodipodi:namedview',
                                        namespaces=inkex.NSS)[0]

        # getting the main SVG document element (canvas)
        svg = self.document.getroot()

        # getting the width and height attributes of the canvas
        canvas_width = self.unittouu(svg.get('width'))
        canvas_height = self.unittouu(svg.attrib['height'])

        # If a selected object exists, set guides to that object.
        # Otherwise, use document center guides
        if (target == "selection"):

            # If there is no selection, quit with message
            if not self.options.ids:
                inkex.errormsg(_("Please select at least one object first"))
                exit()

            else:
                q = {}
                q = self.selection_bounding_box(self.options.ids)

            # get width, height, center of bounding box
            obj_width = q['width']
            obj_height = q['height']
            center_x = q['x'] + obj_width / 2
            center_y = (canvas_height - q['y'] - obj_height) + obj_height / 2

        else:

            # Pick document center
            center_x = canvas_width / 2
            center_y = canvas_height / 2

        # call the function. Output.
        guidetools.drawGuide(center_x, "vertical", namedview)
        guidetools.drawGuide(center_y, "horizontal", namedview)
Ejemplo n.º 4
0
    def effect(self):

        # Get script's options values.

        # Factor to multiply in order to get user units (pixels)
        factor = self.unittouu('1' + self.options.unit)

        # document or selection
        target = self.options.target

        # boolean
        same_margins = self.options.same_margins

        # convert string to integer, in user units (pixels)
        top_margin = float(self.options.top_margin) * factor
        right_margin = float(self.options.right_margin) * factor
        bottom_margin = float(self.options.bottom_margin) * factor
        left_margin = float(self.options.left_margin) * factor

        # getting parent tag of the guides
        namedview = self.document.xpath(
            '/svg:svg/sodipodi:namedview', namespaces=inkex.NSS)[0]

        # getting the main SVG document element (canvas)
        svg = self.document.getroot()

        # if same margins, set them all to same value
        if same_margins:
            right_margin = top_margin
            bottom_margin = top_margin
            left_margin = top_margin

        # getting the width and height attributes of the canvas
        canvas_width = self.unittouu(svg.get('width'))
        canvas_height = self.unittouu(svg.get('height'))

        # If selection, draw around selection. Otherwise use document.
        if (target == "selection"):

            # If there is no selection, quit with message
            if not self.options.ids:
                inkex.errormsg(_("Please select an object first"))
                exit()

            # get bounding box
            obj_x1, obj_x2, obj_y1, obj_y2 = simpletransform.computeBBox([self.getElementById(id) for id in self.options.ids])

            # start position of guides
            top_pos = canvas_height - obj_y1 - top_margin
            right_pos = obj_x2 - right_margin
            bottom_pos = canvas_height - obj_y2 + bottom_margin
            left_pos = obj_x1 + left_margin

            # Draw the four margin guides
            # TODO: only draw if not on border
            guidetools.drawGuide(top_pos, "horizontal", namedview)
            guidetools.drawGuide(right_pos, "vertical", namedview)
            guidetools.drawGuide(bottom_pos, "horizontal", namedview)
            guidetools.drawGuide(left_pos, "vertical", namedview)

        else:

            # draw margin guides (if not zero)
            if same_margins:
                right_margin = top_margin
                bottom_margin = top_margin
                left_margin = top_margin

            # start position of guides
            top_pos = canvas_height - top_margin
            right_pos = canvas_width - right_margin
            bottom_pos = bottom_margin
            left_pos = left_margin

            # Draw the four margin guides (if margin exists)
            if top_pos != canvas_height:
                guidetools.drawGuide(top_pos, "horizontal", namedview)
            if right_pos != canvas_width:
                guidetools.drawGuide(right_pos, "vertical", namedview)
            if bottom_pos != 0:
                guidetools.drawGuide(bottom_pos, "horizontal", namedview)
            if left_pos != 0:
                guidetools.drawGuide(left_pos, "vertical", namedview)
    def effect(self):

        # Get script's options values.

        # Factor to multiply in order to get user units (pixels)
        factor = self.svg.unittouu('1' + self.options.unit)

        # document or selection
        target = self.options.target

        # boolean
        same_margins = self.options.same_margins

        # convert string to integer, in user units (pixels)
        top_margin = float(self.options.top_margin) * factor
        right_margin = float(self.options.right_margin) * factor
        bottom_margin = float(self.options.bottom_margin) * factor
        left_margin = float(self.options.left_margin) * factor

        # getting parent tag of the guides
        namedview = self.document.xpath('/svg:svg/sodipodi:namedview',
                                        namespaces=inkex.NSS)[0]

        # getting the main SVG document element (canvas)
        svg = self.document.getroot()

        # if same margins, set them all to same value
        if same_margins:
            right_margin = top_margin
            bottom_margin = top_margin
            left_margin = top_margin

        # getting the width and height attributes of the canvas
        canvas_width = self.svg.unittouu(svg.get('width'))
        canvas_height = self.svg.unittouu(svg.get('height'))

        # If selection, draw around selection. Otherwise use document.
        if (target == "selection"):

            # If there is no selection, quit with message
            if not self.options.ids:
                inkex.errormsg(_("Please select an object first"))
                exit()

            # query bounding box, upper left corner (?)
            q = {'x': 0, 'y': 0, 'width': 0, 'height': 0}
            for query in q.keys():
                p = Popen(
                    'inkscape --query-%s --query-id=%s "%s"' % (
                        query,
                        self.options.ids[0],
                        self.args[-1],
                    ),
                    shell=True,
                    stdout=PIPE,
                    stderr=PIPE,
                )
                p.wait()
                q[query] = p.stdout.read()

            # get center of bounding box
            obj_width = float(q['width'])
            obj_height = float(q['height'])
            obj_x = float(q['x']) + obj_width / 2
            obj_y = (canvas_height - float(q['y']) -
                     obj_height) + obj_height / 2

            # start position of guides (not sur why I need to add the last half width/height)
            top_pos = obj_y - top_margin + obj_height / 2
            right_pos = obj_x + obj_width - right_margin - obj_width / 2
            bottom_pos = obj_y - obj_height + bottom_margin + obj_height / 2
            left_pos = obj_x + left_margin - obj_width / 2

            # Draw the four margin guides
            # TODO: only draw if not on border
            guidetools.drawGuide(top_pos, "horizontal", namedview)
            guidetools.drawGuide(right_pos, "vertical", namedview)
            guidetools.drawGuide(bottom_pos, "horizontal", namedview)
            guidetools.drawGuide(left_pos, "vertical", namedview)

        else:

            # draw margin guides (if not zero)
            if same_margins:
                right_margin = top_margin
                bottom_margin = top_margin
                left_margin = top_margin

            # start position of guides
            top_pos = canvas_height - top_margin
            right_pos = canvas_width - right_margin
            bottom_pos = bottom_margin
            left_pos = left_margin

            # Draw the four margin guides (if margin exists)
            if top_pos != canvas_height:
                guidetools.drawGuide(top_pos, "horizontal", namedview)
            if right_pos != canvas_width:
                guidetools.drawGuide(right_pos, "vertical", namedview)
            if bottom_pos != 0:
                guidetools.drawGuide(bottom_pos, "horizontal", namedview)
            if left_pos != 0:
                guidetools.drawGuide(left_pos, "vertical", namedview)
    def effect(self):

        # Get script's options values.

        # Factor to multiply in order to get user units (pixels)
        factor = self.unittouu("1" + self.options.unit)

        # document or selection
        target = self.options.target

        # boolean
        same_margins = self.options.same_margins

        # convert string to integer, in user units (pixels)
        top_margin = float(self.options.top_margin) * factor
        right_margin = float(self.options.right_margin) * factor
        bottom_margin = float(self.options.bottom_margin) * factor
        left_margin = float(self.options.left_margin) * factor

        # getting parent tag of the guides
        namedview = self.document.xpath("/svg:svg/sodipodi:namedview", namespaces=inkex.NSS)[0]

        # getting the main SVG document element (canvas)
        svg = self.document.getroot()

        # if same margins, set them all to same value
        if same_margins:
            right_margin = top_margin
            bottom_margin = top_margin
            left_margin = top_margin

            # getting the width and height attributes of the canvas
        canvas_width = self.unittouu(svg.get("width"))
        canvas_height = self.unittouu(svg.get("height"))

        # If selection, draw around selection. Otherwise use document.
        if target == "selection":

            # If there is no selection, quit with message
            if not self.options.ids:
                inkex.errormsg(_("Please select an object first"))
                exit()

                # query bounding box, upper left corner (?)
            q = {"x": 0, "y": 0, "width": 0, "height": 0}
            for query in q.keys():
                p = Popen(
                    'inkscape --query-%s --query-id=%s "%s"' % (query, self.options.ids[0], self.args[-1]),
                    shell=True,
                    stdout=PIPE,
                    stderr=PIPE,
                )
                p.wait()
                q[query] = p.stdout.read()

                # get center of bounding box
            obj_width = float(q["width"])
            obj_height = float(q["height"])
            obj_x = float(q["x"]) + obj_width / 2
            obj_y = (canvas_height - float(q["y"]) - obj_height) + obj_height / 2

            # start position of guides (not sur why I need to add the last half width/height)
            top_pos = obj_y - top_margin + obj_height / 2
            right_pos = obj_x + obj_width - right_margin - obj_width / 2
            bottom_pos = obj_y - obj_height + bottom_margin + obj_height / 2
            left_pos = obj_x + left_margin - obj_width / 2

            # Draw the four margin guides
            # TODO: only draw if not on border
            guidetools.drawGuide(top_pos, "horizontal", namedview)
            guidetools.drawGuide(right_pos, "vertical", namedview)
            guidetools.drawGuide(bottom_pos, "horizontal", namedview)
            guidetools.drawGuide(left_pos, "vertical", namedview)

        else:

            # draw margin guides (if not zero)
            if same_margins:
                right_margin = top_margin
                bottom_margin = top_margin
                left_margin = top_margin

                # start position of guides
            top_pos = canvas_height - top_margin
            right_pos = canvas_width - right_margin
            bottom_pos = bottom_margin
            left_pos = left_margin

            # Draw the four margin guides (if margin exists)
            if top_pos != canvas_height:
                guidetools.drawGuide(top_pos, "horizontal", namedview)
            if right_pos != canvas_width:
                guidetools.drawGuide(right_pos, "vertical", namedview)
            if bottom_pos != 0:
                guidetools.drawGuide(bottom_pos, "horizontal", namedview)
            if left_pos != 0:
                guidetools.drawGuide(left_pos, "vertical", namedview)
    def effect(self):

        # Get script's options values.

        # Factor to multiply in order to get user units (pixels)
        factor = self.unittouu('1' + self.options.unit)

        # document or selection
        target = self.options.target

        # boolean
        same_margins = self.options.same_margins

        # convert string to integer, in user units (pixels)
        top_margin = float(self.options.top_margin) * factor
        right_margin = float(self.options.right_margin) * factor
        bottom_margin = float(self.options.bottom_margin) * factor
        left_margin = float(self.options.left_margin) * factor

        # getting parent tag of the guides
        namedview = self.document.xpath('/svg:svg/sodipodi:namedview',
                                        namespaces=inkex.NSS)[0]

        # getting the main SVG document element (canvas)
        svg = self.document.getroot()

        # if same margins, set them all to same value
        if same_margins:
            right_margin = top_margin
            bottom_margin = top_margin
            left_margin = top_margin

        # getting the width and height attributes of the canvas
        canvas_width = self.unittouu(svg.get('width'))
        canvas_height = self.unittouu(svg.get('height'))

        # If selection, draw around selection. Otherwise use document.
        if (target == "selection"):

            # If there is no selection, quit with message
            if not self.options.ids:
                inkex.errormsg(_("Please select at least one object first"))
                exit()

            else:
                q = {}
                q = self.selection_bounding_box(self.options.ids)

            # get center of bounding box
            obj_width = q['width']
            obj_height = q['height']
            obj_x = q['x'] + obj_width / 2
            obj_y = (canvas_height - q['y'] - obj_height) + obj_height / 2

            # start position of guides
            # (not sure why I need to add the last half width/height)
            top_pos = obj_y - top_margin + obj_height / 2
            right_pos = obj_x + obj_width - right_margin - obj_width / 2
            bottom_pos = obj_y - obj_height + bottom_margin + obj_height / 2
            left_pos = obj_x + left_margin - obj_width / 2

            # Draw the four margin guides
            # TODO: only draw if not on border
            guidetools.drawGuide(top_pos, "horizontal", namedview)
            guidetools.drawGuide(right_pos, "vertical", namedview)
            guidetools.drawGuide(bottom_pos, "horizontal", namedview)
            guidetools.drawGuide(left_pos, "vertical", namedview)

        else:

            # draw margin guides (if not zero)
            if same_margins:
                right_margin = top_margin
                bottom_margin = top_margin
                left_margin = top_margin

            # start position of guides
            top_pos = canvas_height - top_margin
            right_pos = canvas_width - right_margin
            bottom_pos = bottom_margin
            left_pos = left_margin

            # Draw the four margin guides (if margin exists)
            if top_pos != canvas_height:
                guidetools.drawGuide(top_pos, "horizontal", namedview)
            if right_pos != canvas_width:
                guidetools.drawGuide(right_pos, "vertical", namedview)
            if bottom_pos != 0:
                guidetools.drawGuide(bottom_pos, "horizontal", namedview)
            if left_pos != 0:
                guidetools.drawGuide(left_pos, "vertical", namedview)