Code

r16552@tres: ted | 2007-09-11 22:54:20 -0700
[inkscape.git] / share / extensions / xaml2svg.xsl
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 \r
3 <!--\r
4 Copyright (c) 2005-2007 Toine de Greef (a.degreef@chello.nl)\r
5 \r
6 Permission is hereby granted, free of charge, to any person obtaining a copy\r
7 of this software and associated documentation files (the "Software"), to deal\r
8 in the Software without restriction, including without limitation the rights\r
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
10 copies of the Software, and to permit persons to whom the Software is\r
11 furnished to do so, subject to the following conditions:\r
12 \r
13 The above copyright notice and this permission notice shall be included in\r
14 all copies or substantial portions of the Software.\r
15 \r
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
22 THE SOFTWARE.\r
23 -->\r
24 \r
25 <xsl:stylesheet version="1.0"\r
26 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
27 xmlns:xlink="http://www.w3.org/1999/xlink"\r
28 xmlns:svg="http://www.w3.org/2000/svg"\r
29 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
30 xmlns:msxsl="urn:schemas-microsoft-com:xslt">\r
31 <xsl:strip-space elements="*" />\r
32 <xsl:output method="xml" encoding="UTF-8"/>\r
33 <xsl:include href="xaml2svg/animation.xsl" />\r
34 <xsl:include href="xaml2svg/brushes.xsl" />\r
35 <xsl:include href="xaml2svg/canvas.xsl" />\r
36 <xsl:include href="xaml2svg/geometry.xsl" />\r
37 <xsl:include href="xaml2svg/properties.xsl" />\r
38 <xsl:include href="xaml2svg/shapes.xsl" />\r
39 <xsl:include href="xaml2svg/transform.xsl" />\r
40 \r
41 <xsl:template match="/">\r
42   <svg>\r
43     <xsl:attribute name="overflow">visible</xsl:attribute>\r
44     <xsl:variable name="viewBox"><xsl:apply-templates mode="boundingbox" /></xsl:variable>\r
45     <xsl:if test="system-property('xsl:vendor') = 'Microsoft'">\r
46       <xsl:attribute name="viewBox">\r
47         <xsl:value-of select="concat(msxsl:node-set($viewBox)/boundingbox/@x1, ' ')" />\r
48         <xsl:value-of select="concat(msxsl:node-set($viewBox)/boundingbox/@y1, ' ')" />\r
49         <xsl:value-of select="concat(msxsl:node-set($viewBox)/boundingbox/@x2 - msxsl:node-set($viewBox)/boundingbox/@x1, ' ')" />\r
50         <xsl:value-of select="msxsl:node-set($viewBox)/boundingbox/@y2 - msxsl:node-set($viewBox)/boundingbox/@y1" />\r
51       </xsl:attribute>\r
52     </xsl:if>  \r
53     <xsl:apply-templates mode="svg" />\r
54   </svg>\r
55 </xsl:template>\r
56 \r
57 <xsl:template mode="forward" match="*[name(.) = 'Image']">\r
58   <xsl:if test="@Canvas.Left or @Canvas.Top"><xsl:value-of disable-output-escaping="yes" select="concat('&lt;svg x=&quot;', @Canvas.Left, '&quot; y=&quot;', @Canvas.Top, '&quot;&gt;')" /></xsl:if>\r
59   <image>\r
60     <xsl:if test="@Source"><xsl:attribute name="xlink:href"><xsl:value-of select="@Source" /></xsl:attribute></xsl:if>\r
61     <xsl:if test="@Width"><xsl:attribute name="width"><xsl:value-of select="@Width" /></xsl:attribute></xsl:if>\r
62     <xsl:if test="@Height"><xsl:attribute name="height"><xsl:value-of select="@Height" /></xsl:attribute></xsl:if>\r
63     <xsl:call-template name="template_properties" />\r
64     <xsl:call-template name="template_transform" />\r
65     <xsl:apply-templates mode="forward" />\r
66   </image>\r
67   <xsl:if test="@Canvas.Left or @Canvas.Top"><xsl:value-of disable-output-escaping="yes" select="'&lt;/svg&gt;&#13;'" /></xsl:if>\r
68 </xsl:template>\r
69 \r
70 <xsl:template mode="forward" match="*[name(.) = 'TextBlock']">\r
71   <xsl:if test="@Canvas.Left or @Canvas.Top"><xsl:value-of disable-output-escaping="yes" select="concat('&lt;svg x=&quot;', @Canvas.Left, '&quot; y=&quot;', @Canvas.Top, '&quot;&gt;')" /></xsl:if>\r
72   <text>\r
73     <xsl:if test="@FontSize"><xsl:attribute name="font-size"><xsl:value-of select="@FontSize" /></xsl:attribute></xsl:if>\r
74     <xsl:if test="@FontWeight"><xsl:attribute name="font-weight"><xsl:value-of select="@FontWeight" /></xsl:attribute></xsl:if>\r
75     <xsl:if test="@FontFamily"><xsl:attribute name="font-family"><xsl:value-of select="@FontFamily" /></xsl:attribute></xsl:if>\r
76     <xsl:if test="@FontStyle"><xsl:attribute name="font-style"><xsl:value-of select="@FontStyle" /></xsl:attribute></xsl:if>\r
77     <xsl:if test="@Foreground"><xsl:attribute name="fill"><xsl:value-of select="@Foreground" /></xsl:attribute></xsl:if>\r
78     <xsl:if test="@Width"><xsl:attribute name="width"><xsl:value-of select="@Width" /></xsl:attribute></xsl:if>\r
79     <xsl:if test="@Height"><xsl:attribute name="height"><xsl:value-of select="@Height" /></xsl:attribute></xsl:if>\r
80     <xsl:if test="@HorizontalAlignment">\r
81       <xsl:attribute name="text-anchor">\r
82         <xsl:choose>\r
83           <xsl:when test="@HorizontalAlignment = 'Left'">start</xsl:when>\r
84           <xsl:when test="@HorizontalAlignment = 'Center'">middle</xsl:when>\r
85           <xsl:when test="@HorizontalAlignment = 'Right'">end</xsl:when>\r
86         </xsl:choose>\r
87       </xsl:attribute>\r
88     </xsl:if>\r
89     <xsl:attribute name="dominant-baseline">hanging</xsl:attribute>\r
90     <xsl:call-template name="template_properties" />\r
91     <xsl:call-template name="template_transform" />\r
92     <xsl:apply-templates />\r
93   </text>\r
94   <xsl:if test="@Canvas.Left or @Canvas.Top"><xsl:value-of disable-output-escaping="yes" select="'&lt;/svg&gt;&#13;'" /></xsl:if>\r
95 </xsl:template>\r
96 \r
97 <xsl:template match="*">\r
98 <xsl:comment><xsl:value-of select="concat('Unknown tag: ', name(.))" /></xsl:comment>\r
99 </xsl:template>\r
100 \r
101 </xsl:stylesheet>\r