New version of Ab2d.ReaderSvg available

by abenedik 1. August 2011 10:19

I am happy to announce that the new version of Ab2d.ReaderSvg library is available.

The version adds improved support for svg use and embedded svg elements. Those two svg elements are now correctly placed and have the correct size.

The new version also provides two new properties that can be used to fix problems that are caused by the differences between WPF and svg.

The first new property is SwitchElementProcessingType. It specifies which children of the svg switch element will be imported and shown. The switch element in svg file defines children that are shown based on the conditions defined in switch element. Because it is not possible to process svg conditions in WPF, it is possible to choose how the children will be imported and which children will be shown. The possible values for SwitchElementProcessingType are:

  • Disabled - svg switch element will not be imported.
  • ShowFirstDiscardOthers - only the first switch child will be imported. Other children will not be imported.
  • ShowFirstHideOthers - all switch children will be imported. Only the first element will be shown. Other children will have their Visibility set to Hidden.
  • ShowFirstCollapseOthers (default) - all switch children will be imported. Only the first element will be shown. Other children will have their Visibility set to Collapsed.
  • ShowAll - all switch children will be imported and shown.

 

The second new property is OverrideMiterLimit. The property has been added because WPF renders miter limit line cab differently as they are defined in svg specifications. The miter lime cabs show sharp line edges. But when the two lines meet at low angle, the sharp edge could extend very far away from the line junction. Therefore the miter limit can limit the sharp edges. In WPF the miter limit is used to specify how far away the sharp edge is allowed to go. In svg, the miter limit defined at which angle the miter limit is converted into beveled edge. This difference can lead to some anomalies when importing svg files. In this case the OverrideMiterLimit can be used to override the miter limit specified in the svg file and use value 1 or 2 instead.

For more information about the differences please see forum thread about this.

For backwards compatibility by default the miter limit defined in svg file is used (OverrideMiterLimit = 0).

 

Both new properties can be also set in the new ViewerSvg (here the default OverrideMiterLimit is set to 2 - miter limit of 2 is used by default).

Tags: , , ,

ReaderSvg

New version of Ab2d.ReaderSvg and ViewerSvg

by abenedik 20. August 2010 17:55

The best svg reader for WPF and svg to xaml converter for WPF and Silverlight is now even better.

This release focuses mostly on making work with Ab2d.ReaderSvg easier. Now it is possible to get progress report when reading svg files (there are also two interesting samples about this). It is now easier to use GetXaml method when the read svg file has embedded images. Also the ResourceDictionaryWriter class (helper class to create ResourceDictionaries from svg files) is now greatly improved. With new protected fields and protected virtual methods it is now very customizable.

The reading engine also has some improvements. It fixes some of the special issues that were reported by error reporting in ViewerSvg. The number or error reports is now very low and this tells that the reading engine is already very good and can handle really most of svg files.

The problems with showing the exported xaml in Visual Studio 2010 designer for Silverlight are now gone. With the new version the GetXaml method sets Width and Height to Path element when it is called to create xaml for Silverlight. This is a workaround for a bug in Visual Studio - please vote for the bug on Microsoft Connect so it will be fixed as soon as possible.

The samples have also been updated. There are now a few more samples and they are now available for both Visual Studio 2008 and 2010.

The following is a list of all changes in Ab2d.ReaderSvg:

  • Added ProgressChanged event to ReaderSvg to get report progress when reading file.
  • Improved GetXaml method for Silverlight: Added workaround for displaying Paths in Silverlight in Visual Studio 2010 designer - set Width and Height to Path element.
  • 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 reading some svg files with embedded image that reported "Invalid length for a Base-64 char array." error (used custom base64 reader instead of .Net method to read the string).
  • 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).

 

 

As always the ViewerSvg application has also been improved.

As with Paste2Xaml the ViewerSvg can now also change the size of read elements to any custom size. This is not done with only adding a ScaleTransform to the root element (as in previous versions) but now the positions, sizes and other values are changed to fit into the new size.

The improvements in Ab2d.ReaderSvg are also reflected in ViewerSvg. There is now an option to read or skip reading hidden elements. The export dialog also has some new settings - see the following is a screenshot:

