TranslateTransform appearing on converted xaml text
#11
I understand now. The following code:

<GeometryDrawing>
- <GeometryDrawing.Pen>
<Pen Brush="#00FFFFFF" Thickness="0" />
</GeometryDrawing.Pen>
- <GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,32,32" />
</GeometryDrawing.Geometry>
</GeometryDrawing>

does ensure that the read geometry have the correct size. The size is specified in the svg root element: width="32px" height="32px"

With geometry objects it is not possible to specify size as with shapes (Canvas Width="32" Height="32"), therefore ReaderSvg adds a transparent rectangle with the specified size.


As I have guessed, the reason for many DrawingGroups is that your second svg file have many group ("g") elements.


You also mentioned that you had some hidden images (when posting the second svg content, you deleted that comment). There is a known issue in the current version of ReaderSvg where hidden elements influence the size measured when AutoSize is true. I am preparing a new version of ReaderSvg - this issue was be resolved with this version.
Andrej Benedik
#12
Is it not possible to ignore those width and height setting while converting to xaml? The exported xaml from viewer svg doesnt show the transforamtions.

It would be nice if I could get the exact same output xaml as the viewersvg.

Otherwise I'll have to write extra code to remove the transformations.
Also the svg images do not have any hidden image data. I was only using some samples but the actual ones have only the image content.
#13
Uh, now I finally understand the problem.

I see now that ViewerSvg can show different xaml because it can use some internal ways to get read object as geometry.

I will update ReaderSvg in such a way that it will be also possible to read svg file as geometry without getting the Transformation or additional RectangleGeometry to ensure correct size.

What is more, I will also add an option to optimize groups - so you will not get Canvases or DrawingGroup that contain only another Canvas or DrawingGroup.

pranav, when I will prepare the fix for that I will prepare a pre-release version for you.


Until than you can use the following workaround (it is not nice - it deletes the transformation before calling GetXaml method).

var readerSvg = new Ab2d.ReaderSvg();
readerSvg.AutoSize = true;
var readImage = readerSvg.ReadGeometry(svgFileName);

if (readImage != null)
{
try
{
((DrawingGroup) ((DrawingGroup) ((DrawingImage) readImage.Source).Drawing).Children[0]).Transform = null;
}
catch
{
// just in case
}
}

string xaml = readerSvg.GetXaml();
Andrej Benedik
#14
Thanks. That helped solve the problem.

When would you be releasing the next version?
#15
I am planning to release an official version in two or three weeks. I am preparing a new application that will help create vector assets from svg or metafiles.
Andrej Benedik
  


Forum Jump:


Users browsing this thread:
1 Guest(s)