diff options
| author | Ted Gould <ted@gould.cx> | 2010-05-15 18:08:17 +0000 |
|---|---|---|
| committer | Ted Gould <ted@gould.cx> | 2010-05-15 18:08:17 +0000 |
| commit | 2d8c2dfd832ce207aef3895e702bff4098ab7136 (patch) | |
| tree | 642a37c6e3ca05d5e991ffe868f03c9cc58e51bc /share | |
| parent | Merge from trunk (diff) | |
| parent | Minor tweaks to text toolbar. (diff) | |
| download | inkscape-2d8c2dfd832ce207aef3895e702bff4098ab7136.tar.gz inkscape-2d8c2dfd832ce207aef3895e702bff4098ab7136.zip | |
Updating to trunk
(bzr r8254.1.54)
Diffstat (limited to 'share')
24 files changed, 576 insertions, 170 deletions
diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index cd409d233..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 \ @@ -133,9 +134,10 @@ 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_effect.py \ + webslicer_export.py \ web-set-att.py \ web-transmit-att.py \ whirl.py \ @@ -244,6 +246,7 @@ modules = \ sk1_input.inx \ sk1_output.inx \ spirograph.inx \ + split.inx \ straightseg.inx \ summersnight.inx \ svg2xaml.inx \ @@ -259,9 +262,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 \ 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): 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': 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 @@ <dependency type="executable" location="path">dvips</dependency> <dependency type="executable" location="path">pstoedit</dependency> <param name="formule" type="string" _gui-text="LaTeX formula: ">\(\displaystyle\frac{\pi^2}{6}=\lim_{n \to \infty}\sum_{k=1}^n \frac{1}{k^2}\)</param> + <param name="packages" type="string" _gui-text="Additional packages (comma-separated): "></param> <effect> <object-type>all</object-type> <effects-menu> 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 <julienvitard@gmail.com> +2010-04-04: Added support for custom packages + Christoph Schmidt-Hieber <christsc@gmx.de> + 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: 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 @@ <id>org.ekips.filter.extractimage</id> <dependency type="executable" location="extensions">extractimage.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> - <param name="filepath" type="string" _gui-text="Path to save image">none</param> - <_param name="desc" type="description">Note: The file extension is appended automatically.</_param> + <param name="filepath" type="string" _gui-text="Path to save image:">none</param> + <_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.</_param> <effect needs-live-preview="false"> <object-type>all</object-type> <effects-menu> 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) 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 @@ <param name="mirror" type="boolean" _gui-text="Mirror Y-axis">FALSE</param> <param name="xOrigin" type="float" min="-100000" max="100000" _gui-text="X-origin (px)">0.0</param> <param name="yOrigin" type="float" min="-100000" max="100000" _gui-text="Y-origin (px)">0.0</param> + <param name="resolution" type="int" min="90" max="2048" _gui-text="Resolution (dpi)">1016</param> + <param name="pen" type="int" min="1" max="10" _gui-text="Pen number">1</param> <param name="plotInvisibleLayers" type="boolean" _gui-text="Plot invisible layers">FALSE</param> <output> <extension>.hpgl</extension> 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() 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' } 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> </page> <page name="Help" _gui-text="Help"> - <_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).</_param> 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 @@ +<inkscape-extension> + <_name>Split text</_name> + <id>com.nerdson.split</id> + <dependency type="executable" location="extensions">split.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <param name="texthelp" type="description">This effect splits texts into different lines, words or letters. Select below how your text should be splitted.</param> + <param name="splittype" type="enum" _gui-text="Split:"> + <item value="line">Lines</item> + <item value="word">Words</item> + <item value="letter">Letters</item> + </param> + <param name="preserve" type="boolean" _gui-text="Preserve original text?">true</param> + <effect> + <object-type>text</object-type> + <effects-menu> + <submenu _name="Text"/> + </effects-menu> + </effect> + <script> + <command reldir="extensions" interpreter="python">split.py</command> + </script> +</inkscape-extension> 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() 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..9cdac7fc2 100644 --- a/share/extensions/uniconv_output.py +++ b/share/extensions/uniconv_output.py @@ -94,13 +94,13 @@ def get_command(): 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() @@ -122,6 +122,7 @@ def get_command(): '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 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 index b5c5b48ed..68f63ce72 100644 --- a/share/extensions/webslicer-create-group.inx +++ b/share/extensions/webslicer_create_group.inx @@ -2,17 +2,18 @@ <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> <_name>Set a layout group</_name> <id>org.inkscape.web.slicer.create-group</id> - <dependency type="executable" location="extensions">webslicer-create-group.py</dependency> + <dependency type="executable" location="extensions">webslicer_effect.py</dependency> + <dependency type="executable" location="extensions">webslicer_create_group.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> - <_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> - <param name="html-id" type="string" _gui-text="HTML id atribute"></param> - <param name="html-class" type="string" _gui-text="HTML class atribute"></param> - <param name="width-unity" type="enum" _gui-text="Width Unity"> + <_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.</_param> + <param name="html-id" type="string" _gui-text="HTML id atribute:"></param> + <param name="html-class" type="string" _gui-text="HTML class atribute:"></param> + <param name="width-unity" type="enum" _gui-text="Width unit:"> <_item value="px">Pixel (fixed)</_item> <_item value="percent">Percent (relative to parent size)</_item> <_item value="undefined">Undefined (relative to non-floating content size)</_item> </param> - <param name="height-unity" type="enum" _gui-text="Height Unity"> + <param name="height-unity" type="enum" _gui-text="Height unit:"> <_item value="px">Pixel (fixed)</_item> <_item value="percent">Percent (relative to parent size)</_item> <_item value="undefined">Undefined (relative to non-floating content size)</_item> @@ -26,6 +27,6 @@ </effects-menu> </effect> <script> - <command reldir="extensions" interpreter="python">webslicer-create-group.py</command> + <command reldir="extensions" interpreter="python">webslicer_create_group.py</command> </script> </inkscape-extension> diff --git a/share/extensions/webslicer-create-group.py b/share/extensions/webslicer_create_group.py index aadfded38..666649bfb 100755..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.inx b/share/extensions/webslicer_create_rect.inx index 7ac681e69..7490953c5 100644 --- a/share/extensions/webslicer-create-rect.inx +++ b/share/extensions/webslicer_create_rect.inx @@ -2,49 +2,50 @@ <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> <_name>Create a slicer rectangle</_name> <id>org.inkscape.web.slicer.create-rect</id> - <dependency type="executable" location="extensions">webslicer-create-rect.py</dependency> + <dependency type="executable" location="extensions">webslicer_effect.py</dependency> + <dependency type="executable" location="extensions">webslicer_create_rect.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> - <param name="name" type="string" _gui-text="Name"></param> - <param name="format" type="enum" _gui-text="Format"> + <param name="name" type="string" _gui-text="Name:"></param> + <param name="format" type="enum" _gui-text="Format:"> <item value="png">PNG</item> <item value="jpg">JPG</item> <item value="gif">GIF</item> </param> - <param name="dpi" type="float" min="1" max="9999" _gui-text="DPI">90</param> - <param name="dimension" type="string" _gui-text="Force Dimension"></param> + <param name="dpi" type="float" min="1" max="9999" _gui-text="DPI:">90</param> + <param name="dimension" type="string" _gui-text="Force Dimension:"></param> <_param name="help-dimension1" type="description">Force Dimension must be set as "<width>x<height>"</_param> - <_param name="help-dimension2" type="description">If had set, this will replace DPI.</_param> - <param name="bg-color" type="string" _gui-text="Background color"></param> + <_param name="help-dimension2" type="description">If set, this will replace DPI.</_param> + <param name="bg-color" type="string" _gui-text="Background color:"></param> <param name="tab" type="notebook"> <page name="tabJPG" gui-text="JPG"> <_param name="help-jpg" type="description">JPG specific options</_param> - <param name="quality" type="int" min="0" max="100" _gui-text="Quality">85</param> + <param name="quality" type="int" min="0" max="100" _gui-text="Quality:">85</param> <_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> </page> <page name="tabGIF" gui-text="GIF"> <_param name="help-gif" type="description">GIF specific options</_param> - <param name="gif-type" type="enum" _gui-text="Type"> + <param name="gif-type" type="enum" _gui-text="Type:"> <_item value="grayscale">Grayscale</_item> <_item value="palette">Palette</_item> </param> - <param name="palette-size" type="int" min="2" max="256" _gui-text="Palette size">256</param> + <param name="palette-size" type="int" min="2" max="256" _gui-text="Palette size:">256</param> </page> <page name="tabHTML" gui-text="HTML"> - <param name="html-id" type="string" _gui-text="HTML id atribute"></param> - <param name="html-class" type="string" _gui-text="HTML class atribute"></param> + <param name="html-id" type="string" _gui-text="HTML id atribute:"></param> + <param name="html-class" type="string" _gui-text="HTML class atribute:"></param> <_param name="help-gif" type="description">Options for HTML export</_param> - <param name="layout-disposition" type="enum" _gui-text="Layout disposition"> + <param name="layout-disposition" type="enum" _gui-text="Layout disposition:"> <_item value="bg-parent-repeat">Tiled Background (on parent group)</_item> <_item value="bg-parent-repeat-x">Background — repeat horizontally (on parent group)</_item> <_item value="bg-parent-repeat-y">Background — repeat vertically (on parent group)</_item> <_item value="bg-parent-norepeat">Background — no repeat (on parent group)</_item> - <_item value="bg-div-norepeat">Positioned <div> width the image as Background</_item> + <_item value="bg-div-norepeat">Positioned <div> with the image as Background</_item> <_item value="img-pos">Positioned Image</_item> <_item value="img-nonpos">Non Positioned Image</_item> <_item value="img-float-left">Left Floated Image</_item> <_item value="img-float-right">Right Floated Image</_item> </param> - <param name="layout-position-anchor" type="enum" _gui-text="Position anchor"> + <param name="layout-position-anchor" type="enum" _gui-text="Position anchor:"> <_item value="tl">Top and Left</_item> <_item value="tr">Top and right</_item> <_item value="bl">Bottom and Left</_item> @@ -61,6 +62,6 @@ </effects-menu> </effect> <script> - <command reldir="extensions" interpreter="python">webslicer-create-rect.py</command> + <command reldir="extensions" interpreter="python">webslicer_create_rect.py</command> </script> </inkscape-extension> diff --git a/share/extensions/webslicer-create-rect.py b/share/extensions/webslicer_create_rect.py index 957d6a8b2..5fd961a13 100755 --- a/share/extensions/webslicer-create-rect.py +++ b/share/extensions/webslicer_create_rect.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_CreateRect(inkex.Effect): +class WebSlicer_CreateRect(WebSlicer_Effect): def __init__(self): - inkex.Effect.__init__(self) + WebSlicer_Effect.__init__(self) self.OptionParser.add_option("--name", action="store", type="string", dest="name", @@ -107,7 +102,7 @@ class WebSlicer_CreateRect(inkex.Effect): def effect(self): self.validate_options() - layer = self.get_slicer_layer() + 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): @@ -141,33 +136,18 @@ class WebSlicer_CreateRect(inkex.Effect): 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' ]) ) + conf_list.extend( self.get_conf_from_list([ 'gif_type', 'palette_size' ]) ) if self.options.format == 'jpg': - conf_list.extend( get_conf_from_list([ 'quality' ]) ) + 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( get_conf_from_list(conf_general_atts) ) + conf_list.extend( self.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() 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 index 9f7aac323..eeb753add 100644 --- a/share/extensions/webslicer-export.inx +++ b/share/extensions/webslicer_export.inx @@ -2,10 +2,12 @@ <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> <_name>Export layout pieces and HTML+CSS code</_name> <id>org.inkscape.web.slicer.export</id> - <dependency type="executable" location="extensions">webslicer-export.py</dependency> + <dependency type="executable" location="extensions">webslicer_effect.py</dependency> + <dependency type="executable" location="extensions">webslicer_export.py</dependency> <dependency type="executable" location="extensions">inkex.py</dependency> - <_param name="about" type="description">All sliced images, and optionaly code, will be generated as you had configured and saved to one directory.</_param> - <param name="dir" type="string" _gui-text="Directory path to export"></param> + <_param name="about" type="description">All sliced images, and optionally code, will be generated as you had configured and saved to one directory.</_param> + <param name="dir" type="string" _gui-text="Directory path to export:"></param> + <param name="create-dir" type="boolean" _gui-text="Create directory, if it does not exists">false</param> <param name="with-code" type="boolean" _gui-text="With HTML and CSS">true</param> <effect needs-live-preview="false"> <object-type>all</object-type> @@ -16,6 +18,6 @@ </effects-menu> </effect> <script> - <command reldir="extensions" interpreter="python">webslicer-export.py</command> + <command reldir="extensions" interpreter="python">webslicer_export.py</command> </script> </inkscape-extension> diff --git a/share/extensions/webslicer_export.py b/share/extensions/webslicer_export.py new file mode 100755 index 000000000..3a1a38135 --- /dev/null +++ b/share/extensions/webslicer_export.py @@ -0,0 +1,139 @@ +#!/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 +''' + +from webslicer_effect import * +import inkex +import gettext +import os.path +import commands + +_ = gettext.gettext + +class WebSlicer_Export(WebSlicer_Effect): + + def __init__(self): + 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 {'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 ): + 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') + 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 ) + 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 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, 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, el_conf ) + self.export_img( el, el_conf ) + + + def register_group_code(self, group, conf): + #inkex.errormsg( 'group CSS and HTML' ) + self.html.write( '<div id="G">\n' ) + for att in conf: + self.html.write( ' <!-- {att} : {val} -->\n'.format(att=att, val=conf[att]) ) + self.export_chids_of( group ) + self.html.write( '</div><!-- end id="G" -->\n' ) + + + def register_unity_code(self, el, conf): + #inkex.errormsg( 'unity CSS and HTML' ) + self.html.write( '<div id="image">\n' ) + for att in conf: + self.html.write( ' <!-- {att} : {val} -->\n'.format(att=att, val=conf[att]) ) + self.html.write( '</div><!-- end id="image" -->\n' ) + + + def export_img(self, el, conf): + (status, output) = commands.getstatusoutput("inkscape -e ...") + #inkex.errormsg( status ) + #inkex.errormsg( output ) + + +if __name__ == '__main__': + e = WebSlicer_Export() + e.affect() 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), |
