Imported Upstream version 1.77.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 8988 2011-04-06 15:56:33Z kosek $
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   <fo:inline>
88     <xsl:call-template name="anchor"/>
89     <xsl:apply-templates select="." mode="callout-bug"/>
90   </fo:inline>
91 </xsl:template>
92
93 <xsl:template match="coref">
94   <!-- tricky; this relies on the fact that we can process the "co" that's -->
95   <!-- "over there" as if it were "right here" -->
96
97   <xsl:variable name="co" select="key('id', @linkend)"/>
98   <xsl:choose>
99     <xsl:when test="not($co)">
100       <xsl:message>
101         <xsl:text>Error: coref link is broken: </xsl:text>
102         <xsl:value-of select="@linkend"/>
103       </xsl:message>
104     </xsl:when>
105     <xsl:when test="local-name($co) != 'co'">
106       <xsl:message>
107         <xsl:text>Error: coref doesn't point to a co: </xsl:text>
108         <xsl:value-of select="@linkend"/>
109       </xsl:message>
110     </xsl:when>
111     <xsl:otherwise>
112       <fo:inline>
113         <xsl:call-template name="anchor"/>
114         <xsl:apply-templates select="$co" mode="callout-bug"/>
115       </fo:inline>
116     </xsl:otherwise>
117   </xsl:choose>
118 </xsl:template>
119
120 <xsl:template match="co" mode="callout-bug">
121   <xsl:call-template name="callout-bug">
122     <xsl:with-param name="conum">
123       <xsl:number count="co"
124                   level="any"
125                   from="programlisting|screen|literallayout|synopsis"
126                   format="1"/>
127     </xsl:with-param>
128   </xsl:call-template>
129 </xsl:template>
130
131 <xsl:template name="callout-bug">
132   <xsl:param name="conum" select='1'/>
133
134   <xsl:choose>
135     <!-- Draw callouts as images -->
136     <xsl:when test="$callout.graphics != '0'
137                     and $conum &lt;= $callout.graphics.number.limit">
138       <xsl:variable name="filename"
139                     select="concat($callout.graphics.path, $conum,
140                                    $callout.graphics.extension)"/>
141
142       <fo:external-graphic content-width="{$callout.icon.size}"
143                            width="{$callout.icon.size}">
144         <xsl:attribute name="src">
145           <xsl:choose>
146             <xsl:when test="$passivetex.extensions != 0
147                             or $fop.extensions != 0
148                             or $arbortext.extensions != 0">
149               <xsl:value-of select="$filename"/>
150             </xsl:when>
151             <xsl:otherwise>
152               <xsl:text>url(</xsl:text>
153               <xsl:value-of select="$filename"/>
154               <xsl:text>)</xsl:text>
155             </xsl:otherwise>
156           </xsl:choose>
157         </xsl:attribute>
158       </fo:external-graphic>
159     </xsl:when>
160
161     <xsl:when test="$callout.unicode != 0
162                     and $conum &lt;= $callout.unicode.number.limit">
163       <xsl:variable name="comarkup">
164         <xsl:choose>
165           <xsl:when test="$callout.unicode.start.character = 10102">
166             <xsl:choose>
167               <xsl:when test="$conum = 1">&#10102;</xsl:when>
168               <xsl:when test="$conum = 2">&#10103;</xsl:when>
169               <xsl:when test="$conum = 3">&#10104;</xsl:when>
170               <xsl:when test="$conum = 4">&#10105;</xsl:when>
171               <xsl:when test="$conum = 5">&#10106;</xsl:when>
172               <xsl:when test="$conum = 6">&#10107;</xsl:when>
173               <xsl:when test="$conum = 7">&#10108;</xsl:when>
174               <xsl:when test="$conum = 8">&#10109;</xsl:when>
175               <xsl:when test="$conum = 9">&#10110;</xsl:when>
176               <xsl:when test="$conum = 10">&#10111;</xsl:when>
177               <xsl:when test="$conum = 11">&#9451;</xsl:when>
178               <xsl:when test="$conum = 12">&#9452;</xsl:when>
179               <xsl:when test="$conum = 13">&#9453;</xsl:when>
180               <xsl:when test="$conum = 14">&#9454;</xsl:when>
181               <xsl:when test="$conum = 15">&#9455;</xsl:when>
182               <xsl:when test="$conum = 16">&#9456;</xsl:when>
183               <xsl:when test="$conum = 17">&#9457;</xsl:when>
184               <xsl:when test="$conum = 18">&#9458;</xsl:when>
185               <xsl:when test="$conum = 19">&#9459;</xsl:when>
186               <xsl:when test="$conum = 20">&#9460;</xsl:when>
187             </xsl:choose>
188           </xsl:when>
189           <xsl:when test="$callout.unicode.start.character = 9312">
190             <xsl:choose>
191               <xsl:when test="$conum = 1">&#9312;</xsl:when>
192               <xsl:when test="$conum = 2">&#9313;</xsl:when>
193               <xsl:when test="$conum = 3">&#9314;</xsl:when>
194               <xsl:when test="$conum = 4">&#9315;</xsl:when>
195               <xsl:when test="$conum = 5">&#9316;</xsl:when>
196               <xsl:when test="$conum = 6">&#9317;</xsl:when>
197               <xsl:when test="$conum = 7">&#9318;</xsl:when>
198               <xsl:when test="$conum = 8">&#9319;</xsl:when>
199               <xsl:when test="$conum = 9">&#9320;</xsl:when>
200               <xsl:when test="$conum = 10">&#9321;</xsl:when>
201               <xsl:when test="$conum = 11">&#9322;</xsl:when>
202               <xsl:when test="$conum = 12">&#9323;</xsl:when>
203               <xsl:when test="$conum = 13">&#9324;</xsl:when>
204               <xsl:when test="$conum = 14">&#9325;</xsl:when>
205               <xsl:when test="$conum = 15">&#9326;</xsl:when>
206               <xsl:when test="$conum = 16">&#9327;</xsl:when>
207               <xsl:when test="$conum = 17">&#9328;</xsl:when>
208               <xsl:when test="$conum = 18">&#9329;</xsl:when>
209               <xsl:when test="$conum = 19">&#9330;</xsl:when>
210               <xsl:when test="$conum = 20">&#9331;</xsl:when>
211             </xsl:choose>
212           </xsl:when>
213           <xsl:otherwise>
214             <xsl:message>
215               <xsl:text>Don't know how to generate Unicode callouts </xsl:text>
216               <xsl:text>when $callout.unicode.start.character is </xsl:text>
217               <xsl:value-of select="$callout.unicode.start.character"/>
218             </xsl:message>
219             <fo:inline background-color="#404040"
220                        color="white"
221                        padding-top="0.1em"
222                        padding-bottom="0.1em"
223                        padding-start="0.2em"
224                        padding-end="0.2em"
225                        baseline-shift="0.1em"
226                        font-family="{$body.fontset}"
227                        font-weight="bold"
228                        font-size="75%">
229               <xsl:value-of select="$conum"/>
230             </fo:inline>
231           </xsl:otherwise>
232         </xsl:choose>
233       </xsl:variable>
234
235       <xsl:choose>
236         <xsl:when test="$callout.unicode.font != ''">
237           <fo:inline font-family="{$callout.unicode.font}">
238             <xsl:copy-of select="$comarkup"/>
239           </fo:inline>
240         </xsl:when>
241         <xsl:otherwise>
242           <xsl:copy-of select="$comarkup"/>
243         </xsl:otherwise>
244       </xsl:choose>
245     </xsl:when>
246
247     <!-- Most safe: draw a dark gray square with a white number inside -->
248     <xsl:otherwise>
249       <fo:inline background-color="#404040"
250                  color="white"
251                  padding-top="0.1em"
252                  padding-bottom="0.1em"
253                  padding-start="0.2em"
254                  padding-end="0.2em"
255                  baseline-shift="0.1em"
256                  font-family="{$body.fontset}"
257                  font-weight="bold"
258                  font-size="75%">
259         <xsl:value-of select="$conum"/>
260       </fo:inline>
261     </xsl:otherwise>
262   </xsl:choose>
263 </xsl:template>
264
265 </xsl:stylesheet>