W3C

SVG Layout 1.0, Part 2: Language

W3C Working Draft

This version:
Latest version:
Editors:
Cameron McCormack, Invited Expert
Doug Schepers, W3C <schepers@w3.org>
Authors:
The authors of this specification are the participants of the W3C SVG Working Group.

Abstract

One of the primary uses for SVG is precise layout for advanced design. However, some designs, and many Web applications, need dynamic layout capabilities, and relative positioning based on the viewport or other elements. This specification provides specific and general mechanisms for pragmatic layout of SVG elements.

Although originally designed for use in SVG, some aspects of layout in this specification are defined in XML and are accessed via a presentation property, and therefore could be used in other environments, such as HTML styled with CSS and XSL:FO.

This document defines the markup used by SVG layout.

Status of This Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. The latest status of this document series is maintained at the W3C.

This document is the first public working draft of this specification. There is an accompanying SVG Layout 1.0, Part 1: Primer that lists the ways SVG Layout may be used.

This document has been produced by the W3C SVG Working Group as part of the W3C Graphics Activity within the Interaction Domain.

We explicitly invite comments on this specification. Please send them to www-svg@w3.org (archives), the public email list for issues related to vector graphics on the Web. Acceptance of the archiving policy is requested automatically upon first post to either list. To subscribe to this list, please send an email to www-svg-request@w3.org with the word subscribe in the subject line.

The latest information regarding patent disclosures related to this document is available on the Web. As of this publication, the SVG Working Group are not aware of any royalty-bearing patents they believe to be essential to SVG.

Publication of this document does not imply endorsement by the W3C membership. A list of current W3C Recommendations and other technical documents can be found at http://www.w3.org/TR/. W3C publications may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to cite a W3C Working Draft as anything other than a work in progress.


How to read this document and give feedback

This draft of SVG Layout introduces new Layout syntax and markup for the SVG language. One of the goals is that this specification can be re-used more easily by other specifications that want to have advanced Layout features. This specification introduces syntax that may not be backwards compatible with older SVG User Agents, and the use of this syntax should be accompanied by a fallback using the 'switch' element.

The main purpose of this document is to encourage public feedback. The best way to give feedback is by sending an email to www-svg@w3.org. Please include some kind of keyword that identifies the area of the specification the comment is referring to in the subject line of your message (e.g "Section X.Y - Foo attribute values" or "Layout Functionality"). If you have comments on multiple areas of this document, then it is probably best to split those comments into multiple messages.

The public are welcome to comment on any aspect in this document, but there are a few areas in which the SVG Working Group are explicitly requesting feedback. These areas are noted in place within this document. There is also a specific area related to the specification that is listed here:

Contents

  1. 1. Introduction
  2. 2. Glossary
  3. 3. Combinatorial Arithmetic Values
  4. 4. Springs and Struts
  5. 5. RelaxNG Schema
  6. 6. DOM interfaces
    1. 6.1. Interface RandomInterface
  7. 7. References
    1. 7.1. Normative References
    2. 7.2. Informative References

Introduction

This chapter describes a declarative syntax for an advanced layout feature set, which when combined with the other web technologies, like SVG or CSS, can describe much of the common layout needs on the Web in such a way that client-side generation and alteration can be performed easily.

Note that even though this specification references parts of SVG 1.1 it does not require a complete SVG 1.1 implementation.

This document is normative.

This document contains explicit conformance criteria that overlap with some RNG definitions in requirements. If there is any conflict between the two, the explicit conformance criteria are the definitive reference.

Glossary

This section is normative.

<absotive>

An <absotive> is a value that is a combination of two basic types of value, an absolute value and a relative value, within the user coordinate system. An absotive value consists of a length (that is, a number followed by an optional unit) followed by an arithmetic function, followed by another length. This may be a percentage to which an absolute pixel value is added or subtracted, or it may be a pixel value to which a percentage is added or subtracted.

It's not yet clear whether the syntax should use an addition or subtraction sign (e.g. "50% - 10px", "20px + 10%"), or if it should be function calls (e.g. "50% subtract(10px)", "20px add(10%)"). It's also not yet clear what arithmetic functions should be allowed, such as subtraction, addition, multiplication, or division.

This section is non-normative.

These are definitions from SVG 1.1 and 1.2, and are included here temporarily for reference. They will be removed before this specification is published as a Last Call document.

SVG1.1 Terms

SVG1.2 Tiny Terms

<coordinate>

A <coordinate> represents a <length> in the user coordinate system that is the given distance from the origin of the user coordinate system along the relevant axis (the x-axis for X coordinates, the y-axis for Y coordinates).

<length>

A length is a distance measurement. The format of a <length> is a <number> optionally followed by a unit identifier. If the <length> is expressed as a value without a unit identifier (e.g., 48), then the <length> represents a distance in the current user coordinate system.

