Commit ac5bb8f2 authored by Peter Eisentraut's avatar Peter Eisentraut

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 7dc78d8e and
29046c44, which applied these fixes
manually.
parent 66013fe7
......@@ -13,7 +13,6 @@ README.* conflict-marker-size=32
# Certain data files that contain special whitespace, and other special cases
*.data -whitespace
*.svg whitespace=-blank-at-eol
contrib/pgcrypto/sql/pgp-armor.sql whitespace=-blank-at-eol
src/backend/catalog/sql_features.txt whitespace=space-before-tab,blank-at-eof,-blank-at-eol
......
......@@ -8,11 +8,19 @@ ALL_IMAGES = \
DITAA = ditaa
DOT = dot
XSLTPROC = xsltproc
all: $(ALL_IMAGES)
%.svg: %.gv
%.svg.tmp: %.gv
$(DOT) -T svg -o $@ $<
%.svg: %.txt
%.svg.tmp: %.txt
$(DITAA) -E -S --svg $< $@
# Post-processing for SVG files coming from other tools
#
# Use --novalid to avoid loading SVG DTD if a file specifies it, since
# it might not be available locally, and we don't need it.
%.svg: %.svg.tmp fixup-svg.xsl
$(XSLTPROC) --novalid -o $@ $(word 2,$^) $<
......@@ -22,6 +22,10 @@ Therefore, any tool used needs to be able to produce SVG.
This directory contains makefile rules to build SVG from common input
formats, using some common styling.
fixup-svg.xsl applies some postprocessing to the SVG files produced by
those external tools to address assorted issues. See comments in
there, and adjust and expand as necessary.
Both the source and the SVG output file are committed in this
directory. That way, we don't need all developers to have all the
tools installed. While we accept that there could be some gratuitous
......@@ -59,10 +63,3 @@ Notes:
- The width should be set to something. This ensures that the image
is scaled to fit the page in PDF output. (Other widths than 100%
might be appropriate.)
- SVG images should be scalable as they will be rendered in a variety
of places (web, PDF, etc.) as well as in different viewports
(desktop, mobile, etc.). To help the images successfully scale,
employ a "viewBox" attribute in the SVG tag. For example,
to create an image with a default width and height of 400x300,
you would use viewBox="0.00 0.00 400.00 300.00"
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg"
version="1.0">
<!--
Transform the SVG produced by various tools, applying assorted fixups.
-->
<!--
Add viewBox attribute to svg element if not already present. This allows the
image to scale.
-->
<xsl:template match="svg:svg">
<xsl:copy>
<xsl:if test="not(@viewBox)">
<xsl:attribute name="viewBox">
<xsl:text>0 0 </xsl:text>
<xsl:value-of select="@width"/>
<xsl:text> </xsl:text>
<xsl:value-of select="@height"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!--
Fix stroke="transparent" attribute, which is invalid SVG.
-->
<xsl:template match="@stroke[.='transparent']">
<xsl:attribute name="stroke">none</xsl:attribute>
</xsl:template>
<!--
copy everything else
-->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This diff is collapsed.
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<svg
xmlns='http://www.w3.org/2000/svg'
width='610'
height='210'
viewBox='0.00 0.00 610.00 210.00'
shape-rendering='geometricPrecision'
version='1.0'>
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 610 210" width="610" height="210" shape-rendering="geometricPrecision" version="1.0">
<defs>
<filter id='f2' x='0' y='0' width='200%' height='200%'>
<feOffset result='offOut' in='SourceGraphic' dx='5' dy='5' />
<feGaussianBlur result='blurOut' in='offOut' stdDeviation='3' />
<feBlend in='SourceGraphic' in2='blurOut' mode='normal' />
<filter id="f2" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceGraphic" dx="5" dy="5"/>
<feGaussianBlur result="blurOut" in="offOut" stdDeviation="3"/>
<feBlend in="SourceGraphic" in2="blurOut" mode="normal"/>
</filter>
</defs>
<g stroke-width='1' stroke-linecap='square' stroke-linejoin='round'>
<rect x='0' y='0' width='610' height='210' style='fill: #ffffff'/>
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M25.0 35.0 L25.0 175.0 L585.0 175.0 L585.0 35.0 z' />
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M305.0 175.0 L485.0 175.0 L485.0 147.0 L305.0 147.0 z' />
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M25.0 35.0 L25.0 63.0 L195.0 63.0 L195.0 35.0 z' />
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M305.0 147.0 L305.0 175.0 L195.0 175.0 L195.0 147.0 z' />
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M325.0 63.0 L325.0 91.0 L265.0 91.0 L265.0 105.0 L235.0 105.0 L235.0 63.0 z' />
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M585.0 147.0 L585.0 175.0 L485.0 175.0 L485.0 147.0 z' />
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M195.0 35.0 L285.0 35.0 L285.0 63.0 L195.0 63.0 z' />
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='white' d='M375.0 35.0 L375.0 63.0 L285.0 63.0 L285.0 35.0 z' />
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='none' d='M335.0 133.0 L335.0 105.0 L265.0 105.0 ' />
<path stroke='none' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='#000000' d='M470.0 42.0 L480.0 49.0 L470.0 56.0 z' />
<path stroke='none' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='#000000' d='M260.0 126.0 L265.0 140.0 L270.0 126.0 z' />
<path stroke='none' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='#000000' d='M330.0 126.0 L335.0 140.0 L340.0 126.0 z' />
<path stroke='none' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='#000000' d='M140.0 154.0 L130.0 161.0 L140.0 168.0 z' />
<path stroke='#000000' stroke-width='1.000000' stroke-linecap='round' stroke-linejoin='round' fill='none' d='M265.0 105.0 L265.0 133.0 ' />
<path stroke='#000000' stroke-width='1.000000' stroke-dasharray='5.000000,5.000000' stroke-miterlimit='0' stroke-linecap='butt' stroke-linejoin='round' fill='white' d='M375.0 49.0 L475.0 49.0 ' />
<path stroke='#000000' stroke-width='1.000000' stroke-dasharray='5.000000,5.000000' stroke-miterlimit='0' stroke-linecap='butt' stroke-linejoin='round' fill='white' d='M135.0 161.0 L195.0 161.0 ' />
<text x='48' y='54' font-family='Courier' font-size='15' stroke='none' fill='#000000' ><![CDATA[PageHeaderData]]></text>
<text x='214' y='166' font-family='Courier' font-size='15' stroke='none' fill='#000000' ><![CDATA[Item]]></text>
<text x='216' y='54' font-family='Courier' font-size='15' stroke='none' fill='#000000' ><![CDATA[ItemId]]></text>
<text x='306' y='54' font-family='Courier' font-size='15' stroke='none' fill='#000000' ><![CDATA[ItemId]]></text>
<text x='324' y='166' font-family='Courier' font-size='15' stroke='none' fill='#000000' ><![CDATA[Item]]></text>
<text x='509' y='166' font-family='Courier' font-size='15' stroke='none' fill='#000000' ><![CDATA[Special]]></text>
<g stroke-width="1" stroke-linecap="square" stroke-linejoin="round">
<rect x="0" y="0" width="610" height="210" style="fill: #ffffff"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="white" d="M25.0 35.0 L25.0 175.0 L585.0 175.0 L585.0 35.0 z"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="white" d="M305.0 175.0 L485.0 175.0 L485.0 147.0 L305.0 147.0 z"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="white" d="M25.0 35.0 L25.0 63.0 L195.0 63.0 L195.0 35.0 z"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="white" d="M305.0 147.0 L305.0 175.0 L195.0 175.0 L195.0 147.0 z"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="white" d="M325.0 63.0 L325.0 91.0 L265.0 91.0 L265.0 105.0 L235.0 105.0 L235.0 63.0 z"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="white" d="M585.0 147.0 L585.0 175.0 L485.0 175.0 L485.0 147.0 z"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="white" d="M195.0 35.0 L285.0 35.0 L285.0 63.0 L195.0 63.0 z"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="white" d="M375.0 35.0 L375.0 63.0 L285.0 63.0 L285.0 35.0 z"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="none" d="M335.0 133.0 L335.0 105.0 L265.0 105.0 "/>
<path stroke="none" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="#000000" d="M470.0 42.0 L480.0 49.0 L470.0 56.0 z"/>
<path stroke="none" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="#000000" d="M260.0 126.0 L265.0 140.0 L270.0 126.0 z"/>
<path stroke="none" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="#000000" d="M330.0 126.0 L335.0 140.0 L340.0 126.0 z"/>
<path stroke="none" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="#000000" d="M140.0 154.0 L130.0 161.0 L140.0 168.0 z"/>
<path stroke="#000000" stroke-width="1.000000" stroke-linecap="round" stroke-linejoin="round" fill="none" d="M265.0 105.0 L265.0 133.0 "/>
<path stroke="#000000" stroke-width="1.000000" stroke-dasharray="5.000000,5.000000" stroke-miterlimit="0" stroke-linecap="butt" stroke-linejoin="round" fill="white" d="M375.0 49.0 L475.0 49.0 "/>
<path stroke="#000000" stroke-width="1.000000" stroke-dasharray="5.000000,5.000000" stroke-miterlimit="0" stroke-linecap="butt" stroke-linejoin="round" fill="white" d="M135.0 161.0 L195.0 161.0 "/>
<text x="48" y="54" font-family="Courier" font-size="15" stroke="none" fill="#000000">PageHeaderData</text>
<text x="214" y="166" font-family="Courier" font-size="15" stroke="none" fill="#000000">Item</text>
<text x="216" y="54" font-family="Courier" font-size="15" stroke="none" fill="#000000">ItemId</text>
<text x="306" y="54" font-family="Courier" font-size="15" stroke="none" fill="#000000">ItemId</text>
<text x="324" y="166" font-family="Courier" font-size="15" stroke="none" fill="#000000">Item</text>
<text x="509" y="166" font-family="Courier" font-size="15" stroke="none" fill="#000000">Special</text>
</g>
</svg>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment