Logo

The SVG language
Didier Courtaud
Novembre 2001

Logo orateur

Plan

The SVG language

ATHENS Conference

November 2002

Didier Courtaud

Didier.Courtaud@cea.fr

Disclaimer

Introduction

Introduction : overview

Introduction : definitions and concepts

Introduction : Definitions and concepts ( continued )

Introduction : Definitions and concepts ( continued )

SVG document structure

SVG document structure : Elements grouping

SVG document structure : Referencing

SVG document structure : Referencing ( continued )

SVG document structure : Referencing ( continued )

SVG document structure : Referencing ( continued )

SVG document structure: Metadata

SVG document structure  : Conditional treatment

Coordinates systems

Coordinates systems : transformations

Coordinates systems : transformations ( continued )

Coordinates systems : transformations ( continued )

Coordinates systems : transformations ( continued )

Coordinates systems : transformations ( continued )

Coordinates systems : transformation attributes

Coordinates systems : Viewpoint attributes

Coordinates systems : Viewpoint attributes ( continued )

Coordinates systems : New viewpoints

Low level functionnalities

Low level functionnalities : elementary drawing commands ( continued )

Basic drawing commands

Low level functionnalities : elementary drawing commands ( continued )

Low level functionnalities : examples

?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >

<svg width="600px" height="200px">
  <text x="5" y="20" style="font-size:24">SVG Test: Path using horizontal &amp; vertical lines</text>
  <g style="fill:none; stroke:blue">
    <path d="M 50,50  h 50 v 50 h -50 z"/>
    <path d="M 110,50 h 50 v 50 h -50 v -50"/>
    <path d="m 50,110 h 50 v 50 h -50 z" />
  </g>
</svg>

 

Low level functionnalities: examples ( II )

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >
<svg width="500" height="700" >
  <g style="text-rendering:optimizeLegibility;shape-rendering:default">
    <text x="5" y="20" style="font-size:24">SVG Demo: More elliptical arcs</text>

    <g style="stroke-width:4 ; fill:none; stroke:blue" >
      <path d="M 60,50   A 50 50 0 0 0 110 100" />
      <path d="M 160,50  A 50 50 0 0 1 210 100" />
      <path d="M 60,150  A 50 50 0 1 0 110 200" />
      <path d="M 160,200 A 50 50 0 1 1 210 250" />
    </g>

    <g style="font-size:8" >
      <text x="10"  y="120">M 60,50  A 50 50 0 0 0 110 100</text>
      <text x="150" y="120">M 160,50 A 50 50 0 0 1 210 100</text>
      <text x="10"  y="280">M 60,150 A 50 50 0 1 0 110 200</text>
      <text x="150" y="280">M 160,200 A 50 50 0 1 1 210 250</text>
    </g>
  </g>
</svg>
 

Low level functionnalities : elementary shapes

Low level functionnalities : rectangles

Low level functionnalities : circles

Low level functionnalities : ellipses

Low level functionnalities : lines

Low level functionnalities : polylines

Low level functionnalities :polygons

Low level functionnalities : Basic shapes examples

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >
<svg width="500" height="500" >
  <g style="text-rendering:optimizeLegibility;shape-rendering:default">
    <text x="5" y="20" style="font-size:22">SVG Demo: Basic SVG shapes</text>

    <g style="stroke:black; fill:none; shape-rendering:default" >
      <circle cx="70"  cy="100" r="50"  />
      <rect x="150" y="50" width="135" height="100" />
      <line x1="325" y1="150" x2="375" y2="50" />
      <line x1="375" y1="50"  x2="425" y2="150" />
      <polyline points="50,250,75,350,100,250,125,350,150,250,175,350" />
      <polygon points="250,250,297,284,279,340,220,340,202,284,250,250" />
      <ellipse cx="400" cy="300" rx="72" ry="50" />
    </g>

    <g style="text-rendering:optimizeSpeed">
      <text x="50"  y="175">Circle</text>
      <text x="175" y="175">Rectangle</text>
      <text x="355" y="175">Lines</text>
      <text x="50"  y="375">Polyline</text>
      <text x="225" y="375">Polygon</text>
      <text x="375" y="375">Ellipse</text>
    </g>
  </g>
</svg>
 

Low level functionnalities : Basic shapes examples ( II )

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >

<svg width="680" height="500" >
  <g style="text-rendering:optimizeLegibility">
    <text x="5" y="20" style="font-size:22">SVG Demo: Some basic SVG filled and stroked regular polygons</text>

    <g style="stroke:blue; fill:red; shape-rendering:default; stroke-width:10" >
      <polygon points="99,50,143,125,56,124,99,50" />
      <polygon points="225,50,275,99,225,150,175,100,224,50" />
      <polygon points="350,50,397,84,379,140,320,140,302,84,350,50" />
      <polygon points="475,50,518,74,518,125,475,150,431,124,431,75,475,50" />
      <polygon points="99,175,138,193,148,235,122,269,79,270,51,237,59,195,97,175" />
      <polygon points="225,175,260,189,275,225,260,260,225,275,189,260,175,225,189,189,224,175" />
      <polygon points="350,175,382,186,399,216,393,250,367,271,332,271,306,250,300,216,317,186,350,175" />
      <polygon points="475,175,504,184,522,209,522,240,504,265,475,275,445,265,427,240,427,209,445,184,475,175" />
    </g>
  </g>
</svg>

 

Text

Text : syntax

Text : fitting elements

Text : fitting elements ( continued )

Text : specifications

Text : relationship with paths

Rendering

Rendering : specifications

Rendering : specifications ( examples )

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >

<svg width="500" height="500" >
  <g style="stroke:black; stroke-width:6; text-rendering:optimizeLegibility; shape-rendering:default" >

    <text x="5" y="20" style="font-size:22">SVG Demo: Stroke and fill opacity.</text>

    <rect x="10"  y="100" width="400" height="100" style="fill:yellow"  />
    <rect x="10"  y="225" width="400" height="100" style="fill:green"  />

    <g style="stroke:blue;fill:cyan">
      <rect x="25"  y="50"  width="50"  height="320" style="stroke-opacity:0.2;fill-opacity:0.2"  />
      <rect x="100" y="50"  width="50"  height="320" style="stroke-opacity:0.4;fill-opacity:0.4"  />
      <rect x="175" y="50"  width="50"  height="320" style="stroke-opacity:0.6;fill-opacity:0.6"  />
      <rect x="250" y="50"  width="50"  height="320" style="stroke-opacity:0.8;fill-opacity:0.8"  />
      <rect x="325" y="50"  width="50"  height="320"   />
    </g>

    <text x="40"  y="385">0.2</text>
    <text x="115" y="385">0.4</text>
    <text x="190" y="385">0.6</text>
    <text x="265" y="385">0.8</text>
    <text x="340" y="385">1.0</text>

  </g>
</svg>
 

Rendering : specifications ( examples ) ( II )

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >

<svg width="525" height="500" >
  <g style="shape-rendering:default; stroke-width:14; stroke:#0000FF; fill:none" >
    <path d="M50,50C50,200,200,50,200,200" style="stroke-linecap:butt; stroke-dasharray:10 5" />
    <path d="M50,150C50,300,200,150,200,300" style="stroke-linecap:round; stroke-dasharray:10 20" />
    <path d="M50,250C50,400,200,250,200,400" style="stroke-linecap:square; stroke-dasharray:10 20" />
    <path d="M300,50Q400,400,500,50" style="stroke-linecap:butt; stroke-dasharray:20 10" />
    <path d="M300,150Q400,500,500,150" style="stroke-linecap:round; stroke-dasharray:10 20" />
    <path d="M300,250Q400,600,500,250" style="stroke-linecap:square; stroke-dasharray:10 20" />
  </g>
</svg>

Rendering : markers

Color

Gradients and patterns

Gradients and patterns : linear gradient

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >

