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:fo="http://www.w3.org/1999/XSL/Format"
8 xmlns:xlink="http://www.w3.org/1999/xlink"
9 xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
10 xmlns:xtext="com.nwalsh.xalan.Text"
11 xmlns:lxslt="http://xml.apache.org/xslt"
12 exclude-result-prefixes="xlink stext xtext lxslt"
13 extension-element-prefixes="stext xtext"
16 <!-- ********************************************************************
17 $Id: graphics.xsl 8786 2010-07-28 17:26:46Z mzjn $
18 ********************************************************************
20 This file is part of the XSL DocBook Stylesheet distribution.
21 See ../README or http://docbook.sf.net/release/xsl/current/ for
22 copyright and other information.
25 Colin Paul Adams, <colin@colina.demon.co.uk>
26 Paul Grosso, <pgrosso@arbortext.com>
28 ******************************************************************** -->
30 <!-- ==================================================================== -->
31 <!-- Graphic format tests for the FO backend -->
33 <xsl:param name="graphic.notations">
34 <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
36 <xsl:when test="$passivetex.extensions != 0">
37 <xsl:text> PNG PDF JPG JPEG linespecific </xsl:text>
39 <xsl:when test="$fop1.extensions != 0">
40 <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
42 <xsl:when test="$fop.extensions != 0">
43 <xsl:text> BMP GIF TIFF SVG PNG EPS JPG JPEG linespecific </xsl:text>
45 <xsl:when test="$arbortext.extensions != 0">
46 <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
48 <xsl:when test="$xep.extensions != 0">
49 <xsl:text> SVG PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
52 <xsl:text> PNG PDF JPG JPEG linespecific GIF GIF87a GIF89a TIFF BMP </xsl:text>
57 <xsl:template name="is.graphic.format">
58 <xsl:param name="format"/>
59 <xsl:if test="contains($graphic.notations, concat(' ',$format,' '))">1</xsl:if>
62 <xsl:param name="graphic.extensions">
63 <!-- n.b. exactly one leading space, one trailing space, and one inter-word space -->
65 <xsl:when test="$passivetex.extensions != 0">
66 <xsl:text> png pdf jpg jpeg </xsl:text>
68 <xsl:when test="$fop1.extensions != 0">
69 <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
71 <xsl:when test="$fop.extensions != 0">
72 <xsl:text> bmp gif tif tiff svg png pdf jpg jpeg eps </xsl:text>
74 <xsl:when test="$arbortext.extensions != 0">
75 <xsl:text> png pdf jpg jpeg gif tif tiff bmp </xsl:text>
77 <xsl:when test="$xep.extensions != 0">
78 <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
81 <xsl:text> svg png pdf jpg jpeg gif tif tiff bmp eps </xsl:text>
86 <xsl:template name="is.graphic.extension">
87 <xsl:param name="ext"/>
88 <xsl:variable name="lcext" select="translate($ext,
89 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
90 'abcdefghijklmnopqrstuvwxyz')"/>
92 <xsl:if test="contains($graphic.extensions,
93 concat(' ', $lcext, ' '))">1</xsl:if>
96 <xsl:template name="graphic.format.content-type">
97 <xsl:param name="format"/>
98 <xsl:variable name="is.graphic.format">
99 <xsl:call-template name="is.graphic.format">
100 <xsl:with-param name="format" select="$format"/>
103 <xsl:if test="$is.graphic.format">
105 <xsl:when test="$format = ''"></xsl:when>
106 <xsl:when test="$format = 'linespecific'"></xsl:when>
107 <xsl:when test="$format = 'PS'">application/postscript</xsl:when>
108 <xsl:when test="$format = 'PDF'">application/pdf</xsl:when>
109 <xsl:when test="$format = 'PNG'">image/png</xsl:when>
110 <xsl:when test="$format = 'SVG'">image/svg+xml</xsl:when>
111 <xsl:when test="$format = 'JPG'">image/jpeg</xsl:when>
112 <xsl:when test="$format = 'GIF87a'">image/gif</xsl:when>
113 <xsl:when test="$format = 'GIF89a'">image/gif</xsl:when>
115 <xsl:value-of select="concat('image/',
116 translate($format, &uppercase;, &lowercase;))"/>
123 <!-- ==================================================================== -->
125 <xsl:template match="screenshot">
127 <xsl:apply-templates/>
131 <xsl:template match="screeninfo">
134 <!-- ==================================================================== -->
135 <!-- Override these templates for FO -->
136 <!-- ==================================================================== -->
138 <xsl:template name="process.image">
139 <!-- When this template is called, the current node should be -->
140 <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
141 <!-- those elements have the same set of attributes, so we can -->
142 <!-- handle them all in one place. -->
144 <xsl:variable name="scalefit">
146 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
147 <xsl:when test="@contentwidth">0</xsl:when>
148 <xsl:when test="@contentdepth and
149 @contentdepth != '100%'">0</xsl:when>
150 <xsl:when test="@scale">0</xsl:when>
151 <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
152 <xsl:when test="@width or @depth">1</xsl:when>
153 <xsl:when test="$default.image.width != ''">1</xsl:when>
154 <xsl:otherwise>0</xsl:otherwise>
158 <xsl:variable name="scale">
160 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
161 <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
162 <xsl:when test="@scale">
163 <xsl:value-of select="@scale div 100.0"/>
165 <xsl:otherwise>1.0</xsl:otherwise>
169 <xsl:variable name="filename">
171 <xsl:when test="local-name(.) = 'graphic'
172 or local-name(.) = 'inlinegraphic'">
173 <!-- handle legacy graphic and inlinegraphic by new template -->
174 <xsl:call-template name="mediaobject.filename">
175 <xsl:with-param name="object" select="."/>
179 <!-- imagedata, videodata, audiodata -->
180 <xsl:call-template name="mediaobject.filename">
181 <xsl:with-param name="object" select=".."/>
187 <xsl:variable name="content-type">
188 <xsl:if test="@format">
189 <xsl:call-template name="graphic.format.content-type">
190 <xsl:with-param name="format" select="@format"/>
195 <xsl:variable name="bgcolor">
196 <xsl:call-template name="pi.dbfo_background-color">
197 <xsl:with-param name="node" select=".."/>
201 <fo:external-graphic>
202 <xsl:attribute name="src">
203 <xsl:call-template name="fo-external-image">
204 <xsl:with-param name="filename">
205 <xsl:if test="$img.src.path != '' and
206 not(starts-with($filename, '/')) and
207 not(contains($filename, '://'))">
208 <xsl:value-of select="$img.src.path"/>
210 <xsl:value-of select="$filename"/>
215 <xsl:attribute name="width">
217 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
218 <xsl:when test="contains(@width,'%')">
219 <xsl:value-of select="@width"/>
221 <xsl:when test="@width and not(@width = '')">
222 <xsl:call-template name="length-spec">
223 <xsl:with-param name="length" select="@width"/>
224 <xsl:with-param name="default.units" select="'px'"/>
227 <xsl:when test="not(@depth) and $default.image.width != ''">
228 <xsl:call-template name="length-spec">
229 <xsl:with-param name="length" select="$default.image.width"/>
230 <xsl:with-param name="default.units" select="'px'"/>
233 <xsl:otherwise>auto</xsl:otherwise>
237 <xsl:attribute name="height">
239 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
240 <xsl:when test="contains(@depth,'%')">
241 <xsl:value-of select="@depth"/>
243 <xsl:when test="@depth">
244 <xsl:call-template name="length-spec">
245 <xsl:with-param name="length" select="@depth"/>
246 <xsl:with-param name="default.units" select="'px'"/>
249 <xsl:otherwise>auto</xsl:otherwise>
253 <xsl:attribute name="content-width">
255 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
256 <xsl:when test="contains(@contentwidth,'%')">
257 <xsl:value-of select="@contentwidth"/>
259 <xsl:when test="@contentwidth">
260 <xsl:call-template name="length-spec">
261 <xsl:with-param name="length" select="@contentwidth"/>
262 <xsl:with-param name="default.units" select="'px'"/>
265 <xsl:when test="number($scale) != 1.0">
266 <xsl:value-of select="$scale * 100"/>
267 <xsl:text>%</xsl:text>
269 <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
270 <xsl:otherwise>auto</xsl:otherwise>
274 <xsl:attribute name="content-height">
276 <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
277 <xsl:when test="contains(@contentdepth,'%')">
278 <xsl:value-of select="@contentdepth"/>
280 <xsl:when test="@contentdepth">
281 <xsl:call-template name="length-spec">
282 <xsl:with-param name="length" select="@contentdepth"/>
283 <xsl:with-param name="default.units" select="'px'"/>
286 <xsl:when test="number($scale) != 1.0">
287 <xsl:value-of select="$scale * 100"/>
288 <xsl:text>%</xsl:text>
290 <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
291 <xsl:otherwise>auto</xsl:otherwise>
295 <xsl:if test="$content-type != ''">
296 <xsl:attribute name="content-type">
297 <xsl:value-of select="concat('content-type:',$content-type)"/>
301 <xsl:if test="$bgcolor != ''">
302 <xsl:attribute name="background-color">
303 <xsl:value-of select="$bgcolor"/>
307 <xsl:if test="@align">
308 <xsl:attribute name="text-align">
309 <xsl:value-of select="@align"/>
313 <xsl:if test="@valign">
314 <xsl:attribute name="display-align">
316 <xsl:when test="@valign = 'top'">before</xsl:when>
317 <xsl:when test="@valign = 'middle'">center</xsl:when>
318 <xsl:when test="@valign = 'bottom'">after</xsl:when>
319 <xsl:otherwise>auto</xsl:otherwise>
323 </fo:external-graphic>
326 <!-- ==================================================================== -->
328 <xsl:template match="graphic">
330 <xsl:when test="parent::inlineequation">
331 <xsl:call-template name="process.image"/>
335 <xsl:if test="@align">
336 <xsl:attribute name="text-align">
337 <xsl:value-of select="@align"/>
340 <xsl:call-template name="process.image"/>
346 <xsl:template match="inlinegraphic">
347 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
348 <xsl:variable name="filename">
350 <xsl:when test="@entityref">
351 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
354 <xsl:apply-templates select="@fileref"/>
360 <xsl:when test="@format='linespecific'">
362 <xsl:when test="$use.extensions != '0'
363 and $textinsert.extension != '0'">
365 <xsl:when test="contains($vendor, 'SAXON')">
366 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
368 <xsl:when test="contains($vendor, 'Apache Software Foundation')">
369 <xtext:insertfile href="{$filename}"/>
372 <xsl:message terminate="yes">
373 <xsl:text>Don't know how to insert files with </xsl:text>
374 <xsl:value-of select="$vendor"/>
380 <xsl:message terminate="yes">
381 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
382 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
388 <xsl:call-template name="process.image"/>
393 <!-- ==================================================================== -->
395 <xsl:template match="mediaobject|mediaobjectco">
397 <xsl:variable name="olist" select="imageobject|imageobjectco
398 |videoobject|audioobject
401 <xsl:variable name="object.index">
402 <xsl:call-template name="select.mediaobject.index">
403 <xsl:with-param name="olist" select="$olist"/>
404 <xsl:with-param name="count" select="1"/>
408 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
410 <xsl:variable name="align">
411 <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
414 <xsl:variable name="id">
415 <xsl:call-template name="object.id"/>
418 <fo:block id="{$id}">
419 <xsl:if test="$align != '' ">
420 <xsl:attribute name="text-align">
421 <xsl:value-of select="$align"/>
425 <xsl:apply-templates select="$object"/>
426 <xsl:apply-templates select="caption"/>
430 <xsl:template match="inlinemediaobject">
431 <xsl:call-template name="select.mediaobject"/>
434 <!-- ==================================================================== -->
436 <xsl:template match="imageobjectco">
437 <xsl:apply-templates select="imageobject"/>
438 <xsl:apply-templates select="calloutlist"/>
441 <xsl:template match="imageobject">
443 <xsl:when test="imagedata">
444 <xsl:apply-templates select="imagedata"/>
447 <fo:instream-foreign-object>
448 <xsl:apply-templates mode="copy-all"/>
449 </fo:instream-foreign-object>
454 <!-- ==================================================================== -->
456 <xsl:template match="*" mode="copy-all">
458 <xsl:for-each select="@*">
461 <xsl:apply-templates mode="copy-all"/>
465 <xsl:template match="text()|comment()|processing-instruction()" mode="copy-all">
469 <!-- ==================================================================== -->
471 <xsl:template match="imagedata">
472 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
473 <xsl:variable name="filename">
474 <xsl:call-template name="mediaobject.filename">
475 <xsl:with-param name="object" select=".."/>
480 <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
481 <xsl:apply-templates/>
484 <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
485 <fo:instream-foreign-object>
486 <xsl:apply-templates mode="copy-all" select="*"/>
487 </fo:instream-foreign-object>
490 <xsl:when test="@format='linespecific'">
492 <xsl:when test="$use.extensions != '0'
493 and $textinsert.extension != '0'">
495 <xsl:when test="contains($vendor, 'SAXON')">
496 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
498 <xsl:when test="contains($vendor, 'Apache Software Foundation')">
499 <xtext:insertfile href="{$filename}"/>
502 <xsl:message terminate="yes">
503 <xsl:text>Don't know how to insert files with </xsl:text>
504 <xsl:value-of select="$vendor"/>
510 <xsl:message terminate="yes">
511 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
512 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
518 <xsl:call-template name="process.image"/>
523 <!-- ==================================================================== -->
525 <xsl:template match="videoobject">
526 <xsl:apply-templates select="videodata"/>
529 <xsl:template match="videodata">
530 <xsl:call-template name="process.image"/>
533 <!-- ==================================================================== -->
535 <xsl:template match="audioobject">
536 <xsl:apply-templates select="audiodata"/>
539 <xsl:template match="audiodata">
540 <xsl:call-template name="process.image"/>
543 <!-- ==================================================================== -->
545 <xsl:template match="textobject">
546 <xsl:apply-templates/>
549 <xsl:template match="textdata">
550 <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
551 <xsl:variable name="filename">
553 <xsl:when test="@entityref">
554 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
557 <xsl:apply-templates select="@fileref"/>
562 <xsl:variable name="encoding">
564 <xsl:when test="@encoding">
565 <xsl:value-of select="@encoding"/>
568 <xsl:value-of select="$textdata.default.encoding"/>
574 <xsl:when test="$use.extensions != '0'
575 and $textinsert.extension != '0'">
577 <xsl:when test="element-available('stext:insertfile')">
578 <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
580 <xsl:when test="element-available('xtext:insertfile')">
581 <xtext:insertfile href="{$filename}"/>
584 <xsl:message terminate="yes">
585 <xsl:text>Don't know how to insert files with </xsl:text>
586 <xsl:value-of select="$vendor"/>
592 <xsl:message terminate="yes">
593 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
594 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
600 <!-- ==================================================================== -->
602 <xsl:template match="caption">
604 <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
605 <xsl:attribute name="text-align"><xsl:value-of
606 select="@align"/></xsl:attribute>
608 <xsl:apply-templates/>
612 <!-- ==================================================================== -->
614 <xsl:template name="fo-external-image">
615 <xsl:param name="filename"/>
618 <xsl:when test="$passivetex.extensions != 0
619 or $fop.extensions != 0">
620 <xsl:value-of select="$filename"/>
623 <xsl:value-of select="concat('url(', $filename, ')')"/>
628 <!-- Resolve xml:base attributes -->
629 <xsl:template match="@fileref">
630 <!-- need a check for absolute urls -->
632 <xsl:when test="contains(., ':') or starts-with(.,'/')">
633 <!-- it has a uri scheme or starts with '/', so it is an absolute uri -->
634 <xsl:value-of select="."/>
636 <xsl:when test="$keep.relative.image.uris != 0">
637 <!-- leave it alone -->
638 <xsl:value-of select="."/>
641 <!-- its a relative uri -->
642 <xsl:call-template name="relative-uri">