Path optimization

May 24, 2011 at 4: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.



May 25, 2011 at 12:22 AM


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.

Best regards,

May 25, 2011 at 11:22 AM
Edited May 25, 2011 at 11:24 AM

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"
       inkscape:connector-curvature="0" />


I get this Xaml with OptimizePath=false:


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


And this with OptimizePath=true:


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


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


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



May 25, 2011 at 9: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

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

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. 

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

Best regards,