<svg width="500px" height="600px" >
  <g style="text-rendering:optimizeLegibility;shape-rendering:default">

    <defs>
      <linearGradient id="grad1" x1="0" y1="0" x2="400" y2="400">
        <stop offset="0%"   style="stop-color:#FF0000"/>
        <stop offset="25%"  style="stop-color:#0000FF"/>
        <stop offset="50%"  style="stop-color:#00FF00"/>
        <stop offset="75%"  style="stop-color:#0000FF"/>
        <stop offset="100%" style="stop-color:#FF0000"/>
      </linearGradient>
    </defs>

    <text x="5" y="20" style="font-size:22">SVG Demo: Linear gradients</text>

    <path style="fill:url(#grad1)" d="M0 50 h200 v200 h-200 z"/>

    <circle  style="fill:url(#grad1)" cx="320" cy="150" r="100" />

    <polygon style="fill:url(#grad1)" points="0,400,200,400,100,280" />

    <ellipse style="fill:url(#grad1)" cx="300" cy="350" rx="100" ry="75"/>

    <rect style="fill:url(#grad1)" x="0" y="450" width="400" height="100" />

  </g>
</svg>

Gradients and patterns : radial gradient

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >
<
<svg width="500px" height="500px" >
  <g style="text-rendering:optimizeLegibility;shape-rendering:default">

    <defs>
      <radialGradient id="grad1" cx="250" cy="250" r="300" fx="250" fy="250">
        <stop offset="0%"   style="stop-color:#FF0000"/>
        <stop offset="25%"  style="stop-color:#0000FF"/>
        <stop offset="50%"  style="stop-color:#00FF00"/>
        <stop offset="75%"  style="stop-color:#0000FF"/>
        <stop offset="100%" style="stop-color:#FF0000"/>
      </radialGradient>
    </defs>

    <text x="5" y="20" style="font-size:22">SVG Demo: Radial gradient</text>

    <rect style="fill:url(#grad1)" x="50" y="50" width="400" height="400" />

  </g>
</svg>

Gradients and patterns : patterns

<?xml version="1.0"?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >

<svg width="600px" height="500px" >

  <defs>
     <pattern id="mypattern" x="0" y="0" width="30" height="30">
       <rect width="30" height="30" style="fill:yellow" />
       <path style="fill:none;stroke:blue" d="M0,0 L 30,30 M0,30 L 30,0" />
     </pattern>
  </defs>

  <g style="text-rendering:optimizeLegibility" >
    <text x="5" y="20" style="font-size:22">SVG Demo: Filling and stroking with a custom pattern</text>
  </g>

  <g style="stroke:none; shape-rendering:default" >
    <ellipse cx="150" cy="150" rx="100" ry="100" style="fill:url(#mypattern)" />
    <rect x="300" y="50" width="150" height="150" style="fill:url(#mypattern)" />
    <ellipse cx="250" cy="350" rx="200" ry="75" style="stroke:url(#mypattern);fill:none;stroke-width:20" />
  </g>

</svg>
 

Clipping and masking

Clipping and masking : clipping example

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg SYSTEM "svg-19991203.dtd" >

<svg width="500" height="500" >

  <defs>
    <clipPath>
      <ellipse cx="200" cy="220" rx="80" ry="120" id="myClip"  />
    </clipPath>
  </defs>

  <g style="text-rendering:optimizeLegibility;shape-rendering:default" >
    <text  x="5" y="25" style="font-size:24">SVG Demo: An image clipped by an ellipse.</text>

    <ellipse cx="200" cy="220" rx="90" ry="130" style="fill:#CE8A77" />
    <image x="40" y="100" width="320" height="240" xlink:href="krl1.jpg" style="clip-path:URL(#myClip)"/>
  </g>
</svg>
 

Clipping and masking : mask example

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG December 1999//EN"
  "http://www.w3.org/Graphics/SVG/SVG-19991203.dtd">
<svg width="4in" height="3in">
  <desc>Example of using a mask
  </desc>
  <g>
    <defs>
      <mask id="MyMask">
        <image width="10" height="25" xlink:href="transp.png" />
      </mask>
    </defs>
    <rect style="mask: url(#MyMask)" width="12.5" height="30" />
  </g>
</svg>

Filtering effects

Filtering effects : example

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG December 1999//EN"
 "http://www.w3.org/Graphics/SVG/SVG-19991203.dtd">
<svg width="278px" height="118px">
 <defs>
