summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2014-03-01 15:28:39 +0000
committerJabiertxof <jtx@jtx.marker.es>2014-03-01 15:28:39 +0000
commitefabd8330ec1bfda05e46c5315debc43e6dbca34 (patch)
treeee0a4d3a0898beca0aa9345c71fb5c5c9a55d9a8 /share
parentSubstitute isBSpline property by a cached function isBSpline(bool) (diff)
parentupdate po/POTFILES.in (add new INX file from r13080) (diff)
downloadinkscape-efabd8330ec1bfda05e46c5315debc43e6dbca34.tar.gz
inkscape-efabd8330ec1bfda05e46c5315debc43e6dbca34.zip
update to trunk
(bzr r11950.1.262)
Diffstat (limited to 'share')
-rw-r--r--share/extensions/Makefile.am2
-rw-r--r--share/extensions/tar_layers.inx19
-rwxr-xr-xshare/extensions/tar_layers.py113
3 files changed, 134 insertions, 0 deletions
diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am
index b53446999..c107f7646 100644
--- a/share/extensions/Makefile.am
+++ b/share/extensions/Makefile.am
@@ -159,6 +159,7 @@ extensions = \
synfig_prepare.py \
text_extract.py \
svg_transform.py \
+ tar_layers.py \
text_uppercase.py \
text_lowercase.py \
text_sentencecase.py \
@@ -342,6 +343,7 @@ modules = \
svg_and_media_zip_output.inx \
svgcalendar.inx \
synfig_output.inx \
+ tar_layers.inx \
text_extract.inx \
text_uppercase.inx\
text_lowercase.inx \
diff --git a/share/extensions/tar_layers.inx b/share/extensions/tar_layers.inx
new file mode 100644
index 000000000..43664c910
--- /dev/null
+++ b/share/extensions/tar_layers.inx
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
+ <_name>Collection of SVG files One per root layer</_name>
+ <id>org.inkscape.output.LAYERS</id>
+ <dependency type="extension">org.inkscape.output.svg.inkscape</dependency>
+ <dependency type="executable" location="extensions">tar_layers.py</dependency>
+ <dependency type="executable" location="extensions">inkex.py</dependency>
+ <output>
+ <extension>.tar</extension>
+ <mimetype>application/tar</mimetype>
+ <_filetypename>Layers as Seperate SVG (*.tar)</_filetypename>
+ <_filetypetooltip>Each layer split into it's own svg file and collected as a tape archive (tar file)</_filetypetooltip>
+ <dataloss>false</dataloss>
+ </output>
+ <script>
+ <command reldir="extensions" interpreter="python">tar_layers.py</command>
+ <helper_extension>org.inkscape.output.svg.inkscape</helper_extension>
+ </script>
+</inkscape-extension>
diff --git a/share/extensions/tar_layers.py b/share/extensions/tar_layers.py
new file mode 100755
index 000000000..8d7ce0541
--- /dev/null
+++ b/share/extensions/tar_layers.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2014 Martin Owens, email@doctormo.org
+#
+# 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
+#
+"""
+An extention to export multiple svg files from a single svg file containing layers.
+
+Each defs is duplicated for each svg outputed.
+"""
+import os
+import sys
+import copy
+import tarfile
+import StringIO
+
+# Inkscape Libraries
+import inkex
+import simplestyle
+
+GROUP = "{http://www.w3.org/2000/svg}g"
+LABEL = "{http://www.inkscape.org/namespaces/inkscape}label"
+GROUPMODE = "{http://www.inkscape.org/namespaces/inkscape}groupmode"
+
+
+def oprint(item):
+ """DEBUG print an object"""
+ for name in dir(item):
+ value = getattr(item, name)
+ if callable(value):
+ yield "%s()" % name
+ else:
+ yield "%s = %s" % (name, str(value))
+
+def fprint(data):
+ """DEBUG print something"""
+ if isinstance(data, basestring):
+ sys.stderr.write("DEBUG: %s\n" % data)
+ else:
+ return fprint("%s(%s)\n " % (str(data), type(data).__name__) \
+ + "\n ".join(oprint(data)))
+
+
+class LayersOutput(inkex.Effect):
+ """Entry point to our layers export"""
+ def __init__(self):
+ inkex.Effect.__init__(self)
+ if os.name == 'nt':
+ self.encoding = "cp437"
+ else:
+ self.encoding = "latin-1"
+
+ def make_template(self):
+ """Returns the current document as a new empty document with the same defs"""
+ newdoc = copy.deepcopy(self.document)
+ for (name, layer) in self.layers(newdoc):
+ layer.getparent().remove(layer)
+ return newdoc
+
+ def layers(self, document):
+ for node in document.getroot().iterchildren():
+ if self.is_layer(node):
+ name = node.attrib.get(LABEL, None)
+ if name:
+ yield (name, node)
+
+ def is_layer(self, node):
+ return node.tag == GROUP and node.attrib.get(GROUPMODE,'').lower() == 'layer'
+
+ def io_document(self, name, doc):
+ string = StringIO.StringIO()
+ doc.write(string)
+ string.seek(0)
+ info = tarfile.TarInfo(name=name+'.svg')
+ info.size=len(string.buf)
+ return dict(tarinfo=info, fileobj=string)
+
+ def effect(self):
+ # open output tar file as a stream (to stdout)
+ tar = tarfile.open(fileobj=sys.stdout, mode='w|')
+
+ template = self.make_template()
+
+ previous = None
+ for (name, _layer) in self.layers(self.document):
+ layer = copy.deepcopy(_layer)
+ if previous != None:
+ template.getroot().replace(previous, layer)
+ else:
+ template.getroot().append(layer)
+ previous = layer
+
+ tar.addfile(**self.io_document(name, template))
+
+
+if __name__ == '__main__': #pragma: no cover
+ e = LayersOutput()
+ e.affect()
+
+# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99