~sascha-manns-h/+junk/daps-xslt

« back to all changes in this revision

Viewing changes to fo/admon.xsl

  • Committer: Sascha Manns
  • Date: 2017-10-28 16:44:44 UTC
  • Revision ID: sascha.manns@mailbox.org-20171028164444-f5rhvp6yqtk3wq5j
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="UTF-8"?>
 
2
<!--
 
3
  Purpose:
 
4
    Re-Style admonitions
 
5
 
 
6
  Author(s):  Stefan Knorr <sknorr@suse.de>,
 
7
              Thomas Schraitle <toms@opensuse.org>
 
8
 
 
9
  Copyright:  2013, Stefan Knorr, Thomas Schraitle
 
10
 
 
11
-->
 
12
<!DOCTYPE xsl:stylesheet
 
13
[
 
14
  <!ENTITY % fonts SYSTEM "fonts.ent">
 
15
  <!ENTITY % colors SYSTEM "colors.ent">
 
16
  <!ENTITY % metrics SYSTEM "metrics.ent">
 
17
  %fonts;
 
18
  %colors;
 
19
  %metrics;
 
20
]>
 
21
<xsl:stylesheet  version="1.0"
 
22
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
23
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
 
24
  xmlns:svg="http://www.w3.org/2000/svg"
 
25
  xmlns:date="http://exslt.org/dates-and-times"
 
26
  exclude-result-prefixes="date">
 
27
 
 
28
 
 
29
<xsl:template match="note|important|warning|caution|tip">
 
30
  <xsl:call-template name="graphical.admonition"/>
 
31
</xsl:template>
 
32
 
 
33
<xsl:template name="admon.symbol">
 
34
  <xsl:param name="color" select="'&dark-green;'"/>
 
35
  <xsl:param name="node" select="."/>
 
36
 
 
37
  <!-- Hierarchy of admonition symbols:
 
38
  https://en.wikipedia.org/wiki/Precautionary_statement
 
39
  DocBook (currently) does not support "danger," but on the other hand has
 
40
  both "note" and "tip" at the lowest end. -->
 
41
  <svg:svg width="36" height="36">
 
42
    <svg:g>
 
43
      <xsl:if test="$writing.mode = 'rl'">
 
44
        <xsl:attribute name="transform">matrix(-1,0,0,1,36,0)</xsl:attribute>
 
45
      </xsl:if>
 
46
      <xsl:choose>
 
47
        <xsl:when test="local-name($node)='warning'">
 
48
            <svg:path d="M 18,0 C 8.06,0 0,8.06 0,18 0,27.94 8.06,36 18,36 27.94,36 36,27.94 36,18 36,8.06 27.94,0 18,0 z m 0,7 c 0.62,0 1,0.51 1,1.13 l 0,9.88 1,0 0,-8.53 c 0,-0.62 0.38,-1.13 1,-1.13 0.62,0 1,0.51 1,1.13 L 22,22 l 1,0 0,-4.78 c 0,-0.62 0.29,-1.13 0.91,-1.13 0.62,0 1.09,0.17 1.09,1.13 L 25,22.5 c -8.8e-4,3.6 -3.41,6.5 -7,6.5 -3.59,-9e-4 -7,-2.92 -7,-5.84 l 0,-9.31 c 0,-0.96 0.38,-1.47 1,-1.47 0.62,0 1,0.51 1,1.13 l 0,5.5 1,0 0,-9.53 c -2e-5,-0.62 0.38,-1.13 1,-1.13 0.62,0 1,0.5 1,1.13 L 16,18 17,18 17,8.13 C 17.04,7.51 17.38,7 18,7 z"
 
49
              fill="{$color}"/>
 
50
        </xsl:when>
 
51
        <xsl:when test="local-name($node)='tip'">
 
52
            <svg:path d="M 18,0 C 8.06,0 0,8.06 0,18 0,27.94 8.06,36 18,36 27.94,36 36,27.94 36,18 36,8.06 27.94,0 18,0 z m 0,4.75 c 4.62,0 8.43,3.69 8.38,8.31 -0.052,4.47 -3.11,6.6 -4.19,11.56 l -8.03,2.19 C 14.12,26.35 14.07,25.92 14,25.5 l 4.5,-1.25 -4.78,0 C 12.57,19.55 9.7,17.4 9.66,13.06 9.6,8.44 13.38,4.75 18,4.75 z m -0.88,8.56 -0.41,0.72 -1.97,0 c -1.18,0 -1.39,0.28 -1.19,1 l 1.94,7 c 0.073,0.24 0.31,0.38 0.5,0.38 0.29,0 0.54,-0.16 0.53,-0.5 l -1.88,-6.88 1.47,0 c -0.14,0.24 -0.068,0.58 0.19,0.69 0.47,0.2 0.54,-0.07 0.78,-0.31 0.03,0.12 0.09,0.26 0.22,0.31 0.48,0.19 0.54,-0.07 0.78,-0.31 0.03,0.12 0.11,0.3 0.25,0.34 0.52,0.14 0.51,0.04 0.94,-0.72 l 2.06,0 -1.88,6.88 c 0,0.33 0.25,0.49 0.53,0.5 0.28,0.01 0.45,-0.2 0.5,-0.38 l 1.94,-7 c 0.2,-0.72 0,-1 -1.19,-1 l -1.38,0 C 20.17,13.52 20.12,13.21 19.81,13.13 19.41,13.02 19.27,13.23 19.03,13.47 19.01,13.33 18.96,13.18 18.81,13.13 18.39,12.96 18.27,13.21 18.03,13.47 18.01,13.33 17.97,13.22 17.81,13.13 17.54,12.96 17.24,13.11 17.13,13.31 z M 22,25.69 c -0.07,0.47 -0.1,0.1 -0.13,1.5 l -7.5,2.06 C 14.23,28.75 14.21,28.29 14.19,27.81 z M 21.81,28.25 c 0.029,0.62 -0.18,1.19 -0.44,1.63 l -5.19,1.38 c -0.53,-0.27 -0.99,-0.65 -1.34,-1.13 z"
 
53
              fill="{$color}"/>
 
54
        </xsl:when>
 
55
        <!-- The symbol for these two is currently the same, however,
 
56
        important is orange &amp; caution is red. -->
 
57
        <xsl:when test="local-name($node)='important' or local-name($node)='caution'">
 
58
            <svg:path d="M 18,0 C 8,0 0,8 0,18 0,28 8,36 18,36 28,36 36,28 36,18 36,8 28,0 18,0 z m -2.5,7 5.125,0 -0.75,14.5 -3.625,0 L 15.5,7 z M 18,24 c 0.8,0 1.5,0.25 1.9,0.625 0.45,0.45 0.65,1 0.65,1.9 -10e-6,0.75 -0.25,1.4 -0.65,1.85 C 19.45,28.75 18.8,29 18,29 17.15,29 16.55,28.75 16.1,28.35 15.65,27.9 15.4,27.3 15.4,26.5 c 0,-0.83 0.25,-1.45 0.65,-1.85 C 16.55,24.2 17.15,24 18,24 z"
 
59
              fill="{$color}"/>
 
60
        </xsl:when>
 
61
        <xsl:otherwise>
 
62
          <!-- It's a note. (Or something undefined.) -->
 
63
            <svg:path d="M 18,0 C 8.061,0 0,8.058 0,18 0,27.94 8.061,36 18,36 27.942,36 36,27.94 36,18 36,8.058 27.942,0 18,0 z m -3.5,5.125 c 0.266,1.75e-4 0.512,0.0745 0.688,0.25 l 12,12 0.7188,8.625 c -6e-5,0.511 -0.172,1.047 -0.563,1.438 -0.39,0.39 -0.928,0.605 -1.438,0.563 l -8.625,-0.719 -12,-12 c -0.391,-0.391 -0.391,-1.016 0,-1.406 0.383,-0.383 1.03,-0.408 1.438,0 L 18.125,25.313 25.906,26 25.188,18.219 14.5,7.5 l -4.25,4.25 8.813,8.813 1.906,0.5 -0.531,-1.938 -7.375,-7.375 1.438,-1.406 7.75,7.75 0.844,3.063 c 8.9e-5,0.511 -0.204,1.047 -0.594,1.438 -0.39,0.39 -0.895,0.532 -1.406,0.531 L 18,22.344 8.125,12.469 c -0.39,-0.39 -0.39,-1.047 0,-1.438 L 13.781,5.375 C 13.958,5.199 14.234,5.125 14.5,5.125 z"
 
64
              fill="{$color}"/>
 
65
        </xsl:otherwise>
 
66
      </xsl:choose>
 
67
    </svg:g>
 
68
  </svg:svg>
 
69
</xsl:template>
 
70
 
 
71
<xsl:template name="admon.symbol.color">
 
72
  <xsl:param name="node" select="."/>
 
73
  <xsl:choose>
 
74
    <xsl:when test="$format.print = 1">
 
75
      <xsl:text>&darker-gray;</xsl:text>
 
76
    </xsl:when>
 
77
    <xsl:otherwise>
 
78
      <xsl:choose>
 
79
        <xsl:when test="local-name($node)='warning' or
 
80
                        local-name($node)='caution'">
 
81
          <!-- The symbol for these two is currently the same -->
 
82
          <xsl:text>&dark-blood;</xsl:text>
 
83
        </xsl:when>
 
84
        <xsl:when test="local-name($node)='tip'">
 
85
          <xsl:text>&dark-green;</xsl:text>
 
