spaces.xsl 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?xml version='1.0' encoding="utf-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  4. version='1.0'>
  5. <!-- ********************************************************************
  6. $Id$
  7. ********************************************************************
  8. XSL-FO specification treats all space characters like ordinary spaces.
  9. We need to map them to fo:leader with different widths in order to
  10. simulate desired behaviour.
  11. ******************************************************************** -->
  12. <xsl:template match="text()[namespace-uri(..) = '']">
  13. <xsl:choose>
  14. <xsl:when test="$passivetex.extensions != 0">
  15. <xsl:call-template name="passivetex.dash.subst">
  16. <xsl:with-param name="string">
  17. <xsl:call-template name="space.2000.subst">
  18. <xsl:with-param name="string" select="."/>
  19. </xsl:call-template>
  20. </xsl:with-param>
  21. </xsl:call-template>
  22. </xsl:when>
  23. <xsl:otherwise>
  24. <xsl:call-template name="space.2000.subst">
  25. <xsl:with-param name="string" select="."/>
  26. </xsl:call-template>
  27. </xsl:otherwise>
  28. </xsl:choose>
  29. </xsl:template>
  30. <xsl:param name="space.enquad.width">0.5em</xsl:param> <!-- U+2000 -->
  31. <xsl:param name="space.emquad.width">1em</xsl:param> <!-- U+2001 -->
  32. <xsl:param name="space.enspace.width">0.5em</xsl:param> <!-- U+2002 -->
  33. <xsl:param name="space.emspace.width">1em</xsl:param> <!-- U+2003 -->
  34. <xsl:param name="space.3emspace.width">0.33em</xsl:param><!-- U+2004 -->
  35. <xsl:param name="space.4emspace.width">0.25em</xsl:param><!-- U+2005 -->
  36. <xsl:param name="space.6emspace.width">0.16em</xsl:param><!-- U+2006 -->
  37. <xsl:param name="space.figspace.width"></xsl:param> <!-- U+2007 -->
  38. <xsl:param name="space.punctspace.width"></xsl:param> <!-- U+2008 -->
  39. <xsl:param name="space.thinspace.width">0.2em</xsl:param><!-- U+2009 -->
  40. <xsl:param name="space.hairspace.width">0.1em</xsl:param><!-- U+200A -->
  41. <xsl:template name="space.2000.subst">
  42. <xsl:param name="string"/>
  43. <xsl:choose>
  44. <xsl:when test="contains($string, '&#x2000;') and $space.enquad.width != ''">
  45. <xsl:call-template name="space.2001.subst">
  46. <xsl:with-param name="string" select="substring-before($string, '&#x2000;')"/>
  47. </xsl:call-template>
  48. <fo:leader leader-length="{$space.enquad.width}"/>
  49. <xsl:call-template name="space.2000.subst">
  50. <xsl:with-param name="string" select="substring-after($string, '&#x2000;')"/>
  51. </xsl:call-template>
  52. </xsl:when>
  53. <xsl:otherwise>
  54. <xsl:call-template name="space.2001.subst">
  55. <xsl:with-param name="string" select="$string"/>
  56. </xsl:call-template>
  57. </xsl:otherwise>
  58. </xsl:choose>
  59. </xsl:template>
  60. <xsl:template name="space.2001.subst">
  61. <xsl:param name="string"/>
  62. <xsl:choose>
  63. <xsl:when test="contains($string, '&#x2001;') and $space.emquad.width != ''">
  64. <xsl:call-template name="space.2002.subst">
  65. <xsl:with-param name="string" select="substring-before($string, '&#x2001;')"/>
  66. </xsl:call-template>
  67. <fo:leader leader-length="{$space.emquad.width}"/>
  68. <xsl:call-template name="space.2001.subst">
  69. <xsl:with-param name="string" select="substring-after($string, '&#x2001;')"/>
  70. </xsl:call-template>
  71. </xsl:when>
  72. <xsl:otherwise>
  73. <xsl:call-template name="space.2002.subst">
  74. <xsl:with-param name="string" select="$string"/>
  75. </xsl:call-template>
  76. </xsl:otherwise>
  77. </xsl:choose>
  78. </xsl:template>
  79. <xsl:template name="space.2002.subst">
  80. <xsl:param name="string"/>
  81. <xsl:choose>
  82. <xsl:when test="contains($string, '&#x2002;') and $space.enspace.width != ''">
  83. <xsl:call-template name="space.2003.subst">
  84. <xsl:with-param name="string" select="substring-before($string, '&#x2002;')"/>
  85. </xsl:call-template>
  86. <fo:leader leader-length="{$space.enspace.width}"/>
  87. <xsl:call-template name="space.2002.subst">
  88. <xsl:with-param name="string" select="substring-after($string, '&#x2002;')"/>
  89. </xsl:call-template>
  90. </xsl:when>
  91. <xsl:otherwise>
  92. <xsl:call-template name="space.2003.subst">
  93. <xsl:with-param name="string" select="$string"/>
  94. </xsl:call-template>
  95. </xsl:otherwise>
  96. </xsl:choose>
  97. </xsl:template>
  98. <xsl:template name="space.2003.subst">
  99. <xsl:param name="string"/>
  100. <xsl:choose>
  101. <xsl:when test="contains($string, '&#x2003;') and $space.emspace.width != ''">
  102. <xsl:call-template name="space.2004.subst">
  103. <xsl:with-param name="string" select="substring-before($string, '&#x2003;')"/>
  104. </xsl:call-template>
  105. <fo:leader leader-length="{$space.emspace.width}"/>
  106. <xsl:call-template name="space.2003.subst">
  107. <xsl:with-param name="string" select="substring-after($string, '&#x2003;')"/>
  108. </xsl:call-template>
  109. </xsl:when>
  110. <xsl:otherwise>
  111. <xsl:call-template name="space.2004.subst">
  112. <xsl:with-param name="string" select="$string"/>
  113. </xsl:call-template>
  114. </xsl:otherwise>
  115. </xsl:choose>
  116. </xsl:template>
  117. <xsl:template name="space.2004.subst">
  118. <xsl:param name="string"/>
  119. <xsl:choose>
  120. <xsl:when test="contains($string, '&#x2004;') and $space.3emspace.width != ''">
  121. <xsl:call-template name="space.2005.subst">
  122. <xsl:with-param name="string" select="substring-before($string, '&#x2004;')"/>
  123. </xsl:call-template>
  124. <fo:leader leader-length="{$space.3emspace.width}"/>
  125. <xsl:call-template name="space.2004.subst">
  126. <xsl:with-param name="string" select="substring-after($string, '&#x2004;')"/>
  127. </xsl:call-template>
  128. </xsl:when>
  129. <xsl:otherwise>
  130. <xsl:call-template name="space.2005.subst">
  131. <xsl:with-param name="string" select="$string"/>
  132. </xsl:call-template>
  133. </xsl:otherwise>
  134. </xsl:choose>
  135. </xsl:template>
  136. <xsl:template name="space.2005.subst">
  137. <xsl:param name="string"/>
  138. <xsl:choose>
  139. <xsl:when test="contains($string, '&#x2005;') and $space.4emspace.width != ''">
  140. <xsl:call-template name="space.2006.subst">
  141. <xsl:with-param name="string" select="substring-before($string, '&#x2005;')"/>
  142. </xsl:call-template>
  143. <fo:leader leader-length="{$space.4emspace.width}"/>
  144. <xsl:call-template name="space.2005.subst">
  145. <xsl:with-param name="string" select="substring-after($string, '&#x2005;')"/>
  146. </xsl:call-template>
  147. </xsl:when>
  148. <xsl:otherwise>
  149. <xsl:call-template name="space.2006.subst">
  150. <xsl:with-param name="string" select="$string"/>
  151. </xsl:call-template>
  152. </xsl:otherwise>
  153. </xsl:choose>
  154. </xsl:template>
  155. <xsl:template name="space.2006.subst">
  156. <xsl:param name="string"/>
  157. <xsl:choose>
  158. <xsl:when test="contains($string, '&#x2006;') and $space.6emspace.width != ''">
  159. <xsl:call-template name="space.2007.subst">
  160. <xsl:with-param name="string" select="substring-before($string, '&#x2006;')"/>
  161. </xsl:call-template>
  162. <fo:leader leader-length="{$space.6emspace.width}"/>
  163. <xsl:call-template name="space.2006.subst">
  164. <xsl:with-param name="string" select="substring-after($string, '&#x2006;')"/>
  165. </xsl:call-template>
  166. </xsl:when>
  167. <xsl:otherwise>
  168. <xsl:call-template name="space.2007.subst">
  169. <xsl:with-param name="string" select="$string"/>
  170. </xsl:call-template>
  171. </xsl:otherwise>
  172. </xsl:choose>
  173. </xsl:template>
  174. <xsl:template name="space.2007.subst">
  175. <xsl:param name="string"/>
  176. <xsl:choose>
  177. <xsl:when test="contains($string, '&#x2007;') and $space.figspace.width != ''">
  178. <xsl:call-template name="space.2008.subst">
  179. <xsl:with-param name="string" select="substring-before($string, '&#x2007;')"/>
  180. </xsl:call-template>
  181. <fo:leader leader-length="{$space.figspace.width}"/>
  182. <xsl:call-template name="space.2007.subst">
  183. <xsl:with-param name="string" select="substring-after($string, '&#x2007;')"/>
  184. </xsl:call-template>
  185. </xsl:when>
  186. <xsl:otherwise>
  187. <xsl:call-template name="space.2008.subst">
  188. <xsl:with-param name="string" select="$string"/>
  189. </xsl:call-template>
  190. </xsl:otherwise>
  191. </xsl:choose>
  192. </xsl:template>
  193. <xsl:template name="space.2008.subst">
  194. <xsl:param name="string"/>
  195. <xsl:choose>
  196. <xsl:when test="contains($string, '&#x2008;') and $space.punctspace.width != ''">
  197. <xsl:call-template name="space.2009.subst">
  198. <xsl:with-param name="string" select="substring-before($string, '&#x2008;')"/>
  199. </xsl:call-template>
  200. <fo:leader leader-length="{$space.punctspace.width}"/>
  201. <xsl:call-template name="space.2008.subst">
  202. <xsl:with-param name="string" select="substring-after($string, '&#x2008;')"/>
  203. </xsl:call-template>
  204. </xsl:when>
  205. <xsl:otherwise>
  206. <xsl:call-template name="space.2009.subst">
  207. <xsl:with-param name="string" select="$string"/>
  208. </xsl:call-template>
  209. </xsl:otherwise>
  210. </xsl:choose>
  211. </xsl:template>
  212. <xsl:template name="space.2009.subst">
  213. <xsl:param name="string"/>
  214. <xsl:choose>
  215. <xsl:when test="contains($string, '&#x2009;') and $space.thinspace.width != ''">
  216. <xsl:call-template name="space.200A.subst">
  217. <xsl:with-param name="string" select="substring-before($string, '&#x2009;')"/>
  218. </xsl:call-template>
  219. <fo:leader leader-length="{$space.thinspace.width}"/>
  220. <xsl:call-template name="space.2009.subst">
  221. <xsl:with-param name="string" select="substring-after($string, '&#x2009;')"/>
  222. </xsl:call-template>
  223. </xsl:when>
  224. <xsl:otherwise>
  225. <xsl:call-template name="space.200A.subst">
  226. <xsl:with-param name="string" select="$string"/>
  227. </xsl:call-template>
  228. </xsl:otherwise>
  229. </xsl:choose>
  230. </xsl:template>
  231. <xsl:template name="space.200A.subst">
  232. <xsl:param name="string"/>
  233. <xsl:choose>
  234. <xsl:when test="contains($string, '&#x200A;') and $space.hairspace.width != ''">
  235. <xsl:value-of select="substring-before($string, '&#x200A;')"/>
  236. <fo:leader leader-length="{$space.hairspace.width}"/>
  237. <xsl:call-template name="space.200A.subst">
  238. <xsl:with-param name="string" select="substring-after($string, '&#x200A;')"/>
  239. </xsl:call-template>
  240. </xsl:when>
  241. <xsl:otherwise>
  242. <xsl:value-of select="$string"/>
  243. </xsl:otherwise>
  244. </xsl:choose>
  245. </xsl:template>
  246. </xsl:stylesheet>