Ab2d.ReaderSvg is a class library that can be used to read svg and svgz (compressed
svg) files and import its elements into any WPF application.
The Ab2d.ReaderSvg can accurately read shapes defined in svg file, their strokes, fills and other properties.
It can read all types of gradients, patterns and markers (line starting and ending shapes).
This gives the designers free hands to define their drawings in almost any vector drawing application, save them into svg file and the application developers can than use the drawings in their WPF applications.
The elements in svg file can be converted into shapes or geometry objects.
The shapes (Canvas, Ellipse, Path, etc.) are great because they can be simply modified
and mouse events can be assigned to them. Geometry objects (GeometryDrawing, PathGeometry,
etc.) are a lightweight version of shapes that have much better performance and
lower memory usage but are harder to manipulate. Thereforeg graphics objects are
ideal for complex drawings. And what is more the read geometry can be furher optimized
for even better performance.
For example the following line of XAML is all that is needed to show birthday_cake.svg:
Note that Ab2d.ReaderSvg cannot be used in Silverlight applications - but can be
used in XBAP Web Browser application.
But it is possible to convert svg files into XAML for Silverlight and Windows Store (Windows RT) applications with the ViewerSvg
- Read svg and svgz (compresses svg) files.
- Preserve objects hierarchy.
- Get name of the objects from id attribute or from title element.
- Read embedded bitmap images.
- Read shapes with their properties.
- Read linear and radial gradients.
- Read patterns and convert them into VisualBrush.
- Read marker elements - line starting and ending shapes (arrows, etc.)
- Read use and symbol elements (also used for embedded fonts).
- Read clipPath elements.
- Read elements in svg file as Shapes or as Geometries (better performance).
- Optimize read Geometry for better performance.
- Optionally convert text into Path.
- Automatically resize the read elements.
- Get progress report when reading svg file.
- GetXaml method to get formatted and valid XAML of the read objects.
- Read custom properties and layers data from svg files created in Microsoft Visio.
- Included SvgViewbox and SvgDrawing controls that can be used in XAML.
- Optimize hierarchies of read objects with optimizing the groups or completely flattening the hierarchy.
- True transform transforms the shape data with changing the actual values instead of using RenderTransform or LayoutTransform.
Ab2d.ReaderSvg comes with many samples that shows many new possibilities that are opened with the library. There are WPF and Silverlight sample applications. The following screenshots show some of them:
The prefered way of storing cliparts in WPF is to use ResourceDictionaries. To simplify
creating ResourceDictionaries from svg files there is a ResourceDictionaryWriter
sample application. It is available with full source code, so it can be fully customized.
More about usage of ResourceDictionares can be found on the Microsoft's MSDN.
The following screenshot shows SVG ResourceDictionaryWriter application with three svg files
added to the ResourceDictionary (xaml of ResourceDictionary can be seen on the right):
Also check out the Links section for links to free online
svg libraries and svg editors.
Related Blog posts
To see the development history of Ab2d.ReaderSvg and ViewerSvg,
check out the related
Versions history information
To see the development history of Ab2d.ReaderSvg, check out: