SVG Tiny 1.2 - 20060810

19 Extensibility

Contents

19.1 Foreign namespaces and private data

SVG allows inclusion of elements from foreign namespaces anywhere with the SVG content. In general, the SVG user agent will include the unknown elements in the DOM but will otherwise ignore unknown elements. (The notable exception is described under Embedding Foreign Object Types.)

Extension elements in the SVG namespace must not be used.

Additionally, SVG allows inclusion of attributes from foreign namespaces on any SVG element. The SVG user agent will include unknown attributes in the DOM but will otherwise ignore unknown attributes.Unprefixed attributes on elements in the SVG namespace must not be used for extensions.

SVG's ability to include foreign namespaces can be used for the following purposes:

To illustrate, a business graphics authoring application might want to include some private data within an SVG document so that it could properly reassemble the chart (a pie chart in this case) upon reading it back in:

Example: 23_01.svg
<?xml version="1.0"?>
<svg width="4in" height="3in" version="1.2" baseProfile="tiny"
     xmlns = 'http://www.w3.org/2000/svg'>
  <defs>
    <myapp:piechart xmlns:myapp="http://example.org/myapp"
                    title="Sales by Region">
      <myapp:pieslice label="Northern Region" value="1.23"/>
      <myapp:pieslice label="Eastern Region" value="2.53"/>
      <myapp:pieslice label="Southern Region" value="3.89"/>
      <myapp:pieslice label="Western Region" value="2.04"/>
      <!-- Other private data goes here -->
    </myapp:piechart>
  </defs>
  <desc>This chart includes private data in another namespace
  </desc>
  <!-- In here would be the actual SVG graphics elements which
       draw the pie chart -->
</svg>
    

19.2 Embedding foreign object types

One goal for SVG is to provide a mechanism by which other XML language processors can render into an area within an SVG drawing, with those renderings subject to the various transformations and compositing parameters that are currently active at a given point within the SVG content tree. One particular example of this is to provide a frame for XML content styled with CSS or XSL so that dynamically reflowing text (subject to SVG transformations and compositing) could be inserted into the middle of some SVG content. Another example is inserting a MathML expression into an SVG drawing.

The 'foreignObject' element allows for inclusion of a foreign namespace which has its graphical content drawn by a different user agent. The included foreign graphical content is subject to SVG transformations and compositing.

The user agent must treat all of the content within a 'foreignObject' as foreign content which is to be handed off to an appropriate content handler for rendering. User agents are not required to support any particular content types via 'foreignObject'. In particular, user agents are not required to support SVG content embedded within or referenced by 'foreignObject'; SVG content within 'foreignObject' represents an extension just as with any other type of content.

Usually, a 'foreignObject' will be used in conjunction with the 'switch' element and the requiredExtensions attribute to provide proper checking for user agent support and provide an alternate rendering in case user agent support is not available.

19.2.1 The 'foreignObject' element

The 'foreignObject' element is an extensibility point which allows user agents to offer graphical rendering features beyond those which are defined within this specification.

A conformant SVG user agent is not required to support any particular foreign namespace content within 'foreignObject' itself nor is it required to invoke other user agents to handle particular embedded foreign object types. Ultimately, it is expected that Web browsers will support the ability for SVG to embed content from other XML grammars which use CSS or XSL to format their content, with the resulting CSS- or XSL-formatted content then subject to SVG transformations and compositing. At this time, such a capability is not a requirement. The CDF Working Group is expected to provide this functionality.

The rendered content of a foreignObject must be treated as atomic from the point of view of SVG compositing and transformation, as if it was a single replaced element.

All MouseEvents that are dispatched to a 'foreignObject' element, including mouse events that bubble from the embedded content, must have their clientX/clientY attributes adjusted so that they represent values within the initial viewport coordinate system.

Schema: foreignObject

    <define name='foreignObject'>
      <element name='foreignObject'>
        <ref name='foreignObject.AT'/>
        <ref name='foreignObject.CM'/>
      </element>
    </define>

    <define name='foreignObject.AT' combine='interleave'>
      <ref name='svg.Core.attr'/>
      <ref name='svg.Conditional.attr'/>
      <ref name='svg.XLinkEmbed.attr'/>
      <ref name='svg.Focus.attr'/>
      <ref name='svg.External.attr'/>
      <ref name='svg.Properties.attr'/>
      <ref name='svg.FocusHighlight.attr'/>
      <ref name='svg.Transform.attr'/>
      <ref name='svg.XYWH.attr'/>
    </define>

    <define name='foreignObject.CM'>
  	  <zeroOrMore>
  	    <choice>
          <ref name='svg.Desc.group'/>
          <ref name='svg'/>
  	    </choice>
  	  </zeroOrMore>
    </define>
      

Attribute definitions:

x = "<coordinate>"
The x-axis coordinate of one corner of the rectangular region into which the graphics associated with the contents of the 'foreignObject' will be rendered.

If the attribute is not specified, the effect is as if a value of "0" were specified.

Animatable: yes.
y = "<coordinate>"
The y-axis coordinate of one corner of the rectangular region into which the referenced document is placed.

If the attribute is not specified, the effect is as if a value of "0" were specified.

Animatable: yes.
width = "<length>"
The width of the rectangular region into which the referenced document is placed.

A negative value is unsupported. A value of zero disables rendering of the element. If the attribute is not specified, the effect is as if a value of "0" were specified.

Animatable: yes.
height = "<length>"
The height of the rectangular region into which the referenced document is placed.

A negative value is unsupported. A value of zero disables rendering of the element.

Animatable: yes.
xlink:href = "<XMLRI>"
An IRI reference.

Animatable: yes.
focusable = "true" | "false" | "auto"
See attribute definition for description.

Animatable: Yes
Navigation Attributes
See definition.
 

19.3 An example

Here is an example using a switch and foreignObject:

Example: 23_02.svg
<?xml version="1.0"?>
<svg width="4in" height="3in" version="1.2" baseProfile="tiny" xmlns="http://www.w3.org/2000/svg">
  <desc>This example uses the 'switch' element to provide a fallback graphical 
    representation of the text, if weirdML is not supported.</desc>
  <!-- The 'switch' element will process the first child element
       whose testing attributes evaluate to true.-->
  <switch>
    <!-- Process the embedded weirdML if the requiredExtensions attribute
         evaluates to true (i.e., the user agent supports weirdML
         embedded within SVG). -->
    <foreignObject x="50" y="20" width="100" height="50" 
      requiredExtensions="http://example.com/weirdMLplusSVG">
      <!-- weirdML content goes here -->
      <FreakyText xmlns="http://example.com/weirdML">
        <sparklies q="42"/>
        <throbber seed="1234"/>
        <swirl twist="yeah, baby"/>
        <txt>This is throbbing, swirly text with sparkly bits</txt>
      </FreakyText>
    </foreignObject>
    <!-- Else, process the following alternate SVG.
         Note that there are no testing attributes on the 'textArea' element.
         If no testing attributes are provided, it is as if there
         were testing attributes and they evaluated to true.-->
    <textArea x="50" y="20" width="100" height="50" 
      font-size="10" font-family="Verdana">
      This is plain, conservative SVGT 1.2 text in a
      textArea. 
    </textArea>
  </switch>
</svg>