ViewerSvg export dialog

 

As usual the new version can be downloaded from User Account page (for commercial users) or from my Downloads page (for evaluation version).

Tags: , , ,

ReaderSvg

Improved performance of new version of ReaderSvg library

by abenedik 1. June 2010 15:33

The biggest improvement of the new version of ReaderSvg is improved performance.

To prepare the new version a lot of time was spent in a profiler. I used some very complex files from some common applications that can save drawings into svg file.

It was quickly clear that the most of the CPU cycles were spend to solve svg's style inheritance. A lot of the time was also used to resolve many possibilities to define styles in svg file (svg styles, css, attributes, ect.).

For example if we have a complex hierarchy, the root group element can define stroke thickness for the path element that is 10 children away. The process of getting the correct style declarations was before not optimal and is now much faster.

The SVG Specification allows some very complex stlye declararions that are very rarely used. The code that tries to support all the possibilities is much quite complex and takes significant time to execute. I have analyzed the svg files I have (really a lot of them - lots of them from users feedback) and found out that almost all of them are using only simple style declarations. So I have decided that by default only simple style declarations would be processed. But if needed the complex style processing can be used by setting the new OptimizeStyleProcessing property on ReaderSvg to false.

For example the following style declaration is by default not processed correctly (but magically it is read correctly with setting OptimizeStyleProcessing to false):

<defs>
   <style type="text/css"><![CDATA[
            .mummy circle, .mummy rect, .mummy polygon { fill: green}
            .mummy > .thischild { fill: red }
            .primus + .secundus { fill: red }
            .mummy circle:first-child { fill: red}
         ]]></style>
</defs>

 

Improved performance is not the only improvement. There is more:

  • 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).
  • Fixed measuring size - improved for bigger stroke thickness on some shapes (when AutoSize property on ReaderSvg is true - by default).
  • Fixed SvgViewbox and SvgDrawing controls - they do not throw exceptions when Source is not set but some other property like AutoSize is set.


As usual the existing customers can download the new version from their User Account page. Others can download a 60-days trial version from my Downloads page.

Tags: , , ,

ReaderSvg

Improved design time support for Visual Studio 2010 and Blend

by abenedik 23. April 2010 20:22

We are all very excited about the new Visual Studio 2010.

Among other great new features there is also a new visual designer for Silverlight projects. But the new designer still has some problems. One of them was reported by "ttiggemann" on my forum and is related to xaml created from svg file with ViewerSvg.

The problem is that RenderTransfrom that is written as attribute is not well formed for the designer.

For example the following line is reported as incorrect:

<Canvas RenderTransfrom="1.5 0 0 1.5 100 50">

Such xaml is compiled successfully and also runs correctly shown in the Silverlight application.

The workaround for the designer is to change the attribute into element:

<Canvas>
    <Canvas.RenderTransfrom>
        <MatrixTransform>1.5 0 0 1.5 100 50</MatrixTransform>
    </Canvas.RenderTransfrom>
</Canvas>

 

The same problems occur in Expression Blend.

 

To support this case the Ab2d.ReaderSvg library and the ViewerSvg applications have been changed.

In Ab2d.ReaderSvg library there are now additional properties in BaseXamlWriterSettings that can be passed to GetXaml method. The WriteTransformationsAsElement can be set to true to write RenderTransfroms as elements instead of attributes. This property is by default set to false for xaml for WPF and to true for Silverlight xaml.

The xaml is now furher optimized by converting the transformation that only translate the objects into Canvas.Left and Canvas.Top properties.

For example the following:

<Path RenderTransfrom="1 0 0 1 100 50" ...

is now by default changed into:

<Path Canvas.Left="100" Canvas.Top="50" ...

This behavior is controlled by new UseCanvasPositionForTranslateTransform property on BaseXamlWriterSettings class.

 

The new properties are also reflected in ViewerSvg. This is the screenshot of the new export dialog (new options are marked with red):

ViewerSvg export dialog

 

Besides new settings for displaying transformations, there are also two additional new settings.

