Click here to Skip to main content
Click here to Skip to main content

An SVG framework in C# and an SVG-GDI+ bridge

By , 8 Mar 2003
Rate this:
Please Sign up or sign in to vote.
<!-- Add the rest of your HTML here -->

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Ben Peterson
Web Developer
United Kingdom United Kingdom
My interests are software engineering, Japanese, and talking about how good things used to be back in the good old days.
 
URL: http://www.jbrowse.com
Favorite Toy: http://www.ruby-lang.org
 

Comments and Discussions

 
QuestionProject homepage not accessible PinmemberPie and Ale6-Dec-13 1:27 
BugIncompatible with some locale Pinmemberlill.LEIF2-Jun-12 22:30 
GeneralAcessViolationException setting the SRC property PinmemberJames Darlington27-Oct-10 11:44 
GeneralPlease provide the sample code... to deal with the file having dynamic element entries.. using XmlAttributeCollection...using C# PinmemberNikkiee25-Jun-09 12:04 
Generalremove and insert the another attribute PinmemberNikkiee20-Jun-09 12:53 
GeneralStack Overflow on complex pages PinmemberFranz Fiala12-Apr-09 20:45 
GeneralIncompatible output, not standard svg Pinmembervaleriob24-Nov-08 1:24 
QuestionAnybody can put an example to read a SVG file with this library? PinmemberMarcosjgr12-Sep-08 7:47 
AnswerRe: Anybody can put an example to read a SVG file with this library? PinmemberNikkiee10-Jun-09 15:16 
GeneralRe: Anybody can put an example to read a SVG file with this library? PinmemberNikkiee10-Jun-09 15:19 
AnswerRe: Anybody can put an example to read a SVG file with this library? PinmemberMarcosjgr15-Jun-09 7:34 
GeneralRe: Anybody can put an example to read a SVG file with this library? PinmemberNikkiee20-Jun-09 12:47 
GeneralWarnings and Excepetions, please Help. PinmemberMarcosjgr8-Sep-08 15:30 
GeneralRe: Warnings and Excepetions, please Help. PinmemberMarcosjgr12-Sep-08 7:38 
QuestionSvgAElement Pinmemberaliov_857-Nov-07 0:04 
AnswerRe: SvgAElement Pinmemberaliov_8519-Nov-07 5:44 
QuestionAsp.net 2.0 and SVGNet _VERY URGENT_PLEASE Pinmemberaliov_8516-Oct-07 22:23 
AnswerRe: Asp.net 2.0 and SVGNet _VERY URGENT_PLEASE Pinmemberaliov_8519-Nov-07 5:39 
Generalerror in svgCtl.SRC = "c:\\temp\\foo.svg" PinmemberRazik3-Apr-07 22:37 
GeneralNew Home Page Location Pinmemberlogan13373-Mar-07 15:29 
GeneralRe: New Home Page Location Pinmemberalreadyused5-Aug-08 9:52 
GeneralGood Pinmembernorm .net28-Feb-07 1:10 
QuestionStill alive? PinmemberRazputin5-Feb-07 6:17 
AnswerRe: Still alive? PinmemberBen Peterson5-Feb-07 6:25 
GeneralRe: Still alive? Pinmemberapper28-Sep-08 0:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 9 Mar 2003
Article Copyright 2003 by Ben Peterson
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid