2 <xsl:stylesheet xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
3 xmlns:
xlink=
"http://www.w3.org/1999/xlink"
4 xmlns:
stext=
"http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
5 xmlns:
simg=
"http://nwalsh.com/xslt/ext/com.nwalsh.saxon.ImageIntrinsics"
6 xmlns:
ximg=
"xalan://com.nwalsh.xalan.ImageIntrinsics"
7 xmlns:
xtext=
"xalan://com.nwalsh.xalan.Text"
8 xmlns:
lxslt=
"http://xml.apache.org/xslt"
9 exclude-result-prefixes=
"xlink stext xtext lxslt simg ximg"
10 extension-element-prefixes=
"stext xtext"
13 <!-- ********************************************************************
14 $Id: graphics.xsl,v 1.1 2007/03/10 05:15:13 scott Exp $
15 ********************************************************************
17 This file is part of the XSL DocBook Stylesheet distribution.
18 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
19 and other information.
22 Colin Paul Adams, <colin@colina.demon.co.uk>
24 ******************************************************************** -->
26 <lxslt:component prefix=
"xtext" elements=
"insertfile"/>
27 <lxslt:component prefix=
"ximg" functions=
"new getWidth getDepth"/>
29 <!-- ==================================================================== -->
30 <!-- Graphic format tests for the HTML backend -->
32 <xsl:template name=
"is.graphic.format">
33 <xsl:param name=
"format"></xsl:param>
34 <xsl:if test=
"$format = 'SVG'
38 or $format = 'linespecific'
42 or $format = 'BMP'">1</xsl:if>
45 <xsl:template name=
"is.graphic.extension">
46 <xsl:param name=
"ext"></xsl:param>
47 <xsl:variable name=
"lcext" select=
"translate($ext,
48 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
49 'abcdefghijklmnopqrstuvwxyz')"/>
50 <xsl:if test=
"$lcext = 'svg'
59 or $lcext = 'bmp'">1</xsl:if>
62 <!-- ==================================================================== -->
64 <xsl:template match=
"screenshot">
66 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
67 <xsl:apply-templates/>
71 <xsl:template match=
"screeninfo">
74 <!-- ==================================================================== -->
76 <xsl:template name=
"process.image">
77 <!-- When this template is called, the current node should be -->
78 <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
79 <!-- those elements have the same set of attributes, so we can -->
80 <!-- handle them all in one place. -->
81 <xsl:param name=
"tag" select=
"'img'"/>
82 <xsl:param name=
"alt"/>
83 <xsl:param name=
"longdesc"/>
85 <!-- The HTML img element only supports the notion of content-area
86 scaling; it doesn't support the distinction between a
87 content-area and a viewport-area, so we have to make some
90 1. If only the content-area is specified, everything is fine.
91 (If you ask for a three inch image, that's what you'll get.)
93 2. If only the viewport-area is provided:
94 - If scalefit=1, treat it as both the content-area and
95 the viewport-area. (If you ask for an image in a five inch
96 area, we'll make the image five inches to fill that area.)
97 - If scalefit=0, ignore the viewport-area specification.
99 Note: this is not quite the right semantic and has the additional
100 problem that it can result in anamorphic scaling, which scalefit
103 3. If both the content-area and the viewport-area is specified
104 on a graphic element, ignore the viewport-area.
105 (If you ask for a three inch image in a five inch area, we'll assume
106 it's better to give you a three inch image in an unspecified area
107 than a five inch image in a five inch area.
109 Relative units also cause problems. As a general rule, the stylesheets
110 are operating too early and too loosely coupled with the rendering engine
111 to know things like the current font size or the actual dimensions of
114 1. We use a fixed size for pixels, $pixels.per.inch
116 2. We use a fixed size for "em"s, $points.per.em
118 Percentages are problematic. In the following discussion, we speak
119 of width and contentwidth, but the same issues apply to depth and
122 1. A width of 50% means "half of the available space for the image."
123 That's fine. But note that in HTML, this is a dynamic property and
124 the image size will vary if the browser window is resized.
126 2. A contentwidth of 50% means "half of the actual image width". But
127 the stylesheets have no way to assess the image's actual size. Treating
128 this as a width of 50% is one possibility, but it produces behavior
129 (dynamic scaling) that seems entirely out of character with the
132 Instead, the stylesheets define a $nominal.image.width
133 and convert percentages to actual values based on that nominal size.
135 Scale can be problematic. Scale applies to the contentwidth, so
136 a scale of 50 when a contentwidth is not specified is analagous to a
137 width of 50%. (If a contentwidth is specified, the scaling factor can
138 be applied to that value and no problem exists.)
140 If scale is specified but contentwidth is not supplied, the
141 nominal.image.width is used to calculate a base size
144 Warning: as a consequence of these decisions, unless the aspect ratio
145 of your image happens to be exactly the same as (nominal width / nominal height),
146 specifying contentwidth="50%" and contentdepth="50%" is NOT going to
147 scale the way you expect (or really, the way it should).
149 Don't do that. In fact, a percentage value is not recommended for content
150 size at all. Use scale instead.
152 Finally, align and valign are troublesome. Horizontal alignment is now
153 supported by wrapping the image in a <div align="{@align}"> (in block
154 contexts!). I can't think of anything (practical) to do about vertical
158 <xsl:variable name=
"width-units">
160 <xsl:when test=
"$ignore.image.scaling != 0"></xsl:when>
161 <xsl:when test=
"@width">
162 <xsl:call-template name=
"length-units">
163 <xsl:with-param name=
"length" select=
"@width"/>
166 <xsl:when test=
"not(@depth) and $default.image.width != ''">
167 <xsl:call-template name=
"length-units">
168 <xsl:with-param name=
"length" select=
"$default.image.width"/>
174 <xsl:variable name=
"width">
176 <xsl:when test=
"$ignore.image.scaling != 0"></xsl:when>
177 <xsl:when test=
"@width">
179 <xsl:when test=
"$width-units = '%'">
180 <xsl:value-of select=
"@width"/>
183 <xsl:call-template name=
"length-spec">
184 <xsl:with-param name=
"length" select=
"@width"/>
189 <xsl:when test=
"not(@depth) and $default.image.width != ''">
190 <xsl:value-of select=
"$default.image.width"/>
195 <xsl:variable name=
"scalefit">
197 <xsl:when test=
"$ignore.image.scaling != 0">0</xsl:when>
198 <xsl:when test=
"@contentwidth or @contentdepth">0</xsl:when>
199 <xsl:when test=
"@scale">0</xsl:when>
200 <xsl:when test=
"@scalefit"><xsl:value-of select=
"@scalefit"/></xsl:when>
201 <xsl:when test=
"$width != '' or @depth">1</xsl:when>
202 <xsl:otherwise>0</xsl:otherwise>
206 <xsl:variable name=
"scale">
208 <xsl:when test=
"$ignore.image.scaling != 0">1.0</xsl:when>
209 <xsl:when test=
"@contentwidth or @contentdepth">1.0</xsl:when>
210 <xsl:when test=
"@scale">
211 <xsl:value-of select=
"@scale div 100.0"/>
213 <xsl:otherwise>1.0</xsl:otherwise>
217 <xsl:variable name=
"filename">
219 <xsl:when test=
"local-name(.) = 'graphic'
220 or local-name(.) = 'inlinegraphic'">
221 <!-- handle legacy graphic and inlinegraphic by new template -->
222 <xsl:call-template name=
"mediaobject.filename">
223 <xsl:with-param name=
"object" select=
"."/>
227 <!-- imagedata, videodata, audiodata -->
228 <xsl:call-template name=
"mediaobject.filename">
229 <xsl:with-param name=
"object" select=
".."/>
235 <xsl:variable name=
"output_filename">
237 <xsl:when test=
"@entityref">
238 <xsl:value-of select=
"$filename"/>
241 Moved test for $keep.relative.image.uris to template below:
242 <xsl:template match="@fileref">
245 <xsl:value-of select=
"$filename"/>
250 <xsl:variable name=
"img.src.path.pi">
251 <xsl:call-template name=
"dbhtml-attribute">
252 <xsl:with-param name=
"pis"
253 select=
"../processing-instruction('dbhtml')"/>
254 <xsl:with-param name=
"attribute" select=
"'img.src.path'"/>
258 <xsl:variable name=
"filename.for.graphicsize">
260 <xsl:when test=
"$img.src.path.pi != ''">
261 <xsl:value-of select=
"concat($img.src.path.pi, $filename)"/>
263 <xsl:when test=
"$img.src.path != '' and
264 $graphicsize.use.img.src.path != 0 and
266 not(starts-with($filename, '/')) and
267 not(contains($filename, '://'))">
268 <xsl:value-of select=
"concat($img.src.path, $filename)"/>
271 <xsl:value-of select=
"$filename"/>
276 <xsl:variable name=
"realintrinsicwidth">
277 <!-- This funny compound test works around a bug in XSLTC -->
279 <xsl:when test=
"$use.extensions != 0 and $graphicsize.extension != 0">
281 <xsl:when test=
"function-available('simg:getWidth')">
282 <xsl:value-of select=
"simg:getWidth(simg:new($filename.for.graphicsize),
283 $nominal.image.width)"/>
285 <xsl:when test=
"function-available('ximg:getWidth')">
286 <xsl:value-of select=
"ximg:getWidth(ximg:new($filename.for.graphicsize),
287 $nominal.image.width)"/>
290 <xsl:value-of select=
"0"/>
295 <xsl:value-of select=
"0"/>
300 <xsl:variable name=
"intrinsicwidth">
302 <xsl:when test=
"$realintrinsicwidth = 0">
303 <xsl:value-of select=
"$nominal.image.width"/>
306 <xsl:value-of select=
"$realintrinsicwidth"/>
311 <xsl:variable name=
"intrinsicdepth">
312 <!-- This funny compound test works around a bug in XSLTC -->
314 <xsl:when test=
"$use.extensions != 0 and $graphicsize.extension != 0">
316 <xsl:when test=
"function-available('simg:getDepth')">
317 <xsl:value-of select=
"simg:getDepth(simg:new($filename.for.graphicsize),
318 $nominal.image.depth)"/>
320 <xsl:when test=
"function-available('ximg:getDepth')">
321 <xsl:value-of select=
"ximg:getDepth(ximg:new($filename.for.graphicsize),
322 $nominal.image.depth)"/>
325 <xsl:value-of select=
"$nominal.image.depth"/>
330 <xsl:value-of select=
"$nominal.image.depth"/>
335 <xsl:variable name=
"contentwidth">
337 <xsl:when test=
"$ignore.image.scaling != 0"></xsl:when>
338 <xsl:when test=
"@contentwidth">
339 <xsl:variable name=
"units">
340 <xsl:call-template name=
"length-units">
341 <xsl:with-param name=
"length" select=
"@contentwidth"/>
346 <xsl:when test=
"$units = '%'">
347 <xsl:variable name=
"cmagnitude">
348 <xsl:call-template name=
"length-magnitude">
349 <xsl:with-param name=
"length" select=
"@contentwidth"/>
352 <xsl:value-of select=
"$intrinsicwidth * $cmagnitude div 100.0"/>
353 <xsl:text>px
</xsl:text>
356 <xsl:call-template name=
"length-spec">
357 <xsl:with-param name=
"length" select=
"@contentwidth"/>
363 <xsl:value-of select=
"$intrinsicwidth"/>
364 <xsl:text>px
</xsl:text>
369 <xsl:variable name=
"scaled.contentwidth">
370 <xsl:if test=
"$contentwidth != ''">
371 <xsl:variable name=
"cwidth.in.points">
372 <xsl:call-template name=
"length-in-points">
373 <xsl:with-param name=
"length" select=
"$contentwidth"/>
374 <xsl:with-param name=
"pixels.per.inch" select=
"$pixels.per.inch"/>
375 <xsl:with-param name=
"em.size" select=
"$points.per.em"/>
378 <xsl:value-of select=
"$cwidth.in.points div 72.0 * $pixels.per.inch * $scale"/>
382 <xsl:variable name=
"html.width">
384 <xsl:when test=
"$ignore.image.scaling != 0"></xsl:when>
385 <xsl:when test=
"$width-units = '%'">
386 <xsl:value-of select=
"$width"/>
388 <xsl:when test=
"$width != ''">
389 <xsl:variable name=
"width.in.points">
390 <xsl:call-template name=
"length-in-points">
391 <xsl:with-param name=
"length" select=
"$width"/>
392 <xsl:with-param name=
"pixels.per.inch" select=
"$pixels.per.inch"/>
393 <xsl:with-param name=
"em.size" select=
"$points.per.em"/>
396 <xsl:value-of select=
"round($width.in.points div 72.0 * $pixels.per.inch)"/>
398 <xsl:otherwise></xsl:otherwise>
402 <xsl:variable name=
"contentdepth">
404 <xsl:when test=
"$ignore.image.scaling != 0"></xsl:when>
405 <xsl:when test=
"@contentdepth">
406 <xsl:variable name=
"units">
407 <xsl:call-template name=
"length-units">
408 <xsl:with-param name=
"length" select=
"@contentdepth"/>
413 <xsl:when test=
"$units = '%'">
414 <xsl:variable name=
"cmagnitude">
415 <xsl:call-template name=
"length-magnitude">
416 <xsl:with-param name=
"length" select=
"@contentdepth"/>
419 <xsl:value-of select=
"$intrinsicdepth * $cmagnitude div 100.0"/>
420 <xsl:text>px
</xsl:text>
423 <xsl:call-template name=
"length-spec">
424 <xsl:with-param name=
"length" select=
"@contentdepth"/>
430 <xsl:value-of select=
"$intrinsicdepth"/>
431 <xsl:text>px
</xsl:text>
436 <xsl:variable name=
"scaled.contentdepth">
437 <xsl:if test=
"$contentdepth != ''">
438 <xsl:variable name=
"cdepth.in.points">
439 <xsl:call-template name=
"length-in-points">
440 <xsl:with-param name=
"length" select=
"$contentdepth"/>
441 <xsl:with-param name=
"pixels.per.inch" select=
"$pixels.per.inch"/>
442 <xsl:with-param name=
"em.size" select=
"$points.per.em"/>
445 <xsl:value-of select=
"$cdepth.in.points div 72.0 * $pixels.per.inch * $scale"/>
449 <xsl:variable name=
"depth-units">
450 <xsl:if test=
"@depth">
451 <xsl:call-template name=
"length-units">
452 <xsl:with-param name=
"length" select=
"@depth"/>
457 <xsl:variable name=
"depth">
458 <xsl:if test=
"@depth">
460 <xsl:when test=
"$depth-units = '%'">
461 <xsl:value-of select=
"@depth"/>
464 <xsl:call-template name=
"length-spec">
465 <xsl:with-param name=
"length" select=
"@depth"/>
472 <xsl:variable name=
"html.depth">
474 <xsl:when test=
"$ignore.image.scaling != 0"></xsl:when>
475 <xsl:when test=
"$depth-units = '%'">
476 <xsl:value-of select=
"$depth"/>
478 <xsl:when test=
"@depth and @depth != ''">
479 <xsl:variable name=
"depth.in.points">
480 <xsl:call-template name=
"length-in-points">
481 <xsl:with-param name=
"length" select=
"$depth"/>
482 <xsl:with-param name=
"pixels.per.inch" select=
"$pixels.per.inch"/>
483 <xsl:with-param name=
"em.size" select=
"$points.per.em"/>
486 <xsl:value-of select=
"round($depth.in.points div 72.0 * $pixels.per.inch)"/>
488 <xsl:otherwise></xsl:otherwise>
492 <xsl:variable name=
"viewport">
494 <xsl:when test=
"$ignore.image.scaling != 0">0</xsl:when>
495 <xsl:when test=
"local-name(.) = 'inlinegraphic'
496 or ancestor::inlinemediaobject
497 or ancestor::inlineequation">0</xsl:when>
499 <xsl:value-of select=
"$make.graphic.viewport"/>
505 <xsl:message>=====================================
506 scale: <xsl:value-of select="$scale"/>, <xsl:value-of select="$scalefit"/>
507 @contentwidth <xsl:value-of select="@contentwidth"/>
508 $contentwidth <xsl:value-of select="$contentwidth"/>
509 scaled.contentwidth: <xsl:value-of select="$scaled.contentwidth"/>
510 @width: <xsl:value-of select="@width"/>
511 width: <xsl:value-of select="$width"/>
512 html.width: <xsl:value-of select="$html.width"/>
513 @contentdepth <xsl:value-of select="@contentdepth"/>
514 $contentdepth <xsl:value-of select="$contentdepth"/>
515 scaled.contentdepth: <xsl:value-of select="$scaled.contentdepth"/>
516 @depth: <xsl:value-of select="@depth"/>
517 depth: <xsl:value-of select="$depth"/>
518 html.depth: <xsl:value-of select="$html.depth"/>
519 align: <xsl:value-of select="@align"/>
520 valign: <xsl:value-of select="@valign"/></xsl:message>
523 <xsl:variable name=
"scaled"
524 select=
"@width|@depth|@contentwidth|@contentdepth
527 <xsl:variable name=
"img">
529 <xsl:when test=
"@format = 'SVG'">
530 <object data=
"{$output_filename}" type=
"image/svg+xml">
531 <xsl:call-template name=
"process.image.attributes">
532 <!--xsl:with-param name="alt" select="$alt"/ there's no alt here-->
533 <xsl:with-param name=
"html.depth" select=
"$html.depth"/>
534 <xsl:with-param name=
"html.width" select=
"$html.width"/>
535 <xsl:with-param name=
"longdesc" select=
"$longdesc"/>
536 <xsl:with-param name=
"scale" select=
"$scale"/>
537 <xsl:with-param name=
"scalefit" select=
"$scalefit"/>
538 <xsl:with-param name=
"scaled.contentdepth" select=
"$scaled.contentdepth"/>
539 <xsl:with-param name=
"scaled.contentwidth" select=
"$scaled.contentwidth"/>
540 <xsl:with-param name=
"viewport" select=
"$viewport"/>
542 <xsl:if test=
"@align">
543 <xsl:attribute name=
"align">
545 <xsl:when test=
"@align = 'center'">middle
</xsl:when>
547 <xsl:value-of select=
"@align"/>
552 <xsl:if test=
"$use.embed.for.svg != 0">
553 <embed src=
"{$output_filename}" type=
"image/svg+xml">
554 <xsl:call-template name=
"process.image.attributes">
555 <!--xsl:with-param name="alt" select="$alt"/ there's no alt here -->
556 <xsl:with-param name=
"html.depth" select=
"$html.depth"/>
557 <xsl:with-param name=
"html.width" select=
"$html.width"/>
558 <xsl:with-param name=
"longdesc" select=
"$longdesc"/>
559 <xsl:with-param name=
"scale" select=
"$scale"/>
560 <xsl:with-param name=
"scalefit" select=
"$scalefit"/>
561 <xsl:with-param name=
"scaled.contentdepth" select=
"$scaled.contentdepth"/>
562 <xsl:with-param name=
"scaled.contentwidth" select=
"$scaled.contentwidth"/>
563 <xsl:with-param name=
"viewport" select=
"$viewport"/>
570 <xsl:element name=
"{$tag}">
571 <xsl:if test=
"$tag = 'img' and ../../self::imageobjectco">
572 <xsl:variable name=
"mapname">
573 <xsl:call-template name=
"object.id">
574 <xsl:with-param name=
"object" select=
"../../areaspec"/>
578 <xsl:when test=
"$scaled">
579 <!-- It might be possible to handle some scaling; needs -->
580 <!-- more investigation -->
582 <xsl:text>Warning: imagemaps not supported
</xsl:text>
583 <xsl:text>on scaled images
</xsl:text>
587 <xsl:attribute name=
"border">0</xsl:attribute>
588 <xsl:attribute name=
"usemap">
589 <xsl:value-of select=
"concat('#', $mapname)"/>
595 <xsl:attribute name=
"src">
597 <xsl:when test=
"$img.src.path != '' and
599 not(starts-with($output_filename, '/')) and
600 not(contains($output_filename, '://'))">
601 <xsl:value-of select=
"$img.src.path"/>
604 <xsl:value-of select=
"$output_filename"/>
607 <xsl:if test=
"@align">
608 <xsl:attribute name=
"align">
610 <xsl:when test=
"@align = 'center'">middle
</xsl:when>
612 <xsl:value-of select=
"@align"/>
618 <xsl:call-template name=
"process.image.attributes">
619 <xsl:with-param name=
"alt">
621 <xsl:when test=
"$alt != ''">
622 <xsl:copy-of select=
"$alt"/>
624 <xsl:when test=
"ancestor::figure">
625 <xsl:value-of select=
"normalize-space(ancestor::figure/title)"/>
629 <xsl:with-param name=
"html.depth" select=
"$html.depth"/>
630 <xsl:with-param name=
"html.width" select=
"$html.width"/>
631 <xsl:with-param name=
"longdesc" select=
"$longdesc"/>
632 <xsl:with-param name=
"scale" select=
"$scale"/>
633 <xsl:with-param name=
"scalefit" select=
"$scalefit"/>
634 <xsl:with-param name=
"scaled.contentdepth" select=
"$scaled.contentdepth"/>
635 <xsl:with-param name=
"scaled.contentwidth" select=
"$scaled.contentwidth"/>
636 <xsl:with-param name=
"viewport" select=
"$viewport"/>
643 <xsl:variable name=
"bgcolor">
644 <xsl:call-template name=
"dbhtml-attribute">
645 <xsl:with-param name=
"pis"
646 select=
"../processing-instruction('dbhtml')"/>
647 <xsl:with-param name=
"attribute" select=
"'background-color'"/>
651 <xsl:variable name=
"use.viewport"
652 select=
"$viewport != 0
653 and ($html.width != ''
654 or ($html.depth != '' and $depth-units != '%')
659 <xsl:when test=
"$use.viewport">
660 <table border=
"0" summary=
"manufactured viewport for HTML img"
661 cellspacing=
"0" cellpadding=
"0">
662 <xsl:if test=
"$html.width != ''">
663 <xsl:attribute name=
"width">
664 <xsl:value-of select=
"$html.width"/>
668 <xsl:if test=
"$html.depth != '' and $depth-units != '%'">
669 <!-- don't do this for percentages because browsers get confused -->
671 <xsl:when test=
"$css.decoration != 0">
672 <xsl:attribute name=
"style">
673 <xsl:text>height:
</xsl:text>
674 <xsl:value-of select=
"$html.depth"/>
675 <xsl:text>px
</xsl:text>
679 <xsl:attribute name=
"height">
680 <xsl:value-of select=
"$html.depth"/>
686 <xsl:if test=
"$bgcolor != ''">
688 <xsl:when test=
"$css.decoration != 0">
689 <xsl:attribute name=
"style">
690 <xsl:text>background-color:
</xsl:text>
691 <xsl:value-of select=
"$bgcolor"/>
695 <xsl:attribute name=
"bgcolor">
696 <xsl:value-of select=
"$bgcolor"/>
701 <xsl:if test=
"@align">
702 <xsl:attribute name=
"align">
703 <xsl:value-of select=
"@align"/>
706 <xsl:if test=
"@valign">
707 <xsl:attribute name=
"valign">
708 <xsl:value-of select=
"@valign"/>
711 <xsl:copy-of select=
"$img"/>
717 <xsl:copy-of select=
"$img"/>
721 <xsl:if test=
"$tag = 'img' and ../../self::imageobjectco and not($scaled)">
722 <xsl:variable name=
"mapname">
723 <xsl:call-template name=
"object.id">
724 <xsl:with-param name=
"object" select=
"../../areaspec"/>
728 <map name=
"{$mapname}">
729 <xsl:for-each select=
"../../areaspec//area">
730 <xsl:variable name=
"units">
732 <xsl:when test=
"@units = 'other' and @otherunits">
733 <xsl:value-of select=
"@otherunits"/>
735 <xsl:when test=
"@units">
736 <xsl:value-of select=
"@units"/>
738 <!-- areaspec|areaset/area -->
739 <xsl:when test=
"../@units = 'other' and ../@otherunits">
740 <xsl:value-of select=
"../@otherunits"/>
742 <xsl:when test=
"../@units">
743 <xsl:value-of select=
"../@units"/>
745 <!-- areaspec/areaset/area -->
746 <xsl:when test=
"../../@units = 'other' and ../../@otherunits">
747 <xsl:value-of select=
"../@otherunits"/>
749 <xsl:when test=
"../../@units">
750 <xsl:value-of select=
"../../@units"/>
752 <xsl:otherwise>calspair
</xsl:otherwise>
757 <xsl:when test=
"$units = 'calspair' or
758 $units = 'imagemap'">
759 <xsl:variable name=
"coords" select=
"normalize-space(@coords)"/>
762 <xsl:variable name=
"linkends">
764 <xsl:when test=
"@linkends">
765 <xsl:value-of select=
"normalize-space(@linkends)"/>
768 <xsl:value-of select=
"normalize-space(../@linkends)"/>
773 <xsl:variable name=
"href">
775 <xsl:when test=
"@xlink:href">
776 <xsl:value-of select=
"@xlink:href"/>
779 <xsl:value-of select=
"../@xlink:href"/>
785 <xsl:when test=
"$linkends != ''">
786 <xsl:variable name=
"linkend">
788 <xsl:when test=
"contains($linkends, ' ')">
789 <xsl:value-of select=
"substring-before($linkends, ' ')"/>
792 <xsl:value-of select=
"$linkends"/>
797 <xsl:variable name=
"target" select=
"key('id', $linkend)[1]"/>
799 <xsl:if test=
"$target">
800 <xsl:attribute name=
"href">
801 <xsl:call-template name=
"href.target">
802 <xsl:with-param name=
"object" select=
"$target"/>
807 <xsl:when test=
"$href != ''">
808 <xsl:attribute name=
"href">
809 <xsl:value-of select=
"$href"/>
815 <xsl:attribute name=
"alt">
816 <xsl:value-of select=
"alt[1]"/>
820 <xsl:attribute name=
"coords">
822 <xsl:when test=
"$units = 'calspair'">
824 <xsl:variable name=
"p1"
825 select=
"substring-before($coords, ' ')"/>
826 <xsl:variable name=
"p2"
827 select=
"substring-after($coords, ' ')"/>
829 <xsl:variable name=
"x1" select=
"substring-before($p1,',')"/>
830 <xsl:variable name=
"y1" select=
"substring-after($p1,',')"/>
831 <xsl:variable name=
"x2" select=
"substring-before($p2,',')"/>
832 <xsl:variable name=
"y2" select=
"substring-after($p2,',')"/>
834 <xsl:variable name=
"x1p" select=
"$x1 div 100.0"/>
835 <xsl:variable name=
"y1p" select=
"$y1 div 100.0"/>
836 <xsl:variable name=
"x2p" select=
"$x2 div 100.0"/>
837 <xsl:variable name=
"y2p" select=
"$y2 div 100.0"/>
841 <xsl:text>units: </xsl:text>
842 <xsl:value-of select="$units"/>
843 <xsl:text> </xsl:text>
844 <xsl:value-of select="$x1p"/><xsl:text>, </xsl:text>
845 <xsl:value-of select="$y1p"/><xsl:text>, </xsl:text>
846 <xsl:value-of select="$x2p"/><xsl:text>, </xsl:text>
847 <xsl:value-of select="$y2p"/><xsl:text>, </xsl:text>
851 <xsl:text> </xsl:text>
852 <xsl:value-of select="$intrinsicwidth"/>
853 <xsl:text>, </xsl:text>
854 <xsl:value-of select="$intrinsicdepth"/>
858 <xsl:text> </xsl:text>
859 <xsl:value-of select="$units"/>
860 <xsl:text> </xsl:text>
862 select="round($x1p * $intrinsicwidth div 100.0)"/>
863 <xsl:text>,</xsl:text>
864 <xsl:value-of select="round($intrinsicdepth
865 - ($y2p * $intrinsicdepth div 100.0))"/>
866 <xsl:text>,</xsl:text>
867 <xsl:value-of select="round($x2p *
868 $intrinsicwidth div 100.0)"/>
869 <xsl:text>,</xsl:text>
870 <xsl:value-of select="round($intrinsicdepth
871 - ($y1p * $intrinsicdepth div 100.0))"/>
875 select=
"round($x1p * $intrinsicwidth div 100.0)"/>
876 <xsl:text>,
</xsl:text>
877 <xsl:value-of select=
"round($intrinsicdepth
878 - ($y2p * $intrinsicdepth div 100.0))"/>
879 <xsl:text>,
</xsl:text>
881 select=
"round($x2p * $intrinsicwidth div 100.0)"/>
882 <xsl:text>,
</xsl:text>
883 <xsl:value-of select=
"round($intrinsicdepth
884 - ($y1p * $intrinsicdepth div 100.0))"/>
887 <xsl:copy-of select=
"$coords"/>
895 <xsl:text>Warning: only calspair or
</xsl:text>
896 <xsl:text>otherunits='imagemap' supported
</xsl:text>
897 <xsl:text>in imageobjectco
</xsl:text>
906 <xsl:template name=
"process.image.attributes">
907 <xsl:param name=
"alt"/>
908 <xsl:param name=
"html.width"/>
909 <xsl:param name=
"html.depth"/>
910 <xsl:param name=
"longdesc"/>
911 <xsl:param name=
"scale"/>
912 <xsl:param name=
"scalefit"/>
913 <xsl:param name=
"scaled.contentdepth"/>
914 <xsl:param name=
"scaled.contentwidth"/>
915 <xsl:param name=
"viewport"/>
918 <xsl:when test=
"@contentwidth or @contentdepth">
919 <!-- ignore @width/@depth, @scale, and @scalefit if specified -->
920 <xsl:if test=
"@contentwidth">
921 <xsl:attribute name=
"width">
922 <xsl:value-of select=
"$scaled.contentwidth"/>
925 <xsl:if test=
"@contentdepth">
926 <xsl:attribute name=
"height">
927 <xsl:value-of select=
"$scaled.contentdepth"/>
932 <xsl:when test=
"number($scale) != 1.0">
933 <!-- scaling is always uniform, so we only have to specify one dimension -->
934 <!-- ignore @scalefit if specified -->
935 <xsl:attribute name=
"width">
936 <xsl:value-of select=
"$scaled.contentwidth"/>
940 <xsl:when test=
"$scalefit != 0">
942 <xsl:when test=
"contains($html.width, '%')">
944 <xsl:when test=
"$viewport != 0">
945 <!-- The *viewport* will be scaled, so use 100% here! -->
946 <xsl:attribute name=
"width">
947 <xsl:value-of select=
"'100%'"/>
951 <xsl:attribute name=
"width">
952 <xsl:value-of select=
"$html.width"/>
958 <xsl:when test=
"contains($html.depth, '%')">
959 <!-- HTML doesn't deal with this case very well...do nothing -->
962 <xsl:when test=
"$scaled.contentwidth != '' and $html.width != ''
963 and $scaled.contentdepth != '' and $html.depth != ''">
964 <!-- scalefit should not be anamorphic; figure out which direction -->
965 <!-- has the limiting scale factor and scale in that direction -->
967 <xsl:when test=
"$html.width div $scaled.contentwidth >
968 $html.depth div $scaled.contentdepth">
969 <xsl:attribute name=
"height">
970 <xsl:value-of select=
"$html.depth"/>
974 <xsl:attribute name=
"width">
975 <xsl:value-of select=
"$html.width"/>
981 <xsl:when test=
"$scaled.contentwidth != '' and $html.width != ''">
982 <xsl:attribute name=
"width">
983 <xsl:value-of select=
"$html.width"/>
987 <xsl:when test=
"$scaled.contentdepth != '' and $html.depth != ''">
988 <xsl:attribute name=
"height">
989 <xsl:value-of select=
"$html.depth"/>
996 <xsl:if test=
"$alt != ''">
997 <xsl:attribute name=
"alt">
998 <xsl:value-of select=
"normalize-space($alt)"/>
1002 <xsl:if test=
"$longdesc != ''">
1003 <xsl:attribute name=
"longdesc">
1004 <xsl:value-of select=
"$longdesc"/>
1008 <xsl:if test=
"@align and $viewport = 0">
1009 <xsl:attribute name=
"align">
1011 <xsl:when test=
"@align = 'center'">middle
</xsl:when>
1013 <xsl:value-of select=
"@align"/>
1020 <!-- ==================================================================== -->
1022 <xsl:template match=
"graphic">
1024 <xsl:when test=
"parent::inlineequation">
1025 <xsl:call-template name=
"anchor"/>
1026 <xsl:call-template name=
"process.image"/>
1030 <xsl:if test=
"@align">
1031 <xsl:attribute name=
"align">
1032 <xsl:value-of select=
"@align"/>
1035 <xsl:call-template name=
"anchor"/>
1036 <xsl:call-template name=
"process.image"/>
1042 <xsl:template match=
"inlinegraphic">
1043 <xsl:variable name=
"filename">
1045 <xsl:when test=
"@entityref">
1046 <xsl:value-of select=
"unparsed-entity-uri(@entityref)"/>
1049 <xsl:apply-templates select=
"@fileref"/>
1054 <xsl:call-template name=
"anchor"/>
1057 <xsl:when test=
"@format='linespecific'">
1059 <xsl:when test=
"$use.extensions != '0'
1060 and $textinsert.extension != '0'">
1062 <xsl:when test=
"element-available('stext:insertfile')">
1063 <stext:insertfile href=
"{$filename}" encoding=
"{$textdata.default.encoding}"/>
1065 <xsl:when test=
"element-available('xtext:insertfile')">
1066 <xtext:insertfile href=
"{$filename}"/>
1069 <xsl:message terminate=
"yes">
1070 <xsl:text>No insertfile extension available.
</xsl:text>
1076 <a xlink:
type=
"simple" xlink:
show=
"embed" xlink:
actuate=
"onLoad"
1077 href=
"{$filename}"/>
1082 <xsl:call-template name=
"process.image"/>
1087 <!-- ==================================================================== -->
1089 <xsl:template match=
"mediaobject|mediaobjectco">
1091 <xsl:variable name=
"olist" select=
"imageobject|imageobjectco
1092 |videoobject|audioobject
1095 <xsl:variable name=
"object.index">
1096 <xsl:call-template name=
"select.mediaobject.index">
1097 <xsl:with-param name=
"olist" select=
"$olist"/>
1098 <xsl:with-param name=
"count" select=
"1"/>
1099 </xsl:call-template>
1102 <xsl:variable name=
"object" select=
"$olist[position() = $object.index]"/>
1104 <xsl:variable name=
"align">
1105 <xsl:value-of select=
"$object/descendant::imagedata[@align][1]/@align"/>
1109 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
1110 <xsl:if test=
"$align != '' ">
1111 <xsl:attribute name=
"align">
1112 <xsl:value-of select=
"$align"/>
1115 <xsl:call-template name=
"anchor"/>
1117 <xsl:apply-templates select=
"$object"/>
1118 <xsl:apply-templates select=
"caption"/>
1122 <xsl:template match=
"inlinemediaobject">
1124 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
1125 <xsl:call-template name=
"anchor"/>
1126 <xsl:call-template name=
"select.mediaobject"/>
1130 <xsl:template match=
"programlisting/inlinemediaobject
1131 |screen/inlinemediaobject" priority=
"2">
1132 <!-- the additional span causes problems in some cases -->
1133 <xsl:call-template name=
"select.mediaobject"/>
1136 <!-- ==================================================================== -->
1138 <xsl:template match=
"imageobjectco">
1139 <xsl:call-template name=
"anchor"/>
1140 <xsl:apply-templates select=
"imageobject"/>
1141 <xsl:apply-templates select=
"calloutlist"/>
1144 <xsl:template match=
"imageobject">
1146 <xsl:when xmlns:
svg=
"http://www.w3.org/2000/svg"
1148 <xsl:apply-templates/>
1151 <xsl:apply-templates select=
"imagedata"/>
1156 <xsl:template match=
"imagedata">
1157 <xsl:variable name=
"filename">
1158 <xsl:call-template name=
"mediaobject.filename">
1159 <xsl:with-param name=
"object" select=
".."/>
1160 </xsl:call-template>
1164 <xsl:when test=
"@format='linespecific'">
1166 <xsl:when test=
"$use.extensions != '0'
1167 and $textinsert.extension != '0'">
1169 <xsl:when test=
"element-available('stext:insertfile')">
1170 <stext:insertfile href=
"{$filename}" encoding=
"{$textdata.default.encoding}"/>
1172 <xsl:when test=
"element-available('xtext:insertfile')">
1173 <xtext:insertfile href=
"{$filename}"/>
1176 <xsl:message terminate=
"yes">
1177 <xsl:text>No insertfile extension available.
</xsl:text>
1183 <a xlink:
type=
"simple" xlink:
show=
"embed" xlink:
actuate=
"onLoad"
1184 href=
"{$filename}"/>
1189 <xsl:variable name=
"longdesc.uri">
1190 <xsl:call-template name=
"longdesc.uri">
1191 <xsl:with-param name=
"mediaobject"
1192 select=
"ancestor::imageobject/parent::*"/>
1193 </xsl:call-template>
1196 <xsl:variable name=
"phrases"
1197 select=
"ancestor::mediaobject/textobject[phrase]
1198 |ancestor::inlinemediaobject/textobject[phrase]
1199 |ancestor::mediaobjectco/textobject[phrase]"/>
1201 <xsl:call-template name=
"process.image">
1202 <xsl:with-param name=
"alt">
1203 <xsl:apply-templates select=
"$phrases[not(@role) or @role!='tex'][1]"/>
1205 <xsl:with-param name=
"longdesc">
1206 <xsl:call-template name=
"write.longdesc">
1207 <xsl:with-param name=
"mediaobject"
1208 select=
"ancestor::imageobject/parent::*"/>
1209 </xsl:call-template>
1211 </xsl:call-template>
1213 <xsl:if test=
"$html.longdesc != 0 and $html.longdesc.link != 0
1214 and ancestor::imageobject/parent::*/textobject[not(phrase)]">
1215 <xsl:call-template name=
"longdesc.link">
1216 <xsl:with-param name=
"longdesc.uri" select=
"$longdesc.uri"/>
1217 </xsl:call-template>
1223 <!-- ==================================================================== -->
1225 <xsl:template name=
"longdesc.uri">
1226 <xsl:param name=
"mediaobject" select=
"."/>
1228 <xsl:if test=
"$html.longdesc">
1229 <xsl:if test=
"$mediaobject/textobject[not(phrase)]">
1230 <xsl:variable name=
"image-id">
1231 <xsl:call-template name=
"object.id">
1232 <xsl:with-param name=
"object" select=
"$mediaobject"/>
1233 </xsl:call-template>
1235 <xsl:variable name=
"dbhtml.dir">
1236 <xsl:call-template name=
"dbhtml-dir"/>
1238 <xsl:variable name=
"filename">
1239 <xsl:call-template name=
"make-relative-filename">
1240 <xsl:with-param name=
"base.dir">
1242 <xsl:when test=
"$dbhtml.dir != ''">
1243 <xsl:value-of select=
"$dbhtml.dir"/>
1246 <xsl:value-of select=
"$base.dir"/>
1250 <xsl:with-param name=
"base.name"
1251 select=
"concat('ld-',$image-id,$html.ext)"/>
1252 </xsl:call-template>
1255 <xsl:value-of select=
"$filename"/>
1260 <xsl:template name=
"write.longdesc">
1261 <xsl:param name=
"mediaobject" select=
"."/>
1262 <xsl:if test=
"$html.longdesc != 0 and $mediaobject/textobject[not(phrase)]">
1263 <xsl:variable name=
"filename">
1264 <xsl:call-template name=
"longdesc.uri">
1265 <xsl:with-param name=
"mediaobject" select=
"$mediaobject"/>
1266 </xsl:call-template>
1269 <xsl:value-of select=
"$filename"/>
1271 <xsl:call-template name=
"write.chunk">
1272 <xsl:with-param name=
"filename" select=
"$filename"/>
1273 <xsl:with-param name=
"quiet" select=
"$chunk.quietly"/>
1274 <xsl:with-param name=
"content">
1275 <xsl:call-template name=
"user.preroot"/>
1278 <xsl:call-template name=
"system.head.content"/>
1279 <xsl:call-template name=
"head.content">
1280 <xsl:with-param name=
"title" select=
"'Long Description'"/>
1281 </xsl:call-template>
1282 <xsl:call-template name=
"user.head.content"/>
1285 <xsl:call-template name=
"body.attributes"/>
1286 <xsl:for-each select=
"$mediaobject/textobject[not(phrase)]">
1287 <xsl:apply-templates select=
"./*"/>
1291 <xsl:value-of select=
"$chunk.append"/>
1293 </xsl:call-template>
1297 <xsl:template name=
"longdesc.link">
1298 <xsl:param name=
"longdesc.uri" select=
"''"/>
1300 <xsl:variable name=
"this.uri">
1301 <xsl:call-template name=
"make-relative-filename">
1302 <xsl:with-param name=
"base.dir" select=
"$base.dir"/>
1303 <xsl:with-param name=
"base.name">
1304 <xsl:call-template name=
"href.target.uri"/>
1306 </xsl:call-template>
1309 <xsl:variable name=
"href.to">
1310 <xsl:call-template name=
"trim.common.uri.paths">
1311 <xsl:with-param name=
"uriA" select=
"$longdesc.uri"/>
1312 <xsl:with-param name=
"uriB" select=
"$this.uri"/>
1313 <xsl:with-param name=
"return" select=
"'A'"/>
1314 </xsl:call-template>
1317 <div class=
"longdesc-link" align=
"right">
1319 <span class=
"longdesc-link">
1320 <xsl:text>[
</xsl:text>
1321 <a href=
"{$href.to}" target=
"longdesc">D
</a>
1322 <xsl:text>]
</xsl:text>
1327 <!-- ==================================================================== -->
1329 <xsl:template match=
"videoobject">
1330 <xsl:apply-templates select=
"videodata"/>
1333 <xsl:template match=
"videodata">
1334 <xsl:call-template name=
"process.image">
1335 <xsl:with-param name=
"tag" select=
"'embed'"/>
1336 <xsl:with-param name=
"alt">
1337 <xsl:apply-templates select=
"(../../textobject/phrase)[1]"/>
1339 </xsl:call-template>
1342 <!-- ==================================================================== -->
1344 <xsl:template match=
"audioobject">
1345 <xsl:apply-templates select=
"audiodata"/>
1348 <xsl:template match=
"audiodata">
1349 <xsl:call-template name=
"process.image">
1350 <xsl:with-param name=
"tag" select=
"'embed'"/>
1351 <xsl:with-param name=
"alt">
1352 <xsl:apply-templates select=
"(../../textobject/phrase)[1]"/>
1354 </xsl:call-template>
1357 <!-- ==================================================================== -->
1359 <xsl:template match=
"textobject">
1360 <xsl:apply-templates/>
1363 <xsl:template match=
"textdata">
1364 <xsl:variable name=
"filename">
1366 <xsl:when test=
"@entityref">
1367 <xsl:value-of select=
"unparsed-entity-uri(@entityref)"/>
1370 <xsl:apply-templates select=
"@fileref"/>
1375 <xsl:variable name=
"encoding">
1377 <xsl:when test=
"@encoding">
1378 <xsl:value-of select=
"@encoding"/>
1381 <xsl:value-of select=
"$textdata.default.encoding"/>
1387 <xsl:when test=
"$use.extensions != '0'
1388 and $textinsert.extension != '0'">
1390 <xsl:when test=
"element-available('stext:insertfile')">
1391 <stext:insertfile href=
"{$filename}" encoding=
"{$encoding}"/>
1393 <xsl:when test=
"element-available('xtext:insertfile')">
1394 <xtext:insertfile href=
"{$filename}"/>
1397 <xsl:message terminate=
"yes">
1398 <xsl:text>No insertfile extension available.
</xsl:text>
1404 <a xlink:
type=
"simple" xlink:
show=
"embed" xlink:
actuate=
"onLoad"
1405 href=
"{$filename}"/>
1410 <!-- ==================================================================== -->
1412 <xsl:template match=
"caption">
1414 <xsl:apply-templates select=
"." mode=
"class.attribute"/>
1415 <xsl:if test=
"@align = 'right' or @align = 'left' or @align='center'">
1416 <xsl:attribute name=
"align"><xsl:value-of
1417 select=
"@align"/></xsl:attribute>
1419 <xsl:apply-templates/>
1423 <!-- ==================================================================== -->
1424 <!-- "Support" for SVG -->
1426 <xsl:template match=
"svg:*" xmlns:
svg=
"http://www.w3.org/2000/svg">
1428 <xsl:copy-of select=
"@*"/>
1429 <xsl:apply-templates/>
1434 <!-- The following works sometimes, but needs to take into account
1435 1. When there is no /*/@xml:base
1436 2. When the chunks are going somewhere else
1437 <xsl:variable name="relpath">
1438 <xsl:call-template name="relative-uri">
1439 <xsl:with-param name="filename" select="@fileref"/>
1440 </xsl:call-template>
1444 <xsl:when test="/*/@xml:base
1445 and starts-with($relpath,/*/@xml:base)">
1446 <xsl:value-of select="substring-after($relpath,/*/@xml:base)"/>
1449 <xsl:value-of select="@fileref"/>
1452 <xsl:value-of select="@fileref"/>
1455 <!-- Resolve xml:base attributes -->
1456 <xsl:template match=
"@fileref">
1457 <!-- need a check for absolute urls -->
1459 <xsl:when test=
"contains(., ':')">
1460 <!-- it has a uri scheme so it is an absolute uri -->
1461 <xsl:value-of select=
"."/>
1463 <xsl:when test=
"$keep.relative.image.uris != 0">
1464 <!-- leave it alone -->
1465 <xsl:value-of select=
"."/>
1468 <!-- its a relative uri that needs xml:base processing -->
1469 <xsl:call-template name=
"relative-uri">
1470 </xsl:call-template>