2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
4 <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
6 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7 xmlns:d="http://docbook.org/ns/docbook"
8 xmlns:fo="http://www.w3.org/1999/XSL/Format"
9 xmlns:xlink="http://www.w3.org/1999/xlink"
10 xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
11 xmlns:xtext="com.nwalsh.xalan.Text"
12 xmlns:lxslt="http://xml.apache.org/xslt"
13 exclude-result-prefixes="xlink stext xtext lxslt d"
14 extension-element-prefixes="stext xtext"
17 <!-- ********************************************************************
18 $Id: graphics.xsl 8144 2008-10-25 09:41:24Z mzjn $
19 ********************************************************************
21 This file is part of the XSL DocBook Stylesheet distribution.
22 See ../README or http://docbook.sf.net/release/xsl/current/ for
23 copyright and other information.
26 Colin Paul Adams, <colin@colina.demon.co.uk>
27 Paul Grosso, <pgrosso@arbortext.com>
29 ******************************************************************** -->
31 <!-- ==================================================================== -->
32 <!-- Graphic format tests for the FO backend -->
34 <xsl:param name="graphic.notations">
35 <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
37 <xsl:when test="$passivetex.extensions != 0">
38 <xsl:text> PNG PDF JPG JPEG linespecific </xsl:text>
40 <xsl:when test="$fop1.extensions != 0">
41 <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
43 <xsl:when test="$fop.extensions != 0">
44 <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
46 <xsl:when test="$arbortext.extensions != 0">
47 <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
49 <xsl:when test="$xep.extensions != 0">
50 <xsl:text> SVG PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
53 <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
58 <xsl:template name="is.graphic.format">
59 <xsl:param name="format"/>
60 <xsl:if test="contains($graphic.notations, concat(' ',$format,' '))">1</xsl:if>
63 <xsl:param name="graphic.extensions">
64 <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
66 <xsl:when test="$passivetex.extensions != 0">
67 <xsl:text> png pdf jpg jpeg </xsl:text>
69 <xsl:when test="$fop1.extensions != 0">
70 <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
72 <xsl:when test="$fop.extensions != 0">
73 <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
75 <xsl:when test="$arbortext.extensions != 0">
76 <xsl:text> png pdf jpg jpeg gif tif tiff bmp </xsl:text>
78 <xsl:when test="$xep.extensions != 0">
79 <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
82 <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
87 <xsl:template name="is.graphic.extension">
88 <xsl:param name="ext"/>
89 <xsl:variable name="lcext" select="translate($ext,
90 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
91 'abcdefghijklmnopqrstuvwxyz')"/>
93 <xsl:if test="contains($graphic.extensions,
94 concat(' ', $lcext, ' '))">1</xsl:if>
97 <xsl:template name="graphic.format.content-type">
98 <xsl:param name="format"/>
99 <xsl:variable name="is.graphic.format">
100 <xsl:call-template name="is.graphic.format">
101 <xsl:with-param name="format" select="$format"/>
104 <xsl:if test="$is.graphic.format">
106 <xsl:when test="$format = ''"></xsl:when>
107 <xsl:when test="$format = 'linespecific'"></xsl:when>
108 <xsl:when test="$format = 'PS'">application/postscript</xsl:when>
109 <xsl:when test="$format = 'PDF'">application/pdf</xsl:when>
110 <xsl:when test="$format = 'PNG'">image/png</xsl:when>
111 <xsl:when test="$format = 'SVG'">image/svg+xml</xsl:when>
112 <xsl:when test="$format = 'JPG'">image/jpeg</xsl:when>
113 <xsl:when test="$format = 'GIF87a'">image/gif</xsl:when>
114 <xsl:when test="$format = 'GIF89a'">image/gif</xsl:when>
116 <xsl:value-of select="concat('image/',
117 translate($format, &uppercase;, &lowercase;))"/>
124 <!-- ==================================================================== -->
126 <xsl:template match="d:screenshot">
128 <xsl:apply-templates/>
132 <xsl:template match="d:screeninfo">
135 <!-- ==================================================================== -->
136 <!-- Override these templates for FO -->
137 <!-- ==================================================================== -->
139 <xsl:template name="process.image">
140 <!-- When this template is called, the current node should be -->
141 <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
142 <!-- those elements have the same set of attributes, so we can -->
143 <!-- handle them all in one place. -->
145 <xsl:variable name="scalefit">
147 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
148 <xsl:when test="@contentwidth">0</xsl:when>
149 <xsl:when test="@contentdepth and
150 @contentdepth != '100%'">0</xsl:when>
151 <xsl:when test="@scale">0</xsl:when>
152 <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
153 <xsl:when test="@width or @depth">1</xsl:when>
154 <xsl:when test="$default.image.width != ''">1</xsl:when>
155 <xsl:otherwise>0</xsl:otherwise>
159 <xsl:variable name="scale">
161 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
162 <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
163 <xsl:when test="@scale">
164 <xsl:value-of select="@scale div 100.0"/>
166 <!-- added next line to adjust scaling where scalefit = 1 -->
167 <xsl:when test="@scalefit and @scalefit = '1'">1.0</xsl:when>
168 <xsl:otherwise>0.75</xsl:otherwise>
172 <xsl:variable name="filename">
174 <xsl:when test="local-name(.) = 'graphic'
175 or local-name(.) = 'inlinegraphic'">
176 <!-- handle legacy graphic and inlinegraphic by new template -->
177 <xsl:call-template name="mediaobject.filename">
178 <xsl:with-param name="object" select="."/>
182 <!-- imagedata, videodata, audiodata -->
183 <xsl:call-template name="mediaobject.filename">
184 <xsl:with-param name="object" select=".."/>
190 <xsl:variable name="content-type">
191 <xsl:if test="@format">
192 <xsl:call-template name="graphic.format.content-type">
193 <xsl:with-param name="format" select="@format"/>
198 <xsl:variable name="bgcolor">
199 <xsl:call-template name="pi.dbfo_background-color">
200 <xsl:with-param name="node" select=".."/>
204 <fo:external-graphic>
205 <xsl:attribute name="src">
206 <xsl:call-template name="fo-external-image">
207 <xsl:with-param name="filename">
208 <xsl:if test="$img.src.path != '' and
209 not(starts-with($filename, '/')) and
210 not(contains($filename, '://'))">
211 <xsl:value-of select="$img.src.path"/>
213 <xsl:value-of select="$filename"/>
218 <xsl:attribute name="width">
220 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
221 <xsl:when test="contains(@width,'%')">
222 <xsl:value-of select="@width"/>
224 <xsl:when test="@width and not(@width = '')">
225 <xsl:call-template name="length-spec">
226 <xsl:with-param name="length" select="@width"/>
227 <xsl:with-param name="default.units" select="'px'"/>
230 <xsl:when test="not(@depth) and $default.image.width != ''">
231 <xsl:call-template name="length-spec">
232 <xsl:with-param name="length" select="$default.image.width"/>
233 <xsl:with-param name="default.units" select="'px'"/>
236 <xsl:otherwise>auto</xsl:otherwise>
240 <xsl:attribute name="height">
242 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
243 <xsl:when test="contains(@depth,'%')">
244 <xsl:value-of select="@depth"/>
246 <xsl:when test="@depth">
247 <xsl:call-template name="length-spec">
248 <xsl:with-param name="length" select="@depth"/>
249 <xsl:with-param name="default.units" select="'px'"/>
252 <xsl:otherwise>auto</xsl:otherwise>
256 <xsl:attribute name="content-width">
258 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
259 <xsl:when test="contains(@contentwidth,'%')">
260 <xsl:value-of select="@contentwidth"/>
262 <xsl:when test="@contentwidth">
263 <xsl:call-template name="length-spec">
264 <xsl:with-param name="length" select="@contentwidth"/>
265 <xsl:with-param name="default.units" select="'px'"/>
268 <xsl:when test="number($scale) != 1.0">
269 <xsl:value-of select="$scale * 100"/>
270 <xsl:text>%</xsl:text>
272 <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
273 <xsl:otherwise>auto</xsl:otherwise>
277 <xsl:attribute name="content-height">
279 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
280 <xsl:when test="contains(@contentdepth,'%')">
281 <xsl:value-of select="@contentdepth"/>
283 <xsl:when test="@contentdepth">
284 <xsl:call-template name="length-spec">
285 <xsl:with-param name="length" select="@contentdepth"/>
286 <xsl:with-param name="default.units" select="'px'"/>
289 <xsl:when test="number($scale) != 1.0">
290 <xsl:value-of select="$scale * 100"/>
291 <xsl:text>%</xsl:text>
293 <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
294 <xsl:otherwise>auto</xsl:otherwise>
298 <xsl:if test="$content-type != ''">
299 <xsl:attribute name="content-type">
300 <xsl:value-of select="concat('content-type:',$content-type)"/>
304 <xsl:if test="$bgcolor != ''">
305 <xsl:attribute name="background-color">
306 <xsl:value-of select="$bgcolor"/>
310 <xsl:if test="@align">
311 <xsl:attribute name="text-align">
312 <xsl:value-of select="@align"/>
316 <xsl:if test="@valign">
317 <xsl:attribute name="display-align">
319 <xsl:when test="@valign = 'top'">before</xsl:when>
320 <xsl:when test="@valign = 'middle'">center</xsl:when>
321 <xsl:when test="@valign = 'bottom'">after</xsl:when>
322 <xsl:otherwise>auto</xsl:otherwise>
326 </fo:external-graphic>
329 <!-- ==================================================================== -->
331 <xsl:template match="d:graphic">
333 <xsl:when test="parent::d:inlineequation">
334 <xsl:call-template name="process.image"/>
338 <xsl:if test="@align">
339 <xsl:attribute name="text-align">
340 <xsl:value-of select="@align"/>
343 <xsl:call-template name="process.image"/>
349 <xsl:template match="d:inlinegraphic">
350 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
351 <xsl:variable name="filename">
353 <xsl:when test="@entityref">
354 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
357 <xsl:apply-templates select="@fileref"/>
363 <xsl:when test="@format='linespecific'">
365 <xsl:when test="$use.extensions != '0'
366 and $textinsert.extension != '0'">
368 <xsl:when test="contains($vendor, 'SAXON')">
369 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
371 <xsl:when test="contains($vendor, 'Apache Software Foundation')">
372 <xtext:insertfile href="{$filename}"/>
375 <xsl:message terminate="yes">
376 <xsl:text>Don't know how to insert files with </xsl:text>
377 <xsl:value-of select="$vendor"/>
383 <xsl:message terminate="yes">
384 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
385 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
391 <xsl:call-template name="process.image"/>
396 <!-- ==================================================================== -->
398 <xsl:template match="d:mediaobject|d:mediaobjectco">
400 <xsl:variable name="olist" select="d:imageobject|d:imageobjectco
401 |d:videoobject|d:audioobject
404 <xsl:variable name="object.index">
405 <xsl:call-template name="select.mediaobject.index">
406 <xsl:with-param name="olist" select="$olist"/>
407 <xsl:with-param name="count" select="1"/>
411 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
413 <xsl:variable name="align">
414 <xsl:value-of select="$object/descendant::d:imagedata[@align][1]/@align"/>
417 <xsl:variable name="id">
418 <xsl:call-template name="object.id"/>
421 <fo:block id="{$id}">
422 <xsl:if test="$align != '' ">
423 <xsl:attribute name="text-align">
424 <xsl:value-of select="$align"/>
428 <xsl:apply-templates select="$object"/>
429 <xsl:apply-templates select="d:caption"/>
433 <xsl:template match="d:inlinemediaobject">
434 <xsl:call-template name="select.mediaobject"/>
437 <!-- ==================================================================== -->
439 <xsl:template match="d:imageobjectco">
440 <xsl:apply-templates select="d:imageobject"/>
441 <xsl:apply-templates select="d:calloutlist"/>
444 <xsl:template match="d:imageobject">
446 <xsl:when test="d:imagedata">
447 <xsl:apply-templates select="d:imagedata"/>
450 <fo:instream-foreign-object>
451 <xsl:apply-templates mode="copy-all"/>
452 </fo:instream-foreign-object>
457 <!-- ==================================================================== -->
459 <xsl:template match="*" mode="copy-all">
461 <xsl:for-each select="@*">
464 <xsl:apply-templates mode="copy-all"/>
468 <xsl:template match="text()|comment()|processing-instruction()" mode="copy-all">
472 <!-- ==================================================================== -->
474 <xsl:template match="d:imagedata">
475 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
476 <xsl:variable name="filename">
477 <xsl:call-template name="mediaobject.filename">
478 <xsl:with-param name="object" select=".."/>
483 <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
484 <xsl:apply-templates/>
487 <xsl:when test="@format='linespecific'">
489 <xsl:when test="$use.extensions != '0'
490 and $textinsert.extension != '0'">
492 <xsl:when test="contains($vendor, 'SAXON')">
493 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
495 <xsl:when test="contains($vendor, 'Apache Software Foundation')">
496 <xtext:insertfile href="{$filename}"/>
499 <xsl:message terminate="yes">
500 <xsl:text>Don't know how to insert files with </xsl:text>
501 <xsl:value-of select="$vendor"/>
507 <xsl:message terminate="yes">
508 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
509 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
515 <xsl:call-template name="process.image"/>
520 <!-- ==================================================================== -->
522 <xsl:template match="d:videoobject">
523 <xsl:apply-templates select="d:videodata"/>
526 <xsl:template match="d:videodata">
527 <xsl:call-template name="process.image"/>
530 <!-- ==================================================================== -->
532 <xsl:template match="d:audioobject">
533 <xsl:apply-templates select="d:audiodata"/>
536 <xsl:template match="d:audiodata">
537 <xsl:call-template name="process.image"/>
540 <!-- ==================================================================== -->
542 <xsl:template match="d:textobject">
543 <xsl:apply-templates/>
546 <xsl:template match="d:textdata">
547 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
548 <xsl:variable name="filename">
550 <xsl:when test="@entityref">
551 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
554 <xsl:apply-templates select="@fileref"/>
559 <xsl:variable name="encoding">
561 <xsl:when test="@encoding">
562 <xsl:value-of select="@encoding"/>
565 <xsl:value-of select="$textdata.default.encoding"/>
571 <xsl:when test="$use.extensions != '0'
572 and $textinsert.extension != '0'">
574 <xsl:when test="element-available('stext:insertfile')">
575 <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
577 <xsl:when test="element-available('xtext:insertfile')">
578 <xtext:insertfile href="{$filename}"/>
581 <xsl:message terminate="yes">
582 <xsl:text>Don't know how to insert files with </xsl:text>
583 <xsl:value-of select="$vendor"/>
589 <xsl:message terminate="yes">
590 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
591 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
597 <!-- ==================================================================== -->
599 <xsl:template match="d:caption">
601 <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
602 <xsl:attribute name="text-align"><xsl:value-of
603 select="@align"/></xsl:attribute>
605 <xsl:apply-templates/>
609 <!-- ==================================================================== -->
611 <xsl:template name="fo-external-image">
612 <xsl:param name="filename"/>
615 <xsl:when test="$passivetex.extensions != 0
616 or $fop.extensions != 0">
617 <xsl:value-of select="$filename"/>
620 <xsl:value-of select="concat('url(', $filename, ')')"/>
625 <!-- Resolve xml:base attributes -->
626 <xsl:template match="@fileref">
627 <!-- need a check for absolute urls -->
629 <xsl:when test="contains(., ':') or starts-with(.,'/')">
630 <!-- it has a uri scheme or starts with '/', so it is an absolute uri -->
631 <xsl:value-of select="."/>
633 <xsl:when test="$keep.relative.image.uris != 0">
634 <!-- leave it alone -->
635 <xsl:value-of select="."/>
638 <!-- its a relative uri -->
639 <xsl:call-template name="relative-uri">