From: Aurélio A. Heckert (a) Date: Mon, 26 Apr 2010 04:45:48 +0000 (-0300) Subject: webslicer is starting to export image pieces X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d3f6aa3df5556f279194848b5bd571ff67fdaf66;p=inkscape.git webslicer is starting to export image pieces --- diff --git a/share/extensions/webslicer_create_group.inx b/share/extensions/webslicer_create_group.inx index 68f63ce72..e4bf4e310 100644 --- a/share/extensions/webslicer_create_group.inx +++ b/share/extensions/webslicer_create_group.inx @@ -18,6 +18,7 @@ <_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 index 666649bfb..c6f9e653e 100644 --- a/share/extensions/webslicer_create_group.py +++ b/share/extensions/webslicer_create_group.py @@ -43,6 +43,10 @@ class WebSlicer_CreateGroup(WebSlicer_Effect): action="store", type="string", dest="height_unity", help="") + self.OptionParser.add_option("--bg-color", + action="store", type="string", + dest="bg_color", + help="") def get_base_elements(self): @@ -72,14 +76,11 @@ class WebSlicer_CreateGroup(WebSlicer_Effect): 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 + desc.text = self.get_conf_text_from_list( + [ 'html_id', 'html_class', + 'width_unity', 'height_unity', + 'bg_color' ] ) + for id,node in self.selected.iteritems(): group.insert( 1, node ) diff --git a/share/extensions/webslicer_create_rect.inx b/share/extensions/webslicer_create_rect.inx index 7490953c5..651dda668 100644 --- a/share/extensions/webslicer_create_rect.inx +++ b/share/extensions/webslicer_create_rect.inx @@ -35,11 +35,11 @@ <_param name="help-gif" type="description">Options for HTML export + <_item value="bg-el-norepeat">Positioned html block element with the image as Background <_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> 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 @@ -47,8 +47,13 @@ <_item value="tl">Top and Left + <_item value="tc">Top and Center <_item value="tr">Top and right + <_item value="ml">Middle and Left + <_item value="mc">Middle and Center + <_item value="mr">Middle and Right <_item value="bl">Bottom and Left + <_item value="bc">Bottom and Center <_item value="br">Bottom and Right diff --git a/share/extensions/webslicer_create_rect.py b/share/extensions/webslicer_create_rect.py index 5fd961a13..9e916532f 100755 --- a/share/extensions/webslicer_create_rect.py +++ b/share/extensions/webslicer_create_rect.py @@ -121,30 +121,20 @@ class WebSlicer_CreateRect(WebSlicer_Effect): 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() ) + desc.text = self.get_conf_text_from_list( self.get_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 ] + def get_conf_list(self): + conf_list = [ 'format' ] if self.options.format == 'gif': - conf_list.extend( self.get_conf_from_list([ 'gif_type', 'palette_size' ]) ) + conf_list.extend( [ 'gif_type', 'palette_size' ] ) if self.options.format == 'jpg': - conf_list.extend( self.get_conf_from_list([ 'quality' ]) ) - conf_general_atts = [ + conf_list.extend( [ 'quality' ] ) + conf_list.extend( [ '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 diff --git a/share/extensions/webslicer_effect.py b/share/extensions/webslicer_effect.py index 37bea447b..d91d0ce85 100644 --- a/share/extensions/webslicer_effect.py +++ b/share/extensions/webslicer_effect.py @@ -50,3 +50,12 @@ class WebSlicer_Effect(inkex.Effect): layer = layer[0] return layer + def get_conf_text_from_list(self, conf_atts): + conf_list = [] + for att in conf_atts: + if not is_empty(getattr(self.options, att)): + conf_list.append( + att.replace('_','-') +': '+ str(getattr(self.options, att)) + ) + return "\n".join( conf_list ) + diff --git a/share/extensions/webslicer_export.py b/share/extensions/webslicer_export.py index 3a1a38135..02d049364 100755 --- a/share/extensions/webslicer_export.py +++ b/share/extensions/webslicer_export.py @@ -21,6 +21,7 @@ from webslicer_effect import * import inkex import gettext import os.path +import tempfile import commands _ = gettext.gettext @@ -76,13 +77,27 @@ class WebSlicer_Export(WebSlicer_Effect): inkex.errormsg( _('Can\'t create code files.') ) inkex.errormsg( _('Error: %s') % e ) return {'error':'Can\'t create code files.'} + # Create the temporary SVG with invisible Slicer layer to export image pieces + self.create_the_temporary_svg() # 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() + # Delete the temporary SVG with invisible Slicer layer + self.delete_the_temporary_svg() + def create_the_temporary_svg(self): + (ref, self.tmp_svg) = tempfile.mkstemp('.svg') + layer = self.get_slicer_layer() + current_style = layer.attrib['style'] + layer.attrib['style'] = 'display:none' + self.document.write( self.tmp_svg ); + layer.attrib['style'] = current_style + + def delete_the_temporary_svg(self): + os.remove( self.tmp_svg ) def get_el_conf(self, el): desc = el.find('{http://www.w3.org/2000/svg}desc') @@ -129,7 +144,13 @@ class WebSlicer_Export(WebSlicer_Effect): def export_img(self, el, conf): - (status, output) = commands.getstatusoutput("inkscape -e ...") + (status, output) = commands.getstatusoutput( + "inkscape -i '%s' -e '%s' '%s'" % ( + el.attrib['id'], + os.path.join( self.options.dir, el.attrib['id']+'.png' ), + self.tmp_svg + ) + ) #inkex.errormsg( status ) #inkex.errormsg( output )