Embedded Content

SVG 2 Requirement: - Have a video element in SVG namespace with the same characteristics as the HTML 5 video element.
- Support 'canvas' element in SVG 2
- the 'video' element
- the 'audio' element
Resolution: - Keep the "Allow video elements to have captions, tracks, etc" SVG 2 requirement.
- The "Provide a way to control audio level and playback" SVG 2 requirement does not need any action, as we will get this functionality from HTMLAudioElement.
- We will keep the "Allow video elements to have captions, tracks, etc" SVG 2 requirement.
- Add an iframe-like element to SVG that includes declarative support for dynamic loading
Purpose: To allow various HTML embedded content elements to be used directly in SVG and support dynamic loading of content.
Owner: stakagi (ACTION-3432)

Overview

SVG supports embedded content similar to the HTML5's embedded content. Embedded content is content that imports another resource into the document, or content from another vocabulary that is inserted into the document.

The embedded content elements which SVG supports are 'image', 'video', 'audio', 'iframe', 'canvas' and 'foreignObject'.

Except 'canvas' and 'foreignObject', embedded content supports Resource Priorities for hinting of downloading external resources. The normative reference is Resource Priorities.

Stakagi: The current Resource Priorities draft does not support embedded content elements which is going to be added by SVG2.0, such as video. Besides, the consideration for mapping and its tiling use cases may be insufficient. It may be better to describe detailed behavior of Resource Priorities in SVG at SVG specifications.

Placement and scaling of the referenced resource

Some embedding elements which refer to an external resource establish a new viewport for the referenced content as described in Establishing a new viewport. The bounds for the new viewport are defined by attributes 'iframe/x', 'iframe/y', 'iframe/width' and 'iframe/height'. The placement and scaling of the referenced resource are controlled by the 'preserveAspectRatio' attribute on the corresponding element.

Brian: I think it's not obvious that we want to add preserveAspectRatio to these elements since CSS3 Images is trying to define similar functionality. Maybe make this an issue?

Attribute definitions:

Name Value Lacuna value Animatable
x, y <length> 0 yes
width, height <length> | auto 0 yes

The 'iframe/x', 'iframe/y', 'iframe/width' and 'iframe/height' attributes specify the rectangular region into which the referenced resource is placed.

A negative value for is invalid (see Error processing). A value of zero for either attribute disables rendering of the element.

The 'auto' value for is used to size the corresponding element automatically based on the intrinsic size or aspect ratio of the referenced resource. If the intrinsic aspect ratio of the referenced resource is unknown, it is assumed to be 2:1. If the intrinsic size of the referenced resource is unknown, it is assumed to be 300x150, just as is required for CSS replaced elements. If 'auto' is specified for just one of 'iframe/width' or 'iframe/height', then the other is determined based on the intrinsic aspect ratio. The automatically determined values are interpreted as user units, and are reflected in the x and y IDL attributes as SVG_LENGTHTYPE_NUMBER values.

Since the pixel coordinate system which some embedded contents has is not always equivalent SVG coordinate system to embed, 'canvas' and 'iframe' have intrinsic width and height as 'canvas/canvasWidth' and 'canvas/canvasHeight' for 'canvas', 'iframe/frameWidth' and 'iframe/frameHeight' for 'iframe' to assign its intrinsic content size.

The 'image' element

The 'image' element indicates that the contents of a complete file are to be rendered into a given rectangle within the current user coordinate system. The 'image' element can refer to raster image files such as PNG or JPEG or to files with MIME type of "image/svg+xml". Conforming SVG viewers need to support at least PNG, JPEG and SVG format files.

The result of processing an 'image' is always a four-channel RGBA result. When an 'image' element references a raster image file such as PNG or JPEG files which only has three channels (RGB), then the effect is as if the object were converted into a 4-channel RGBA image with the alpha channel uniformly set to 1. For a single-channel raster image, the effect is as if the object were converted into a 4-channel RGBA image, where the single channel from the referenced object is used to compute the three color channels and the alpha channel is uniformly set to 1.

When an 'image' element references an SVG image, the 'clip' and 'overflow' properties on the root element in the referenced SVG image are ignored (in the same manner as the 'x', 'y', 'width' and 'height' attributes are ignored). Unless the value of 'preserveAspectRatio' on the 'image' element starts with 'defer', the 'preserveAspectRatio' attribute on the root element in the referenced SVG image is also ignored (see 'preserveAspectRatio' for details). Instead, the 'preserveAspectRatio' attribute on the referencing 'image' element defines how the SVG image content is fitted into the viewport and the 'clip' and 'overflow' properties on the 'image' element define how the SVG image content is clipped (or not) relative to the viewport.

