pdf-custom.xsl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied. See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. -->
  18. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  19. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  20. xmlns:xslthl="http://xslthl.sf.net"
  21. exclude-result-prefixes="xslthl"
  22. version='1.0'>
  23. <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
  24. <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/fo/highlight.xsl"/>
  25. <xsl:param name="admon.graphics">'1'</xsl:param>
  26. <xsl:param name="admon.graphics.path">src/docbook/images/</xsl:param>
  27. <!-- xsl:param name="draft.watermark.image" select="'images/draft.png'"/ -->
  28. <xsl:param name="paper.type" select="'A4'"/>
  29. <xsl:param name="page.margin.top" select="'1cm'"/>
  30. <xsl:param name="region.before.extent" select="'1cm'"/>
  31. <xsl:param name="body.margin.top" select="'1.5cm'"/>
  32. <xsl:param name="body.margin.bottom" select="'1.5cm'"/>
  33. <xsl:param name="region.after.extent" select="'1cm'"/>
  34. <xsl:param name="page.margin.bottom" select="'1cm'"/>
  35. <xsl:param name="title.margin.left" select="'0cm'"/>
  36. <!--###################################################
  37. Header
  38. ################################################### -->
  39. <!-- More space in the center header for long text -->
  40. <xsl:attribute-set name="header.content.properties">
  41. <xsl:attribute name="font-family">
  42. <xsl:value-of select="$body.font.family"/>
  43. </xsl:attribute>
  44. <xsl:attribute name="margin-left">-5em</xsl:attribute>
  45. <xsl:attribute name="margin-right">-5em</xsl:attribute>
  46. </xsl:attribute-set>
  47. <!--###################################################
  48. Table of Contents
  49. ################################################### -->
  50. <xsl:param name="generate.toc">
  51. book toc,title
  52. </xsl:param>
  53. <!--###################################################
  54. Custom Header
  55. ################################################### -->
  56. <xsl:template name="header.content">
  57. <xsl:param name="pageclass" select="''"/>
  58. <xsl:param name="sequence" select="''"/>
  59. <xsl:param name="position" select="''"/>
  60. <xsl:param name="gentext-key" select="''"/>
  61. <xsl:variable name="Version">
  62. <xsl:choose>
  63. <xsl:when test="//productname">
  64. <xsl:value-of select="//productname"/><xsl:text> </xsl:text>
  65. </xsl:when>
  66. <xsl:otherwise>
  67. <xsl:text>please define productname in your docbook file!</xsl:text>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </xsl:variable>
  71. <xsl:choose>
  72. <xsl:when test="$sequence='blank'">
  73. <xsl:choose>
  74. <xsl:when test="$position='center'">
  75. <xsl:value-of select="$Version"/>
  76. </xsl:when>
  77. <xsl:otherwise>
  78. </xsl:otherwise>
  79. </xsl:choose>
  80. </xsl:when>
  81. <xsl:when test="$pageclass='titlepage'">
  82. </xsl:when>
  83. <xsl:when test="$position='center'">
  84. <xsl:value-of select="$Version"/>
  85. </xsl:when>
  86. <xsl:otherwise>
  87. </xsl:otherwise>
  88. </xsl:choose>
  89. </xsl:template>
  90. <!--###################################################
  91. Custom Footer
  92. ################################################### -->
  93. <xsl:template name="footer.content">
  94. <xsl:param name="pageclass" select="''"/>
  95. <xsl:param name="sequence" select="''"/>
  96. <xsl:param name="position" select="''"/>
  97. <xsl:param name="gentext-key" select="''"/>
  98. <xsl:variable name="Version">
  99. <xsl:choose>
  100. <xsl:when test="//releaseinfo">
  101. <xsl:value-of select="//releaseinfo"/>
  102. </xsl:when>
  103. <xsl:otherwise>
  104. </xsl:otherwise>
  105. </xsl:choose>
  106. </xsl:variable>
  107. <xsl:variable name="Title">
  108. <xsl:value-of select="//title"/>
  109. </xsl:variable>
  110. <xsl:choose>
  111. <xsl:when test="$sequence='blank'">
  112. <xsl:choose>
  113. <xsl:when test="$double.sided != 0 and $position = 'left'">
  114. <xsl:value-of select="$Version"/>
  115. </xsl:when>
  116. <xsl:when test="$double.sided = 0 and $position = 'center'">
  117. </xsl:when>
  118. <xsl:otherwise>
  119. <fo:page-number/>
  120. </xsl:otherwise>
  121. </xsl:choose>
  122. </xsl:when>
  123. <xsl:when test="$pageclass='titlepage'">
  124. </xsl:when>
  125. <xsl:when test="$double.sided != 0 and $sequence = 'even' and $position='left'">
  126. <fo:page-number/>
  127. </xsl:when>
  128. <xsl:when test="$double.sided != 0 and $sequence = 'odd' and $position='right'">
  129. <fo:page-number/>
  130. </xsl:when>
  131. <xsl:when test="$double.sided = 0 and $position='right'">
  132. <fo:page-number/>
  133. </xsl:when>
  134. <xsl:when test="$double.sided != 0 and $sequence = 'odd' and $position='left'">
  135. <xsl:value-of select="$Version"/>
  136. </xsl:when>
  137. <xsl:when test="$double.sided != 0 and $sequence = 'even' and $position='right'">
  138. <xsl:value-of select="$Version"/>
  139. </xsl:when>
  140. <xsl:when test="$double.sided = 0 and $position='left'">
  141. <xsl:value-of select="$Version"/>
  142. </xsl:when>
  143. <xsl:when test="$position='center'">
  144. <xsl:value-of select="$Title"/>
  145. </xsl:when>
  146. <xsl:otherwise>
  147. </xsl:otherwise>
  148. </xsl:choose>
  149. </xsl:template>
  150. <xsl:template match="processing-instruction('hard-pagebreak')">
  151. <fo:block break-before='page'/>
  152. </xsl:template>
  153. <!--###################################################
  154. Extensions
  155. ################################################### -->
  156. <!-- These extensions are required for table printing and other stuff
  157. <xsl:param name="use.extensions">1</xsl:param>
  158. <xsl:param name="tablecolumns.extension">0</xsl:param>
  159. <xsl:param name="callout.extensions">1</xsl:param>
  160. <xsl:param name="fop.extensions">1</xsl:param>
  161. -->
  162. <!--###################################################
  163. Paper & Page Size
  164. ################################################### -->
  165. <!-- Paper type, no headers on blank pages, no double sided printing -->
  166. <xsl:param name="double.sided">0</xsl:param>
  167. <xsl:param name="headers.on.blank.pages">0</xsl:param>
  168. <xsl:param name="footers.on.blank.pages">0</xsl:param>
  169. <!--###################################################
  170. Fonts & Styles
  171. ################################################### -->
  172. <xsl:param name="hyphenate">false</xsl:param>
  173. <!-- Default Font size -->
  174. <xsl:param name="body.font.master">11</xsl:param>
  175. <xsl:param name="body.font.small">8</xsl:param>
  176. <!-- Line height in body text -->
  177. <xsl:param name="line-height">1.4</xsl:param>
  178. <!-- Chapter title size -->
  179. <xsl:attribute-set name="chapter.titlepage.recto.style">
  180. <xsl:attribute name="text-align">left</xsl:attribute>
  181. <xsl:attribute name="font-weight">bold</xsl:attribute>
  182. <xsl:attribute name="font-size">
  183. <xsl:value-of select="$body.font.master * 1.8"/>
  184. <xsl:text>pt</xsl:text>
  185. </xsl:attribute>
  186. </xsl:attribute-set>
  187. <!-- Why is the font-size for chapters hardcoded in the XSL FO templates?
  188. Let's remove it, so this sucker can use our attribute-set only... -->
  189. <xsl:template match="title" mode="chapter.titlepage.recto.auto.mode">
  190. <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
  191. xsl:use-attribute-sets="chapter.titlepage.recto.style">
  192. <xsl:call-template name="component.title">
  193. <xsl:with-param name="node" select="ancestor-or-self::chapter[1]"/>
  194. </xsl:call-template>
  195. </fo:block>
  196. </xsl:template>
  197. <!-- Sections 1, 2 and 3 titles have a small bump factor and padding -->
  198. <xsl:attribute-set name="section.title.level1.properties">
  199. <xsl:attribute name="space-before.optimum">0.8em</xsl:attribute>
  200. <xsl:attribute name="space-before.minimum">0.8em</xsl:attribute>
  201. <xsl:attribute name="space-before.maximum">0.8em</xsl:attribute>
  202. <xsl:attribute name="font-size">
  203. <xsl:value-of select="$body.font.master * 1.5"/>
  204. <xsl:text>pt</xsl:text>
  205. </xsl:attribute>
  206. <xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
  207. <xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
  208. <xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
  209. </xsl:attribute-set>
  210. <xsl:attribute-set name="section.title.level2.properties">
  211. <xsl:attribute name="space-before.optimum">0.6em</xsl:attribute>
  212. <xsl:attribute name="space-before.minimum">0.6em</xsl:attribute>
  213. <xsl:attribute name="space-before.maximum">0.6em</xsl:attribute>
  214. <xsl:attribute name="font-size">
  215. <xsl:value-of select="$body.font.master * 1.25"/>
  216. <xsl:text>pt</xsl:text>
  217. </xsl:attribute>
  218. <xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
  219. <xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
  220. <xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
  221. </xsl:attribute-set>
  222. <xsl:attribute-set name="section.title.level3.properties">
  223. <xsl:attribute name="space-before.optimum">0.4em</xsl:attribute>
  224. <xsl:attribute name="space-before.minimum">0.4em</xsl:attribute>
  225. <xsl:attribute name="space-before.maximum">0.4em</xsl:attribute>
  226. <xsl:attribute name="font-size">
  227. <xsl:value-of select="$body.font.master * 1.0"/>
  228. <xsl:text>pt</xsl:text>
  229. </xsl:attribute>
  230. <xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
  231. <xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
  232. <xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
  233. </xsl:attribute-set>
  234. <!-- Use code syntax highlighting -->
  235. <xsl:param name="highlight.source" select="1"/>
  236. <xsl:param name="highlight.default.language" select="xml" />
  237. <xsl:template match='xslthl:keyword'>
  238. <fo:inline font-weight="bold" color="#7F0055"><xsl:apply-templates/></fo:inline>
  239. </xsl:template>
  240. <xsl:template match='xslthl:comment'>
  241. <fo:inline font-style="italic" color="#3F5F5F"><xsl:apply-templates/></fo:inline>
  242. </xsl:template>
  243. <xsl:template match='xslthl:oneline-comment'>
  244. <fo:inline font-style="italic" color="#3F5F5F"><xsl:apply-templates/></fo:inline>
  245. </xsl:template>
  246. <xsl:template match='xslthl:multiline-comment'>
  247. <fo:inline font-style="italic" color="#3F5FBF"><xsl:apply-templates/></fo:inline>
  248. </xsl:template>
  249. <xsl:template match='xslthl:tag'>
  250. <fo:inline color="#3F7F7F"><xsl:apply-templates/></fo:inline>
  251. </xsl:template>
  252. <xsl:template match='xslthl:attribute'>
  253. <fo:inline color="#7F007F"><xsl:apply-templates/></fo:inline>
  254. </xsl:template>
  255. <xsl:template match='xslthl:value'>
  256. <fo:inline color="#2A00FF"><xsl:apply-templates/></fo:inline>
  257. </xsl:template>
  258. <xsl:template match='xslthl:string'>
  259. <fo:inline color="#2A00FF"><xsl:apply-templates/></fo:inline>
  260. </xsl:template>
  261. <!--###################################################
  262. Tables
  263. ################################################### -->
  264. <!-- Some padding inside tables -->
  265. <xsl:attribute-set name="table.cell.padding">
  266. <xsl:attribute name="padding-left">4pt</xsl:attribute>
  267. <xsl:attribute name="padding-right">4pt</xsl:attribute>
  268. <xsl:attribute name="padding-top">4pt</xsl:attribute>
  269. <xsl:attribute name="padding-bottom">4pt</xsl:attribute>
  270. </xsl:attribute-set>
  271. <!-- Only hairlines as frame and cell borders in tables -->
  272. <xsl:param name="table.frame.border.thickness">0.1pt</xsl:param>
  273. <xsl:param name="table.cell.border.thickness">0.1pt</xsl:param>
  274. <!--###################################################
  275. Labels
  276. ################################################### -->
  277. <!-- Label Chapters and Sections (numbering) -->
  278. <xsl:param name="chapter.autolabel" select="1"/>
  279. <xsl:param name="section.autolabel" select="1"/>
  280. <xsl:param name="section.autolabel.max.depth" select="1"/>
  281. <xsl:param name="section.label.includes.component.label" select="1"/>
  282. <xsl:param name="table.footnote.number.format" select="'1'"/>
  283. <!--###################################################
  284. Programlistings
  285. ################################################### -->
  286. <!-- Verbatim text formatting (programlistings) -->
  287. <xsl:attribute-set name="monospace.verbatim.properties">
  288. <xsl:attribute name="font-size">
  289. <xsl:value-of select="$body.font.small * 1.0"/>
  290. <xsl:text>pt</xsl:text>
  291. </xsl:attribute>
  292. </xsl:attribute-set>
  293. <xsl:attribute-set name="verbatim.properties">
  294. <xsl:attribute name="space-before.minimum">1em</xsl:attribute>
  295. <xsl:attribute name="space-before.optimum">1em</xsl:attribute>
  296. <xsl:attribute name="space-before.maximum">1em</xsl:attribute>
  297. <xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
  298. <xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
  299. <xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
  300. <xsl:attribute name="border-color">#444444</xsl:attribute>
  301. <xsl:attribute name="border-style">solid</xsl:attribute>
  302. <xsl:attribute name="border-width">0.1pt</xsl:attribute>
  303. <xsl:attribute name="padding-top">0.5em</xsl:attribute>
  304. <xsl:attribute name="padding-left">0.5em</xsl:attribute>
  305. <xsl:attribute name="padding-right">0.5em</xsl:attribute>
  306. <xsl:attribute name="padding-bottom">0.5em</xsl:attribute>
  307. <xsl:attribute name="margin-left">0.5em</xsl:attribute>
  308. <xsl:attribute name="margin-right">0.5em</xsl:attribute>
  309. </xsl:attribute-set>
  310. <!-- Shade (background) programlistings -->
  311. <xsl:param name="shade.verbatim">1</xsl:param>
  312. <xsl:attribute-set name="shade.verbatim.style">
  313. <xsl:attribute name="background-color">#F0F0F0</xsl:attribute>
  314. </xsl:attribute-set>
  315. <xsl:attribute-set name="list.block.spacing">
  316. <xsl:attribute name="space-before.optimum">0.1em</xsl:attribute>
  317. <xsl:attribute name="space-before.minimum">0.1em</xsl:attribute>
  318. <xsl:attribute name="space-before.maximum">0.1em</xsl:attribute>
  319. <xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
  320. <xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
  321. <xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
  322. </xsl:attribute-set>
  323. <xsl:attribute-set name="example.properties">
  324. <xsl:attribute name="space-before.minimum">0.5em</xsl:attribute>
  325. <xsl:attribute name="space-before.optimum">0.5em</xsl:attribute>
  326. <xsl:attribute name="space-before.maximum">0.5em</xsl:attribute>
  327. <xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
  328. <xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
  329. <xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
  330. <xsl:attribute name="keep-together.within-column">always</xsl:attribute>
  331. </xsl:attribute-set>
  332. <!--###################################################
  333. Title information for Figures, Examples etc.
  334. ################################################### -->
  335. <xsl:attribute-set name="formal.title.properties" use-attribute-sets="normal.para.spacing">
  336. <xsl:attribute name="font-weight">normal</xsl:attribute>
  337. <xsl:attribute name="font-style">italic</xsl:attribute>
  338. <xsl:attribute name="font-size">
  339. <xsl:value-of select="$body.font.master"/>
  340. <xsl:text>pt</xsl:text>
  341. </xsl:attribute>
  342. <xsl:attribute name="hyphenate">false</xsl:attribute>
  343. <xsl:attribute name="space-before.minimum">0.1em</xsl:attribute>
  344. <xsl:attribute name="space-before.optimum">0.1em</xsl:attribute>
  345. <xsl:attribute name="space-before.maximum">0.1em</xsl:attribute>
  346. </xsl:attribute-set>
  347. <!--###################################################
  348. Callouts
  349. ################################################### -->
  350. <!-- don't use images for callouts
  351. <xsl:param name="callout.graphics">0</xsl:param>
  352. <xsl:param name="callout.unicode">1</xsl:param>
  353. -->
  354. <!-- Place callout marks at this column in annotated areas
  355. <xsl:param name="callout.defaultcolumn">90</xsl:param>
  356. -->
  357. <!--###################################################
  358. Misc
  359. ################################################### -->
  360. <!-- Placement of titles -->
  361. <xsl:param name="formal.title.placement">
  362. figure after
  363. example after
  364. equation before
  365. table before
  366. procedure before
  367. </xsl:param>
  368. <!-- Format Variable Lists as Blocks (prevents horizontal overflow) -->
  369. <xsl:param name="variablelist.as.blocks">1</xsl:param>
  370. <xsl:param name="body.start.indent">0pt</xsl:param>
  371. <!-- Show only Sections up to level 3 in the TOCs -->
  372. <xsl:param name="toc.section.depth">3</xsl:param>
  373. <!-- Remove "Chapter" from the Chapter titles... -->
  374. <xsl:param name="local.l10n.xml" select="document('')"/>
  375. <l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
  376. <l:l10n language="en">
  377. <l:context name="title-numbered">
  378. <l:template name="chapter" text="%n.&#160;%t"/>
  379. <l:template name="section" text="%n&#160;%t"/>
  380. </l:context>
  381. <l:context name="title">
  382. <l:template name="example" text="Example&#160;%n&#160;%t"/>
  383. </l:context>
  384. </l:l10n>
  385. </l:i18n>
  386. <!--###################################################
  387. colored and hyphenated links
  388. ################################################### -->
  389. <!--
  390. <xsl:template match="ulink">
  391. <fo:basic-link external-destination="{@url}"
  392. xsl:use-attribute-sets="xref.properties"
  393. text-decoration="underline"
  394. color="blue">
  395. <xsl:choose>
  396. <xsl:when test="count(child::node())=0">
  397. <xsl:value-of select="@url"/>
  398. </xsl:when>
  399. <xsl:otherwise>
  400. <xsl:apply-templates/>
  401. </xsl:otherwise>
  402. </xsl:choose>
  403. </fo:basic-link>
  404. </xsl:template>
  405. <xsl:template match="link">
  406. <fo:basic-link internal-destination="{@linkend}"
  407. xsl:use-attribute-sets="xref.properties"
  408. text-decoration="underline"
  409. color="blue">
  410. <xsl:choose>
  411. <xsl:when test="count(child::node())=0">
  412. <xsl:value-of select="@linkend"/>
  413. </xsl:when>
  414. <xsl:otherwise>
  415. <xsl:apply-templates/>
  416. </xsl:otherwise>
  417. </xsl:choose>
  418. </fo:basic-link>
  419. </xsl:template>
  420. -->
  421. </xsl:stylesheet>