summaryrefslogtreecommitdiff
path: root/tools/boostbook/xsl/fo.xsl
blob: 422811cb80c25c0abf3299c1fa8136a6f0573671 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2003 Douglas Gregor -->
<!-- Distributed under the Boost Software License, Version 1.0. -->
<!-- (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) -->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                version="1.0">

  <!-- Import the FO stylesheet -->
  <xsl:import 
    href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>

  <xsl:param name="chapter.autolabel" select="0"/>
  <xsl:param name="refentry.generate.name" select="0"/>
  <xsl:param name="refentry.generate.title" select="1"/>
  <xsl:param name="fop1.extensions" select="1"/>
  <xsl:param name="make.year.ranges" select="1"/>
  <xsl:param name="ulink.show" select="0"/>

   
  <!--
  The following code sets which sections start new pages in the PDF document flow.
  
  The parameter "boost.section.newpage.depth" set how far down the hierarchy the
  page breaks go.  Defaults to 1 (the same as html chunking), in which case only 
  top level sections start a new page, set to a higher value to force nested sections
  onto new pages as well.
  
  For top level sections (level 1), we use "break-before" which forces the very first
  section onto a separate page from the TOC.
  
  For nested sections (level 2 and greater) we use "break-after" which keeps nested
  sections together with their enclosing section (rationale: the enclosing section
  often has nothing but a title, and no content except the nested sections, and we 
  don't want a page break right after a section title!).
  
  For reference sections, we turn page breaks *off* by setting "refentry.pagebreak" to 0.
  This is for the same reason we use "break-after" for nested sections - we want reference 
  entries to be on the same page as the title and synopsis which encloses them.  Ideally
  we'd use "break-after" here too, but I can't find an easy to to fix that.
  
  Finally note that TOC's and Indexes don't get page breaks forced after them.
  Again there's no easy fix here, *except* for the top level TOC which gets a page break
  after it thanks to the "break-before" on level 1 sections.  Unfortunately this means
  there's no break after the last section and before the first Index, *unless* the
  final section has nested sections which may then trigger one!
  
  We could fix all this by cut-and-pasting the relevant XSL from the stylesheets to here
  and making sure everything uses "break-after", but whether it's worth it is questionable...?
  
  -->
   
  <xsl:param name="boost.section.newpage.depth" select="1"/>
  <xsl:param name="refentry.pagebreak" select="0"/>

   <xsl:attribute-set name="section.level1.properties" use-attribute-sets="section.properties">
      <xsl:attribute name="break-before">
         <xsl:if test="($boost.section.newpage.depth &gt; 0)">
            page
         </xsl:if>
         <xsl:if test="not($boost.section.newpage.depth &gt; 0)">
            auto
         </xsl:if>
      </xsl:attribute>
   </xsl:attribute-set>

   <xsl:attribute-set name="section.level2.properties" use-attribute-sets="section.properties">
      <xsl:attribute name="break-after">
         <xsl:if test="($boost.section.newpage.depth &gt; 1)">
            page
         </xsl:if>
         <xsl:if test="not($boost.section.newpage.depth &gt; 1)">
            auto
         </xsl:if>
      </xsl:attribute>
   </xsl:attribute-set>

   <xsl:attribute-set name="section.level3.properties" use-attribute-sets="section.properties">
      <xsl:attribute name="break-after">
         <xsl:if test="($boost.section.newpage.depth &gt; 2)">
            page
         </xsl:if>
         <xsl:if test="not($boost.section.newpage.depth &gt; 2)">
            auto
         </xsl:if>
      </xsl:attribute>
   </xsl:attribute-set>

   <xsl:attribute-set name="section.level4.properties" use-attribute-sets="section.properties">
      <xsl:attribute name="break-after">
         <xsl:if test="($boost.section.newpage.depth &gt; 3)">
            page
         </xsl:if>
         <xsl:if test="not($boost.section.newpage.depth &gt; 3)">
            auto
         </xsl:if>
      </xsl:attribute>
   </xsl:attribute-set>

   <xsl:attribute-set name="section.level5.properties" use-attribute-sets="section.properties">
      <xsl:attribute name="break-after">
         <xsl:if test="($boost.section.newpage.depth &gt; 4)">
            page
         </xsl:if>
         <xsl:if test="not($boost.section.newpage.depth &gt; 4)">
            auto
         </xsl:if>
      </xsl:attribute>
   </xsl:attribute-set>

   <xsl:attribute-set name="section.level6.properties" use-attribute-sets="section.properties">
      <xsl:attribute name="break-after">
         <xsl:if test="($boost.section.newpage.depth &gt; 5)">
            page
         </xsl:if>
         <xsl:if test="not($boost.section.newpage.depth &gt; 5)">
            auto
         </xsl:if>
      </xsl:attribute>
   </xsl:attribute-set>

   <!-- The question and answer templates are copied here from the
       1.61.3 DocBook XSL stylesheets so that we can eliminate the emission
       of id attributes in the emitted fo:list-item-label elements. FOP
       0.20.5 has problems with these id attributes, and they are otherwise
       unused. -->
<xsl:template match="question">
  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>

  <xsl:variable name="entry.id">
    <xsl:call-template name="object.id">
      <xsl:with-param name="object" select="parent::*"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="deflabel">
    <xsl:choose>
      <xsl:when test="ancestor-or-self::*[@defaultlabel]">
        <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
                              /@defaultlabel"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$qanda.defaultlabel"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <fo:list-item id="{$entry.id}" xsl:use-attribute-sets="list.item.spacing">
    <fo:list-item-label end-indent="label-end()">
      <xsl:choose>
        <xsl:when test="$deflabel = 'none'">
          <fo:block/>
        </xsl:when>
        <xsl:otherwise>
          <fo:block>
            <xsl:apply-templates select="." mode="label.markup"/>
            <xsl:text>.</xsl:text> <!-- FIXME: Hack!!! This should be in the locale! -->
          </fo:block>
        </xsl:otherwise>
      </xsl:choose>
    </fo:list-item-label>
    <fo:list-item-body start-indent="body-start()">
      <xsl:choose>
        <xsl:when test="$deflabel = 'none'">
          <fo:block font-weight="bold">
            <xsl:apply-templates select="*[local-name(.)!='label']"/>
          </fo:block>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="*[local-name(.)!='label']"/>
        </xsl:otherwise>
      </xsl:choose>
    </fo:list-item-body>
  </fo:list-item>
</xsl:template>

<xsl:template match="answer">
  <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
  <xsl:variable name="entry.id">
    <xsl:call-template name="object.id">
      <xsl:with-param name="object" select="parent::*"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="deflabel">
    <xsl:choose>
      <xsl:when test="ancestor-or-self::*[@defaultlabel]">
        <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
                              /@defaultlabel"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$qanda.defaultlabel"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <fo:list-item xsl:use-attribute-sets="list.item.spacing">
    <fo:list-item-label end-indent="label-end()">
      <xsl:choose>
        <xsl:when test="$deflabel = 'none'">
          <fo:block/>
        </xsl:when>
        <xsl:otherwise>
          <fo:block>
            <!-- FIXME: Hack!!! This should be in the locale! -->
            <xsl:variable name="answer.label">
              <xsl:apply-templates select="." mode="label.markup"/>
            </xsl:variable>
            <xsl:copy-of select="$answer.label"/>
            <xsl:if test="string($answer.label) != ''">
              <xsl:text>.</xsl:text>
            </xsl:if>
          </fo:block>
        </xsl:otherwise>
      </xsl:choose>
    </fo:list-item-label>
    <fo:list-item-body start-indent="body-start()">
      <xsl:apply-templates select="*[local-name(.)!='label']"/>
    </fo:list-item-body>
  </fo:list-item>
</xsl:template>

<!-- 

 The following rules apply syntax highlighting to phrases
 that have been appropriately marked up, the highlighting
 used is the same as that used by our CSS style sheets,
 but potentially we have the option to do better here
 since we can add bold and italic formatting quite easily
 
 -->

<xsl:template match="//phrase[@role='keyword' and
                     (ancestor::programlisting or
                      ancestor::synopsis or
                      ancestor::literallayout)]">
  <fo:inline color="#0000AA"><xsl:apply-templates/></fo:inline>
