Imported Upstream version 1.78.1
[platform/upstream/docbook-xsl-stylesheets.git] / fo / callout.xsl
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:sverb="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Verbatim"
5                 xmlns:xverb="com.nwalsh.xalan.Verbatim"
6                 xmlns:lxslt="http://xml.apache.org/xslt"
7                 exclude-result-prefixes="sverb xverb lxslt"
8                 version='1.0'>
9
10 <!-- ********************************************************************
11      $Id: callout.xsl 9668 2012-11-28 00:47:59Z bobstayton $
12      ********************************************************************
13
14      This file is part of the XSL DocBook Stylesheet distribution.
15      See ../README or http://docbook.sf.net/release/xsl/current/ for
16      copyright and other information.
17
18      ******************************************************************** -->
19
20 <lxslt:component prefix="xverb"
21                  functions="insertCallouts"/>
22
23 <xsl:template match="programlistingco|screenco">
24   <xsl:variable name="verbatim" select="programlisting|screen"/>
25   <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
26
27   <xsl:choose>
28     <xsl:when test="$use.extensions != '0'
29                     and $callouts.extension != '0'">
30       <xsl:variable name="rtf">
31         <xsl:apply-templates select="$verbatim">
32           <xsl:with-param name="suppress-numbers" select="'1'"/>
33         </xsl:apply-templates>
34       </xsl:variable>
35
36       <xsl:variable name="rtf-with-callouts">
37         <xsl:choose>
38           <xsl:when test="contains($vendor, 'SAXON ')">
39             <xsl:copy-of select="sverb:insertCallouts(areaspec,$rtf)"/>
40           </xsl:when>
41           <xsl:when test="contains($vendor, 'Apache Software Foundation')">
42             <xsl:copy-of select="xverb:insertCallouts(areaspec,$rtf)"/>
43           </xsl:when>
44           <xsl:otherwise>
45             <xsl:message terminate="yes">
46               <xsl:text>Don't know how to do callouts with </xsl:text>
47               <xsl:value-of select="$vendor"/>
48             </xsl:message>
49           </xsl:otherwise>
50         </xsl:choose>
51       </xsl:variable>
52
53       <xsl:choose>
54         <xsl:when test="$verbatim/@linenumbering = 'numbered'
55                         and $linenumbering.extension != '0'">
56           <xsl:call-template name="number.rtf.lines">
57             <xsl:with-param name="rtf" select="$rtf-with-callouts"/>
58             <xsl:with-param name="pi.context"
59                             select="programlisting|screen"/>
60           </xsl:call-template>
61           <xsl:apply-templates select="calloutlist"/>
62         </xsl:when>
63         <xsl:otherwise>
64           <xsl:copy-of select="$rtf-with-callouts"/>
65           <xsl:apply-templates select="calloutlist"/>
66         </xsl:otherwise>
67       </xsl:choose>
68     </xsl:when>
69     <xsl:otherwise>
70       <xsl:apply-templates/>
71     </xsl:otherwise>
72   </xsl:choose>
73 </xsl:template>
74
75 <xsl:template match="areaspec|areaset|area">
76 </xsl:template>
77
78 <xsl:template match="areaset" mode="conumber">
79   <xsl:number count="area|areaset" format="1"/>
80 </xsl:template>
81
82 <xsl:template match="area" mode="conumber">
83   <xsl:number count="area|areaset" format="1"/>
84 </xsl:template>
85
86 <xsl:template match="co">
87   <xsl:param name="coref"/> 
88   <!-- link to the callout? -->
89   <xsl:variable name="linkend">
90     <xsl:choose>
91       <!-- if more than one target, choose the first -->
92       <xsl:when test="contains(normalize-space(@linkends), ' ')">
93         <xsl:value-of select="substring-before(normalize-space(@linkends), ' ')"/>
94       </xsl:when>
95       <xsl:when test="string-length(normalize-space(@linkends)) != 0">
96         <xsl:value-of select="normalize-space(@linkends)"/>
97       </xsl:when>
98       <xsl:otherwise>
99       </xsl:otherwise>
100     </xsl:choose>
101   </xsl:variable>
102
103   <xsl:choose>
104     <xsl:when test="string-length($linkend) != 0">
105       <fo:basic-link internal-destination="{$linkend}">
106         <xsl:choose>
107           <xsl:when test="$coref">
108             <xsl:call-template name="anchor">
109               <xsl:with-param name="node" select="$coref"/>
110               <xsl:with-param name="conditional" select="0"/>
111             </xsl:call-template>
112           </xsl:when>
113           <xsl:otherwise>
114             <xsl:call-template name="anchor">
115               <xsl:with-param name="conditional" select="0"/>
116             </xsl:call-template>
117           </xsl:otherwise>
118         </xsl:choose>
119         <xsl:apply-templates select="." mode="callout-bug"/>
120       </fo:basic-link>
121     </xsl:when>
122     <xsl:otherwise>
123       <fo:inline>
124         <xsl:choose>
125           <xsl:when test="$coref">
126             <xsl:call-template name="anchor">
127               <xsl:with-param name="node" select="$coref"/>
128               <xsl:with-param name="conditional" select="0"/>
129             </xsl:call-template>
130           </xsl:when>
131           <xsl:otherwise>
132             <xsl:call-template name="anchor">
133               <xsl:with-param name="conditional" select="0"/>
134             </xsl:call-template>
135           </xsl:otherwise>
136         </xsl:choose>
137         <xsl:apply-templates select="." mode="callout-bug"/>
138       </fo:inline>
139     </xsl:otherwise>
140   </xsl:choose>
141 </xsl:template>
142
143 <xsl:template match="coref">
144   <!-- this relies on the fact that we can process the "co" that's -->
145   <!-- "over there" as if it were "right here" -->
146
147   <xsl:variable name="co" select="key('id', @linkend)"/>
148   <xsl:choose>
149     <xsl:when test="not($co)">
150       <xsl:message>
151         <xsl:text>Error: coref link is broken: </xsl:text>
152         <xsl:value-of select="@linkend"/>
153       </xsl:message>
154     </xsl:when>
155     <xsl:when test="local-name($co) != 'co'">
156       <xsl:message>
157         <xsl:text>Error: coref doesn't point to a co: </xsl:text>
158         <xsl:value-of select="@linkend"/>
159       </xsl:message>
160     </xsl:when>
161     <xsl:otherwise>
162       <!-- process it as if it were the co itself -->
163       <xsl:apply-templates select="$co">
164         <xsl:with-param name="coref" select="."/>
165       </xsl:apply-templates>
166     </xsl:otherwise>
167   </xsl:choose>
168 </xsl:template>
169
170 <xsl:template match="co" mode="callout-bug">
171   <xsl:call-template name="callout-bug">
172     <xsl:with-param name="conum">
173       <xsl:number count="co"
174                   level="any"
175                   from="programlisting|screen|literallayout|synopsis"
176                   format="1"/>
177     </xsl:with-param>
178   </xsl:call-template>
179 </xsl:template>
180
181 <xsl:template name="callout-bug">
182   <xsl:param name="conum" select='1'/>
183
184   <xsl:choose>
185     <!-- Draw callouts as images -->
186     <xsl:when test="$callout.graphics != '0'
187                     and $conum &lt;= $callout.graphics.number.limit">
188       <xsl:variable name="filename"
189                     select="concat($callout.graphics.path, $conum,
190                                    $callout.graphics.extension)"/>
191
192       <fo:external-graphic content-width="{$callout.icon.size}"
193                            width="{$callout.icon.size}">
194         <xsl:attribute name="src">
195           <xsl:choose>
196             <xsl:when test="$fop.extensions != 0
197                             or $arbortext.extensions != 0">
198               <xsl:value-of select="$filename"/>
199             </xsl:when>
200             <xsl:otherwise>
201               <xsl:text>url(</xsl:text>
202               <xsl:value-of select="$filename"/>
203               <xsl:text>)</xsl:text>
204             </xsl:otherwise>
205           </xsl:choose>
206         </xsl:attribute>
207       </fo:external-graphic>
208     </xsl:when>
209
210     <xsl:when test="$callout.unicode != 0
211                     and $conum &lt;= $callout.unicode.number.limit">
212       <xsl:variable name="comarkup">
213         <xsl:choose>
214           <xsl:when test="$callout.unicode.start.character = 10102">
215             <xsl:choose>
216               <xsl:when test="$conum = 1">&#10102;</xsl:when>
217               <xsl:when test="$conum = 2">&#10103;</xsl:when>
218               <xsl:when test="$conum = 3">&#10104;</xsl:when>
219               <xsl:when test="$conum = 4">&#10105;</xsl:when>
220               <xsl:when test="$conum = 5">&#10106;</xsl:when>
221               <xsl:when test="$conum = 6">&#10107;</xsl:when>
222               <xsl:when test="$conum = 7">&#10108;</xsl:when>
223               <xsl:when test="$conum = 8">&#10109;</xsl:when>
224               <xsl:when test="$conum = 9">&#10110;</xsl:when>
225               <xsl:when test="$conum = 10">&#10111;</xsl:when>
226               <xsl:when test="$conum = 11">&#9451;</xsl:when>
227               <xsl:when test="$conum = 12">&#9452;</xsl:when>
228               <xsl:when test="$conum = 13">&#9453;</xsl:when>
229               <xsl:when test="$conum = 14">&#9454;</xsl:when>
230               <xsl:when test="$conum = 15">&#9455;</xsl:when>
231               <xsl:when test="$conum = 16">&#9456;</xsl:when>
232               <xsl:when test="$conum = 17">&#9457;</xsl:when>
233               <xsl:when test="$conum = 18">&#9458;</xsl:when>
234               <xsl:when test="$conum = 19">&#9459;</xsl:when>
235               <xsl:when test="$conum = 20">&#9460;</xsl:when>
236             </xsl:choose>
237           </xsl:when>
238           <xsl:when test="$callout.unicode.start.character = 9312">
239             <xsl:choose>
240               <xsl:when test="$conum = 1">&#9312;</xsl:when>
241               <xsl:when test="$conum = 2">&#9313;</xsl:when>
242               <xsl:when test="$conum = 3">&#9314;</xsl:when>
243               <xsl:when test="$conum = 4">&#9315;</xsl:when>
244               <xsl:when test="$conum = 5">&#9316;</xsl:when>
245               <xsl:when test="$conum = 6">&#9317;</xsl:when>
246               <xsl:when test="$conum = 7">&#9318;</xsl:when>
247               <xsl:when test="$conum = 8">&#9319;</xsl:when>
248               <xsl:when test="$conum = 9">&#9320;</xsl:when>
249               <xsl:when test="$conum = 10">&#9321;</xsl:when>
250               <xsl:when test="$conum = 11">&#9322;</xsl:when>
251               <xsl:when test="$conum = 12">&#9323;</xsl:when>
252               <xsl:when test="$conum = 13">&#9324;</xsl:when>
253               <xsl:when test="$conum = 14">&#9325;</xsl:when>
254               <xsl:when test="$conum = 15">&#9326;</xsl:when>
255               <xsl:when test="$conum = 16">&#9327;</xsl:when>
256               <xsl:when test="$conum = 17">&#9328;</xsl:when>
257               <xsl:when test="$conum = 18">&#9329;</xsl:when>
258               <xsl:when test="$conum = 19">&#9330;</xsl:when>
259               <xsl:when test="$conum = 20">&#9331;</xsl:when>
260             </xsl:choose>
261           </xsl:when>
262           <xsl:otherwise>
263             <xsl:message>
264               <xsl:text>Don't know how to generate Unicode callouts </xsl:text>
265               <xsl:text>when $callout.unicode.start.character is </xsl:text>
266               <xsl:value-of select="$callout.unicode.start.character"/>
267             </xsl:message>
268             <fo:inline background-color="#404040"
269                        color="white"
270                        padding-top="0.1em"
271                        padding-bottom="0.1em"
272                        padding-start="0.2em"
273                        padding-end="0.2em"
274                        baseline-shift="0.1em"
275                        font-family="{$body.fontset}"
276                        font-weight="bold"
277                        font-size="75%">
278               <xsl:value-of select="$conum"/>
279             </fo:inline>
280           </xsl:otherwise>
281         </xsl:choose>
282       </xsl:variable>
283
284       <xsl:choose>
285         <xsl:when test="$callout.unicode.font != ''">
286           <fo:inline font-family="{$callout.unicode.font}">
287             <xsl:copy-of select="$comarkup"/>
288           </fo:inline>
289         </xsl:when>
290         <xsl:otherwise>
291           <xsl:copy-of select="$comarkup"/>
292         </xsl:otherwise>
293       </xsl:choose>
294     </xsl:when>
295
296     <!-- Most safe: draw a dark gray square with a white number inside -->
297     <xsl:otherwise>
298       <fo:inline background-color="#404040"
299                  color="white"
300                  padding-top="0.1em"
301                  padding-bottom="0.1em"
302                  padding-start="0.2em"
303                  padding-end="0.2em"
304                  baseline-shift="0.1em"
305                  font-family="{$body.fontset}"
306                  font-weight="bold"
307                  font-size="75%">
308         <xsl:value-of select="$conum"/>
309       </fo:inline>
310     </xsl:otherwise>
311   </xsl:choose>
312 </xsl:template>
313
314 </xsl:stylesheet>