callout.xsl 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. $Id$
  11. ********************************************************************
  12. This file is part of the XSL DocBook Stylesheet distribution.
  13. See ../README or http://docbook.sf.net/release/xsl/current/ for
  14. copyright and other information.
  15. ******************************************************************** -->
  16. <lxslt:component prefix="xverb"
  17. functions="insertCallouts"/>
  18. <xsl:template match="programlistingco|screenco">
  19. <xsl:variable name="verbatim" select="programlisting|screen"/>
  20. <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
  21. <xsl:choose>
  22. <xsl:when test="$use.extensions != '0'
  23. and $callouts.extension != '0'">
  24. <xsl:variable name="rtf">
  25. <xsl:apply-templates select="$verbatim">
  26. <xsl:with-param name="suppress-numbers" select="'1'"/>
  27. </xsl:apply-templates>
  28. </xsl:variable>
  29. <xsl:variable name="rtf-with-callouts">
  30. <xsl:choose>
  31. <xsl:when test="contains($vendor, 'SAXON ')">
  32. <xsl:copy-of select="sverb:insertCallouts(areaspec,$rtf)"/>
  33. </xsl:when>
  34. <xsl:when test="contains($vendor, 'Apache Software Foundation')">
  35. <xsl:copy-of select="xverb:insertCallouts(areaspec,$rtf)"/>
  36. </xsl:when>
  37. <xsl:otherwise>
  38. <xsl:message terminate="yes">
  39. <xsl:text>Don't know how to do callouts with </xsl:text>
  40. <xsl:value-of select="$vendor"/>
  41. </xsl:message>
  42. </xsl:otherwise>
  43. </xsl:choose>
  44. </xsl:variable>
  45. <xsl:choose>
  46. <xsl:when test="$verbatim/@linenumbering = 'numbered'
  47. and $linenumbering.extension != '0'">
  48. <xsl:call-template name="number.rtf.lines">
  49. <xsl:with-param name="rtf" select="$rtf-with-callouts"/>
  50. <xsl:with-param name="pi.context"
  51. select="programlisting|screen"/>
  52. </xsl:call-template>
  53. <xsl:apply-templates select="calloutlist"/>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. <xsl:copy-of select="$rtf-with-callouts"/>
  57. <xsl:apply-templates select="calloutlist"/>
  58. </xsl:otherwise>
  59. </xsl:choose>
  60. </xsl:when>
  61. <xsl:otherwise>
  62. <xsl:apply-templates/>
  63. </xsl:otherwise>
  64. </xsl:choose>
  65. </xsl:template>
  66. <xsl:template match="areaspec|areaset|area">
  67. </xsl:template>
  68. <xsl:template match="areaset" mode="conumber">
  69. <xsl:number count="area|areaset" format="1"/>
  70. </xsl:template>
  71. <xsl:template match="area" mode="conumber">
  72. <xsl:number count="area|areaset" format="1"/>
  73. </xsl:template>
  74. <xsl:template match="co">
  75. <fo:inline>
  76. <xsl:call-template name="anchor"/>
  77. <xsl:apply-templates select="." mode="callout-bug"/>
  78. </fo:inline>
  79. </xsl:template>
  80. <xsl:template match="coref">
  81. <!-- tricky; this relies on the fact that we can process the "co" that's -->
  82. <!-- "over there" as if it were "right here" -->
  83. <xsl:variable name="co" select="key('id', @linkend)"/>
  84. <xsl:choose>
  85. <xsl:when test="not($co)">
  86. <xsl:message>
  87. <xsl:text>Error: coref link is broken: </xsl:text>
  88. <xsl:value-of select="@linkend"/>
  89. </xsl:message>
  90. </xsl:when>
  91. <xsl:when test="local-name($co) != 'co'">
  92. <xsl:message>
  93. <xsl:text>Error: coref doesn't point to a co: </xsl:text>
  94. <xsl:value-of select="@linkend"/>
  95. </xsl:message>
  96. </xsl:when>
  97. <xsl:otherwise>
  98. <fo:inline>
  99. <xsl:call-template name="anchor"/>
  100. <xsl:apply-templates select="$co" mode="callout-bug"/>
  101. </fo:inline>
  102. </xsl:otherwise>
  103. </xsl:choose>
  104. </xsl:template>
  105. <xsl:template match="co" mode="callout-bug">
  106. <xsl:call-template name="callout-bug">
  107. <xsl:with-param name="conum">
  108. <xsl:number count="co"
  109. level="any"
  110. from="programlisting|screen|literallayout|synopsis"
  111. format="1"/>
  112. </xsl:with-param>
  113. </xsl:call-template>
  114. </xsl:template>
  115. <xsl:template name="callout-bug">
  116. <xsl:param name="conum" select='1'/>
  117. <xsl:choose>
  118. <!-- Draw callouts as images -->
  119. <xsl:when test="$callout.graphics != '0'
  120. and $conum &lt;= $callout.graphics.number.limit">
  121. <xsl:variable name="filename"
  122. select="concat($callout.graphics.path, $conum,
  123. $callout.graphics.extension)"/>
  124. <fo:external-graphic content-width="{$callout.icon.size}"
  125. width="{$callout.icon.size}">
  126. <xsl:attribute name="src">
  127. <xsl:choose>
  128. <xsl:when test="$passivetex.extensions != 0
  129. or $fop.extensions != 0
  130. or $arbortext.extensions != 0">
  131. <xsl:value-of select="$filename"/>
  132. </xsl:when>
  133. <xsl:otherwise>
  134. <xsl:text>url(</xsl:text>
  135. <xsl:value-of select="$filename"/>
  136. <xsl:text>)</xsl:text>
  137. </xsl:otherwise>
  138. </xsl:choose>
  139. </xsl:attribute>
  140. </fo:external-graphic>
  141. </xsl:when>
  142. <xsl:when test="$callout.unicode != 0
  143. and $conum &lt;= $callout.unicode.number.limit">
  144. <xsl:variable name="comarkup">
  145. <xsl:choose>
  146. <xsl:when test="$callout.unicode.start.character = 10102">
  147. <xsl:choose>
  148. <xsl:when test="$conum = 1">&#10102;</xsl:when>
  149. <xsl:when test="$conum = 2">&#10103;</xsl:when>
  150. <xsl:when test="$conum = 3">&#10104;</xsl:when>
  151. <xsl:when test="$conum = 4">&#10105;</xsl:when>
  152. <xsl:when test="$conum = 5">&#10106;</xsl:when>
  153. <xsl:when test="$conum = 6">&#10107;</xsl:when>
  154. <xsl:when test="$conum = 7">&#10108;</xsl:when>
  155. <xsl:when test="$conum = 8">&#10109;</xsl:when>
  156. <xsl:when test="$conum = 9">&#10110;</xsl:when>
  157. <xsl:when test="$conum = 10">&#10111;</xsl:when>
  158. </xsl:choose>
  159. </xsl:when>
  160. <xsl:otherwise>
  161. <xsl:message>
  162. <xsl:text>Don't know how to generate Unicode callouts </xsl:text>
  163. <xsl:text>when $callout.unicode.start.character is </xsl:text>
  164. <xsl:value-of select="$callout.unicode.start.character"/>
  165. </xsl:message>
  166. <fo:inline background-color="#404040"
  167. color="white"
  168. padding-top="0.1em"
  169. padding-bottom="0.1em"
  170. padding-start="0.2em"
  171. padding-end="0.2em"
  172. baseline-shift="0.1em"
  173. font-family="{$body.fontset}"
  174. font-weight="bold"
  175. font-size="75%">
  176. <xsl:value-of select="$conum"/>
  177. </fo:inline>
  178. </xsl:otherwise>
  179. </xsl:choose>
  180. </xsl:variable>
  181. <xsl:choose>
  182. <xsl:when test="$callout.unicode.font != ''">
  183. <fo:inline font-family="{$callout.unicode.font}">
  184. <xsl:copy-of select="$comarkup"/>
  185. </fo:inline>
  186. </xsl:when>
  187. <xsl:otherwise>
  188. <xsl:copy-of select="$comarkup"/>
  189. </xsl:otherwise>
  190. </xsl:choose>
  191. </xsl:when>
  192. <!-- Most safe: draw a dark gray square with a white number inside -->
  193. <xsl:otherwise>
  194. <fo:inline background-color="#404040"
  195. color="white"
  196. padding-top="0.1em"
  197. padding-bottom="0.1em"
  198. padding-start="0.2em"
  199. padding-end="0.2em"
  200. baseline-shift="0.1em"
  201. font-family="{$body.fontset}"
  202. font-weight="bold"
  203. font-size="75%">
  204. <xsl:value-of select="$conum"/>
  205. </fo:inline>
  206. </xsl:otherwise>
  207. </xsl:choose>
  208. </xsl:template>
  209. </xsl:stylesheet>