try to center the image (probably don't work on something else than my screen)
This commit is contained in:
parent
cbd29f50a6
commit
7f64134886
1 changed files with 34 additions and 8 deletions
42
svg.xsl
42
svg.xsl
|
@ -4,14 +4,14 @@
|
|||
<xsl:output indent="yes" />
|
||||
|
||||
<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" />
|
||||
</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" />
|
||||
|
@ -19,14 +19,40 @@
|
|||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- TODO: usage temporaire d'un offset pour que l'image soit pas hors de
|
||||
l'écran, il faut trouver à l'avenir un moyen que ça soit automatique ?? -->
|
||||
<!-- Dimensions arbitraires -->
|
||||
<xsl:variable
|
||||
name="offset" select="250" />
|
||||
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" />
|
||||
|
||||
<g
|
||||
transform="translate({$offset}, {$offset})">
|
||||
<path
|
||||
d="{$path}" stroke="green" fill="none" />
|
||||
transform="translate({$transX}, {$transY}) scale({$scale})">
|
||||
<path d="{$path}" stroke="green" fill="none" />
|
||||
</g>
|
||||
</xsl:template>
|
||||
|
||||
|
|
Reference in a new issue