The long awaited Ab2d.ReaderSvg update is available

by abenedik 9. April 2009 18:20

I am really excited to announce that the long awaited new version of ReaderSvg has been released.

The new version 3.0 is full of great new features and improvements. The most important is the support for Drawing objects (objects that derive from Geometry class - DrawingGeometry, StreamGeometry, etc.)

Previous versions of Ab2d.ReaderSvg returned the read svg files as Shapes (Path, Polyline, Ellipse, etc.). This was great when you needed to manipulate separate objects or add some mouse events to objects. The flexibility of Shapes has its cost when complex objects are shown - the performance could be very poor and memory consumption very high. WPF provides a much more efficient way to show more complex images - by using Drawing objects instead of Shapes.

With the new Ab2d.ReaderSvg it is possible to read the objects as Shapes (with the Read method) or as Drawings (with the new ReadGeometry method). And what is more, it is also possible to further optimize the drawing by using resources for similar Pens and Brushes and by combining geometries together (with passing the GeometrySettings to ReadGeometry method).

To make the usage of read svg objects simpler, there is also a ResourceDictionaryWriter sample applications that can produce complex ResourceDictionaries from svg files with just a few mouse clicks. The following screenshot shows SVG ResourceDictionaryWriter application with three svg files added to the ResourceDictionary (xaml of ResourceDictionary can be seen on the right):

Svg ResourceDictionaryWriter screenshot

The support for Drawing objects is just one of the improvements of the new version. Another very big improvement is much better performance of ReaderSvg - now reading svg files is almost as fast as parsing xaml with XamlReader.

Here is the full list of changes:

  • Added Drawing objects support:
    new ReadGeometry method with support for advanced geometry optimization and use of resources (Burshes and Pens are defined in resources).
    new ResourceDictionaryWriter class and sample SampleResourceDictionary aplication to simplify creating resources from the svg files
  • Added SvgDrawing control to show svg file as geometries in xaml
  • Greatly improved performance on svg files where path elements have a lot of segments.
  • Added GetXaml method to get the xaml of the read objects (also used in ViewerSvg; it is much more accurate as System.Windows.Markup.XamlWriter.Save)
  • Added GetObjectName method - gets the name of the object. If object does not have a name defined returns null
  • Optimized the output xaml for Path element - now the properties with default values are no longer displayed. This in most cases removes the following properties: StrokeStartLineCap, StrokeEndLineCap, StrokeDashCap, StrokeLineJoin, StrokeMiterLimit, StrokeDashOffset
  • Added support for gradientTransform on radialGradient
  • Added support for known colors in xaml writter - known colors like Black, Yellow can now be written with its name instead of hex display (#FF000000). This feature is used by default but can be disabled with setting UseColorNames in XamlWriterSettings to false.
  • Fixed propagating text styles to child tspan elements (for example if text has underline decoration set, underline will be used also on the child tspan elements - if not overwritten by different text-decoraton)
  • The path is now automatically closed when the last segment ends on the same position as the start segment. Before if the paths were not manually closed, there could be some sharp edges on some parts of the path.
  • Improved setting the size of returned Viewbox.
    If AutoSize is false the returned Viewbox has the size that is defined in the svg file. The previous version did not set the size correctly.
    If the svg width and height are specified in cm, mm or inches the output size in xaml is set in cm.
  • Added AutoSize property to SvgViewbox and SvgDrawing
  • Added support for bitmap patterns - used as background textures
  • Added BitmapImages property that contains all the bitmaps read with ReaderSvg (also contains images embedded into the svg file)
  • Added ReadPathAsPathGeometry property - If false (default) the path is read as StreamGeometry (better performance). If true the path is read as PathGeometry (worse performance but path can be modified).

IMPORTANT NOTE:

Because of so many changes, it is possible that some of the applications that are using Ab2d.ReaderSvg need to be changed. Please consider the following two issues:

NamedObject dictionarty is changed from Dictionary<string, FrameworkElement> to Dictionary<string, object>. This change was added so the NamedObject property can be also used when svg file was read as Geometry. ReadGeometry method returns objects that are not derived from FrameworkElement. So the type change was needed. It would be also possible to define a new dictionary, but this would only postpone the change - in the future all the readers would implement the same interface and there will be room for only one named objects dictionary. This change could mean that the code that is using the NamedObject must be changed. If only the Read method is used (and not ReadGeometry), than the following code can be used:
FrameworkElement element = myReaderSvg.NamedObject["myObject"] as FrameworkElement;

Another change is that by default all paths are now read as StreamGeometry (before they were read as PathGeometry). This greatly improves the performance of reading svg file and drawing objects in WPF. But if your code expects the PathGeometry, the default behavior would throw a runtime exception. To avoid this, you can change your code to support StreamGeometry or set the new ReadPathAsPathGeometry property on ReaderSvg to true.

The ViewerSvg application has also been updated to support the new features of ReaderSvg. The following screenshot shows the new export dialog (notice the new geometries and new export images options):

ViewerSvg Export Dialog

The new version can be downloaded from my Downloads page.
After downloading just install the new version over the previous version (no need to uninstall).

Tags: , , ,

ReaderSvg