Tuesday, November 18, 2008

<use>, SVG and Opera

Une version française de cet article est disponible:

I'm currently testing the advanced possibilities of SVG. For my tests, I'm using mainly GPAC, Firefox and Opera; Safari also sometimes. You can find a comparison of implementations at this link, which is based on the test suite for SVG 1.2 defined by the W3C. Moreover, there is a state of the implementation of SVG in Firefox here. There is an equivalent for Opera here.

The <use element on an external link is an interesting possibility for animation, user interfaces, patterns ...

For example, you define a widget with id 'mywidget' in a svg named s1.svg. Then you can use it in another svg with the line:

This is a simple way to develop projects gradually in a structured way.

We will quickly find situations where there is a complex document with an external <use> which itself contains a <use>. For example, you run a widget with a <use>, as above, and this widget itself is defined with a <use> pointing to another file.

Following is an example used for testing, based on the structure of a cartoon-type svg: a scene uses a background, itself constructed from various elements.

Main.svg file:
xmlns: xlink = 'http://www.w3.org/1999/xlink'
xmlns: svg = 'http://www.w3.org/2000/svg'
xmlns = 'http://www.w3.org/2000/svg'
width ='800 'height ='600'
<use id='decor' xlink:href="decor.svg#decor"/>
</ svg>

File decor.svg (resume the previous tag svg)
<svg ...>
<use id='decor' xlink:href="bulle.svg#circ"/>
</ svg>

Bulle.svg file:
<svg ... >
<circle id='circ' cx='100' cy='100' r='50' fill='red'/>
</ svg>

This test works well in GPAC, but not in Firefox 3.0.1, or Opera 9.62.

For Firefox, the status page above said about <use>: "Only works for internal document references (bug 269482).", So the external references are not yet supported.

For Opera, the first level of external <use> works, contrary to what is said on the Opera site "Note: External references, eg, are not supported."

It appears that the lack of common support for external <use> prevents the time when we will systematically structure SVG scenes with <use>.

I think I will continue to structure scenes with use and make a xslt transformation seeking use in a document to replace the content. To be continued ...

No comments: