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 8421 2009-05-04 07:49:49Z bobstayton $
15 ********************************************************************
17 This file is part of the XSL DocBook Stylesheet distribution.
18 See ../README or http://docbook.sf.net/release/xsl/current/ for
19 copyright 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="common.html.attributes"/>
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="pi.dbhtml_img.src.path">
252 <xsl:with-param name="node" select=".."/>
256 <xsl:variable name="filename.for.graphicsize">
258 <xsl:when test="$img.src.path.pi != ''">
259 <xsl:value-of select="concat($img.src.path.pi, $filename)"/>
261 <xsl:when test="$img.src.path != '' and
262 $graphicsize.use.img.src.path != 0 and
264 not(starts-with($filename, '/')) and
265 not(contains($filename, '://'))">
266 <xsl:value-of select="concat($img.src.path, $filename)"/>
269 <xsl:value-of select="$filename"/>
274 <xsl:variable name="realintrinsicwidth">
275 <!-- This funny compound test works around a bug in XSLTC -->
277 <xsl:when test="$use.extensions != 0 and $graphicsize.extension != 0">
279 <xsl:when test="function-available('simg:getWidth')">
280 <xsl:value-of select="simg:getWidth(simg:new($filename.for.graphicsize),
281 $nominal.image.width)"/>
283 <xsl:when test="function-available('ximg:getWidth')">
284 <xsl:value-of select="ximg:getWidth(ximg:new($filename.for.graphicsize),
285 $nominal.image.width)"/>
288 <xsl:value-of select="0"/>
293 <xsl:value-of select="0"/>
298 <xsl:variable name="intrinsicwidth">
300 <xsl:when test="$realintrinsicwidth = 0">
301 <xsl:value-of select="$nominal.image.width"/>
304 <xsl:value-of select="$realintrinsicwidth"/>
309 <xsl:variable name="intrinsicdepth">
310 <!-- This funny compound test works around a bug in XSLTC -->
312 <xsl:when test="$use.extensions != 0 and $graphicsize.extension != 0">
314 <xsl:when test="function-available('simg:getDepth')">
315 <xsl:value-of select="simg:getDepth(simg:new($filename.for.graphicsize),
316 $nominal.image.depth)"/>
318 <xsl:when test="function-available('ximg:getDepth')">
319 <xsl:value-of select="ximg:getDepth(ximg:new($filename.for.graphicsize),
320 $nominal.image.depth)"/>
323 <xsl:value-of select="$nominal.image.depth"/>
328 <xsl:value-of select="$nominal.image.depth"/>
333 <xsl:variable name="contentwidth">
335 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
336 <xsl:when test="@contentwidth">
337 <xsl:variable name="units">
338 <xsl:call-template name="length-units">
339 <xsl:with-param name="length" select="@contentwidth"/>
344 <xsl:when test="$units = '%'">
345 <xsl:variable name="cmagnitude">
346 <xsl:call-template name="length-magnitude">
347 <xsl:with-param name="length" select="@contentwidth"/>
350 <xsl:value-of select="$intrinsicwidth * $cmagnitude div 100.0"/>
351 <xsl:text>px</xsl:text>
354 <xsl:call-template name="length-spec">
355 <xsl:with-param name="length" select="@contentwidth"/>
361 <xsl:value-of select="$intrinsicwidth"/>
362 <xsl:text>px</xsl:text>
367 <xsl:variable name="scaled.contentwidth">
368 <xsl:if test="$contentwidth != ''">
369 <xsl:variable name="cwidth.in.points">
370 <xsl:call-template name="length-in-points">
371 <xsl:with-param name="length" select="$contentwidth"/>
372 <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
373 <xsl:with-param name="em.size" select="$points.per.em"/>
376 <xsl:value-of select="$cwidth.in.points div 72.0 * $pixels.per.inch * $scale"/>
380 <xsl:variable name="html.width">
382 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
383 <xsl:when test="$width-units = '%'">
384 <xsl:value-of select="$width"/>
386 <xsl:when test="$width != ''">
387 <xsl:variable name="width.in.points">
388 <xsl:call-template name="length-in-points">
389 <xsl:with-param name="length" select="$width"/>
390 <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
391 <xsl:with-param name="em.size" select="$points.per.em"/>
394 <xsl:value-of select="round($width.in.points div 72.0 * $pixels.per.inch)"/>
396 <xsl:otherwise></xsl:otherwise>
400 <xsl:variable name="contentdepth">
402 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
403 <xsl:when test="@contentdepth">
404 <xsl:variable name="units">
405 <xsl:call-template name="length-units">
406 <xsl:with-param name="length" select="@contentdepth"/>
411 <xsl:when test="$units = '%'">
412 <xsl:variable name="cmagnitude">
413 <xsl:call-template name="length-magnitude">
414 <xsl:with-param name="length" select="@contentdepth"/>
417 <xsl:value-of select="$intrinsicdepth * $cmagnitude div 100.0"/>
418 <xsl:text>px</xsl:text>
421 <xsl:call-template name="length-spec">
422 <xsl:with-param name="length" select="@contentdepth"/>
428 <xsl:value-of select="$intrinsicdepth"/>
429 <xsl:text>px</xsl:text>
434 <xsl:variable name="scaled.contentdepth">
435 <xsl:if test="$contentdepth != ''">
436 <xsl:variable name="cdepth.in.points">
437 <xsl:call-template name="length-in-points">
438 <xsl:with-param name="length" select="$contentdepth"/>
439 <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
440 <xsl:with-param name="em.size" select="$points.per.em"/>
443 <xsl:value-of select="$cdepth.in.points div 72.0 * $pixels.per.inch * $scale"/>
447 <xsl:variable name="depth-units">
448 <xsl:if test="@depth">
449 <xsl:call-template name="length-units">
450 <xsl:with-param name="length" select="@depth"/>
455 <xsl:variable name="depth">
456 <xsl:if test="@depth">
458 <xsl:when test="$depth-units = '%'">
459 <xsl:value-of select="@depth"/>
462 <xsl:call-template name="length-spec">
463 <xsl:with-param name="length" select="@depth"/>
470 <xsl:variable name="html.depth">
472 <xsl:when test="$ignore.image.scaling != 0"></xsl:when>
473 <xsl:when test="$depth-units = '%'">
474 <xsl:value-of select="$depth"/>
476 <xsl:when test="@depth and @depth != ''">
477 <xsl:variable name="depth.in.points">
478 <xsl:call-template name="length-in-points">
479 <xsl:with-param name="length" select="$depth"/>
480 <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
481 <xsl:with-param name="em.size" select="$points.per.em"/>
484 <xsl:value-of select="round($depth.in.points div 72.0 * $pixels.per.inch)"/>
486 <xsl:otherwise></xsl:otherwise>
490 <xsl:variable name="viewport">
492 <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
493 <xsl:when test="local-name(.) = 'inlinegraphic'
494 or ancestor::inlinemediaobject
495 or ancestor::inlineequation">0</xsl:when>
497 <xsl:value-of select="$make.graphic.viewport"/>
503 <xsl:message>=====================================
504 scale: <xsl:value-of select="$scale"/>, <xsl:value-of select="$scalefit"/>
505 @contentwidth <xsl:value-of select="@contentwidth"/>
506 $contentwidth <xsl:value-of select="$contentwidth"/>
507 scaled.contentwidth: <xsl:value-of select="$scaled.contentwidth"/>
508 @width: <xsl:value-of select="@width"/>
509 width: <xsl:value-of select="$width"/>
510 html.width: <xsl:value-of select="$html.width"/>
511 @contentdepth <xsl:value-of select="@contentdepth"/>
512 $contentdepth <xsl:value-of select="$contentdepth"/>
513 scaled.contentdepth: <xsl:value-of select="$scaled.contentdepth"/>
514 @depth: <xsl:value-of select="@depth"/>
515 depth: <xsl:value-of select="$depth"/>
516 html.depth: <xsl:value-of select="$html.depth"/>
517 align: <xsl:value-of select="@align"/>
518 valign: <xsl:value-of select="@valign"/></xsl:message>
521 <xsl:variable name="scaled"
522 select="@width|@depth|@contentwidth|@contentdepth
525 <xsl:variable name="img">
527 <xsl:when test="@format = 'SVG'">
528 <object type="image/svg+xml">
529 <xsl:attribute name="data">
531 <xsl:when test="$img.src.path != '' and
533 not(starts-with($output_filename, '/')) and
534 not(contains($output_filename, '://'))">
535 <xsl:value-of select="$img.src.path"/>
538 <xsl:value-of select="$output_filename"/>
540 <xsl:call-template name="process.image.attributes">
541 <!--xsl:with-param name="alt" select="$alt"/ there's no alt here-->
542 <xsl:with-param name="html.depth" select="$html.depth"/>
543 <xsl:with-param name="html.width" select="$html.width"/>
544 <xsl:with-param name="longdesc" select="$longdesc"/>
545 <xsl:with-param name="scale" select="$scale"/>
546 <xsl:with-param name="scalefit" select="$scalefit"/>
547 <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
548 <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
549 <xsl:with-param name="viewport" select="$viewport"/>
551 <xsl:if test="@align">
552 <xsl:attribute name="align">
554 <xsl:when test="@align = 'center'">middle</xsl:when>
556 <xsl:value-of select="@align"/>
561 <xsl:if test="$use.embed.for.svg != 0">
562 <embed type="image/svg+xml">
563 <xsl:attribute name="src">
565 <xsl:when test="$img.src.path != '' and
567 not(starts-with($output_filename, '/')) and
568 not(contains($output_filename, '://'))">
569 <xsl:value-of select="$img.src.path"/>
572 <xsl:value-of select="$output_filename"/>
574 <xsl:call-template name="process.image.attributes">
575 <!--xsl:with-param name="alt" select="$alt"/ there's no alt here -->
576 <xsl:with-param name="html.depth" select="$html.depth"/>
577 <xsl:with-param name="html.width" select="$html.width"/>
578 <xsl:with-param name="longdesc" select="$longdesc"/>
579 <xsl:with-param name="scale" select="$scale"/>
580 <xsl:with-param name="scalefit" select="$scalefit"/>
581 <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
582 <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
583 <xsl:with-param name="viewport" select="$viewport"/>
590 <xsl:element name="{$tag}">
591 <xsl:if test="$tag = 'img' and ../../self::imageobjectco">
592 <xsl:variable name="mapname">
593 <xsl:call-template name="object.id">
594 <xsl:with-param name="object" select="../../areaspec"/>
598 <xsl:when test="$scaled">
599 <!-- It might be possible to handle some scaling; needs -->
600 <!-- more investigation -->
602 <xsl:text>Warning: imagemaps not supported </xsl:text>
603 <xsl:text>on scaled images</xsl:text>
607 <xsl:attribute name="border">0</xsl:attribute>
608 <xsl:attribute name="usemap">
609 <xsl:value-of select="concat('#', $mapname)"/>
615 <xsl:attribute name="src">
617 <xsl:when test="$img.src.path != '' and
619 not(starts-with($output_filename, '/')) and
620 not(contains($output_filename, '://'))">
621 <xsl:value-of select="$img.src.path"/>
624 <xsl:value-of select="$output_filename"/>
627 <xsl:if test="@align">
628 <xsl:attribute name="align">
630 <xsl:when test="@align = 'center'">middle</xsl:when>
632 <xsl:value-of select="@align"/>
638 <xsl:call-template name="process.image.attributes">
639 <xsl:with-param name="alt">
641 <xsl:when test="$alt != ''">
642 <xsl:copy-of select="$alt"/>
644 <xsl:when test="ancestor::figure">
645 <xsl:value-of select="normalize-space(ancestor::figure/title)"/>
649 <xsl:with-param name="html.depth" select="$html.depth"/>
650 <xsl:with-param name="html.width" select="$html.width"/>
651 <xsl:with-param name="longdesc" select="$longdesc"/>
652 <xsl:with-param name="scale" select="$scale"/>
653 <xsl:with-param name="scalefit" select="$scalefit"/>
654 <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
655 <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
656 <xsl:with-param name="viewport" select="$viewport"/>
663 <xsl:variable name="bgcolor">
664 <xsl:call-template name="pi.dbhtml_background-color">
665 <xsl:with-param name="node" select=".."/>
669 <xsl:variable name="use.viewport"
670 select="$viewport != 0
671 and ($html.width != ''
672 or ($html.depth != '' and $depth-units != '%')
677 <xsl:when test="$use.viewport">
678 <table border="0" summary="manufactured viewport for HTML img"
679 cellspacing="0" cellpadding="0">
680 <xsl:if test="$html.width != ''">
681 <xsl:attribute name="width">
682 <xsl:value-of select="$html.width"/>
686 <xsl:if test="$html.depth != '' and $depth-units != '%'">
687 <!-- don't do this for percentages because browsers get confused -->
689 <xsl:when test="$css.decoration != 0">
690 <xsl:attribute name="style">
691 <xsl:text>height: </xsl:text>
692 <xsl:value-of select="$html.depth"/>
693 <xsl:text>px</xsl:text>
697 <xsl:attribute name="height">
698 <xsl:value-of select="$html.depth"/>
704 <xsl:if test="$bgcolor != ''">
706 <xsl:when test="$css.decoration != 0">
707 <xsl:attribute name="style">
708 <xsl:text>background-color: </xsl:text>
709 <xsl:value-of select="$bgcolor"/>
713 <xsl:attribute name="bgcolor">
714 <xsl:value-of select="$bgcolor"/>
719 <xsl:if test="@align">
720 <xsl:attribute name="align">
721 <xsl:value-of select="@align"/>
724 <xsl:if test="@valign">
725 <xsl:attribute name="valign">
726 <xsl:value-of select="@valign"/>
729 <xsl:copy-of select="$img"/>
735 <xsl:copy-of select="$img"/>
739 <xsl:if test="$tag = 'img' and ../../self::imageobjectco and not($scaled)">
740 <xsl:variable name="mapname">
741 <xsl:call-template name="object.id">
742 <xsl:with-param name="object" select="../../areaspec"/>
746 <map name="{$mapname}">
747 <xsl:for-each select="../../areaspec//area">
748 <xsl:variable name="units">
750 <xsl:when test="@units = 'other' and @otherunits">
751 <xsl:value-of select="@otherunits"/>
753 <xsl:when test="@units">
754 <xsl:value-of select="@units"/>
756 <!-- areaspec|areaset/area -->
757 <xsl:when test="../@units = 'other' and ../@otherunits">
758 <xsl:value-of select="../@otherunits"/>
760 <xsl:when test="../@units">
761 <xsl:value-of select="../@units"/>
763 <!-- areaspec/areaset/area -->
764 <xsl:when test="../../@units = 'other' and ../../@otherunits">
765 <xsl:value-of select="../@otherunits"/>
767 <xsl:when test="../../@units">
768 <xsl:value-of select="../../@units"/>
770 <xsl:otherwise>calspair</xsl:otherwise>
775 <xsl:when test="$units = 'calspair' or
776 $units = 'imagemap'">
777 <xsl:variable name="coords" select="normalize-space(@coords)"/>
780 <xsl:variable name="linkends">
782 <xsl:when test="@linkends">
783 <xsl:value-of select="normalize-space(@linkends)"/>
786 <xsl:value-of select="normalize-space(../@linkends)"/>
791 <xsl:variable name="href">
793 <xsl:when test="@xlink:href">
794 <xsl:value-of select="@xlink:href"/>
797 <xsl:value-of select="../@xlink:href"/>
803 <xsl:when test="$linkends != ''">
804 <xsl:variable name="linkend">
806 <xsl:when test="contains($linkends, ' ')">
807 <xsl:value-of select="substring-before($linkends, ' ')"/>
810 <xsl:value-of select="$linkends"/>
815 <xsl:variable name="target" select="key('id', $linkend)[1]"/>
817 <xsl:if test="$target">
818 <xsl:attribute name="href">
819 <xsl:call-template name="href.target">
820 <xsl:with-param name="object" select="$target"/>
825 <xsl:when test="$href != ''">
826 <xsl:attribute name="href">
827 <xsl:value-of select="$href"/>
833 <xsl:attribute name="alt">
834 <xsl:value-of select="alt[1]"/>
838 <xsl:attribute name="coords">
840 <xsl:when test="$units = 'calspair'">
842 <xsl:variable name="p1"
843 select="substring-before($coords, ' ')"/>
844 <xsl:variable name="p2"
845 select="substring-after($coords, ' ')"/>
847 <xsl:variable name="x1" select="substring-before($p1,',')"/>
848 <xsl:variable name="y1" select="substring-after($p1,',')"/>
849 <xsl:variable name="x2" select="substring-before($p2,',')"/>
850 <xsl:variable name="y2" select="substring-after($p2,',')"/>
852 <xsl:variable name="x1p" select="$x1 div 100.0"/>
853 <xsl:variable name="y1p" select="$y1 div 100.0"/>
854 <xsl:variable name="x2p" select="$x2 div 100.0"/>
855 <xsl:variable name="y2p" select="$y2 div 100.0"/>
859 <xsl:text>units: </xsl:text>
860 <xsl:value-of select="$units"/>
861 <xsl:text> </xsl:text>
862 <xsl:value-of select="$x1p"/><xsl:text>, </xsl:text>
863 <xsl:value-of select="$y1p"/><xsl:text>, </xsl:text>
864 <xsl:value-of select="$x2p"/><xsl:text>, </xsl:text>
865 <xsl:value-of select="$y2p"/><xsl:text>, </xsl:text>
869 <xsl:text> </xsl:text>
870 <xsl:value-of select="$intrinsicwidth"/>
871 <xsl:text>, </xsl:text>
872 <xsl:value-of select="$intrinsicdepth"/>
876 <xsl:text> </xsl:text>
877 <xsl:value-of select="$units"/>
878 <xsl:text> </xsl:text>
880 select="round($x1p * $intrinsicwidth div 100.0)"/>
881 <xsl:text>,</xsl:text>
882 <xsl:value-of select="round($intrinsicdepth
883 - ($y2p * $intrinsicdepth div 100.0))"/>
884 <xsl:text>,</xsl:text>
885 <xsl:value-of select="round($x2p *
886 $intrinsicwidth div 100.0)"/>
887 <xsl:text>,</xsl:text>
888 <xsl:value-of select="round($intrinsicdepth
889 - ($y1p * $intrinsicdepth div 100.0))"/>
893 select="round($x1p * $intrinsicwidth div 100.0)"/>
894 <xsl:text>,</xsl:text>
895 <xsl:value-of select="round($intrinsicdepth
896 - ($y2p * $intrinsicdepth div 100.0))"/>
897 <xsl:text>,</xsl:text>
899 select="round($x2p * $intrinsicwidth div 100.0)"/>
900 <xsl:text>,</xsl:text>
901 <xsl:value-of select="round($intrinsicdepth
902 - ($y1p * $intrinsicdepth div 100.0))"/>
905 <xsl:copy-of select="$coords"/>
913 <xsl:text>Warning: only calspair or </xsl:text>
914 <xsl:text>otherunits='imagemap' supported </xsl:text>
915 <xsl:text>in imageobjectco</xsl:text>
924 <xsl:template name="process.image.attributes">
925 <xsl:param name="alt"/>
926 <xsl:param name="html.width"/>
927 <xsl:param name="html.depth"/>
928 <xsl:param name="longdesc"/>
929 <xsl:param name="scale"/>
930 <xsl:param name="scalefit"/>
931 <xsl:param name="scaled.contentdepth"/>
932 <xsl:param name="scaled.contentwidth"/>
933 <xsl:param name="viewport"/>
936 <xsl:when test="@contentwidth or @contentdepth">
937 <!-- ignore @width/@depth, @scale, and @scalefit if specified -->
938 <xsl:if test="@contentwidth and $scaled.contentwidth != ''">
939 <xsl:attribute name="width">
940 <xsl:value-of select="$scaled.contentwidth"/>
943 <xsl:if test="@contentdepth and $scaled.contentdepth != ''">
944 <xsl:attribute name="height">
945 <xsl:value-of select="$scaled.contentdepth"/>
950 <xsl:when test="number($scale) != 1.0">
951 <!-- scaling is always uniform, so we only have to specify one dimension -->
952 <!-- ignore @scalefit if specified -->
953 <xsl:attribute name="width">
954 <xsl:value-of select="$scaled.contentwidth"/>
958 <xsl:when test="$scalefit != 0">
960 <xsl:when test="contains($html.width, '%')">
962 <xsl:when test="$viewport != 0">
963 <!-- The *viewport* will be scaled, so use 100% here! -->
964 <xsl:attribute name="width">
965 <xsl:value-of select="'100%'"/>
969 <xsl:attribute name="width">
970 <xsl:value-of select="$html.width"/>
976 <xsl:when test="contains($html.depth, '%')">
977 <!-- HTML doesn't deal with this case very well...do nothing -->
980 <xsl:when test="$scaled.contentwidth != '' and $html.width != ''
981 and $scaled.contentdepth != '' and $html.depth != ''">
982 <!-- scalefit should not be anamorphic; figure out which direction -->
983 <!-- has the limiting scale factor and scale in that direction -->
985 <xsl:when test="$html.width div $scaled.contentwidth >
986 $html.depth div $scaled.contentdepth">
987 <xsl:attribute name="height">
988 <xsl:value-of select="$html.depth"/>
992 <xsl:attribute name="width">
993 <xsl:value-of select="$html.width"/>
999 <xsl:when test="$scaled.contentwidth != '' and $html.width != ''">
1000 <xsl:attribute name="width">
1001 <xsl:value-of select="$html.width"/>
1005 <xsl:when test="$scaled.contentdepth != '' and $html.depth != ''">
1006 <xsl:attribute name="height">
1007 <xsl:value-of select="$html.depth"/>
1014 <xsl:if test="$alt != ''">
1015 <xsl:attribute name="alt">
1016 <xsl:value-of select="normalize-space($alt)"/>
1020 <xsl:if test="$longdesc != ''">
1021 <xsl:attribute name="longdesc">
1022 <xsl:value-of select="$longdesc"/>
1026 <xsl:if test="@align and $viewport = 0">
1027 <xsl:attribute name="align">
1029 <xsl:when test="@align = 'center'">middle</xsl:when>
1031 <xsl:value-of select="@align"/>
1038 <!-- ==================================================================== -->
1040 <xsl:template match="graphic">
1042 <xsl:when test="parent::inlineequation">
1043 <xsl:call-template name="anchor"/>
1044 <xsl:call-template name="process.image"/>
1048 <xsl:if test="@align">
1049 <xsl:attribute name="align">
1050 <xsl:value-of select="@align"/>
1053 <xsl:call-template name="anchor"/>
1054 <xsl:call-template name="process.image"/>
1060 <xsl:template match="inlinegraphic">
1061 <xsl:variable name="filename">
1063 <xsl:when test="@entityref">
1064 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1067 <xsl:apply-templates select="@fileref"/>
1072 <xsl:call-template name="anchor"/>
1075 <xsl:when test="@format='linespecific'">
1077 <xsl:when test="$use.extensions != '0'
1078 and $textinsert.extension != '0'">
1080 <xsl:when test="element-available('stext:insertfile')">
1081 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
1083 <xsl:when test="element-available('xtext:insertfile')">
1084 <xtext:insertfile href="{$filename}"/>
1087 <xsl:message terminate="yes">
1088 <xsl:text>No insertfile extension available.</xsl:text>
1094 <xsl:message terminate="yes">
1095 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
1096 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
1102 <xsl:call-template name="process.image"/>
1107 <!-- ==================================================================== -->
1109 <xsl:template match="mediaobject|mediaobjectco">
1111 <xsl:variable name="olist" select="imageobject|imageobjectco
1112 |videoobject|audioobject
1115 <xsl:variable name="object.index">
1116 <xsl:call-template name="select.mediaobject.index">
1117 <xsl:with-param name="olist" select="$olist"/>
1118 <xsl:with-param name="count" select="1"/>
1119 </xsl:call-template>
1122 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
1124 <xsl:variable name="align">
1125 <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
1129 <xsl:apply-templates select="." mode="common.html.attributes"/>
1130 <xsl:if test="$align != '' ">
1131 <xsl:attribute name="align">
1132 <xsl:value-of select="$align"/>
1135 <xsl:call-template name="anchor"/>
1137 <xsl:apply-templates select="$object"/>
1138 <xsl:apply-templates select="caption"/>
1142 <xsl:template match="inlinemediaobject">
1144 <xsl:apply-templates select="." mode="common.html.attributes"/>
1145 <xsl:call-template name="anchor"/>
1146 <xsl:call-template name="select.mediaobject"/>
1150 <xsl:template match="programlisting/inlinemediaobject
1151 |screen/inlinemediaobject" priority="2">
1152 <!-- the additional span causes problems in some cases -->
1153 <xsl:call-template name="select.mediaobject"/>
1156 <!-- ==================================================================== -->
1158 <xsl:template match="imageobjectco">
1159 <xsl:call-template name="anchor"/>
1160 <xsl:apply-templates select="imageobject"/>
1161 <xsl:apply-templates select="calloutlist"/>
1164 <xsl:template match="imageobject">
1165 <xsl:apply-templates select="imagedata"/>
1168 <xsl:template match="imagedata">
1169 <xsl:variable name="filename">
1170 <xsl:call-template name="mediaobject.filename">
1171 <xsl:with-param name="object" select=".."/>
1172 </xsl:call-template>
1176 <!-- Handle MathML and SVG markup in imagedata -->
1177 <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
1178 <xsl:apply-templates/>
1181 <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
1182 <xsl:apply-templates/>
1185 <xsl:when test="@format='linespecific'">
1187 <xsl:when test="$use.extensions != '0'
1188 and $textinsert.extension != '0'">
1190 <xsl:when test="element-available('stext:insertfile')">
1191 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
1193 <xsl:when test="element-available('xtext:insertfile')">
1194 <xtext:insertfile href="{$filename}"/>
1197 <xsl:message terminate="yes">
1198 <xsl:text>No insertfile extension available.</xsl:text>
1204 <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"
1205 href="{$filename}"/>
1210 <xsl:variable name="longdesc.uri">
1211 <xsl:call-template name="longdesc.uri">
1212 <xsl:with-param name="mediaobject"
1213 select="ancestor::imageobject/parent::*"/>
1214 </xsl:call-template>
1217 <xsl:variable name="phrases"
1218 select="ancestor::mediaobject/textobject[phrase]
1219 |ancestor::inlinemediaobject/textobject[phrase]
1220 |ancestor::mediaobjectco/textobject[phrase]"/>
1222 <xsl:call-template name="process.image">
1223 <xsl:with-param name="alt">
1224 <xsl:apply-templates select="$phrases[not(@role) or @role!='tex'][1]"/>
1226 <xsl:with-param name="longdesc">
1227 <xsl:call-template name="write.longdesc">
1228 <xsl:with-param name="mediaobject"
1229 select="ancestor::imageobject/parent::*"/>
1230 </xsl:call-template>
1232 </xsl:call-template>
1234 <xsl:if test="$html.longdesc != 0 and $html.longdesc.link != 0
1235 and ancestor::imageobject/parent::*/textobject[not(phrase)]">
1236 <xsl:call-template name="longdesc.link">
1237 <xsl:with-param name="longdesc.uri" select="$longdesc.uri"/>
1238 </xsl:call-template>
1244 <!-- ==================================================================== -->
1246 <xsl:template name="longdesc.uri">
1247 <xsl:param name="mediaobject" select="."/>
1248 <xsl:if test="$html.longdesc">
1249 <xsl:if test="$mediaobject/textobject[not(phrase)]">
1250 <xsl:variable name="dbhtml.dir">
1251 <xsl:call-template name="dbhtml-dir"/>
1253 <xsl:variable name="filename">
1254 <xsl:call-template name="make-relative-filename">
1255 <xsl:with-param name="base.dir">
1257 <xsl:when test="$dbhtml.dir != ''">
1258 <xsl:value-of select="$dbhtml.dir"/>
1261 <xsl:value-of select="$base.dir"/>
1265 <xsl:with-param name="base.name">
1268 $mediaobject/@*[local-name() = 'id']
1269 and not($use.id.as.filename = 0)">
1270 <!-- * if this mediaobject has an ID, then we use the -->
1271 <!-- * value of that ID as basename for the "longdesc" -->
1272 <!-- * file (that is, without prepending an "ld-" too it) -->
1273 <xsl:value-of select="$mediaobject/@*[local-name() = 'id']"/>
1274 <xsl:value-of select="$html.ext"/>
1277 <!-- * otherwise, if this mediaobject does not have an -->
1278 <!-- * ID, then we generate an ID... -->
1279 <xsl:variable name="image-id">
1280 <xsl:call-template name="object.id">
1281 <xsl:with-param name="object" select="$mediaobject"/>
1282 </xsl:call-template>
1284 <!-- * ...and then we take that generated ID, prepend an -->
1285 <!-- * "ld-" to it, and use that as the basename for the file -->
1286 <xsl:value-of select="concat('ld-',$image-id,$html.ext)"/>
1290 </xsl:call-template>
1293 <xsl:value-of select="$filename"/>
1298 <xsl:template name="write.longdesc">
1299 <xsl:param name="mediaobject" select="."/>
1300 <xsl:if test="$html.longdesc != 0 and $mediaobject/textobject[not(phrase)]">
1301 <xsl:variable name="filename">
1302 <xsl:call-template name="longdesc.uri">
1303 <xsl:with-param name="mediaobject" select="$mediaobject"/>
1304 </xsl:call-template>
1307 <xsl:value-of select="$filename"/>
1309 <xsl:call-template name="write.chunk">
1310 <xsl:with-param name="filename" select="$filename"/>
1311 <xsl:with-param name="quiet" select="$chunk.quietly"/>
1312 <xsl:with-param name="content">
1313 <xsl:call-template name="user.preroot"/>
1316 <xsl:call-template name="system.head.content"/>
1317 <xsl:call-template name="head.content">
1318 <xsl:with-param name="title" select="'Long Description'"/>
1319 </xsl:call-template>
1320 <xsl:call-template name="user.head.content"/>
1323 <xsl:call-template name="body.attributes"/>
1324 <xsl:for-each select="$mediaobject/textobject[not(phrase)]">
1325 <xsl:apply-templates select="./*"/>
1329 <xsl:value-of select="$chunk.append"/>
1331 </xsl:call-template>
1335 <xsl:template name="longdesc.link">
1336 <xsl:param name="longdesc.uri" select="''"/>
1338 <xsl:variable name="this.uri">
1339 <xsl:call-template name="make-relative-filename">
1340 <xsl:with-param name="base.dir" select="$base.dir"/>
1341 <xsl:with-param name="base.name">
1342 <xsl:call-template name="href.target.uri"/>
1344 </xsl:call-template>
1347 <xsl:variable name="href.to">
1348 <xsl:call-template name="trim.common.uri.paths">
1349 <xsl:with-param name="uriA" select="$longdesc.uri"/>
1350 <xsl:with-param name="uriB" select="$this.uri"/>
1351 <xsl:with-param name="return" select="'A'"/>
1352 </xsl:call-template>
1355 <div class="longdesc-link" align="{$direction.align.end}">
1357 <span class="longdesc-link">
1358 <xsl:text>[</xsl:text>
1359 <a href="{$href.to}" target="longdesc">D</a>
1360 <xsl:text>]</xsl:text>
1365 <!-- ==================================================================== -->
1367 <xsl:template match="videoobject">
1368 <xsl:apply-templates select="videodata"/>
1371 <xsl:template match="videodata">
1372 <xsl:call-template name="process.image">
1373 <xsl:with-param name="tag" select="'embed'"/>
1374 <xsl:with-param name="alt">
1375 <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
1377 </xsl:call-template>
1380 <!-- ==================================================================== -->
1382 <xsl:template match="audioobject">
1383 <xsl:apply-templates select="audiodata"/>
1386 <xsl:template match="audiodata">
1387 <xsl:call-template name="process.image">
1388 <xsl:with-param name="tag" select="'embed'"/>
1389 <xsl:with-param name="alt">
1390 <xsl:apply-templates select="(../../textobject/phrase)[1]"/>
1392 </xsl:call-template>
1395 <!-- ==================================================================== -->
1397 <xsl:template match="textobject">
1398 <xsl:apply-templates/>
1401 <xsl:template match="textdata">
1402 <xsl:variable name="filename">
1404 <xsl:when test="@entityref">
1405 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1408 <xsl:apply-templates select="@fileref"/>
1413 <xsl:variable name="encoding">
1415 <xsl:when test="@encoding">
1416 <xsl:value-of select="@encoding"/>
1419 <xsl:value-of select="$textdata.default.encoding"/>
1425 <xsl:when test="$use.extensions != '0'
1426 and $textinsert.extension != '0'">
1428 <xsl:when test="element-available('stext:insertfile')">
1429 <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
1431 <xsl:when test="element-available('xtext:insertfile')">
1432 <xtext:insertfile href="{$filename}"/>
1435 <xsl:message terminate="yes">
1436 <xsl:text>No insertfile extension available.</xsl:text>
1442 <xsl:message terminate="yes">
1443 <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
1444 <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
1450 <!-- ==================================================================== -->
1452 <xsl:template match="caption">
1454 <xsl:apply-templates select="." mode="common.html.attributes"/>
1455 <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
1456 <xsl:attribute name="align"><xsl:value-of
1457 select="@align"/></xsl:attribute>
1459 <xsl:apply-templates/>
1463 <!-- ==================================================================== -->
1464 <!-- "Support" for SVG -->
1466 <xsl:template match="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
1468 <xsl:copy-of select="@*"/>
1469 <xsl:apply-templates/>
1474 <!-- The following works sometimes, but needs to take into account
1475 1. When there is no /*/@xml:base
1476 2. When the chunks are going somewhere else
1477 <xsl:variable name="relpath">
1478 <xsl:call-template name="relative-uri">
1479 <xsl:with-param name="filename" select="@fileref"/>
1480 </xsl:call-template>
1484 <xsl:when test="/*/@xml:base
1485 and starts-with($relpath,/*/@xml:base)">
1486 <xsl:value-of select="substring-after($relpath,/*/@xml:base)"/>
1489 <xsl:value-of select="@fileref"/>
1492 <xsl:value-of select="@fileref"/>
1495 <!-- Resolve xml:base attributes -->
1496 <xsl:template match="@fileref">
1497 <!-- need a check for absolute urls -->
1499 <xsl:when test="contains(., ':')">
1500 <!-- it has a uri scheme so it is an absolute uri -->
1501 <xsl:value-of select="."/>
1503 <xsl:when test="$keep.relative.image.uris != 0">
1504 <!-- leave it alone -->
1505 <xsl:value-of select="."/>
1508 <!-- its a relative uri that needs xml:base processing -->
1509 <xsl:call-template name="relative-uri">
1510 </xsl:call-template>