format
This commit is contained in:
parent
e9ae88daf5
commit
1215d802bd
1 changed files with 68 additions and 69 deletions
137
svg.xsl
137
svg.xsl
|
@ -1,85 +1,84 @@
|
|||
<?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" />
|
||||
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>
|
||||
<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">
|
||||
<!-- Tracé -->
|
||||
<xsl:variable name="path">
|
||||
<xsl:call-template name="generatePath">
|
||||
<xsl:with-param name="idx" select="1" />
|
||||
<xsl:with-param name="path" select="'M 0 0 '" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<!-- 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="'M 0 0 '" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- Dimensions arbitraires -->
|
||||
<xsl:variable
|
||||
name="width" select="1000" />
|
||||
<xsl:variable
|
||||
name="height" select="800" />
|
||||
<!-- 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="x"
|
||||
select="$width div max(LINETO/@x) div 1.4" />
|
||||
<xsl:variable name="y"
|
||||
select="$height div max(LINETO/@y) div 1.4" />
|
||||
<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>
|
||||
<!-- 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" />
|
||||
<!-- 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" />
|
||||
|
||||
<!-- TODO : Faudrais faire en sorte que :
|
||||
<!-- TODO : Faudrais faire en sorte que :
|
||||
+ le scale est petit
|
||||
+ l'épaisseur du tracé est épais -->
|
||||
<g
|
||||
transform="translate({$transX}, {$transY}) scale({$scale})">
|
||||
<path d="{$path}" stroke="black" fill="none" />
|
||||
</g>
|
||||
</xsl:template>
|
||||
<g
|
||||
transform="translate({$transX}, {$transY}) scale({$scale})">
|
||||
<path d="{$path}" stroke="black" fill="none" />
|
||||
</g>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Fonction récursive terminale -->
|
||||
<xsl:template name="generatePath">
|
||||
<xsl:param name="idx" />
|
||||
<xsl:param name="path" />
|
||||
<!-- 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"
|
||||
select="LINETO[$idx]/@x" />
|
||||
<xsl:variable name="y"
|
||||
select="LINETO[$idx]/@y" />
|
||||
|
||||
<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:choose>
|
||||
<xsl:when test="$idx > count(LINETO)">
|
||||
<xsl:value-of select="$path" />
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:variable name="x"
|
||||
select="LINETO[$idx]/@x" />
|
||||
<xsl:variable name="y"
|
||||
select="LINETO[$idx]/@y" />
|
||||
|
||||
<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>
|
||||
|
|
Reference in a new issue