SVG Tiny 1.2 only supports optional units on the 'width' and 'height' attributes on the 'svg' element. These can specify values in any of the following units: in, cm, mm, pt, pc, px and %. If one of the unit identifiers is provided (e.g., 12mm), then the <length> is processed according to the description in Units.

Percentage values (e.g., 10%) on the width and height attributes of the svg element represent a percent of the viewport (refer to the section that discusses Units in general).

Combinatorial Arithmetic Values

SVG 1.1 specifies a <coordinate> or a <length> value for the x, y, width, and height attributes. This specification extends the allowed attribute values to include <absotive> values.

How does this work with SMIL animation?

How does this normalize?

Feature String

A User Agent which supports this feature must evaluate to "true" for a requiredFeatures attribute whose value is http://www.w3.org/Graphics/SVG/feature/1.2/#ArithmeticValues.

http://www.w3.org/Graphics/SVG/feature/1.2/#ArithmeticValues
The ability to interpret and render values which contain arithmetic operations.
		
Currently, SVG units can express a coordinate N pixels from the top or left edge of the viewport, 
but not from the right or bottom edge (unless N is 0, in which case I can use %). So it's easy to 
draw a 10px-wide rectangle along the left edge of the viewport, but not the right edge.

I can work around this limitation in some cases by introducing an <svg> container. For example,
I can actually draw a 10px wide rectangle along the right edge using
<svg ...>
  <svg x="100%" style="overflow:visible">
    <rect x="-10" width="10" y="0" height="100%"/>
  </svg>
</svg>
However, as far as I can tell there is no way to use this to draw, say, a rectangle inset from the 
viewport by 10px on each side. (And of course it's very ugly.)

A very simple extension would be to allow length values like "50%-10". This is necessarily trivial 
to implement since length interpretation already requires support for viewport percentages and 
user-space units; this just combines them into a single value.

An important use-case for this is "nine-grid" image stretching 
(see e.g. http://msdn.microsoft.com/en-us/library/bb189722.aspx). It would be very useful if SVG 
images supported this, for example for use as background images for flexible HTML content.

Of course, SVG direly needs a real layout mechanism. But this is a very small tweak that would provide 
a great deal of value.

RelaxNG Schema for SVG Layout 1.0

The schema for SVG Layout 1.0 is written in RelaxNG [RelaxNG], a namespace-aware schema language that uses the datatypes from XML Schema Part 2 [Schema2]. This allows namespaces and modularity to be much more naturally expressed than using DTD syntax. The RelaxNG schema for SVG Filter 1.2 may be imported by other RelaxNG schemas, or combined with other schemas in other languages into a multi-namespace, multi-grammar schema using Namespace-based Validation Dispatching Language [NVDL].

Unlike a DTD, the schema used for validation is not hardcoded into the document instance. There is no equivalent to the DOCTYPE declaration. Simply point your editor or other validation tool to the IRI of the schema (or your local cached copy, as you prefer).

The RNG is under construction, and only the individual RNG snippets are available at this time. They have not yet been integrated into a functional schema. The individual RNG files are available here.

DOM interfaces

The interfaces below will be made available in a IDL file for an upcoming draft.

The following interfaces are defined below: RandomInterface.



Interface RandomInterface

The RandomInterface interface corresponds to the 'RandomInterface' element.



IDL Definition
interface RandomInterface : SVGElement { 
	  readonly attribute InterfaceString foo;
	};


Attributes
readonly InterfaceString foo
Corresponds to attribute bar on the given 'Random' element.

References

Normative References

[NVDL]
Document Schema Definition Languages (DSDL) — Part 4: Namespace-based Validation Dispatching Language — NVDL. ISO/IEC FCD 19757-4, See http://www.asahi-net.or.jp/~eb2m-mrt/dsdl/
[RelaxNG]
Document Schema Definition Languages (DSDL) — Part 2: Regular grammar- based validation — RELAX NG. ISO/IEC FDIS 19757-2:2002(E), J. Clark, 村田 真 (Murata M.), eds., 12 December 2002. See http://www.y12.doe.gov/sgml/sc34/document/0362_files/relaxng-is.pdf
[Schema2]
XML Schema Part 2: Datatypes Second Edition, P. Biron, A. Malhotra, eds. W3C, 28 October 2004 (Recommendation). Latest version available at http://www.w3.org/TR/xmlschema-2/. See also Processing XML 1.1 documents with XML Schema 1.0 processors.
[SVG11]
Scalable Vector Graphics (SVG) 1.1 Specification, Dean Jackson editor, W3C, 14 January 2003 (Recommendation). See http://www.w3.org/TR/2003/REC-SVG11-20030114/

Informative References

[SVGLP]
SVG Layout Primer, See http://
[]
, See http://