An Example of IntegrationAs an example of using .NET Open Source projects together, this example will demonstrate the creation of a very simplistic SVG to GDI+ converter. This will allow a user to draw shapes on the screen and save them as an SVG XML file. First, some terms need to be defined. SVGScalable Vector Graphics (SVG) is a W3C (http://www.w3c.org) standard for representing vector drawings in XML. Vector-based drawing applications are very popular because they are easy to use and can be much more scalable than raster-based graphics. Raster graphics are fixed size graphics that contains many pixel dots. Vector graphics, on the other had, contain vector coordinates that are used to create the graphic via Vector Mathematics. Because of this, scaling a vector graphic to a custom resolution is much simpler than scaling a similar raster graphic. Vector graphics are also smaller than rastor graphics because they store much less data. Adobe (http://www.adobe.com/svg) has probably the most popular SVG viewer that is a plug-in to Microsoft Internet Explorer. Listing 12.1. Simple SVG Document<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" ![]() <rect x="52" y="176" width="102" height="226" style="fill:rgb(51,153,51);stroke:rgb(0,0 ![]() <ellipse cx="106" cy="118" rx="86" ry="58" style="fill:rgb(51,0,204);stroke:rgb(0,0 ![]() <line x1="204" y1="86" x2="437" y2="151" style="fill:rgb(0,0,0);stroke:rgb(0,0 ![]() </svg> Even if you are unfamiliar with SVG or vector graphics in general, it is clear from the XML element names in Listing 12.1 that this graphical drawing contains a rectangle (rect), an ellipse, and a line. The coordinates are given in a standard x/y Cartesian plane. Also included are fill colors, line weights, and colors in the style attribute. You can see that SVG is complex enough to produce the most amazing graphics. The output in Adobe's SVG Viewer is shown in Figure 12-1. Figure 12-1. SVG Viewed in Internet Explorer.![]()
Therefore, in theory the SVG output of this example should be able to be imported from or exported to any of these programs. In the interest of making SVG cover all the bases of a complex vector-based drawing application, SVG can get very complicated. It would be great to have a simple, graphical drawing program something like the paint application shipped with Windows to create an SVG file. Unfortunately, many of these products and programs out there will display SVG code, but most of these programs do not support modifying the SVG. Apache's Batik (http:// http://xml.apache.org/batik) is a notable Open Source SVG project written in Java. Probably the best SVG editor was the JASC Webdraw product that is now discontinued. So this example is a proof of concept to illustrate the speed of integration of Open Source and create a simple program that could be expanded into a very useful application. System.Drawing and GDI+System.Drawing is a part of every CLI implementation discussed in Chapter 2, "Open Source and the .NET Platform." It is a nice standard for basic graphical functionality such as drawing two-dimensional shapes, printing, and imaging. More advanced functionality is found in the System.Drawing.Drawing2D namespace. This namespace is fully implemented in fewer of the CLI implementations. For instance, Mono (http://www.go-mono.com/class-status-System.Drawingl) reports the namespace as 76% done. It seems to be in the SSCLI, but it's unclear in the DOTGNU documentation. For Microsoft's CLR implementation, System.Drawing is mostly mapped to GDI+ functions.GDI+ is Microsoft's successor to the GDI (Graphics Device Interface) for drawing on the screen. GDI+ is inherent in Windows XP and 2003 Server. This provides printing and basic drawing for any graphical Windows device. |