</xsl:template>
<xsl:template match="//phrase[@role='special' and
                     (ancestor::programlisting or
                      ancestor::synopsis or
                      ancestor::literallayout)]">
  <fo:inline color="#707070"><xsl:apply-templates/></fo:inline>
</xsl:template>
<xsl:template match="//phrase[@role='preprocessor' and
                     (ancestor::programlisting or
                      ancestor::synopsis or
                      ancestor::literallayout)]">
  <fo:inline color="#402080"><xsl:apply-templates/></fo:inline>
</xsl:template>
<xsl:template match="//phrase[@role='char' and
                     (ancestor::programlisting or
                      ancestor::synopsis or
                      ancestor::literallayout)]">
  <fo:inline color="teal"><xsl:apply-templates/></fo:inline>
</xsl:template>
<xsl:template match="//phrase[@role='comment' and
                     (ancestor::programlisting or
                      ancestor::synopsis or
                      ancestor::literallayout)]">
  <fo:inline color="#800000"><xsl:apply-templates/></fo:inline>
</xsl:template>
<xsl:template match="//phrase[@role='string' and
                     (ancestor::programlisting or
                      ancestor::synopsis or
                      ancestor::literallayout)]">
  <fo:inline color="teal"><xsl:apply-templates/></fo:inline>
