SVG - Scalable Vector Graphic
This document has been established from the W3 SVG specification and Apache documentation
SVG is a specification of documents to describe scalable 2D graphics in XML.
It is compatible with XML 1.0.
It is mainly used to make graphical web pages and may replace flash or combined
with XUL.
SVG can replace Flash for creating graphics for the Web.
Some frameworks exists to build Web application in SVG.
Why use SVG?
Svg allows to put graphics inside a web page, or a desktop document that
can interacts with textual data. A SVG page may be built from a database,
it may be searched by a search engine. You can turn XML numeric data into
graphics by an XSL transformation.
A xvg page is scalable and interactive. You can display a city or a
building and allow a user to visit it by selecting locations.
Svg is a standard defined by the World Web Consortium and may be freely used
at production or end-user level without license to pay.
How to use SVG?
A SVG file is an XML document with graphical tags. It is viewed with a common
browser with a plug-in, or a special viewer.
Svg may be used:
- as a standalone web page.
- embedded with the include tags: img src, object, applet, iframe.
(I had tried the embed tag and this works on IE and Opera).
- linked with the link <a> tag.
- included by a CSS or XSL property or in XHTML.
Example:
<embed src="webmasting.svg" type="image/svg+xml"
width="200" height="100">
Main functions of SVG
- transformations
- colors, opacity, gradients, textures.
- fill: painting the content of a shape or text.
- stroke: painting the outline of a shape or text.
- clipping
- filter effects
- template of objects
- inserting symbols or images at coordinates.
- interactive, event handling
- dynamic
- scripting
- animation
File format
A SVG file must have the ".svg" extension under Unix, Windows.
A compressed, zipped SVG file must have the ".svgz" extension.
In the same manner you can save an image taken from a web page, you
can save SVG either as .svg or .svgz.
A SVG file has no doctype but an informative svg tag instead:
<svg version="1.1"
baseprofile="full"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ev="http://www.w3.org/2001/xml-events">
How to program SVG documents?
To build a SVG document you need for a canvas. Batik
provides a such Java canvas named "SVGCanvas2D" that convert your
drawing into SVG.
If you want visually build a SVG document, you need for a component that can
display SVG content and let the user interact with that content (insert object,
rotate, put text, etc...) "JSVGCanvas" is a Java component to do
that.
You need also to manipulate the SVG document from a scripting language with
a DOM API. DOM (Document Object Model) is an object oriented representation
of the document. Events may be assigned then to SVG elements.
All these modules are provided by Batik
for Java programmers.
Components of SVG
Data types
SVG document is made of:
- vector graphic shapes
- images
- texts
- containers of other elements
- styling properties.
Elements
- Canvas: a surface where to draw.- Viewport: a rectangular region in a canvas.
- Use: a template.
- Property: a parameter for how to render the document.
- Graphical shapes: rect, circle, ellipse, line, polyline, polygon.
- Image.
- Text
- Symbol: reusable object as flowchart, electronic symbols.
- Container, made of other elements:
- g: a container for grouping graphic elements, used as partial canvas.
- svg: a document.
- switch: a list of alternative elements with conditions for one selected.
- clipPath: masked elements.
- mask: use objects as mask.
- pattern: a texture.
- a: a link.
SVG and XML
XML may be translated into SVG with an XSL definition. This allows documents produced by application, statistics for example, to be turned directly into graphical view/It is compatible with HTML 4.0 and XHTML 1.0
The following XML extensions may be used on SVG documents:
- XLink: for referencing.
- XPointer: syntax for referencing element
- Stylesheet: styled either by CSS 2 or XSL.
- DOM: included in SVG and compatible with DOM 2 plus event handling.
- Incorporates and extends SMIL, the animation language.
Converting SVG to GIF, PNG, JPG or other raster image
Using Batik
This is easy, just export the image in the raster format. The result is not
perfect.
Make a screen shoot
1) set the screen to a resolution high enough to display the whole image.
2) use a capture tool such as IrfanView or XnView or a specialized tool as
MWSnap, and start capturing
in background task for the current window and client.
3) display the SVG file with a browser (the Adobe plug-in must be installed)
and press the capture key or click on the array to capture, depending on the
tool used.
4) save the capture, as a PNG file or Jpeg.
Simple demo: Tetris
View the source, in JavaScript and SVG. Requires Firefox 1.5
More informations
See also
- Canvas. Graphics on Canvas make use of SVG.
- SVG or Canvas? Which to choose...
Demonstrations
- Several demos.
- Examples using several editors or other programs.
- Adobe and SVG. Plug-in for your browser and examples.
References
- W3C. The official specification.
- The Mozilla project for SVG.
- SVG Basics.
Tools
- Batik. A set of modules to generate, display and convert SVG (Java).
- SVG Web. A plugin to add SVG support to any browser that lacks it, including Internet Explorer and Firefox.
- FOP. A java tool to convert SVG to PDF.
- Inkscape. Open source editor.
- Raphael. JavaScript library to build graphics.
- Dmoz. The SVG directory at Dmoz.