Code

r16572@tres: ted | 2007-09-12 21:55:43 -0700
[inkscape.git] / share / extensions / xaml2svg / shapes.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 Version history:\r
25 \r
26 20070907 Initial release\r
27 20070912 starts-with(@Data, 'F0 ') to strip of F0 from path data\r
28 20070912 nonzero and evenodd were outside xsl:attribute (reported by bulia byak and Ted Gould)\r
29 \r
30 -->\r
31 \r
32 <xsl:stylesheet version="1.0" \r
33 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
34 xmlns:xlink="http://www.w3.org/1999/xlink"\r
35 xmlns:svg="http://www.w3.org/2000/svg"\r
36 xmlns:def="Definition"\r
37 exclude-result-prefixes="def">\r
38 <xsl:strip-space elements="*" />\r
39 <xsl:output method="xml" encoding="ISO-8859-1"/>\r
40 \r
41 <xsl:template mode="forward" match="*[name(.) = 'Path']">\r
42   <path>\r
43     <xsl:if test="@Data">\r
44       <xsl:attribute name="d">\r
45         <xsl:choose>\r
46           <xsl:when test="starts-with(@Data, 'F0 ')"><xsl:value-of select="substring-after(@Data, 'F0 ')" /></xsl:when>\r
47           <xsl:when test="starts-with(@Data, 'F1 ')"><xsl:value-of select="substring-after(@Data, 'F1 ')" /></xsl:when>\r
48           <xsl:otherwise><xsl:value-of select="@Data" /></xsl:otherwise>\r
49         </xsl:choose>\r
50       </xsl:attribute>\r
51     </xsl:if>\r
52     <xsl:choose>\r
53       <xsl:when test="@FillRule = 'nonzero' or starts-with(@Data, 'F1 ')"><xsl:attribute name="fill-rule">nonzero</xsl:attribute></xsl:when>\r
54       <xsl:when test="@FillRule = 'evenodd' or starts-with(@Data, 'F0 ')"><xsl:attribute name="fill-rule">evenodd</xsl:attribute></xsl:when>\r
55     </xsl:choose>\r
56     <xsl:call-template name="template_properties" />  \r
57     <xsl:call-template name="template_transform" />  \r
58     <xsl:apply-templates mode="forward" />\r
59   </path>\r
60 </xsl:template>    \r
61 \r
62 <xsl:template mode="forward" match="*[name(.) = 'Path.Data']">\r
63   <xsl:attribute name="d">\r
64     <xsl:apply-templates mode="forward" />\r
65   </xsl:attribute>\r
66   <xsl:if test="@FillRule">\r
67     <xsl:attribute name="fill-rule">\r
68       <xsl:choose>\r
69         <xsl:when test="@FillRule = 'nonzero'">nonzero</xsl:when>\r
70         <xsl:otherwise>evenodd</xsl:otherwise>\r
71       </xsl:choose>\r
72     </xsl:attribute>\r
73   </xsl:if>\r
74 </xsl:template>\r
75 \r
76 <xsl:template mode="forward" match="*[name(.) = 'Line']">\r
77   <line>\r
78     <xsl:if test="@X1"><xsl:attribute name="x1"><xsl:value-of select="@X1" /></xsl:attribute></xsl:if> \r
79     <xsl:if test="@Y1"><xsl:attribute name="y1"><xsl:value-of select="@Y1" /></xsl:attribute></xsl:if> \r
80     <xsl:if test="@X2"><xsl:attribute name="x2"><xsl:value-of select="@X2" /></xsl:attribute></xsl:if> \r
81     <xsl:if test="@Y2"><xsl:attribute name="y2"><xsl:value-of select="@Y2" /></xsl:attribute></xsl:if> \r
82     <xsl:call-template name="template_properties" />  \r
83     <xsl:call-template name="template_transform" />  \r
84     <xsl:apply-templates mode="forward" />\r
85   </line>\r
86 </xsl:template>\r
87 \r
88 <xsl:template mode="forward" match="*[name(.) = 'Ellipse']">\r
89   <ellipse>\r
90     <xsl:if test="@Width">\r
91       <xsl:attribute name="rx"><xsl:value-of select="@Width div 2" /></xsl:attribute>\r
92       <xsl:if test="@Canvas.Left">\r
93         <xsl:attribute name="cx"><xsl:value-of select="@Canvas.Left + @Width div 2" /></xsl:attribute>\r
94       </xsl:if>\r
95     </xsl:if>\r
96     <xsl:if test="@Height">\r
97       <xsl:attribute name="ry"><xsl:value-of select="@Height div 2" /></xsl:attribute>\r
98       <xsl:if test="@Canvas.Top">\r
99         <xsl:attribute name="cy"><xsl:value-of select="@Canvas.Top + @Height div 2" /></xsl:attribute>\r
100       </xsl:if>\r
101     </xsl:if>\r
102     <xsl:call-template name="template_properties" />  \r
103     <xsl:call-template name="template_transform" />  \r
104     <xsl:apply-templates mode="forward" />\r
105   </ellipse>\r
106 </xsl:template>\r
107 \r
108 <xsl:template mode="forward" match="*[name(.) = 'Rectangle']">\r
109   <rect>\r
110     <xsl:if test="@Canvas.Left"><xsl:attribute name="x"><xsl:value-of select="@Canvas.Left" /></xsl:attribute></xsl:if>  \r
111     <xsl:if test="@Canvas.Top"><xsl:attribute name="y"><xsl:value-of select="@Canvas.Top" /></xsl:attribute></xsl:if>  \r
112     <xsl:if test="@Width"><xsl:attribute name="width"><xsl:value-of select="@Width" /></xsl:attribute></xsl:if>  \r
113     <xsl:if test="@Height"><xsl:attribute name="height"><xsl:value-of select="@Height" /></xsl:attribute></xsl:if>  \r
114     <xsl:if test="@RadiusX"><xsl:attribute name="rx"><xsl:value-of select="@RadiusX" /></xsl:attribute></xsl:if>  \r
115     <xsl:if test="@RadiusY"><xsl:attribute name="ry"><xsl:value-of select="@RadiusY" /></xsl:attribute></xsl:if>  \r
116     <xsl:call-template name="template_properties" /> \r
117     <xsl:call-template name="template_transform" />\r
118     <xsl:call-template name="template_timeline_animations" />\r
119     <xsl:apply-templates mode="forward" />\r
120   </rect>\r
121 </xsl:template>\r
122 \r
123 <xsl:template mode="forward" match="*[name(.) = 'Polyline']">\r
124   <polyline>\r
125     <xsl:if test="@Points"><xsl:attribute name="points"><xsl:value-of select="@Points" /></xsl:attribute></xsl:if>\r
126     <xsl:attribute name="fill-rule">\r
127       <xsl:choose>\r
128         <xsl:when test="@FillRule = 'nonzero'">nonzero</xsl:when>\r
129         <xsl:when test="@FillRule = 'evenodd'">evenodd</xsl:when>\r
130       </xsl:choose>\r
131     </xsl:attribute>\r
132     <xsl:call-template name="template_properties" />  \r
133     <xsl:call-template name="template_transform" />  \r
134     <xsl:apply-templates mode="forward" />\r
135   </polyline>\r
136 </xsl:template>\r
137 \r
138 <xsl:template mode="forward" match="*[name(.) = 'Polygon']">\r
139   <polygon>\r
140     <xsl:if test="@Points"><xsl:attribute name="points"><xsl:value-of select="@Points" /></xsl:attribute></xsl:if>\r
141     <xsl:attribute name="fill-rule">\r
142       <xsl:choose>\r
143         <xsl:when test="@FillRule = 'nonzero'">nonzero</xsl:when>\r
144         <xsl:when test="@FillRule = 'evenodd'">evenodd</xsl:when>\r
145       </xsl:choose>\r
146     </xsl:attribute>\r
147     <xsl:call-template name="template_properties" />  \r
148     <xsl:call-template name="template_transform" />  \r
149     <xsl:apply-templates mode="forward" />\r
150   </polygon>\r
151 </xsl:template>\r
152 \r
153 <xsl:template mode="forward" match="*[name(.) = 'Glyphs']">\r
154   <defs>\r
155     <font-face>\r
156       <xsl:attribute name="font-family"><xsl:value-of select="concat('TrueType ', generate-id(.))" /></xsl:attribute>\r
157       <font-face-src><font-face-uri><xsl:attribute name="xlink:href"><xsl:value-of select="@FontUri" /></xsl:attribute></font-face-uri></font-face-src>\r
158     </font-face>\r
159   </defs>\r
160   <text>\r
161     <xsl:if test="@FontRenderingEmSize"><xsl:attribute name="font-size"><xsl:value-of select="@FontRenderingEmSize" /></xsl:attribute></xsl:if>\r
162     <xsl:if test="@OriginX"><xsl:attribute name="x"><xsl:value-of select="@OriginX" /></xsl:attribute></xsl:if>\r
163     <xsl:if test="@OriginY"><xsl:attribute name="y"><xsl:value-of select="@OriginY" /></xsl:attribute></xsl:if>\r
164     <xsl:attribute name="font-family"><xsl:value-of select="concat('TrueType ', generate-id(.))" /></xsl:attribute>\r
165     <xsl:call-template name="template_properties" />  \r
166     <xsl:call-template name="template_transform" />  \r
167     <xsl:if test="@UnicodeString"><xsl:value-of select="@UnicodeString" /></xsl:if>\r
168   </text>\r
169 </xsl:template>\r
170 \r
171 </xsl:stylesheet>\r