</xsl:template>
<xsl:template match="//phrase[@role='number' and
                     (ancestor::programlisting or
                      ancestor::synopsis or
                      ancestor::literallayout)]">
  <fo:inline color="teal"><xsl:apply-templates/></fo:inline>
</xsl:template>
<xsl:template match="//phrase[@role='white_bkd' and
                     (ancestor::programlisting or
                      ancestor::synopsis or
                      ancestor::literallayout)]">
  <fo:inline color="#FFFFFF"><xsl:apply-templates/></fo:inline>
</xsl:template>
<xsl:template match="//phrase[@role='dk_grey_bkd' and
                     (ancestor::programlisting or
                      ancestor::synopsis or
                      ancestor::literallayout)]">
  <fo:inline color="#999999"><xsl:apply-templates/></fo:inline>
</xsl:template>

<!--
Make all hyperlinks blue colored:
-->
<xsl:attribute-set name="xref.properties">
  <xsl:attribute name="color">blue</xsl:attribute>
</xsl:attribute-set>

<!--
Put a box around admonishments and keep them together:
-->
<xsl:attribute-set name="graphical.admonition.properties">
  <xsl:attribute name="border-color">#FF8080</xsl:attribute>
  <xsl:attribute name="border-width">1px</xsl:attribute>
  <xsl:attribute name="border-style">solid</xsl:attribute>
  <xsl:attribute name="padding-left">0.2cm</xsl:attribute>
  <xsl:attribute name="padding-right">0.2cm</xsl:attribute>
  <xsl:attribute name="padding-top">0.2cm</xsl:attribute>
  <xsl:attribute name="padding-bottom">0.2cm</xsl:attribute>
  <xsl:attribute name="keep-together.within-page">1</xsl:attribute>
  <xsl:attribute name="margin-left">0pt</xsl:attribute>
  <xsl:attribute name="margin-right">0pt</xsl:attribute>
</xsl:attribute-set>

