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

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

A bunch of additional improvements available

by abenedik 31. January 2009 20:36

I have got some great test svg files and some very helpful user feedback. This lead to the following improvements in Ab2d.ReaderSvg:

  • 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 measuring of objects when AutoSize is true (now transformed elements are correctly measured).
  • Improved ellipse - before svg ellipse was converted into Path WPF element - now it is converted into Ellipse WPF element
  • Added reading elements inside svg link element (before the whole element was skipped). Linking is not supported, but its content is now rendered.
  • Added support for underline and line-through text decorations.
  • Improved processing of text and tspan svg elements.
  • Added help file.

The ViewerSvg has been also improved to support new AutoSize property. Now it also has an automatic error reporting - when an exception occurs in ViewerSvg or Ab2d.ReaderSvg, user can now submit error information to help resolve the problems.

The new automatic error reporting is now part of new Paste2Xaml as well.

To install the new version, download the installer from my Downloads page and simply install it over the previous version (no need to uninstall).

Tags: , , , , ,

ReaderSvg | ReaderWmf

Ab2d.ReaderSvg library improved

by abenedik 4. January 2009 20:34

Ab2d.ReaderSvg library has been improved.

The list of changes is not long. I needed some new functionality for importing text. The previous version has also some problems with importing rectangles. This is a list of changes for version 2.2:

  • Added support for FontWeight and Italic FontStyle.
  • Added support for Rotate in Tspan (for Text on Path).
  • Fixed fill and stroke brush for Rectangle element.
  • Removed RunWithDeveloperLicense Dialog (shown when commercial license is installed, but the application did not have an embedded license.licx file).

The new version is available on https://www.ab4d.com/ReaderSvg.aspx.

Tags: , , ,

ReaderSvg

New version of ViewerSvg and Ab2d.ReaderSvg available

by abenedik 12. December 2008 19:30

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

ViewerSvg

The new Ab2d.ReaderSvg library is now even better. The following is a list of new features and improvements:

  • Fixed resolving external references in svgz files.
  • Fixed positioning bitmap images.
  • Adjusted LinearGradientBrush to show correctly in WPF.
  • Added support for MappingMode in LinearGradientBrush.
  • Added reading elements inside switch element (before switch was skipped).
  • Improved evaluation mode.

ViewerSvg application has also been improved. Now it is using my ZoomPanel.

Most of the improvements are based on great user feedback. I am grateful for it. So if you find any file that is not read correctly you are most welcome to upload it on my Feedback page.

Unfortunately I did not have time to implement support for Geometry and its optimization as it is done in Ab2d.ReaderSvg. But this feature is very high on my priority list and will be surely implemented soon.

The new version is available from https://www.ab4d.com/ViewerSvg.aspx.

Tags: , , ,

ReaderSvg