Now it is possible to control if the default xaml namespace is added to the xaml (useful when exporting as Canvas, Viewbox, etc.)

Also by default the number of displayed decimals is now unlimited - because in most cases the xaml is compiled so the number of decimals in xaml does not affect the size of the final product.

 

Unfortunately the RenderTransform is not the only problem. The xaml with changed transformations is still not shown in the Visual Studio 2010 designer.

The reason for this is a bug in VS. It does not show Path elements that are children of a Canvas. Frown

For example the following xaml is not shown in the designer:

<Canvas Width="400" Height="300">
    <Path Fill="Red" Stroke="Black" StrokeThickness="2" Data="M10,10 L300,10 300,100 10,100z"/>
    <Path Stroke="Blue" StrokeThickness="2">
        <Path.Data>
            <LineGeometry StartPoint="10 10" EndPoint="100 100"/>
        </Path.Data>
    </Path>
</Canvas>

I have already submitted the problem to Microsoft Connect and it is already confirmed as a bug. Hopefully there will be a fix for it available soon. Please vote for the bug here and help programmers to decide what to fix first.

 

But the good news is that the new xaml export options fix the problems with the visual designer in Expression Blend.

 

Besides changes in generated xaml there are also two other improvement in the new ReaderSvg:

  • Added support for some svg files that define url references with "&quot;" - for example: style="stroke: url(&quot;#linearGradient4603&quot;)".
  • Added support for lengthAdjust attribute in text and tspan elements.

 

As usual the new version can be downloaded from User Account page (for commercial users) or from my Downloads page (for evaluation version).

Tags: , ,

ReaderSvg

New major update of ReaderSvg with additional support for Microsoft Visio released

by abenedik 29. March 2010 09:22

 

I am happy to announce that a new major update for Ab2d.ReaderSvg library has been released.

ViewerSvg, a svg to xaml converter for WPF and Silverlight, has also been improved.

ViewerSvg

The new version 4.0 brings many new features and improvements. The most important new features are support for svg marker element (adds support for arrows and other line start and end markers) and svg symbol element (adds support for embedded fonts and other symbols).

But I am the most excited about the additional support for svg files created in Microsoft Visio. One step for improved Visio support was the implementation of marker elements (for connection line arrows). Another change was that now the names of read objects can be get from svg id attribute (as in most svg files) or from svg title element (used by Visio). This means that the names of the objects that were defined in Microsoft Visio are preserved when the svg file is read.

But I did not stop there. I have also added support for layers defined in Visio and for reading custom properties and attached data.

Some time ago I have found a demonstration on how to connect data to Visio diagram. I was amazed with how easy is to do this and how good the results look like. The demonstration can be seen here: http://office.microsoft.com/en-us/visio/HA100518191033.aspx

The demonstration ends with the statement: "the possibilities are endless".

Now imagine that it is also possible to get the Visio diagram with embedded data and animate it, add mouse events to the diagram elements and make other modification of the diagram in a WPF or a Silverlight application.

This is very easy to do with ViewerSvg or Ab2d.ReaderSvg library.

With ViwerSvg it is possible to convert diagrams from svg file to xaml file. It also possible to export the embedded data into xml serialized DataTable. It is easy to use the xaml and the xml (DataTable) to create WPF or Silverlight applications.

With using Ab2d.ReaderSvg in WPF application it is possible to open the svg file directly in the application. The embedded data and the data about layers can be accessed from the application (note that layers data cannot be exported from ViewerSvg and therefore cannot be used in Silverlight applications).

The new version of ReaderSvg comes with new samples that demonstrate various uses of diagram data and layers. The following screenshots show one scenario:


Creating Network diagram in Microsoft Visio:

Network diagram in Visio


Network diagram opened in ViewerSvg with previewing the embedded data:

Network diagram in ViewerSvg


Network diagram svg file opened in WPF application with Ab2d.ReaderSvg:
Network diagram in WPF

 

To see more screenshots and complete list of features check out the new ViewerSvg and the Ab2d.ReaderSvg pages.

 

