The IntegrationSo Didgets provides the ability for a user to intuitively create a drawing on the screen and print it out. SVG# is very good at reading and writing SVG files. The two together make for a primitive SVG editor. Utilizing the SVG# project as the SVG engine for the Didgets project required some code to transform SVG types into Didget types and back again. After exploring the possibility of using inheritance or interfaces, the simplest approach seemed to be putting a thin layer in between the two projects. This would allow for both projects to progress with minimal effect on either project. SVGDidgets in Listing 12.2 is part of the simple class to convert the SVG Objects. Listing 12.2. SVGDidgets C# Codeforeach(XmlNode node in svgnodes) { if(node.NamespaceURI == SvgDocument.SvgNamespace) { SvgElement svgnode = (SvgElement)svgdocument.RootElement.ChildNodes[nodes]; switch(svgnode.ToString()) { case "SharpVectors.Dom.Svg.SvgEllipseElement": EllipseShape ellipse = new EllipseShape(); ellipse.Size = new Size((int)((SvgEllipseElement)svgnode).Rx.AnimVal ![]() ellipse.Location = new Point((int)((SvgEllipseElement)svgnode).Cx ![]() ![]() ![]() d.Widgets.Add(ellipse); rotate((SvgElement)svgnode, ellipse); break; ....... case "SharpVectors.Dom.Svg.SvgTextElement": Text text = new Text(); text.TextProperties.Text = ((SvgTextElement)svgnode).InnerText; text.Location = new Point((int)((SvgTextElement)svgnode).X.AnimVal ![]() d.Widgets.Add(text); rotate((SvgElement)svgnode, text); break; ....... case "SharpVectors.Dom.Svg.SvgLineElement": PlazaConsulting.Didgets.Primitives.Line line = new PlazaConsulting ![]() line.StartPoint = new Point((int)((SvgLineElement)svgnode).X1.AnimVal ![]() line.EndPoint = new Point((int)((SvgLineElement)svgnode).X2.AnimVal ![]() d.Widgets.Add(line); rotate((SvgElement)svgnode, line); break; } } nodes++; } Figure 12.3 to be saved into a file output that is Listing 12.1 and be viewed in Internet Explorer as in Figure 12.1.Reading in the SVG Document into a Didgets workspace is a little harder. This is because many SVG editors punt and just save everything as an SVG path type, which is not as clean as most SVG developers like. This means that everything (even a rectangle) is saved as a group of polylines instead of using the native SVG Rect. This path element will have to map to a polyline for now until Didgets is expanded and can support a better type or until the intelligence is added to detect a built-in shape from the path type, which will require some fairly good artificial intelligence. Where to Go from HereThere are obvious shortcomings in this example, but the point is that it took very little work to create a useful application, and we finished relatively quickly. Some improvements for the project could be:
In the "Popular Projects" section of this chapter, I mentioned both Command Bar and the SharpZipLib. Command Bar empowers you to create Chapter 4's example of using Visual Studio.NET to edit a NAnt file with intellisense (Figure 4-7), it would be nice to let an advanced user switch from graphical drawing mode and rubber-band style stretching to pure text mode where he could easily create Listing 12.1's simple drawing with full intellisense. Then the user could switch back to the graphical view. This concept is also used in Visual Studio.NET for ASP.NET pages. You can use the design mode or the HTML view mode and theoretically switch back and forth. But that is not so easy to support, as Visual Studio.NET illustrates, because sometimes the graphical mode changes everything you did by hand in the HTML view mode. The good news is that Visual Studio.NET 2005 does not do this anymore, but this leads me to believe it is harder to support for Didgets than it appears on the surface. Licensing ConsiderationsIntegrating Open Source projects can be powerful, but you must be careful about licensing. Legal advice and exploration would be required when creating a project or product that includes multiple Open Source projects under different licenses. For instance, if one of the products is LGL and the other is BSD or Apache, the licensing issue can get a little messy. But normally this is easily worked out with the Open Source project's leadership. |