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

SVGPad - Application and class library for editing SVG documents.

By , 6 Sep 2004
 

Introduction

This article presents the SVGPad application, a simple C# tool designed for editing SVG documents. The SVGPad is a very simple editor (it is not a WYSIWYG application) that can be useful for learning SVG syntax and for building simple SVG documents. It provides a complete control over the SVG document generated (and this is not always true if you use a graphic tool).

Background

The article assumes that you are familiar with basic concepts of Scalable Vector Graphics (SVG), an XML application that provides a language to describe two-dimensional graphics.

SVG specification is published by W3C and can be found here:

SVG graphics are based on three different types of objects: vector graphics, images, and text. Graphical objects can be grouped, styled, transformed, and animated. Animation is performed via scripting since a rich set of event handlers (such as onmouseover, onclick, …) can be assigned to any SVG object.

SVG has several benefits that make it the best choice for web applications that need 2D graphic support. Because it is a vector format the graphic files are smaller and they are resolution independent. In addition since graphics are stored in a text file labels and descriptions can be indexed by search engines.

SVGPad

How it works

The SVGPad UI is divided in two main panes.

The left pane contains a tree that represents the SVG document. The right pane contains a PropertyGrid displaying the property of the current selected object on the tree and a text box that shows the SVG representation of the selected object. The PropertyGrid shows only the attributes that are suitable for the element type selected.

The application functionality can be accessed using the toolbar of via the tree context menu.

Supported elements and attributes

The SVGPad does not cover all the SVG elements and attributes; in this first release it just implements the most common elements:

  • text
  • desc
  • group
  • rect
  • circle
  • ellipse
  • line
  • path
  • polygon
  • image

For each element a subset of SVG attributes is supported:

  • Core attributes
  • Paint/Color attributes
  • Style attributes
  • Opacity attributes
  • Graphic attributes

Other SVGPad functions

  • New, create a new empty SVG document.
  • Open, load an SVG document from a file.
  • Save, save the current document.
  • Preview, open the SVG file in the default web browser.
  • Copy, copy the selected SVG element.
  • Cut, cut the selected SVG element.
  • Paste, paste the element in the clipboard.
  • Delete, delete the selected SVG element.
  • Element up, move the selected element up (before its previous element)
  • Element down, move the selected element down (after its next element)
  • Level up, move the selected element up one level in a hierarchy

SVGLib

The SVGPad application is based on the SVGLib C# class library. The SVGLib provides a set of classes that represent the SVG document, the SVG elements and attributes. It can be used for creating and managing SVG documents.

The SVGLib classes have been documented using NDoc and the chm file is included in the attached binary file zip.

Using the SVGLib is very simple; first of all you need to create a document:

SvgDoc doc = new SvgDoc();
SvgRoot root = doc.CreateNewDocument();
root.Width = "500px";
root.Height = "500px";
        

Then you can start adding elements:

SvgRect rect = new SvgRect(doc, 
     "50px", 
     "25px", 
     "300px", 
     "200px",
     "3px", 
     Color.LightPink, 
     Color.Black);
doc.AddElement(root, rect);

rect.RX = "2px";
rect.RY = "2px";

SvgCircle circle1 = new SvgCircle(doc, 
     "350px", 
     "200px", 
     "50px");
doc.AddElement(root, circle1);

circle1.Fill = Color.DarkBlue;

SvgCircle circle2 = new SvgCircle(doc, 
     "50px", 
     "200px", 
     "50px");
doc.AddElement(root, circle2);

circle2.Fill = Color.DarkBlue;

Finally you can save the document.

doc.SaveToFile("c:\\temp\\sampledoc.svg");

Here the created file shown in a web browser.

History

  • 05-Sep-2004 R0.10, First release.

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

big71
Web Developer
Italy Italy
Member
No Biography provided

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5membermanoj kumar choubey20 Feb '12 - 19:31 
Nice
GeneralHow to update style attribute of a Path tag using This librarymemberEsonix22 May '11 - 23:55 
Hello Everyone,
 
I'm trying to update style attribute of Path tag of an SVG formatted USA map. using this Class Library.I've downloaded a SVG file from http://commons.wikimedia.org/wiki/File:USA_Counties_with_FIPS_and_names.svg and now working with it. Suppose we've the following path tag information:
 
"path id="HI_1_" style="fill:#FBE620" d="M 71.817000,164.70000 L 72.407000,163.61600 L 73.098000,163.51800 L 98.371000,178.00200 L 99.061000,177.70700 L 99.701000,176.76900 L 99.849000,176.47400 L 99.356000,175.93100 L 99.259000,175.29200 z"
 
I want to change the filling color of this style attribute.The changed one will be like
 
