by Andrew Watt
In this chapter
Vector Graphics Overview
Vector Graphics on the Web
The SVG Rendering Model
SVG Document Structure
SVG Basic Shapes
Paths in SVG
Text Handling in SVG
Gradients in SVG
Declarative SVG Animations
Scripting SVG
Linking in SVG
Additional Resources
Roadmap
Scalable Vector Graphics (SVG) is one of the most exciting of the new XML-based specifications to emerge from the W3C. Many of the other XML specifications can be pretty abstract at times, but SVG is very visual. As you improve your skills in how to create SVG, you will have the pleasure of easily seeing your increasing control of the technology right in front of your eyes.
SVG provides an XML-based vector graphics format that was intended by the World Wide Web Consortium (W3C) to replace many uses of bitmap graphics in Web pages. It can be used for many situations in which you might currently use GIFs, including animated GIFs. It can also be used to create complex animations that can compete with Macromedia Flash and add subtle transitions that Flash, being frame-based, is less suited to produce. In addition, SVG has enormous potential for the creation of maps and technical diagrams in which the ability to zoom in to and out of a map or diagram can be of enormous practical benefit.
A graphics format must be visual, so straightaway we will create a visual example—although we won't examine the syntax in detail at this point. Let's suppose that you want to create a graphics rollover using conventional technologies. You might use two bitmap graphics, perhaps produced in an expensive proprietary graphics editor, together with some JavaScript to create the rollover. Using SVG, you can create rollovers simply by declaring what you want to happen.
Listing 23.1 is a fairly straightforward piece of SVG that creates a rollover button. Don't worry about the detail of the code just now: We will discuss it later. The code describes an SVG button and its behavior in response to particular mouse events. When the button is unmoused, it contains a gradient that has a bright green top and bottom with a quiet pink center and dark blue text. When the graphic is moused, the gradient changes to a red center with pale green edges while at the same time the color of the text changes to white. Figures 23.1 and 23.2 show the appearance onscreen when the graphic is unmoused and moused.
To produce, without using SVG, a visual effect similar to that produced by Listing 23.1, you would typically have to use two bitmap graphics and a little straightforward JavaScript. In SVG, you simply describe the appearance of the button at rest, as it were, and also describe the animation that is to take place when the rectangle is moused. Assuming that you have the syntax correct, the rest is handled by the SVG rendering engine. SVG makes such animations delightfully simple.
18.218.151.44