AB4D Forum

Full Version: TranslateTransform appearing on converted xaml text
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,

I use the ReadGeometry and GetXaml methods to obtain the xaml text of the svg images. I noticed the following text appearing in the xaml

<DrawingGroup>
<DrawingGroup.Transform>
  <TranslateTransform X="0" Y="0.000375187519239262" />
  </DrawingGroup.Transform>
<DrawingGroup>

I do not want to see these transformations in my xaml and I'm not sure how to remove them.

I do not see this in the xaml text when I use the ViewerSvg, export and choose get geometries. Please let me know how I could get rid of these transformations.

Thanks
All you need to do is to set AutoSize to false before reading svg file.
Hi,

When I set the AutoSize property to false, I get the following xaml inserted instead. I do not wish to see this as well. I would like my xaml to be the same as the one I see when exported and chose get geometries from ViewerSvg. Could you please help me to achieve that?

<GeometryDrawing>
- <GeometryDrawing.Pen>
<Pen Brush="#00FFFFFF" Thickness="0" />
</GeometryDrawing.Pen>
- <GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,32,32" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
The xaml that you posted is 100% valid.

I do not know what exactly would you like in xaml (in ViewerSvg there is a lot of different options - you did not mention which one you want) - do you like some other root element or some optimizations?
The xaml is valid. But not the same format as my older xaml which we are currently using. The one exported from the viewer is exactly what I am looking for. It would be better to achieve the same format if possible.

Unfortunately I'm not able to attach the screen shot of my viewer svg settings.

I'll try to list the settings below.

Exports as: WPF XAML
Root eleement: Image

Import Options: Get Geometries
Optimization: None
No advanced geometry settings is set
Export Text as: Path Geometry

save embedded images is disabled

Other Options (the following are the only options checked)
Add Default name spaces
Use advanced XamlWriter

Number of decimals is 12.123

None of the other options are modified. No prefix, suffix set. Offset X and Y are 0.0
For example, the xaml exported with the setting as per the previous post is as follows.

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Image Stretch="Uniform">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup>
<DrawingGroup>
<DrawingGroup>
<GeometryDrawing Brush="Black" Geometry="F1M15.996,0C7.162,0 0,7.176 0,16.007 0,24.842 7.162,32 15.996,32 24.832,32 32,24.842 32,16.007 32,7.176 24.832,0 15.996,0z M18.785,29.221L13.215,29.221 13.215,13.13 18.785,13.13 18.785,29.221z M16.002,9.277C14.207,9.277 12.754,7.822 12.754,6.028 12.754,4.226 14.207,2.779 16.002,2.779 17.791,2.779 19.246,4.226 19.246,6.028 19.246,7.822 17.791,9.277 16.002,9.277z"/>
</DrawingGroup>
</DrawingGroup>
</DrawingGroup>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</UserControl>



The xaml generated by using readersvg objects ReadGeometry and GetXaml methods is as follows.


<Image xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Stretch="Uniform">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup>
<DrawingGroup.Transform>
<TranslateTransform X="0" Y="0.000375187519239262"/>
</DrawingGroup.Transform>
<DrawingGroup>
<DrawingGroup>
<GeometryDrawing Brush="#FF000000" Geometry="F1M15.996,0C7.162,0 0,7.176 0,16.007 0,24.842 7.162,32 15.996,32 24.832,32 32,24.842 32,16.007 32,7.176 24.832,0 15.996,0z M18.785,29.221L13.215,29.221 13.215,13.13 18.785,13.13 18.785,29.221z M16.002,9.277C14.207,9.277 12.754,7.822 12.754,6.028 12.754,4.226 14.207,2.779 16.002,2.779 17.791,2.779 19.246,4.226 19.246,6.028 19.246,7.822 17.791,9.277 16.002,9.277z"/>
</DrawingGroup>
</DrawingGroup>
</DrawingGroup>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>

As I had mentioned the following is the difference.
<DrawingGroup.Transform>
<TranslateTransform X="0" Y="0.000375187519239262"/>
</DrawingGroup.Transform>

Also why is that so many DrawingGroup elements added which are empty?. The image looks fine but I am concerned about my xaml text.
I agree that having TranslateTransform with X and Y almost zero does not look nice. But it also does not hurt. As said before it is created when have AutoSize property set to true before reading svg file. For historical reasons in Ab2d.ReaderSvg this is set to true by default (so you need to manually set it to false). In ViewerSvg this is set to false by default (set in the main ViewerSvg window).

The reason that you have so many DrawingGroup is the structure of your svg file - you have many group ("g") elements there.

I will improve the code so in case the X and Y for TranslateTransform are almost zero or very small regarding the whole size, I will not display the TranslateTransform any more.
I understand that setting the AutoSize to false does not include that xaml but inserts the following.

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

Is there something else I need to modify to get the same output as in the viewerSvg export? I have posted my settings earlier.
Could you please post the content of the svg file that you want to convert. After that I will prepare a code snippet to generate the xaml.
The following the svg file's content I'm trying to convert.

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="32px"
height="32px" viewBox="0 0 32 32" enable-background="new 0 0 32 32" xml:space="preserve">
<g id="Indicators">
<g id="_x30_00_-_Properties">
<path d="M15.996,0C7.162,0,0,7.176,0,16.007C0,24.842,7.162,32,15.996,32C24.832,32,32,24.842,32,16.007
C32,7.176,24.832,0,15.996,0z M18.785,29.221h-5.57V13.13h5.57V29.221z M16.002,9.277c-1.795,0-3.248-1.455-3.248-3.249
c0-1.802,1.453-3.249,3.248-3.249c1.789,0,3.244,1.447,3.244,3.249C19.246,7.822,17.791,9.277,16.002,9.277z"/>
</g>
</g>
</svg>


I checked with more images. I still get the transformations with other images. Here is another svg content where it occurs.

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="32px"
height="32px" viewBox="0 0 32 32" enable-background="new 0 0 32 32" xml:space="preserve">
<g id="File">
<g id="_x30_00_-_Save">
<g>
<g>
<rect x="8.875" y="24.438" width="3.671" height="3.933"/>
<g>
<g>
<path d="M30.747,0H1.259C1.077,0,0.912,0.063,0.762,0.15C0.455,0.327,0.237,0.646,0.237,1.019V30.98
C0.237,31.536,0.7,32,1.259,32h29.488c0.555,0,1.016-0.464,1.016-1.02v-5.911V1.019C31.763,0.463,31.302,0,30.747,0z
M22.595,30.572H6.56v-8.456h16.035V30.572z M25.448,16.194H6.56V0.931h18.889V16.194z"/>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>
Pages: 1 2