<!--
Put a box around code blocks, also set the font size
and keep the block together if we can using the widows 
and orphans controls.  Hyphenation and line wrapping
is also turned on, so that long lines of code don't
bleed off the edge of the page, a carriage return
symbol is used as the hyphenation character:
-->
<xsl:attribute-set name="monospace.verbatim.properties">
  <xsl:attribute name="border-color">#DCDCDC</xsl:attribute>
  <xsl:attribute name="border-width">1px</xsl:attribute>
  <xsl:attribute name="border-style">solid</xsl:attribute>
  <xsl:attribute name="padding-left">0.2cm</xsl:attribute>
  <xsl:attribute name="padding-right">0.2cm</xsl:attribute>
  <xsl:attribute name="padding-top">0.2cm</xsl:attribute>
  <xsl:attribute name="padding-bottom">0.2cm</xsl:attribute>
  <xsl:attribute name="widows">6</xsl:attribute>
  <xsl:attribute name="orphans">40</xsl:attribute>
  <xsl:attribute name="font-size">9pt</xsl:attribute>
  <xsl:attribute name="hyphenate">true</xsl:attribute>
  <xsl:attribute name="wrap-option">wrap</xsl:attribute>
  <xsl:attribute name="hyphenation-character">&#x21B5;</xsl:attribute>
  <xsl:attribute name="margin-left">0pt</xsl:attribute>
  <xsl:attribute name="margin-right">0pt</xsl:attribute>
</xsl:attribute-set>

<xsl:param name="hyphenate.verbatim" select="1"></xsl:param>
<xsl:param name="monospace.font.family">monospace,Symbol</xsl:param>

  <!--Regular monospace text should have the same font size as code blocks etc-->
<xsl:attribute-set name="monospace.properties">
  <xsl:attribute name="font-size">9pt</xsl:attribute>
</xsl:attribute-set>
  
<!-- 
Put some small amount of padding around table cells, and keep tables
together on one page if possible:
-->
<xsl:attribute-set name="table.cell.padding">
  <xsl:attribute name="padding-left">0.2cm</xsl:attribute>
  <xsl:attribute name="padding-right">0.2cm</xsl:attribute>
  <xsl:attribute name="padding-top">0.2cm</xsl:attribute>
  <xsl:attribute name="padding-bottom">0.2cm</xsl:attribute>
</xsl:attribute-set>

  <!--Formal and informal tables have the same properties
      Using widow-and-orphan control here gives much better
      results for very large tables than a simple "keep-together"
      instruction-->
<xsl:attribute-set name="table.properties">
  <xsl:attribute name="keep-together.within-page">1</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="informaltable.properties">
  <xsl:attribute name="keep-together.within-page">1</xsl:attribute>
</xsl:attribute-set>

<!--
General default options go here:
* Borders are mid-grey.
* Body text is not indented compared to the titles.
* Page margins are a rather small 0.5in, but we need
  all the space we can get for code blocks.
* Paper size is A4: an ISO standard, slightly taller and narrower than US Letter.
* Use SVG graphics for admonishments: the bitmaps look awful in PDF's.
* Disable draft mode so we're not constantly trying to download the necessary graphic.
* Set default image paths to pull down direct from SVN: individual Jamfiles can override this
  and pass an absolute path to local versions of the images, but we can't get that here, so
  we'll use SVN instead so that most things "just work".
-->
<xsl:param name="table.frame.border.color">#DCDCDC</xsl:param>
<xsl:param name="table.cell.border.color">#DCDCDC</xsl:param>
<xsl:param name="body.start.indent">0pt</xsl:param>
<xsl:param name="page.margin.inner">0.5in</xsl:param>
<xsl:param name="page.margin.outer">0.5in</xsl:param>
<xsl:param name="paper.type">A4</xsl:param>
<xsl:param name="admon.graphics">1</xsl:param>
<xsl:param name="admon.graphics.extension">.svg</xsl:param>
<xsl:param name="draft.mode">no</xsl:param>
<xsl:param name="admon.graphics.path">http://svn.boost.org/svn/boost/trunk/doc/src/images/</xsl:param>
<xsl:param name="callout.graphics.path">http://svn.boost.org/svn/boost/trunk/doc/src/images/callouts/</xsl:param>
<xsl:param name="img.src.path">http://svn.boost.org/svn/boost/trunk/doc/html/</xsl:param>

</xsl:stylesheet>