分享

Simple SVG Editor

 goodwangLib 2012-01-09

SvgPaint is the simplest SVG editor. This application is a combination of two projects from The Code Project: DrawTools by Alex Fry and SVGPad by Maurizio Bigoloni. This application implements only trivial graphics elements from SVG format, no rendering, no transforming, etc.

Sample screenshot

How It Works

Sample screenshot

SvgLib reads and parses the Svg file and creates object SvgDoc with SvgElements.

Then, from SvgElements, create the DrawObjects, objects by DrawObject library.

After editing using the DrawTools library, the graphics objects may be saved in the edited Svg file.

I do not use serialization because it is used in the DrawTools project. I added to DrawObjects static methods that create an XML string with graphic elements in Svg format.

I also added a few graphics classes into used projects:

  • SvgPolyline into SvgPad
  • DrawText, DrawImage into DrawTools

Moreover, I added scaling capability and filling.

How to Transform Svg Elements to Draw Objects

After created SvgDoc, calling recursing method AddFromSvg() (beginning from root element), that, for all Svg elements, calls static method CreateDrawObject() of the DrawObject class:

public void AddFromSvg(SvgElement ele) 
{ 
	while (ele != null) 
	{ 
		DrawObject o = this.CreateDrawObject(ele); 
		if (o != null) 
			Add(o); 
		SvgElement child = ele.getChild(); 
		while (child != null) 
		{ 
			AddFromSvg(child); 
			child = child.getNext(); 
		} 
		ele = ele.getNext(); 
	} 
} 

The method CreateDrawObject() of basic class DrawObject has input parameter SvgElement and calls static method Create() of inherited draw objects that create themselves.

Then, the new draw objects add to GraphicsList object:

DrawObject CreateDrawObject(SvgElement svge) 
{ 
	DrawObject o = null; 
	switch (svge.getElementType()) 
	{ 
		case SvgElement._SvgElementType.typeLine: 
			o = DrawLine.Create((SvgLine )svge); 
			break; 
		case SvgElement._SvgElementType.typeRect: 
			o = DrawRectangle.Create((SvgRect )svge); 
			break; 
		case SvgElement._SvgElementType.typeEllipse: 
			o = DrawEllipse.Create((SvgEllipse )svge); 
			break; 
		case SvgElement._SvgElementType.typePolyline: 
			o = DrawPolygon.Create((SvgPolyline )svge); 
			break; 
		case SvgElement._SvgElementType.typeImage: 
			o = DrawImage.Create((SvgImage )svge); 
			break; 
		case SvgElement._SvgElementType.typeText: 
			o = DrawText.Create((SvgText )svge); 
			break; 
		case SvgElement._SvgElementType.typeGroup: 
			o = CreateGroup((SvgGroup )svge); 
			break; 
		default: 
		break; 
	} 
	return o; 
} 

Graphics Classes

Sample screenshot

For more details, see DrawTools and SVGPad projects on The Code Project site.

I thank Alex Fry and Maurizio Bigoloni for these interesting projects.

History

  • 18th September, 2007: I added print/preview and exported into JPG, GIF, PNG formats
  • 16th November, 2006: Initial version 

Contact Details

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多