4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/moinformat/resources/notugly.xsl Mon Jul 01 19:22:49 2019 +0200
4.3 @@ -0,0 +1,584 @@
4.4 +<?xml version="1.0" ?>
4.5 +
4.6 +<!--
4.7 +Copied from diagram-tools:
4.8 +
4.9 +http://www.hokstad.com/making-graphviz-output-pretty-with-xsl.html
4.10 +
4.11 +Copyright (c) 2012 Vidar Hokstad <vidar@hokstad.com>
4.12 +Copyright (c) 2016, 2019 Paul Boddie <paul@boddie.org.uk>
4.13 +
4.14 +Permission is hereby granted, free of charge, to any person obtaining a
4.15 +copy of this software and associated documentation files (the "Software"),
4.16 +to deal in the Software without restriction, including without limitation
4.17 +the rights to use, copy, modify, merge, publish, distribute, sublicense,
4.18 +and/or sell copies of the Software, and to permit persons to whom the
4.19 +Software is furnished to do so, subject to the following conditions:
4.20 +
4.21 +The above copyright notice and this permission notice shall be included
4.22 +in all copies or substantial portions of the Software.
4.23 +
4.24 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
4.25 +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4.26 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
4.27 +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
4.28 +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
4.29 +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
4.30 +OTHER DEALINGS IN THE SOFTWARE.
4.31 +-->
4.32 +
4.33 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
4.34 + xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg">
4.35 +<xsl:output method="xml" indent="yes"
4.36 + doctype-public="-//W3C//DTD SVG 1.0//EN"
4.37 + doctype-system="http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"/>
4.38 +
4.39 +<xsl:variable name="text-style">font-size:10px; font-family:sans-serif;</xsl:variable>
4.40 +
4.41 +<!-- Used to generate unique gradient fills for colors given by hex value
4.42 + Search for generate-id to find where its used
4.43 +-->
4.44 +<xsl:key name="fills" match="*" use="@fill"/>
4.45 +
4.46 +<xsl:template match="@*|node()">
4.47 + <xsl:copy>
4.48 + <xsl:apply-templates select="@*|node()"/>
4.49 + </xsl:copy>
4.50 +</xsl:template>
4.51 +
4.52 +<xsl:template match="svg:svg">
4.53 + <svg xmlns="http://www.w3.org/2000/svg">
4.54 + <!-- Order is important here, so the attributes below overrides the
4.55 + originals, which are copied "wholesale" -->
4.56 + <xsl:apply-templates select="@*" />
4.57 +
4.58 + <defs>
4.59 + <linearGradient id="white" x1="0%" y1="0%" x2="0%" y2="0%">
4.60 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.61 + </linearGradient>
4.62 +
4.63 + <linearGradient id="black" x1="0%" y1="0%" x2="0%" y2="0%">
4.64 + <stop offset="0%" style="stop-color:rgb(0,0,0);stop-opacity:1"/>
4.65 + </linearGradient>
4.66 +
4.67 + <linearGradient id="aquamarine" x1="0%" y1="0%" x2="100%" y2="100%">
4.68 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.69 + <stop offset="100%" style="stop-color:rgb(127,255,212);stop-opacity:1"/>
4.70 + </linearGradient>
4.71 +
4.72 + <linearGradient id="azure" x1="0%" y1="0%" x2="100%" y2="100%">
4.73 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.74 + <stop offset="100%" style="stop-color:rgb(240,255,255);stop-opacity:1"/>
4.75 + </linearGradient>
4.76 +
4.77 + <linearGradient id="blue" x1="0%" y1="0%" x2="100%" y2="100%">
4.78 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.79 + <stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1"/>
4.80 + </linearGradient>
4.81 +
4.82 + <linearGradient id="blueviolet" x1="0%" y1="0%" x2="100%" y2="100%">
4.83 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.84 + <stop offset="100%" style="stop-color:rgb(138,43,226);stop-opacity:1"/>
4.85 + </linearGradient>
4.86 +
4.87 + <linearGradient id="brown" x1="0%" y1="0%" x2="100%" y2="100%">
4.88 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.89 + <stop offset="100%" style="stop-color:rgb(165,42,42);stop-opacity:1"/>
4.90 + </linearGradient>
4.91 +
4.92 + <linearGradient id="cadetblue" x1="0%" y1="0%" x2="100%" y2="100%">
4.93 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.94 + <stop offset="100%" style="stop-color:rgb(95,158,160);stop-opacity:1"/>
4.95 + </linearGradient>
4.96 +
4.97 + <linearGradient id="chocolate" x1="0%" y1="0%" x2="100%" y2="100%">
4.98 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.99 + <stop offset="100%" style="stop-color:rgb(210,105,30);stop-opacity:1"/>
4.100 + </linearGradient>
4.101 +
4.102 + <linearGradient id="cornflowerblue" x1="0%" y1="0%" x2="100%" y2="100%">
4.103 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.104 + <stop offset="100%" style="stop-color:rgb(100,149,237);stop-opacity:1"/>
4.105 + </linearGradient>
4.106 +
4.107 + <linearGradient id="crimson" x1="0%" y1="0%" x2="100%" y2="100%">
4.108 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.109 + <stop offset="100%" style="stop-color:rgb(220,20,60);stop-opacity:1"/>
4.110 + </linearGradient>
4.111 +
4.112 + <linearGradient id="cyan" x1="0%" y1="0%" x2="100%" y2="100%">
4.113 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.114 + <stop offset="100%" style="stop-color:rgb(0,255,255);stop-opacity:1"/>
4.115 + </linearGradient>
4.116 +
4.117 + <linearGradient id="darkgreen" x1="0%" y1="0%" x2="100%" y2="100%">
4.118 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.119 + <stop offset="100%" style="stop-color:rgb(0,100,0);stop-opacity:1"/>
4.120 + </linearGradient>
4.121 +
4.122 + <linearGradient id="darkorange" x1="0%" y1="0%" x2="100%" y2="100%">
4.123 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.124 + <stop offset="100%" style="stop-color:rgb(255,140,0);stop-opacity:1"/>
4.125 + </linearGradient>
4.126 +
4.127 + <linearGradient id="gold" x1="0%" y1="0%" x2="100%" y2="100%">
4.128 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.129 + <stop offset="100%" style="stop-color:rgb(255,215,0);stop-opacity:1"/>
4.130 + </linearGradient>
4.131 +
4.132 + <linearGradient id="gray" x1="0%" y1="0%" x2="100%" y2="100%">
4.133 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.134 + <stop offset="100%" style="stop-color:rgb(192,192,192);stop-opacity:1"/>
4.135 + </linearGradient>
4.136 +
4.137 + <linearGradient id="greenyellow" x1="0%" y1="0%" x2="100%" y2="100%">
4.138 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.139 + <stop offset="100%" style="stop-color:rgb(173,255,47);stop-opacity:1"/>
4.140 + </linearGradient>
4.141 +
4.142 + <linearGradient id="green" x1="0%" y1="0%" x2="100%" y2="100%">
4.143 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.144 + <stop offset="100%" style="stop-color:rgb(0,255,0);stop-opacity:1"/>
4.145 + </linearGradient>
4.146 +
4.147 + <linearGradient id="grey" x1="0%" y1="0%" x2="100%" y2="100%">
4.148 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.149 + <stop offset="100%" style="stop-color:rgb(192,192,192);stop-opacity:1"/>
4.150 + </linearGradient>
4.151 +
4.152 + <linearGradient id="hotpink" x1="0%" y1="0%" x2="100%" y2="100%">
4.153 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.154 + <stop offset="100%" style="stop-color:rgb(255,105,180);stop-opacity:1"/>
4.155 + </linearGradient>
4.156 +
4.157 + <linearGradient id="indianred" x1="0%" y1="0%" x2="100%" y2="100%">
4.158 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.159 + <stop offset="100%" style="stop-color:rgb(205,92,92);stop-opacity:1"/>
4.160 + </linearGradient>
4.161 +
4.162 + <linearGradient id="indigo" x1="0%" y1="0%" x2="100%" y2="100%">
4.163 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.164 + <stop offset="100%" style="stop-color:rgb(75,0,130);stop-opacity:1"/>
4.165 + </linearGradient>
4.166 +
4.167 + <linearGradient id="lavender" x1="0%" y1="0%" x2="100%" y2="100%">
4.168 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.169 + <stop offset="100%" style="stop-color:rgb(230,230,250);stop-opacity:1"/>
4.170 + </linearGradient>
4.171 +
4.172 + <linearGradient id="lightblue" x1="0%" y1="0%" x2="100%" y2="100%">
4.173 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.174 + <stop offset="100%" style="stop-color:rgb(173,216,230);stop-opacity:1"/>
4.175 + </linearGradient>
4.176 +
4.177 + <linearGradient id="lightgray" x1="0%" y1="0%" x2="100%" y2="100%">
4.178 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.179 + <stop offset="100%" style="stop-color:rgb(211,211,211);stop-opacity:1"/>
4.180 + </linearGradient>
4.181 +
4.182 + <linearGradient id="lightgrey" x1="0%" y1="0%" x2="100%" y2="100%">
4.183 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.184 + <stop offset="100%" style="stop-color:rgb(211,211,211);stop-opacity:1"/>
4.185 + </linearGradient>
4.186 +
4.187 + <linearGradient id="magenta" x1="0%" y1="0%" x2="100%" y2="100%">
4.188 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.189 + <stop offset="100%" style="stop-color:rgb(255,0,255);stop-opacity:1"/>
4.190 + </linearGradient>
4.191 +
4.192 + <linearGradient id="maroon" x1="0%" y1="0%" x2="100%" y2="100%">
4.193 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.194 + <stop offset="100%" style="stop-color:rgb(176,48,96);stop-opacity:1"/>
4.195 + </linearGradient>
4.196 +
4.197 + <linearGradient id="mediumblue" x1="0%" y1="0%" x2="100%" y2="100%">
4.198 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.199 + <stop offset="100%" style="stop-color:rgb(0,0,205);stop-opacity:1"/>
4.200 + </linearGradient>
4.201 +
4.202 + <linearGradient id="mediumpurple" x1="0%" y1="0%" x2="100%" y2="100%">
4.203 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.204 + <stop offset="100%" style="stop-color:rgb(147,112,219);stop-opacity:1"/>
4.205 + </linearGradient>
4.206 +
4.207 + <linearGradient id="orange" x1="0%" y1="0%" x2="100%" y2="100%">
4.208 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.209 + <stop offset="100%" style="stop-color:rgb(255,165,0);stop-opacity:1"/>
4.210 + </linearGradient>
4.211 +
4.212 + <linearGradient id="pink" x1="0%" y1="0%" x2="100%" y2="100%">
4.213 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.214 + <stop offset="100%" style="stop-color:rgb(255,192,203);stop-opacity:1"/>
4.215 + </linearGradient>
4.216 +
4.217 + <linearGradient id="purple" x1="0%" y1="0%" x2="100%" y2="100%">
4.218 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.219 + <stop offset="100%" style="stop-color:rgb(160,32,240);stop-opacity:1"/>
4.220 + </linearGradient>
4.221 +
4.222 + <linearGradient id="red" x1="0%" y1="0%" x2="100%" y2="100%">
4.223 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.224 + <stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1"/>
4.225 + </linearGradient>
4.226 +
4.227 + <linearGradient id="steelblue" x1="0%" y1="0%" x2="100%" y2="100%">
4.228 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.229 + <stop offset="100%" style="stop-color:rgb(70,130,180);stop-opacity:1"/>
4.230 + </linearGradient>
4.231 +
4.232 + <linearGradient id="violet" x1="0%" y1="0%" x2="100%" y2="100%">
4.233 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.234 + <stop offset="100%" style="stop-color:rgb(238,130,238);stop-opacity:1"/>
4.235 + </linearGradient>
4.236 +
4.237 + <linearGradient id="yellow" x1="0%" y1="0%" x2="100%" y2="100%">
4.238 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.239 + <stop offset="100%" style="stop-color:rgb(255,255,0);stop-opacity:1"/>
4.240 + </linearGradient>
4.241 +
4.242 + <linearGradient id="none" x1="0%" y1="0%" x2="100%" y2="100%">
4.243 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.244 + <stop offset="100%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.245 + </linearGradient>
4.246 +
4.247 + <xsl:for-each select="*//*[generate-id() = generate-id(key('fills',@fill)[1])][substring(@fill,1,1)='#']">
4.248 + <linearGradient x1="0%" y1="0%" x2="100%" y2="100%">
4.249 + <xsl:attribute name="id">fill-<xsl:value-of select="substring(@fill,2,6)"/></xsl:attribute>
4.250 + <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
4.251 + <stop offset="100%">
4.252 + <xsl:attribute name="style">stop-color:<xsl:value-of select="@fill" />;stop-opacity:1</xsl:attribute>
4.253 + </stop>
4.254 + </linearGradient>
4.255 + </xsl:for-each>
4.256 +
4.257 + </defs>
4.258 +
4.259 +
4.260 + <xsl:apply-templates />
4.261 + </svg>
4.262 +</xsl:template>
4.263 +
4.264 +<!-- Match the top most "g" -->
4.265 +<xsl:template match="/svg:svg/svg:g">
4.266 + <g>
4.267 + <xsl:apply-templates select="@*"/>
4.268 + <!-- Graphviz uses a polygon as the background. Don't want a gradient there -->
4.269 + <xsl:for-each select="svg:polygon">
4.270 + <xsl:copy><xsl:apply-templates select="@*" /></xsl:copy>
4.271 + </xsl:for-each>
4.272 + <xsl:apply-templates select="svg:title|svg:g" />
4.273 + </g>
4.274 +</xsl:template>
4.275 +
4.276 +
4.277 +<xsl:template match="svg:text">
4.278 + <text>
4.279 + <xsl:apply-templates select="@*" />
4.280 + <xsl:if test="not(@font-family) and not(@font-size)">
4.281 + <xsl:attribute name="style"><xsl:value-of select="$text-style" /></xsl:attribute>
4.282 + </xsl:if>
4.283 + <xsl:apply-templates select="text()"/>
4.284 + </text>
4.285 +</xsl:template>
4.286 +
4.287 +
4.288 +<xsl:template match="svg:g">
4.289 + <xsl:copy>
4.290 + <xsl:apply-templates select="@*" />
4.291 + <xsl:choose>
4.292 + <!-- Handle linked groups. -->
4.293 + <xsl:when test="svg:a">
4.294 + <xsl:for-each select="svg:a">
4.295 + <xsl:copy>
4.296 + <xsl:apply-templates select="@*" />
4.297 + <xsl:call-template name="group">
4.298 + <xsl:with-param name="class" select="../@class"/>
4.299 + </xsl:call-template>
4.300 + </xsl:copy>
4.301 + </xsl:for-each>
4.302 + <!-- Handle labels. -->
4.303 + <xsl:apply-templates select="svg:text" />
4.304 + </xsl:when>
4.305 + <!-- Handle bare groups. -->
4.306 + <xsl:otherwise>
4.307 + <xsl:call-template name="group"/>
4.308 + </xsl:otherwise>
4.309 + </xsl:choose>
4.310 + </xsl:copy>
4.311 +</xsl:template>
4.312 +
4.313 +
4.314 +<xsl:template name="group">
4.315 + <xsl:param name="class" select="@class"/>
4.316 +
4.317 + <!-- Process any subgroups, apparent in Graphviz 2.38.0 output. -->
4.318 + <xsl:apply-templates select="svg:g"/>
4.319 +
4.320 + <!-- Produce shadows for nodes. -->
4.321 + <xsl:for-each select="svg:polygon|svg:ellipse">
4.322 + <xsl:call-template name="poly-shadow" />
4.323 + </xsl:for-each>
4.324 +
4.325 + <xsl:choose>
4.326 + <!-- Rewrite node outlines. -->
4.327 + <xsl:when test="$class='node' and svg:path|svg:polyline">
4.328 + <xsl:call-template name="node-outline">
4.329 + <xsl:with-param name="current" select="*[1]"/>
4.330 + <xsl:with-param name="style">shadow</xsl:with-param>
4.331 + </xsl:call-template>
4.332 + </xsl:when>
4.333 + <xsl:otherwise>
4.334 + <xsl:for-each select="svg:path">
4.335 + <xsl:call-template name="path-shadow-edge" />
4.336 + </xsl:for-each>
4.337 + </xsl:otherwise>
4.338 + </xsl:choose>
4.339 +
4.340 + <xsl:for-each select="svg:polygon|svg:ellipse">
4.341 + <xsl:sort select="@ry" order="descending" />
4.342 + <xsl:call-template name="poly-main" />
4.343 + </xsl:for-each>
4.344 +
4.345 + <xsl:choose>
4.346 + <!-- Rewrite node outlines. -->
4.347 + <xsl:when test="$class='node' and svg:path|svg:polyline">
4.348 + <xsl:call-template name="node-outline">
4.349 + <xsl:with-param name="current" select="*[1]"/>
4.350 + </xsl:call-template>
4.351 + </xsl:when>
4.352 + <xsl:otherwise>
4.353 + <xsl:for-each select="svg:path">
4.354 + <path><xsl:apply-templates select="@*" /></path>
4.355 + </xsl:for-each>
4.356 + </xsl:otherwise>
4.357 + </xsl:choose>
4.358 +
4.359 + <!-- Handle labels. -->
4.360 + <xsl:apply-templates select="svg:text" />
4.361 +</xsl:template>
4.362 +
4.363 +<xsl:template name="node-outline">
4.364 + <xsl:param name="path-so-far"/>
4.365 + <xsl:param name="current"/>
4.366 + <xsl:param name="style"/>
4.367 +
4.368 + <xsl:choose>
4.369 + <!-- Visit each child element, collecting the path details. -->
4.370 + <xsl:when test="$current">
4.371 + <xsl:choose>
4.372 + <xsl:when test="local-name($current) = 'path'">
4.373 + <xsl:call-template name="filter-path">
4.374 + <xsl:with-param name="path-so-far" select="$path-so-far"/>
4.375 + <xsl:with-param name="point" select="substring-before($current/@d, 'C')"/>
4.376 + <xsl:with-param name="points" select="concat('C', substring-after($current/@d, 'C'))"/>
4.377 + <xsl:with-param name="current" select="$current"/>
4.378 + <xsl:with-param name="style" select="$style"/>
4.379 + </xsl:call-template>
4.380 + </xsl:when>
4.381 + <xsl:when test="local-name($current) = 'polyline'">
4.382 + <xsl:call-template name="polyline-to-path">
4.383 + <xsl:with-param name="path-so-far" select="$path-so-far"/>
4.384 + <xsl:with-param name="point" select="concat('M', substring-before($current/@points, ' '))"/>
4.385 + <xsl:with-param name="points" select="substring-after($current/@points, ' ')"/>
4.386 + <xsl:with-param name="current" select="$current"/>
4.387 + <xsl:with-param name="style" select="$style"/>
4.388 + </xsl:call-template>
4.389 + </xsl:when>
4.390 + <xsl:otherwise>
4.391 + <xsl:call-template name="node-outline">
4.392 + <xsl:with-param name="path-so-far" select="$path-so-far"/>
4.393 + <xsl:with-param name="current" select="$current/following-sibling::*[1]"/>
4.394 + <xsl:with-param name="style" select="$style"/>
4.395 + </xsl:call-template>
4.396 + </xsl:otherwise>
4.397 + </xsl:choose>
4.398 + </xsl:when>
4.399 + <!-- With no more elements to visit, generate the path. -->
4.400 + <xsl:otherwise>
4.401 + <xsl:choose>
4.402 + <xsl:when test="$style = 'shadow'">
4.403 + <path style="fill: black; stroke: none; fill-opacity:0.15" transform="translate(3,3)"
4.404 + d="{$path-so-far}"/>
4.405 + </xsl:when>
4.406 + <xsl:otherwise>
4.407 + <!-- Provide the path attributes using dynamic colour discoveries. -->
4.408 + <xsl:element name="path">
4.409 + <xsl:attribute name="d"><xsl:value-of select="$path-so-far"/></xsl:attribute>
4.410 + <xsl:call-template name="make-style-attribute">
4.411 + <xsl:with-param name="fill"
4.412 + select="normalize-space(substring-after(substring-before(ancestor::*[svg:polygon]/svg:polygon[1]/@style,';'),'fill:'))"/>
4.413 + <xsl:with-param name="fill-explicit"
4.414 + select="@fill"/>
4.415 + <xsl:with-param name="stroke"
4.416 + select="normalize-space(substring-after(substring-before(ancestor::*[svg:polygon]/svg:polygon[1]/@style,';'),'stroke:'))"/>
4.417 + <xsl:with-param name="stroke-explicit">black</xsl:with-param>
4.418 + <xsl:with-param name="none-is-transparent" select="true()"/>
4.419 + </xsl:call-template>
4.420 + </xsl:element>
4.421 + </xsl:otherwise>
4.422 + </xsl:choose>
4.423 + </xsl:otherwise>
4.424 + </xsl:choose>
4.425 +</xsl:template>
4.426 +
4.427 +<xsl:template name="filter-path">
4.428 + <xsl:param name="path-so-far"/>
4.429 + <xsl:param name="point"/>
4.430 + <xsl:param name="points"/>
4.431 + <xsl:param name="current"/>
4.432 + <xsl:param name="style"/>
4.433 +
4.434 + <xsl:variable name="next" select="substring-before($points, ' ')"/>
4.435 + <xsl:variable name="remaining" select="substring-after($points, ' ')"/>
4.436 +
4.437 + <xsl:choose>
4.438 + <!-- With path points remaining, include the current point if appropriate
4.439 + and visit those remaining. -->
4.440 + <xsl:when test="$remaining">
4.441 + <xsl:call-template name="filter-path">
4.442 + <xsl:with-param name="path-so-far" select="concat($path-so-far, ' ', $point)"/>
4.443 + <xsl:with-param name="point" select="$next"/>
4.444 + <xsl:with-param name="points" select="$remaining"/>
4.445 + <xsl:with-param name="current" select="$current"/>
4.446 + <xsl:with-param name="style" select="$style"/>
4.447 + </xsl:call-template>
4.448 + </xsl:when>
4.449 + <!-- With up to one remaining after this point, include the current point,
4.450 + if appropriate, and the one remaining. -->
4.451 + <xsl:otherwise>
4.452 + <xsl:call-template name="node-outline">
4.453 + <xsl:with-param name="path-so-far" select="concat($path-so-far, ' ', $point, ' ', $points)"/>
4.454 + <xsl:with-param name="current" select="$current/following-sibling::*[1]"/>
4.455 + <xsl:with-param name="style" select="$style"/>
4.456 + <xsl:with-param name="last" select="$current"/>
4.457 + </xsl:call-template>
4.458 + </xsl:otherwise>
4.459 + </xsl:choose>
4.460 +</xsl:template>
4.461 +
4.462 +<xsl:template name="polyline-to-path">
4.463 + <xsl:param name="path-so-far"/>
4.464 + <xsl:param name="point"/>
4.465 + <xsl:param name="points"/>
4.466 + <xsl:param name="current"/>
4.467 + <xsl:param name="style"/>
4.468 +
4.469 + <xsl:variable name="next" select="substring-before($points, ' ')"/>
4.470 + <xsl:variable name="remaining" select="substring-after($points, ' ')"/>
4.471 +
4.472 + <xsl:choose>
4.473 + <!-- With path points remaining, include the current point if appropriate
4.474 + and visit those remaining. -->
4.475 + <xsl:when test="$remaining">
4.476 + <xsl:call-template name="polyline-to-path">
4.477 + <xsl:with-param name="path-so-far" select="concat($path-so-far, ' ', $point)"/>
4.478 + <xsl:with-param name="point" select="concat('L', $next)"/>
4.479 + <xsl:with-param name="points" select="$remaining"/>
4.480 + <xsl:with-param name="current" select="$current"/>
4.481 + <xsl:with-param name="style" select="$style"/>
4.482 + </xsl:call-template>
4.483 + </xsl:when>
4.484 + <!-- With up to one remaining after this point, include the current point,
4.485 + if appropriate, and the one remaining. -->
4.486 + <xsl:otherwise>
4.487 + <xsl:call-template name="node-outline">
4.488 + <xsl:with-param name="path-so-far" select="concat($path-so-far, ' ', $point, ' L', $points)"/>
4.489 + <xsl:with-param name="current" select="$current/following-sibling::*[1]"/>
4.490 + <xsl:with-param name="style" select="$style"/>
4.491 + <xsl:with-param name="last" select="$current"/>
4.492 + </xsl:call-template>
4.493 + </xsl:otherwise>
4.494 + </xsl:choose>
4.495 +</xsl:template>
4.496 +
4.497 +<xsl:template name="poly-shadow">
4.498 + <xsl:element name="{name()}">
4.499 + <xsl:apply-templates select="@*"/>
4.500 + <xsl:attribute name="style">fill: black; stroke: none; fill-opacity:0.3</xsl:attribute>
4.501 + <xsl:attribute name="transform">translate(3,3)</xsl:attribute>
4.502 + </xsl:element>
4.503 +</xsl:template>
4.504 +
4.505 +<xsl:template name="path-shadow-edge">
4.506 + <xsl:element name="{name()}">
4.507 + <xsl:apply-templates select="@*"/>
4.508 + <xsl:attribute name="style">fill: none; stroke: black; stroke-opacity:0.3</xsl:attribute>
4.509 + <xsl:attribute name="transform">translate(3,3)</xsl:attribute>
4.510 + </xsl:element>
4.511 +</xsl:template>
4.512 +
4.513 +<xsl:template name="poly-main">
4.514 + <xsl:element name="{name()}">
4.515 + <xsl:apply-templates select="@*" />
4.516 + <xsl:call-template name="make-style-attribute">
4.517 + <xsl:with-param name="fill"
4.518 + select="normalize-space(substring-after(substring-before(@style,';'),'fill:'))"/>
4.519 + <xsl:with-param name="fill-explicit"
4.520 + select="@fill"/>
4.521 + <xsl:with-param name="stroke"
4.522 + select="normalize-space(substring-after(substring-after(@style,';'),'stroke:'))"/>
4.523 + <xsl:with-param name="stroke-explicit"
4.524 + select="@stroke"/>
4.525 + </xsl:call-template>
4.526 + </xsl:element>
4.527 +</xsl:template>
4.528 +
4.529 +<xsl:template name="path-main">
4.530 + <path>
4.531 + <xsl:apply-templates select="@*" />
4.532 + <!-- This is somewhat broken - the gradient is set based on the position/size of the element it is used with; as a result it doesn't line up properly with the main polygon -->
4.533 + <xsl:call-template name="make-style-attribute">
4.534 + <xsl:with-param name="fill"
4.535 + select="normalize-space(substring-after(substring-before(ancestor::*[svg:polygon]/svg:polygon[1]/@style,';'),'fill:'))"/>
4.536 + <xsl:with-param name="fill-explicit"
4.537 + select="ancestor::*[svg:polygon]/svg:polygon[1]/@fill"/>
4.538 + <xsl:with-param name="stroke"
4.539 + select="normalize-space(substring-after(substring-before(ancestor::*[svg:polygon]/svg:polygon[1]/@style,';'),'stroke:'))"/>
4.540 + <xsl:with-param name="stroke-explicit">black</xsl:with-param>
4.541 + </xsl:call-template>
4.542 + </path>
4.543 +</xsl:template>
4.544 +
4.545 +<xsl:template name="make-style-attribute">
4.546 + <xsl:param name="fill"/>
4.547 + <xsl:param name="fill-explicit"/>
4.548 + <xsl:param name="stroke"/>
4.549 + <xsl:param name="stroke-explicit"/>
4.550 + <xsl:param name="none-is-transparent" select="false()"/>
4.551 +
4.552 + <xsl:attribute name="style">
4.553 + <xsl:choose>
4.554 + <xsl:when test="$fill and (not($none-is-transparent) or $fill != 'none')">
4.555 + <xsl:call-template name="make-style-fill">
4.556 + <xsl:with-param name="fill" select="$fill"/>
4.557 + </xsl:call-template>
4.558 + </xsl:when>
4.559 + <xsl:when test="$fill-explicit and (not($none-is-transparent) or $fill-explicit != 'none')">
4.560 + <xsl:choose>
4.561 + <xsl:when test="starts-with($fill-explicit, '#')">
4.562 + <xsl:call-template name="make-style-fill">
4.563 + <xsl:with-param name="fill" select="$fill-explicit"/>
4.564 + </xsl:call-template>
4.565 + </xsl:when>
4.566 + <xsl:otherwise>fill: url(#<xsl:value-of select="$fill-explicit"/>);</xsl:otherwise>
4.567 + </xsl:choose>
4.568 + </xsl:when>
4.569 + <xsl:otherwise>fill: none;</xsl:otherwise>
4.570 + </xsl:choose>
4.571 + <xsl:choose>
4.572 + <xsl:when test="$stroke">stroke: <xsl:value-of select="$stroke"/>;</xsl:when>
4.573 + <xsl:when test="$stroke-explicit">stroke: <xsl:value-of select="$stroke-explicit"/>;</xsl:when>
4.574 + <xsl:otherwise>stroke: black;</xsl:otherwise>
4.575 + </xsl:choose>
4.576 + </xsl:attribute>
4.577 +</xsl:template>
4.578 +
4.579 +<xsl:template name="make-style-fill">
4.580 + <xsl:param name="fill"/>
4.581 + <xsl:choose>
4.582 + <xsl:when test="substring($fill,1,1) = '#'">fill: url(#fill-<xsl:value-of select="substring($fill,2,6)"/>);</xsl:when>
4.583 + <xsl:otherwise>fill: url(#<xsl:value-of select="$fill"/>);</xsl:otherwise>
4.584 + </xsl:choose>
4.585 +</xsl:template>
4.586 +
4.587 +</xsl:stylesheet>
6.1 --- a/moinformat/utils/graphviz.py Thu May 30 23:32:27 2019 +0200
6.2 +++ b/moinformat/utils/graphviz.py Mon Jul 01 19:22:49 2019 +0200
6.3 @@ -20,7 +20,8 @@
6.4 """
6.5
6.6 from moinformat.errors import ProcessingError
6.7 -from os.path import exists, join
6.8 +from moinformat.resources import __file__ as resources_file
6.9 +from os.path import exists, join, split
6.10 from StringIO import StringIO
6.11 from subprocess import Popen, PIPE
6.12 from xml.sax.saxutils import XMLGenerator
6.13 @@ -30,7 +31,6 @@
6.14
6.15 # Configurable paths and locations.
6.16
6.17 -DIAGRAM_TOOLS_PATH = "/home/paulb/Software/Graphical/diagram-tools"
6.18 GRAPHVIZ_PATH = "/usr/bin"
6.19 XSLT_PROCESSOR = "/usr/bin/xsltproc"
6.20
6.21 @@ -48,8 +48,11 @@
6.22
6.23 # XSL transformations for SVG output.
6.24
6.25 +RESOURCES_PATH = split(resources_file)[0]
6.26 +
6.27 TRANSFORMS = {
6.28 - "notugly" : join(DIAGRAM_TOOLS_PATH, "notugly.xsl"),
6.29 + "fixlinks" : (join(RESOURCES_PATH, "fixlinks.xsl"), ["document_index"]),
6.30 + "notugly" : (join(RESOURCES_PATH, "notugly.xsl"), []),
6.31 }
6.32
6.33
6.34 @@ -133,9 +136,12 @@
6.35 else:
6.36 return join(GRAPHVIZ_PATH, filter)
6.37
6.38 -def transform_output(process, format, transforms):
6.39 +def transform_output(process, format, transforms, params):
6.40
6.41 - "Transform the output from 'process' as 'format' using 'transforms'."
6.42 + """
6.43 + Transform the output from 'process' as 'format' using 'transforms' and
6.44 + 'params'.
6.45 + """
6.46
6.47 # No transformation can occur if the processor is missing.
6.48
6.49 @@ -146,19 +152,28 @@
6.50 # preceding one, with the first accepting the initial Graphviz output.
6.51
6.52 for transform in transforms:
6.53 - stylesheet = TRANSFORMS.get(transform)
6.54 + stylesheet, stylesheet_params = TRANSFORMS.get(transform)
6.55
6.56 # Ignore unrecognised or missing stylesheets.
6.57
6.58 if not stylesheet or not exists(stylesheet):
6.59 continue
6.60
6.61 + # Build the command parameters.
6.62 +
6.63 + command_params = []
6.64 +
6.65 + for param in stylesheet_params:
6.66 + value = params.get(param)
6.67 + if value:
6.68 + command_params += ["--stringparam", param, value]
6.69 +
6.70 # Invoke the processor, indicating standard input as the source
6.71 # document.
6.72 - # Example: /usr/bin/dot /usr/local/share/diagram-tools/notugly.xsl -
6.73 + # Example: /usr/bin/xsltproc notugly.xsl -
6.74
6.75 process = Popen(
6.76 - [XSLT_PROCESSOR, stylesheet, "-"],
6.77 + [XSLT_PROCESSOR] + command_params + [stylesheet, "-"],
6.78 shell=False,
6.79 stdin=process.stdout,
6.80 stdout=PIPE,
6.81 @@ -204,12 +219,14 @@
6.82 self.filter = filter
6.83 self.text = text
6.84
6.85 - def call(self, format, transforms=None, filename=None):
6.86 + def call(self, format, transforms=None, filename=None, params=None):
6.87
6.88 """
6.89 Invoke Graphviz to produce output in the given 'format'. Any
6.90 'transforms' are used to transform the output, if appropriate. Any
6.91 given 'filename' is used to write to a file.
6.92 +
6.93 + Any 'params' are used to parameterise any transformations.
6.94 """
6.95
6.96 program = get_program(self.filter)
6.97 @@ -237,7 +254,7 @@
6.98 # Chain the invocation to transformations, if appropriate.
6.99
6.100 if svg and transforms:
6.101 - end = transform_output(start, format, transforms)
6.102 + end = transform_output(start, format, transforms, params)
6.103
6.104 # Send the graph to the filter.
6.105