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