Click here to Skip to main content
Licence 
First Posted 8 Mar 2003
Views 189,997
Downloads 5,781
Bookmarked 58 times

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

By Ben Peterson | 8 Mar 2003
Svg.Net is a C# framework for creating SVG images. A GDI-SVG bridge is implemented on top of it.
1 vote, 4.3%
1

2
1 vote, 4.3%
3
7 votes, 30.4%
4
14 votes, 60.9%
5
4.62/5 - 23 votes
1 removed
μ 4.45, σa 1.65 [?]

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

Member
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
 


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAcessViolationException setting the SRC property PinmemberJames Darlington12:44 27 Oct '10  
GeneralPlease provide the sample code... to deal with the file having dynamic element entries.. using XmlAttributeCollection...using C# PinmemberNikkiee13:04 25 Jun '09  
Generalremove and insert the another attribute PinmemberNikkiee13:53 20 Jun '09  
GeneralStack Overflow on complex pages PinmemberFranz Fiala21:45 12 Apr '09  
GeneralIncompatible output, not standard svg Pinmembervaleriob2:24 24 Nov '08  
QuestionAnybody can put an example to read a SVG file with this library? PinmemberMarcosjgr8:47 12 Sep '08  
AnswerRe: Anybody can put an example to read a SVG file with this library? PinmemberNikkiee16:16 10 Jun '09  
GeneralRe: Anybody can put an example to read a SVG file with this library? PinmemberNikkiee16:19 10 Jun '09  
AnswerRe: Anybody can put an example to read a SVG file with this library? PinmemberMarcosjgr8:34 15 Jun '09  
GeneralRe: Anybody can put an example to read a SVG file with this library? PinmemberNikkiee13:47 20 Jun '09  
GeneralWarnings and Excepetions, please Help. PinmemberMarcosjgr16:30 8 Sep '08  
GeneralRe: Warnings and Excepetions, please Help. PinmemberMarcosjgr8:38 12 Sep '08  
QuestionSvgAElement Pinmemberaliov_851:04 7 Nov '07  
AnswerRe: SvgAElement Pinmemberaliov_856:44 19 Nov '07  
QuestionAsp.net 2.0 and SVGNet _VERY URGENT_PLEASE Pinmemberaliov_8523:23 16 Oct '07  
AnswerRe: Asp.net 2.0 and SVGNet _VERY URGENT_PLEASE Pinmemberaliov_856:39 19 Nov '07  
Generalerror in svgCtl.SRC = "c:\\temp\\foo.svg" PinmemberRazik23:37 3 Apr '07  
GeneralNew Home Page Location Pinmemberlogan133716:29 3 Mar '07  
GeneralRe: New Home Page Location Pinmemberalreadyused10:52 5 Aug '08  
that link's dead today, found the home page here:

[^]
but not a lot on it though...
GeneralGood Pinmembernorm .net2:10 28 Feb '07  
QuestionStill alive? PinmemberRazputin7:17 5 Feb '07  
AnswerRe: Still alive? PinmemberBen Peterson7:25 5 Feb '07  
GeneralRe: Still alive? Pinmemberapper1:55 28 Sep '08  
Generali don't know how to install the source file...:( Pinmemberhenin1:33 18 Oct '06  
QuestionASP.NET + SvgNet?? PinmemberMicke1233:41 16 Oct '06  

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.

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