1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:fo="http://www.w3.org/1999/XSL/Format"
4                xmlns:xlink="http://www.w3.org/1999/xlink"
5                xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
6                xmlns:xtext="com.nwalsh.xalan.Text"
7                xmlns:lxslt="http://xml.apache.org/xslt"
8                exclude-result-prefixes="xlink stext xtext lxslt"
9                extension-element-prefixes="stext xtext"
10                version='1.0'>
11
12<!-- ********************************************************************
13     $Id$
14     ********************************************************************
15
16     This file is part of the XSL DocBook Stylesheet distribution.
17     See /README or http://nwalsh.com/docbook/xsl/ for copyright
18     and other information.
19
20     Contributors:
21     Colin Paul Adams, <colin@colina.demon.co.uk>
22
23     ******************************************************************** -->
24
25<!-- ==================================================================== -->
26<!-- Graphic format tests for the FO backend -->
27
28<!--
29FIXME: make is.graphic.* work correctly depending on the backend!
30<xsl:param name="passivetex.extensions" select="0" doc:type='boolean'/>
31<xsl:param name="fop.extensions" select="0" doc:type='boolean'/>
32-->
33
34<xsl:template name="is.graphic.format">
35  <xsl:param name="format"></xsl:param>
36  <xsl:if test="$format = 'PNG'
37                or $format = 'PDF'
38                or $format = 'JPG'
39                or $format = 'JPEG'
40                or $format = 'linespecific'
41                or $format = 'GIF'
42                or $format = 'GIF87a'
43                or $format = 'GIF89a'
44                or $format = 'BMP'">1</xsl:if>
45</xsl:template>
46
47<xsl:template name="is.graphic.extension">
48  <xsl:param name="ext"></xsl:param>
49  <xsl:if test="$ext = 'png'
50                or $ext = 'pdf'
51                or $ext = 'jpeg'
52                or $ext = 'jpg'
53                or $ext = 'gif'
54                or $ext = 'bmp'">1</xsl:if>
55</xsl:template>
56
57<!-- ==================================================================== -->
58
59<xsl:template match="screenshot">
60  <fo:block>
61    <xsl:apply-templates/>
62  </fo:block>
63</xsl:template>
64
65<xsl:template match="screeninfo">
66</xsl:template>
67
68<!-- ==================================================================== -->
69<!-- Override these templates for FO -->
70<!-- ==================================================================== -->
71
72<xsl:template name="process.image">
73  <!-- When this template is called, the current node should be  -->
74  <!-- a graphic, inlinegraphic, imagedata, or videodata. All    -->
75  <!-- those elements have the same set of attributes, so we can -->
76  <!-- handle them all in one place.                             -->
77  <xsl:variable name="input-filename">
78    <xsl:choose>
79      <xsl:when test="@entityref">
80        <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
81      </xsl:when>
82      <xsl:when test="@fileref">
83        <!-- FIXME: is this right? What if @fileref is a relative -->
84        <!-- URI? What if @fileref contains backslashes? -->
85        <xsl:text>file:</xsl:text>
86        <xsl:value-of select="@fileref"/>
87      </xsl:when>
88      <xsl:otherwise>
89        <xsl:message>
90          <xsl:text>Expected @entityref or @fileref on </xsl:text>
91          <xsl:value-of select="name(.)"/>
92        </xsl:message>
93      </xsl:otherwise>
94    </xsl:choose>
95  </xsl:variable>
96
97  <xsl:variable name="fileext">
98    <xsl:call-template name="filename-extension">
99      <xsl:with-param name="filename" select="$input-filename"/>
100    </xsl:call-template>
101  </xsl:variable>
102
103  <xsl:variable name="filename">
104    <xsl:choose>
105      <xsl:when test="$fileext != ''">
106        <xsl:value-of select="$input-filename"/>
107      </xsl:when>
108      <xsl:when test="$graphic.default.extension != ''">
109        <xsl:value-of select="$input-filename"/>
110        <xsl:text>.</xsl:text>
111        <xsl:value-of select="$graphic.default.extension"/>
112      </xsl:when>
113      <xsl:otherwise>
114        <xsl:value-of select="$input-filename"/>
115      </xsl:otherwise>
116    </xsl:choose>
117  </xsl:variable>
118
119  <xsl:variable name="scale">
120    <xsl:choose>
121      <xsl:when test="@scale"><xsl:value-of select="@scale"/>%</xsl:when>
122      <xsl:otherwise>auto</xsl:otherwise>
123    </xsl:choose>
124  </xsl:variable>
125
126  <xsl:variable name="width">
127    <xsl:choose>
128      <xsl:when test="@width">
129        <xsl:call-template name="length-spec">
130          <xsl:with-param name="length" select="@width"/>
131          <xsl:with-param name="default.units" select="$default.units"/>
132        </xsl:call-template>
133      </xsl:when>
134      <xsl:otherwise>auto</xsl:otherwise>
135    </xsl:choose>
136  </xsl:variable>
137
138  <xsl:variable name="height">
139    <xsl:choose>
140      <xsl:when test="@depth">
141        <xsl:call-template name="length-spec">
142          <xsl:with-param name="length" select="@depth"/>
143          <xsl:with-param name="default.units" select="$default.units"/>
144        </xsl:call-template>
145      </xsl:when>
146      <xsl:otherwise>auto</xsl:otherwise>
147    </xsl:choose>
148  </xsl:variable>
149
150  <!-- Scaling seems to require calculating an absolute width and height
151       from a scale factor and the intrinsic width and height (possibly
152       with contributions from the specified width and height). I'm not
153       sure how to specify that... -->
154
155  <xsl:choose>
156    <xsl:when test="$passivetex.extensions != 0
157                    or $fop.extensions != 0
158                    or $arbortext.extensions != 0">
159      <fo:external-graphic src="{$filename}"
160                           content-width="{$width}"
161                           content-height="{$height}"
162                           width="auto"
163                           height="auto"/>
164    </xsl:when>
165    <xsl:otherwise>
166      <fo:external-graphic src="url({$filename})"
167                           content-width="{$width}"
168                           content-height="{$height}"
169                           width="auto"
170                           height="auto"/>
171    </xsl:otherwise>
172  </xsl:choose>
173</xsl:template>
174
175<!-- ==================================================================== -->
176
177<xsl:template match="graphic">
178  <fo:block>
179    <xsl:call-template name="process.image"/>
180  </fo:block>
181</xsl:template>
182
183<xsl:template match="inlinegraphic">
184  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
185  <xsl:variable name="filename">
186    <xsl:choose>
187      <xsl:when test="@entityref">
188        <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
189      </xsl:when>
190      <xsl:otherwise>
191        <xsl:value-of select="@fileref"/>
192      </xsl:otherwise>
193    </xsl:choose>
194  </xsl:variable>
195
196  <xsl:choose>
197    <xsl:when test="@format='linespecific'">
198      <xsl:choose>
199        <xsl:when test="$use.extensions != '0'
200                        and $textinsert.extension != '0'">
201          <xsl:choose>
202            <xsl:when test="contains($vendor, 'SAXON')">
203              <stext:insertfile href="{$filename}"/>
204            </xsl:when>
205            <xsl:when test="contains($vendor, 'Apache Software Foundation')">
206              <xtext:insertfile href="{$filename}"/>
207            </xsl:when>
208            <xsl:otherwise>
209              <xsl:message terminate="yes">
210                <xsl:text>Don't know how to insert files with </xsl:text>
211                <xsl:value-of select="$vendor"/>
212              </xsl:message>
213            </xsl:otherwise>
214          </xsl:choose>
215        </xsl:when>
216        <xsl:otherwise>
217          <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
218             href="{$filename}"/>
219        </xsl:otherwise>
220      </xsl:choose>
221    </xsl:when>
222    <xsl:otherwise>
223      <xsl:call-template name="process.image"/>
224    </xsl:otherwise>
225  </xsl:choose>
226</xsl:template>
227
228<!-- ==================================================================== -->
229
230<xsl:template match="mediaobject">
231  <fo:block>
232    <xsl:call-template name="select.mediaobject"/>
233    <xsl:apply-templates select="caption"/>
234  </fo:block>
235</xsl:template>
236
237<xsl:template match="inlinemediaobject">
238  <xsl:call-template name="select.mediaobject"/>
239</xsl:template>
240
241<!-- ==================================================================== -->
242
243<xsl:template match="imageobjectco">
244  <xsl:apply-templates select="imageobject"/>
245  <xsl:apply-templates select="calloutlist"/>
246</xsl:template>
247
248<xsl:template match="imageobject">
249  <xsl:apply-templates select="imagedata"/>
250</xsl:template>
251
252<xsl:template match="imagedata">
253  <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
254  <xsl:variable name="filename">
255    <xsl:call-template name="mediaobject.filename">
256      <xsl:with-param name="object" select=".."/>
257    </xsl:call-template>
258  </xsl:variable>
259
260  <xsl:choose>
261    <xsl:when test="@format='linespecific'">
262      <xsl:choose>
263        <xsl:when test="$use.extensions != '0'
264                        and $textinsert.extension != '0'">
265          <xsl:choose>
266            <xsl:when test="contains($vendor, 'SAXON')">
267              <stext:insertfile href="{$filename}"/>
268            </xsl:when>
269            <xsl:when test="contains($vendor, 'Apache Software Foundation')">
270              <xtext:insertfile href="{$filename}"/>
271            </xsl:when>
272            <xsl:otherwise>
273              <xsl:message terminate="yes">
274                <xsl:text>Don't know how to insert files with </xsl:text>
275                <xsl:value-of select="$vendor"/>
276              </xsl:message>
277            </xsl:otherwise>
278          </xsl:choose>
279        </xsl:when>
280        <xsl:otherwise>
281          <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
282             href="{$filename}"/>
283        </xsl:otherwise>
284      </xsl:choose>
285    </xsl:when>
286    <xsl:otherwise>
287      <xsl:call-template name="process.image"/>
288    </xsl:otherwise>
289  </xsl:choose>
290</xsl:template>
291
292<!-- ==================================================================== -->
293
294<xsl:template match="videoobject">
295  <xsl:apply-templates select="videodata"/>
296</xsl:template>
297
298<xsl:template match="videodata">
299  <xsl:call-template name="process.image"/>
300</xsl:template>
301
302<!-- ==================================================================== -->
303
304<xsl:template match="audioobject">
305  <xsl:apply-templates select="audiodata"/>
306</xsl:template>
307
308<xsl:template match="audiodata">
309  <xsl:call-template name="process.image"/>
310</xsl:template>
311
312<!-- ==================================================================== -->
313
314<xsl:template match="textobject">
315  <xsl:apply-templates/>
316</xsl:template>
317
318<!-- ==================================================================== -->
319
320<xsl:template match="caption">
321  <fo:block>
322    <xsl:apply-templates/>
323  </fo:block>
324</xsl:template>
325
326</xsl:stylesheet>
327