From 400bd7de610121bd8fbf4f38b47dabc1a0df0ee3 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sun, 28 Mar 2010 08:35:33 +0200 Subject: Extensions. Use uniconvertor first, instead of uniconv. Fixed bugs: - https://launchpad.net/bugs/226383 (bzr r9246) --- share/extensions/uniconv-ext.py | 8 ++++---- share/extensions/uniconv_output.py | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/uniconv-ext.py b/share/extensions/uniconv-ext.py index 6869196a5..3b248d8b8 100644 --- a/share/extensions/uniconv-ext.py +++ b/share/extensions/uniconv-ext.py @@ -28,13 +28,13 @@ cmd = None try: from subprocess import Popen, PIPE - p = Popen('uniconv', shell=True, stdout=PIPE, stderr=PIPE).wait() + p = Popen('uniconvertor', shell=True, stdout=PIPE, stderr=PIPE).wait() if p==0 : - cmd = 'uniconv' + cmd = 'uniconvertor' else: - p = Popen('uniconvertor', shell=True, stdout=PIPE, stderr=PIPE).wait() + p = Popen('uniconv', shell=True, stdout=PIPE, stderr=PIPE).wait() if p==0 : - cmd = 'uniconvertor' + cmd = 'uniconv' except ImportError: from popen2 import Popen3 p = Popen3('uniconv', True).wait() diff --git a/share/extensions/uniconv_output.py b/share/extensions/uniconv_output.py index ee32edae3..ffd78736b 100644 --- a/share/extensions/uniconv_output.py +++ b/share/extensions/uniconv_output.py @@ -92,21 +92,21 @@ def run(command_format, prog_name, uniconv_format): def get_command(): cmd = None - try: - from subprocess import Popen, PIPE +try: + from subprocess import Popen, PIPE + p = Popen('uniconvertor', shell=True, stdout=PIPE, stderr=PIPE).wait() + if p==0 : + cmd = 'uniconvertor' + else: p = Popen('uniconv', shell=True, stdout=PIPE, stderr=PIPE).wait() if p==0 : cmd = 'uniconv' - else: - p = Popen('uniconvertor', shell=True, stdout=PIPE, stderr=PIPE).wait() - if p==0 : - cmd = 'uniconvertor' - except ImportError: - from popen2 import Popen3 - p = Popen3('uniconv', True).wait() - if p!=32512 : cmd = 'uniconv' - p = Popen3('uniconvertor', True).wait() - if p!=32512 : cmd = 'uniconvertor' +except ImportError: + from popen2 import Popen3 + p = Popen3('uniconv', True).wait() + if p!=32512 : cmd = 'uniconv' + p = Popen3('uniconvertor', True).wait() + if p!=32512 : cmd = 'uniconvertor' if cmd == None: # there's no succeffully-returning uniconv command; try to get the module directly (on Windows) -- cgit v1.2.3 From de0d8c41b2329cc9571415c1bb93ca711c1c6bf0 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sun, 28 Mar 2010 08:45:18 +0200 Subject: Extensions. Small bug in uniconvertor output. (bzr r9247) --- share/extensions/uniconv_output.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/uniconv_output.py b/share/extensions/uniconv_output.py index ffd78736b..9cdac7fc2 100644 --- a/share/extensions/uniconv_output.py +++ b/share/extensions/uniconv_output.py @@ -92,21 +92,21 @@ def run(command_format, prog_name, uniconv_format): def get_command(): cmd = None -try: - from subprocess import Popen, PIPE - p = Popen('uniconvertor', shell=True, stdout=PIPE, stderr=PIPE).wait() - if p==0 : - cmd = 'uniconvertor' - else: - p = Popen('uniconv', shell=True, stdout=PIPE, stderr=PIPE).wait() + try: + from subprocess import Popen, PIPE + p = Popen('uniconvertor', shell=True, stdout=PIPE, stderr=PIPE).wait() if p==0 : - cmd = 'uniconv' -except ImportError: - from popen2 import Popen3 - p = Popen3('uniconv', True).wait() - if p!=32512 : cmd = 'uniconv' - p = Popen3('uniconvertor', True).wait() - if p!=32512 : cmd = 'uniconvertor' + cmd = 'uniconvertor' + else: + p = Popen('uniconv', shell=True, stdout=PIPE, stderr=PIPE).wait() + if p==0 : + cmd = 'uniconv' + except ImportError: + from popen2 import Popen3 + p = Popen3('uniconv', True).wait() + if p!=32512 : cmd = 'uniconv' + p = Popen3('uniconvertor', True).wait() + if p!=32512 : cmd = 'uniconvertor' if cmd == None: # there's no succeffully-returning uniconv command; try to get the module directly (on Windows) @@ -122,6 +122,7 @@ except ImportError: 'and install into your Inkscape\'s Python location\n')) sys.exit(1) cmd = 'python -c "from uniconvertor import uniconv; uniconv();"' + return cmd # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99 -- cgit v1.2.3 From d43f0f04589e66a600ec71b154519b34157ad784 Mon Sep 17 00:00:00 2001 From: "Aurelio A. Heckert (a)" Date: Mon, 29 Mar 2010 15:46:20 -0300 Subject: webslicer effects now extends a commom WebSlicer_Effect class (bzr r9253) --- share/extensions/webslicer-create-group.inx | 31 ----- share/extensions/webslicer-create-group.py | 98 ---------------- share/extensions/webslicer-create-rect.inx | 66 ----------- share/extensions/webslicer-create-rect.py | 174 ---------------------------- share/extensions/webslicer-export.inx | 21 ---- share/extensions/webslicer-export.py | 58 ---------- share/extensions/webslicer_create_group.inx | 32 +++++ share/extensions/webslicer_create_group.py | 98 ++++++++++++++++ share/extensions/webslicer_create_rect.inx | 67 +++++++++++ share/extensions/webslicer_create_rect.py | 160 +++++++++++++++++++++++++ share/extensions/webslicer_effect.py | 52 +++++++++ share/extensions/webslicer_export.inx | 22 ++++ share/extensions/webslicer_export.py | 55 +++++++++ 13 files changed, 486 insertions(+), 448 deletions(-) delete mode 100644 share/extensions/webslicer-create-group.inx delete mode 100755 share/extensions/webslicer-create-group.py delete mode 100644 share/extensions/webslicer-create-rect.inx delete mode 100755 share/extensions/webslicer-create-rect.py delete mode 100644 share/extensions/webslicer-export.inx delete mode 100755 share/extensions/webslicer-export.py create mode 100644 share/extensions/webslicer_create_group.inx create mode 100755 share/extensions/webslicer_create_group.py create mode 100644 share/extensions/webslicer_create_rect.inx create mode 100755 share/extensions/webslicer_create_rect.py create mode 100644 share/extensions/webslicer_effect.py create mode 100644 share/extensions/webslicer_export.inx create mode 100755 share/extensions/webslicer_export.py (limited to 'share/extensions') diff --git a/share/extensions/webslicer-create-group.inx b/share/extensions/webslicer-create-group.inx deleted file mode 100644 index b5c5b48ed..000000000 --- a/share/extensions/webslicer-create-group.inx +++ /dev/null @@ -1,31 +0,0 @@ - - - <_name>Set a layout group - org.inkscape.web.slicer.create-group - webslicer-create-group.py - inkex.py - <_param name="about" type="description">Layout Group is only about to help a better code generation (if you need it). To use this, first you must to select some "Slicer rectangles". - - - - <_item value="px">Pixel (fixed) - <_item value="percent">Percent (relative to parent size) - <_item value="undefined">Undefined (relative to non-floating content size) - - - <_item value="px">Pixel (fixed) - <_item value="percent">Percent (relative to parent size) - <_item value="undefined">Undefined (relative to non-floating content size) - - - all - - - - - - - - diff --git a/share/extensions/webslicer-create-group.py b/share/extensions/webslicer-create-group.py deleted file mode 100755 index aadfded38..000000000 --- a/share/extensions/webslicer-create-group.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python -''' -Copyright (C) 2010 Aurelio A. Heckert, aurium (a) gmail dot com - -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 -import gettext - -_ = gettext.gettext - -def is_empty(val): - if val is None: - return True - else: - return len(str(val)) == 0 - -class WebSlicer_CreateGroup(inkex.Effect): - - def __init__(self): - inkex.Effect.__init__(self) - self.OptionParser.add_option("--html-id", - action="store", type="string", - dest="html_id", - help="") - self.OptionParser.add_option("--html-class", - action="store", type="string", - dest="html_class", - help="") - self.OptionParser.add_option("--width-unity", - action="store", type="string", - dest="width_unity", - help="") - self.OptionParser.add_option("--height-unity", - action="store", type="string", - dest="height_unity", - help="") - - - def get_base_elements(self): - layerArr = self.document.xpath( - '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', - namespaces=inkex.NSS) - if len(layerArr) > 0: - self.layer = layerArr[0] - else: - inkex.errormsg(_('You must to create and select some "Slicer rectangles" before try to group.')) - exit(3) - self.layer_descendants = self.get_descendants_in_array(self.layer) - - - def get_descendants_in_array(self, el): - descendants = el.getchildren() - for e in descendants: - descendants.extend( self.get_descendants_in_array(e) ) - return descendants - - - def effect(self): - self.get_base_elements() - if len(self.selected) == 0: - inkex.errormsg(_('You must to select some "Slicer rectangles" or other "Layout groups".')) - exit(1) - for id,node in self.selected.iteritems(): - if node not in self.layer_descendants: - inkex.errormsg(_('Opss... The element "%s" is not in the Web Slicer layer') % id) - exit(2) - g_parent = self.getParentNode(node) - group = inkex.etree.SubElement(g_parent, 'g') - desc = inkex.etree.SubElement(group, 'desc') - conf_txt = '' - if not is_empty(self.options.html_id): - conf_txt += 'html-id:' + self.options.html_id +'\n' - if not is_empty(self.options.html_class): - conf_txt += 'html-class:' + self.options.html_class +'\n' - conf_txt += 'width-unity:' + self.options.width_unity +'\n' - conf_txt += 'height-unity:' + self.options.height_unity - desc.text = conf_txt - for id,node in self.selected.iteritems(): - group.insert( 1, node ) - - -if __name__ == '__main__': - e = WebSlicer_CreateGroup() - e.affect() diff --git a/share/extensions/webslicer-create-rect.inx b/share/extensions/webslicer-create-rect.inx deleted file mode 100644 index 7ac681e69..000000000 --- a/share/extensions/webslicer-create-rect.inx +++ /dev/null @@ -1,66 +0,0 @@ - - - <_name>Create a slicer rectangle - org.inkscape.web.slicer.create-rect - webslicer-create-rect.py - inkex.py - - - PNG - JPG - GIF - - 90 - - <_param name="help-dimension1" type="description">Force Dimension must be set as "<width>x<height>" - <_param name="help-dimension2" type="description">If had set, this will replace DPI. - - - - <_param name="help-jpg" type="description">JPG specific options - 85 - <_param name="help-quality" type="description">0 is the lowest image quality and highest compression, and 100 is the best quality but least effective compression - - - <_param name="help-gif" type="description">GIF specific options - - <_item value="grayscale">Grayscale - <_item value="palette">Palette - - 256 - - - - - <_param name="help-gif" type="description">Options for HTML export - - <_item value="bg-parent-repeat">Tiled Background (on parent group) - <_item value="bg-parent-repeat-x">Background — repeat horizontally (on parent group) - <_item value="bg-parent-repeat-y">Background — repeat vertically (on parent group) - <_item value="bg-parent-norepeat">Background — no repeat (on parent group) - <_item value="bg-div-norepeat">Positioned <div> width the image as Background - <_item value="img-pos">Positioned Image - <_item value="img-nonpos">Non Positioned Image - <_item value="img-float-left">Left Floated Image - <_item value="img-float-right">Right Floated Image - - - <_item value="tl">Top and Left - <_item value="tr">Top and right - <_item value="bl">Bottom and Left - <_item value="br">Bottom and Right - - - - - all - - - - - - - - diff --git a/share/extensions/webslicer-create-rect.py b/share/extensions/webslicer-create-rect.py deleted file mode 100755 index 957d6a8b2..000000000 --- a/share/extensions/webslicer-create-rect.py +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/env python -''' -Copyright (C) 2010 Aurelio A. Heckert, aurium (a) gmail dot com - -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 -import gettext - -_ = gettext.gettext - -def is_empty(val): - if val is None: - return True - else: - return len(str(val)) == 0 - -class WebSlicer_CreateRect(inkex.Effect): - - def __init__(self): - inkex.Effect.__init__(self) - self.OptionParser.add_option("--name", - action="store", type="string", - dest="name", - help="") - self.OptionParser.add_option("--format", - action="store", type="string", - dest="format", - help="") - self.OptionParser.add_option("--dpi", - action="store", type="int", - dest="dpi", - help="") - self.OptionParser.add_option("--dimension", - action="store", type="string", - dest="dimension", - help="") - self.OptionParser.add_option("--bg-color", - action="store", type="string", - dest="bg_color", - help="") - self.OptionParser.add_option("--quality", - action="store", type="int", - dest="quality", - help="") - self.OptionParser.add_option("--gif-type", - action="store", type="string", - dest="gif_type", - help="") - self.OptionParser.add_option("--palette-size", - action="store", type="int", - dest="palette_size", - help="") - self.OptionParser.add_option("--html-id", - action="store", type="string", - dest="html_id", - help="") - self.OptionParser.add_option("--html-class", - action="store", type="string", - dest="html_class", - help="") - self.OptionParser.add_option("--layout-disposition", - action="store", type="string", - dest="layout_disposition", - help="") - self.OptionParser.add_option("--layout-position-anchor", - action="store", type="string", - dest="layout_position_anchor", - help="") - # inkscape param workarround - self.OptionParser.add_option("--tab") - - - def unique_slice_name(self): - name = self.options.name - el = self.document.xpath( '//*[@id="'+name+'"]', namespaces=inkex.NSS ) - if len(el) > 0: - if name[-3:] == '-00': name = name[:-3] - num = 0 - num_s = '00' - while len(el) > 0: - num += 1 - num_s = str(num) - if len(num_s)==1 : num_s = '0'+num_s - el = self.document.xpath( '//*[@id="'+name+'-'+num_s+'"]', - namespaces=inkex.NSS ) - self.options.name = name+'-'+num_s - - - def validate_options(self): - self.options.format = self.options.ensure_value('format', 'png').lower() - if not is_empty( self.options.dimension ): - self.options.dimension - - def effect(self): - self.validate_options() - layer = self.get_slicer_layer() - #TODO: get selected elements to define location and size - rect = inkex.etree.SubElement(layer, 'rect') - if is_empty(self.options.name): - self.options.name = 'slice-00' - self.unique_slice_name() - rect.set('id', self.options.name) - rect.set('fill', 'red') - rect.set('opacity', '0.5') - rect.set('x', '-100') - rect.set('y', '-100') - rect.set('width', '200') - rect.set('height', '200') - desc = inkex.etree.SubElement(rect, 'desc') - conf_txt = "format:"+ self.options.format +"\n" - if not is_empty(self.options.dpi): - conf_txt += "dpi:" + str(self.options.dpi) +"\n" - if not is_empty(self.options.html_id): - conf_txt += "html-id:" + self.options.html_id - desc.text = "\n".join( self.get_full_conf_list() ) - - - - def get_conf_from_list(self, conf_atts): - conf_list = [] - for att in conf_atts: - if not is_empty(getattr(self.options, att)): - conf_list.append( att +':'+ str(getattr(self.options, att)) ) - return conf_list - - - def get_full_conf_list(self): - conf_list = [ 'format:'+self.options.format ] - if self.options.format == 'gif': - conf_list.extend( get_conf_from_list([ 'gif_type', 'palette_size' ]) ) - if self.options.format == 'jpg': - conf_list.extend( get_conf_from_list([ 'quality' ]) ) - conf_general_atts = [ - 'dpi', 'dimension', - 'bg_color', 'html_id', 'html_class', - 'layout_disposition', 'layout_position_anchor' - ] - conf_list.extend( get_conf_from_list(conf_general_atts) ) - return conf_list - - - def get_slicer_layer(self): - # Test if webslicer-layer layer existis - layer = self.document.xpath( - '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', - namespaces=inkex.NSS) - if len(layer) is 0: - # Create a new layer - layer = inkex.etree.SubElement(self.document.getroot(), 'g') - layer.set('id', 'webslicer-layer') - layer.set(inkex.addNS('label', 'inkscape'), 'Web Slicer') - layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer') - else: - layer = layer[0] - return layer - - -if __name__ == '__main__': - e = WebSlicer_CreateRect() - e.affect() diff --git a/share/extensions/webslicer-export.inx b/share/extensions/webslicer-export.inx deleted file mode 100644 index 9f7aac323..000000000 --- a/share/extensions/webslicer-export.inx +++ /dev/null @@ -1,21 +0,0 @@ - - - <_name>Export layout pieces and HTML+CSS code - org.inkscape.web.slicer.export - webslicer-export.py - inkex.py - <_param name="about" type="description">All sliced images, and optionaly code, will be generated as you had configured and saved to one directory. - - true - - all - - - - - - - - diff --git a/share/extensions/webslicer-export.py b/share/extensions/webslicer-export.py deleted file mode 100755 index c8e4cbb0d..000000000 --- a/share/extensions/webslicer-export.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -''' -Copyright (C) 2010 Aurelio A. Heckert, aurium (a) gmail dot com - -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 -import gettext -import os.path -import commands - -_ = gettext.gettext - -def is_empty(val): - if val is None: - return True - else: - return len(str(val)) == 0 - -class WebSlicer_Export(inkex.Effect): - - def __init__(self): - inkex.Effect.__init__(self) - self.OptionParser.add_option("--with-code", - action="store", type="string", - dest="with_code", - help="") - self.OptionParser.add_option("--dir", - action="store", type="string", - dest="dir", - help="") - - def effect(self): - if is_empty( self.options.dir ): - inkex.errormsg(_('You must to give a directory to export the slices.')) - return - if not os.path.exists( self.options.dir ): - inkex.errormsg(_('The directory "%s" does not exists.') % self.options.dir) - return - (status, output) = commands.getstatusoutput("inkscape -e ...") - - -if __name__ == '__main__': - e = WebSlicer_Export() - e.affect() diff --git a/share/extensions/webslicer_create_group.inx b/share/extensions/webslicer_create_group.inx new file mode 100644 index 000000000..3e4a66dec --- /dev/null +++ b/share/extensions/webslicer_create_group.inx @@ -0,0 +1,32 @@ + + + <_name>Set a layout group + org.inkscape.web.slicer.create-group + webslicer_effect.py + webslicer_create_group.py + inkex.py + <_param name="about" type="description">Layout Group is only about to help a better code generation (if you need it). To use this, first you must to select some "Slicer rectangles". + + + + <_item value="px">Pixel (fixed) + <_item value="percent">Percent (relative to parent size) + <_item value="undefined">Undefined (relative to non-floating content size) + + + <_item value="px">Pixel (fixed) + <_item value="percent">Percent (relative to parent size) + <_item value="undefined">Undefined (relative to non-floating content size) + + + all + + + + + + + + diff --git a/share/extensions/webslicer_create_group.py b/share/extensions/webslicer_create_group.py new file mode 100755 index 000000000..aadfded38 --- /dev/null +++ b/share/extensions/webslicer_create_group.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +''' +Copyright (C) 2010 Aurelio A. Heckert, aurium (a) gmail dot com + +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 +import gettext + +_ = gettext.gettext + +def is_empty(val): + if val is None: + return True + else: + return len(str(val)) == 0 + +class WebSlicer_CreateGroup(inkex.Effect): + + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option("--html-id", + action="store", type="string", + dest="html_id", + help="") + self.OptionParser.add_option("--html-class", + action="store", type="string", + dest="html_class", + help="") + self.OptionParser.add_option("--width-unity", + action="store", type="string", + dest="width_unity", + help="") + self.OptionParser.add_option("--height-unity", + action="store", type="string", + dest="height_unity", + help="") + + + def get_base_elements(self): + layerArr = self.document.xpath( + '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', + namespaces=inkex.NSS) + if len(layerArr) > 0: + self.layer = layerArr[0] + else: + inkex.errormsg(_('You must to create and select some "Slicer rectangles" before try to group.')) + exit(3) + self.layer_descendants = self.get_descendants_in_array(self.layer) + + + def get_descendants_in_array(self, el): + descendants = el.getchildren() + for e in descendants: + descendants.extend( self.get_descendants_in_array(e) ) + return descendants + + + def effect(self): + self.get_base_elements() + if len(self.selected) == 0: + inkex.errormsg(_('You must to select some "Slicer rectangles" or other "Layout groups".')) + exit(1) + for id,node in self.selected.iteritems(): + if node not in self.layer_descendants: + inkex.errormsg(_('Opss... The element "%s" is not in the Web Slicer layer') % id) + exit(2) + g_parent = self.getParentNode(node) + group = inkex.etree.SubElement(g_parent, 'g') + desc = inkex.etree.SubElement(group, 'desc') + conf_txt = '' + if not is_empty(self.options.html_id): + conf_txt += 'html-id:' + self.options.html_id +'\n' + if not is_empty(self.options.html_class): + conf_txt += 'html-class:' + self.options.html_class +'\n' + conf_txt += 'width-unity:' + self.options.width_unity +'\n' + conf_txt += 'height-unity:' + self.options.height_unity + desc.text = conf_txt + for id,node in self.selected.iteritems(): + group.insert( 1, node ) + + +if __name__ == '__main__': + e = WebSlicer_CreateGroup() + e.affect() diff --git a/share/extensions/webslicer_create_rect.inx b/share/extensions/webslicer_create_rect.inx new file mode 100644 index 000000000..776d269e8 --- /dev/null +++ b/share/extensions/webslicer_create_rect.inx @@ -0,0 +1,67 @@ + + + <_name>Create a slicer rectangle + org.inkscape.web.slicer.create-rect + webslicer_effect.py + webslicer_create_rect.py + inkex.py + + + PNG + JPG + GIF + + 90 + + <_param name="help-dimension1" type="description">Force Dimension must be set as "<width>x<height>" + <_param name="help-dimension2" type="description">If had set, this will replace DPI. + + + + <_param name="help-jpg" type="description">JPG specific options + 85 + <_param name="help-quality" type="description">0 is the lowest image quality and highest compression, and 100 is the best quality but least effective compression + + + <_param name="help-gif" type="description">GIF specific options + + <_item value="grayscale">Grayscale + <_item value="palette">Palette + + 256 + + + + + <_param name="help-gif" type="description">Options for HTML export + + <_item value="bg-parent-repeat">Tiled Background (on parent group) + <_item value="bg-parent-repeat-x">Background — repeat horizontally (on parent group) + <_item value="bg-parent-repeat-y">Background — repeat vertically (on parent group) + <_item value="bg-parent-norepeat">Background — no repeat (on parent group) + <_item value="bg-div-norepeat">Positioned <div> width the image as Background + <_item value="img-pos">Positioned Image + <_item value="img-nonpos">Non Positioned Image + <_item value="img-float-left">Left Floated Image + <_item value="img-float-right">Right Floated Image + + + <_item value="tl">Top and Left + <_item value="tr">Top and right + <_item value="bl">Bottom and Left + <_item value="br">Bottom and Right + + + + + all + + + + + + + + diff --git a/share/extensions/webslicer_create_rect.py b/share/extensions/webslicer_create_rect.py new file mode 100755 index 000000000..8c1e5e5ac --- /dev/null +++ b/share/extensions/webslicer_create_rect.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python +''' +Copyright (C) 2010 Aurelio A. Heckert, aurium (a) gmail dot com + +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 webslicer_effect +import inkex +import gettext + +_ = gettext.gettext + +def is_empty(val): + if val is None: + return True + else: + return len(str(val)) == 0 + +class WebSlicer_CreateRect(webslicer_effect.WebSlicer_Effect): + + def __init__(self): + webslicer_effect.WebSlicer_Effect.__init__(self) + self.OptionParser.add_option("--name", + action="store", type="string", + dest="name", + help="") + self.OptionParser.add_option("--format", + action="store", type="string", + dest="format", + help="") + self.OptionParser.add_option("--dpi", + action="store", type="int", + dest="dpi", + help="") + self.OptionParser.add_option("--dimension", + action="store", type="string", + dest="dimension", + help="") + self.OptionParser.add_option("--bg-color", + action="store", type="string", + dest="bg_color", + help="") + self.OptionParser.add_option("--quality", + action="store", type="int", + dest="quality", + help="") + self.OptionParser.add_option("--gif-type", + action="store", type="string", + dest="gif_type", + help="") + self.OptionParser.add_option("--palette-size", + action="store", type="int", + dest="palette_size", + help="") + self.OptionParser.add_option("--html-id", + action="store", type="string", + dest="html_id", + help="") + self.OptionParser.add_option("--html-class", + action="store", type="string", + dest="html_class", + help="") + self.OptionParser.add_option("--layout-disposition", + action="store", type="string", + dest="layout_disposition", + help="") + self.OptionParser.add_option("--layout-position-anchor", + action="store", type="string", + dest="layout_position_anchor", + help="") + # inkscape param workarround + self.OptionParser.add_option("--tab") + + + def unique_slice_name(self): + name = self.options.name + el = self.document.xpath( '//*[@id="'+name+'"]', namespaces=inkex.NSS ) + if len(el) > 0: + if name[-3:] == '-00': name = name[:-3] + num = 0 + num_s = '00' + while len(el) > 0: + num += 1 + num_s = str(num) + if len(num_s)==1 : num_s = '0'+num_s + el = self.document.xpath( '//*[@id="'+name+'-'+num_s+'"]', + namespaces=inkex.NSS ) + self.options.name = name+'-'+num_s + + + def validate_options(self): + self.options.format = self.options.ensure_value('format', 'png').lower() + if not is_empty( self.options.dimension ): + self.options.dimension + + def effect(self): + self.validate_options() + layer = self.get_slicer_layer(True) + #TODO: get selected elements to define location and size + rect = inkex.etree.SubElement(layer, 'rect') + if is_empty(self.options.name): + self.options.name = 'slice-00' + self.unique_slice_name() + rect.set('id', self.options.name) + rect.set('fill', 'red') + rect.set('opacity', '0.5') + rect.set('x', '-100') + rect.set('y', '-100') + rect.set('width', '200') + rect.set('height', '200') + desc = inkex.etree.SubElement(rect, 'desc') + conf_txt = "format:"+ self.options.format +"\n" + if not is_empty(self.options.dpi): + conf_txt += "dpi:" + str(self.options.dpi) +"\n" + if not is_empty(self.options.html_id): + conf_txt += "html-id:" + self.options.html_id + desc.text = "\n".join( self.get_full_conf_list() ) + + + + def get_conf_from_list(self, conf_atts): + conf_list = [] + for att in conf_atts: + if not is_empty(getattr(self.options, att)): + conf_list.append( att +':'+ str(getattr(self.options, att)) ) + return conf_list + + + def get_full_conf_list(self): + conf_list = [ 'format:'+self.options.format ] + if self.options.format == 'gif': + conf_list.extend( self.get_conf_from_list([ 'gif_type', 'palette_size' ]) ) + if self.options.format == 'jpg': + conf_list.extend( self.get_conf_from_list([ 'quality' ]) ) + conf_general_atts = [ + 'dpi', 'dimension', + 'bg_color', 'html_id', 'html_class', + 'layout_disposition', 'layout_position_anchor' + ] + conf_list.extend( self.get_conf_from_list(conf_general_atts) ) + return conf_list + + + +if __name__ == '__main__': + e = WebSlicer_CreateRect() + e.affect() diff --git a/share/extensions/webslicer_effect.py b/share/extensions/webslicer_effect.py new file mode 100644 index 000000000..37bea447b --- /dev/null +++ b/share/extensions/webslicer_effect.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +''' +Copyright (C) 2010 Aurelio A. Heckert, aurium (a) gmail dot com + +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 + + +def is_empty(val): + if val is None: + return True + else: + return len(str(val)) == 0 + + +class WebSlicer_Effect(inkex.Effect): + + def __init__(self): + inkex.Effect.__init__(self) + + def get_slicer_layer(self, force_creation=False): + # Test if webslicer-layer layer existis + layer = self.document.xpath( + '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', + namespaces=inkex.NSS) + if len(layer) is 0: + if force_creation: + # Create a new layer + layer = inkex.etree.SubElement(self.document.getroot(), 'g') + layer.set('id', 'webslicer-layer') + layer.set(inkex.addNS('label', 'inkscape'), 'Web Slicer') + layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer') + else: + layer = None + else: + layer = layer[0] + return layer + diff --git a/share/extensions/webslicer_export.inx b/share/extensions/webslicer_export.inx new file mode 100644 index 000000000..2434c9582 --- /dev/null +++ b/share/extensions/webslicer_export.inx @@ -0,0 +1,22 @@ + + + <_name>Export layout pieces and HTML+CSS code + org.inkscape.web.slicer.export + webslicer_effect.py + webslicer_export.py + inkex.py + <_param name="about" type="description">All sliced images, and optionaly code, will be generated as you had configured and saved to one directory. + + true + + all + + + + + + + + diff --git a/share/extensions/webslicer_export.py b/share/extensions/webslicer_export.py new file mode 100755 index 000000000..1d5057a43 --- /dev/null +++ b/share/extensions/webslicer_export.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +''' +Copyright (C) 2010 Aurelio A. Heckert, aurium (a) gmail dot com + +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 webslicer_effect +import inkex +import gettext +import os.path +import commands + +_ = gettext.gettext + +class WebSlicer_Export(webslicer_effect.WebSlicer_Effect): + + def __init__(self): + webslicer_effect.WebSlicer_Effect.__init__(self) + self.OptionParser.add_option("--with-code", + action="store", type="string", + dest="with_code", + help="") + self.OptionParser.add_option("--dir", + action="store", type="string", + dest="dir", + help="") + + def effect(self): + if is_empty( self.options.dir ): + inkex.errormsg(_('You must to give a directory to export the slices.')) + return + if not os.path.exists( self.options.dir ): + inkex.errormsg(_('The directory "%s" does not exists.') % self.options.dir) + return + (status, output) = commands.getstatusoutput("inkscape -e ...") + inkex.errormsg( status ) + inkex.errormsg( output ) + + +if __name__ == '__main__': + e = WebSlicer_Export() + e.affect() -- cgit v1.2.3 From b8859cd12327c84f5ca8d4bf8614f0d0913d3c25 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Mon, 29 Mar 2010 22:32:32 +0200 Subject: Add console helper application based on inkscapec.exe from Jos Hirth, which provides Unix-like behavior on Windows. (bzr r9254) --- share/extensions/webslicer_create_group.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 share/extensions/webslicer_create_group.py (limited to 'share/extensions') diff --git a/share/extensions/webslicer_create_group.py b/share/extensions/webslicer_create_group.py old mode 100755 new mode 100644 -- cgit v1.2.3 From 8a39d60c95dc8367e398eb420c5722b54aa7fb5a Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Mon, 29 Mar 2010 23:06:33 +0200 Subject: Remove remnants of rather pointless MMX optimizations, and fix build failure caused by recent extension renames (bzr r9255) --- share/extensions/Makefile.am | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index cd409d233..a64d77203 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -133,9 +133,9 @@ extensions = \ uniconv-ext.py \ uniconv_output.py \ voronoi.py \ - webslicer-create-group.py \ - webslicer-create-rect.py \ - webslicer-export.py \ + webslicer_create_group.py \ + webslicer_create_rect.py \ + webslicer_export.py \ web-set-att.py \ web-transmit-att.py \ whirl.py \ @@ -259,9 +259,9 @@ modules = \ text_braille.inx \ triangle.inx \ txt2svg.inx \ - webslicer-create-group.inx \ - webslicer-create-rect.inx \ - webslicer-export.inx \ + webslicer_create_group.inx \ + webslicer_create_rect.inx \ + webslicer_export.inx \ web-set-att.inx \ web-transmit-att.inx \ whirl.inx \ -- cgit v1.2.3 From fe83fef83df5cdee64b4da900197cb3c9e1b9a6e Mon Sep 17 00:00:00 2001 From: "Aurelio A. Heckert (a)" Date: Mon, 29 Mar 2010 18:42:38 -0300 Subject: webslicer: preparing to export (bzr r9256) --- share/extensions/webslicer_create_group.py | 19 ++----- share/extensions/webslicer_create_rect.py | 12 +--- share/extensions/webslicer_export.inx | 1 + share/extensions/webslicer_export.py | 88 ++++++++++++++++++++++++++---- 4 files changed, 85 insertions(+), 35 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/webslicer_create_group.py b/share/extensions/webslicer_create_group.py index aadfded38..666649bfb 100644 --- a/share/extensions/webslicer_create_group.py +++ b/share/extensions/webslicer_create_group.py @@ -17,21 +17,16 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ''' +from webslicer_effect import * import inkex import gettext _ = gettext.gettext -def is_empty(val): - if val is None: - return True - else: - return len(str(val)) == 0 - -class WebSlicer_CreateGroup(inkex.Effect): +class WebSlicer_CreateGroup(WebSlicer_Effect): def __init__(self): - inkex.Effect.__init__(self) + WebSlicer_Effect.__init__(self) self.OptionParser.add_option("--html-id", action="store", type="string", dest="html_id", @@ -51,12 +46,8 @@ class WebSlicer_CreateGroup(inkex.Effect): def get_base_elements(self): - layerArr = self.document.xpath( - '//*[@id="webslicer-layer" and @inkscape:groupmode="layer"]', - namespaces=inkex.NSS) - if len(layerArr) > 0: - self.layer = layerArr[0] - else: + self.layer = self.get_slicer_layer() + if is_empty(self.layer): inkex.errormsg(_('You must to create and select some "Slicer rectangles" before try to group.')) exit(3) self.layer_descendants = self.get_descendants_in_array(self.layer) diff --git a/share/extensions/webslicer_create_rect.py b/share/extensions/webslicer_create_rect.py index 8c1e5e5ac..5fd961a13 100755 --- a/share/extensions/webslicer_create_rect.py +++ b/share/extensions/webslicer_create_rect.py @@ -17,22 +17,16 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ''' -import webslicer_effect +from webslicer_effect import * import inkex import gettext _ = gettext.gettext -def is_empty(val): - if val is None: - return True - else: - return len(str(val)) == 0 - -class WebSlicer_CreateRect(webslicer_effect.WebSlicer_Effect): +class WebSlicer_CreateRect(WebSlicer_Effect): def __init__(self): - webslicer_effect.WebSlicer_Effect.__init__(self) + WebSlicer_Effect.__init__(self) self.OptionParser.add_option("--name", action="store", type="string", dest="name", diff --git a/share/extensions/webslicer_export.inx b/share/extensions/webslicer_export.inx index 2434c9582..3a7324370 100644 --- a/share/extensions/webslicer_export.inx +++ b/share/extensions/webslicer_export.inx @@ -7,6 +7,7 @@ inkex.py <_param name="about" type="description">All sliced images, and optionaly code, will be generated as you had configured and saved to one directory. + false true all diff --git a/share/extensions/webslicer_export.py b/share/extensions/webslicer_export.py index 1d5057a43..e722ccb1a 100755 --- a/share/extensions/webslicer_export.py +++ b/share/extensions/webslicer_export.py @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ''' -import webslicer_effect +from webslicer_effect import * import inkex import gettext import os.path @@ -25,29 +25,93 @@ import commands _ = gettext.gettext -class WebSlicer_Export(webslicer_effect.WebSlicer_Effect): +class WebSlicer_Export(WebSlicer_Effect): def __init__(self): - webslicer_effect.WebSlicer_Effect.__init__(self) - self.OptionParser.add_option("--with-code", - action="store", type="string", - dest="with_code", - help="") + WebSlicer_Effect.__init__(self) self.OptionParser.add_option("--dir", action="store", type="string", dest="dir", help="") + self.OptionParser.add_option("--create-dir", + action="store", type="inkbool", + default=False, + dest="create_dir", + help="") + self.OptionParser.add_option("--with-code", + action="store", type="inkbool", + default=False, + dest="with_code", + help="") def effect(self): + # The user must supply a directory to export: if is_empty( self.options.dir ): inkex.errormsg(_('You must to give a directory to export the slices.')) - return + return {'error':'You must to give a directory to export the slices.'} + # No directory separator at the path end: + if self.options.dir[-1] == '/' or self.options.dir[-1] == '\\': + self.options.dir = self.options.dir[0:-1] + # Test if the directory exists: if not os.path.exists( self.options.dir ): - inkex.errormsg(_('The directory "%s" does not exists.') % self.options.dir) - return + if self.options.create_dir: + # Try to create it: + try: + os.makedirs( self.options.dir ) + except Exception as e: + inkex.errormsg( _('Can\'t create "%s".') % self.options.dir ) + inkex.errormsg( _('Error: %s') % e ) + return {'error':'Can\'t create the directory to export.'} + else: + inkex.errormsg(_('The directory "%s" does not exists.') % self.options.dir) + return + # Create HTML and CSS files, if the user wants: + if self.options.with_code: + try: + self.html = open(os.path.join(self.options.dir,'layout.html'), 'w') + self.css = open(os.path.join(self.options.dir,'style.css'), 'w') + except Exception as e: + inkex.errormsg( _('Can\'t create code files.') ) + inkex.errormsg( _('Error: %s') % e ) + return {'error':'Can\'t create code files.'} + # Start what we really want! + self.export_chids_of( self.get_slicer_layer() ) + # Close the HTML and CSS files: + if self.options.with_code: + self.html.close() + self.css.close() + + + def export_chids_of(self, parent): + nmspc = '{http://www.w3.org/2000/svg}' + for el in parent.getchildren(): + if el.tag == nmspc+'g': + if self.options.with_code: + self.register_group_code( el ) + else: + self.export_chids_of( el ) + if el.tag in [ nmspc+'rect', nmspc+'path', nmspc+'circle' ]: + if self.options.with_code: + self.register_unity_code( el ) + self.export_img( el ) + + + def register_group_code(self, group): + #inkex.errormsg( 'group CSS and HTML' ) + self.html.write( '
\n' ) + self.export_chids_of( group ) + self.html.write( '
\n' ) + + + def register_unity_code(self, el): + #inkex.errormsg( 'unity CSS and HTML' ) + self.html.write( el.tag + '\n' ) + + + def export_img(self, el): (status, output) = commands.getstatusoutput("inkscape -e ...") - inkex.errormsg( status ) - inkex.errormsg( output ) + #inkex.errormsg( status ) + #inkex.errormsg( output ) if __name__ == '__main__': -- cgit v1.2.3 From 546e0fe304254cd4fec7930ebf62fef55f576755 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Tue, 30 Mar 2010 18:23:12 -0400 Subject: adjustable hpgl scaling and pen number Fixed bugs: - https://launchpad.net/bugs/548918 (bzr r9262) --- share/extensions/hpgl_output.inx | 2 ++ share/extensions/hpgl_output.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/hpgl_output.inx b/share/extensions/hpgl_output.inx index f5cb9b7f8..fc65e7070 100644 --- a/share/extensions/hpgl_output.inx +++ b/share/extensions/hpgl_output.inx @@ -9,6 +9,8 @@ FALSE 0.0 0.0 + 1016 + 1 FALSE .hpgl diff --git a/share/extensions/hpgl_output.py b/share/extensions/hpgl_output.py index 8c6eaa168..28e123498 100644 --- a/share/extensions/hpgl_output.py +++ b/share/extensions/hpgl_output.py @@ -37,18 +37,26 @@ class MyEffect(inkex.Effect): action="store", type="float", dest="yOrigin", default=0.0, help="Y Origin (pixels)") + self.OptionParser.add_option("-r", "--resolution", + action="store", type="int", + dest="resolution", default=1016, + help="Resolution (dpi)") + self.OptionParser.add_option("-n", "--pen", + action="store", type="int", + dest="pen", default=1, + help="Pen number") self.OptionParser.add_option("-p", "--plotInvisibleLayers", action="store", type="inkbool", dest="plotInvisibleLayers", default="FALSE", help="Plot invisible layers") - self.hpgl = ['IN;SP1;'] def output(self): print ''.join(self.hpgl) def effect(self): + self.hpgl = ['IN;SP%d;' % self.options.pen] x0 = self.options.xOrigin y0 = self.options.yOrigin - scale = 1016.0/90 + scale = float(self.options.resolution)/90 mirror = 1.0 if self.options.mirror: mirror = -1.0 @@ -78,6 +86,7 @@ class MyEffect(inkex.Effect): cmd = 'PU' first = False self.hpgl.append('%s%d,%d;' % (cmd,(csp[1][0] - x0)*scale,(csp[1][1]*mirror - y0)*scale)) + self.hpgl.append('PU;') if __name__ == '__main__': #pragma: no cover e = MyEffect() -- cgit v1.2.3 From 6159a01be0a00d822f934ab0490aa8d92b62b2e4 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Tue, 30 Mar 2010 21:15:17 -0400 Subject: patch for Bug 465571, comment 8 (bzr r9263) --- share/extensions/render_barcode_datamatrix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'share/extensions') diff --git a/share/extensions/render_barcode_datamatrix.py b/share/extensions/render_barcode_datamatrix.py index 5db552d91..e5365546e 100644 --- a/share/extensions/render_barcode_datamatrix.py +++ b/share/extensions/render_barcode_datamatrix.py @@ -579,7 +579,7 @@ def add_finder_pattern( array, data_nrow, data_ncol, reg_row, reg_col ): def draw_SVG_square((w,h), (x,y), parent): style = { 'stroke' : 'none', - 'width' : '1', + 'stroke-width' : '1', 'fill' : '#000000' } -- cgit v1.2.3 From 802aa9cefcddbe036e54c45cb8bf2bf5b827b5ee Mon Sep 17 00:00:00 2001 From: "Aurelio A. Heckert (a)" Date: Wed, 31 Mar 2010 19:28:27 -0300 Subject: some love to webslicer export (bzr r9265) --- share/extensions/webslicer_export.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/webslicer_export.py b/share/extensions/webslicer_export.py index e722ccb1a..3a1a38135 100755 --- a/share/extensions/webslicer_export.py +++ b/share/extensions/webslicer_export.py @@ -70,6 +70,8 @@ class WebSlicer_Export(WebSlicer_Effect): try: self.html = open(os.path.join(self.options.dir,'layout.html'), 'w') self.css = open(os.path.join(self.options.dir,'style.css'), 'w') + self.html.write('Only a test yet\n\n') + self.css.write('Only a test yet\n\n') except Exception as e: inkex.errormsg( _('Can\'t create code files.') ) inkex.errormsg( _('Error: %s') % e ) @@ -82,33 +84,51 @@ class WebSlicer_Export(WebSlicer_Effect): self.css.close() + def get_el_conf(self, el): + desc = el.find('{http://www.w3.org/2000/svg}desc') + conf = {} + if desc is not None: + #desc = desc.text.split("\n") + for line in desc.text.split("\n"): + if line.find(':') > 0: + line = line.split(':') + conf[line[0].strip()] = line[1].strip() + return conf + + def export_chids_of(self, parent): nmspc = '{http://www.w3.org/2000/svg}' for el in parent.getchildren(): + el_conf = self.get_el_conf( el ) if el.tag == nmspc+'g': if self.options.with_code: - self.register_group_code( el ) + self.register_group_code( el, el_conf ) else: self.export_chids_of( el ) if el.tag in [ nmspc+'rect', nmspc+'path', nmspc+'circle' ]: if self.options.with_code: - self.register_unity_code( el ) - self.export_img( el ) + self.register_unity_code( el, el_conf ) + self.export_img( el, el_conf ) - def register_group_code(self, group): + def register_group_code(self, group, conf): #inkex.errormsg( 'group CSS and HTML' ) self.html.write( '
\n' ) + for att in conf: + self.html.write( ' \n'.format(att=att, val=conf[att]) ) self.export_chids_of( group ) self.html.write( '
\n' ) - def register_unity_code(self, el): + def register_unity_code(self, el, conf): #inkex.errormsg( 'unity CSS and HTML' ) - self.html.write( el.tag + '\n' ) + self.html.write( '
\n' ) + for att in conf: + self.html.write( ' \n'.format(att=att, val=conf[att]) ) + self.html.write( '
\n' ) - def export_img(self, el): + def export_img(self, el, conf): (status, output) = commands.getstatusoutput("inkscape -e ...") #inkex.errormsg( status ) #inkex.errormsg( output ) -- cgit v1.2.3 From 359c083429295b4be4ca96d655c0d50f38f86a7a Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Fri, 2 Apr 2010 12:34:59 -0400 Subject: patch for Bug 461964 comment 16 (bzr r9276) --- share/extensions/wireframe_sphere.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'share/extensions') diff --git a/share/extensions/wireframe_sphere.py b/share/extensions/wireframe_sphere.py index 8fbd4d3f1..5391af3e6 100644 --- a/share/extensions/wireframe_sphere.py +++ b/share/extensions/wireframe_sphere.py @@ -66,7 +66,7 @@ from math import * def draw_SVG_ellipse((rx, ry), (cx, cy), parent, start_end=(0,2*pi),transform='' ): style = { 'stroke' : '#000000', - 'width' : '1', + 'stroke-width' : '1', 'fill' : 'none' } circ_attribs = {'style':simplestyle.formatStyle(style), inkex.addNS('cx','sodipodi') :str(cx), -- cgit v1.2.3 From c36d67ae71480d2371a49d4c02b1597db736c6ac Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sat, 10 Apr 2010 20:59:57 +0200 Subject: commit patch for LaTeX equation render extension by Christoph Schmidt-Hieber Fixed bugs: - https://launchpad.net/bugs/555128 (bzr r9308) --- share/extensions/eqtexsvg.inx | 1 + share/extensions/eqtexsvg.py | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/eqtexsvg.inx b/share/extensions/eqtexsvg.inx index e99dfeb1d..70516b33f 100644 --- a/share/extensions/eqtexsvg.inx +++ b/share/extensions/eqtexsvg.inx @@ -8,6 +8,7 @@ dvips pstoedit \(\displaystyle\frac{\pi^2}{6}=\lim_{n \to \infty}\sum_{k=1}^n \frac{1}{k^2}\) + all diff --git a/share/extensions/eqtexsvg.py b/share/extensions/eqtexsvg.py index 563bf2c4c..8e2e70a10 100644 --- a/share/extensions/eqtexsvg.py +++ b/share/extensions/eqtexsvg.py @@ -9,6 +9,9 @@ This extension need, to work properly: Copyright (C) 2006 Julien Vitard +2010-04-04: Added support for custom packages + Christoph Schmidt-Hieber + 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 @@ -27,15 +30,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA import inkex, os, tempfile, sys, xml.dom.minidom -def create_equation_tex(filename, equation): +def parse_pkgs(pkgstring): + pkglist = pkgstring.replace(" ","").split(",") + header = "" + for pkg in pkglist: + header += "\\usepackage{%s}\n" % pkg + + return header + +def create_equation_tex(filename, equation, add_header=""): tex = open(filename, 'w') tex.write("""%% processed with eqtexsvg.py \\documentclass{article} \\usepackage{amsmath} \\usepackage{amssymb} \\usepackage{amsfonts} - -\\thispagestyle{empty} +""") + tex.write(add_header) + tex.write("""\\thispagestyle{empty} \\begin{document} """) tex.write(equation) @@ -76,8 +88,12 @@ class EQTEXSVG(inkex.Effect): inkex.Effect.__init__(self) self.OptionParser.add_option("-f", "--formule", action="store", type="string", - dest="formula", default=10.0, + dest="formula", default="", help="LaTeX formula") + self.OptionParser.add_option("-p", "--packages", + action="store", type="string", + dest="packages", default="", + help="Additional packages") def effect(self): base_dir = tempfile.mkdtemp("", "inkscape-"); @@ -102,7 +118,8 @@ class EQTEXSVG(inkex.Effect): os.remove(err_file) os.rmdir(base_dir) - create_equation_tex(latex_file, self.options.formula) + add_header = parse_pkgs(self.options.packages) + create_equation_tex(latex_file, self.options.formula, add_header) os.system('latex "-output-directory=%s" -halt-on-error "%s" > "%s"' \ % (base_dir, latex_file, out_file)) try: -- cgit v1.2.3 From c9512062e43089b6f080b4933d906cac531e7953 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Sun, 11 Apr 2010 15:22:02 -0400 Subject: fix some typing errors when converting from quadratic to cubic Bezier (bzr r9315) --- share/extensions/cubicsuperpath.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/cubicsuperpath.py b/share/extensions/cubicsuperpath.py index ae9c308e1..af61acb3a 100755 --- a/share/extensions/cubicsuperpath.py +++ b/share/extensions/cubicsuperpath.py @@ -123,17 +123,17 @@ def CubicSuperPath(simplepath): lastctrl = params[2:4] elif cmd == 'Q': q0=last[:] - q1=params[0:1] - q2=params[2:3] - x0= q0[0] - x1=1/3*q0[0]+2/3*q1[0] - x2= 2/3*q1[0]+1/3*q2[0] - x3= q2[0] - y0= q0[1] - y1=1/3*q0[1]+2/3*q1[1] - y2= 2/3*q1[1]+1/3*q2[1] - y3= q2[1] - csp[subpath].append([lastctrl[:][x0,y0][x1,y1]]) + q1=params[0:2] + q2=params[2:4] + x0= q0[0] + x1=1./3*q0[0]+2./3*q1[0] + x2= 2./3*q1[0]+1./3*q2[0] + x3= q2[0] + y0= q0[1] + y1=1./3*q0[1]+2./3*q1[1] + y2= 2./3*q1[1]+1./3*q2[1] + y3= q2[1] + csp[subpath].append([lastctrl[:],[x0,y0],[x1,y1]]) last = [x3,y3] lastctrl = [x2,y2] elif cmd == 'A': -- cgit v1.2.3 From 96576bd4d00e5412656bc67fb8159520ba203ed3 Mon Sep 17 00:00:00 2001 From: Alexandre Prokoudine Date: Wed, 14 Apr 2010 06:13:15 +0400 Subject: Typo fix by Yuri Chornoivan (bzr r9323) --- share/extensions/webslicer_export.inx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'share/extensions') diff --git a/share/extensions/webslicer_export.inx b/share/extensions/webslicer_export.inx index 3a7324370..4d083324e 100644 --- a/share/extensions/webslicer_export.inx +++ b/share/extensions/webslicer_export.inx @@ -5,7 +5,7 @@ webslicer_effect.py webslicer_export.py inkex.py - <_param name="about" type="description">All sliced images, and optionaly code, will be generated as you had configured and saved to one directory. + <_param name="about" type="description">All sliced images, and optionally code, will be generated as you had configured and saved to one directory. false true -- cgit v1.2.3 From 5b6caf2b2c37a2b40df79450b5b2b00beae87ac5 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 14 Apr 2010 19:38:59 +0200 Subject: Spelling correction in Optimized SVG extension. Fixed bugs: - https://launchpad.net/bugs/562784 (bzr r9330) --- share/extensions/scour.inx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/scour.inx b/share/extensions/scour.inx index ee310c503..472643dce 100644 --- a/share/extensions/scour.inx +++ b/share/extensions/scour.inx @@ -23,14 +23,14 @@ - <_param name="instructions" type="description" xml:space="preserve">This extension optimize the SVG file according to the following options: + <_param name="instructions" type="description" xml:space="preserve">This extension optimizes the SVG file according to the following options: * Simplify colors: convert all colors to #RRGGBB format. * Style to xml: convert styles into XML attributes. * Group collapsing: collapse <g> elements. * Enable id stripping: remove all un-referenced ID attributes. * Embed rasters: embed rasters as base64-encoded data. * Keep editor data: don't remove Inkscape, Sodipodi or Adobe Illustrator elements and attributes. - * Enable viewboxing: size image to 100%/100% and introduce a viewBox + * Enable viewboxing: size image to 100%/100% and introduce a viewBox. * Strip xml prolog: don't output the xml prolog. * Set precision: set number of significant digits (default: 5). * Indent: indentation of the output: none, space, tab (default: space). -- cgit v1.2.3 From e28c1beffbc01f79a15c5ecce34296e49865d115 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Thu, 15 Apr 2010 21:56:04 +0200 Subject: Extensions. Extract Image fix for uppercase image type, and default path set to the user's home directory. Fixed bugs: - https://launchpad.net/bugs/554734 (bzr r9336) --- share/extensions/extractimage.inx | 5 +++-- share/extensions/extractimage.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/extractimage.inx b/share/extensions/extractimage.inx index 364898c51..984dc9aef 100644 --- a/share/extensions/extractimage.inx +++ b/share/extensions/extractimage.inx @@ -4,8 +4,9 @@ org.ekips.filter.extractimage extractimage.py inkex.py - none - <_param name="desc" type="description">Note: The file extension is appended automatically. + none + <_param name="desc" type="description" xml:space="preserve">* Don't type the file extension, it is appended automatically. +* A relative path (or a filename without path) is relative to the user's home directory. all diff --git a/share/extensions/extractimage.py b/share/extensions/extractimage.py index 8b47de958..4093b94a7 100644 --- a/share/extensions/extractimage.py +++ b/share/extensions/extractimage.py @@ -54,10 +54,16 @@ class MyEffect(inkex.Effect): semicolon = xlink.find(';') if semicolon>0: for sub in mimesubext.keys(): - if sub in xlink[5:semicolon]: + if sub in xlink[5:semicolon].lower(): fileext=mimesubext[sub] path=path+fileext; - break + if (not os.path.isabs(path)): + if os.name == 'nt': + path = os.path.join(os.environ['USERPROFILE'],path) + else: + path = os.path.join(os.path.expanduser("~"),path) + inkex.errormsg(_('Image extracted to: %s') % path) + break #save data = base64.decodestring(xlink[comma:]) open(path,'wb').write(data) -- cgit v1.2.3 From 8c1ce7fb19f85b5a3ad7b47f1e07675c0915a2cb Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sat, 17 Apr 2010 13:07:27 +0200 Subject: Missing dependency for webslicer extensions. (bzr r9342) --- share/extensions/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'share/extensions') diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index a64d77203..b5bf8cd33 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -135,6 +135,7 @@ extensions = \ voronoi.py \ webslicer_create_group.py \ webslicer_create_rect.py \ + webslicer_effect.py \ webslicer_export.py \ web-set-att.py \ web-transmit-att.py \ -- cgit v1.2.3 From 248333dc76b6e6757046e37163a4f3d0f4242118 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sat, 17 Apr 2010 13:22:19 +0200 Subject: Typo and consistency fix in webslicer extensions. Fixed bugs: - https://launchpad.net/bugs/565241 (bzr r9343) --- share/extensions/webslicer_create_group.inx | 10 +++++----- share/extensions/webslicer_create_rect.inx | 28 ++++++++++++++-------------- share/extensions/webslicer_export.inx | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/webslicer_create_group.inx b/share/extensions/webslicer_create_group.inx index 3e4a66dec..68f63ce72 100644 --- a/share/extensions/webslicer_create_group.inx +++ b/share/extensions/webslicer_create_group.inx @@ -5,15 +5,15 @@ webslicer_effect.py webslicer_create_group.py inkex.py - <_param name="about" type="description">Layout Group is only about to help a better code generation (if you need it). To use this, first you must to select some "Slicer rectangles". - - - + <_param name="about" type="description">Layout Group is only about to help a better code generation (if you need it). To use this, you must to select some "Slicer rectangles" first. + + + <_item value="px">Pixel (fixed) <_item value="percent">Percent (relative to parent size) <_item value="undefined">Undefined (relative to non-floating content size) - + <_item value="px">Pixel (fixed) <_item value="percent">Percent (relative to parent size) <_item value="undefined">Undefined (relative to non-floating content size) diff --git a/share/extensions/webslicer_create_rect.inx b/share/extensions/webslicer_create_rect.inx index 776d269e8..7490953c5 100644 --- a/share/extensions/webslicer_create_rect.inx +++ b/share/extensions/webslicer_create_rect.inx @@ -5,47 +5,47 @@ webslicer_effect.py webslicer_create_rect.py inkex.py - - + + PNG JPG GIF - 90 - + 90 + <_param name="help-dimension1" type="description">Force Dimension must be set as "<width>x<height>" - <_param name="help-dimension2" type="description">If had set, this will replace DPI. - + <_param name="help-dimension2" type="description">If set, this will replace DPI. + <_param name="help-jpg" type="description">JPG specific options - 85 + 85 <_param name="help-quality" type="description">0 is the lowest image quality and highest compression, and 100 is the best quality but least effective compression <_param name="help-gif" type="description">GIF specific options - + <_item value="grayscale">Grayscale <_item value="palette">Palette - 256 + 256 - - + + <_param name="help-gif" type="description">Options for HTML export - + <_item value="bg-parent-repeat">Tiled Background (on parent group) <_item value="bg-parent-repeat-x">Background — repeat horizontally (on parent group) <_item value="bg-parent-repeat-y">Background — repeat vertically (on parent group) <_item value="bg-parent-norepeat">Background — no repeat (on parent group) - <_item value="bg-div-norepeat">Positioned <div> width the image as Background + <_item value="bg-div-norepeat">Positioned <div> with the image as Background <_item value="img-pos">Positioned Image <_item value="img-nonpos">Non Positioned Image <_item value="img-float-left">Left Floated Image <_item value="img-float-right">Right Floated Image - + <_item value="tl">Top and Left <_item value="tr">Top and right <_item value="bl">Bottom and Left diff --git a/share/extensions/webslicer_export.inx b/share/extensions/webslicer_export.inx index 4d083324e..eeb753add 100644 --- a/share/extensions/webslicer_export.inx +++ b/share/extensions/webslicer_export.inx @@ -6,7 +6,7 @@ webslicer_export.py inkex.py <_param name="about" type="description">All sliced images, and optionally code, will be generated as you had configured and saved to one directory. - + false true -- cgit v1.2.3 From 8ae9517bda1535a9c29a45a6cb11806d8287ab78 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Sun, 18 Apr 2010 18:04:37 -0400 Subject: cubic root solver patch by Nick Fixed bugs: - https://launchpad.net/bugs/539614 (bzr r9353) --- share/extensions/bezmisc.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/bezmisc.py b/share/extensions/bezmisc.py index f5c290708..e663fa67f 100755 --- a/share/extensions/bezmisc.py +++ b/share/extensions/bezmisc.py @@ -1,5 +1,6 @@ #!/usr/bin/env python ''' +Copyright (C) 2010 Nick Drobchenko, nick@cnc-club.ru Copyright (C) 2005 Aaron Spike, aaron@ekips.org This program is free software; you can redistribute it and/or modify @@ -21,9 +22,29 @@ import math, cmath def rootWrapper(a,b,c,d): if a: - #TODO: find a new cubic solver and put it here - #return solveCubicMonic(b/a,c/a,d/a) - return () + # Monics formula see http://en.wikipedia.org/wiki/Cubic_function#Monic_formula_of_roots + a,b,c = (b/a, c/a, d/a) + m = 2.0*a**3 - 9.0*a*b + 27.0*c + k = a**2 - 3.0*b + n = m**2 - 4.0*k**3 + w1 = -.5 + .5*cmath.sqrt(-3.0) + w2 = -.5 - .5*cmath.sqrt(-3.0) + if n < 0: + m1 = pow(complex((m+cmath.sqrt(n))/2),1./3) + n1 = pow(complex((m-cmath.sqrt(n))/2),1./3) + else: + if m+math.sqrt(n) < 0: + m1 = -pow(-(m+math.sqrt(n))/2,1./3) + else: + m1 = pow((m+math.sqrt(n))/2,1./3) + if m-math.sqrt(n) < 0: + n1 = -pow(-(m-math.sqrt(n))/2,1./3) + else: + n1 = pow((m-math.sqrt(n))/2,1./3) + x1 = -1./3 * (a + m1 + n1) + x2 = -1./3 * (a + w1*m1 + w2*n1) + x3 = -1./3 * (a + w2*m1 + w1*n1) + return (x1,x2,x3) elif b: det=c**2.0-4.0*b*d if det: @@ -75,7 +96,7 @@ def linebezierintersect(((lx1,ly1),(lx2,ly2)),((bx0,by0),(bx1,by1),(bx2,by2),(bx if type(i) is complex and i.imag==0: i = i.real if type(i) is not complex and 0<=i<=1: - retval.append(i) + retval.append(bezierpointatt(((bx0,by0),(bx1,by1),(bx2,by2),(bx3,by3)),i)) return retval def bezierpointatt(((bx0,by0),(bx1,by1),(bx2,by2),(bx3,by3)),t): -- cgit v1.2.3 From 67f89c16d1aeb13322183e347e3246ac33177bb7 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Tue, 20 Apr 2010 18:14:27 +0200 Subject: Extensions. New text split extension (Bug #171748). Fixed bugs: - https://launchpad.net/bugs/171748 (bzr r9360) --- share/extensions/Makefile.am | 2 + share/extensions/split.inx | 22 +++++ share/extensions/split.py | 215 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+) create mode 100644 share/extensions/split.inx create mode 100644 share/extensions/split.py (limited to 'share/extensions') diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index b5bf8cd33..7327ffbd5 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -115,6 +115,7 @@ extensions = \ sk2svg.sh \ SpSVG.pm \ spirograph.py\ + split.py \ straightseg.py \ summersnight.py \ svgcalendar.py \ @@ -245,6 +246,7 @@ modules = \ sk1_input.inx \ sk1_output.inx \ spirograph.inx \ + split.inx \ straightseg.inx \ summersnight.inx \ svg2xaml.inx \ diff --git a/share/extensions/split.inx b/share/extensions/split.inx new file mode 100644 index 000000000..0f8cea0ce --- /dev/null +++ b/share/extensions/split.inx @@ -0,0 +1,22 @@ + + <_name>Split text + com.nerdson.split + split.py + inkex.py + This effect splits texts into different lines, words or letters. Select below how your text should be splitted. + + Lines + Words + Letters + + true + + text + + + + + + diff --git a/share/extensions/split.py b/share/extensions/split.py new file mode 100644 index 000000000..5e9de002b --- /dev/null +++ b/share/extensions/split.py @@ -0,0 +1,215 @@ +#!/usr/bin/env python +''' +Copyright (C) 2009 Karlisson Bezerra, contato@nerdson.com + +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 + +class Split(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option("-s", "--splittype", + action="store", type="string", + dest="split_type", default="word", + help="type of split") + self.OptionParser.add_option("-p", "--preserve", + action="store", type="inkbool", + dest="preserve", default="True", + help="Preserve original") + + + def split_lines(self, node): + """Returns a list of lines""" + + lines = [] + count = 1 + + for n in node: + if not (n.tag == inkex.addNS("flowPara", "svg") or n.tag == inkex.addNS("tspan", "svg")): + if n.tag == inkex.addNS("textPath", "svg"): + inkex.debug("This type of text element isn't supported. First remove text from path.") + break + else: + continue + + text = inkex.etree.Element(inkex.addNS("text", "svg"), node.attrib) + + #handling flowed text nodes + if node.tag == inkex.addNS("flowRoot", "svg"): + try: + from simplestyle import parseStyle + fontsize = parseStyle(node.get("style"))["font-size"] + except: + fontsize = "12px" + fs = inkex.unittouu(fontsize) + + #selects the flowRegion's child (svg:rect) to get @X and @Y + id = node.get("id") + flowref = self.xpathSingle('/svg:svg//*[@id="%s"]/svg:flowRegion[1]' % id)[0] + + if flowref.tag == inkex.addNS("rect", "svg"): + text.set("x", flowref.get("x")) + text.set("y", str(float(flowref.get("y")) + fs * count)) + count += 1 + else: + inkex.debug("This type of text element isn't supported. First unflow text.") + break + + #now let's convert flowPara into tspan + tspan = inkex.etree.Element(inkex.addNS("tspan", "svg")) + tspan.set(inkex.addNS("role","sodipodi"), "line") + tspan.text = n.text + text.append(tspan) + + else: + from copy import copy + x = n.get("x") or node.get("x") + y = n.get("y") or node.get("y") + + text.set("x", x) + text.set("y", y) + text.append(copy(n)) + + lines.append(text) + + return lines + + + def split_words(self, node): + """Returns a list of words""" + + words = [] + + #Function to recursively extract text + def plain_str(elem): + words = [] + if elem.text: + words.append(elem.text) + for n in elem: + words.extend(plain_str(n)) + if n.tail: + words.append(n.tail) + return words + + #if text has more than one line, iterates through elements + lines = self.split_lines(node) + if not lines: + return words + + for line in lines: + #gets the position of text node + x = float(line.get("x")) + y = line.get("y") + + #gets the font size. if element doesn't have a style attribute, it assumes font-size = 12px + try: + from simplestyle import parseStyle + fontsize = parseStyle(line.get("style"))["font-size"] + except: + fontsize = "12px" + fs = inkex.unittouu(fontsize) + + #extract and returns a list of words + words_list = "".join(plain_str(line)).split() + prev_len = 0 + + #creates new text nodes for each string in words_list + for word in words_list: + tspan = inkex.etree.Element(inkex.addNS("tspan", "svg")) + tspan.text = word + + text = inkex.etree.Element(inkex.addNS("text", "svg"), line.attrib) + tspan.set(inkex.addNS("role","sodipodi"), "line") + + #positioning new text elements + x = x + prev_len * fs + prev_len = len(word) + text.set("x", str(x)) + text.set("y", str(y)) + + text.append(tspan) + words.append(text) + + return words + + + def split_letters(self, node): + """Returns a list of letters""" + + letters = [] + + words = self.split_words(node) + if not words: + return letters + + for word in words: + + x = float(word.get("x")) + y = word.get("y") + + #gets the font size. If element doesn't have a style attribute, it assumes font-size = 12px + try: + import simplestyle + fontsize = simplestyle.parseStyle(word.get("style"))["font-size"] + except: + fontsize = "12px" + fs = inkex.unittouu(fontsize) + + #for each letter in element string + for letter in word[0].text: + tspan = inkex.etree.Element(inkex.addNS("tspan", "svg")) + tspan.text = letter + + text = inkex.etree.Element(inkex.addNS("text", "svg"), node.attrib) + text.set("x", str(x)) + text.set("y", str(y)) + x += fs + + text.append(tspan) + letters.append(text) + return letters + + + def effect(self): + """Applies the effect""" + + split_type = self.options.split_type + preserve = self.options.preserve + + #checks if the selected elements are text nodes + for id, node in self.selected.iteritems(): + if not (node.tag == inkex.addNS("text", "svg") or node.tag == inkex.addNS("flowRoot", "svg")): + inkex.debug("Please select only text elements.") + break + else: + if split_type == "line": + nodes = self.split_lines(node) + elif split_type == "word": + nodes = self.split_words(node) + elif split_type == "letter": + nodes = self.split_letters(node) + + for n in nodes: + node.getparent().append(n) + + #preserve original element + if not preserve and nodes: + parent = node.getparent() + parent.remove(node) + +b = Split() +b.affect() -- cgit v1.2.3