From cb3c5f1d6220fb6494e7e21be697c23eeaeb75e8 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Thu, 9 Feb 2012 06:25:41 +0100 Subject: Extensions. PEP8, error handling and various extension fixes. (bzr r10954) --- share/extensions/Makefile.am | 6 +- share/extensions/dxf_outlines.py | 22 +- share/extensions/gimp_xcf.py | 166 ++++++----- share/extensions/inkex.py | 5 +- share/extensions/markers_strokepaint.py | 2 +- share/extensions/printing-marks.inx | 51 ---- share/extensions/printing-marks.py | 484 ------------------------------- share/extensions/printing_marks.inx | 51 ++++ share/extensions/printing_marks.py | 487 ++++++++++++++++++++++++++++++++ share/extensions/summersnight.py | 16 +- 10 files changed, 677 insertions(+), 613 deletions(-) delete mode 100644 share/extensions/printing-marks.inx delete mode 100755 share/extensions/printing-marks.py create mode 100644 share/extensions/printing_marks.inx create mode 100755 share/extensions/printing_marks.py diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index 8718de825..eab9a9c6c 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -4,7 +4,7 @@ SUBDIRS = \ Barcode \ Poly3DObjects \ test \ - ink2canvas \ + ink2canvas \ xaml2svg extensiondir = $(datadir)/inkscape/extensions @@ -116,7 +116,7 @@ extensions = \ pixelsnap.py \ plt_output.py \ polyhedron_3d.py \ - printing-marks.py \ + printing_marks.py \ ps2dxf.sh \ ps2pdf-ext.py \ pturtle.py \ @@ -304,7 +304,7 @@ modules = \ plt_input.inx \ plt_output.inx \ polyhedron_3d.inx \ - printing-marks.inx \ + printing_marks.inx \ ps_input.inx \ radiusrand.inx \ render_barcode.inx \ diff --git a/share/extensions/dxf_outlines.py b/share/extensions/dxf_outlines.py index e8cb58848..d93e1ff2f 100755 --- a/share/extensions/dxf_outlines.py +++ b/share/extensions/dxf_outlines.py @@ -60,12 +60,22 @@ def get_matrix(u, i, j): class MyEffect(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) - self.OptionParser.add_option("-R", "--ROBO", action="store", type="string", dest="ROBO") - self.OptionParser.add_option("-P", "--POLY", action="store", type="string", dest="POLY") - self.OptionParser.add_option("--units", action="store", type="string", dest="units") - self.OptionParser.add_option("--encoding", action="store", type="string", dest="char_encode", default="latin_1") - self.OptionParser.add_option("--tab", action="store", type="string", dest="tab") - self.OptionParser.add_option("--inputhelp", action="store", type="string", dest="inputhelp") + self.OptionParser.add_option("-R", "--ROBO", action="store", + type="string", dest="ROBO", + default=False) + self.OptionParser.add_option("-P", "--POLY", action="store", + type="string", dest="POLY", + default=True) + self.OptionParser.add_option("--units", action="store", + type="string", dest="units", + default="72./90") # Points + self.OptionParser.add_option("--encoding", action="store", + type="string", dest="char_encode", + default="latin_1") + self.OptionParser.add_option("--tab", action="store", + type="string", dest="tab") + self.OptionParser.add_option("--inputhelp", action="store", + type="string", dest="inputhelp") self.dxf = [] self.handle = 255 # handle for DXF ENTITY self.layers = ['0'] diff --git a/share/extensions/gimp_xcf.py b/share/extensions/gimp_xcf.py index 8c063d660..3cd30ac10 100755 --- a/share/extensions/gimp_xcf.py +++ b/share/extensions/gimp_xcf.py @@ -1,7 +1,8 @@ #!/usr/bin/env python ''' Copyright (C) 2006 Aaron Spike, aaron@ekips.org -Copyright (C) 2010-2011 Nicolas Dufour, nicoduf@yahoo.fr (Windows support and various fixes) +Copyright (C) 2010-2012 Nicolas Dufour, nicoduf@yahoo.fr +(Windows support and various fixes) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,15 +18,31 @@ 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 -import sys, os, tempfile, shutil + import gettext +import os +import shutil +from subprocess import Popen, PIPE +import sys +import tempfile + +import inkex + +_ = gettext.gettext + +# Define extension exceptions +class GimpXCFError(Exception): pass + +class GimpXCFExpectedIOError(GimpXCFError): pass + +class GimpXCFGimpNotInstalled(GimpXCFError): + def __init__(self): + inkex.errormsg(_('Gimp must be installed and set in your path variable.')) + +class GimpXCFScriptFuError(GimpXCFError): + def __init__(self): + inkex.errormsg(_('An error occured while processing the XCF file.')) -try: - from subprocess import Popen, PIPE - bsubprocess = True -except: - bsubprocess = False class MyEffect(inkex.Effect): def __init__(self): @@ -34,17 +51,17 @@ class MyEffect(inkex.Effect): action="store", type="string", dest="tab") self.OptionParser.add_option("-d", "--guides", - action="store", type="inkbool", - dest="saveGuides", default=False, - help="Save the Guides with the .XCF") + action="store", type="inkbool", + dest="saveGuides", default=False, + help="Save the Guides with the .XCF") self.OptionParser.add_option("-r", "--grid", - action="store", type="inkbool", - dest="saveGrid", default=False, - help="Save the Grid with the .XCF") + action="store", type="inkbool", + dest="saveGrid", default=False, + help="Save the Grid with the .XCF") self.OptionParser.add_option("-b", "--background", - action="store", type="inkbool", - dest="layerBackground", default=False, - help="Add background color to each layer") + action="store", type="inkbool", + dest="layerBackground", default=False, + help="Add background color to each layer") def output(self): pass @@ -61,27 +78,28 @@ class MyEffect(inkex.Effect): pageHeight = int(inkex.unittouu(self.xpathSingle('/svg:svg/@height').split('.')[0])) pageWidth = int(inkex.unittouu(self.xpathSingle('/svg:svg/@width').split('.')[0])) - #create os temp dir + # Create os temp dir (to store exported pngs and Gimp log file) self.tmp_dir = tempfile.mkdtemp() # Guides hGuides = [] vGuides = [] if self.options.saveGuides: - guideXpath = "sodipodi:namedview/sodipodi:guide" #grab all guide tags in the namedview tag + # Grab all guide tags in the namedview tag + guideXpath = "sodipodi:namedview/sodipodi:guide" for guideNode in self.document.xpath(guideXpath, namespaces=inkex.NSS): ori = guideNode.get('orientation') if ori == '0,1': - #this is a horizontal guide + # This is a horizontal guide pos = int(guideNode.get('position').split(',')[1].split('.')[0]) - #GIMP doesn't like guides that are outside of the image + # GIMP doesn't like guides that are outside of the image if pos > 0 and pos < pageHeight: - #the origin is at the top in GIMP land + # The origin is at the top in GIMP land hGuides.append(str(pageHeight - pos)) elif ori == '1,0': - #this is a vertical guide + # This is a vertical guide pos = int(guideNode.get('position').split(',')[0].split('.')[0]) - #GIMP doesn't like guides that are outside of the image + # GIMP doesn't like guides that are outside of the image if pos > 0 and pos < pageWidth: vGuides.append(str(pos)) @@ -91,12 +109,12 @@ class MyEffect(inkex.Effect): # Grid gridSpacingFunc = '' gridOriginFunc = '' - #GIMP only allows one rectangular grid + # GIMP only allows one rectangular grid gridXpath = "sodipodi:namedview/inkscape:grid[@type='xygrid' and (not(@units) or @units='px')]" if (self.options.saveGrid and self.document.xpath(gridXpath, namespaces=inkex.NSS)): gridNode = self.xpathSingle(gridXpath) if gridNode != None: - #these attributes could be nonexistant + # These attributes could be nonexistant spacingX = gridNode.get('spacingx') if spacingX == None: spacingX = '1 ' @@ -121,11 +139,11 @@ class MyEffect(inkex.Effect): opacity += "0" pngs = [] names = [] - valid = 0 + self.valid = 0 path = "/svg:svg/*[name()='g' or @style][@id]" for node in self.document.xpath(path, namespaces=inkex.NSS): if len(node) > 0: # Get rid of empty layers - valid=1 + self.valid = 1 id = node.get('id') if node.get("{" + inkex.NSS["inkscape"] + "}label"): name = node.get("{" + inkex.NSS["inkscape"] + "}label") @@ -133,32 +151,32 @@ class MyEffect(inkex.Effect): name = id filename = os.path.join(self.tmp_dir, "%s.png" % id) command = "inkscape -i \"%s\" -j %s %s -e \"%s\" %s " % (id, area, opacity, filename, svg_file) - if bsubprocess: - p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) - return_code = p.wait() - f = p.stdout - err = p.stderr - else: - _,f,err = os.popen3(command,'r') + + p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) + return_code = p.wait() + f = p.stdout + err = p.stderr + stdin = p.stdin f.read() f.close() err.close() + stdin.close() + if os.name == 'nt': filename = filename.replace("\\", "/") pngs.append(filename) names.append(name.encode('utf-8')) - if (valid==0): - inkex.errormsg(gettext.gettext('This extension requires at least one non empty layer.')) + if (self.valid == 0): self.clear_tmp() - sys.exit(0) - - filelist = '"%s"' % '" "'.join(pngs) - namelist = '"%s"' % '" "'.join(names) - xcf = os.path.join(self.tmp_dir, "%s.xcf" % docname) - if os.name == 'nt': - xcf = xcf.replace("\\", "/") - script_fu = """ + inkex.errormsg(_('This extension requires at least one non empty layer.')) + else: + filelist = '"%s"' % '" "'.join(pngs) + namelist = '"%s"' % '" "'.join(names) + xcf = os.path.join(self.tmp_dir, "%s.xcf" % docname) + if os.name == 'nt': + xcf = xcf.replace("\\", "/") + script_fu = """ (tracing 1) (define (png-to-layer img png_filename layer_name) @@ -206,27 +224,47 @@ class MyEffect(inkex.Effect): (gimp-image-undo-enable img) (gimp-file-save RUN-NONINTERACTIVE img (car (gimp-image-get-active-layer img)) "%s" "%s")) (gimp-quit 0) - """ % (filelist, namelist, hGList, vGList, gridSpacingFunc, gridOriginFunc, xcf, xcf) - - junk = os.path.join(self.tmp_dir, 'junk_from_gimp.txt') - f = os.popen('gimp -i --batch-interpreter plug-in-script-fu-eval -b - > %s 2>&1' % junk,'w') - f.write(script_fu) - f.close() - # uncomment these lines to see the output from gimp - #err = open(junk, 'r') - #inkex.debug(err.read()) - #err.close() - - x = open(xcf, 'rb') - if os.name == 'nt': + """ % (filelist, namelist, hGList, vGList, gridSpacingFunc, gridOriginFunc, xcf, xcf) + + junk = os.path.join(self.tmp_dir, 'junk_from_gimp.txt') + command = 'gimp -i --batch-interpreter plug-in-script-fu-eval -b - > %s 2>&1' % junk + + p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) + f = p.stdin + out = p.stdout + err = p.stderr + f.write(script_fu) + return_code = p.wait() + + if p.returncode != 0: + self.clear_tmp() + raise GimpXCFGimpNotInstalled + + f.close() + err.close() + out.close() + # Uncomment these lines to see the output from gimp + #err = open(junk, 'r') + #inkex.debug(err.read()) + #err.close() + try: - import msvcrt - msvcrt.setmode(1, os.O_BINARY) + x = open(xcf, 'rb') except: - pass - sys.stdout.write(x.read()) - x.close() - self.clear_tmp() + self.clear_tmp() + raise GimpXCFScriptFuError + + if os.name == 'nt': + try: + import msvcrt + msvcrt.setmode(1, os.O_BINARY) + except: + pass + try: + sys.stdout.write(x.read()) + finally: + x.close() + self.clear_tmp() if __name__ == '__main__': diff --git a/share/extensions/inkex.py b/share/extensions/inkex.py index b2b59442b..52b048dc8 100755 --- a/share/extensions/inkex.py +++ b/share/extensions/inkex.py @@ -96,7 +96,10 @@ def errormsg(msg): ... inkex.errormsg(_("This extension requires two selected paths.")) """ - sys.stderr.write((unicode(msg) + "\n").encode("UTF-8")) + if isinstance(msg, unicode): + sys.stderr.write((msg + "\n").encode("UTF-8")) + else: + sys.stderr.write((unicode(msg, "utf-8", errors='replace') + "\n").encode("UTF-8")) def check_inkbool(option, opt, value): if str(value).capitalize() == 'True': diff --git a/share/extensions/markers_strokepaint.py b/share/extensions/markers_strokepaint.py index d357d1988..5c760cd17 100755 --- a/share/extensions/markers_strokepaint.py +++ b/share/extensions/markers_strokepaint.py @@ -69,7 +69,7 @@ class MyEffect(inkex.Effect): defs = self.xpathSingle('/svg:svg//svg:defs') if defs == None: defs = inkex.etree.SubElement(self.document.getroot(),inkex.addNS('defs','svg')) - + for id, node in self.selected.iteritems(): mprops = ['marker','marker-start','marker-mid','marker-end'] try: diff --git a/share/extensions/printing-marks.inx b/share/extensions/printing-marks.inx deleted file mode 100644 index 511c9675a..000000000 --- a/share/extensions/printing-marks.inx +++ /dev/null @@ -1,51 +0,0 @@ - - - <_name>Printing Marks - org.inkscape.printing.marks - printing-marks.py - inkex.py - - - - true - false - true - false - true - false - - - - <_item value="canvas">Canvas - <_item value="selection">Selection - - - px - pt - in - cm - mm - - 5 - <_param name="bleed_settings" type="description" appearance="header">Bleed Margin - 5 - 5 - 5 - 5 - - - - - all - - - - - - - - - - diff --git a/share/extensions/printing-marks.py b/share/extensions/printing-marks.py deleted file mode 100755 index 041025708..000000000 --- a/share/extensions/printing-marks.py +++ /dev/null @@ -1,484 +0,0 @@ -#!/usr/bin/env python -''' -This extension allows you to draw crop, registration and other -printing marks in Inkscape. - -Authors: - Nicolas Dufour - Association Inkscape-fr - Aurelio A. Heckert - -Copyright (C) 2008 Authors - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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, simplestyle, math -from subprocess import Popen, PIPE, STDOUT - -class Printing_Marks (inkex.Effect): - - # Default parameters - stroke_width = 0.25 - mark_size = inkex.unittouu('1cm') - min_mark_margin = inkex.unittouu('3mm') - - def __init__(self): - inkex.Effect.__init__(self) - self.OptionParser.add_option("--where", - action="store", type="string", - dest="where_to_crop", default=True, - help="Apply crop marks to...") - self.OptionParser.add_option("--crop_marks", - action="store", type="inkbool", - dest="crop_marks", default=True, - help="Draw crop Marks?") - self.OptionParser.add_option("--bleed_marks", - action="store", type="inkbool", - dest="bleed_marks", default=False, - help="Draw Bleed Marks?") - self.OptionParser.add_option("--registration_marks", - action="store", type="inkbool", - dest="reg_marks", default=False, - help="Draw Registration Marks?") - self.OptionParser.add_option("--star_target", - action="store", type="inkbool", - dest="star_target", default=False, - help="Draw Star Target?") - self.OptionParser.add_option("--colour_bars", - action="store", type="inkbool", - dest="colour_bars", default=False, - help="Draw Colour Bars?") - self.OptionParser.add_option("--page_info", - action="store", type="inkbool", - dest="page_info", default=False, - help="Draw Page Information?") - self.OptionParser.add_option("--unit", - action="store", type="string", - dest="unit", default=100.0, - help="Draw measurment") - self.OptionParser.add_option("--crop_offset", - action="store", type="float", - dest="crop_offset", default=0, - help="Offset") - self.OptionParser.add_option("--bleed_top", - action="store", type="float", - dest="bleed_top", default=0, - help="Bleed Top Size") - self.OptionParser.add_option("--bleed_bottom", - action="store", type="float", - dest="bleed_bottom", default=0, - help="Bleed Bottom Size") - self.OptionParser.add_option("--bleed_left", - action="store", type="float", - dest="bleed_left", default=0, - help="Bleed Left Size") - self.OptionParser.add_option("--bleed_right", - action="store", type="float", - dest="bleed_right", default=0, - help="Bleed Right Size") - self.OptionParser.add_option("--tab", - action="store", type="string", - dest="tab", - help="The selected UI-tab when OK was pressed") - - 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': simplestyle.formatStyle(style), - 'id': name, - 'd': 'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)} - inkex.etree.SubElement(parent, 'path', line_attribs) - - def draw_bleed_line(self, x1, y1, x2, y2, name, parent): - style = { 'stroke': '#000000', 'stroke-width': str(self.stroke_width), - 'fill': 'none', - 'stroke-miterlimit': '4', 'stroke-dasharray': '4, 2, 1, 2', - 'stroke-dashoffset': '0' } - line_attribs = {'style': simplestyle.formatStyle(style), - 'id': name, - 'd': 'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)} - inkex.etree.SubElement(parent, 'path', line_attribs) - - def draw_reg_circles(self, cx, cy, r, name, colours, parent): - for i in range(len(colours)): - style = {'stroke':colours[i], 'stroke-width':str(r / len(colours)), - 'fill':'none'} - circle_attribs = {'style':simplestyle.formatStyle(style), - inkex.addNS('label','inkscape'):name, - 'cx':str(cx), 'cy':str(cy), - 'r':str((r / len(colours)) * (i + 0.5))} - inkex.etree.SubElement(parent, inkex.addNS('circle','svg'), - circle_attribs) - - def draw_reg_marks(self, cx, cy, rotate, name, parent): - colours = ['#000000','#00ffff','#ff00ff','#ffff00','#000000'] - g = inkex.etree.SubElement(parent, 'g', { 'id': name }) - for i in range(len(colours)): - style = {'fill':colours[i], 'fill-opacity':'1', 'stroke':'none'} - r = (self.mark_size/2) - step = r - stroke = r / len(colours) - regoffset = stroke * i - regmark_attribs = {'style': simplestyle.formatStyle(style), - 'd': 'm' +\ - ' '+str(-regoffset)+','+str(r) +\ - ' '+str(-stroke) +',0' +\ - ' '+str(step) +','+str(-r) +\ - ' '+str(-step) +','+str(-r) +\ - ' '+str(stroke) +',0' +\ - ' '+str(step) +','+str(r) +\ - ' '+str(-step) +','+str(r) +\ - ' z', - 'transform': 'translate('+str(cx)+','+str(cy)+ \ - ') rotate('+str(rotate)+')'} - inkex.etree.SubElement(g, 'path', regmark_attribs) - - def draw_star_target(self, cx, cy, name, parent): - r = (self.mark_size/2) - style = {'fill':'#000 device-cmyk(1,1,1,1)', 'fill-opacity':'1', 'stroke':'none'} - d = ' M 0,0' - i = 0 - while i < ( 2 * math.pi ): - i += math.pi / 16 - d += ' L 0,0 ' +\ - ' L '+ str(math.sin(i)*r) +','+ str(math.cos(i)*r) +\ - ' L '+ str(math.sin(i+0.09)*r) +','+ str(math.cos(i+0.09)*r) - regmark_attribs = {'style':simplestyle.formatStyle(style), - inkex.addNS('label','inkscape'):name, - 'transform':'translate('+str(cx)+','+str(cy)+')', - 'd':d} - inkex.etree.SubElement(parent, inkex.addNS('path','svg'), - regmark_attribs) - - def draw_coluor_bars(self, cx, cy, rotate, name, parent): - g = inkex.etree.SubElement(parent, 'g', { - 'id':name, - 'transform':'translate('+str(cx)+','+str(cy)+\ - ') rotate('+str(rotate)+')' }) - l = min( self.mark_size / 3, max(self.area_w,self.area_h) / 45 ) - for bar in [{'c':'*', 'stroke':'#000', 'x':0, 'y':-(l+1)}, - {'c':'r', 'stroke':'#0FF', 'x':0, 'y':0}, - {'c':'g', 'stroke':'#F0F', 'x':(l*11)+1, 'y':-(l+1)}, - {'c':'b', 'stroke':'#FF0', 'x':(l*11)+1, 'y':0} - ]: - i = 0 - while i <= 1: - cr = '255' - cg = '255' - cb = '255' - if bar['c'] == 'r' or bar['c'] == '*' : cr = str(255*i) - if bar['c'] == 'g' or bar['c'] == '*' : cg = str(255*i) - if bar['c'] == 'b' or bar['c'] == '*' : cb = str(255*i) - r_att = {'fill':'rgb('+cr+','+cg+','+cb+')', - 'stroke':bar['stroke'], - 'stroke-width':'0.5', - 'x':str((l*i*10)+bar['x']), 'y':str(bar['y']), - 'width':str(l), 'height':str(l)} - r = inkex.etree.SubElement(g, 'rect', r_att) - i += 0.1 - - def get_selection_area(self): - sel_area = {} - min_x, min_y, max_x, max_y = False, False, False, False - for id in self.options.ids: - sel_area[id] = {} - for att in [ "x", "y", "width", "height" ]: - args = [ "inkscape", "-I", id, "--query-"+att, self.svg_file ] - sel_area[id][att] = \ - Popen(args, stdout=PIPE, stderr=PIPE).communicate()[0] - current_min_x = float( sel_area[id]["x"] ) - current_min_y = float( sel_area[id]["y"] ) - current_max_x = float( sel_area[id]["x"] ) + \ - float( sel_area[id]["width"] ) - current_max_y = float( sel_area[id]["y"] ) + \ - float( sel_area[id]["height"] ) - if not min_x: min_x = current_min_x - if not min_y: min_y = current_min_y - if not max_x: max_x = current_max_x - if not max_y: max_y = current_max_y - if current_min_x < min_x: min_x = current_min_x - if current_min_y < min_y: min_y = current_min_y - if current_max_x > max_x: max_x = current_max_x - if current_max_y > max_y: max_y = current_max_y - #inkex.errormsg( '>> '+ id + - # ' min_x:'+ str(min_x) + - # ' min_y:'+ str(min_y) + - # ' max_x:'+ str(max_x) + - # ' max_y:'+ str(max_y) ) - self.area_x1 = min_x - self.area_y1 = min_y - self.area_x2 = max_x - self.area_y2 = max_y - self.area_w = max_x - min_x - self.area_h = max_y - min_y - - def effect(self): - - if self.options.where_to_crop == 'selection' : - self.get_selection_area() - #inkex.errormsg('Sory, the crop to selection is a TODO feature') - #exit(1) - else : - svg = self.document.getroot() - self.area_w = inkex.unittouu(svg.get('width')) - self.area_h = inkex.unittouu(svg.attrib['height']) - self.area_x1 = 0 - self.area_y1 = 0 - self.area_x2 = self.area_w - self.area_y2 = self.area_h - - # Get SVG document dimensions - # self.width must be replaced by self.area_x2. same to others. - svg = self.document.getroot() - #self.width = width = inkex.unittouu(svg.get('width')) - #self.height = height = inkex.unittouu(svg.attrib['height']) - - # Convert parameters to user unit - offset = inkex.unittouu(str(self.options.crop_offset) + \ - self.options.unit) - bt = inkex.unittouu(str(self.options.bleed_top) + self.options.unit) - bb = inkex.unittouu(str(self.options.bleed_bottom) + self.options.unit) - bl = inkex.unittouu(str(self.options.bleed_left) + self.options.unit) - br = inkex.unittouu(str(self.options.bleed_right) + self.options.unit) - # Bleed margin - if bt < offset : bmt = 0 - else : bmt = bt - offset - if bb < offset : bmb = 0 - else : bmb = bb - offset - if bl < offset : bml = 0 - else : bml = bl - offset - if br < offset : bmr = 0 - else : bmr = br - offset - - # Define the new document limits - offset_left = self.area_x1 - offset - offset_right = self.area_x2 + offset - offset_top = self.area_y1 - offset - offset_bottom = self.area_y2 + offset - - # Get middle positions - middle_vertical = self.area_y1 + ( self.area_h / 2 ) - middle_horizontal = self.area_x1 + ( self.area_w / 2 ) - - # Test if printing-marks layer existis - layer = self.document.xpath( - '//*[@id="printing-marks" and @inkscape:groupmode="layer"]', - namespaces=inkex.NSS) - if layer: svg.remove(layer[0]) # remove if it existis - # Create a new layer - layer = inkex.etree.SubElement(svg, 'g') - layer.set('id', 'printing-marks') - layer.set(inkex.addNS('label', 'inkscape'), 'Printing Marks') - layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer') - layer.set(inkex.addNS('insensitive', 'sodipodi'), 'true') - - # Crop Mark - if self.options.crop_marks == True: - # Create a group for Crop Mark - g_attribs = {inkex.addNS('label','inkscape'):'CropMarks', - 'id':'CropMarks'} - g_crops = inkex.etree.SubElement(layer, 'g', g_attribs) - - # Top left Mark - self.draw_crop_line(self.area_x1, offset_top, - self.area_x1, offset_top - self.mark_size, - 'cropTL1', g_crops) - self.draw_crop_line(offset_left, self.area_y1, - offset_left - self.mark_size, self.area_y1, - 'cropTL2', g_crops) - - # Top right Mark - self.draw_crop_line(self.area_x2, offset_top, - self.area_x2, offset_top - self.mark_size, - 'cropTR1', g_crops) - self.draw_crop_line(offset_right, self.area_y1, - offset_right + self.mark_size, self.area_y1, - 'cropTR2', g_crops) - - # Bottom left Mark - self.draw_crop_line(self.area_x1, offset_bottom, - self.area_x1, offset_bottom + self.mark_size, - 'cropBL1', g_crops) - self.draw_crop_line(offset_left, self.area_y2, - offset_left - self.mark_size, self.area_y2, - 'cropBL2', g_crops) - - # Bottom right Mark - self.draw_crop_line(self.area_x2, offset_bottom, - self.area_x2, offset_bottom + self.mark_size, - 'cropBR1', g_crops) - self.draw_crop_line(offset_right, self.area_y2, - offset_right + self.mark_size, self.area_y2, - 'cropBR2', g_crops) - - # Bleed Mark - if self.options.bleed_marks == True: - # Create a group for Bleed Mark - g_attribs = {inkex.addNS('label','inkscape'):'BleedMarks', - 'id':'BleedMarks'} - g_bleed = inkex.etree.SubElement(layer, 'g', g_attribs) - - # Top left Mark - self.draw_bleed_line(self.area_x1 - bl, offset_top - bmt, - self.area_x1 - bl, offset_top - bmt - self.mark_size, - 'bleedTL1', g_bleed) - self.draw_bleed_line(offset_left - bml, self.area_y1 - bt, - offset_left - bml - self.mark_size, self.area_y1 - bt, - 'bleedTL2', g_bleed) - - # Top right Mark - self.draw_bleed_line(self.area_x2 + br, offset_top - bmt, - self.area_x2 + br, offset_top - bmt - self.mark_size, - 'bleedTR1', g_bleed) - self.draw_bleed_line(offset_right + bmr, self.area_y1 - bt, - offset_right + bmr + self.mark_size, self.area_y1 - bt, - 'bleedTR2', g_bleed) - - # Bottom left Mark - self.draw_bleed_line(self.area_x1 - bl, offset_bottom + bmb, - self.area_x1 - bl, offset_bottom + bmb + self.mark_size, - 'bleedBL1', g_bleed) - self.draw_bleed_line(offset_left - bml, self.area_y2 + bb, - offset_left - bml - self.mark_size, self.area_y2 + bb, - 'bleedBL2', g_bleed) - - # Bottom right Mark - self.draw_bleed_line(self.area_x2 + br, offset_bottom + bmb, - self.area_x2 + br, offset_bottom + bmb + self.mark_size, - 'bleedBR1', g_bleed) - self.draw_bleed_line(offset_right + bmr, self.area_y2 + bb, - offset_right + bmr + self.mark_size, self.area_y2 + bb, - 'bleedBR2', g_bleed) - - # Registration Mark - if self.options.reg_marks == True: - # Create a group for Registration Mark - g_attribs = {inkex.addNS('label','inkscape'):'RegistrationMarks', - 'id':'RegistrationMarks'} - g_center = inkex.etree.SubElement(layer, 'g', g_attribs) - - # Left Mark - cx = max( bml + offset, self.min_mark_margin ) - self.draw_reg_marks(self.area_x1 - cx - (self.mark_size/2), - middle_vertical - self.mark_size*1.5, - '0', 'regMarkL', g_center) - - # Right Mark - cx = max( bmr + offset, self.min_mark_margin ) - self.draw_reg_marks(self.area_x2 + cx + (self.mark_size/2), - middle_vertical - self.mark_size*1.5, - '180', 'regMarkR', g_center) - - # Top Mark - cy = max( bmt + offset, self.min_mark_margin ) - self.draw_reg_marks(middle_horizontal, - self.area_y1 - cy - (self.mark_size/2), - '90', 'regMarkT', g_center) - - # Bottom Mark - cy = max( bmb + offset, self.min_mark_margin ) - self.draw_reg_marks(middle_horizontal, - self.area_y2 + cy + (self.mark_size/2), - '-90', 'regMarkB', g_center) - - # Star Target - if self.options.star_target == True: - # Create a group for Star Target - g_attribs = {inkex.addNS('label','inkscape'):'StarTarget', - 'id':'StarTarget'} - g_center = inkex.etree.SubElement(layer, 'g', g_attribs) - - if self.area_h < self.area_w : - # Left Star - cx = max( bml + offset, self.min_mark_margin ) - self.draw_star_target(self.area_x1 - cx - (self.mark_size/2), - middle_vertical, - 'starTargetL', g_center) - # Right Star - cx = max( bmr + offset, self.min_mark_margin ) - self.draw_star_target(self.area_x2 + cx + (self.mark_size/2), - middle_vertical, - 'starTargetR', g_center) - else : - # Top Star - cy = max( bmt + offset, self.min_mark_margin ) - self.draw_star_target(middle_horizontal - self.mark_size*1.5, - self.area_y1 - cy - (self.mark_size/2), - 'starTargetT', g_center) - # Bottom Star - cy = max( bmb + offset, self.min_mark_margin ) - self.draw_star_target(middle_horizontal - self.mark_size*1.5, - self.area_y2 + cy + (self.mark_size/2), - 'starTargetB', g_center) - - - # Colour Bars - if self.options.colour_bars == True: - # Create a group for Colour Bars - g_attribs = {inkex.addNS('label','inkscape'):'ColourBars', - 'id':'PrintingColourBars'} - g_center = inkex.etree.SubElement(layer, 'g', g_attribs) - - if self.area_h > self.area_w : - # Left Bars - cx = max( bml + offset, self.min_mark_margin ) - self.draw_coluor_bars(self.area_x1 - cx - (self.mark_size/2), - middle_vertical + self.mark_size, - 90, - 'PrintingColourBarsL', g_center) - # Right Bars - cx = max( bmr + offset, self.min_mark_margin ) - self.draw_coluor_bars(self.area_x2 + cx + (self.mark_size/2), - middle_vertical + self.mark_size, - 90, - 'PrintingColourBarsR', g_center) - else : - # Top Bars - cy = max( bmt + offset, self.min_mark_margin ) - self.draw_coluor_bars(middle_horizontal + self.mark_size, - self.area_y1 - cy - (self.mark_size/2), - 0, - 'PrintingColourBarsT', g_center) - # Bottom Bars - cy = max( bmb + offset, self.min_mark_margin ) - self.draw_coluor_bars(middle_horizontal + self.mark_size, - self.area_y2 + cy + (self.mark_size/2), - 0, - 'PrintingColourBarsB', g_center) - - - # Page Information - if self.options.page_info == True: - # Create a group for Page Information - g_attribs = {inkex.addNS('label','inkscape'):'PageInformation', - 'id':'PageInformation'} - g_pag_info = inkex.etree.SubElement(layer, 'g', g_attribs) - y_margin = max( bmb + offset, self.min_mark_margin ) - txt_attribs = { - 'style': 'font-size:12px;font-style:normal;font-weight:normal;fill:#000000;font-family:Bitstream Vera Sans,sans-serif;text-anchor:middle;text-align:center', - 'x': str(middle_horizontal), - 'y': str(self.area_y2+y_margin+self.mark_size+20) - } - txt = inkex.etree.SubElement(g_pag_info, 'text', txt_attribs) - txt.text = 'Page size: ' +\ - str(round(inkex.uutounit(self.area_w,self.options.unit),2)) +\ - 'x' +\ - str(round(inkex.uutounit(self.area_h,self.options.unit),2)) +\ - ' ' + self.options.unit - - -if __name__ == '__main__': - e = Printing_Marks() - e.affect() diff --git a/share/extensions/printing_marks.inx b/share/extensions/printing_marks.inx new file mode 100644 index 000000000..19a29bf02 --- /dev/null +++ b/share/extensions/printing_marks.inx @@ -0,0 +1,51 @@ + + + <_name>Printing Marks + org.inkscape.printing.marks + printing_marks.py + inkex.py + + + + true + false + true + false + true + false + + + + <_item value="canvas">Canvas + <_item value="selection">Selection + + + px + pt + in + cm + mm + + 5 + <_param name="bleed_settings" type="description" appearance="header">Bleed Margin + 5 + 5 + 5 + 5 + + + + + all + + + + + + + + + + diff --git a/share/extensions/printing_marks.py b/share/extensions/printing_marks.py new file mode 100755 index 000000000..7d3ab02d1 --- /dev/null +++ b/share/extensions/printing_marks.py @@ -0,0 +1,487 @@ +#!/usr/bin/env python +''' +This extension allows you to draw crop, registration and other +printing marks in Inkscape. + +Authors: + Nicolas Dufour - Association Inkscape-fr + Aurelio A. Heckert + +Copyright (C) 2008 Authors + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +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 +''' + +from subprocess import Popen, PIPE, STDOUT +import math + +import inkex +import simplestyle + +class Printing_Marks (inkex.Effect): + + # Default parameters + stroke_width = 0.25 + mark_size = inkex.unittouu('1cm') + min_mark_margin = inkex.unittouu('3mm') + + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option("--where", + action="store", type="string", + dest="where_to_crop", default=True, + help="Apply crop marks to...") + self.OptionParser.add_option("--crop_marks", + action="store", type="inkbool", + dest="crop_marks", default=True, + help="Draw crop Marks?") + self.OptionParser.add_option("--bleed_marks", + action="store", type="inkbool", + dest="bleed_marks", default=False, + help="Draw Bleed Marks?") + self.OptionParser.add_option("--registration_marks", + action="store", type="inkbool", + dest="reg_marks", default=False, + help="Draw Registration Marks?") + self.OptionParser.add_option("--star_target", + action="store", type="inkbool", + dest="star_target", default=False, + help="Draw Star Target?") + self.OptionParser.add_option("--colour_bars", + action="store", type="inkbool", + dest="colour_bars", default=False, + help="Draw Colour Bars?") + self.OptionParser.add_option("--page_info", + action="store", type="inkbool", + dest="page_info", default=False, + help="Draw Page Information?") + self.OptionParser.add_option("--unit", + action="store", type="string", + dest="unit", default="px", + help="Draw measurment") + self.OptionParser.add_option("--crop_offset", + action="store", type="float", + dest="crop_offset", default=0, + help="Offset") + self.OptionParser.add_option("--bleed_top", + action="store", type="float", + dest="bleed_top", default=0, + help="Bleed Top Size") + self.OptionParser.add_option("--bleed_bottom", + action="store", type="float", + dest="bleed_bottom", default=0, + help="Bleed Bottom Size") + self.OptionParser.add_option("--bleed_left", + action="store", type="float", + dest="bleed_left", default=0, + help="Bleed Left Size") + self.OptionParser.add_option("--bleed_right", + action="store", type="float", + dest="bleed_right", default=0, + help="Bleed Right Size") + self.OptionParser.add_option("--tab", + action="store", type="string", + dest="tab", + help="The selected UI-tab when OK was pressed") + + 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': simplestyle.formatStyle(style), + 'id': name, + 'd': 'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)} + inkex.etree.SubElement(parent, 'path', line_attribs) + + def draw_bleed_line(self, x1, y1, x2, y2, name, parent): + style = { 'stroke': '#000000', 'stroke-width': str(self.stroke_width), + 'fill': 'none', + 'stroke-miterlimit': '4', 'stroke-dasharray': '4, 2, 1, 2', + 'stroke-dashoffset': '0' } + line_attribs = {'style': simplestyle.formatStyle(style), + 'id': name, + 'd': 'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)} + inkex.etree.SubElement(parent, 'path', line_attribs) + + def draw_reg_circles(self, cx, cy, r, name, colours, parent): + for i in range(len(colours)): + style = {'stroke':colours[i], 'stroke-width':str(r / len(colours)), + 'fill':'none'} + circle_attribs = {'style':simplestyle.formatStyle(style), + inkex.addNS('label','inkscape'):name, + 'cx':str(cx), 'cy':str(cy), + 'r':str((r / len(colours)) * (i + 0.5))} + inkex.etree.SubElement(parent, inkex.addNS('circle','svg'), + circle_attribs) + + def draw_reg_marks(self, cx, cy, rotate, name, parent): + colours = ['#000000','#00ffff','#ff00ff','#ffff00','#000000'] + g = inkex.etree.SubElement(parent, 'g', { 'id': name }) + for i in range(len(colours)): + style = {'fill':colours[i], 'fill-opacity':'1', 'stroke':'none'} + r = (self.mark_size/2) + step = r + stroke = r / len(colours) + regoffset = stroke * i + regmark_attribs = {'style': simplestyle.formatStyle(style), + 'd': 'm' +\ + ' '+str(-regoffset)+','+str(r) +\ + ' '+str(-stroke) +',0' +\ + ' '+str(step) +','+str(-r) +\ + ' '+str(-step) +','+str(-r) +\ + ' '+str(stroke) +',0' +\ + ' '+str(step) +','+str(r) +\ + ' '+str(-step) +','+str(r) +\ + ' z', + 'transform': 'translate('+str(cx)+','+str(cy)+ \ + ') rotate('+str(rotate)+')'} + inkex.etree.SubElement(g, 'path', regmark_attribs) + + def draw_star_target(self, cx, cy, name, parent): + r = (self.mark_size/2) + style = {'fill':'#000 device-cmyk(1,1,1,1)', 'fill-opacity':'1', 'stroke':'none'} + d = ' M 0,0' + i = 0 + while i < ( 2 * math.pi ): + i += math.pi / 16 + d += ' L 0,0 ' +\ + ' L '+ str(math.sin(i)*r) +','+ str(math.cos(i)*r) +\ + ' L '+ str(math.sin(i+0.09)*r) +','+ str(math.cos(i+0.09)*r) + regmark_attribs = {'style':simplestyle.formatStyle(style), + inkex.addNS('label','inkscape'):name, + 'transform':'translate('+str(cx)+','+str(cy)+')', + 'd':d} + inkex.etree.SubElement(parent, inkex.addNS('path','svg'), + regmark_attribs) + + def draw_coluor_bars(self, cx, cy, rotate, name, parent): + g = inkex.etree.SubElement(parent, 'g', { + 'id':name, + 'transform':'translate('+str(cx)+','+str(cy)+\ + ') rotate('+str(rotate)+')' }) + l = min( self.mark_size / 3, max(self.area_w,self.area_h) / 45 ) + for bar in [{'c':'*', 'stroke':'#000', 'x':0, 'y':-(l+1)}, + {'c':'r', 'stroke':'#0FF', 'x':0, 'y':0}, + {'c':'g', 'stroke':'#F0F', 'x':(l*11)+1, 'y':-(l+1)}, + {'c':'b', 'stroke':'#FF0', 'x':(l*11)+1, 'y':0} + ]: + i = 0 + while i <= 1: + cr = '255' + cg = '255' + cb = '255' + if bar['c'] == 'r' or bar['c'] == '*' : cr = str(255*i) + if bar['c'] == 'g' or bar['c'] == '*' : cg = str(255*i) + if bar['c'] == 'b' or bar['c'] == '*' : cb = str(255*i) + r_att = {'fill':'rgb('+cr+','+cg+','+cb+')', + 'stroke':bar['stroke'], + 'stroke-width':'0.5', + 'x':str((l*i*10)+bar['x']), 'y':str(bar['y']), + 'width':str(l), 'height':str(l)} + r = inkex.etree.SubElement(g, 'rect', r_att) + i += 0.1 + + def get_selection_area(self): + sel_area = {} + min_x, min_y, max_x, max_y = False, False, False, False + for id in self.options.ids: + sel_area[id] = {} + for att in [ "x", "y", "width", "height" ]: + args = [ "inkscape", "-I", id, "--query-"+att, self.svg_file ] + sel_area[id][att] = \ + Popen(args, stdout=PIPE, stderr=PIPE).communicate()[0] + current_min_x = float( sel_area[id]["x"] ) + current_min_y = float( sel_area[id]["y"] ) + current_max_x = float( sel_area[id]["x"] ) + \ + float( sel_area[id]["width"] ) + current_max_y = float( sel_area[id]["y"] ) + \ + float( sel_area[id]["height"] ) + if not min_x: min_x = current_min_x + if not min_y: min_y = current_min_y + if not max_x: max_x = current_max_x + if not max_y: max_y = current_max_y + if current_min_x < min_x: min_x = current_min_x + if current_min_y < min_y: min_y = current_min_y + if current_max_x > max_x: max_x = current_max_x + if current_max_y > max_y: max_y = current_max_y + #inkex.errormsg( '>> '+ id + + # ' min_x:'+ str(min_x) + + # ' min_y:'+ str(min_y) + + # ' max_x:'+ str(max_x) + + # ' max_y:'+ str(max_y) ) + self.area_x1 = min_x + self.area_y1 = min_y + self.area_x2 = max_x + self.area_y2 = max_y + self.area_w = max_x - min_x + self.area_h = max_y - min_y + + def effect(self): + + if self.options.where_to_crop == 'selection' : + self.get_selection_area() + #inkex.errormsg('Sory, the crop to selection is a TODO feature') + #exit(1) + else : + svg = self.document.getroot() + self.area_w = inkex.unittouu(svg.get('width')) + self.area_h = inkex.unittouu(svg.attrib['height']) + self.area_x1 = 0 + self.area_y1 = 0 + self.area_x2 = self.area_w + self.area_y2 = self.area_h + + # Get SVG document dimensions + # self.width must be replaced by self.area_x2. same to others. + svg = self.document.getroot() + #self.width = width = inkex.unittouu(svg.get('width')) + #self.height = height = inkex.unittouu(svg.attrib['height']) + + # Convert parameters to user unit + offset = inkex.unittouu(str(self.options.crop_offset) + \ + self.options.unit) + bt = inkex.unittouu(str(self.options.bleed_top) + self.options.unit) + bb = inkex.unittouu(str(self.options.bleed_bottom) + self.options.unit) + bl = inkex.unittouu(str(self.options.bleed_left) + self.options.unit) + br = inkex.unittouu(str(self.options.bleed_right) + self.options.unit) + # Bleed margin + if bt < offset : bmt = 0 + else : bmt = bt - offset + if bb < offset : bmb = 0 + else : bmb = bb - offset + if bl < offset : bml = 0 + else : bml = bl - offset + if br < offset : bmr = 0 + else : bmr = br - offset + + # Define the new document limits + offset_left = self.area_x1 - offset + offset_right = self.area_x2 + offset + offset_top = self.area_y1 - offset + offset_bottom = self.area_y2 + offset + + # Get middle positions + middle_vertical = self.area_y1 + ( self.area_h / 2 ) + middle_horizontal = self.area_x1 + ( self.area_w / 2 ) + + # Test if printing-marks layer existis + layer = self.document.xpath( + '//*[@id="printing-marks" and @inkscape:groupmode="layer"]', + namespaces=inkex.NSS) + if layer: svg.remove(layer[0]) # remove if it existis + # Create a new layer + layer = inkex.etree.SubElement(svg, 'g') + layer.set('id', 'printing-marks') + layer.set(inkex.addNS('label', 'inkscape'), 'Printing Marks') + layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer') + layer.set(inkex.addNS('insensitive', 'sodipodi'), 'true') + + # Crop Mark + if self.options.crop_marks == True: + # Create a group for Crop Mark + g_attribs = {inkex.addNS('label','inkscape'):'CropMarks', + 'id':'CropMarks'} + g_crops = inkex.etree.SubElement(layer, 'g', g_attribs) + + # Top left Mark + self.draw_crop_line(self.area_x1, offset_top, + self.area_x1, offset_top - self.mark_size, + 'cropTL1', g_crops) + self.draw_crop_line(offset_left, self.area_y1, + offset_left - self.mark_size, self.area_y1, + 'cropTL2', g_crops) + + # Top right Mark + self.draw_crop_line(self.area_x2, offset_top, + self.area_x2, offset_top - self.mark_size, + 'cropTR1', g_crops) + self.draw_crop_line(offset_right, self.area_y1, + offset_right + self.mark_size, self.area_y1, + 'cropTR2', g_crops) + + # Bottom left Mark + self.draw_crop_line(self.area_x1, offset_bottom, + self.area_x1, offset_bottom + self.mark_size, + 'cropBL1', g_crops) + self.draw_crop_line(offset_left, self.area_y2, + offset_left - self.mark_size, self.area_y2, + 'cropBL2', g_crops) + + # Bottom right Mark + self.draw_crop_line(self.area_x2, offset_bottom, + self.area_x2, offset_bottom + self.mark_size, + 'cropBR1', g_crops) + self.draw_crop_line(offset_right, self.area_y2, + offset_right + self.mark_size, self.area_y2, + 'cropBR2', g_crops) + + # Bleed Mark + if self.options.bleed_marks == True: + # Create a group for Bleed Mark + g_attribs = {inkex.addNS('label','inkscape'):'BleedMarks', + 'id':'BleedMarks'} + g_bleed = inkex.etree.SubElement(layer, 'g', g_attribs) + + # Top left Mark + self.draw_bleed_line(self.area_x1 - bl, offset_top - bmt, + self.area_x1 - bl, offset_top - bmt - self.mark_size, + 'bleedTL1', g_bleed) + self.draw_bleed_line(offset_left - bml, self.area_y1 - bt, + offset_left - bml - self.mark_size, self.area_y1 - bt, + 'bleedTL2', g_bleed) + + # Top right Mark + self.draw_bleed_line(self.area_x2 + br, offset_top - bmt, + self.area_x2 + br, offset_top - bmt - self.mark_size, + 'bleedTR1', g_bleed) + self.draw_bleed_line(offset_right + bmr, self.area_y1 - bt, + offset_right + bmr + self.mark_size, self.area_y1 - bt, + 'bleedTR2', g_bleed) + + # Bottom left Mark + self.draw_bleed_line(self.area_x1 - bl, offset_bottom + bmb, + self.area_x1 - bl, offset_bottom + bmb + self.mark_size, + 'bleedBL1', g_bleed) + self.draw_bleed_line(offset_left - bml, self.area_y2 + bb, + offset_left - bml - self.mark_size, self.area_y2 + bb, + 'bleedBL2', g_bleed) + + # Bottom right Mark + self.draw_bleed_line(self.area_x2 + br, offset_bottom + bmb, + self.area_x2 + br, offset_bottom + bmb + self.mark_size, + 'bleedBR1', g_bleed) + self.draw_bleed_line(offset_right + bmr, self.area_y2 + bb, + offset_right + bmr + self.mark_size, self.area_y2 + bb, + 'bleedBR2', g_bleed) + + # Registration Mark + if self.options.reg_marks == True: + # Create a group for Registration Mark + g_attribs = {inkex.addNS('label','inkscape'):'RegistrationMarks', + 'id':'RegistrationMarks'} + g_center = inkex.etree.SubElement(layer, 'g', g_attribs) + + # Left Mark + cx = max( bml + offset, self.min_mark_margin ) + self.draw_reg_marks(self.area_x1 - cx - (self.mark_size/2), + middle_vertical - self.mark_size*1.5, + '0', 'regMarkL', g_center) + + # Right Mark + cx = max( bmr + offset, self.min_mark_margin ) + self.draw_reg_marks(self.area_x2 + cx + (self.mark_size/2), + middle_vertical - self.mark_size*1.5, + '180', 'regMarkR', g_center) + + # Top Mark + cy = max( bmt + offset, self.min_mark_margin ) + self.draw_reg_marks(middle_horizontal, + self.area_y1 - cy - (self.mark_size/2), + '90', 'regMarkT', g_center) + + # Bottom Mark + cy = max( bmb + offset, self.min_mark_margin ) + self.draw_reg_marks(middle_horizontal, + self.area_y2 + cy + (self.mark_size/2), + '-90', 'regMarkB', g_center) + + # Star Target + if self.options.star_target == True: + # Create a group for Star Target + g_attribs = {inkex.addNS('label','inkscape'):'StarTarget', + 'id':'StarTarget'} + g_center = inkex.etree.SubElement(layer, 'g', g_attribs) + + if self.area_h < self.area_w : + # Left Star + cx = max( bml + offset, self.min_mark_margin ) + self.draw_star_target(self.area_x1 - cx - (self.mark_size/2), + middle_vertical, + 'starTargetL', g_center) + # Right Star + cx = max( bmr + offset, self.min_mark_margin ) + self.draw_star_target(self.area_x2 + cx + (self.mark_size/2), + middle_vertical, + 'starTargetR', g_center) + else : + # Top Star + cy = max( bmt + offset, self.min_mark_margin ) + self.draw_star_target(middle_horizontal - self.mark_size*1.5, + self.area_y1 - cy - (self.mark_size/2), + 'starTargetT', g_center) + # Bottom Star + cy = max( bmb + offset, self.min_mark_margin ) + self.draw_star_target(middle_horizontal - self.mark_size*1.5, + self.area_y2 + cy + (self.mark_size/2), + 'starTargetB', g_center) + + + # Colour Bars + if self.options.colour_bars == True: + # Create a group for Colour Bars + g_attribs = {inkex.addNS('label','inkscape'):'ColourBars', + 'id':'PrintingColourBars'} + g_center = inkex.etree.SubElement(layer, 'g', g_attribs) + + if self.area_h > self.area_w : + # Left Bars + cx = max( bml + offset, self.min_mark_margin ) + self.draw_coluor_bars(self.area_x1 - cx - (self.mark_size/2), + middle_vertical + self.mark_size, + 90, + 'PrintingColourBarsL', g_center) + # Right Bars + cx = max( bmr + offset, self.min_mark_margin ) + self.draw_coluor_bars(self.area_x2 + cx + (self.mark_size/2), + middle_vertical + self.mark_size, + 90, + 'PrintingColourBarsR', g_center) + else : + # Top Bars + cy = max( bmt + offset, self.min_mark_margin ) + self.draw_coluor_bars(middle_horizontal + self.mark_size, + self.area_y1 - cy - (self.mark_size/2), + 0, + 'PrintingColourBarsT', g_center) + # Bottom Bars + cy = max( bmb + offset, self.min_mark_margin ) + self.draw_coluor_bars(middle_horizontal + self.mark_size, + self.area_y2 + cy + (self.mark_size/2), + 0, + 'PrintingColourBarsB', g_center) + + + # Page Information + if self.options.page_info == True: + # Create a group for Page Information + g_attribs = {inkex.addNS('label','inkscape'):'PageInformation', + 'id':'PageInformation'} + g_pag_info = inkex.etree.SubElement(layer, 'g', g_attribs) + y_margin = max( bmb + offset, self.min_mark_margin ) + txt_attribs = { + 'style': 'font-size:12px;font-style:normal;font-weight:normal;fill:#000000;font-family:Bitstream Vera Sans,sans-serif;text-anchor:middle;text-align:center', + 'x': str(middle_horizontal), + 'y': str(self.area_y2+y_margin+self.mark_size+20) + } + txt = inkex.etree.SubElement(g_pag_info, 'text', txt_attribs) + txt.text = 'Page size: ' +\ + str(round(inkex.uutounit(self.area_w,self.options.unit),2)) +\ + 'x' +\ + str(round(inkex.uutounit(self.area_h,self.options.unit),2)) +\ + ' ' + self.options.unit + + +if __name__ == '__main__': + e = Printing_Marks() + e.affect() diff --git a/share/extensions/summersnight.py b/share/extensions/summersnight.py index d3521d285..3bfa70cbd 100755 --- a/share/extensions/summersnight.py +++ b/share/extensions/summersnight.py @@ -17,9 +17,17 @@ 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, simpletransform, voronoi2svg -from ffgeom import * import gettext +import os + +import cubicsuperpath +import inkex +import simplepath +import simpletransform +import voronoi2svg + +from ffgeom import * + _ = gettext.gettext try: @@ -30,7 +38,8 @@ except: class Project(inkex.Effect): def __init__(self): - inkex.Effect.__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.")) @@ -122,6 +131,7 @@ class Project(inkex.Effect): p = intersectSegments(vert,horz) return [p['x'],p['y']] + if __name__ == '__main__': e = Project() e.affect() -- cgit v1.2.3