Related products:

Latest version:

Supported environments:

Ab2d.ReaderSvg - svg and svgz importer

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:<ab2d:SvgViewbox Source="samples/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
converter.

Features:

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.

Samples

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:

ResourceDictionaryWriter

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.

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
blog posts.

Version history

New in version 6.2

Added support for using polygon as clip-path.

Improved transforming shapes and brushes.

Prevented applying opacity twice - to alpha value in color and to Opacity property on element.

Added support for "fill-opacity" and "stroke-opacity" attributes.

Fixed ResourceDictionaryWriter so that the ResolveResourceKeyCallback is called also for root keys.

Used black as default fill color (when fill is not specified).

Prevented stretching geometry under some circumstanes when svg file was read as geometry.

New in version 6.1

Changed reading transformation so that the type of transformation is preserved (rotate transform is read as RotateTransform and not as MatrixTransform as before). Added new property to ReaderSvg to control this behavior: ConvertTransformationsToMatrixTransform. You can set it to true for backward compatibility.

Changing the way names are set to objects when a new Canvas is created to host the object's transformation.
Now the object gets the original svg name. The created transformation Canvas gets the name that has "_transform" sufix.
This behaviour can be controlled by SetSvgNameToParentTransformCanvas and TransformCanvasNameFormatString properties - see help for this properties for more info.

New in version 5.6

Improved RenderToBitmap when rendering to custom size bitmaps and when AutoSize was set to false when reading svg file (the problem was that all objects were scaled to the border of the image).

Added SvgCreator property that specifies the application that was used to create svg file (it it can be determined - currently the supported applications are: Visio, CorelDraw, Adobe Illustrator, Inkscape).

Improved design time support for SvgDrawing control - now the svg file is shown in design time (before the image in design time was shown only in SvgViewbox).

Added SvgFileLoading and SvgFileLoaded events to SvgViewbox and SvgDrawing controls.

Prevented locking referenced image files.

New in version 4.5

Added OverrideMiterLimit property to ReaderSvg. With OverrideMiterLimit it is possible to override the used miter limit value and correct the problems that can be caused by the different rendering of miter limit in svg and WPF.

Added SwitchElementProcessingType property to ReaderSvg. It defines how switch children will be processed - possible values: Disabled, ShowFirstDiscardOthers, ShowFirstHideOthers, ShowFirstCollapseOthers or ShowAll.

Fixed positioning and sizing of use and embedded svg elements.

New in version 4.4

Markers (arrows and other line endings) are now correctly show on line and polyline elements (before they worked only on path elements).

markerWidth and markerHeight are correctly handled.

Removed obsolete Ab2d.SvgViewbox control - the control has been obsolete for a few versions - Ab2d.Controls.SvgViewbox should be used instead. This also removes the need for Designer assemblies to remove the obsolete control from Designer ToolBox.

New in version 4.3

Added ProgressChanged event to ReaderSvg to get report progress when reading file.

Improved GetXaml method - now the images are written to xaml without need to specify ResolveImagePath delegate. The uri format can be specified with the new DefaultImageUriFormatString property in XamlWritterSettings.

Improved reading linked images (not embedded into svg file). Before an exception was thrown when the image file could not be located - now the image object is created but its Source is not set.

Fixed problems with reading svg files from Microsoft Visio that have more than one layer with the same name defined.

Improved ResourceDictionaryWriter class to make it much more customizable. The AddFile and AddStream methods now work correctly. The usedSvgReader, geometrySettings and xamlWritterSettings fields are now protected so they can be changed in derived class. Also the methods CreateReaderSvg, CreateXamlWriterSettings, ReadSvgFile, ReadSvgStream, GetXaml, GetRootResourceKey and ResolveResourceKeyCallback are now protected and virtual so they can be overriden in derived class.

Added AddHiddenElements property that specifies if hidden elements are read. If the value of AddHiddenElements is true, than hidden elements are read and have their Visibility property set to Hidden or Collapsed (depends on using display or visibility attribute in svg file).

New in version 4.2

Improved performance - time to read some complex svg files is decreased by almost 300%.

Added OptimizeStyleProcessing property to ReaderSvg. By default its value is set to true to improved performace. But for some rarely used style declarations the optimized processing can produce wrong results - in those cases set the value to false.

Added support for text and tspan baseline-shift.

Now polyline and polygon are read as WPF's Polyline and Polygon elements (in previous version they were read as Path).

Added support to read embedded data from svg file created in Microsoft Visio - added the following methods: GetCustomProperties, GetObjectsWithCustomProperties, GetCustomPropertiesDataTable

Added NamedObjectsSource property to ReaderSvg to specify the source of the object names - for example for Microsoft Visio or other application that do not allow to set the svg's id attribute, the NamedObjectsSource can be set to NamedObjectsSourceType.Title or NamedObjectsSourceType.TitleIfExist.

Added NamedObjectsSource property to SvgViewbox and SvgDrawing

New in version 3.1

Added support for all types of svg patterns:
before only TexturePatterns were supported, now other types of patterns are supported as well. All patterns are now converted into VisualBrush.
NOTE: Silverlight does not support VisualBrush - Red brush is used instead.

Added support for complex Strokes and Pens - before Strokes and Pens can be only
SolidColorBrush. Now also other types of Brushes are supported (LinearGradientBrush,
RadialGradientBrush, VisualBrush, etc.).

Fixed using opacity on some svg elements.

Improved support for RadialGradient when gradientTransform was used.

Fixed getting the size of the root svg element when only width or only height is
specified (when AutoSize is false).

Fixed using Ab2d.ReaderSvg inside WinForms applications.

Fixed licensing problems when used on 64-bit OS.

New in version 3.0

Added Geometry 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

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.

Greatly improved performance on svg files where path elements have a lot of segments.

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 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).

New in version 2.3

Added AutoSize property. If its value is true (default - as previous version) the
size of returned Canvas is calculated from the size of objects it contains. This
is useful if you do not care whether the objects were drawn on the Letter or A4
page - you just need the returned object to be as big as its containg objects. If
AutoSize is false the size defined in svg element is used for the size of returned
Canvas. This is useful if you were working on a Letter page and would like to preserve
the positions of objects inside the Letter area.

Improved performance when reading text. Also now more fonts are rendered correctly.

Fixed reading embedded images (sometime the bounds of the TextureBrush) were not
read correctly.

New in version 1.6

Fixed reading number in exponent format (for example 1.234e-3) in transform element.
This fixed the problems when some elements in the read image were placed on the
wrong location and with the wrong size.

New in version 1.5

Added support for reading svgz (compresses svg) files.

Fixed reading some embedded images - sometimes "Invalid character in a Base-64 string."
exception was thrown.

New in version 1.4

Added SvgViewbox.

Fixed closing paths (some paths did not close correctly).

New in version 1.3

Fixed reading text for svg files created in Inkscape.

Added SvgBounds property (bounds of the elements in svg). Set InnerWidth and InnerHeight
as obsolete.

Improved read svg elements so they fit correctly into parent object. For example
before some svg files produced Viewboxes that exceeded (or were smaller) the size
of parent StackPanel. Now the Viewbox should fit into StackPanel.

Read FillRule to NonZero or EvenOdd.

Fixed some bugs that crashed the ReaderSvg.

New in version 1.2

In case text does not have any special stroke or fill set now a TextBlock is used
to render text. In previous version all text were converted to paths with made simple
texts very complex.

Added property UseSimpleText that forces the ReaderSvg to always use TextBlock to
render text.