TrueTransform added to ReaderSvg and ReaderWmf

by abenedik 21. June 2013 10:16

For quite some time it was possible to transform the read objects in ViewerSvg and Paste2Xaml. I am not talking about simply adding a transformation to read objects but to actually change all coordinates, sizes and other values with the specified transformation.

For example after reading a svg file we get the following xaml (some common properties were removed to simplify the xaml):

<Canvas Width="422.425" Height="208.895">
    <TextBlock Text="text1" FontSize="10" Canvas.Left="68.571" Canvas.Top="103.145"/>
    <Path Stroke="Black" StrokeThickness="3" StrokeMiterLimit="2" 
          Data="M366.43,67.029C358.951,54.888 368.807,24.872 384.677,34.264 394.346,39.986 389.365,72.847 384.677,80.68 384.384,71.342 374.133,66.51 366.43,67.029z"/>

In Export dialog in ViewerSvg it was possible to transform this with specifying custom width (instead of 422.425) we could set the width to 100. After transformation the xaml is:

<Canvas Width="100" Height="49.5">
    <TextBlock Text="text1" FontSize="2.368" Canvas.Left="16.233" Canvas.Top="24.441"/>
    <Path Stroke="Black" StrokeThickness="0.711" StrokeMiterLimit="2" 
          Data="M86.744,15.883C84.974,13.006 87.307,5.894 91.064,8.119 93.353,9.475 92.174,17.262 91.064,19.118 90.995,16.905 88.568,15.76 86.744,15.883z"/>

As seen from xaml, the transformation changed the FontSize, position in canvas, StrokeThickness and also path data. ViewerSvg and Paste2Xaml used an internal TrueTransform class that performed the transformation.

This can be very useful in many cases:

  • When creating graphics for WPF, Silverlight or WinRT the graphics elements can be created in a drawing application and can have any possible dimension. But if your application needs graphics element that would have size 100 x 100, it is very convenient to transform the graphics into the required dimensions.
  • Some drawing applications (for example Inkscape) allow users to draw in real units (in mm), but when the drawing is saved into svg file, all the units are converted to pixels. With using TrueTransform it is possible to convert the coordinates and other data back to mm units.

Now this functionally is available in Ab2d.ReaderSvg and Ab2d.ReaderWmf libraries also. This means that you can now also use TrueTransform in your applications.

The simplest way to use TrueTransform is to use Transform or TransformFromPixelsToMM methods on ReaderSvg or ReaderWmf class. The Transform needs two parameters: the first one is a Transform object (can be ScaleTransform, TranslateTransform, TransformGroup, or any other Transform); the second is a Boolean that specifies if the LastReadViewbox (property of ReaderSvg and ReaderWmf) is also changed – if true this means that GetXaml method will return the xaml of the transformed objects. The TransformFromPixelsToMM method can be used to transform from pixel to real units.

It is not only possible to transform the objects that are read from svg or metafiles but also almost any other objects – this can be done with Ab2d.Common.ReaderSvg.TrueTransform (or Ab2d.Common.ReaderWmf.TrueTransform) class.

ReaderSvg also got a new property – SvgCreator. It is an enum that is set after reading svg file and specifies the application that was used to create svg file. Currently the following applications are recognized: Microsoft Visio, CorelDraw, Adobe Illustrator and Inkscape.


There is also a new sample that come with ReaderSvg that demonstrates the new transformations.

As always if you are new to our tools, you are most welcome to download a 60-day trial from the Download page. Existing customers can get the updated versions from their User Account page.

Tags: ,

ReaderSvg | ReaderWmf