'''
Copyright (C) 2010 Craig Marshall, craig9 [at] gmail.com
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
-----------------------
This script slices an inkscape drawing along the guides, similarly to
the GIMP plugin called "guillotine". It can optionally export to the
same directory as the SVG file with the same name, but with a number
suffix. e.g.
will export to:
etc.
'''
# standard library
import locale
import os
import sys
try:
except:
# local library
import inkex
import simplestyle
def float_sort(a, b):
'''
This is used to sort the horizontal and vertical guide positions,
which are floating point numbers, but which are held as text.
'''
"""Exports slices made using guides"""
'''
Returns all guide elements as an iterable collection
'''
guides = []
for g in xpath:
guide = {}
guide['position'] = y
guide['position'] = x
return guides
'''
Returns all horizontal guides as a list of floats stored as
strings. Each value is the position from 0 in pixels.
'''
guides = []
for g in self.get_guides():
if g['orientation'] == 'horizontal':
return guides
'''
Returns all vertical guides as a list of floats stored as
strings. Each value is the position from 0 in pixels.
'''
guides = []
for g in self.get_guides():
if g['orientation'] == 'vertical':
return guides
'''
Make a sorted list of all horizontal guide positions,
including 0 and the document height, but not including
those outside of the canvas
'''
horizontals = ['0']
for h in self.get_all_horizontal_guides():
return horizontals
'''
Make a sorted list of all vertical guide positions,
including 0 and the document width, but not including
those outside of the canvas.
'''
verticals = ['0']
for v in self.get_all_vertical_guides():
return verticals
'''
Returns a list of all "slices" as denoted by the guides
on the page. Each slice is really just a 4 element list of
floats (stored as strings), consisting of the X and Y start
position and the X and Y end position.
'''
slices = []
return slices
'''
Attempts to get directory and image as passed in by the inkscape
dialog. If the boolean ignore flag is set, then it will ignore
these settings and try to use the settings from the export
filename.
'''
else:
'''
First get the export-filename from the document, if the
document has been exported before (TODO: Will not work if it
hasn't been exported yet), then uses this to return a tuple
consisting of the directory to export to, and the filename
without extension.
'''
att = '{http://www.inkscape.org/namespaces/inkscape}export-filename'
try:
except KeyError:
"need to have previously exported the document. " +
"Otherwise no export hints exist!")
'''
Runs inkscape's command line interface and exports the image
slice from the 4 coordinates in s, and saves as the filename
given.
'''
command = "inkscape -a %s:%s:%s:%s -e \"%s\" \"%s\" " % (self.get_localised_string(s[0]), self.get_localised_string(s[1]), self.get_localised_string(s[2]), self.get_localised_string(s[3]), filename, svg_file)
if bsubprocess:
return_code = p.wait()
f = p.stdout
else:
f.close()
'''
Takes the slices list and passes each one with a calculated
'''
output_files = list()
dirname = './'
i = 0
for s in slices:
self.export_slice(s, f)
i += 1
if __name__ == "__main__":
e = Guillotine()
e.affect()