23 Extensibility
Contents
- 23.1 Foreign namespaces and private data
- 23.2 Embedding foreign object types
- 23.3 The ‘foreignObject’ element
- 23.4 An example
- 23.5 Adding private elements and attributes to the DTD
- 23.6 DOM interfaces
- 23.6.1 Interface SVGForeignObjectElement
23.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.)
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 with otherwise ignore
unknown attributes.
SVG's ability to include foreign namespaces can be used for
the following purposes:
- Application-specific information so that authoring
applications can include model-level data in the SVG content
to serve their "roundtripping" purposes (i.e., the ability to
write, then read a file without loss of higher-level
information).
- Supplemental data for extensibility. For example, suppose
you have an extrusion extension which takes any 2D graphics
and extrudes it in three dimensions. When applying the
extrusion extension, you probably will need to set some
parameters. The parameters can be included in the SVG content
by inserting elements from an extrusion extension
namespace.
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?xml version= "1.0" standalone= "yes" ?>
<svg width= "4in" height= "3in" version= "1.1"
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>
|
23.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 [MATHML].
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 contents of ‘foreignObject’ are assumed to be
from a different namespace. Any SVG elements within a ‘foreignObject’ will not be drawn,
except in the situation where a properly defined SVG
subdocument with a proper ‘xmlns’
(see Namespaces in XML
[XML-NS])
attribute specification is embedded recursively. One situation
where this can occur is when an SVG document fragment is
embedded within another non-SVG document fragment, which in
turn is embedded within an SVG document fragment (e.g., an SVG
document fragment contains an XHTML document fragment which in
turn contains yet another SVG document fragment).
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.
23.3 The ‘foreignObject’ element
‘foreignObject’
- Categories:
- None
- Content model:
-
Any elements or character data.
- Attributes:
- core attributes — ‘id’, ‘xml:base’, ‘xml:lang’, ‘xml:space’
- conditional processing attributes — ‘requiredFeatures’, ‘requiredExtensions’, ‘systemLanguage’
- graphical event attributes — ‘onfocusin’, ‘onfocusout’, ‘onactivate’, ‘onclick’, ‘onmousedown’, ‘onmouseup’, ‘onmouseover’, ‘onmousemove’, ‘onmouseout’, ‘onload’
- presentation attributes — ‘alignment-baseline’, ‘baseline-shift’, ‘clip’, ‘clip-path’, ‘clip-rule’, ‘color’, ‘color-interpolation’, ‘color-interpolation-filters’, ‘color-profile’, ‘color-rendering’, ‘cursor’, ‘direction’, ‘display’, ‘dominant-baseline’, ‘enable-background’, ‘fill’, ‘fill-opacity’, ‘fill-rule’, ‘filter’, ‘flood-color’, ‘flood-opacity’, ‘font-family’, ‘font-size’, ‘font-size-adjust’, ‘font-stretch’, ‘font-style’, ‘font-variant’, ‘font-weight’, ‘glyph-orientation-horizontal’, ‘glyph-orientation-vertical’, ‘image-rendering’, ‘kerning’, ‘letter-spacing’, ‘lighting-color’, ‘marker-end’, ‘marker-mid’, ‘marker-start’, ‘mask’, ‘opacity’, ‘overflow’, ‘pointer-events’, ‘shape-rendering’, ‘stop-color’, ‘stop-opacity’, ‘stroke’, ‘stroke-dasharray’, ‘stroke-dashoffset’, ‘stroke-linecap’, ‘stroke-linejoin’, ‘stroke-miterlimit’, ‘stroke-opacity’, ‘stroke-width’, ‘text-anchor’, ‘text-decoration’, ‘text-rendering’, ‘unicode-bidi’, ‘visibility’, ‘word-spacing’, ‘writing-mode’
- ‘class’
- ‘style’
- ‘externalResourcesRequired’
- ‘transform’
- ‘x’
- ‘y’
- ‘width’
- ‘height’
- DOM Interfaces:
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 an error (see Error processing).
A value of zero disables rendering of the element.
Animatable:
yes.
-
height = "<length>"
- The height of the rectangular region into which the
referenced document is placed.
A negative value is an error (see Error processing).
A value of zero disables rendering of the element.
Animatable:
yes.
23.4 An example
Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?xml version= "1.0" standalone= "yes" ?>
<svg width= "4in" height= "3in" version= "1.1"
xmlns = 'http://www.w3.org/2000/svg' >
<desc>This example uses the 'switch' element to provide a
fallback graphical representation of an paragraph, if
XMHTML is not supported.</desc>
<!-- The 'switch' element will process the first child element
whose testing attributes evaluate to true.-->
< switch >
<!-- Process the embedded XHTML if the requiredExtensions attribute
evaluates to true (i.e., the user agent supports XHTML
embedded within SVG). -->
<foreignObject width= "100" height= "50"
requiredExtensions= "http://example.com/SVGExtensions/EmbeddedXHTML" >
<!-- XHTML content goes here -->
<body xmlns= "http://www.w3.org/1999/xhtml" >
<p>Here is a paragraph that requires word wrap</p>
</body>
</foreignObject>
<!-- Else, process the following alternate SVG.
Note that there are no testing attributes on the 'text' element.
If no testing attributes are provided, it is as if there
were testing attributes and they evaluated to true.-->
<text font-size= "10" font-family= "Verdana" >
<tspan x= "10" y= "10" >Here is a paragraph that</tspan>
<tspan x= "10" y= "20" >requires word wrap.</tspan>
</text>
</ switch >
</svg>
|
It is not required that SVG user agent support the ability
to invoke other arbitrary user agents to handle embedded
foreign object types; however, all conforming SVG user agents
would need to support the ‘switch’ element and
must be able to render valid SVG elements when they appear as
one of the alternatives within a ‘switch’
element.
Ultimately, it is expected that commercial 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 subject to SVG
transformations and compositing. At this time, such a
capability is not a requirement.
23.5 Adding private elements and attributes to the DTD
Using foreign namespaces as an extension mechanism adds flexibility, is
readily handled by validation technologies like NVDL and RelaxNG, but typically
breaks DTD validation unless the DTD has explicit extensibility hooks.
The SVG DTD allows for extending the SVG language within the
internal DTD subset. Within the internal DTD subset, you have
the ability to add custom elements and attributes to most SVG
elements. This facility may be used if DTD validation is desired.
The DTD defines an extension entity for most of SVG
elements. For example, the ‘view’ element is defined in
the DTD as follows:
<!ENTITY % SVG.view.extra.content "" >
<!ENTITY % SVG.view.element "INCLUDE" >
<![%SVG.view.element;[
<!ENTITY % SVG.view.content
"( %SVG.Description.class; %SVG.view.extra.content; )*"
>
<!ELEMENT %SVG.view.qname; %SVG.view.content; >
<!-- end of SVG.view.element -->]]>
<!ENTITY % SVG.view.attlist "INCLUDE" >
<![%SVG.view.attlist;[
<!ATTLIST %SVG.view.qname;
%SVG.Core.attrib;
%SVG.External.attrib;
viewBox %ViewBoxSpec.datatype; #IMPLIED
preserveAspectRatio %PreserveAspectRatioSpec.datatype; 'xMidYMid meet'
zoomAndPan ( disable | magnify ) 'magnify'
viewTarget CDATA #IMPLIED
>
<!-- end of SVG.view.attlist -->]]>
The entity SVG.view.extra.content
can be defined in the
internal DTD subset to add custom sub-elements
attributes to the ‘view’ element within a given
document, and an <!ATTLIST>
can be used to add
custom attributes. For example, the following extends the ‘view’ element with an
additional child element ‘customNS:customElement’ and an
additional attribute ‘customNS:customAttr’:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?xml version= "1.0" standalone= "no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
<!ENTITY % SVG.view.extra.content "| customNS:customElement" >
<!ATTLIST %SVG.view.qname;
xmlns:customNS CDATA #FIXED "http://www.example.org/customNS"
customNS:customAttr CDATA #IMPLIED>
<!ELEMENT customNS:customElement EMPTY >
<!ATTLIST customNS:customElement
xmlns:customNS CDATA #FIXED "http://www.example.org/customNS"
info CDATA #IMPLIED>
]>
<svg xmlns= "http://www.w3.org/2000/svg" version= "1.1"
width= "8cm" height= "4cm" >
<desc>Extend the 'view' element via the internal DTD subset</desc>
<!-- Presumably, some great graphics would go here. -->
<view viewBox= "100 110 20 30" customNS:customAttr= "123" >
<customNS:customElement info= "abc" />
</view>
</svg>
|
23.6 DOM interfaces
23.6.1 Interface SVGForeignObjectElement
The SVGForeignObjectElement interface corresponds to the
‘foreignObject’ element.
interface SVGForeignObjectElement : SVGElement,
SVGTests,
SVGLangSpace,
SVGExternalResourcesRequired,
SVGStylable,
SVGTransformable {
readonly attribute SVGAnimatedLength x;
readonly attribute SVGAnimatedLength y;
readonly attribute SVGAnimatedLength width;
readonly attribute SVGAnimatedLength height;
};
-
x (readonly SVGAnimatedLength)
Corresponds to attribute ‘x’ on the given ‘foreignObject’
element.
-
y (readonly SVGAnimatedLength)
Corresponds to attribute ‘y’ on the given ‘foreignObject’
element.
-
width (readonly SVGAnimatedLength)
Corresponds to attribute ‘width’ on the given ‘foreignObject’
element.
-
height (readonly SVGAnimatedLength)
Corresponds to attribute ‘height’ on the given ‘foreignObject’
element.