This project has moved and is read-only. For the latest updates, please go here.

Path optimization

May 24, 2011 at 5:28 PM

What exactly does OptimizePath=true do?

I would expect it to create a light-weight StreamGeometry instead of a PathGeometry, but I always get PathGeometries when converting SVG to XAML.

Tobias

 

Coordinator
May 25, 2011 at 1:22 AM

Hello,

Yes, that is what it does. Also, the parser directly uses the SVG path markup syntax, without breaking it to line segments.
StreamGeometry is not directly created in XAML, if it uses the path markup syntax then it is StreamGeometry.

http://msdn.microsoft.com/en-us/library/ms752293.aspx

http://msdn.microsoft.com/en-us/library/ms742199.aspx

Best regards,
Paul. 

May 25, 2011 at 12:22 PM
Edited May 25, 2011 at 12:24 PM

For an SVG with:

 

<path  style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
       d="M 345.71429,260.93361 100,526.6479 l 477.14286,0 z"
       id="path2987"
       inkscape:connector-curvature="0" />

 

I get this Xaml with OptimizePath=false:

 

...
<GeometryDrawing.Geometry>
          <PathGeometry FillRule="Nonzero" Figures="M345.71429,260.93361L100,526.6479L577.14286,526.647888183594z" />
</GeometryDrawing.Geometry>
...

 

And this with OptimizePath=true:

 

...
<GeometryDrawing.Geometry>
          <PathGeometry FillRule="Nonzero" Figures="M345.71429,260.93361L100,526.6479 577.14286,526.6479z" />
</GeometryDrawing.Geometry>
...

 

The only difference is in the decimal places used in the path string.

Shouldn't OptimizePath=true make this become:

<Path Data="F0 M345.71429,260.93361L100,526.6479 577.14286,526.6479z" />

or

<StreamGeometry>F0 M345.71429,260.93361L100,526.6479 577.14286,526.6479z</StreamGeometry>

???

Tobias


Coordinator
May 25, 2011 at 10:45 PM

Hello Tobias,

>>The only difference is in the decimal places used in the path string.

Yes, because it is simply packed again by the renderer, the difference in decimal places is due to first creating LineSegment.

For instance for a triangle, we could have

<PathGeometry>
	<PathFigure IsClosed="True" StartPoint="10, 100">
		<LineSegment Point="100,100"/>
		<LineSegment Point="100,50"/>
	</PathFigure>
</PathGeometry>

Or, we could use the mini-language or markup syntax as

<PathGeometry Figures="M10,100 L100,100 L100,50Z"/>

If you set the OptimizePath=false, we could generate the first one if we want,
because the path is parsed into LineSegments. 

The second one will actually create the StreamGeometry, which is the lightweight
equivalent to PathGeometry, optimized for minimal use of memory. 

The <Path Data=""/> creates the Path object, which is a Shape, a higher level object, and that is
how it is used to create the StreamGeometry version of the path data. SharpVectors
currently creates only low level objects.

http://msdn.microsoft.com/en-us/library/system.windows.shapes.path.aspx 

In XAML if you use the mini-language or markup syntax, you are actually creating the
StreamGeometry and this cannot be edited. StreamGeometry is a memory representation
and is not defined directly in XAML. This is my understand of it - let me know if I am missing
something.

Best regards,
Paul.