SvgNet
About our Logo...
DOWNLOADS
Source & Examples (v 0.92)
Previous Version (v 0.91)
Original Version (v0.9)
Help File
Feedback
LINKS
Svg and Ruby
Adobe's SVG control
Our Sponsors

SvgNet, open source SVG library for C#

Current version: 0.92 (updated September 2003)

SvgNet is an extensible set of C# classes designed to make processing and, in particular, building SVG documents easier in C#. It focuses on ease of use, so it contains many typecast operators, string parsers, and shortcut methods to make code that builds SVG as brief and readable as possible. An important part of SvgNet is the SVG-GDI bridge, a simple set of classes that take GDI calls and output corresponding SVG.

What's in SvgNet?
What's the status of SvgNet?
Where's the documentation for SvgNet?
How can I add to SvgNet?


What's in SvgNet?

SvgNet consists of the following parts:

Classes to represent SVG elements and SVG types

SvgNet contains a family of classes that represent SVG elements (e.g. ellipse or tspan) and SVG types (e.g. a transformation list, a style, or a path description). The SVG types are provided with operators to make constructing and modifying SVG documents easy. For example, to change some properties of a style you can do:
                            myEllipse.Style = new Style("fill:red");
                            myEllipse.Style.Set("opacity", 0.5);
                            myEllipse.Style += "stroke:black";
                        

Classes to read, write and copy SVG scenes

To get an SVG string from a tree of SVG elements you have created is as simple as this:
                            SvgElement myRootElement = SvgFactory.ReadSvgString(s);
                            s = myRootElement.WriteSvgString(); 
                        
XML output can use entities to reduce the size and increase the legibility of the document.

The SvgFactory class also contains methods to make a deep copy of any SVG node and its descendants. All SVG types and elements are cloneable.

The Svg-Gdi bridge

The SvgGdi bridge is a set of classes that use SvgNet to translate between SVG and GDI+. What this means is that any code that uses GDI+ to draw graphics can easily output SVG as well, simply by plugging in the SvgGraphics object. This object is exactly the same as a regular .NET Graphics object, but creates an SVG tree. Even things like hatched fills and line anchors are implemented. The irritatingly old-fashioned 'current transformation' system of GDI+ is implemented by creating nested SVG group elements, resulting in SVG output that's a bit cleaner than the corresponding GDI+ metafile in some ways.

SvgGdi is the main use for SvgNet, although other things (a collection of basic shapes, maybe charting tools) may be built on SvgNet in the future.
Back to top

What's the status of SvgNet?

Current version:

The latest version, 0.92 (September 2003) incorporates various fixes and features suggested by helpful SVG users:
  • New SvgScriptElement added. It contains a script wrapped in a CDATA section.
  • Writing out XML has been made faster.
  • Some small problems/typos fixed.
  • Version 0.92 comes with a Visual Studio 2003 project file, not a 2002 one. However, you can still use the source files perfectly well in any VS 2002 project.
The previous version was 0.91. Changes from 0.9 (the first released version) included:
  • Bitmap drawing is done by embedding a png in the SVG output. This is far faster than the original method.
  • It is possible to emit SVG that doesn't reference the SVG 1.1 DTD. This helps with a bug in the .NET runtime that misparses some DTDs.
  • Some files are renamed for consistency.
  • xlink attributes could not be written previously because the xlink namespace was not referenced in the document. This is fixed, although as with the DTD, XML output would be easier if something other than Microsoft's System.XML classes were being used.

Done:

Well, everything described above is done, everything you can read about in the documentation is done. In other words, SvgNet represents most Svg elements, reads and writes SVG, and can copy and compress SVG trees and styles. SvgGdi represents most GDI+ actions, but some of the implementations could stand to be improved.

Todo:

Short term:
  • An Ant build file so that we don't rely on Visual Studio project files?
  • Filters -- no filter nodes are implemented so filters have to be constructed attribute by attribute.
  • Text Flow/Wrap -- this is waiting for SVG 1.2
  • Animation -- there should be classes to represent animation nodes and probably some helpers to make animation easier
  • Complete SvgGdi -- SvgGdi could still have more things added to it, like support for non-rectangular clipping regions and custom line anchors. If someone did this it would be greatly appreciated.
Long term:
  • SvgTools -- a library of common SVG objects such as cylinders and stars that we intend to build on top of SvgNet. It's not done yet.
  • SvgChart -- a library of chart objects, built on top of SvgTools, to handle scales and draw charts. The eventual purpose of SvgNet is to support this.
  • Renderer -- it would not be hard to write a simple renderer for the basic shapes and styles in SVG. Anybody who wants to add a 'Draw' method to each SvgElement class is welcome to :)
Back to top

Where is the documentation for SvgNet?

The SvgNet class libraries are documented using NDoc. That documentation can be downloaded as a zipped-up complete .chm file. In addition to the documentation, SvgNet comes with two example projects:
  • SvgDocTest -- test application that reads and writes documents and constructs an SVG document. This application is both an example and test system.
  • SvgGdiTest -- application that draws various scenes with SVG and GDI+. It is both an example of SvgGdi use, and a test of how accurate SvgGdi's emulation of GDI+ is.
NB -- These two programs require the Adobe SVG control in order to display SVG, and won't build without it. In every other way, building SvgNet should be just a matter of clicking 'Build'. Back to top

How can I add to SvgNet?

SvgNet is an open-source project which has been developed by RiskCare Ltd. SvgNet is released under a BSD-like license -- i.e. you can do whatever you want with it, provided you credit the original authors.

Of course, it would be ideal if you folded whatever changes you care to make back into the project. If there's an enhancement you'd like to make, or that you'd like someone else to make, please mail us and tell us about it. For that matter, you can send complaints, idle speculation, and any other kind of feedback to the same address.

Back to top