SvgNet & SvgGdi
SvgNet is a C# library designed to facilitate the processing and particularly the creation of SVG documents in C#.
The project homepage is
here. Source on the homepage may be more recent than
The Code Project copy.
What it does
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.
Documentation
The SvgNet class libraries are documented in this help package. Additionally, there are two example applications bundled with SvgNet:
- 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.
The SvgNet Project
SvgNet is an Open Source project under a BSD-like license (license terms are reproduced in every SvgNet source file). SvgNet is copyright 2003 RiskCare Ltd.
The SvgNet project home page is
here.