I talked on the last post about the problems in using directly SVG in the current status of affair. I wanted to continue using these standard technologies (DocBook and SVGs to produce PDF and XHTML through XSLT stylesheets and FO processors), but I had to circumvent somehow the problems. Here’s the solution I found.
My problem is I can’t use directly SVGs. So, at last I concluded that the practical solution is to produce two PNGs of different resolution for the PDF and XHTML output. But then I considered the fact that I didn’t want to make things manually: I wanted to continue making the document as if the problem wasn’t there, so that, once the situation will be stable, I have to do nothing but to remove the additional infrastructure I’m putting in. So, for the making of the PNG versions I simply had to expand the Makefile I already had:
# variables for SVG to PNG conversion
SVGS := $(wildcard *.svg)
LOWRES_PNGS := $(SVGS:.svg=_lowres.png)
HIRES_PNGS := $(SVGS:.svg=_hires.png)
[…]
# SVG to PNG handling
corso_reworked.xml: corso.xml imageprocessing.xsl
xsltproc imageprocessing.xsl corso.xml > corso_reworked.xml
%_lowres.png: %.svg
inkscape --file=$< --export-png=$@
%_hires.png: %.svg
inkscape --file=$< --export-dpi=300 --export-png=$@
This code simply takes all SVGs it can find, and make a low and hi res versions (for example, from stack_tcp_ip.svg generate stack_tcp_ip_hires.png and stack_tcp_ip_lowres.png).
This was the easy part. But how could I modify the docbook? Very simple: being XML, I simply had to write one more XSLT that made conversions for me. To be exact, the change is from something like this:
<mediaobject id="StackTCPIP">
<imageobject>
<imagedata
fileref="stack_tcp_ip.svg"
format="SVG"
align="center"/>
</imageobject>
</mediaobject>
To something like that:
<mediaobject id="StackTCPIP">
<imageobject role="fo">
<imagedata
fileref="stack_tcp_ip_hires.png"
format="PNG"
align="center"/>
</imageobject>
<imageobject role="xhtml">
<imagedata
fileref="stack_tcp_ip_lowres.png"
format="PNG"
align="center"/>
</imageobject>
</mediaobject>
That is, the imageobject is duplicated with different roles, and the imagedata are changed to accomodate the PNG version. At the end, all the work is made automatically and, again, in a standard way. The two files that make all the work are thus this Makefile (the one I’m using for producing the documents) and the SVG to PNG stylesheet. The second one I tried to make the most flexible, so that it works on various situations.
Posted by mattia as docbook, fo, make, pdf, png, svg, xhtml, xslt at 1:45 AM CEST
