Logo

2D Web Graphics: SVG

I. Herman, W3C, Head of Offices
Hong Kong, 2nd of September, 2002

  1. Graphics on the Web Today
  2. What do we Need?
  3. SVG
  4. A Simple SVG Example
  5. Transformation Examples
  6. Geometry: Path Expressions
  7. Path Examples
  8. Path “Shortcuts”
  9. Text
  10. International Text
  11. Inclusion of Images
  12. SVG Attributes
  13. Stroke Attributes
  14. Area Attributes
  15. Gradient Fill Examples
  16. Pattern Fill
  17. Text Attributes
  18. Filters
  19. Filter Operations
  20. Filter Details
  21. Colour Matrix Manipulation
  22. Picture Compositing
  23. Convolution Matrix on Pixels
  24. SVG Animation
  25. SVG Animation Example
  26. What is animated?
  27. Walking Man...
  28. How is animation performed?
  29. Bouncing Cubes
  30. When is animation performed?
  31. Chaining Animations
  32. Animated Patterns
  33. Changing Pattern References
  34. Lights and Images
  35. SVG DOM
  36. SVG DOM Objects and Methods
  37. Interaction with the DOM Tree
  38. When Should Scripts Be Used?
  39. Clock
  40. Mine Sweeper Example
  41. SVG and HTML
  42. Better (Future) Integration
  43. Implementations: Players
  44. Implementations: Authoring
  45. Application Examples
  46. Roadmap of SVG Evolution
  47. SVG Basic & Tiny
  48. First Mobile SVG Implementations
  49. Further Information
  50. Further Information (cont)
Logo

Graphics on the Web Today

  • Pixel based images (gif, png, jpeg, ...)
    • Fixed resolution
    • Can be very large
    • Original “information” is lost
      • difficult to add metadata
      • difficult to adapt to viewing environment
    • Limited interaction (except for animated gifs and the like)
    • Client/server side image maps for linking
      • clumsy, requires separate authoring tools
  • Other, proprietary solutions
    • proprietary authoring tools, players, ...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 20021 (50)
Logo

What do we Need?

Vector graphics
Resolution independent
Keeps "content" information
In line with earlier developments (GKS, PHIGS, PostScript, ...)
Textual encoding (too)
Let the client side interpret the content
Searchable
Easy to edit, add links, etc
Based on XML
Use a well-understood syntax
Can “inherit” functionalities from elsewhere
Can make use of XML aware software (implementations, editing, ...)
Integrates well with the rest of the Web

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 20022 (50)
Logo

SVG

Scalable Vector Graphics (SVG):

  • W3C Working Group was created in 1998
  • Specification quite stable by 2000, with first implementations
  • Version 1.0 became a W3C recommendation in September 2001
  • Work is continuing:
    • Mobile Profiles (part of the 3GPP protocols)
    • Richer functionalities: Version 2.0
“SVG is the HTML for Graphics”

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 20023 (50)
Logo

A Simple SVG Example

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 20024 (50)
Logo

Transformation Examples

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 20025 (50)
Logo

Geometry: Path Expressions

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 20026 (50)
Logo

Path Examples

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 20027 (50)
Logo

Path “Shortcuts”

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 20028 (50)
Logo

Text

  • Is a separate element

    <text x=".." y="..">Blablabla</text>

  • Has tons of attributes (mostly from CSS):
    • font, weight, font style, size
    • colour (both outline and inside a character)
    • writing mode, text anchor
    • B
  • Text can be positioned on a curve:
    <path id="path"> ...</path>
    <text><textPath xlink:href="#path"> ...</textPath></text>
image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 20029 (50)
Logo

International Text

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200210 (50)
Logo

Inclusion of Images

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200211 (50)
Logo

SVG Attributes

  • The usual attributes are available:
    • stroke attributes (line join, miter, dash array, etc)
    • fill rule (even-odd, nonzero)
    • pattern fill (an image can also be a pattern!)
    • clipping, masking
  • Colour
  • Patterns, linear and radial colour gradients
  • Opacity ("alpha" value)
  • Attributes can be set directly or through CSS

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200212 (50)
Logo

