fix memory issues

This commit is contained in:
Mylloon 2024-05-06 20:16:34 +02:00
parent feec279622
commit 160cbc2516
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

66
svg.xsl
View file

@ -11,14 +11,6 @@
<!-- Template pour le traceur -->
<xsl:template match="traceur">
<!-- Tracé -->
<xsl:variable name="path">
<xsl:call-template name="generatePath">
<xsl:with-param name="idx" select="1" />
<xsl:with-param name="path" select="'M0 0 '" />
</xsl:call-template>
</xsl:variable>
<!-- Dimensions arbitraires -->
<xsl:variable
name="width" select="1000" />
@ -53,42 +45,52 @@
<!-- TODO : Faudrais faire en sorte que :
+ le scale est petit
+ l'épaisseur du tracé est épais -->
<g
<g stroke="black" fill="none"
transform="translate({$transX}, {$transY}) scale({$scale})">
<path d="{$path}" stroke="black" fill="none" />
<xsl:call-template name="generatePath" />
</g>
</xsl:template>
<!-- Fonction récursive terminale -->
<!-- Tracés -->
<xsl:template name="generatePath">
<xsl:param name="idx" />
<xsl:param name="path" />
<xsl:param name="idx"
select="1" />
<xsl:param name="x" select="0" />
<xsl:param name="y" select="0" />
<xsl:if
test="$idx lt count(*)">
<xsl:variable
name="action" select="*[position() = $idx]" />
<xsl:choose>
<xsl:when test="$idx > count(*)">
<xsl:value-of select="$path" />
<!-- 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>
<xsl:otherwise>
<xsl:variable
name="currentNode" select="*[position() = $idx]" />
<xsl:variable
name="pos" select="concat($currentNode/@x, ' ', $currentNode/@y)" />
<xsl:choose>
<xsl:when test="name($currentNode) = 'MOVETO'">
<xsl:call-template name="generatePath">
<!-- 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="path" select="concat($path, ' M', $pos)" />
<xsl:with-param name="x" select="$action/@x" />
<xsl:with-param name="y" select="$action/@y" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="generatePath">
<xsl:with-param name="idx" select="$idx + 1" />
<xsl:with-param name="path" select="concat($path, ' L', $pos)" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:transform>