Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ac5bb8f

Browse files
committed
Add XSL stylesheet to fix up SVG files
The SVG output produced by external tools needs some postprocessing. This is implemented by this new XSL stylesheet. Issues are: - SVG produced by Ditaa does not add a viewBox attribute to the svg element, needed to make the image scalable. - SVG produced by Graphviz uses a stroke="transparent" attribute, which is not valid SVG. It appears to mostly work, but FOP complains. Other tweaks can be added over time. This reverts 7dc78d8 and 29046c4, which applied these fixes manually.
1 parent 66013fe commit ac5bb8f

File tree

6 files changed

+119
-80
lines changed

6 files changed

+119
-80
lines changed

.gitattributes

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ README.* conflict-marker-size=32
1313

1414
# Certain data files that contain special whitespace, and other special cases
1515
*.data -whitespace
16-
*.svg whitespace=-blank-at-eol
1716
contrib/pgcrypto/sql/pgp-armor.sql whitespace=-blank-at-eol
1817
src/backend/catalog/sql_features.txt whitespace=space-before-tab,blank-at-eof,-blank-at-eol
1918

doc/src/sgml/images/Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@ ALL_IMAGES = \
88

99
DITAA = ditaa
1010
DOT = dot
11+
XSLTPROC = xsltproc
1112

1213
all: $(ALL_IMAGES)
1314

14-
%.svg: %.gv
15+
%.svg.tmp: %.gv
1516
$(DOT) -T svg -o $@ $<
1617

17-
%.svg: %.txt
18+
%.svg.tmp: %.txt
1819
$(DITAA) -E -S --svg $< $@
20+
21+
# Post-processing for SVG files coming from other tools
22+
#
23+
# Use --novalid to avoid loading SVG DTD if a file specifies it, since
24+
# it might not be available locally, and we don't need it.
25+
%.svg: %.svg.tmp fixup-svg.xsl
26+
$(XSLTPROC) --novalid -o $@ $(word 2,$^) $<

doc/src/sgml/images/README

+4-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Therefore, any tool used needs to be able to produce SVG.
2222
This directory contains makefile rules to build SVG from common input
2323
formats, using some common styling.
2424

25+
fixup-svg.xsl applies some postprocessing to the SVG files produced by
26+
those external tools to address assorted issues. See comments in
27+
there, and adjust and expand as necessary.
28+
2529
Both the source and the SVG output file are committed in this
2630
directory. That way, we don't need all developers to have all the
2731
tools installed. While we accept that there could be some gratuitous
@@ -59,10 +63,3 @@ Notes:
5963
- The width should be set to something. This ensures that the image
6064
is scaled to fit the page in PDF output. (Other widths than 100%
6165
might be appropriate.)
62-
63-
- SVG images should be scalable as they will be rendered in a variety
64-
of places (web, PDF, etc.) as well as in different viewports
65-
(desktop, mobile, etc.). To help the images successfully scale,
66-
employ a "viewBox" attribute in the SVG tag. For example,
67-
to create an image with a default width and height of 400x300,
68-
you would use viewBox="0.00 0.00 400.00 300.00"

doc/src/sgml/images/fixup-svg.xsl

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3+
xmlns:svg="http://www.w3.org/2000/svg"
4+
version="1.0">
5+
6+
<!--
7+
Transform the SVG produced by various tools, applying assorted fixups.
8+
-->
9+
10+
<!--
11+
Add viewBox attribute to svg element if not already present. This allows the
12+
image to scale.
13+
-->
14+
<xsl:template match="svg:svg">
15+
<xsl:copy>
16+
<xsl:if test="not(@viewBox)">
17+
<xsl:attribute name="viewBox">
18+
<xsl:text>0 0 </xsl:text>
19+
<xsl:value-of select="@width"/>
20+
<xsl:text> </xsl:text>
21+
<xsl:value-of select="@height"/>
22+
</xsl:attribute>
23+
</xsl:if>
24+
<xsl:apply-templates select="@* | node()"/>
25+
</xsl:copy>
26+
</xsl:template>
27+
28+
<!--
29+
Fix stroke="transparent" attribute, which is invalid SVG.
30+
-->
31+
<xsl:template match="@stroke[.='transparent']">
32+
<xsl:attribute name="stroke">none</xsl:attribute>
33+
</xsl:template>
34+
35+
<!--
36+
copy everything else
37+
-->
38+
<xsl:template match="@* | node()">
39+
<xsl:copy>
40+
<xsl:apply-templates select="@* | node()"/>
41+
</xsl:copy>
42+
</xsl:template>
43+
44+
</xsl:stylesheet>

doc/src/sgml/images/gin.svg

+31-34
Loading

0 commit comments

Comments
 (0)