Stroke Attributes

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200213 (50)
Logo

Area Attributes

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200214 (50)
Logo

Gradient Fill Examples

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200215 (50)
Logo

Pattern Fill

    <pattern id="P" width="150" height="147">
        <image width="150" height="147" xlink:href="Persian.png"/>
    </pattern>
image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200216 (50)
Logo

Text Attributes

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200217 (50)
Logo

Filters

  • Graphics on the Web is often used for "artwork"
    • complex logos
    • "sexy" presentations (shadow effects, pseudo 3D)
    • advertisements
  • Filters have been added to SVG to produce artwork:
    • a collection of filter primitives
    • combined in a data-flow network
    • applied after all rendering operations, but before display
image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200218 (50)
Logo

Filter Operations

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200219 (50)
Logo

Filter Details

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200220 (50)
Logo

Colour Matrix Manipulation

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200221 (50)
Logo

Picture Compositing

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200222 (50)
Logo

Convolution Matrix on Pixels

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200223 (50)
Logo

SVG Animation

  • SVG Animation = change object attributes dynamically
  • Animation is controlled through a set of animation objects
    • reusing parts of W3C's SMIL2.0 Specification

      (Synchronized Multimedia Integration Language Version 2.0)

  • Declarative syntax, no real increase in file size
  • Animation is performed on client side

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200224 (50)
Logo

SVG Animation Example

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200225 (50)
Logo

What is animated?

  • Practically all attributes can be changed
  • Separate animation elements
    • animate, animateMotion, animateTransform
    • animateColor
    • set (changes discrete values)
  • Example:
image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200226 (50)
Logo

Walking Man...

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200227 (50)
Logo

How is animation performed?

  • By default, animation is linear
    • the [from,to] interval is interpolated linearly over required duration
  • Alternative possibilities:
    • Discrete jumps (no interpolation)
    • Specify intermediate (key) values and time
    • Replace linear interpolation by (cubic) splines (in [0,1])
    • Key times and spline interpolation can be combined

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200228 (50)
Logo

Bouncing Cubes

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200229 (50)
Logo

When is animation performed?

  • Simple case: time-based animation
    • begin, dur, end attributes
    • values are in time (with "t = 0" value at loading)
    • all kinds of time units are available
  • Complicated case: event-based animation
    • begin attribute can refer to events, eg:
      • obj.click, when a click occurs on obj
      • anim.end or anim.begin, when anim ends, resp. begins
      • anim.end; anim2.end, when anim or anim2 ends
      • anim.begin+4s 4 seconds afteranim begins
      • obj.mouseover, obj.mouseout when mouse moves over/out obj
      • ...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200230 (50)
Logo

Chaining Animations

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200231 (50)
Logo

Animated Patterns

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200232 (50)
Logo

Changing Pattern References

    <path fill="url(#Pattern)"
        <set attributeName="fill" to="url(#Pattern2)" begin="click"/>
    </path>
image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200233 (50)
Logo

Lights and Images

Put a light source "above" the image and animate its characteristics...

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200234 (50)
Logo

SVG DOM

  • DOM = Document Object Model
    • programmatic interface to the runtime XML tree
    • a general W3C mechanism with an SVG specialization
  • Scripts can be included in SVG (through a script node)
  • Scripts can modify:
    • the XML tree (add and/or delete nodes)
    • the attributes of individual objects

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200235 (50)
Logo

SVG DOM Objects and Methods

  • General DOM methods (inherited by SVG):
    • getOwnerDocument(), getNodeName(), getChildNodes(),...
    • getPreviousSiblings(), getAttributes().item(0),...
    • getLength(), item()
    • getElementsByTagName(), getElementById(),...
    • getAttribute(), setAttribute(), hasAttribute(),...
  • SVG Specific:
    • SVGDocument object (subclass of Document)
    • SVGTranform object
      • setMatrix(), setTranslate(), setRotate(), etc, methods

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200236 (50)
Logo

Interaction with the DOM Tree

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200237 (50)
Logo