86
        </xsl:when>
 
87
        <xsl:when test="local-name($node)='important'">
 
88
          <xsl:text>&mid-orange;</xsl:text>
 
89
        </xsl:when>
 
90
        <xsl:otherwise>
 
91
          <!-- It's a note. (Or something undefined.) -->
 
92
          <xsl:text>&darker-gray;</xsl:text>
 
93
        </xsl:otherwise>
 
94
      </xsl:choose>
 
95
    </xsl:otherwise>
 
96
  </xsl:choose>
 
97
</xsl:template>
 
98
 
 
99
<xsl:template name="compact.or.normal.block">
 
100
 <xsl:variable name="color">
 
101
  <xsl:call-template name="admon.symbol.color"/>
 
102
 </xsl:variable>
 
103
 <fo:block>
 
104
  <xsl:attribute name="color">
 
105
   <xsl:choose>
 
106
    <xsl:when test="not(@role = 'compact')">
 
107
     <xsl:value-of select="$color"/>
 
108
    </xsl:when>
 
109
    <xsl:otherwise>&darker-gray;</xsl:otherwise>
 
110
   </xsl:choose>
 
111
  </xsl:attribute>
 
112
  <xsl:value-of select="@role"/>
 
113
  <xsl:apply-templates select="." mode="object.title.markup">
 
114
   <xsl:with-param name="allow-anchors" select="1"/>
 
115
  </xsl:apply-templates>
 
116
 </fo:block>
 
117
</xsl:template>
 
118
 
 
119
<xsl:template name="graphical.admonition">
 
120
  <xsl:variable name="id">
 
121
    <xsl:call-template name="object.id"/>
 
122
  </xsl:variable>
 
123
  <xsl:variable name="color">
 
124
   <xsl:call-template name="admon.symbol.color"/>
 
125
  </xsl:variable>
 
126
  <xsl:variable name="graphic.width">
 
127
    <xsl:choose>
 
128
      <xsl:when test="@role='compact'">5</xsl:when>
 
129
      <xsl:otherwise>8</xsl:otherwise>
 
130
    </xsl:choose>
 
131
  </xsl:variable>
 
132
  <xsl:variable name="padding">
 
133
    <xsl:choose>
 
134
      <xsl:when test="@role='compact'">0.7mm</xsl:when>
 
135
      <xsl:otherwise>3mm</xsl:otherwise>
 
136
    </xsl:choose>
 
137
  </xsl:variable>
 
138
 
 
139
  <fo:block id="{$id}" xsl:use-attribute-sets="graphical.admonition.properties">
 
140
    <fo:list-block
 
141
      provisional-distance-between-starts="{&columnfragment; + &gutterfragment;}mm"
 
142
      provisional-label-separation="&gutter;mm">
 
143
      <fo:list-item>
 
144
          <fo:list-item-label end-indent="label-end()">
 
145
            <fo:block text-align="start" padding-before="1.2mm" padding-after="1.2mm">
 
146
              <fo:instream-foreign-object content-width="{$graphic.width}mm">
 
147
                <xsl:call-template name="admon.symbol">
 
148
                  <xsl:with-param name="color" select="$color"/>
 
149
                </xsl:call-template>
 
150
              </fo:instream-foreign-object>
 
151
            </fo:block>
 
152
          </fo:list-item-label>
 
153
          <fo:list-item-body start-indent="body-start()">
 
154
            <fo:block padding-start="{(&gutter; - 0.75) div 2}mm"
 
155
              padding-before="{$padding}" padding-after="{$padding}">
 
156
              <xsl:if test="((title or info/title) or ($admon.textlabel != 0 and not(@role='compact')))">
 
157
                <xsl:choose>
 
158
                 <xsl:when test="@role='compact'">
 
159
                  <fo:block
 
160
                   xsl:use-attribute-sets="admonition.title.properties admonition.compact.title.properties">
 
161
                   <xsl:call-template name="compact.or.normal.block"/>
 
162
                  </fo:block>
 
163
                 </xsl:when>
 
164
                 <xsl:otherwise>
 
165
                  <fo:block xsl:use-attribute-sets="admonition.title.properties admonition.normal.title.properties">
 
166
                   <xsl:call-template name="compact.or.normal.block"/>
 
167
                  </fo:block>
 
168
                 </xsl:otherwise>
 
169
                </xsl:choose>
 
170
              </xsl:if>
 
171
              <fo:block xsl:use-attribute-sets="admonition.properties">
 
172
                <xsl:apply-templates/>
 
173
              </fo:block>
 
174
            </fo:block>
 
175
          </fo:list-item-body>
 
176
      </fo:list-item>
 
177
    </fo:list-block>
 
178
  </fo:block>
 
179
</xsl:template>
 
180
 
 
181
</xsl:stylesheet>