96 lines
3.2 KiB
XML
96 lines
3.2 KiB
XML
<?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="/">
|
|
<svg version="1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<xsl:apply-templates select="traceur" />
|
|
</svg>
|
|
</xsl:template>
|
|
|
|
<!-- Template pour le traceur -->
|
|
<xsl:template match="traceur">
|
|
<!-- Dimensions arbitraires -->
|
|
<xsl:variable
|
|
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="dividende"
|
|
select="1.4" />
|
|
<xsl:variable name="x"
|
|
select="$width div max(*/@x) div $dividende" />
|
|
<xsl:variable name="y"
|
|
select="$height div max(*/@y) div $dividende" />
|
|
|
|
<!-- 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(*/@x ) * $scale" />
|
|
<xsl:variable
|
|
name="transY" select="$height - max(*/@y) * $scale" />
|
|
|
|
<g stroke="black"
|
|
stroke-width="{1 div $scale}"
|
|
transform="translate({$transX}, {$transY}) scale({$scale})">
|
|
<xsl:call-template name="generatePath" />
|
|
</g>
|
|
</xsl:template>
|
|
|
|
<!-- Tracés -->
|
|
<xsl:template name="generatePath">
|
|
<xsl:param name="idx"
|
|
select="1" />
|
|
<xsl:param name="x" select="0" />
|
|
<xsl:param name="y" select="0" />
|
|
|
|
<xsl:if
|
|
test="count(*) >= $idx">
|
|
<xsl:variable
|
|
name="action" select="*[position() = $idx]" />
|
|
|
|
<xsl:choose>
|
|
<!-- Déplacement -->
|
|
<xsl:when test="name($action) = 'MOVETO'">
|
|
<xsl:call-template name="generatePath">
|
|
<xsl:with-param name="idx" select="$idx + 1" />
|
|
<xsl:with-param name="x" select="$action/@x" />
|
|
<xsl:with-param name="y" select="$action/@y" />
|
|
</xsl:call-template>
|
|
</xsl:when>
|
|
|
|
<!-- Ecriture -->
|
|
<xsl:when test="name($action) = 'LINETO'">
|
|
<xsl:variable name="pos"
|
|
select="concat($x, ' ', $y)" />
|
|
<xsl:variable name="nouvellePos"
|
|
select="concat($action/@x, ' ', $action/@y)" />
|
|
|
|
<path
|
|
d="{concat('M', $pos, ' L', $nouvellePos)}" />
|
|
|
|
<xsl:call-template
|
|
name="generatePath">
|
|
<xsl:with-param name="idx" select="$idx + 1" />
|
|
<xsl:with-param name="x" select="$action/@x" />
|
|
<xsl:with-param name="y" select="$action/@y" />
|
|
</xsl:call-template>
|
|
</xsl:when>
|
|
</xsl:choose>
|
|
</xsl:if>
|
|
</xsl:template>
|
|
</xsl:transform>
|