Why does it make sense to override 'clip' but not 'clip-path'?

The value of the 'viewBox' attribute to use when evaluating the 'preserveAspectRatio' attribute is defined by the referenced content. For content that clearly identifies a viewBox (e.g. an SVG file with the 'viewBox' attribute on the outermost svg element) that value should be used. For most raster content (PNG, JPEG) the bounds of the image should be used (i.e. the 'image' element has an implicit 'viewBox' of '0 0 raster-image-width raster-image-height'). Where no value is readily available (e.g. an SVG file with no 'viewBox' attribute on the outermost svg element) the 'preserveAspectRatio' attribute is ignored, and only the translation due to the 'x' & 'y' attributes of the viewport is used to display the content.

We should say how the use of an #xywh media fragment interacts with the the above.

For example, if the image element referenced a PNG or JPEG and preserveAspectRatio="xMinYMin meet", then the aspect ratio of the raster would be preserved (which means that the scale factor from image's coordinates to current user space coordinates would be the same for both X and Y), the raster would be sized as large as possible while ensuring that the entire raster fits within the viewport, and the top/left of the raster would be aligned with the top/left of the viewport as defined by the attributes 'x', 'y', 'width' and 'height' on the 'image' element.  If the value of 'preserveAspectRatio' was 'none' then aspect ratio of the image would not be preserved. The image would be fitted such that the top/left corner of the raster exactly aligns with coordinate ('x', 'y') and the bottom/right corner of the raster exactly aligns with coordinate ('x'+'width', 'y'+'height').

The resource referenced by the 'image' element represents a separate document which generates its own parse tree and document object model (if the resource is XML). Thus, there is no inheritance of properties into the image.

Unlike 'use', the 'image' element cannot reference elements within an SVG file.

SVG 2 Requirement: Support auto-sized images.
Resolution: We will allow auto-sized images in SVG 2.
Purpose: To allow raster images to use their own size without the need to set width and height.
Owner: Cameron (ACTION-3340)
SVG 2 Requirement: Support selecting part of an 'image' for display.
Resolution: We will have a method for 'image' to select a part of an image to display, maybe by allowing 'viewBox' on it.
Purpose: To allow selection of part of an image without requiring the author to manually slice the image.
Owner: Nobody
SVG 2 Requirement: Support the 'object-fit' and 'object-position' properties from css3-images.
Resolution: SVG 2 will depend on CSS3 Image Values and CSS4 Image Values.
Purpose: To align with the CSS way of specifying image fitting that 'preserveAspectRatio' provides.
Owner: Cameron or Erik (no action)

Attribute definitions:

Name Value Lacuna value Animatable
xlink:href <url> (none) yes

An URL reference identifying the image to render.

Name Value Lacuna value Animatable
preserveAspectRatio defer? <align> [ meet | slice ]? xMidYMid meet yes

Specifies the fitting behavior when the aspect ratio of the referenced image does not match the aspect ratio of the rectangle it is placed in. See the definition of 'preserveAspectRatio' for details.

An example:

<?xml version="1.0" standalone="no"?>
<svg width="4in" height="3in"
     xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <desc>This graphic links to an external image
  </desc>
  <image x="200" y="200" width="100px" height="100px"
         xlink:href="myimage.png">
    <title>My image</title>
  </image>
</svg>

The 'video' element

The 'video' element introduces the function that is almost equivalent to 'video' element of html5.0 into svg. But, from the difference of the model of svg and html, it has some differences. This chapter describe them mainly. Therefore, except for any SVG-specific rules explicitly mentioned in this specification, the normative definition for this element is the 'video' element of html5.0.

To refer a video resource, 'video' element uses 'src' attribute insted of 'xlink:href'.

Placement of video resources is established in accordance with Placement and scaling of the referenced resource using ‘x’, ‘y’, ‘width’, ‘height’ and ‘preserveAspectRatio’ attributes.

The 'audio' element

The 'audio' element introduces the function that is almost equivalent to 'audio' element of html5.0 into svg. Except for any SVG-specific rules explicitly mentioned in this specification, the normative definition for this element is the 'audio' element of html5.0. The 'audio' element is not rendered on screen unless it has 'controls' boolean attribute of true.

If 'controls' boolean attribute is present, the 'x', 'y' attributes specify the upper left corner of built-in controller. Otherwise those attributes has no effects.

The 'iframe' element

The 'iframe' element introduces the function that is almost equivalent to 'iframe' element of html5.0 into svg. Except for any SVG-specific rules explicitly mentioned in this specification, the normative definition for this element is the 'iframe' element of html5.0.

The 'iframe' element introduces a new nested browsing context. Placement of browsing context is established in accordance with placement and scaling of the referenced resource using 'x', 'y', 'width', 'height', 'frameWidth', 'frameHeight' and 'preserveAspectRatio' attributes.

The 'frameWidth' and 'frameHeight' specifies the natural (intrinsic) size (dimension) of browsing context(in CSS pixel) in non negative value. Unlike from 'canvas', floating point values are acceptable as intrinsic width and height. (See also CSS Image Values and Replaced Content Module Level 4 #sizing)

If 'frameWidth' or 'frameHeight' attributes are not specified, values of 'width' or 'height' are assigned to corresponding DOM attributes.

Are 'frameWidth' and 'frameHeight' really required? They may only be the same as 'width' and 'height'.

Differ from 'image' element, even if 'iframe' element references an SVG document, placement and scaling is achieved toward browsing context based on its intrinsic size. After that, referred SVG document will be arranged based on initial viewport establishment process for browsing context.

Attribute definitions:

Name Value Lacuna value Animatable
frameWidth <length> 0 yes
frameHeight <length> 0 yes

The 'canvas' element

The 'canvas' element introduces the function that is almost equivalent to 'canvas' element of html5.0 into svg. Except for any SVG-specific rules explicitly mentioned in this specification, the normative definition for this element is the 'canvas' element of html5.0.

The 'canvasWidth' and 'canvasHeight' specifies the natural size(dimension) of canvas object in non negative integer. Therefore it corresponds to html:canvas's 'width' and 'height'. (See also CSS Image Values and Replaced Content Module Level 4 #sizing)

On the other hand, 'x', 'y', 'width' and 'height' attributes specify the rectangular region into which the canvas object is placed considering 'preserveAspectRatio' attribute in accordance with Placement and scaling of the referenced resource.

If 'canvasWidth' or 'canvasHeight' are not specified, INT('width') or INT('height') are assigned to corresponding DOM attributes. In this case, if 'width' or 'height' is less than 1 , then the canvas object is not generated.

Are 'canvasWidth' and 'canvasHeight' really required? They may only be the same as INT('width') and INT('height').

Attribute definitions:

Name Value Lacuna value Animatable
canvasWidth <length> 0 yes
canvasHeight <length> 0 yes

The 'foreignObject' element

'foreignObject'

Stakagi: Should 'foreignObject' be in an Embedded Content chapter? Or should it still be an Extensibility chapter?

The 'source' element

The source element allows authors to specify multiple alternative media resources for media elements. Except for any SVG-specific rules explicitly mentioned in this specification, the normative definition for this element is the 'source' element of html5.0.

The 'track' element

The track element allows authors to specify explicit external timed text tracks for media elements. Except for any SVG-specific rules explicitly mentioned in this specification, the normative definition for this element is the 'track' element of html5.0.

DOM interfaces

Stakagi: In this draft, elements which introduced from HTML inherits HTMLElement as a result. Does this cause problems?

Interface SVGImageElement

The SVGImageElement interface corresponds to the 'image' element.

interface SVGImageElement : SVGGraphicsElement {
  readonly attribute SVGAnimatedLength x;
  readonly attribute SVGAnimatedLength y;
  readonly attribute SVGAnimatedLength width;
  readonly attribute SVGAnimatedLength height;
  readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio;
};

SVGImageElement implements SVGURIReference;
Attributes:
x (readonly SVGAnimatedLength)
Corresponds to attribute 'x' on the given 'image' element.
y (readonly SVGAnimatedLength)
Corresponds to attribute 'y' on the given 'image' element.
width (readonly SVGAnimatedLength)
Corresponds to attribute 'width' on the given 'image' element.
height (readonly SVGAnimatedLength)
Corresponds to attribute 'height' on the given 'image' element.
preserveAspectRatio (readonly SVGAnimatedPreserveAspectRatio)
Corresponds to attribute 'preserveAspectRatio' on the given 'image' element.

Interface SVGVideoElement

The SVGVideoElement interface corresponds to the 'video' element. This interface introduces the function that is almost equivalent to 'HTMLVideoElement' interface of html5.0 into svg.

interface SVGVideoElement : SVGGraphicsElement {
  readonly attribute SVGAnimatedLength x;
  readonly attribute SVGAnimatedLength y;
  readonly attribute SVGAnimatedLength width;
  readonly attribute SVGAnimatedLength height;
  readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio;
};
SVGVideoElement implements HTMLVideoElement;
Attributes:
x (readonly SVGAnimatedLength)
Corresponds to attribute 'x' on the given 'video' element.
y (readonly SVGAnimatedLength)
Corresponds to attribute 'y' on the given 'video' element.
width (readonly SVGAnimatedLength)
Corresponds to attribute 'width' on the given 'video' element.
height (readonly SVGAnimatedLength)
Corresponds to attribute 'height' on the given 'video' element.
preserveAspectRatio (readonly SVGAnimatedPreserveAspectRatio)
Corresponds to attribute 'preserveAspectRatio' on the given 'video' element.

Interface SVGAudioElement

The SVGAudioElement interface corresponds to the 'audio' element. This interface introduces the function that is almost equivalent to 'HTMLAudioElement' interface of html5.0 into svg.

interface SVGAudioElement : SVGGraphicsElement {
  readonly attribute SVGAnimatedLength x;
  readonly attribute SVGAnimatedLength y;
};
SVGAudioElement implements HTMLAudioElement;
Attributes:
x (readonly SVGAnimatedLength)
Corresponds to attribute 'x' on the given 'audio' element.
y (readonly SVGAnimatedLength)
Corresponds to attribute 'y' on the given 'audio' element.

Interface SVGIframeElement

The SVGIframeElement interface corresponds to the 'iframe' element. This interface introduces the function that is almost equivalent to 'HTMLIframeElement' interface of html5.0 into svg.

interface SVGIframeElement : SVGGraphicsElement {
  readonly attribute SVGAnimatedLength x;
  readonly attribute SVGAnimatedLength y;
  readonly attribute SVGAnimatedLength width;
  readonly attribute SVGAnimatedLength height;
  readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio;
  readonly attribute SVGAnimatedLength frameWidth;
  readonly attribute SVGAnimatedLength frameHeight;
};

SVGIframeElement implements HTMLIframeElement;

Brian: Is it possible to use SVGIFrameElement implements HTMLIFrameElement? (fixed)

Attributes:
x (readonly SVGAnimatedLength)
Corresponds to attribute 'x' on the given 'iframe' element.
y (readonly SVGAnimatedLength)
Corresponds to attribute 'y' on the given 'iframe' element.
width (readonly SVGAnimatedLength)
Corresponds to attribute 'width' on the given 'iframe' element.
height (readonly SVGAnimatedLength)
Corresponds to attribute 'height' on the given 'iframe' element.
preserveAspectRatio (readonly SVGAnimatedPreserveAspectRatio)
Corresponds to attribute 'preserveAspectRatio' on the given 'iframe' element.
frameWidth (readonly SVGAnimatedLength)
Corresponds to attribute 'frameWidth' on the given 'iframe' element.
frameHeight (readonly SVGAnimatedLength)
Corresponds to attribute 'frameHeight' on the given 'iframe' element.

Interface SVGCanvasElement

The SVGCanvasElement interface corresponds to the 'canvas' element. This interface introduces the function that is almost equivalent to 'HTMLCanvasElement' interface of html5.0 into svg.

interface SVGCanvasElement : SVGGraphicsElement {
  readonly attribute SVGAnimatedLength x;
  readonly attribute SVGAnimatedLength y;
  readonly attribute SVGAnimatedLength width;
  readonly attribute SVGAnimatedLength height;
  readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio;
  readonly attribute SVGAnimatedLength canvasWidth;
  readonly attribute SVGAnimatedLength canvasHeight;
};
SVGCanvasElement implements HTMLCanvasElement;
Attributes:
x (readonly SVGAnimatedLength)
Corresponds to attribute 'x' on the given 'canvas' element.
y (readonly SVGAnimatedLength)
Corresponds to attribute 'y' on the given 'canvas' element.
width (readonly SVGAnimatedLength)
Corresponds to attribute 'width' on the given 'canvas' element.
height (readonly SVGAnimatedLength)
Corresponds to attribute 'height' on the given 'canvas' element.
preserveAspectRatio (readonly SVGAnimatedPreserveAspectRatio)
Corresponds to attribute 'preserveAspectRatio' on the given 'canvas' element.
canvasWidth (readonly SVGAnimatedLength)
Corresponds to attribute INT('canvasWidth') on the given 'canvas' element.
canvasHeight (readonly SVGAnimatedLength)
Corresponds to attribute INT('canvasHeight') on the given 'canvas' element.

Interface SVGSourceElement

The SVGSourceElement interface corresponds to the 'source' element. This interface introduces the function that is almost equivalent to 'HTMLSourceElement' interface of html5.0 into svg.

interface SVGSourceElement : SVGElement { };
SVGSourceElement implements HTMLSourceElement;

Interface SVGTrackElement

The SVGTrackElement interface corresponds to the 'track' element. This interface introduces the function that is almost equivalent to 'HTMLTrackElement' interface of html5.0 into svg.

interface SVGTrackElement : SVGElement { };
SVGTrackElement implements HTMLTrackElement;