Click here to Skip to main content
Licence 
First Posted 8 Mar 2003
Views 198,401
Bookmarked 60 times

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

By | 8 Mar 2003 | Article
Svg.Net is a C# framework for creating SVG images. A GDI-SVG bridge is implemented on top of it.

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
BugIncompatible with some locale Pinmemberlill.LEIF22:30 2 Jun '12  
GeneralAcessViolationException setting the SRC property PinmemberJames Darlington11:44 27 Oct '10  
GeneralPlease provide the sample code... to deal with the file having dynamic element entries.. using XmlAttributeCollection...using C# PinmemberNikkiee12:04 25 Jun '09  
Generalremove and insert the another attribute PinmemberNikkiee12:53 20 Jun '09  
GeneralStack Overflow on complex pages PinmemberFranz Fiala20:45 12 Apr '09  
GeneralIncompatible output, not standard svg Pinmembervaleriob1:24 24 Nov '08  
QuestionAnybody can put an example to read a SVG file with this library? PinmemberMarcosjgr7:47 12 Sep '08  
AnswerRe: Anybody can put an example to read a SVG file with this library? PinmemberNikkiee15:16 10 Jun '09  
GeneralRe: Anybody can put an example to read a SVG file with this library? PinmemberNikkiee15:19 10 Jun '09  
AnswerRe: Anybody can put an example to read a SVG file with this library? PinmemberMarcosjgr7:34 15 Jun '09  
GeneralRe: Anybody can put an example to read a SVG file with this library? PinmemberNikkiee12:47 20 Jun '09  
GeneralWarnings and Excepetions, please Help. PinmemberMarcosjgr15:30 8 Sep '08  
Hi everybody.
I have Vista SP1 and VS 2008 in my pc. Of course, now I downloaded SVG Adobe too and SVG version 0.92.
 
I'm trying to compile this project but some errors occurs.
My firts question is about the windows, maybe this project does not run here and maybe does not run with VS 2008 too. So if it runs please tell me what I need to do.
Second.
About the errors:
First I Build the solution in VS2008 no errors happends but 708 warnings appears, here is one:
 
Warning	1	Missing XML comment for publicly visible type or member 'SvgNet.SvgElement._children'	C:\Users\M\Documents\Proyectos\svgnet_src092\SvgNet\SvgNet\SvgElement.cs	59	23	SvgNet
 
Second. I select SvgDocTest as startup project so when I run the project a exceptions happends:
((System.ComponentModel.ISupportInitialize)(this.svgOut)).EndInit()
 
Here is the part of the code that the project stop, and the exception:
 
COMException was unhandled
Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
 
If anybody know how to resolved, please post it Confused | :confused: .
 
Thanks Wink | ;) .
 
Marcos G.
GeneralRe: Warnings and Excepetions, please Help. PinmemberMarcosjgr7:38 12 Sep '08  
QuestionSvgAElement Pinmemberaliov_850:04 7 Nov '07  
AnswerRe: SvgAElement Pinmemberaliov_855:44 19 Nov '07  
QuestionAsp.net 2.0 and SVGNet _VERY URGENT_PLEASE Pinmemberaliov_8522:23 16 Oct '07  
AnswerRe: Asp.net 2.0 and SVGNet _VERY URGENT_PLEASE Pinmemberaliov_855:39 19 Nov '07  
Generalerror in svgCtl.SRC = "c:\\temp\\foo.svg" PinmemberRazik22:37 3 Apr '07  
GeneralNew Home Page Location Pinmemberlogan133715:29 3 Mar '07  
GeneralRe: New Home Page Location Pinmemberalreadyused9:52 5 Aug '08  
GeneralGood Pinmembernorm .net1:10 28 Feb '07  
QuestionStill alive? PinmemberRazputin6:17 5 Feb '07  
AnswerRe: Still alive? PinmemberBen Peterson6:25 5 Feb '07  
GeneralRe: Still alive? Pinmemberapper0:55 28 Sep '08  
Generali don't know how to install the source file...:( Pinmemberhenin0:33 18 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
Web04 | 2.5.120604.1 | Last Updated 9 Mar 2003
Article Copyright 2003 by Ben Peterson
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid