Code

Extensions. Tiny blur bug in XAML export (Bug #572965).
[inkscape.git] / share / extensions / svg2xaml.xsl
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 \r
3 <!--\r
4 Copyright (c) 2005-2007 authors:\r
5 Original version: Toine de Greef (a.degreef@chello.nl)\r
6 Modified (2010) by Nicolas Dufour (nicoduf@yahoo.fr) (blur support, units\r
7 convertion, comments, and some other fixes)\r
8 \r
9 Permission is hereby granted, free of charge, to any person obtaining a copy\r
10 of this software and associated documentation files (the "Software"), to deal\r
11 in the Software without restriction, including without limitation the rights\r
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
13 copies of the Software, and to permit persons to whom the Software is\r
14 furnished to do so, subject to the following conditions:\r
15 \r
16 The above copyright notice and this permission notice shall be included in\r
17 all copies or substantial portions of the Software.\r
18 \r
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
25 THE SOFTWARE.\r
26 -->\r
27 \r
28 <xsl:stylesheet version="1.0"\r
29 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
30 xmlns:xlink="http://www.w3.org/1999/xlink"\r
31 xmlns:xs="http://www.w3.org/2001/XMLSchema"\r
32 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\r
33 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\r
34 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
35 xmlns:exsl="http://exslt.org/common"\r
36 xmlns:libxslt="http://xmlsoft.org/XSLT/namespace"\r
37 exclude-result-prefixes="rdf xlink xs exsl libxslt">\r
38 \r
39 <xsl:strip-space elements="*" />\r
40 <xsl:output method="xml" encoding="UTF-8"/>\r
41 \r
42 <xsl:param name="silverlight_compatible" select="1" />\r
43 \r
44 <!-- Root template.\r
45 Everything starts here! -->\r
46 <xsl:template match="/">\r
47   <xsl:choose>\r
48     <xsl:when test="$silverlight_compatible = 1">\r
49       <xsl:apply-templates mode="forward" />\r
50     </xsl:when>\r
51     <xsl:otherwise>\r
52       <Viewbox Stretch="Uniform">\r
53         <xsl:apply-templates mode="forward" />\r
54       </Viewbox>\r
55     </xsl:otherwise>   \r
56   </xsl:choose>\r
57 </xsl:template>\r
58 \r
59 <!-- SVG and groups\r
60 (including layers) -->\r
61 <xsl:template mode="forward" match="*[name(.) = 'svg' or name(.) = 'g']">\r
62   <xsl:choose>\r
63     <xsl:when test="name(.) = 'svg' or @transform or @viewBox or @id or @clip-path or (@style and contains(@style, 'clip-path:url(#')) or (@width and not(contains(@width, '%'))) or @x or @y or (@height and not(contains(@height, '%'))) or *[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']">\r
64       <Canvas>\r
65         <xsl:apply-templates mode="id" select="." />\r
66         <!--\r
67         <xsl:apply-templates mode="clip" select="." />\r
68         -->\r
69         <xsl:if test="@style and contains(@style, 'display:none')"><xsl:attribute name="Visibility">Collapsed</xsl:attribute></xsl:if>\r
70         <xsl:if test="@style and contains(@style, 'opacity:')">\r
71         <xsl:attribute name="Opacity">\r
72             <xsl:choose>\r
73                 <xsl:when test="contains(substring-after(@style, 'opacity:'), ';')"><xsl:value-of select="substring-before(substring-after(@style, 'opacity:'), ';')" /></xsl:when>\r
74                   <xsl:otherwise><xsl:value-of select="substring-after(@style, 'opacity:')" /></xsl:otherwise>\r
75             </xsl:choose>\r
76         </xsl:attribute>\r
77         </xsl:if>\r
78         <xsl:if test="@width and not(contains(@width, '%'))">\r
79         <xsl:attribute name="Width">\r
80             <xsl:call-template name="convert_unit">\r
81                 <xsl:with-param name="convert_value" select="@width" />\r
82             </xsl:call-template>\r
83         </xsl:attribute></xsl:if>\r
84         <xsl:if test="@height and not(contains(@height, '%'))">\r
85         <xsl:attribute name="Height">\r
86             <xsl:call-template name="convert_unit">\r
87                 <xsl:with-param name="convert_value" select="@height" />\r
88             </xsl:call-template>\r
89         </xsl:attribute></xsl:if>\r
90         <xsl:if test="@x">\r
91         <xsl:attribute name="Canvas.Left">\r
92             <xsl:call-template name="convert_unit">\r
93                 <xsl:with-param name="convert_value" select="@x" />\r
94             </xsl:call-template>\r
95         </xsl:attribute></xsl:if>\r
96         <xsl:if test="@y">\r
97         <xsl:attribute name="Canvas.Top">\r
98             <xsl:call-template name="convert_unit">\r
99                 <xsl:with-param name="convert_value" select="@y" />\r
100             </xsl:call-template>\r
101         </xsl:attribute></xsl:if>\r
102         <xsl:if test="@viewBox">\r
103           <xsl:variable name="viewBox"><xsl:value-of select="normalize-space(translate(@viewBox, ',', ' '))" /></xsl:variable>\r
104           <xsl:attribute name="Width"><xsl:value-of select="substring-before(substring-after(substring-after($viewBox, ' '), ' '), ' ')" /></xsl:attribute>\r
105           <xsl:attribute name="Height"><xsl:value-of select="substring-after(substring-after(substring-after($viewBox, ' '), ' '), ' ')" /></xsl:attribute>\r
106           <Canvas.RenderTransform>\r
107             <TranslateTransform>\r
108               <xsl:attribute name="X"><xsl:value-of select="-number(substring-before($viewBox, ' '))" /></xsl:attribute>\r
109               <xsl:attribute name="Y"><xsl:value-of select="-number(substring-before(substring-after($viewBox, ' '), ' '))" /></xsl:attribute>\r
110             </TranslateTransform>\r
111           </Canvas.RenderTransform>\r
112         </xsl:if>\r
113     <xsl:if test="@transform">\r
114       <Canvas>\r
115         <Canvas.RenderTransform>\r
116           <TransformGroup><xsl:apply-templates mode="transform" select="." /></TransformGroup>\r
117         </Canvas.RenderTransform>\r
118         <xsl:apply-templates mode="forward" select="*" />\r
119       </Canvas>\r
120     </xsl:if>\r
121 \r
122         <xsl:if test="*[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']">\r
123           <Canvas.Resources>\r
124             <xsl:apply-templates mode="forward" select="*[name(.) = 'linearGradient' or name(.) = 'radialGradient' or name(.) = 'defs' or name(.) = 'clipPath']" />\r
125           </Canvas.Resources>\r
126         </xsl:if>\r
127         <xsl:if test="not(@transform)">\r
128           <xsl:apply-templates mode="forward" select="*[name(.) != 'linearGradient' and name(.) != 'radialGradient' and name(.) != 'defs' and name(.) != 'clipPath']" />\r
129         </xsl:if>  \r
130       </Canvas>\r
131     </xsl:when>\r
132     <xsl:when test="not(@transform)">\r
133       <xsl:apply-templates mode="forward" select="*" />\r
134     </xsl:when>\r
135   </xsl:choose>\r
136 </xsl:template>\r
137 \r
138 <!--\r
139 // Resources (defs) //\r
140 \r
141 * Resources ids\r
142 * Generic defs template\r
143 * Generic filters template\r
144 * Filter effects\r
145 * Linked filter effects\r
146 * Linear gradients\r
147 * Radial gradients\r
148 * Generic gradient stops\r
149 * Clipping\r
150 -->\r
151 \r
152 <!-- Resources ids -->\r
153 <xsl:template mode="resources" match="*">\r
154   <!-- should be in-depth -->\r
155   <xsl:if test="ancestor::*[name(.) = 'defs']"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>\r
156 </xsl:template>\r
157 \r
158 <!-- Generic defs template -->\r
159 <xsl:template mode="forward" match="defs">\r
160   <xsl:apply-templates mode="forward" />\r
161 </xsl:template>\r
162 \r
163 <!-- Generic filters template\r
164 Limited to one filter (can be improved) -->\r
165 <xsl:template mode="forward" match="*[name(.) = 'filter']">\r
166     <xsl:if test="count(*) = 1">\r
167       <xsl:apply-templates mode="forward" />\r
168     </xsl:if> \r
169 </xsl:template>\r
170 \r
171 <!-- Filter effects -->\r
172 <xsl:template mode="forward" match="*[name(.) = 'feGaussianBlur']">\r
173         <BlurEffect>\r
174             <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>\r
175             <xsl:if test="@stdDeviation"><xsl:attribute name="Radius"><xsl:value-of select="round(@stdDeviation * 3)" /></xsl:attribute></xsl:if>\r
176         </BlurEffect>  \r
177 </xsl:template>\r
178 \r
179 <!-- Linked filter effect -->\r
180 <xsl:template mode="filter_effect" match="*">\r
181 <xsl:choose>\r
182     <xsl:when test="@filter and starts-with(@filter, 'url(#')">\r
183         <xsl:attribute name="Effect">\r
184             <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@filter, 'url(#'), ')'), '}')" />\r
185         </xsl:attribute>\r
186     </xsl:when>\r
187     <xsl:when test="@style and contains(@style, 'filter:url(#')">\r
188         <xsl:attribute name="Effect">\r
189             <xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'filter:url(#'), ')'), '}')" />\r
190         </xsl:attribute>\r
191     </xsl:when>\r
192 </xsl:choose>\r
193 </xsl:template>\r
194 \r
195 <!-- Linear gradient -->\r
196 <xsl:template mode="forward" match="*[name(.) = 'linearGradient']">\r
197   <LinearGradientBrush>\r
198     <xsl:if test="@id"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>\r
199     <xsl:attribute name="MappingMode">\r
200       <xsl:choose>\r
201         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">Absolute</xsl:when>\r
202         <xsl:otherwise>RelativeToBoundingBox</xsl:otherwise>\r
203       </xsl:choose>\r
204     </xsl:attribute>\r
205     <xsl:if test="@spreadMethod">\r
206       <xsl:attribute name="SpreadMethod">\r
207         <xsl:choose>\r
208           <xsl:when test="@spreadMethod = 'pad'">Pad</xsl:when>\r
209           <xsl:when test="@spreadMethod = 'reflect'">Reflect</xsl:when>\r
210           <xsl:when test="@spreadMethod = 'repeat'">Repeat</xsl:when>\r
211         </xsl:choose>\r
212       </xsl:attribute>\r
213     </xsl:if>\r
214     <xsl:choose>\r
215       <xsl:when test="@x1 and @y1 and @x2 and @y2">\r
216         <xsl:choose>\r
217           <xsl:when test="contains(@x1, '%') and contains(@y1, '%')">\r
218             <xsl:attribute name="StartPoint"><xsl:value-of select="concat(substring-before(@x1, '%') div 100, ',', substring-before(@y1,'%') div 100)" /></xsl:attribute>\r
219           </xsl:when>\r
220           <xsl:otherwise>\r
221             <xsl:attribute name="StartPoint"><xsl:value-of select="concat(@x1, ',', @y1)" /></xsl:attribute>\r
222           </xsl:otherwise>\r
223         </xsl:choose>\r
224         <xsl:choose>\r
225           <xsl:when test="contains(@x2, '%') and contains(@y2, '%')">\r
226             <xsl:attribute name="EndPoint"><xsl:value-of select="concat(substring-before(@x2, '%') div 100, ',', substring-before(@y2,'%') div 100)" /></xsl:attribute>\r
227           </xsl:when>\r
228           <xsl:otherwise>\r
229             <xsl:attribute name="EndPoint"><xsl:value-of select="concat(@x2, ',', @y2)" /></xsl:attribute>\r
230           </xsl:otherwise>\r
231         </xsl:choose>  \r
232       </xsl:when>\r
233       <xsl:otherwise>\r
234         <xsl:attribute name="StartPoint"><xsl:value-of select="'0,0'" /></xsl:attribute>\r
235         <xsl:attribute name="EndPoint"><xsl:value-of select="'1,1'" /></xsl:attribute>\r
236       </xsl:otherwise>\r
237     </xsl:choose>\r
238     <LinearGradientBrush.GradientStops>\r
239       <GradientStopCollection>\r
240         <xsl:choose>\r
241           <xsl:when test="@xlink:href">\r
242             <xsl:variable name="reference_id" select="@xlink:href" />\r
243             <xsl:apply-templates mode="forward" select="//*[name(.) = 'linearGradient' and $reference_id = concat('#', @id)]/*" />\r
244           </xsl:when>\r
245           <xsl:otherwise><xsl:apply-templates mode="forward" /></xsl:otherwise>\r
246         </xsl:choose>\r
247       </GradientStopCollection>\r
248     </LinearGradientBrush.GradientStops>\r
249     <xsl:if test="@gradientTransform">\r
250     <LinearGradientBrush.Transform>\r
251       <xsl:apply-templates mode="transform" select="." />\r
252     </LinearGradientBrush.Transform>\r
253   </xsl:if>\r
254   </LinearGradientBrush>\r
255 </xsl:template>\r
256 \r
257 <!-- Radial gradient -->\r
258 <xsl:template mode="forward" match="*[name(.) = 'radialGradient']">\r
259   <RadialGradientBrush>\r
260     <xsl:if test="@id"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>\r
261     <xsl:attribute name="MappingMode">\r
262       <xsl:choose>\r
263         <xsl:when test="@gradientUnits = 'userSpaceOnUse' ">Absolute</xsl:when>\r
264         <xsl:otherwise>RelativeToBoundingBox</xsl:otherwise>\r
265       </xsl:choose>\r
266     </xsl:attribute>\r
267     <xsl:if test="@spreadMethod">\r
268       <xsl:attribute name="SpreadMethod">\r
269         <xsl:choose>\r
270           <xsl:when test="@spreadMethod = 'pad'">Pad</xsl:when>\r
271           <xsl:when test="@spreadMethod = 'reflect'">Reflect</xsl:when>\r
272           <xsl:when test="@spreadMethod = 'repeat'">Repeat</xsl:when>\r
273         </xsl:choose>\r
274       </xsl:attribute>\r
275     </xsl:if>\r
276     <xsl:if test="@cx and @cy">\r
277       <xsl:attribute name="Center">\r
278         <xsl:choose>\r
279           <xsl:when test="contains(@cx, '%') and contains(@cy, '%')">\r
280             <xsl:value-of select="concat(number(substring-before(@cx, '%')) div 100, ',', number(substring-before(@cy, '%')) div 100)" />\r
281           </xsl:when>\r
282           <xsl:otherwise>\r
283             <xsl:value-of select="concat(@cx, ',', @cy)" />\r
284           </xsl:otherwise>\r
285         </xsl:choose>\r
286       </xsl:attribute>\r
287     </xsl:if>  \r
288     <xsl:if test="@fx and @fy">\r
289       <xsl:attribute name="GradientOrigin">\r
290         <xsl:choose>\r
291           <xsl:when test="contains(@fx, '%') and contains(@fy, '%')">\r
292             <xsl:value-of select="concat(number(substring-before(@fx, '%')) div 100, ',', number(substring-before(@fy, '%')) div 100)" />\r
293           </xsl:when>\r
294           <xsl:otherwise>\r
295             <xsl:value-of select="concat(@fx, ',', @fy)" />\r
296           </xsl:otherwise>\r
297         </xsl:choose>\r
298       </xsl:attribute>\r
299     </xsl:if>\r
300     <xsl:if test="@r">\r
301       <xsl:choose>\r
302         <xsl:when test="contains(@r, '%')">\r
303           <xsl:attribute name="RadiusX"><xsl:value-of select="number(substring-before(@r, '%')) div 100" /></xsl:attribute>\r
304           <xsl:attribute name="RadiusY"><xsl:value-of select="number(substring-before(@r, '%')) div 100" /></xsl:attribute>\r
305         </xsl:when>\r
306         <xsl:otherwise>\r
307           <xsl:attribute name="RadiusX"><xsl:value-of select="@r" /></xsl:attribute>\r
308           <xsl:attribute name="RadiusY"><xsl:value-of select="@r" /></xsl:attribute>\r
309         </xsl:otherwise>\r
310       </xsl:choose>\r
311     </xsl:if>\r
312     <RadialGradientBrush.GradientStops>\r
313       <GradientStopCollection>\r
314         <xsl:choose>\r
315           <xsl:when test="@xlink:href">\r
316             <xsl:variable name="reference_id" select="@xlink:href" />\r
317             <xsl:apply-templates mode="forward" select="//*[name(.) = 'linearGradient' and $reference_id = concat('#', @id)]/*" />\r
318           </xsl:when>\r
319           <xsl:otherwise><xsl:apply-templates mode="forward" /></xsl:otherwise>\r
320         </xsl:choose>\r
321       </GradientStopCollection>\r
322     </RadialGradientBrush.GradientStops>\r
323     <xsl:if test="@gradientTransform">\r
324     <RadialGradientBrush.Transform>\r
325       <xsl:apply-templates mode="transform" select="." />\r
326     </RadialGradientBrush.Transform>\r
327     </xsl:if>\r
328   </RadialGradientBrush>\r
329 </xsl:template>\r
330 \r
331 <!-- Generic gradient stops -->\r
332 <xsl:template mode="forward" match="*[name(.) = 'stop']">\r
333   <GradientStop>\r
334     <!--xsl:apply-templates mode="stop_opacity" select="." /-->\r
335     <xsl:apply-templates mode="stop_color" select="." />\r
336     <xsl:apply-templates mode="offset" select="." />\r
337     <xsl:apply-templates mode="forward" />\r
338   </GradientStop>\r
339 </xsl:template>\r
340 \r
341 <!-- Clipping -->\r
342 <xsl:template mode="clip" match="*">\r
343   <xsl:choose>\r
344     <xsl:when test="@clip-path and defs/clipPath/path/@d"><xsl:attribute name="Clip"><xsl:value-of select="defs/clipPath/path/@d" /></xsl:attribute></xsl:when>\r
345     <xsl:when test="@clip-path and starts-with(@clip-path, 'url(#')"><xsl:attribute name="Clip"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@clip-path, 'url(#'), ')'), '}')" /></xsl:attribute></xsl:when>\r
346     <xsl:when test="@style and contains(@style, 'clip-path:url(#')"><xsl:attribute name="Clip"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" /></xsl:attribute></xsl:when>\r
347     <xsl:when test="clipPath"><xsl:apply-templates mode="forward" /></xsl:when>\r
348   </xsl:choose>\r
349 </xsl:template>\r
350 \r
351 <!--\r
352 // Misc templates //\r
353 \r
354 * Object description\r
355 * Id converter\r
356 * Decimal to hexadecimal converter\r
357 * Unit to pixel converter\r
358 * Title and description\r
359 * Misc ignored stuff (markers, patterns, styles)\r
360 * Symbols\r
361 * Use\r
362 * RDF and foreign objects\r
363 * Unknows tags\r
364 -->\r
365 \r
366 <!-- Object description -->\r
367 <xsl:template mode="desc" match="*">\r
368   <xsl:if test="*[name(.) = 'desc']/text()"><xsl:attribute name="Tag"><xsl:value-of select="*[name(.) = 'desc']/text()" /></xsl:attribute></xsl:if>\r
369 </xsl:template>\r
370 \r
371 <!-- Id converter. Removes "-" from the original id. -->\r
372 <xsl:template mode="id" match="*">\r
373 <xsl:if test="@id">\r
374   <xsl:attribute name="Name"><xsl:value-of select="translate(@id, '- ', '')" /></xsl:attribute>\r
375   <!--\r
376     <xsl:attribute name="x:Key"><xsl:value-of select="translate(@id, '- ', '')" /></xsl:attribute>\r
377   -->\r
378 </xsl:if>\r
379 </xsl:template>\r
380 \r
381 <!-- Decimal to hexadecimal converter -->\r
382 <xsl:template name="to_hex">\r
383   <xsl:param name="convert" />\r
384   <xsl:value-of select="concat(substring('0123456789ABCDEF', 1 + floor(round($convert) div 16), 1), substring('0123456789ABCDEF', 1 + round($convert) mod 16, 1))" />\r
385 </xsl:template>\r
386 \r
387 <!-- Unit to pixel converter\r
388 Values with units (except %) are converted to pixels and rounded.\r
389 Unknown units are kept. -->\r
390 <xsl:template name="convert_unit">\r
391   <xsl:param name="convert_value" />\r
392       <xsl:choose>\r
393         <xsl:when test="contains($convert_value, 'px')">\r
394             <xsl:value-of select="round(translate($convert_value, 'px', ''))" />\r
395         </xsl:when>\r
396         <xsl:when test="contains($convert_value, 'pt')">\r
397             <xsl:value-of select="round(translate($convert_value, 'pt', '') * 1.25)" />\r
398         </xsl:when>\r
399         <xsl:when test="contains($convert_value, 'pc')">\r
400             <xsl:value-of select="round(translate($convert_value, 'pc', '') * 15)" />\r
401         </xsl:when>\r
402         <xsl:when test="contains($convert_value, 'mm')">\r
403             <xsl:value-of select="round(translate($convert_value, 'mm', '') * 3.543307)" />\r
404         </xsl:when>\r
405         <xsl:when test="contains($convert_value, 'cm')">\r
406             <xsl:value-of select="round(translate($convert_value, 'cm', '') * 35.43307)" />\r
407         </xsl:when>\r
408         <xsl:when test="contains($convert_value, 'in')">\r
409             <xsl:value-of select="round(translate($convert_value, 'in', '') * 90)" />\r
410         </xsl:when>\r
411         <xsl:when test="contains($convert_value, 'ft')">\r
412             <xsl:value-of select="round(translate($convert_value, 'ft', '') * 1080)" />\r
413         </xsl:when>\r
414         <xsl:when test="not(string(number($convert_value))='NaN')">\r
415             <xsl:value-of select="round($convert_value)" />\r
416         </xsl:when>\r
417         <xsl:otherwise>\r
418             <xsl:value-of select="$convert_value" />\r
419         </xsl:otherwise>\r
420       </xsl:choose>\r
421 </xsl:template>\r
422 \r
423 <!-- Title and description\r
424 Blank template. Title is ignored and desc is converted to Tag in the mode="desc" template\r
425 -->\r
426 <xsl:template mode="forward" match="*[name(.) = 'title' or name(.) = 'desc']">\r
427   <!-- -->\r
428 </xsl:template>\r
429 \r
430 <!-- Misc ignored stuff (markers, patterns, styles) -->\r
431 <xsl:template mode="forward" match="*[name(.) = 'marker' or name(.) = 'pattern' or name(.) = 'style']">\r
432   <!-- -->\r
433 </xsl:template>\r
434 \r
435 <!-- Symbols -->\r
436 <xsl:template mode="forward" match="*[name(.) = 'symbol']">\r
437   <Style>\r
438     <xsl:if test="@id"><xsl:attribute name="x:Key"><xsl:value-of select="@id" /></xsl:attribute></xsl:if>\r
439     <Canvas>\r
440       <xsl:apply-templates mode="forward" />\r
441     </Canvas>\r
442   </Style>\r
443 </xsl:template>\r
444 \r
445 <!-- Use -->\r
446 <xsl:template mode="forward" match="*[name(.) = 'use']">\r
447   <Canvas>\r
448     <xsl:if test="@xlink:href"><xsl:attribute name="Style"><xsl:value-of select="@xlink:href" /></xsl:attribute></xsl:if>\r
449     <!--xsl:apply-templates mode="transform" select="." /-->\r
450     <xsl:apply-templates mode="forward" />\r
451   </Canvas>\r
452 </xsl:template>\r
453 \r
454 <!-- RDF and foreign objects -->\r
455 <xsl:template mode="forward" match="rdf:RDF | *[name(.) = 'foreignObject']">\r
456   <!-- -->\r
457 </xsl:template>\r
458 \r
459 <!-- Unknown tags -->\r
460 <xsl:template match="*">\r
461 <xsl:comment><xsl:value-of select="concat('Unknown tag: ', name(.))" /></xsl:comment>\r
462 </xsl:template>\r
463 \r
464 \r
465 <!--\r
466 // Colors and patterns //\r
467 \r
468 * Generic color template\r
469 * Fill\r
470 * Fill opacity\r
471 * Fill rule\r
472 * Generic fill template\r
473 * Stroke\r
474 * Stroke opacity\r
475 * Generic stroke template\r
476 * Stroke width\r
477 * Stroke mitterlimit\r
478 * Stroke dasharray\r
479 * Stroke dashoffset\r
480 * Linejoin SVG to XAML converter\r
481 * Stroke linejoin\r
482 * Linecap SVG to XAML converter\r
483 * Stroke linecap\r
484 * Gradient stop\r
485 * Gradient stop opacity\r
486 * Gradient stop offset\r
487 -->\r
488 \r
489 <!-- Generic color template -->\r
490 <xsl:template name="template_color">\r
491   <xsl:param name="colorspec" />\r
492   <xsl:param name="opacityspec" />\r
493   <xsl:choose>\r
494     <xsl:when test="starts-with($colorspec, 'rgb(') and not(contains($colorspec , '%'))">\r
495       <xsl:value-of select="'#'" />\r
496       <xsl:if test="$opacityspec != '' and number($opacityspec) != 1"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="round(number($opacityspec) * 255)" /></xsl:with-param></xsl:call-template></xsl:if>\r
497       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="substring-before(substring-after($colorspec, 'rgb('), ',')" /></xsl:with-param></xsl:call-template>\r
498       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), ',')" /></xsl:with-param></xsl:call-template>\r
499       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), ')')" /></xsl:with-param></xsl:call-template>\r
500     </xsl:when>\r
501     <xsl:when test="starts-with($colorspec, 'rgb(') and contains($colorspec , '%')">\r
502       <xsl:value-of select="'#'" />\r
503       <xsl:if test="$opacityspec != '' and number($opacityspec) != 1"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="round(number($opacityspec) * 255)" /></xsl:with-param></xsl:call-template></xsl:if>\r
504       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number(substring-before(substring-after($colorspec, 'rgb('), '%,')) * 255 div 100" /></xsl:with-param></xsl:call-template>\r
505       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number(substring-before(substring-after(substring-after($colorspec, 'rgb('), ','), '%,')) * 255 div 100" /></xsl:with-param></xsl:call-template>\r
506       <xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number(substring-before(substring-after(substring-after(substring-after($colorspec, 'rgb('), ','), ','), '%)')) * 255 div 100" /></xsl:with-param></xsl:call-template>\r
507     </xsl:when>\r
508     <xsl:when test="starts-with($colorspec, '#')">\r
509       <xsl:value-of select="'#'" />\r
510       <xsl:if test="$opacityspec != ''"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="round(number($opacityspec) * 255)" /></xsl:with-param></xsl:call-template></xsl:if>\r
511       <xsl:choose>\r
512         <xsl:when test="string-length(substring-after($colorspec, '#')) = 3">\r
513           <xsl:variable name="colorspec3"><xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" /></xsl:variable>\r
514           <xsl:value-of select="concat(substring($colorspec3, 1, 1), substring($colorspec3, 1, 1))" />\r
515           <xsl:value-of select="concat(substring($colorspec3, 2, 1), substring($colorspec3, 2, 1))" />\r
516           <xsl:value-of select="concat(substring($colorspec3, 3, 1), substring($colorspec3, 3, 1))" />\r
517         </xsl:when>\r
518         <xsl:otherwise><xsl:value-of select="translate(substring-after($colorspec, '#'), 'abcdefgh', 'ABCDEFGH')" /></xsl:otherwise>\r
519       </xsl:choose>\r
520     </xsl:when>\r
521     <xsl:otherwise>\r
522       <xsl:variable name="named_color_hex" select="document('colors.xml')/colors/color[@name = translate($colorspec, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]/@hex" />\r
523       <xsl:choose>\r
524         <xsl:when test="$named_color_hex and $named_color_hex != ''">\r
525           <xsl:value-of select="'#'" />\r
526           <xsl:if test="$opacityspec != '' and number($opacityspec) != 1"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number($opacityspec) * 255" /></xsl:with-param></xsl:call-template></xsl:if>\r
527           <xsl:value-of select="substring-after($named_color_hex, '#')" />\r
528         </xsl:when>\r
529         <xsl:otherwise><xsl:value-of select="$colorspec" /></xsl:otherwise>\r
530       </xsl:choose>\r
531     </xsl:otherwise>\r
532   </xsl:choose>\r
533 </xsl:template>\r
534 \r
535 <!-- Fill -->\r
536 <xsl:template mode="fill" match="*">\r
537   <xsl:choose>\r
538     <xsl:when test="@fill and starts-with(@fill, 'url(#')"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@fill, 'url(#'), ')'), '}')" /></xsl:when>\r
539     <xsl:when test="@fill"><xsl:value-of select="@fill" /></xsl:when>\r
540     <xsl:when test="@style and contains(@style, 'fill:') and starts-with(substring-after(@style, 'fill:'), 'url(#')"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" /></xsl:when>\r
541     <xsl:when test="@style and contains(@style, 'fill:')">\r
542       <xsl:variable name="Fill" select="substring-after(@style, 'fill:')" />\r
543       <xsl:choose>\r
544         <xsl:when test="contains($Fill, ';')">\r
545           <xsl:value-of select="substring-before($Fill, ';')" />\r
546         </xsl:when>\r
547         <xsl:otherwise><xsl:value-of select="$Fill" /></xsl:otherwise>\r
548       </xsl:choose>\r
549     </xsl:when>\r
550     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="fill" select="parent::*"/></xsl:when>\r
551   </xsl:choose>\r
552 </xsl:template>\r
553 \r
554 <!-- Fill opacity -->\r
555 <xsl:template mode="fill_opacity" match="*">\r
556   <xsl:choose>\r
557     <xsl:when test="@fill-opacity"><xsl:value-of select="@fill-opacity" /></xsl:when>\r
558     <xsl:when test="@style and contains(@style, 'fill-opacity:')">\r
559       <xsl:variable name="Opacity" select="substring-after(@style, 'fill-opacity:')" />\r
560       <xsl:choose>\r
561         <xsl:when test="contains($Opacity, ';')"><xsl:value-of select="substring-before($Opacity, ';')" /></xsl:when>\r
562         <xsl:otherwise><xsl:value-of select="$Opacity" /></xsl:otherwise>\r
563       </xsl:choose>\r
564     </xsl:when>\r
565     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="fill_opacity" select="parent::*" /></xsl:when>\r
566   </xsl:choose>\r
567 </xsl:template>\r
568 \r
569 <!-- Fill rule -->\r
570 <xsl:template mode="fill_rule" match="*">\r
571   <xsl:choose>\r
572     <xsl:when test="@fill-rule and (@fill-rule = 'nonzero' or @fill-rule = 'evenodd')"><xsl:attribute name="FillRule"><xsl:value-of select="@fill-rule" /></xsl:attribute></xsl:when>\r
573     <xsl:when test="@style and contains(@style, 'fill-rule:')">\r
574       <xsl:variable name="FillRule" select="substring-after(@style, 'fill-rule:')" />\r
575       <xsl:choose>\r
576         <xsl:when test="contains($FillRule, ';')">\r
577           <xsl:if test="substring-before($FillRule, ';') = 'nonzero' or substring-before($FillRule, ';') = 'evenodd'"><xsl:attribute name="FillRule"><xsl:value-of select="substring-before($FillRule, ';')" /></xsl:attribute></xsl:if>\r
578         </xsl:when>\r
579         <xsl:when test="$FillRule = 'nonzero' or $FillRule = 'evenodd'"><xsl:attribute name="FillRule"><xsl:value-of select="$FillRule" /></xsl:attribute></xsl:when>\r
580       </xsl:choose>\r
581     </xsl:when>\r
582     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="fill_rule" select="parent::*"/></xsl:when>\r
583     <xsl:otherwise><xsl:attribute name="FillRule">NonZero</xsl:attribute></xsl:otherwise>\r
584   </xsl:choose>\r
585 </xsl:template>\r
586 \r
587 <!-- Generic fill template -->\r
588 <xsl:template mode="template_fill" match="*">\r
589   <xsl:variable name="fill"><xsl:apply-templates mode="fill" select="." /></xsl:variable>\r
590   <xsl:variable name="fill_opacity"><xsl:apply-templates mode="fill_opacity" select="." /></xsl:variable>\r
591   <xsl:if test="not($fill = 'none')">\r
592     <xsl:attribute name="Fill">\r
593       <xsl:choose>\r
594         <xsl:when test="$fill != ''">\r
595           <xsl:call-template name="template_color">\r
596             <xsl:with-param name="colorspec">\r
597               <xsl:if test="$fill != 'none'"><xsl:value-of select="$fill" /></xsl:if>\r
598             </xsl:with-param>\r
599             <xsl:with-param name="opacityspec"><xsl:value-of select="$fill_opacity" /></xsl:with-param>\r
600           </xsl:call-template>\r
601         </xsl:when>\r
602         <xsl:otherwise>#000000</xsl:otherwise>\r
603       </xsl:choose>\r
604     </xsl:attribute>\r
605   </xsl:if>\r
606 </xsl:template>\r
607 \r
608 <!-- Stroke -->\r
609 <xsl:template mode="stroke" match="*">\r
610   <xsl:choose>\r
611     <xsl:when test="@stroke and starts-with(@stroke, 'url(#')"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@stroke, 'url(#'), ')'), '}')" /></xsl:when>\r
612     <xsl:when test="@stroke and @stroke != 'none'"><xsl:value-of select="@stroke" /></xsl:when>\r
613     <xsl:when test="@style and contains(@style, 'stroke:') and starts-with(substring-after(@style, 'stroke:'), 'url(#')"><xsl:value-of select="concat('{StaticResource ', substring-before(substring-after(@style, 'url(#'), ')'), '}')" /></xsl:when>\r
614     <xsl:when test="@style and contains(@style, 'stroke:')">\r
615       <xsl:variable name="Stroke" select="substring-after(@style, 'stroke:')" />\r
616       <xsl:choose>\r
617         <xsl:when test="contains($Stroke, ';')">\r
618           <xsl:if test="substring-before($Stroke, ';') != 'none'"><xsl:value-of select="substring-before($Stroke, ';')" /></xsl:if>\r
619         </xsl:when>\r
620         <xsl:when test="$Stroke != 'none'"><xsl:value-of select="$Stroke" /></xsl:when>\r
621       </xsl:choose>\r
622     </xsl:when>\r
623     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke" select="parent::*"/></xsl:when>\r
624   </xsl:choose>\r
625 </xsl:template>\r
626 \r
627 <!-- Stroke opacity -->\r
628 <xsl:template mode="stroke_opacity" match="*">\r
629   <xsl:choose>\r
630     <xsl:when test="@stroke-opacity"><xsl:value-of select="@stroke-opacity" /></xsl:when>\r
631     <xsl:when test="@style and contains(@style, 'stroke-opacity:')">\r
632       <xsl:variable name="Opacity" select="substring-after(@style, 'stroke-opacity:')" />\r
633       <xsl:choose>\r
634         <xsl:when test="contains($Opacity, ';')"><xsl:value-of select="substring-before($Opacity, ';')" /></xsl:when>\r
635         <xsl:otherwise><xsl:value-of select="$Opacity" /></xsl:otherwise>\r
636       </xsl:choose>\r
637     </xsl:when>\r
638     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_opacity" select="parent::*" /></xsl:when>\r
639   </xsl:choose>\r
640 </xsl:template>\r
641 \r
642 <!-- Generic stroke template -->\r
643 <xsl:template mode="template_stroke" match="*">\r
644   <xsl:variable name="stroke"><xsl:apply-templates mode="stroke" select="." /></xsl:variable>\r
645   <xsl:variable name="stroke_opacity"><xsl:apply-templates mode="stroke_opacity" select="." /></xsl:variable>\r
646   <xsl:if test="$stroke != ''">\r
647     <xsl:attribute name="Stroke">\r
648       <xsl:call-template name="template_color">\r
649         <xsl:with-param name="colorspec"><xsl:value-of select="$stroke" /></xsl:with-param>\r
650         <xsl:with-param name="opacityspec"><xsl:value-of select="$stroke_opacity" /></xsl:with-param>\r
651       </xsl:call-template>\r
652     </xsl:attribute>\r
653   </xsl:if>\r
654 </xsl:template>\r
655 \r
656 <!-- Stroke width -->\r
657 <xsl:template mode="stroke_width" match="*">\r
658   <xsl:choose>\r
659     <xsl:when test="@stroke-width">\r
660         <xsl:attribute name="StrokeThickness"><xsl:value-of select="@stroke-width" /></xsl:attribute>\r
661     </xsl:when>\r
662     <xsl:when test="@style and contains(@style, 'stroke-width:')">\r
663       <xsl:attribute name="StrokeThickness">\r
664           <xsl:call-template name="convert_unit">\r
665             <xsl:with-param name="convert_value">\r
666             <xsl:choose>\r
667               <xsl:when test="contains(substring-after(@style, 'stroke-width:'), ';')"><xsl:value-of select="substring-before(substring-after(@style, 'stroke-width:'), ';')" /></xsl:when>\r
668               <xsl:otherwise><xsl:value-of select="substring-after(@style, 'stroke-width:')" /></xsl:otherwise>\r
669             </xsl:choose>\r
670             </xsl:with-param>\r
671         </xsl:call-template> \r
672       </xsl:attribute>\r
673     </xsl:when>\r
674     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_width" select="parent::*"/></xsl:when>\r
675   </xsl:choose>\r
676 </xsl:template>\r
677 \r
678 <!-- Stroke miterlimit -->\r
679 <xsl:template mode="stroke_miterlimit" match="*">\r
680   <xsl:choose>\r
681     <xsl:when test="@stroke-miterlimit"><xsl:attribute name="StrokeMiterLimit"><xsl:value-of select="@stroke-miterlimit" /></xsl:attribute></xsl:when>\r
682     <xsl:when test="@style and contains(@style, 'stroke-miterlimit:')">\r
683       <xsl:variable name="StrokeMiterLimit" select="substring-after(@style, 'stroke-miterlimit:')" />\r
684       <xsl:attribute name="StrokeMiterLimit">\r
685         <xsl:choose>\r
686           <xsl:when test="contains($StrokeMiterLimit, ';')"><xsl:value-of select="substring-before($StrokeMiterLimit, ';')" /></xsl:when>\r
687           <xsl:otherwise><xsl:value-of select="$StrokeMiterLimit" /></xsl:otherwise>\r
688         </xsl:choose>\r
689       </xsl:attribute>\r
690     </xsl:when>\r
691     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_miterlimit" select="parent::*"/></xsl:when>\r
692   </xsl:choose>\r
693 </xsl:template>\r
694 \r
695 <!-- Stroke dasharray -->\r
696 <xsl:template mode="stroke_dasharray" match="*">\r
697   <!-- stroke-dasharray="10,30,20,30" becomes StrokeDashArray="1 3 2 3" ?? -->\r
698   <xsl:choose>\r
699     <xsl:when test="@stroke-dasharray and @stroke-dasharray != 'none'"><xsl:attribute name="StrokeDashArray"><xsl:value-of select="@stroke-dasharray" /></xsl:attribute></xsl:when>\r
700     <xsl:when test="@style and contains(@style, 'stroke-dasharray:')">\r
701       <xsl:variable name="StrokeDashArray" select="substring-after(@style, 'stroke-dasharray:')" />\r
702       <xsl:choose>\r
703         <xsl:when test="contains($StrokeDashArray, ';')">\r
704           <xsl:if test="substring-before($StrokeDashArray, ';') != 'none'"><xsl:attribute name="StrokeDashArray"><xsl:value-of select="substring-before($StrokeDashArray, ';')" /></xsl:attribute></xsl:if>\r
705         </xsl:when>\r
706         <xsl:when test="$StrokeDashArray != 'none'"><xsl:attribute name="StrokeDashArray"><xsl:value-of select="$StrokeDashArray" /></xsl:attribute></xsl:when>\r
707       </xsl:choose>\r
708     </xsl:when>\r
709     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_dasharray" select="parent::*"/></xsl:when>\r
710   </xsl:choose>\r
711 </xsl:template>\r
712 \r
713 <!-- Stroke dashoffset -->\r
714 <xsl:template mode="stroke_dashoffset" match="*">\r
715   <xsl:choose>\r
716     <xsl:when test="@stroke-dashoffset"><xsl:attribute name="StrokeDashOffset"><xsl:value-of select="@stroke-dashoffset" /></xsl:attribute></xsl:when>\r
717     <xsl:when test="@style and contains(@style, 'stroke-dashoffset:')">\r
718       <xsl:variable name="StrokeDashOffset" select="substring-after(@style, 'stroke-dashoffset:')" />\r
719       <xsl:attribute name="StrokeDashOffset">\r
720         <xsl:choose>\r
721           <xsl:when test="contains($StrokeDashOffset, ';')"><xsl:value-of select="substring-before($StrokeDashOffset, ';')" /></xsl:when>\r
722           <xsl:otherwise><xsl:value-of select="$StrokeDashOffset" /></xsl:otherwise>\r
723         </xsl:choose>\r
724       </xsl:attribute>\r
725     </xsl:when>\r
726     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_dashoffset" select="parent::*"/></xsl:when>\r
727   </xsl:choose>\r
728 </xsl:template>\r
729 \r
730 <!-- Linejoin SVG to XAML converter -->\r
731 <xsl:template name="linejoin_svg_to_xaml">\r
732   <xsl:param name="linejoin" />\r
733   <xsl:choose>\r
734     <xsl:when test="$linejoin = 'bevel'">Bevel</xsl:when>\r
735     <xsl:when test="$linejoin = 'round'">Round</xsl:when>\r
736     <xsl:otherwise>Miter</xsl:otherwise>\r
737   </xsl:choose>\r
738 </xsl:template>\r
739 \r
740 <!-- Stroke linejoin -->\r
741 <xsl:template mode="stroke_linejoin" match="*">\r
742   <xsl:choose>\r
743     <xsl:when test="@stroke-miterlimit">\r
744       <xsl:attribute name="StrokeLineJoin">\r
745         <xsl:call-template name="linejoin_svg_to_xaml"><xsl:with-param name="linejoin"><xsl:value-of select="@stroke-linejoin" /></xsl:with-param></xsl:call-template>\r
746       </xsl:attribute></xsl:when>\r
747     <xsl:when test="@style and contains(@style, 'stroke-linejoin:')">\r
748       <xsl:variable name="StrokeLineJoin" select="substring-after(@style, 'stroke-linejoin:')" />\r
749       <xsl:attribute name="StrokeLineJoin">\r
750         <xsl:choose>\r
751           <xsl:when test="contains($StrokeLineJoin, ';')">\r
752             <xsl:call-template name="linejoin_svg_to_xaml"><xsl:with-param name="linejoin"><xsl:value-of select="substring-before($StrokeLineJoin, ';')" /></xsl:with-param></xsl:call-template>\r
753           </xsl:when>\r
754           <xsl:otherwise>\r
755             <xsl:call-template name="linejoin_svg_to_xaml"><xsl:with-param name="linejoin"><xsl:value-of select="$StrokeLineJoin" /></xsl:with-param></xsl:call-template>\r
756           </xsl:otherwise>\r
757         </xsl:choose>\r
758       </xsl:attribute>\r
759     </xsl:when>\r
760     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_linejoin" select="parent::*"/></xsl:when>\r
761   </xsl:choose>\r
762 </xsl:template>\r
763 \r
764 <!-- Linecap SVG to XAML converter -->\r
765 <xsl:template name="linecap_svg_to_xaml">\r
766   <xsl:param name="linecap" />\r
767   <xsl:choose>\r
768     <xsl:when test="$linecap = 'round'">Round</xsl:when>\r
769     <xsl:when test="$linecap = 'square'">Square</xsl:when>\r
770     <xsl:otherwise>Flat</xsl:otherwise>\r
771   </xsl:choose>\r
772 </xsl:template>\r
773 \r
774 <!-- Stroke linecap -->\r
775 <xsl:template mode="stroke_linecap" match="*">\r
776   <xsl:choose>\r
777     <xsl:when test="@stroke-linecap">\r
778       <xsl:attribute name="StrokeStartLineCap">\r
779         <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="@stroke-linecap" /></xsl:with-param></xsl:call-template>\r
780       </xsl:attribute>\r
781       <xsl:attribute name="StrokeEndLineCap">\r
782         <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="@stroke-linecap" /></xsl:with-param></xsl:call-template>\r
783       </xsl:attribute></xsl:when>\r
784     <xsl:when test="@style and contains(@style, 'stroke-linecap:')">\r
785       <xsl:variable name="StrokeStartLineCap" select="substring-after(@style, 'stroke-linecap:')" />\r
786       <xsl:variable name="StrokeEndLineCap" select="substring-after(@style, 'stroke-linecap:')" />\r
787       <xsl:attribute name="StrokeStartLineCap">\r
788         <xsl:choose>\r
789           <xsl:when test="contains($StrokeStartLineCap, ';')">\r
790             <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="substring-before($StrokeStartLineCap, ';')" /></xsl:with-param></xsl:call-template>\r
791           </xsl:when>\r
792           <xsl:otherwise>\r
793             <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="$StrokeStartLineCap" /></xsl:with-param></xsl:call-template>\r
794           </xsl:otherwise>\r
795         </xsl:choose>\r
796       </xsl:attribute>\r
797       <xsl:attribute name="StrokeEndLineCap">\r
798         <xsl:choose>\r
799           <xsl:when test="contains($StrokeEndLineCap, ';')">\r
800             <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="substring-before($StrokeEndLineCap, ';')" /></xsl:with-param></xsl:call-template>\r
801           </xsl:when>\r
802           <xsl:otherwise>\r
803             <xsl:call-template name="linecap_svg_to_xaml"><xsl:with-param name="linecap"><xsl:value-of select="$StrokeEndLineCap" /></xsl:with-param></xsl:call-template>\r
804           </xsl:otherwise>\r
805         </xsl:choose>\r
806       </xsl:attribute>\r
807     </xsl:when>\r
808     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stroke_linecap" select="parent::*"/></xsl:when>\r
809   </xsl:choose>\r
810 </xsl:template>\r
811 \r
812 <!-- Gradient stops -->\r
813 <xsl:template mode="stop_color" match="*">\r
814   <xsl:variable name="Opacity">\r
815     <xsl:choose>\r
816       <xsl:when test="@stop-opacity"><xsl:value-of select="@stop-opacity" /></xsl:when>\r
817       <xsl:when test="@style and contains(@style, 'stop-opacity:')">\r
818         <xsl:variable name="temp_opacity" select="substring-after(@style, 'stop-opacity:')" />\r
819         <xsl:choose>\r
820           <xsl:when test="contains($temp_opacity, ';')"><xsl:value-of select="substring-before($temp_opacity, ';')" /></xsl:when>\r
821           <xsl:otherwise><xsl:value-of select="$temp_opacity" /></xsl:otherwise>\r
822         </xsl:choose>\r
823       </xsl:when>\r
824       <xsl:otherwise><xsl:value-of select="''" /></xsl:otherwise>\r
825     </xsl:choose>\r
826   </xsl:variable>\r
827   <xsl:variable name="hex_opacity">\r
828     <xsl:choose>\r
829       <xsl:when test="$Opacity != ''"><xsl:call-template name="to_hex"><xsl:with-param name="convert"><xsl:value-of select="number($Opacity) * 255" /></xsl:with-param></xsl:call-template>  </xsl:when>\r
830       <xsl:otherwise><xsl:value-of select="$Opacity" /></xsl:otherwise>\r
831     </xsl:choose>\r
832   </xsl:variable>\r
833   <xsl:variable name="stopcolor">\r
834     <xsl:choose>\r
835       <xsl:when test="@stop-color">\r
836         <xsl:call-template name="template_color"><xsl:with-param name="colorspec"><xsl:value-of select="@stop-color" /></xsl:with-param></xsl:call-template>\r
837       </xsl:when>\r
838       <xsl:when test="@style and contains(@style, 'stop-color:')">\r
839         <xsl:variable name="Color" select="substring-after(@style, 'stop-color:')" />\r
840         <xsl:choose>\r
841           <xsl:when test="contains($Color, ';')">\r
842             <xsl:call-template name="template_color"><xsl:with-param name="colorspec"><xsl:value-of select="substring-before($Color, ';')" /></xsl:with-param></xsl:call-template>\r
843           </xsl:when>\r
844           <xsl:otherwise>\r
845             <xsl:call-template name="template_color"><xsl:with-param name="colorspec"><xsl:value-of select="$Color" /></xsl:with-param></xsl:call-template>\r
846           </xsl:otherwise>\r
847         </xsl:choose>\r
848       </xsl:when>\r
849       <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stop_color" select="parent::*"/></xsl:when>\r
850       <xsl:otherwise>#000</xsl:otherwise>\r
851     </xsl:choose>\r
852   </xsl:variable>\r
853   <xsl:attribute name="Color">\r
854     <xsl:choose>\r
855       <xsl:when test="$hex_opacity != '' and starts-with($stopcolor, '#')"><xsl:value-of select="concat('#', $hex_opacity, substring-after($stopcolor, '#'))" /></xsl:when>\r
856       <xsl:otherwise><xsl:value-of select="$stopcolor" /></xsl:otherwise>\r
857     </xsl:choose>\r
858   </xsl:attribute>\r
859 </xsl:template>\r
860 \r
861 <!-- Gradient stop opacity -->\r
862 <xsl:template mode="stop_opacity" match="*">\r
863   <xsl:choose>\r
864     <xsl:when test="@stop-opacity"><xsl:attribute name="Opacity"><xsl:value-of select="@stop-opacity" /></xsl:attribute></xsl:when>\r
865     <xsl:when test="@style and contains(@style, 'stop-opacity:')">\r
866       <xsl:variable name="Opacity" select="substring-after(@style, 'stop-opacity:')" />\r
867       <xsl:attribute name="Opacity">\r
868         <xsl:choose>\r
869           <xsl:when test="contains($Opacity, ';')"><xsl:value-of select="substring-before($Opacity, ';')" /></xsl:when>\r
870           <xsl:otherwise><xsl:value-of select="$Opacity" /></xsl:otherwise>\r
871         </xsl:choose>\r
872       </xsl:attribute>\r
873     </xsl:when>\r
874     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stop_opacity" select="parent::*"/></xsl:when>\r
875   </xsl:choose>\r
876 </xsl:template>\r
877 \r
878 <!-- Gradient stop offset -->\r
879 <xsl:template mode="offset" match="*">\r
880   <xsl:choose>\r
881     <xsl:when test="@offset">\r
882       <xsl:attribute name="Offset">\r
883         <xsl:choose>\r
884           <xsl:when test="contains(@offset, '%')"><xsl:value-of select="number(substring-before(@offset, '%')) div 100" /></xsl:when>\r
885           <xsl:otherwise><xsl:value-of select="@offset" /></xsl:otherwise>\r
886         </xsl:choose>\r
887       </xsl:attribute>\r
888     </xsl:when>\r
889     <xsl:when test="@style and contains(@style, 'offset:')">\r
890       <xsl:variable name="Offset" select="substring-after(@style, 'offset:')" />\r
891       <xsl:attribute name="Offset">\r
892         <xsl:choose>\r
893           <xsl:when test="contains($Offset, '%')"><xsl:value-of select="number(substring-before($Offset, '%')) div 100" /></xsl:when>        \r
894           <xsl:when test="contains($Offset, ';')"><xsl:value-of select="substring-before($Offset, ';')" /></xsl:when>\r
895           <xsl:otherwise><xsl:value-of select="$Offset" /></xsl:otherwise>\r
896         </xsl:choose>\r
897       </xsl:attribute>\r
898     </xsl:when>\r
899     <xsl:when test="name(..) = 'g' or name(..) = 'svg'"><xsl:apply-templates mode="stop_offset" select="parent::*"/></xsl:when>\r
900   </xsl:choose>\r
901 </xsl:template>\r
902 \r
903 <!-- \r
904 // Transforms //\r
905 All the matrix, translate, rotate... stuff.\r
906 Fixme: XAML transforms don't show the same result as SVG ones with the same values.\r
907 \r
908 * Parse transform\r
909 * Apply transform\r
910 * Apply transform v2\r
911 -->\r
912 \r
913 <!-- Parse transform -->\r
914 <xsl:template name="parse_transform">\r
915   <xsl:param name="input" />\r
916   <xsl:choose>\r
917     <xsl:when test="starts-with($input, 'matrix(')">\r
918       <MatrixTransform><xsl:attribute name="Matrix"><xsl:value-of select="substring-before(substring-after($input, 'matrix('), ')')" /></xsl:attribute></MatrixTransform>\r
919       <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>      \r
920     </xsl:when>\r
921     <xsl:when test="starts-with($input, 'scale(')">\r
922       <ScaleTransform>\r
923         <xsl:variable name="scale" select="substring-before(substring-after($input, 'scale('), ')')" />\r
924         <xsl:choose>\r
925           <xsl:when test="contains($scale, ',')">\r
926             <xsl:attribute name="ScaleX"><xsl:value-of select="substring-before($scale, ',')" /></xsl:attribute>\r
927             <xsl:attribute name="ScaleY"><xsl:value-of select="substring-after($scale, ',')" /></xsl:attribute>\r
928           </xsl:when>\r
929           <xsl:otherwise>\r
930             <xsl:attribute name="ScaleX"><xsl:value-of select="$scale" /></xsl:attribute>\r
931             <xsl:attribute name="ScaleY"><xsl:value-of select="$scale" /></xsl:attribute>\r
932           </xsl:otherwise>\r
933         </xsl:choose>\r
934       </ScaleTransform>\r
935       <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
936     </xsl:when>\r
937     <xsl:when test="starts-with($input, 'rotate(')">\r
938       <RotateTransform>\r
939         <xsl:attribute name="Angle"><xsl:value-of select="substring-before(substring-after($input, 'rotate('), ')')" /></xsl:attribute>\r
940         <xsl:if test="@rx"><xsl:attribute name="CenterX"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>\r
941         <xsl:if test="@ry"><xsl:attribute name="CenterY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>\r
942       </RotateTransform>\r
943       <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
944     </xsl:when>\r
945     <xsl:when test="starts-with($input, 'skewX(')">\r
946       <SkewTransform>\r
947         <xsl:attribute name="AngleX"><xsl:value-of select="substring-before(substring-after($input, 'skewX('), ')')" /></xsl:attribute>\r
948         <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
949       </SkewTransform>\r
950     </xsl:when>\r
951     <xsl:when test="starts-with($input, 'skewY(')">\r
952       <SkewTransform>\r
953         <xsl:attribute name="AngleY"><xsl:value-of select="substring-before(substring-after($input, 'skewY('), ')')" /></xsl:attribute>\r
954         <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
955       </SkewTransform>\r
956     </xsl:when>\r
957     <xsl:when test="starts-with($input, 'translate(')">\r
958       <TranslateTransform>\r
959         <xsl:variable name="translate" select="substring-before(substring-after($input, 'translate('), ')')" />\r
960         <xsl:choose>\r
961           <xsl:when test="contains($translate, ',')">\r
962             <xsl:attribute name="X"><xsl:value-of select="substring-before($translate, ',')" /></xsl:attribute>\r
963             <xsl:attribute name="Y"><xsl:value-of select="substring-after($translate, ',')" /></xsl:attribute>\r
964           </xsl:when>\r
965           <xsl:when test="contains($translate, ' ')">\r
966             <xsl:attribute name="X"><xsl:value-of select="substring-before($translate, ' ')" /></xsl:attribute>\r
967             <xsl:attribute name="Y"><xsl:value-of select="substring-after($translate, ' ')" /></xsl:attribute>\r
968           </xsl:when>\r
969           <xsl:otherwise><xsl:attribute name="X"><xsl:value-of select="$translate" /></xsl:attribute></xsl:otherwise>\r
970         </xsl:choose>\r
971       </TranslateTransform>\r
972       <xsl:call-template name="parse_transform"><xsl:with-param name="input" select="substring-after($input, ') ')" /></xsl:call-template>\r
973     </xsl:when>\r
974   </xsl:choose>\r
975 </xsl:template>\r
976 \r
977 <!-- Apply transform -->\r
978 <xsl:template mode="transform" match="*">\r
979   <xsl:param name="mapped_type" />\r
980   <xsl:if test="@transform or @gradientTransform">\r
981   <xsl:variable name="transform">\r
982     <xsl:choose>\r
983        <xsl:when test="@transform"><xsl:value-of select="@transform" /></xsl:when>\r
984        <xsl:otherwise><xsl:value-of select="@gradientTransform" /></xsl:otherwise>\r
985     </xsl:choose>\r
986   </xsl:variable>\r
987   <xsl:variable name="transform_nodes">\r
988     <xsl:call-template name="parse_transform">\r
989       <xsl:with-param name="input" select="$transform" />\r
990     </xsl:call-template>\r
991   </xsl:variable>\r
992 \r
993   <xsl:comment>\r
994     <xsl:value-of select="name(.)" />\r
995   </xsl:comment>\r
996 \r
997   <xsl:choose>\r
998     <xsl:when test="$mapped_type and $mapped_type != ''">\r
999       <xsl:element name="{$mapped_type}.RenderTransform">\r
1000         <xsl:choose>\r
1001           <xsl:when test="count(libxslt:node-set($transform_nodes)/*) = 1"><xsl:copy-of select="libxslt:node-set($transform_nodes)" /></xsl:when>\r
1002           <xsl:when test="count(libxslt:node-set($transform_nodes)/*) &gt; 1"><TransformGroup><xsl:copy-of select="libxslt:node-set($transform_nodes)" /></TransformGroup></xsl:when>\r
1003         </xsl:choose>\r
1004       </xsl:element>\r
1005     </xsl:when>\r
1006     <xsl:otherwise>\r
1007       <!-- For instance LinearGradient.Transform -->\r
1008       <xsl:choose>\r
1009           <xsl:when test="count(libxslt:node-set($transform_nodes)/*) = 1"><xsl:copy-of select="libxslt:node-set($transform_nodes)" /></xsl:when>\r
1010           <xsl:when test="count(libxslt:node-set($transform_nodes)/*) &gt; 1"><TransformGroup><xsl:copy-of select="libxslt:node-set($transform_nodes)" /></TransformGroup></xsl:when>\r
1011       </xsl:choose>\r
1012     </xsl:otherwise>\r
1013   </xsl:choose>\r
1014   </xsl:if>  \r
1015 </xsl:template>\r
1016 \r
1017 <!-- Apply transform v2\r
1018 Fixme: is this template still in use? -->\r
1019 <xsl:template mode="transform2" match="*">\r
1020   <xsl:choose>\r
1021     <xsl:when test="@transform">\r
1022       <Canvas>\r
1023         <Canvas.RenderTransform>\r
1024           <TransformGroup><xsl:apply-templates mode="transform" select="." /></TransformGroup>\r
1025         </Canvas.RenderTransform>\r
1026         <xsl:apply-templates mode="forward" select="." />\r
1027       </Canvas>\r
1028     </xsl:when>\r
1029     <xsl:otherwise>\r
1030       <xsl:apply-templates mode="forward" select="." />\r
1031     </xsl:otherwise>\r
1032   </xsl:choose>\r
1033 </xsl:template>\r
1034 \r
1035 <!-- \r
1036 // Objects //\r
1037 \r
1038 * Image\r
1039 * Text\r
1040 * Lines\r
1041 * Rectangle\r
1042 * Polygon\r
1043 * Polyline\r
1044 * Path\r
1045 * Ellipse\r
1046 * Circle\r
1047 -->\r
1048 \r
1049 <!-- Image -->\r
1050 <xsl:template mode="forward" match="*[name(.) = 'image']">\r
1051   <Image>\r
1052     <xsl:apply-templates mode="id" select="." />\r
1053     <xsl:if test="@x"><xsl:attribute name="Canvas.Left">\r
1054         <xsl:call-template name="convert_unit">\r
1055             <xsl:with-param name="convert_value" select="@x" />\r
1056         </xsl:call-template>\r
1057     </xsl:attribute></xsl:if>\r
1058     <xsl:if test="@y"><xsl:attribute name="Canvas.Top">\r
1059         <xsl:call-template name="convert_unit">\r
1060             <xsl:with-param name="convert_value" select="@y" />\r
1061         </xsl:call-template>\r
1062     </xsl:attribute></xsl:if>\r
1063     <xsl:apply-templates mode="desc" select="." />\r
1064     <xsl:apply-templates mode="clip" select="." />\r
1065     <xsl:if test="@xlink:href"><xsl:attribute name="Source"><xsl:value-of select="@xlink:href" /></xsl:attribute></xsl:if>\r
1066     <xsl:if test="@width"><xsl:attribute name="Width">\r
1067         <xsl:call-template name="convert_unit">\r
1068             <xsl:with-param name="convert_value" select="@width" />\r
1069         </xsl:call-template>\r
1070     </xsl:attribute></xsl:if>\r
1071     <xsl:if test="@height"><xsl:attribute name="Height">\r
1072         <xsl:call-template name="convert_unit">\r
1073             <xsl:with-param name="convert_value" select="@height" />\r
1074         </xsl:call-template>\r
1075     </xsl:attribute></xsl:if>\r
1076     <xsl:apply-templates mode="transform" select=".">\r
1077       <xsl:with-param name="mapped_type" select="'Image'" />\r
1078     </xsl:apply-templates>\r
1079     <!--xsl:apply-templates mode="transform" /-->\r
1080     <xsl:apply-templates mode="forward" />\r
1081   </Image>\r
1082 </xsl:template>\r
1083 \r
1084 <!-- Text -->\r
1085 <xsl:template mode="forward" match="*[name(.) = 'text']">\r
1086   <TextBlock>\r
1087     <xsl:if test="@font-size"><xsl:attribute name="FontSize"><xsl:value-of select="@font-size" /></xsl:attribute></xsl:if>\r
1088     <xsl:if test="@style and contains(@style, 'font-size:')">\r
1089       <xsl:variable name="font_size" select="substring-after(@style, 'font-size:')" />\r
1090       <xsl:attribute name="FontSize">\r
1091         <xsl:choose>\r
1092           <xsl:when test="contains($font_size, ';')">\r
1093             <xsl:value-of select="substring-before($font_size, ';')" />\r
1094           </xsl:when>\r
1095           <xsl:otherwise><xsl:value-of select="$font_size" /></xsl:otherwise>\r
1096         </xsl:choose>\r
1097       </xsl:attribute>\r
1098     </xsl:if>\r
1099     <xsl:if test="@font-weight"><xsl:attribute name="FontWeight"><xsl:value-of select="@font-weight" /></xsl:attribute></xsl:if>\r
1100     <xsl:if test="@style and contains(@style, 'font-weight:')">\r
1101       <xsl:variable name="font_weight" select="substring-after(@style, 'font-weight:')" />\r
1102       <xsl:attribute name="FontWeight">\r
1103         <xsl:choose>\r
1104           <xsl:when test="contains($font_weight, ';')">\r
1105             <xsl:value-of select="substring-before($font_weight, ';')" />\r
1106           </xsl:when>\r
1107           <xsl:otherwise><xsl:value-of select="$font_weight" /></xsl:otherwise>\r
1108         </xsl:choose>\r
1109       </xsl:attribute>\r
1110     </xsl:if>\r
1111     <xsl:if test="@font-family"><xsl:attribute name="FontFamily"><xsl:value-of select="@font-family" /></xsl:attribute></xsl:if>\r
1112     <xsl:if test="@style and contains(@style, 'font-family:')">\r
1113       <xsl:variable name="font_family" select="substring-after(@style, 'font-family:')" />\r
1114       <xsl:attribute name="FontFamily">\r
1115         <xsl:choose>\r
1116           <xsl:when test="contains($font_family, ';')">\r
1117             <xsl:value-of select="substring-before($font_family, ';')" />\r
1118           </xsl:when>\r
1119           <xsl:otherwise><xsl:value-of select="$font_family" /></xsl:otherwise>\r
1120         </xsl:choose>\r
1121       </xsl:attribute>\r
1122     </xsl:if>\r
1123     <xsl:if test="@font-style"><xsl:attribute name="FontStyle"><xsl:value-of select="@font-style" /></xsl:attribute></xsl:if>\r
1124     <xsl:if test="@style and contains(@style, 'font-style:')">\r
1125       <xsl:variable name="font_style" select="substring-after(@style, 'font-style:')" />\r
1126       <xsl:attribute name="FontStyle">\r
1127         <xsl:choose>\r
1128           <xsl:when test="contains($font_style, ';')">\r
1129             <xsl:value-of select="substring-before($font_style, ';')" />\r
1130           </xsl:when>\r
1131           <xsl:otherwise><xsl:value-of select="$font_style" /></xsl:otherwise>\r
1132         </xsl:choose>\r
1133       </xsl:attribute>\r
1134     </xsl:if>\r
1135     <xsl:if test="@fill"><xsl:attribute name="Foreground"><xsl:value-of select="@fill" /></xsl:attribute></xsl:if>\r
1136     <xsl:if test="@style and contains(@style, 'fill')">\r
1137       <xsl:variable name="fill" select="substring-after(@style, 'fill:')" />\r
1138       <xsl:attribute name="Foreground">\r
1139         <xsl:choose>\r
1140           <xsl:when test="contains($fill, ';')">\r
1141             <xsl:value-of select="substring-before($fill, ';')" />\r
1142           </xsl:when>\r
1143           <xsl:otherwise><xsl:value-of select="$fill" /></xsl:otherwise>\r
1144         </xsl:choose>\r
1145       </xsl:attribute>\r
1146     </xsl:if>\r
1147     <xsl:if test="@text-anchor">\r
1148       <xsl:attribute name="HorizontalAlignment">\r
1149         <xsl:choose>\r
1150           <xsl:when test="@text-anchor = 'start'">Left</xsl:when>\r
1151           <xsl:when test="@text-anchor = 'middle'">Center</xsl:when>\r
1152           <xsl:when test="@text-anchor = 'end'">Right</xsl:when>\r
1153         </xsl:choose>\r
1154       </xsl:attribute>\r
1155     </xsl:if>\r
1156     <xsl:if test="@width"><xsl:attribute name="Width">\r
1157         <xsl:call-template name="convert_unit">\r
1158             <xsl:with-param name="convert_value" select="@width" />\r
1159         </xsl:call-template>\r
1160     </xsl:attribute></xsl:if>\r
1161     <xsl:if test="@height"><xsl:attribute name="Height">\r
1162         <xsl:call-template name="convert_unit">\r
1163             <xsl:with-param name="convert_value" select="@height" />\r
1164         </xsl:call-template>\r
1165     </xsl:attribute></xsl:if>\r
1166     <xsl:if test="@x"><xsl:attribute name="Canvas.Left">\r
1167         <xsl:call-template name="convert_unit">\r
1168             <xsl:with-param name="convert_value" select="@x" />\r
1169         </xsl:call-template>\r
1170     </xsl:attribute></xsl:if>\r
1171     <xsl:if test="@y"><xsl:attribute name="Canvas.Top">\r
1172         <xsl:call-template name="convert_unit">\r
1173             <xsl:with-param name="convert_value" select="@y" />\r
1174         </xsl:call-template>\r
1175     </xsl:attribute></xsl:if>\r
1176     <xsl:apply-templates mode="id" select="." />\r
1177     <xsl:apply-templates mode="filter_effect" select="." />\r
1178     <xsl:apply-templates mode="desc" select="." />\r
1179     <xsl:apply-templates mode="clip" select="." />\r
1180     <!--xsl:apply-templates mode="transform" select="." /-->\r
1181     <!--xsl:apply-templates mode="forward" /-->\r
1182     <xsl:if test="text()"><xsl:value-of select="text()" /></xsl:if>\r
1183     <xsl:if test="*[name(.) = 'tspan']/text()"><xsl:value-of select="*[name(.) = 'tspan']/text()" /></xsl:if>\r
1184   </TextBlock>\r
1185 </xsl:template>\r
1186  \r
1187 <!-- Lines -->\r
1188 <xsl:template mode="forward" match="*[name(.) = 'line']">\r
1189   <Line>\r
1190     <xsl:if test="@x1"><xsl:attribute name="X1"><xsl:value-of select="@x1" /></xsl:attribute></xsl:if> \r
1191     <xsl:if test="@y1"><xsl:attribute name="Y1"><xsl:value-of select="@y1" /></xsl:attribute></xsl:if> \r
1192     <xsl:if test="@x2"><xsl:attribute name="X2"><xsl:value-of select="@x2" /></xsl:attribute></xsl:if> \r
1193     <xsl:if test="@y2"><xsl:attribute name="Y2"><xsl:value-of select="@y2" /></xsl:attribute></xsl:if>\r
1194     <xsl:apply-templates mode="id" select="." />\r
1195     <xsl:apply-templates mode="template_fill" select="." />\r
1196     <xsl:apply-templates mode="template_stroke" select="." />\r
1197     <xsl:apply-templates mode="stroke_width" select="." />\r
1198     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1199     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1200     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1201     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1202     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1203     <xsl:apply-templates mode="filter_effect" select="." />\r
1204     <xsl:apply-templates mode="desc" select="." />\r
1205 \r
1206     <xsl:apply-templates mode="transform" select=".">\r
1207       <xsl:with-param name="mapped_type" select="'Line'" />\r
1208     </xsl:apply-templates>    \r
1209 \r
1210     <xsl:apply-templates mode="forward" />\r
1211   </Line>\r
1212 </xsl:template>\r
1213 \r
1214 <!-- Rectangle -->\r
1215 <xsl:template mode="forward" match="*[name(.) = 'rect']">\r
1216   <Rectangle>\r
1217     <xsl:if test="@x"><xsl:attribute name="Canvas.Left">\r
1218         <xsl:call-template name="convert_unit">\r
1219             <xsl:with-param name="convert_value" select="@x" />\r
1220         </xsl:call-template>\r
1221     </xsl:attribute></xsl:if>\r
1222     <xsl:if test="@y"><xsl:attribute name="Canvas.Top">\r
1223         <xsl:call-template name="convert_unit">\r
1224             <xsl:with-param name="convert_value" select="@y" />\r
1225         </xsl:call-template>\r
1226     </xsl:attribute></xsl:if>\r
1227     <xsl:if test="@width"><xsl:attribute name="Width">\r
1228         <xsl:call-template name="convert_unit">\r
1229             <xsl:with-param name="convert_value" select="@width" />\r
1230         </xsl:call-template>\r
1231     </xsl:attribute></xsl:if>\r
1232     <xsl:if test="@height"><xsl:attribute name="Height">\r
1233         <xsl:call-template name="convert_unit">\r
1234             <xsl:with-param name="convert_value" select="@height" />\r
1235         </xsl:call-template>\r
1236     </xsl:attribute></xsl:if>\r
1237     <xsl:if test="@rx"><xsl:attribute name="RadiusX"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>\r
1238     <xsl:if test="@ry"><xsl:attribute name="RadiusY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>\r
1239     <xsl:if test="@rx and not(@ry)"><xsl:attribute name="RadiusX"><xsl:value-of select="@rx" /></xsl:attribute><xsl:attribute name="RadiusY"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>\r
1240     <xsl:if test="@ry and not(@rx)"><xsl:attribute name="RadiusX"><xsl:value-of select="@ry" /></xsl:attribute><xsl:attribute name="RadiusY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>\r
1241 \r
1242     <xsl:apply-templates mode="id" select="." />\r
1243     <xsl:apply-templates mode="template_fill" select="." />\r
1244     <xsl:apply-templates mode="template_stroke" select="." />\r
1245     <xsl:apply-templates mode="stroke_width" select="." />\r
1246     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1247     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1248     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1249     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1250     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1251     <xsl:apply-templates mode="filter_effect" select="." />\r
1252     <xsl:apply-templates mode="resources" select="." />\r
1253     <xsl:apply-templates mode="desc" select="." />\r
1254     <xsl:apply-templates mode="clip" select="." />\r
1255 \r
1256     <xsl:apply-templates mode="transform" select=".">\r
1257       <xsl:with-param name="mapped_type" select="'Rectangle'" />\r
1258     </xsl:apply-templates>\r
1259 \r
1260     <xsl:apply-templates mode="forward" />\r
1261   </Rectangle>\r
1262 </xsl:template>\r
1263 \r
1264 <!-- Polygon -->\r
1265 <xsl:template mode="forward" match="*[name(.) = 'polygon']">\r
1266   <Polygon>\r
1267     <xsl:if test="@points"><xsl:attribute name="Points"><xsl:value-of select="@points" /></xsl:attribute></xsl:if>\r
1268     <xsl:apply-templates mode="id" select="." />\r
1269     <xsl:apply-templates mode="fill_rule" select="." />\r
1270     <xsl:apply-templates mode="template_fill" select="." />\r
1271     <xsl:apply-templates mode="template_stroke" select="." />\r
1272     <xsl:apply-templates mode="stroke_width" select="." />\r
1273     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1274     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1275     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1276     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1277     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1278     <xsl:apply-templates mode="filter_effect" select="." />\r
1279     <xsl:apply-templates mode="desc" select="." />\r
1280 \r
1281     <xsl:apply-templates mode="transform" select=".">\r
1282       <xsl:with-param name="mapped_type" select="'Polygon'" />\r
1283     </xsl:apply-templates>\r
1284 \r
1285     <xsl:apply-templates mode="forward" />\r
1286   </Polygon>\r
1287 </xsl:template>\r
1288 \r
1289 <!-- Polyline -->\r
1290 <xsl:template mode="forward" match="*[name(.) = 'polyline']">\r
1291   <Polyline>\r
1292     <xsl:if test="@points"><xsl:attribute name="Points"><xsl:value-of select="@points" /></xsl:attribute></xsl:if>\r
1293     <xsl:apply-templates mode="id" select="." />\r
1294     <xsl:apply-templates mode="fill_rule" select="." />\r
1295     <xsl:apply-templates mode="template_fill" select="." />\r
1296     <xsl:apply-templates mode="template_stroke" select="." />\r
1297     <xsl:apply-templates mode="stroke_width" select="." />\r
1298     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1299     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1300     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1301     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1302     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1303     <xsl:apply-templates mode="filter_effect" select="." />\r
1304     <xsl:apply-templates mode="desc" select="." />\r
1305 \r
1306     <xsl:apply-templates mode="transform" select=".">\r
1307       <xsl:with-param name="mapped_type" select="'Polyline'" />\r
1308     </xsl:apply-templates>\r
1309 \r
1310     <xsl:apply-templates mode="forward" />\r
1311   </Polyline>\r
1312 </xsl:template>\r
1313 \r
1314 <!-- Path -->\r
1315 <xsl:template mode="forward" match="*[name(.) = 'path']">\r
1316   <Path>\r
1317     <xsl:apply-templates mode="id" select="." />\r
1318     <xsl:apply-templates mode="template_fill" select="." />\r
1319     <xsl:apply-templates mode="template_stroke" select="." />\r
1320     <xsl:apply-templates mode="stroke_width" select="." />\r
1321     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1322     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1323     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1324     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1325     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1326     <xsl:apply-templates mode="filter_effect" select="." />\r
1327     <xsl:apply-templates mode="desc" select="." />\r
1328 \r
1329     <xsl:if test="@d">\r
1330       <xsl:choose>\r
1331         <xsl:when test="$silverlight_compatible = 1">\r
1332           <xsl:attribute name="Data">\r
1333             <xsl:value-of select="translate(@d , ',', ' ')" />\r
1334           </xsl:attribute>\r
1335         </xsl:when>\r
1336         <xsl:otherwise>\r
1337           <Path.Data>\r
1338             <PathGeometry>\r
1339               <xsl:attribute name="Figures">\r
1340                 <xsl:value-of select="translate(@d , ',', ' ')" />\r
1341               </xsl:attribute>\r
1342               <xsl:apply-templates mode="fill_rule" select="." />\r
1343             </PathGeometry>\r
1344           </Path.Data>\r
1345          </xsl:otherwise>\r
1346       </xsl:choose>\r
1347     </xsl:if>\r
1348 \r
1349     <xsl:apply-templates mode="transform" select=".">\r
1350       <xsl:with-param name="mapped_type" select="'Path'" />\r
1351     </xsl:apply-templates>\r
1352 \r
1353     <xsl:apply-templates mode="forward" />\r
1354   </Path>\r
1355 </xsl:template>\r
1356 \r
1357 <!-- Ellipse -->\r
1358 <xsl:template mode="forward" match="*[name(.) = 'ellipse']">\r
1359   <Ellipse>\r
1360     <xsl:variable name="cx">\r
1361       <xsl:choose>\r
1362         <xsl:when test="@cx"><xsl:value-of select="@cx" /></xsl:when>\r
1363         <xsl:otherwise>0</xsl:otherwise>\r
1364       </xsl:choose>\r
1365     </xsl:variable>\r
1366     <xsl:variable name="cy">\r
1367       <xsl:choose>\r
1368         <xsl:when test="@cy"><xsl:value-of select="@cy" /></xsl:when>\r
1369         <xsl:otherwise>0</xsl:otherwise>\r
1370       </xsl:choose>\r
1371     </xsl:variable>\r
1372     <xsl:if test="@rx">\r
1373       <xsl:attribute name="Canvas.Left"><xsl:value-of select='format-number($cx - @rx, "#.#")' /></xsl:attribute>\r
1374       <xsl:attribute name="Width"><xsl:value-of select='format-number(2 * @rx, "#.#")' /></xsl:attribute>\r
1375     </xsl:if>\r
1376     <xsl:if test="@ry">\r
1377       <xsl:attribute name="Canvas.Top"><xsl:value-of select='format-number($cy - @ry, "#.#")' /></xsl:attribute>\r
1378       <xsl:attribute name="Height"><xsl:value-of select='format-number(2 * @ry, "#.#")' /></xsl:attribute>\r
1379     </xsl:if>\r
1380     <xsl:apply-templates mode="id" select="." />\r
1381     <xsl:apply-templates mode="template_fill" select="." />\r
1382     <xsl:apply-templates mode="template_stroke" select="." />\r
1383     <xsl:apply-templates mode="stroke_width" select="." />\r
1384     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1385     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1386     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1387     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1388     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1389     <xsl:apply-templates mode="filter_effect" select="." />\r
1390     <xsl:apply-templates mode="desc" select="." />\r
1391     <xsl:apply-templates mode="clip" select="." />\r
1392 \r
1393     <xsl:apply-templates mode="transform" select=".">\r
1394       <xsl:with-param name="mapped_type" select="'Ellipse'" />\r
1395     </xsl:apply-templates>\r
1396 \r
1397     <xsl:apply-templates mode="forward" />\r
1398   </Ellipse>\r
1399 </xsl:template>\r
1400 \r
1401 <!-- Circle -->\r
1402 <xsl:template mode="forward" match="*[name(.) = 'circle']">\r
1403   <Ellipse>\r
1404     <xsl:variable name="cx">\r
1405       <xsl:choose>\r
1406         <xsl:when test="@cx"><xsl:value-of select="@cx" /></xsl:when>\r
1407         <xsl:otherwise>0</xsl:otherwise>\r
1408       </xsl:choose>\r
1409     </xsl:variable>\r
1410     <xsl:variable name="cy">\r
1411       <xsl:choose>\r
1412         <xsl:when test="@cy"><xsl:value-of select="@cy" /></xsl:when>\r
1413         <xsl:otherwise>0</xsl:otherwise>\r
1414       </xsl:choose>\r
1415     </xsl:variable>\r
1416     <xsl:if test="@r">\r
1417        <xsl:attribute name="Canvas.Left"><xsl:value-of select='format-number($cx - @r, "#.#")' /></xsl:attribute>\r
1418        <xsl:attribute name="Canvas.Top"><xsl:value-of select='format-number($cy - @r, "#.#")' /></xsl:attribute>\r
1419        <xsl:attribute name="Width"><xsl:value-of select='format-number(2 * @r, "#.#")' /></xsl:attribute>\r
1420        <xsl:attribute name="Height"><xsl:value-of select='format-number(2 * @r, "#.#")' /></xsl:attribute>\r
1421     </xsl:if>\r
1422     <xsl:apply-templates mode="id" select="." />\r
1423     <xsl:apply-templates mode="template_fill" select="." />\r
1424     <xsl:apply-templates mode="template_stroke" select="." />\r
1425     <xsl:apply-templates mode="stroke_width" select="." />\r
1426     <xsl:apply-templates mode="stroke_miterlimit" select="." />\r
1427     <xsl:apply-templates mode="stroke_dasharray" select="." />\r
1428     <xsl:apply-templates mode="stroke_dashoffset" select="." />\r
1429     <xsl:apply-templates mode="stroke_linejoin" select="." />\r
1430     <xsl:apply-templates mode="stroke_linecap" select="." />\r
1431     <xsl:apply-templates mode="filter_effect" select="." />\r
1432     <xsl:apply-templates mode="desc" select="." />\r
1433     <xsl:apply-templates mode="clip" select="." />\r
1434 \r
1435     <xsl:apply-templates mode="transform" select=".">\r
1436       <xsl:with-param name="mapped_type" select="'Ellipse'" />\r
1437     </xsl:apply-templates>\r
1438 \r
1439     <xsl:apply-templates mode="forward" />\r
1440   </Ellipse>\r
1441 </xsl:template>\r
1442 \r
1443 <!--\r
1444 // Geometry //\r
1445 * Generic clip path template\r
1446 * Geometry for circle\r
1447 * Geometry for rectangle\r
1448 -->\r
1449 \r
1450 <!-- Generic clip path template -->\r
1451 <xsl:template mode="forward" match="*[name(.) = 'clipPath']">\r
1452   <xsl:apply-templates mode="geometry" />\r
1453 </xsl:template>\r
1454 \r
1455 <!-- Geometry for circle -->\r
1456 <xsl:template mode="geometry" match="*[name(.) = 'circle']">\r
1457   <EllipseGeometry>\r
1458     <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>\r
1459     <xsl:if test="@cx and @cy"><xsl:attribute name="Center"><xsl:value-of select="concat(@cx, ',', @cy)" /></xsl:attribute></xsl:if>\r
1460     <xsl:if test="@r">\r
1461       <xsl:attribute name="RadiusX"><xsl:value-of select="@r" /></xsl:attribute>\r
1462       <xsl:attribute name="RadiusY"><xsl:value-of select="@r" /></xsl:attribute>\r
1463     </xsl:if>\r
1464   </EllipseGeometry>\r
1465 </xsl:template>\r
1466 \r
1467 <!-- Geometry for rectangle -->\r
1468 <xsl:template mode="geometry" match="*[name(.) = 'rect']">\r
1469   <RectangleGeometry>\r
1470     <xsl:if test="../@id"><xsl:attribute name="x:Key"><xsl:value-of select="../@id" /></xsl:attribute></xsl:if>\r
1471     <!--\r
1472     <xsl:if test="@x"><xsl:attribute name="Canvas.Left"><xsl:value-of select="@x" /></xsl:attribute></xsl:if>\r
1473     <xsl:if test="@y"><xsl:attribute name="Canvas.Top"><xsl:value-of select="@y" /></xsl:attribute></xsl:if>\r
1474     <xsl:if test="@width"><xsl:attribute name="Width"><xsl:value-of select="@width" /></xsl:attribute></xsl:if>\r
1475     <xsl:if test="@height"><xsl:attribute name="Height"><xsl:value-of select="@height" /></xsl:attribute></xsl:if>\r
1476     <xsl:if test="@rx"><xsl:attribute name="RadiusX"><xsl:value-of select="@rx" /></xsl:attribute></xsl:if>\r
1477     <xsl:if test="@ry"><xsl:attribute name="RadiusY"><xsl:value-of select="@ry" /></xsl:attribute></xsl:if>\r
1478     -->\r
1479     <xsl:attribute name="Rect"><xsl:value-of select="concat('0, 0, ', @width, ', ', @height)" /></xsl:attribute>\r
1480   </RectangleGeometry>\r
1481 </xsl:template>\r
1482 \r
1483 </xsl:stylesheet>\r