2 <!DOCTYPE xsl:stylesheet [ <!ENTITY % xsldoc.ent SYSTEM "./xsldoc.ent"> %xsldoc.ent; ]>
3 <!--#############################################################################
4 | $Id: callout.mod.xsl,v 1.10 2004/01/14 14:54:32 j-devenish Exp $
5 |- #############################################################################
6 | $Author: j-devenish $
7 + ############################################################################## -->
10 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
11 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
12 exclude-result-prefixes="doc" version='1.0'>
14 <doc:reference id="callout" xmlns="">
16 <releaseinfo role="meta">
17 $Id: callout.mod.xsl,v 1.10 2004/01/14 14:54:32 j-devenish Exp $
24 <year>2000</year><year>2001</year><year>2002</year><year>2003</year><year>2004</year>
25 <holder>Ramon Casellas</holder>
28 <doc:revision rcasver="1.5">&rev_2003_05;</doc:revision>
29 <doc:revision rcasver="1.6">
30 <date>January 2004</date>
31 <revremark>Added callout support.</revremark>
35 <title>Callouts <filename>callout.mod.xsl</filename></title>
39 These template use the concept of an <quote>areamark</quote>, an
40 <quote>arearef</quote> and an <quote>areasymbol</quote>. An areamark
41 is a way of illustrating a callout area as part of an image or
42 listing. An arearef is a way of illustrating a callout area as part of
43 a callout list. By default, the areamark and the arearef are both
44 represented by the areasymbol. (Aside: that the areamark is drawn
45 first.) This system allows opens the possibility for an areamark to
46 draw a box around an area in addition to displaying the areasymbol.
52 <doc:template xmlns="">
53 <refpurpose> Essential preamble for <filename>callout.mod.xsl</filename> support </refpurpose>
57 Loads the <productname>overpic</productname> packages and
58 defines <function condition="latex">calsscale</function>
59 and <function condition="latex">calspair</function> (which
60 are used to convert <quote>calspair</quote> coordinates into
61 <productname>overpic</productname> percent-style coordinates.
68 <term><xref linkend="param.latex.use.overpic"/></term>
70 Whether to enable this preamble or not.
71 If 0, callouts will cause &LaTeX; errors.
78 <listitem><simpara>&preamble;</simpara></listitem>
82 <xsl:template name="latex.preamble.essential.callout">
83 <xsl:if test="$latex.use.overpic=1 and //callout">
86 \usepackage[percent]{overpic}
87 \newdimen\dblatex@ascale \newdimen\dblatex@bscale
88 \newdimen\dblatex@adimen \newdimen\dblatex@bdimen
89 \newdimen\dblatex@cdimen \newdimen\dblatex@ddimen
90 \newcommand{\calsscale}{%
91 \ifnum\@tempcnta>\@tempcntb%
93 \dblatex@bscale=\@tempcntb pt%
94 \divide\dblatex@bscale by \@tempcnta%
97 \dblatex@ascale=\@tempcnta pt%
98 \divide\dblatex@ascale by \@tempcntb%
101 \newcommand{\calspair}[3]{
103 \settowidth{\dblatex@cdimen}{\usebox{\z@}}
104 \settoheight{\dblatex@ddimen}{\usebox{\z@}}
105 \divide\dblatex@cdimen by 2
106 \divide\dblatex@ddimen by 2
107 \dblatex@adimen=#1 pt \dblatex@adimen=\strip@pt\dblatex@ascale\dblatex@adimen
108 \dblatex@bdimen=#2 pt \dblatex@bdimen=\strip@pt\dblatex@bscale\dblatex@bdimen
109 \put(\strip@pt\dblatex@adimen,\strip@pt\dblatex@bdimen){\hspace{-\dblatex@cdimen}\raisebox{-\dblatex@ddimen}{\usebox{\z@}}}
116 <doc:template xmlns="">
117 <refpurpose>Process <doc:db>programlistingco</doc:db> and <doc:db>screenco</doc:db> elements</refpurpose>
127 <xsl:template match="programlistingco|screenco">
128 <xsl:apply-templates select="programlisting|screen|calloutlist"/>
131 <doc:template xmlns="">
132 <refpurpose>Process <doc:db>areaset</doc:db>-related elements</refpurpose>
135 Suppressed (<doc:db>area</doc:db> templates are applied by
136 <xref linkend="template.imagedata"/>).
143 <xsl:template match="areaspec|areaset"/>
145 <doc:template xmlns="">
146 <refpurpose>Process <doc:db>co</doc:db>-related elements</refpurpose>
149 Print a callout number as a parenthesis.
156 <para>This template is probably never applied, because
157 we can't yet handled <doc:db basename="co">cos</doc:db>
158 in verbatim environments.</para>
161 <xsl:template match="co">
162 <xsl:variable name="conum">
163 <xsl:number count="co" format="1"/>
165 <xsl:text>(</xsl:text>
166 <xsl:value-of select="$conum"/>
167 <xsl:text>)</xsl:text>
170 <doc:template xmlns="">
171 <refpurpose>Process <doc:db>calloutlist</doc:db> elements</refpurpose>
181 <xsl:template match="calloutlist">
182 <xsl:apply-templates select="./title"/>
183 <xsl:text> \begin{description} </xsl:text>
184 <xsl:apply-templates select="callout"/>
185 <xsl:text>\end{description} </xsl:text>
188 <doc:template xmlns="">
189 <refpurpose>Process titles for <doc:db>calloutlist</doc:db> elements</refpurpose>
200 <term><xref linkend="param.latex.list.title.style"/></term>
202 The &LaTeX; command for formatting titles.
203 </simpara></listitem>
211 <listitem><simpara>The &LaTeX; command to use. Defaults to
212 <xref linkend="param.latex.list.title.style"/>.</simpara></listitem>
218 Applies templates as a paragraph, formatted with the specified style.
222 <xsl:template match="calloutlist/title">
223 <xsl:param name="style" select="$latex.list.title.style"/>
224 <xsl:text> {</xsl:text>
225 <xsl:value-of select="$style"/>
226 <xsl:text>{</xsl:text>
227 <xsl:apply-templates/>
228 <xsl:text>}} </xsl:text>
231 <doc:template basename="callout" xmlns="">
232 <refpurpose>Process <doc:db>callout</doc:db> elements</refpurpose>
235 Formats arearefs as an <function condition="latex">item</function>,
236 then applies templates. Since there may be multiple IDs specified
237 in the <sgmltag class="attribute">arearefs</sgmltag> attribute,
238 the <xref linkend="template.generate.callout.arearefs"/> template is
239 called recursively to generate the arearefs.
246 <xsl:template match="callout">
247 <xsl:text>\item[{</xsl:text>
248 <xsl:call-template name="generate.callout.arearefs"/>
249 <xsl:text>}]\null{} </xsl:text>
250 <xsl:apply-templates/>
251 <xsl:text> </xsl:text>
254 <doc:template xmlns="">
255 <refpurpose>Determine a <doc:db>callout</doc:db>'s arearefs</refpurpose>
258 Splits the arearef attribute on whitespace, then
259 constructs a list of references by applying templates
260 in <quote>generate.callout.arearef</quote> mode.
268 The current node must be a <doc:db>callout</doc:db>.
272 <xsl:template name="generate.callout.arearefs">
273 <xsl:param name="arearefs" select="normalize-space(@arearefs)"/>
274 <xsl:param name="count" select="1"/>
275 <xsl:if test="$arearefs!=''">
277 <xsl:when test="substring-before($arearefs,' ')=''">
278 <xsl:apply-templates select="." mode="generate.callout.arearef">
279 <xsl:with-param name="arearef" select="$arearefs"/>
280 <xsl:with-param name="count" select="$count"/>
281 <xsl:with-param name="last" select="true()"/>
282 </xsl:apply-templates>
285 <xsl:apply-templates select="." mode="generate.callout.arearef">
286 <xsl:with-param name="arearef" select="substring-before($arearefs,' ')"/>
287 <xsl:with-param name="count" select="$count"/>
288 <xsl:with-param name="last" select="false()"/>
289 </xsl:apply-templates>
292 <xsl:call-template name="generate.callout.arearefs">
293 <xsl:with-param name="arearefs" select="substring-after($arearefs,' ')"/>
294 <xsl:with-param name="count" select="$count + 1"/>
299 <doc:template xmlns="">
300 <refpurpose>Format a <doc:db>callout</doc:db>'s arearefs</refpurpose>
303 Applies templates in <quote>generate.callout.arearef</quote> mode.
314 The ID of the <doc:db>area</doc:db> to which a <doc:db>callout</doc:db>
316 </simpara></listitem>
321 The <doc:db>area</doc:db> object to which a <doc:db>callout</doc:db>
322 refers. By default, this searches for a area whose <sgmltag
323 class="attribute">id</sgmltag> attribute equals the
324 <literal>arearef</literal> parameter.
325 </simpara></listitem>
330 The position of this reference in the list of references
331 used by a given <doc:db>callout</doc:db>. Influences
332 delimiters for list items.
333 </simpara></listitem>
338 Whether this area reference is the last one for a given
339 <doc:db>callout</doc:db>. Influences delimiters for list
341 </simpara></listitem>
347 Formats a reference for a single arearef. This is performed by
348 applying templates for the <doc:db>area</doc:db> in
349 <quote>generate.area.arearef</quote> mode.
352 The current node must be a <doc:db>callout</doc:db>.
355 Uses the <quote>naturalinlinelist</quote> localisation context.
359 <xsl:template match="callout" mode="generate.callout.arearef">
360 <xsl:param name="arearef" select="@arearefs"/>
361 <xsl:param name="area" select="key('id', $arearef)"/>
362 <xsl:param name="last" select="false()"/>
363 <xsl:param name="count" select="1"/>
364 <xsl:variable name="first" select="$count=1"/>
366 <xsl:when test="$first">
367 <xsl:call-template name="gentext.template">
368 <xsl:with-param name="context" select="'naturalinlinelist'"/>
369 <xsl:with-param name="name" select="'start'"/>
372 <xsl:when test="$last">
373 <xsl:call-template name="gentext.template">
374 <xsl:with-param name="context" select="'naturalinlinelist'"/>
375 <xsl:with-param name="name">
377 <xsl:when test="$count > 2">
378 <xsl:text>lastofmany</xsl:text>
381 <xsl:text>lastoftwo</xsl:text>
388 <xsl:call-template name="gentext.template">
389 <xsl:with-param name="context" select="'naturalinlinelist'"/>
390 <xsl:with-param name="name" select="'middle'"/>
395 <xsl:when test="$area">
396 <xsl:apply-templates select="$area" mode="generate.area.arearef"/>
399 <xsl:text>?</xsl:text>
401 <xsl:text>Error: no ID for constraint arearefs: </xsl:text>
402 <xsl:value-of select="$arearef"/>
403 <xsl:text>.</xsl:text>
407 <xsl:if test="$last">
408 <xsl:call-template name="gentext.template">
409 <xsl:with-param name="context" select="'naturalinlinelist'"/>
410 <xsl:with-param name="name" select="'end'"/>
415 <doc:template basename="area" xmlns="">
416 <refpurpose>Illustrate a reference to a callout's area</refpurpose>
419 Formats an <doc:db>area</doc:db> as part of a
428 The current node must be an <doc:db>area</doc:db>.
431 Applies templates in the <quote>generate.arearef.calspair</quote>,
432 <quote>generate.arearef.linerange</quote> and
433 <quote>generate.arearef</quote> modes.
437 <xsl:template match="area" mode="generate.area.arearef">
438 <xsl:variable name="units">
440 <xsl:when test="@units!=''">
441 <xsl:value-of select="@units"/>
443 <xsl:when test="../@units!=''">
444 <xsl:value-of select="../@units"/>
446 <xsl:when test="../../@units!=''">
447 <xsl:value-of select="../../@units"/>
452 <xsl:when test="$units='calspair'">
453 <xsl:apply-templates select="." mode="generate.arearef.calspair"/>
455 <xsl:when test="$units='linerange'">
456 <xsl:apply-templates select="." mode="generate.arearef.linerange"/>
459 <xsl:apply-templates select="." mode="generate.arearef">
460 <xsl:with-param name="units" select="$units"/>
461 </xsl:apply-templates>
466 <doc:template basename="area" xmlns="">
467 <refpurpose>Illustrate a reference to a callout's area</refpurpose>
470 Formats an <doc:db>area</doc:db> as part of a
479 This is a fallback template for unknown units.
480 It does not format an arearef but instead prints
485 <xsl:template match="area" mode="generate.arearef">
486 <xsl:param name="units"/>
487 <xsl:message>Error: unsupported arearef units <xsl:value-of select="$units"/>.</xsl:message>
490 <doc:template basename="area" xmlns="">
491 <refpurpose>Illustrate a reference to a callout's area</refpurpose>
494 Formats calspair units for a callout list.
502 Calls <xref linkend="template.area-generate.area.areasymbol"/>.
506 <xsl:template match="area" mode="generate.arearef.calspair">
507 <xsl:apply-templates select="." mode="generate.area.areasymbol"/>
510 <doc:template basename="area" xmlns="">
511 <refpurpose>Illustrate a reference to a callout's area</refpurpose>
514 Formats linerange units for a callout list.
522 Formats a line range numerically, condensing the line range
523 down to a single line reference if the starting line is the
524 same as the finishing line.
528 <xsl:template match="area" mode="generate.arearef.linerange">
530 <xsl:when test="not(contains(@coords, ' '))">
531 <xsl:value-of select="@coords"/>
534 <xsl:variable name="start" select="substring-before(@coords, ' ')"/>
535 <xsl:variable name="finish" select="substring-after(@coords, ' ')"/>
537 <xsl:when test="$start=$finish">
538 <xsl:value-of select="$start"/>
541 <xsl:call-template name="string-replace">
542 <xsl:with-param name="from" select="' '"/>
543 <xsl:with-param name="to" select="'--'"/>
544 <xsl:with-param name="string" select="@coords"/>
552 <doc:template basename="area" xmlns="">
553 <refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
556 Formats an <doc:db>area</doc:db> as part of a
557 displayed image or listing.
565 Applies templates in the <quote>generate.area.areamark</quote> mode.
569 <xsl:template match="area">
570 <xsl:apply-templates select="." mode="generate.area.areamark"/>
573 <doc:template basename="area" xmlns="">
574 <refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
577 Formats an <doc:db>area</doc:db> as part of a
578 displayed image or listing.
586 Applies templates in the <quote>generate.areamark.calspair</quote> or
587 <quote>generate.areamark</quote> modes.
591 <xsl:template match="area" mode="generate.area.areamark">
592 <xsl:variable name="units">
594 <xsl:when test="@units!=''">
595 <xsl:value-of select="@units"/>
597 <xsl:when test="../@units!=''">
598 <xsl:value-of select="../@units"/>
600 <xsl:when test="../../@units!=''">
601 <xsl:value-of select="../../@units"/>
606 <xsl:when test="$units='calspair'">
607 <xsl:apply-templates select="." mode="generate.areamark.calspair"/>
610 <xsl:apply-templates select="." mode="generate.areamark">
611 <xsl:with-param name="units" select="$units"/>
612 </xsl:apply-templates>
617 <doc:template basename="area" xmlns="">
618 <refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
621 Formats an <doc:db>area</doc:db> as part of a
622 displayed image or listing.
630 This is a fallback template for unknown units.
631 It does not format an areamark but instead prints
636 <xsl:template match="area" mode="generate.areamark">
637 <xsl:param name="units"/>
638 <xsl:message>Error: unsupported areamark units <xsl:value-of select="$units"/>.</xsl:message>
641 <doc:template basename="area" xmlns="">
642 <refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
645 Formats calspair units for a displayed image or listing.
653 Converts calspair coordinates relative to the width and height of the
654 displayed image area. Will understand "x1,y1 x2,y2" and also "x1 y1".
655 In the former case, the drawing location is moved to the centre of
656 the implied rectangle. Templates are then applied in the
657 <quote>generate.area.areasymbol</quote> mode.
661 <xsl:template match="area" mode="generate.areamark.calspair">
663 <xsl:when test="not(contains(@coords, ' '))">
664 <xsl:message>Error: invalid calspair '<xsl:value-of select="@coords"/>'.</xsl:message>
667 <xsl:variable name="x1y1">
668 <xsl:value-of select="substring-before(@coords, ' ')"/>
670 <xsl:variable name="x1">
672 <xsl:when test="contains($x1y1, ',')">
673 <xsl:value-of select="substring-before($x1y1, ',')"/>
676 <xsl:value-of select="$x1y1"/>
680 <xsl:variable name="y1">
682 <xsl:when test="contains($x1y1, ',')">
683 <xsl:value-of select="substring-after($x1y1, ',')"/>
686 <xsl:value-of select="''"/>
690 <xsl:variable name="x2y2">
691 <xsl:value-of select="substring-after(@coords, ' ')"/>
693 <xsl:variable name="y2">
695 <xsl:when test="contains($x2y2, ',')">
696 <xsl:value-of select="substring-after($x2y2, ',')"/>
699 <xsl:value-of select="$x2y2"/>
703 <xsl:variable name="x2">
705 <xsl:when test="contains($x2y2, ',')">
706 <xsl:value-of select="substring-before($x2y2, ',')"/>
709 <xsl:value-of select="''"/>
713 <xsl:text>\calspair{</xsl:text>
714 <!-- choose horizontal coordinate -->
716 <xsl:when test="$x1 != '' and $x2 != ''">
717 <xsl:value-of select="(number($x1)+number($x2)) div 200"/>
720 <xsl:value-of select="number(concat($x1, $x2)) div 100"/>
723 <xsl:text>}{</xsl:text>
724 <!-- choose vertical coordinate -->
726 <xsl:when test="$y1 != '' and $y2 != ''">
727 <xsl:value-of select="(number($y1)+number($y2)) div 200"/>
730 <xsl:value-of select="number(concat($y1, $y2)) div 100"/>
733 <xsl:text>}{</xsl:text>
734 <xsl:apply-templates select="." mode="generate.area.areasymbol"/>
735 <xsl:text>} </xsl:text>
740 <doc:template basename="area" xmlns="">
741 <refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
744 Formats an <doc:db>area</doc:db> as an overlay
745 on an image or listing.
753 If the area has a <sgmltag class="attribute">label</sgmltag>
754 attribute, it is used as raw &LaTeX; code.
757 If the area has a linkends attribute, templates are
758 applied for the first linkend using
759 <quote>generate.callout.areasymbol</quote> mode.
760 It is implicit in this scenario that an arearef
761 and an areamark will both consist of an identical
765 If none of the above were performed, an asterisk is printed.
769 <xsl:template match="area" mode="generate.area.areasymbol">
770 <xsl:param name="linkends" select="normalize-space(@linkends)"/>
772 <xsl:when test="@label">
773 <xsl:value-of select="@label"/>
775 <xsl:when test="$linkends!=''">
776 <xsl:variable name="linkend">
778 <xsl:when test="contains($linkends, ' ')">
779 <xsl:value-of select="substring-before($linkends, ' ')"/>
782 <xsl:value-of select="$linkends"/>
786 <xsl:variable name="target" select="key('id', $linkend)"/>
788 <xsl:when test="count($target)>0">
789 <xsl:for-each select="$target">
790 <xsl:apply-templates select="." mode="generate.callout.areasymbol">
791 <xsl:with-param name="arearef" select="generate-id(current())"/>
792 <xsl:with-param name="area" select="current()"/>
793 </xsl:apply-templates>
797 <xsl:text>?</xsl:text>
799 <xsl:text>Error: no ID for constraint linkends: </xsl:text>
800 <xsl:value-of select="$linkends"/>
801 <xsl:text>.</xsl:text>
807 <xsl:text>*</xsl:text>
812 <doc:template basename="callout" xmlns="">
813 <refpurpose>Illustrate a callout's area as part of an image or listing</refpurpose>
816 Illustrates an <doc:db>area</doc:db> as part of a
817 displayed image or listing.
825 Prints the numeric position of the <doc:db>callout</doc:db> within its <doc:db>calloutlist</doc:db>.
829 <xsl:template match="callout" mode="generate.callout.areasymbol">
830 <xsl:number count="callout" format="1"/>
833 <doc:template xmlns="">
834 <refpurpose>Process <doc:db>mediaobjectco</doc:db> elements</refpurpose>
844 <xsl:template match="mediaobjectco">
845 <xsl:text> </xsl:text>
846 <xsl:apply-templates select="imageobjectco"/>
847 <xsl:text> </xsl:text>
850 <doc:template xmlns="">
851 <refpurpose>Process <doc:db>imageobjectco</doc:db> elements</refpurpose>
861 <xsl:template match="imageobjectco">
862 <xsl:apply-templates select="imageobject"/>
863 <xsl:text> </xsl:text>
864 <xsl:apply-templates select="calloutlist"/>
867 <doc:template basename="imageobject" xmlns="">
868 <refpurpose>Process a <doc:db>imageobjectco</doc:db>'s <doc:db>imageobject</doc:db> elements</refpurpose>
871 Applies templates for <doc:db>imagedata</doc:db>.
878 <xsl:template match="imageobjectco/imageobject">
879 <xsl:apply-templates select="imagedata">
880 <xsl:with-param name="is.imageobjectco" select="true()"/>
881 </xsl:apply-templates>