Made SVG icons no longer require a viewBox to display properly

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1489 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-03-30 15:28:57 +00:00
parent 9d08f8c0a7
commit 4a79a4b1da
2 changed files with 13 additions and 4 deletions

View File

@ -5,11 +5,10 @@
in the extension. The SVG inside the group makes up the actual icon, and in the extension. The SVG inside the group makes up the actual icon, and
needs use a viewBox instead of width/height for it to scale properly. needs use a viewBox instead of width/height for it to scale properly.
Multiple icons can be included, each within their own group. A final element Multiple icons can be included, each within their own group.
with ID "svg_eof" must be included too.
--> -->
<g id="hello_world"> <g id="hello_world">
<svg viewBox="0 0 102 102" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <svg width="102" height="102" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Created with SVG-edit - http://svg-edit.googlecode.com/ --> <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
<g> <g>
<title>Layer 1</title> <title>Layer 1</title>
@ -19,5 +18,4 @@
</g> </g>
</svg> </svg>
</g> </g>
<g id="svg_eof"/>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -293,6 +293,17 @@ $(function() {
var svgroot = svgdoc.createElementNS(svgns, "svg"); var svgroot = svgdoc.createElementNS(svgns, "svg");
svgroot.setAttributeNS(svgns, 'viewBox', [0,0,icon_w,icon_h].join(' ')); svgroot.setAttributeNS(svgns, 'viewBox', [0,0,icon_w,icon_h].join(' '));
// Make flexible by converting width/height to viewBox
var w = svg.getAttribute('width');
var h = svg.getAttribute('height');
svg.removeAttribute('width');
svg.removeAttribute('height');
var vb = svg.getAttribute('viewBox');
if(!vb) {
svg.setAttribute('viewBox', [0,0,w,h].join(' '));
}
$(svgroot).attr({ $(svgroot).attr({
"xmlns": svgns, "xmlns": svgns,
"width": icon_w, "width": icon_w,