<filter id="Shadow">
<feGaussianBlur in="SourceAlpha"
  stdDeviation="3"
  result="blurredAlpha" />
 <feOffset in="blurredAlpha"
   dx="2" dy="1"
   result="offsetBlurredAlpha" />
 <feDiffuseLighting in="blurredAlpha"
   diffuseConstant=".5"
    surfaceScale="5"
    resultScale="5"
    LightColor="white"
    result="bumpMapDiffuse" >
 <feDistantLight azimuth="135" elevation="60"/>
</feDiffuseLighting>
<feComposite in="bumpMapDiffuse" in2="SourceGraphic"
  operator="arithmetic" k1="1"
  result="litPaint" />
 <feSpecularLighting in="blurredAlpha"
   surfaceScale="5"
   specularConstant=".5"
   specularExponent="10"
   lightColor="white"
   result="bumpMapSpecular" >
  <feDistantLight azimuth="135" elevation="60"/>
 </feSpecularLighting>
 <feComposite in="litPaint" in2="bumpMapSpecular"
   operator="arithmetic" k2="1" k3="1"
   result="litPaint" />
  <feComposite in="litPaint"
    in2="SourceAlpha"
    operator="in"
    result="litPaint" />
 <feMerge>
    <feMergeNode in="offsetBlurredAlpha" />
     <feMergeNode in="litPaint" />
  </feMerge>
 </filter>
 </defs>
  <desc>Example filters02 - text with shadowing effect</desc>

  <text style="font-size:36px; fill:red; filter:url(#Shadow)"
  x="10px" y="70px">Shadowed Text</text>
</svg>

Links

Links : internal links

Scripts

Animations

Animations : elements

Animations : example

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG December 1999//EN"
  "http://www.w3.org/Graphics/SVG/SVG-19991203.dtd">
<svg width="8cm" height="3cm"  viewBox="0 0 800 300">
  <desc>Example anim01 - demonstrate animation elements</desc>

  <!-- The following illustrates the use of the 'animate' element
to animate a rectangles x, y, and width attributes so that
the rectangle grows to ultimately fill the viewport. -->
  <rect id="RectElement" x="300" y="100" width="300" height="100"
   style="fill:rgb(255,255,0)" >
 <animate attributeName="x" attributeType="XML"
      begin="0s" dur="9s" fill="freeze" from="300" to="0" />
 <animate attributeName="y" attributeType="XML"
      begin="0s" dur="9s" fill="freeze" from="100" to="0" />
  <animate attributeName="width" attributeType="XML"
   begin="0s" dur="9s" fill="freeze" from="300" to="800" />
  <animate attributeName="height" attributeType="XML"
  begin="0s" dur="9s" fill="freeze" from="100" to="300" />
  </rect>
<!-- Set up a new user coordinate system so that
the text string's origin is at (0,0), allowing
 rotation and scale relative to the new origin -->
  <g transform="translate(100,100)" >
    <!-- The following illustrates the use of the 'set', 'animateMotion',
'animateColor' and 'animateTransform' elements. The 'text' element
 below starts off hidden (i.e., invisible). At 3 seconds, it:
   * becomes visible
   * continuously moves diagonally across the viewport
   * changes color from blue to dark red
   * rotates from -30 to zero degrees
   * scales by a factor of three. -->
<text id="TextElement" x="0" y="0"
  style="font-family:Verdana; font-size:35.27; visibility:hidden" >
  It's alive!
 <set attributeName="visibility" attributeType="CSS" to="visible"
begin="3s" dur="6s" fill="freeze" />

<animateMotion path="M 0 0 L 100 100"
 begin="3s" dur="6s" fill="freeze" />
 <animateColor attributeName="fill" attributeType="CSS"
 from="rgb(0,0,255)" to="rgb(128,0,0)"
 begin="3s" dur="6s" fill="freeze" />
 <animateTransform attributeName="transform" attributeType="XML"
 type="rotate" from="-30" to="0"

 begin="3s" dur="6s" fill="freeze" />
<animateTransform attributeName="transform" attributeType="XML"
 type="scale" from="1" to="3"
 begin="3s" dur="6s" fill="freeze" />
    </text>
  </g>
</svg>

Animations : example ( continued )

Other functionnalities

Other functionnalities ( continued )

Other functionnalities ( continued )

Language definition and use

Conclusion