Here is a full list of changes in Ab2d.ReaderSvg v4.0:

  • Added support for "marker" svg element - add support for arrows and other line start and end markers
  • Added support for "symbol" svg element - this also adds support for embedded fonts inside svg file
  • Added support for "clipPath" - object clipping
  • Added support for "use" element
  • Added support for xml:space="preserve" attribute - preserves the space before and after the text
  • Added support for textLength attribute in text and tspan elements
  • Fixed reading Rect data written with ',' instead of ' ' (for example '0,0,1,1' works now)
  • The Name property on the read objects is now set (so it is not needed to use NamedObjects dictionary or GetObjectName method). Setting Name can be turned off wuth SetNameProperty no ReaderSvg.
  • Improved the algorithm to correct the names read from svg file (now the name is not changed to lower case any more and also all letters are allowed and not only letters from 'a' to 'z').
  • Added FallbackBrush property to SilverlightXamlWriterSettings so it is possible to control which brush is used instead of VisualBrush that is not supported in Silverlight
  • Added GetLayerNames and GetElementsForLayerName methods to read layer information from svg file defined in Microsoft Visio
  • 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


The following is a list of changes in ViewerSvg application:

  • Added support for showing custom properties defined in svg file
  • Improved selection of objects
  • Added Export image button - export selected element into bitmap image
  • Added batch convertion of svg files to XAML for Silverlight

 

The 60-day evaluation version can be downloaded from my Downloads page. (If you already have an evaluation version, please uninstall it before installing the new version)

The existing customers can get the new version from their Users Account page (note that the commercial version is now different from the evaluation version available from my Downloads page)

Tags: , ,

ReaderSvg

New version of Paste2Xaml application available

by abenedik 2. January 2010 16:38

A new version of Paste2Xaml application is available.

It fixes some problem with the previous version. It can be downloaded from my Downloads page.

 

Here is a short description of the application.

As its name suggests, it can be used to copy vector graphics from almost any 2D vector drawing application and simply paste it into Paset2Xaml. There it can be exported into XAML than be used for WPF and Silverlight. The application can be also used to open Windows Matafiles (wmf) or Enhanced Metafiles (emf) and convert them into XAML.

It is internally using Ab2d.ReaderWmf library that can be also used in your application to read metafiles at runtime.

 

The following example is showing the Paste2Xaml screenshot after the graph from Excel 2003 has been pasted into the application.

Paste2Xaml with Excel graph

Note:

For creating xaml from Excel graphs I recommend using Excel 2003. The Excel 2007 usually does not put the graph as vector data into the clipboard. Instead it renders the graph into bitmap and stores graph as image into the clipboard. This usually happens for 3D graphs or when special effects are used (shadows, etc.). Simple 2D graphs are pasted as vector elements. But for 3D graphs, Excel 2003 is recommended.

 

There is also a Silverlight tutorial on how to create animated graph from Excel - check it out here.

 

The following are screenshots of metafiles converted to xaml and show in IE (click on image to see it in full size):


Word art from Microsoft Word 2003

Formated cells from Microsoft Excel 2007
   

Calendar created in Microsoft Visio 2003

Database schema created in Microsoft Visio 2003
   

Meeting Room schema created in Microsoft Visio 2003

Electrical equipment schema created in Microsoft Visio 2003
   

Brainstorm diagram created in Microsoft Visio 2003

Sample from Microsoft Office free Clip Arts
   

Sample from Microsoft Office free Clip Arts

Sample from Microsoft Office free Clip Arts
   

Sample from Microsoft Office free Clip Arts

Sample from Microsoft Office free Clip Arts

Tags: , , ,

ReaderWmf

New version of Ab2d.ReaderSvg with support for svg patterns is available

by abenedik 19. June 2009 20:33

The biggest improvement of the new Ab2d.ReaderSvg is added support for svg patterns. This feature has been requested by many users because svg patterns are commonly used by svg file created with Microsoft Visio. Another big improvement is support for complex strokes and pens - now also LinearGradientBrush, RadialGradientBrush, VisualBrush are supported.

Here is the whole list of changes:

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

ViewerSvg screenshot

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