summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelio A. Heckert (a) <auriumgmaildotcom>2010-04-27 00:30:08 +0000
committerAurelio A. Heckert (a) <auriumgmaildotcom>2010-04-27 00:30:08 +0000
commit011fa2a6c6ee81c5ae02bf6fbb49bb80c7d5fe6d (patch)
tree44d368602c615c86e92a225f0d46b08dd8a20132
parentExtensions. Fix for bug #569885 (No opacity value in XAML export) and whitesp... (diff)
downloadinkscape-011fa2a6c6ee81c5ae02bf6fbb49bb80c7d5fe6d.tar.gz
inkscape-011fa2a6c6ee81c5ae02bf6fbb49bb80c7d5fe6d.zip
some love to webslicer_export.py
(bzr r9379)
-rwxr-xr-xshare/extensions/webslicer_export.py86
1 files changed, 68 insertions, 18 deletions
diff --git a/share/extensions/webslicer_export.py b/share/extensions/webslicer_export.py
index 02d049364..6b4ef75d8 100755
--- a/share/extensions/webslicer_export.py
+++ b/share/extensions/webslicer_export.py
@@ -72,7 +72,7 @@ class WebSlicer_Export(WebSlicer_Effect):
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')
+ 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 )
@@ -84,45 +84,63 @@ class WebSlicer_Export(WebSlicer_Effect):
# Close the HTML and CSS files:
if self.options.with_code:
self.html.close()
+ self.css.write( self.css_code() )
self.css.close()
# Delete the temporary SVG with invisible Slicer layer
self.delete_the_temporary_svg()
+ #TODO: prevent inkex to return svg code to update Inkscape
+
+
+ svgNS = '{http://www.w3.org/2000/svg}'
+
def create_the_temporary_svg(self):
(ref, self.tmp_svg) = tempfile.mkstemp('.svg')
layer = self.get_slicer_layer()
- current_style = layer.attrib['style']
+ current_style = ('style' in layer.attrib) and layer.attrib['style'] or ''
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 )
+
+ noid_element_count = 0
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()
+ if desc is None:
+ desc = inkex.etree.SubElement(el, 'desc')
+ if desc.text is None:
+ desc.text = ''
+ for line in desc.text.split("\n"):
+ if line.find(':') > 0:
+ line = line.split(':')
+ conf[line[0].strip()] = line[1].strip()
+ if not 'html-id' in conf:
+ if el == self.get_slicer_layer():
+ return {'html-id':'#body#'}
+ else:
+ self.noid_element_count += 1
+ conf['html-id'] = 'element-'+str(self.noid_element_count)
+ desc.text += "\nhtml-id:"+conf['html-id']
return conf
def export_chids_of(self, parent):
- nmspc = '{http://www.w3.org/2000/svg}'
+ parent_id = self.get_el_conf( parent )['html-id']
for el in parent.getchildren():
el_conf = self.get_el_conf( el )
- if el.tag == nmspc+'g':
+ if el.tag == self.svgNS+'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 el.tag in [ self.svgNS+'rect', self.svgNS+'path', self.svgNS+'circle' ]:
if self.options.with_code:
- self.register_unity_code( el, el_conf )
+ self.register_unity_code( el, el_conf, parent_id )
self.export_img( el, el_conf )
@@ -135,19 +153,35 @@ class WebSlicer_Export(WebSlicer_Effect):
self.html.write( '</div><!-- end id="G" -->\n' )
- def register_unity_code(self, el, conf):
+ def register_unity_code(self, el, conf, parent_id):
#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' )
+ css_selector = '#'+conf['html-id']
+ if not 'layout-disposition' in conf:
+ conf['layout-disposition'] = 'bg-el-norepeat'
+ if conf['layout-disposition'][0:9] == 'bg-parent':
+ if parent_id == '#body#':
+ css_selector = 'body'
+ else:
+ css_selector = '#'+parent_id
+ for att in conf:
+ self.html.write( '<!-- bg {att} : {val} -->\n'.format(att=att, val=conf[att]) )
+ else:
+ 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' )
+ self.reg_css( css_selector, 'background',
+ 'url("%s")' % self.img_name(el, conf) )
+ def img_name(self, el, conf):
+ return el.attrib['id']+'.png'
+
def export_img(self, el, conf):
(status, output) = commands.getstatusoutput(
"inkscape -i '%s' -e '%s' '%s'" % (
el.attrib['id'],
- os.path.join( self.options.dir, el.attrib['id']+'.png' ),
+ os.path.join( self.options.dir, self.img_name(el, conf) ),
self.tmp_svg
)
)
@@ -155,6 +189,22 @@ class WebSlicer_Export(WebSlicer_Effect):
#inkex.errormsg( output )
+ _css = {}
+ def reg_css(self, selector, att, val):
+ if not selector in self._css: self._css[selector] = {}
+ if not att in self._css[selector]: self._css[selector][att] = []
+ self._css[selector][att].append( val )
+
+ def css_code(self):
+ code = ''
+ for selector in self._css:
+ code += '\n'+selector+' {\n'
+ for att in self._css[selector]:
+ code += ' '+ att +': '+ (', '.join(self._css[selector][att])) +';\n'
+ code += '}\n'
+ return code
+
+
if __name__ == '__main__':
e = WebSlicer_Export()
e.affect()