When Should Scripts Be Used?

  • Complex animation and/or interaction
    • complicated visual effects
    • need for the state of interaction
    • more compact code
    • list handling
  • Numerical calculations
  • Client/server type applications
  • Random features (eg, random choice among alternatives)

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200238 (50)
Logo

Clock

    <g onload="Start(evt)" ... >
    ...
    function Start(evt)
        var now=new Date();
        clockObj.adjustTime(now);
    }
image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200239 (50)
Logo

Mine Sweeper Example

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200240 (50)
Logo

SVG and HTML

Inclusion into HTML with a plugin:

    <object data="File.svg" width=".." height=".." type="image/svg+xml">
        <img src="..." alt="Image replacement...>
    </object>
  • embed also works, but is deprecated in HTML4 and XHTML
  • all kinds of units (mm, cm, inch, etc) can also be used

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200241 (50)
Logo

Better (Future) Integration

  • Inclusion into any XML with namespaces (eg, XHTML)
    <?xml version="1.0" standalone="yes"?>
    <parent xmlns="http://example.org"
            xmlns:gr="http://www.w3.org/2000/svg">
      <parentElement>....</parentElement>
      <anotherParentElement>
        <gr:svg viewBox="..." width="..." height="..." ... >
          <gr:rect>....</gr:rect>
        </gr:svg>
      </anotherParentElement>
    </parent>
  • Works in W3C's Amaya, X-Smiles, and Mozilla's SVG build
    • none of these is a complete implementation of SVG...
  • Allows for a nice combination of XML applications!

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200242 (50)
Logo

Implementations: Players

  • Adobe's plugin, works with major browsers on Win and Mac;

    Linux and Solaris in beta

  • kSVG project for Konqueror on Linux
  • Various standalone players, mostly in Java (eg, Batik)
  • Ongoing Mozilla project
  • Implementations for Palm PC-s, phones, embedded systems
    • they implement the mobile profiles (see later)
  • Canon is experimenting with an SVG Printer
None of these are complete, but we are getting there!

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200243 (50)
Logo

Implementations: Authoring

  • Export facilities from Adobe AI, Corel, OpenOffice.org, ...
  • "Pure" SVG drawing tool from Jasc, PCX, ...
  • Conversion tools
    • Square1's PS to SVG
    • SVG Factory's WMF or BMP to SVG
    • KK Software or Celiena's raster to SVG
    • Software Mechanics' SVGMaker
  • Subclass to Java's Graphics2D to generate SVG (part of Batik)
  • Direct SVG DOM implementation in Java (also part of Batik)

Check W3C's site: http://www.w3.org/Graphics/SVG/!

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200244 (50)
Logo

Application Examples

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200245 (50)
Logo

Roadmap of SVG Evolution

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200246 (50)
Logo

SVG Basic & Tiny

  • SVG Basic:
    • All numbers must be limited to a 16bits range
    • No elliptical arcs in paths
    • Subset of the presentation and CSS attributes
    • Subsets of filters (e.g., no lighting)
    • Scripting facility is optional
    • etc
  • SVG Tiny:
    • All the SVG Basic profile restrictions
    • No clipping, no opacity, no filters
    • No text on path
    • etc
  • Candidate recommendation published since 30th of April 2002

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200247 (50)
Logo

First Mobile SVG Implementations

image replacement for an SVG file...

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200248 (50)
Logo

Further Information

The SVG Recommendation itself:
http://www.w3.org/TR/SVG/
Textbooks
There are about six books published already (!)
Some other sites on SVG:
http://www.kevlindev.com (Kevin Lindsey)
http://pilat.free.fr/filters/ (Michel Hirtzler)
http://groups.yahoo.com/group/svg-developers/
....
Proceedings of SVG Open 2002
http://www.svgopen.org/index-2002.shtml
Start by:
http://wdvl.com/Authoring/Languages/XML/SVG/
http://www.w3.org/Graphics/SVG/

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200249 (50)
Logo

Further Information (cont)

I. Herman, W3C, Head of OfficesHong Kong, 2nd of September, 200250 (50)