2024-05-04 02:42:50 +02:00
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version= "2.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg">
<xsl:output indent= "yes" />
<xsl:template match= "/" >
2024-05-05 23:29:11 +02:00
<svg version= "1.0" xmlns:xlink= "http://www.w3.org/1999/xlink" >
2024-05-04 02:42:50 +02:00
<xsl:apply-templates select= "traceur" />
</svg>
</xsl:template>
<!-- Template pour le traceur -->
<xsl:template match= "traceur" >
2024-05-05 23:29:11 +02:00
<!-- Tracé -->
2024-05-04 02:42:50 +02:00
<xsl:variable name= "path" >
<xsl:call-template name= "generatePath" >
<xsl:with-param name= "idx" select= "1" />
2024-05-05 21:29:23 +02:00
<xsl:with-param name= "path" select= "'M 0 0 '" />
2024-05-04 02:42:50 +02:00
</xsl:call-template>
</xsl:variable>
2024-05-05 23:29:11 +02:00
<!-- Dimensions arbitraires -->
2024-05-05 21:29:23 +02:00
<xsl:variable
2024-05-05 23:29:11 +02:00
name="width" select="1000" />
<xsl:variable
name="height" select="800" />
<xsl:variable name= "scale" >
<!-- Valeurs trouvés au fils de plusieurs tests -->
<xsl:variable name= "x"
select="$width div max(LINETO/@x) div 1.4" />
<xsl:variable name= "y"
select="$height div max(LINETO/@y) div 1.4" />
<!-- La plus petite valeur entre X et Y -->
<xsl:choose >
<xsl:when test= "$y > $x" >
<xsl:value-of select= "$x " />
</xsl:when>
<xsl:otherwise >
<xsl:value-of select= "$y" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Translation pour être à peu près centré -->
<xsl:variable
name="transX" select="($width * 1.2) - max(LINETO/@x) * $scale" />
<xsl:variable
name="transY" select="$height - max(LINETO/@y) * $scale" />
2024-05-06 00:34:58 +02:00
<!-- TODO : Faudrais faire en sorte que :
+ le scale est petit
+ l'épaisseur du tracé est épais -->
2024-05-05 21:29:23 +02:00
<g
2024-05-05 23:29:11 +02:00
transform="translate({$transX}, {$transY}) scale({$scale})">
2024-05-05 23:38:31 +02:00
<path d= "{$path}" stroke= "black" fill= "none" />
2024-05-05 21:29:23 +02:00
</g>
2024-05-04 02:42:50 +02:00
</xsl:template>
<!-- Fonction récursive terminale -->
<xsl:template name= "generatePath" >
<xsl:param name= "idx" />
<xsl:param name= "path" />
<xsl:choose >
<xsl:when test= "$idx > count(LINETO)" >
<xsl:value-of select= "$path" />
</xsl:when>
<xsl:otherwise >
<xsl:variable name= "x"
2024-05-05 21:29:23 +02:00
select="LINETO[$idx]/@x" />
2024-05-04 02:42:50 +02:00
<xsl:variable name= "y"
2024-05-05 21:29:23 +02:00
select="LINETO[$idx]/@y" />
2024-05-04 02:42:50 +02:00
<xsl:call-template name= "generatePath" >
<xsl:with-param name= "idx" select= "$idx + 1" />
<xsl:with-param name= "path" select= "concat($path, ' L ', $x, ' ', $y)" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:transform>