SVG is short for Scalable Vector Graphics. It is a graphic format in which the shapes are specified in XML. The XML is then rendered by an SVG viewer. Today most web browser can display SVG just like they can display PNG, GIF, and JPG.
2. Agenda
● History of SVG
● Syntax and Anatomy of SVG files
● Basic Shapes, Paths and Text
● Integrating SVG with (X)HTML5
● Styling SVG with CSS
● SVG Animation
○ Declarative with SMIL
○ Imperative with JavaScript
● Generating SVG
○ From XML with XSLT
● How SVG contributes to Reactive Design
● Comparison of SVG with (X)HTML5 Canvas
3. ● Raster images are made up of a set grid of
dots called pixels where each pixel is
assigned a color value.
● Number of pixels is limited
● Resolution dependent.
● Raster image file types BMP, JPEG, PNG
Types of images: Raster
4.
5. ● In physics, vectors is a representation of
both a magnitude (or length) and a direction.
● In vector graphics, the shape is saved as
vector statements.
● Mathematical equations, rather than pixels
● Vector images file types drw, pct, svg
Types of images: Vectors
8. 1998 Macromedia and Microsoft introduce VML
1998 Adobe and SUN submit PGML to W3C
1998 W3C creates SVG Working Group
2001 SVG 1.0 becomes W3C REC
2003 SVG 1.1 becomes W3C REC including Tiny and
Basic profiles for Mobile SVG
2008 SVG Tiny 1.2 becomes W3C REC
2011 SVG 1.1 Second Edition
History of SVG
9. Explaining the name: SVG
“SVG stands for Scalable Vector Graphics, an XML
grammar for styleable [and scriptable] graphics,
usable as an XML namespace.”
10. Explaining the name: SVG
Scalable
Change size uniformly without loss in size. Possible
because graphics are defined as numbers i.e. scaling
involves multiplying or dividing numbers defining SVG
shape
Vector Graphics
Shapes to be displayed are stored as vectors or vector
like structures (as numbers, not as pixels)
11. Explaining the name: SVG
XML
Parsers widely available
Namespace
Mixing SVG with other XML languages like
XHTML, SMIL and MathML
Styleable (and scriptable)
Use CSS (and JavaScript)
12. Why SVG?
1. Scalable
2. Fast to load/ Small in size
3. Scriptable (or Interactive)
4. Animatable
5. Searchable
6. Support on Browsers and Mobile
13. Where to use SVG?
1. Two dimensional graphs
2. Column charts, Pie charts
3. Scalable icons and logos
4. Architecture and design diagrams
5. Road Maps
6. Simple games
14. Where not to use SVG?
Not ideal for bitmap graphics like photos,
movies etc.
15. Related Standards
● Extensible Markup Language (XML) 1.0
● Namespaces in XML
● XML Linking Language (XLink) (incl. XML Base)
● CSS
● XSLT
● Associating Style Sheets with XML documents
● DOM (Level 1 and much of Level 2)
● Synchronized Multimedia Integration Language (SMIL) 3.0
● HTML 4, XHTML 1.0 (and (X)HTML5)
● Unicode
● Accessibility
18. ● Elements must be complete
(Tags must always be closed)
● Elements must be nested
(Tags must be closed in reverse order)
● Only 5 predefined entities:
& & < < > >
' ' " "
XML Basics for SVG
19. SVG Namespace and Identifiers
Namespaces:
SVG: http://www.w3.org/2000/svg
XLink: http://www.w3.org/1999/xlink
Public Identifier for SVG 1.1:
PUBLIC "-//W3C//DTD SVG 1.1//EN"
System Identifier for the SVG 1.1 Recommendation:
http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd
Example Document Type Declaration:
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
20. Hello, World in SVG
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<text y="12pt">Hello, World!</text>
</svg>
Note: Document Type Declaration shown for completeness. Not needed. Not
recommended.
21. Structuring, Grouping and Referencing in
SVG
<g>,<use>, <defs> and <symbol> Elements
For structuring a document by using SVG elements that allow us to define,
group, and reference objects within the document. These elements make
reusing elements easy, while maintaining clean and readable code.
22. ● The group <g> element is used for logically grouping together sets of
related graphical elements.
<g/>
25. <defs/>
● The <defs> element is like a “template” that you want to reuse later at
multiple times throughout the document.
● <defs> allows to reuse:
○ single element
○ g (group of elements)
○ symbol
27. ● The <use> element lets you reuse existing elements, giving you a similar
functionality to the copy-paste functionality in a graphics editor.
<use/>
29. ● <symbol> elements combines the benefits of both the <defs> and the <g>
elements.
● Used to define symbols such as icons, for example, that are referenced
throughout the document.
● It accepts a viewBox attribute which allows it to scale-to-fit inside any
viewport it is rendered in.
<symbol/>
34. Unit Description
em Default font size - usually the height of a character.
ex The height of the character x
px Pixels
pt Points (1 / 72 of an inch)
pc Picas (1 / 6 of an inch)
cm Centimeters
mm Millimeters
in Inches
Coordinate System Units
38. ● Synchronized Multimedia Integration
Language (SMIL)
● JavaScript
● CSS
Advantage to SMIL over JS animations is that JS
animations don't work when the SVG is embedded as an
img or used as a background-image in CSS. SMIL
animations do work in both cases
SVG Animation
48. ● A stand-alone SVG Web page
● Embedding by reference
(X)HTML: <img/> element
● Embedding inline (namespaces)
● External link
(X)HTML: <a/> element
● Referenced from CSS or XSL
Options for using SVG on the Web
49. A stand-alone SVG Web page
<svg xmlns="http://www.w3.org/2000/svg">
<text y="50pt">Hello, World!</text>
</svg>
55. ● Using presentation attribute
● Using css properties
● <style> tag inside <svg>
● Embedded stylesheet
● External Stylesheet
How SVGs can be styled in CSS
69. SVG
● Vector based (composed of
shapes)
● Resolution independent.
● Multiple graphical elements,
which become the part of the
DOM.
● Modified through script and CSS.
● SVG is not suited for game
applications.
● Better scalability — can be
printed with high quality at any
resolution
Canvas
● Raster based (composed of
pixel)
● Resolution dependent.
● Single HTML element similar to
<img> in behavior.
● Modified through script only.
● Canvas is suited for
graphic-intensive games.
● Poor scalability — not suitable
for printing on higher resolution