"path id="HI_1_" style="fill:#F0E020" d="M 71.817000,164.70000 L 72.407000,163.61600 L 73.098000,163.51800 L 98.371000,178.00200 L 99.061000,177.70700 L 99.701000,176.76900 L 99.849000,176.47400 L 99.356000,175.93100 L 99.259000,175.29200 z"
 
Can anyone help me to do that. Thanks in advance.
 
regards,
Esonix
QuestionHave you complete some 'unsupport' functions?memberYinBoChao26 Sep '09 - 17:10 
such as 'linearGradient','radialGradient'
and so on.
General'crop' vector imagememberabentov16 Mar '09 - 16:18 
hi,
 
i have a general question:
 
is it conceptually possible to 'crop' a vector/svg graphic/image?
 
I'll explain myself:
 
in adobe photoshop (i know it's bitmap based) one can select a rectangle within a larger image and then 'crop'/cut out just the smaller inner part.
 
in adobe flash in order to perform a similar task, one should resize just the 'stage' and all objects left outside will be invisible, thus 'croped'. or one should select all objects around the inner object/s and delete them.
 
can this be made with a svg file? if yes, does this .net library support this feature?
 
i hope i've made my question clear,
thanks in advance,
Albert
 
ps. i am ready to assist developing such a feature on an open source basis, let me know if interested
GeneralYou made a mistake in svglib! [modified]memberWan--Vevi23 Jul '08 - 22:16 
first its a cool application and very useable.
i use your svglib in an application.and i find a mistake in your svglib.
eg:there is a path in svg file,and the rull-file is "evenodd",but use your demo open it
the rullfill attributes is none.and i find the mistake in your svglib's svgelement.cs.
there is the code in origine file.
 
internal bool SetAttributeValue(string sName, string sValue)
		{
			bool bReturn = false;
 
			for (int i = 0; i < m_attributes.Count; i++ )
			{
				SvgAttribute attr = (SvgAttribute) m_attributes[i];
				if ( attr.Name == sName )
				{
					switch (attr.AttributeDataType)
					{
						case   SvgAttribute._SvgAttributeDataType.datatypeString:
						case SvgAttribute._SvgAttributeDataType.datatypeHRef:
							attr.Value = sValue;
							break;
 
						case SvgAttribute._SvgAttributeDataType.datatypeEnum:
							int nValue = 0;
							try
							{
                                                                   //there is a wrong !!!!!!!!!///
                                                                    nValue = Convert.ToInt32(sValue);
                                                                 }
							catch
							{
							}
the sValue is "evenodd",you can't turn it to int32.it rutern null forever if it's
SvgAttribute._SvgAttributeDataType.datatypeEnum type .
and i modify your code :
     try
            {
                    //ArrayList tempValueArray = attr.AttributeEnumValues;
                    for (int j = 0; j < attr.AttributeEnumValues.Count; j++)
                        {
                           if (sValue==attr.AttributeEnumValues[j].ToString().Trim())
                               {
                                        nValue = j + 1;
                                }
                              }
                         }
      catch { }
is there a better way for it?
please contact me ,and i have a lot of question with the svg to ask .
my e-mail is wwei466@sina.com
 
from vevi
modified on Thursday, July 24, 2008 10:49 PM

Question.net 2.0?memberJaime Olivares25 Nov '07 - 9:46 
Your idea looks great, but have you updated at least to .net 2.0?

GeneralLoading of Adobe Illustrator SVG file errormemberlieperik21 Jan '07 - 4:06 
Hi
 
First of all, a great article! I've a question:
 
We use Adobe Illustrator a lot and saved files to SVG format using Adobe Illustrator. However when we load the file into SVGPad we see a lot of errors and when saving the file, the file gets corrupt and can no longer be loaded correctly.
 
What is required to make SVGPad so that it can read Adobe Illustrator exported SVG files correct?

GeneralExporting the assemblymemberMr Delphi Developer12 Apr '06 - 4:38 
Can you create a DLL that can be used in other environments besides .NET?

GeneralWoomembervivaladan5 Mar '06 - 4:24 
Nice and simple assembly you have here. Easy to find on google ("SVG C#") and it will make my software engineering coursework alot easier. Thanks
Generalinstalling svgpadmemberforkinpm6 Feb '05 - 20:31 
Email: webmaster@codeproject.com
Date: 02.02.05
From: Patrick M. Forkin
Subject: Editor SVGPad
 
Hallo!
 
I am not a programmer but, I joined to be able to download the above editor.
 
I was in search of such an editor for my SVG work.
 
After unzipping, I am unable to get the programme to load
in either of the versions you offer. All I seem to be able to do is to open the help documentation.
I have incidentally tried with both of the file types
you have on offer.
 
Is there a bug in the zipped code, or is there something
I am missing which I should have done?
 
Please let me know since I really would like to be able to use the product.
 
Can anyone help me?
 
Regards, Patrick Forkin.

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 7 Sep 2004
Article Copyright 2004 by big71
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid