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
|
\item[6 mai\sp] Ajout de quelques \lsys{}s trouvés sur
|
||||||
\href{https://onlinetools.com/math/l-system-generator}{onlinetools}
|
\href{https://onlinetools.com/math/l-system-generator}{onlinetools}
|
||||||
et \href{https://anvaka.github.io/lsystem/}{anvaka/lsystem}
|
et \href{https://anvaka.github.io/lsystem/}{anvaka/lsystem}
|
||||||
|
\item[18 mai\,] Images \svg~correctement centrés.
|
||||||
\end{description}
|
\end{description}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,7 +141,6 @@ Dans cette partie, nous abordons les limitations de notre projet.
|
||||||
|
|
||||||
%\subsubsection*{Bugs}
|
%\subsubsection*{Bugs}
|
||||||
% TODO - uniquement s'il y a des 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
|
%\subsection{Omissions} % Ce qu'il manque
|
||||||
% TODO - uniquement s'il y a des omissions
|
% TODO - uniquement s'il y a des omissions
|
||||||
|
|
89
svg.xsl
89
svg.xsl
|
@ -4,49 +4,78 @@
|
||||||
<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">
|
<xsl:variable name="maxX"
|
||||||
<xsl:apply-templates select="traceur" />
|
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>
|
</svg>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
<!-- Template pour le traceur -->
|
<!-- Template pour le traceur -->
|
||||||
<xsl:template match="traceur">
|
<xsl:template match="traceur">
|
||||||
<!-- Dimensions arbitraires -->
|
<!-- Dimensions et largeur de trait -->
|
||||||
<xsl:variable
|
<xsl:param name="minX" />
|
||||||
name="width" select="1000" />
|
<xsl:param name="minY" />
|
||||||
<xsl:variable
|
<xsl:param name="strokeWidth" />
|
||||||
name="height" select="800" />
|
|
||||||
|
|
||||||
<xsl:variable name="scale">
|
<!-- Décalage -->
|
||||||
<!-- Valeurs trouvés au fils de plusieurs tests -->
|
<xsl:variable
|
||||||
<xsl:variable name="dividende"
|
name="transX">
|
||||||
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 -->
|
|
||||||
<xsl:choose>
|
<xsl:choose>
|
||||||
<xsl:when test="$y > $x">
|
<xsl:when test="0 > $minX">
|
||||||
<xsl:value-of select="$x" />
|
<xsl:value-of select="abs($minX)" />
|
||||||
</xsl:when>
|
</xsl:when>
|
||||||
<xsl:otherwise>
|
<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:otherwise>
|
||||||
</xsl:choose>
|
</xsl:choose>
|
||||||
</xsl:variable>
|
</xsl:variable>
|
||||||
|
|
||||||
|
<g
|
||||||
<!-- Translation pour être à peu près centré -->
|
stroke="black" stroke-width="{$strokeWidth}"
|
||||||
<xsl:variable
|
transform="translate({$transX}, {$transY})">
|
||||||
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})">
|
|
||||||
<xsl:call-template name="generatePath" />
|
<xsl:call-template name="generatePath" />
|
||||||
</g>
|
</g>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
Reference in a new issue