correctly center and adapt size
This commit is contained in:
parent
cb3b44aa1e
commit
1dec319eb4
2 changed files with 60 additions and 31 deletions
|
@ -128,6 +128,7 @@ Chacun a écrit les fichiers \xsd~correspondant à ses fichiers \xml.
|
|||
\item[6 mai\sp] Ajout de quelques \lsys{}s trouvés sur
|
||||
\href{https://onlinetools.com/math/l-system-generator}{onlinetools}
|
||||
et \href{https://anvaka.github.io/lsystem/}{anvaka/lsystem}
|
||||
\item[18 mai\,] Images \svg~correctement centrés.
|
||||
\end{description}
|
||||
|
||||
|
||||
|
@ -140,7 +141,6 @@ Dans cette partie, nous abordons les limitations de notre projet.
|
|||
|
||||
%\subsubsection*{Bugs}
|
||||
% TODO - uniquement s'il y a des bugs
|
||||
% Problème : quand `n' est grand, on a souvent des problèmes de mémoire
|
||||
|
||||
%\subsection{Omissions} % Ce qu'il manque
|
||||
% TODO - uniquement s'il y a des omissions
|
||||
|
|
89
svg.xsl
89
svg.xsl
|
@ -4,49 +4,78 @@
|
|||
<xsl:output indent="yes" />
|
||||
|
||||
<xsl:template match="/">
|
||||
<svg version="1.0" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<xsl:apply-templates select="traceur" />
|
||||
<xsl:variable name="maxX"
|
||||
select="max(*/*/@x)" />
|
||||
<xsl:variable name="maxY"
|
||||
select="max(*/*/@y)" />
|
||||
<xsl:variable name="minX"
|
||||
select="min(*/*/@x)" />
|
||||
<xsl:variable name="minY"
|
||||
select="min(*/*/@y)" />
|
||||
|
||||
<!-- Largeur et hauteur avec décalage -->
|
||||
<xsl:variable name="width"
|
||||
select="$maxX - $minX" />
|
||||
<xsl:variable name="height"
|
||||
select="$maxY - $minY" />
|
||||
|
||||
<svg
|
||||
version="1.0"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
viewBox="0 0 {$width} {$height}">
|
||||
<xsl:apply-templates select="traceur">
|
||||
<xsl:with-param name="minX" select="$minX" />
|
||||
<xsl:with-param name="minY" select="$minY" />
|
||||
<xsl:with-param name="strokeWidth">
|
||||
<!-- On prend le plus grand côté qu'on divise -->
|
||||
<xsl:variable name="d" select="1000" />
|
||||
<xsl:choose>
|
||||
<xsl:when test="$width > $height">
|
||||
<xsl:value-of select="$width div $d" />
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$height div $d" />
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:with-param>
|
||||
</xsl:apply-templates>
|
||||
</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" />
|
||||
<!-- Dimensions et largeur de trait -->
|
||||
<xsl:param name="minX" />
|
||||
<xsl:param name="minY" />
|
||||
<xsl:param name="strokeWidth" />
|
||||
|
||||
<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 -->
|
||||
<!-- Décalage -->
|
||||
<xsl:variable
|
||||
name="transX">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$y > $x">
|
||||
<xsl:value-of select="$x" />
|
||||
<xsl:when test="0 > $minX">
|
||||
<xsl:value-of select="abs($minX)" />
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$y" />
|
||||
<xsl:value-of select="0" />
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<xsl:variable
|
||||
name="transY">
|
||||
<xsl:choose>
|
||||
<xsl:when test="0 > $minY">
|
||||
<xsl:value-of select="abs($minY)" />
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="0" />
|
||||
</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})">
|
||||
<g
|
||||
stroke="black" stroke-width="{$strokeWidth}"
|
||||
transform="translate({$transX}, {$transY})">
|
||||
<xsl:call-template name="generatePath" />
|
||||
</g>
|
||||
</xsl:template>
|
||||
|
|
Reference in a new issue