diff options
| author | Aaron Spike <aaron@ekips.org> | 2008-05-03 20:26:45 +0000 |
|---|---|---|
| committer | acspike <acspike@users.sourceforge.net> | 2008-05-03 20:26:45 +0000 |
| commit | e8ca3c02671e0efed6e8c19b9aa7cc6cde832401 (patch) | |
| tree | 5ac33f3a505bb8647333b77d53d4da9d01b06a1b | |
| parent | Cmake: Fixed HAVE_CAIRO_PDF and moved ConfigChecks to it's own file (diff) | |
| download | inkscape-e8ca3c02671e0efed6e8c19b9aa7cc6cde832401.tar.gz inkscape-e8ca3c02671e0efed6e8c19b9aa7cc6cde832401.zip | |
Export grid and guides to XCF (Bug #222655)
Patch by PsychoAlienDog. Excellent work. We may want to reexamine the printing of debug info by xpathSingle() when there is no grid.
(bzr r5591)
| -rw-r--r-- | share/extensions/gimp_xcf.inx | 3 | ||||
| -rwxr-xr-x | share/extensions/gimp_xcf.py | 77 |
2 files changed, 79 insertions, 1 deletions
diff --git a/share/extensions/gimp_xcf.inx b/share/extensions/gimp_xcf.inx index 8f54cd6c0..904720af9 100644 --- a/share/extensions/gimp_xcf.inx +++ b/share/extensions/gimp_xcf.inx @@ -6,6 +6,9 @@ <dependency type="executable" location="extensions">gimp_xcf.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> <dependency type="executable" location="path">gimp</dependency> + + <param name="guides" type="boolean" _gui-text="Save Guides:"></param> + <param name="grid" type="boolean" _gui-text="Save Grid:"></param> <output> <extension>.xcf</extension> <mimetype>application/x-xcf</mimetype> diff --git a/share/extensions/gimp_xcf.py b/share/extensions/gimp_xcf.py index d24b32c35..28cb8c392 100755 --- a/share/extensions/gimp_xcf.py +++ b/share/extensions/gimp_xcf.py @@ -22,14 +22,69 @@ import sys, os, tempfile class MyEffect(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) + self.OptionParser.add_option("-d", "--guides", + 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") def output(self): pass def effect(self): svg_file = self.args[-1] docname = self.xpathSingle('/svg:svg/@sodipodi:docname')[:-4] + pageHeight = int(self.xpathSingle('/svg:svg/@height').split('.')[0]) + pageWidth = int(self.xpathSingle('/svg:svg/@width').split('.')[0]) #create os temp dir tmp_dir = tempfile.mkdtemp() + + hGuides = [] + vGuides = [] + if self.options.saveGuides: + guideXpath = "sodipodi:namedview/sodipodi:guide" #grab all guide tags in the namedview tag + for guideNode in self.document.xpath(guideXpath, namespaces=inkex.NSS): + ori = guideNode.get('orientation') + if ori == '0,1': + #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 + if pos > 0 and pos < pageHeight: + #the origin is at the top in GIMP land + hGuides.append(str(pageHeight - pos)) + elif ori == '1,0': + #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 + if pos > 0 and pos < pageWidth: + vGuides.append(str(pos)) + + hGList = ' '.join(hGuides) + vGList = ' '.join(vGuides) + + gridSpacingFunc = '' + gridOriginFunc = '' + #GIMP only allows one rectangular grid + if self.options.saveGrid: + gridNode = self.xpathSingle("sodipodi:namedview/inkscape:grid[@type='xygrid' and (not(@units) or @units='px')]") + if gridNode != None: + #these attributes could be nonexistant + spacingX = gridNode.get('spacingx') + if spacingX == None: spacingX = '1 ' + + spacingY = gridNode.get('spacingy') + if spacingY == None: spacingY = '1 ' + + originX = gridNode.get('originx') + if originX == None: originX = '0 ' + + originY = gridNode.get('originy') + if originY == None: originY = '0 ' + + gridSpacingFunc = '(gimp-image-grid-set-spacing img %s %s)' % (spacingX[:-2], spacingY[:-2]) + gridOriginFunc = '(gimp-image-grid-set-offset img %s %s)'% (originX[:-2], originY[:-2]) area = '--export-area-canvas' pngs = [] @@ -75,11 +130,30 @@ class MyEffect(inkex.Effect): ) (map cons '(%s) '(%s)) ) + (gimp-image-resize-to-layers img) + + (for-each + (lambda (hGuide) + (gimp-image-add-hguide img hGuide) + ) + '(%s) + ) + + (for-each + (lambda (vGuide) + (gimp-image-add-vguide img vGuide) + ) + '(%s) + ) + + %s + %s + (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, xcf, xcf) + """ % (filelist, namelist, hGList, vGList, gridSpacingFunc, gridOriginFunc, xcf, xcf) junk = os.path.join(tmp_dir, 'junk_from_gimp.txt') f = os.popen('gimp -i --batch-interpreter plug-in-script-fu-eval -b - > %s 2>&1' % junk,'w') @@ -96,3 +170,4 @@ class MyEffect(inkex.Effect): e = MyEffect() e.affect() + |
