graphics.xsl 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  1. <?xml version="1.0" encoding="ASCII"?><!--This file was created automatically by html2xhtml--><!--from the HTML stylesheets.--><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory" xmlns:simg="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.ImageIntrinsics" xmlns:ximg="xalan://com.nwalsh.xalan.ImageIntrinsics" xmlns:xtext="xalan://com.nwalsh.xalan.Text" xmlns:lxslt="http://xml.apache.org/xslt" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xlink stext xtext lxslt simg ximg" extension-element-prefixes="stext xtext" version="1.0">
  2. <!-- ********************************************************************
  3. $Id: graphics.xsl 9710 2013-01-22 19:34:18Z bobstayton $
  4. ********************************************************************
  5. This file is part of the XSL DocBook Stylesheet distribution.
  6. See ../README or http://docbook.sf.net/release/xsl/current/ for
  7. copyright and other information.
  8. Contributors:
  9. Colin Paul Adams, <colin@colina.demon.co.uk>
  10. ******************************************************************** -->
  11. <lxslt:component prefix="xtext" elements="insertfile"/>
  12. <lxslt:component prefix="ximg" functions="new getWidth getDepth"/>
  13. <!-- ==================================================================== -->
  14. <!-- Graphic format tests for the HTML backend -->
  15. <xsl:template name="is.graphic.format">
  16. <xsl:param name="format"/>
  17. <xsl:if test="$format = 'SVG' or $format = 'PNG' or $format = 'JPG' or $format = 'JPEG' or $format = 'linespecific' or $format = 'GIF' or $format = 'GIF87a' or $format = 'GIF89a' or $format = 'BMP'">1</xsl:if>
  18. </xsl:template>
  19. <xsl:template name="is.graphic.extension">
  20. <xsl:param name="ext"/>
  21. <xsl:variable name="lcext" select="translate($ext, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
  22. <xsl:if test="$lcext = 'svg' or $lcext = 'png' or $lcext = 'jpeg' or $lcext = 'jpg' or $lcext = 'avi' or $lcext = 'mpg' or $lcext = 'mp4' or $lcext = 'mpeg' or $lcext = 'qt' or $lcext = 'gif' or $lcext = 'acc' or $lcext = 'mp1' or $lcext = 'mp2' or $lcext = 'mp3' or $lcext = 'mp4' or $lcext = 'm4v' or $lcext = 'm4a' or $lcext = 'wav' or $lcext = 'ogv' or $lcext = 'ogg' or $lcext = 'webm' or $lcext = 'bmp'">1</xsl:if>
  23. </xsl:template>
  24. <!-- ==================================================================== -->
  25. <xsl:template match="screenshot">
  26. <div>
  27. <xsl:apply-templates select="." mode="common.html.attributes"/>
  28. <xsl:call-template name="id.attribute"/>
  29. <xsl:call-template name="anchor"/>
  30. <xsl:apply-templates/>
  31. </div>
  32. </xsl:template>
  33. <xsl:template match="screenshot/title">
  34. <xsl:call-template name="formal.object.heading">
  35. <xsl:with-param name="object" select=".."/>
  36. </xsl:call-template>
  37. </xsl:template>
  38. <xsl:template match="screeninfo">
  39. </xsl:template>
  40. <!-- ==================================================================== -->
  41. <xsl:template name="process.image">
  42. <!-- When this template is called, the current node should be -->
  43. <!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
  44. <!-- those elements have the same set of attributes, so we can -->
  45. <!-- handle them all in one place. -->
  46. <xsl:param name="tag" select="'img'"/>
  47. <xsl:param name="alt"/>
  48. <xsl:param name="longdesc"/>
  49. <!-- The HTML img element only supports the notion of content-area
  50. scaling; it doesn't support the distinction between a
  51. content-area and a viewport-area, so we have to make some
  52. compromises.
  53. 1. If only the content-area is specified, everything is fine.
  54. (If you ask for a three inch image, that's what you'll get.)
  55. 2. If only the viewport-area is provided:
  56. - If scalefit=1, treat it as both the content-area and
  57. the viewport-area. (If you ask for an image in a five inch
  58. area, we'll make the image five inches to fill that area.)
  59. - If scalefit=0, ignore the viewport-area specification.
  60. Note: this is not quite the right semantic and has the additional
  61. problem that it can result in anamorphic scaling, which scalefit
  62. should never cause.
  63. 3. If both the content-area and the viewport-area is specified
  64. on a graphic element, ignore the viewport-area.
  65. (If you ask for a three inch image in a five inch area, we'll assume
  66. it's better to give you a three inch image in an unspecified area
  67. than a five inch image in a five inch area.
  68. Relative units also cause problems. As a general rule, the stylesheets
  69. are operating too early and too loosely coupled with the rendering engine
  70. to know things like the current font size or the actual dimensions of
  71. an image. Therefore:
  72. 1. We use a fixed size for pixels, $pixels.per.inch
  73. 2. We use a fixed size for "em"s, $points.per.em
  74. Percentages are problematic. In the following discussion, we speak
  75. of width and contentwidth, but the same issues apply to depth and
  76. contentdepth
  77. 1. A width of 50% means "half of the available space for the image."
  78. That's fine. But note that in HTML, this is a dynamic property and
  79. the image size will vary if the browser window is resized.
  80. 2. A contentwidth of 50% means "half of the actual image width". But
  81. the stylesheets have no way to assess the image's actual size. Treating
  82. this as a width of 50% is one possibility, but it produces behavior
  83. (dynamic scaling) that seems entirely out of character with the
  84. meaning.
  85. Instead, the stylesheets define a $nominal.image.width
  86. and convert percentages to actual values based on that nominal size.
  87. Scale can be problematic. Scale applies to the contentwidth, so
  88. a scale of 50 when a contentwidth is not specified is analagous to a
  89. width of 50%. (If a contentwidth is specified, the scaling factor can
  90. be applied to that value and no problem exists.)
  91. If scale is specified but contentwidth is not supplied, the
  92. nominal.image.width is used to calculate a base size
  93. for scaling.
  94. Warning: as a consequence of these decisions, unless the aspect ratio
  95. of your image happens to be exactly the same as (nominal width / nominal height),
  96. specifying contentwidth="50%" and contentdepth="50%" is NOT going to
  97. scale the way you expect (or really, the way it should).
  98. Don't do that. In fact, a percentage value is not recommended for content
  99. size at all. Use scale instead.
  100. Finally, align and valign are troublesome. Horizontal alignment is now
  101. supported by wrapping the image in a <div align="{@align}"> (in block
  102. contexts!). I can't think of anything (practical) to do about vertical
  103. alignment.
  104. -->
  105. <xsl:variable name="width-units">
  106. <xsl:choose>
  107. <xsl:when test="$ignore.image.scaling != 0"/>
  108. <xsl:when test="@width">
  109. <xsl:call-template name="length-units">
  110. <xsl:with-param name="length" select="@width"/>
  111. </xsl:call-template>
  112. </xsl:when>
  113. <xsl:when test="not(@depth) and $default.image.width != ''">
  114. <xsl:call-template name="length-units">
  115. <xsl:with-param name="length" select="$default.image.width"/>
  116. </xsl:call-template>
  117. </xsl:when>
  118. </xsl:choose>
  119. </xsl:variable>
  120. <xsl:variable name="width">
  121. <xsl:choose>
  122. <xsl:when test="$ignore.image.scaling != 0"/>
  123. <xsl:when test="@width">
  124. <xsl:choose>
  125. <xsl:when test="$width-units = '%'">
  126. <xsl:value-of select="@width"/>
  127. </xsl:when>
  128. <xsl:otherwise>
  129. <xsl:call-template name="length-spec">
  130. <xsl:with-param name="length" select="@width"/>
  131. </xsl:call-template>
  132. </xsl:otherwise>
  133. </xsl:choose>
  134. </xsl:when>
  135. <xsl:when test="not(@depth) and $default.image.width != ''">
  136. <xsl:value-of select="$default.image.width"/>
  137. </xsl:when>
  138. </xsl:choose>
  139. </xsl:variable>
  140. <xsl:variable name="scalefit">
  141. <xsl:choose>
  142. <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
  143. <xsl:when test="@contentwidth or @contentdepth">0</xsl:when>
  144. <xsl:when test="@scale">0</xsl:when>
  145. <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
  146. <xsl:when test="$width != '' or @depth">1</xsl:when>
  147. <xsl:otherwise>0</xsl:otherwise>
  148. </xsl:choose>
  149. </xsl:variable>
  150. <xsl:variable name="scale">
  151. <xsl:choose>
  152. <xsl:when test="$ignore.image.scaling != 0">1.0</xsl:when>
  153. <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
  154. <xsl:when test="@scale">
  155. <xsl:value-of select="@scale div 100.0"/>
  156. </xsl:when>
  157. <xsl:otherwise>1.0</xsl:otherwise>
  158. </xsl:choose>
  159. </xsl:variable>
  160. <xsl:variable name="filename">
  161. <xsl:choose>
  162. <xsl:when test="local-name(.) = 'graphic' or local-name(.) = 'inlinegraphic'">
  163. <!-- handle legacy graphic and inlinegraphic by new template -->
  164. <xsl:call-template name="mediaobject.filename">
  165. <xsl:with-param name="object" select="."/>
  166. </xsl:call-template>
  167. </xsl:when>
  168. <xsl:otherwise>
  169. <!-- imagedata, videodata, audiodata -->
  170. <xsl:call-template name="mediaobject.filename">
  171. <xsl:with-param name="object" select=".."/>
  172. </xsl:call-template>
  173. </xsl:otherwise>
  174. </xsl:choose>
  175. </xsl:variable>
  176. <xsl:variable name="output_filename">
  177. <xsl:choose>
  178. <xsl:when test="@entityref">
  179. <xsl:value-of select="$filename"/>
  180. </xsl:when>
  181. <!--
  182. Moved test for $keep.relative.image.uris to template below:
  183. <xsl:template match="@fileref">
  184. -->
  185. <xsl:otherwise>
  186. <xsl:value-of select="$filename"/>
  187. </xsl:otherwise>
  188. </xsl:choose>
  189. </xsl:variable>
  190. <xsl:variable name="img.src.path.pi">
  191. <xsl:call-template name="pi.dbhtml_img.src.path">
  192. <xsl:with-param name="node" select=".."/>
  193. </xsl:call-template>
  194. </xsl:variable>
  195. <xsl:variable name="filename.for.graphicsize">
  196. <xsl:choose>
  197. <xsl:when test="$img.src.path.pi != ''">
  198. <xsl:value-of select="concat($img.src.path.pi, $filename)"/>
  199. </xsl:when>
  200. <xsl:when test="$img.src.path != '' and $graphicsize.use.img.src.path != 0 and $tag = 'img' and not(starts-with($filename, '/')) and not(contains($filename, '://'))">
  201. <xsl:value-of select="concat($img.src.path, $filename)"/>
  202. </xsl:when>
  203. <xsl:otherwise>
  204. <xsl:value-of select="$filename"/>
  205. </xsl:otherwise>
  206. </xsl:choose>
  207. </xsl:variable>
  208. <xsl:variable name="realintrinsicwidth">
  209. <!-- This funny compound test works around a bug in XSLTC -->
  210. <xsl:choose>
  211. <xsl:when test="$use.extensions != 0 and $graphicsize.extension != 0 and not(@format='SVG')">
  212. <xsl:choose>
  213. <xsl:when test="function-available('simg:getWidth')">
  214. <xsl:value-of select="simg:getWidth(simg:new($filename.for.graphicsize), $nominal.image.width)"/>
  215. </xsl:when>
  216. <xsl:when test="function-available('ximg:getWidth')">
  217. <xsl:value-of select="ximg:getWidth(ximg:new($filename.for.graphicsize), $nominal.image.width)"/>
  218. </xsl:when>
  219. <xsl:otherwise>
  220. <xsl:value-of select="0"/>
  221. </xsl:otherwise>
  222. </xsl:choose>
  223. </xsl:when>
  224. <xsl:otherwise>
  225. <xsl:value-of select="0"/>
  226. </xsl:otherwise>
  227. </xsl:choose>
  228. </xsl:variable>
  229. <xsl:variable name="intrinsicwidth">
  230. <xsl:choose>
  231. <xsl:when test="$realintrinsicwidth = 0">
  232. <xsl:value-of select="$nominal.image.width"/>
  233. </xsl:when>
  234. <xsl:otherwise>
  235. <xsl:value-of select="$realintrinsicwidth"/>
  236. </xsl:otherwise>
  237. </xsl:choose>
  238. </xsl:variable>
  239. <xsl:variable name="intrinsicdepth">
  240. <!-- This funny compound test works around a bug in XSLTC -->
  241. <xsl:choose>
  242. <xsl:when test="$use.extensions != 0 and $graphicsize.extension != 0 and not(@format='SVG')">
  243. <xsl:choose>
  244. <xsl:when test="function-available('simg:getDepth')">
  245. <xsl:value-of select="simg:getDepth(simg:new($filename.for.graphicsize), $nominal.image.depth)"/>
  246. </xsl:when>
  247. <xsl:when test="function-available('ximg:getDepth')">
  248. <xsl:value-of select="ximg:getDepth(ximg:new($filename.for.graphicsize), $nominal.image.depth)"/>
  249. </xsl:when>
  250. <xsl:otherwise>
  251. <xsl:value-of select="$nominal.image.depth"/>
  252. </xsl:otherwise>
  253. </xsl:choose>
  254. </xsl:when>
  255. <xsl:otherwise>
  256. <xsl:value-of select="$nominal.image.depth"/>
  257. </xsl:otherwise>
  258. </xsl:choose>
  259. </xsl:variable>
  260. <xsl:variable name="contentwidth">
  261. <xsl:choose>
  262. <xsl:when test="$ignore.image.scaling != 0"/>
  263. <xsl:when test="@contentwidth">
  264. <xsl:variable name="units">
  265. <xsl:call-template name="length-units">
  266. <xsl:with-param name="length" select="@contentwidth"/>
  267. </xsl:call-template>
  268. </xsl:variable>
  269. <xsl:choose>
  270. <xsl:when test="$units = '%'">
  271. <xsl:variable name="cmagnitude">
  272. <xsl:call-template name="length-magnitude">
  273. <xsl:with-param name="length" select="@contentwidth"/>
  274. </xsl:call-template>
  275. </xsl:variable>
  276. <xsl:value-of select="$intrinsicwidth * $cmagnitude div 100.0"/>
  277. <xsl:text>px</xsl:text>
  278. </xsl:when>
  279. <xsl:otherwise>
  280. <xsl:call-template name="length-spec">
  281. <xsl:with-param name="length" select="@contentwidth"/>
  282. </xsl:call-template>
  283. </xsl:otherwise>
  284. </xsl:choose>
  285. </xsl:when>
  286. <xsl:otherwise>
  287. <xsl:value-of select="$intrinsicwidth"/>
  288. <xsl:text>px</xsl:text>
  289. </xsl:otherwise>
  290. </xsl:choose>
  291. </xsl:variable>
  292. <xsl:variable name="scaled.contentwidth">
  293. <xsl:if test="$contentwidth != ''">
  294. <xsl:variable name="cwidth.in.points">
  295. <xsl:call-template name="length-in-points">
  296. <xsl:with-param name="length" select="$contentwidth"/>
  297. <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
  298. <xsl:with-param name="em.size" select="$points.per.em"/>
  299. </xsl:call-template>
  300. </xsl:variable>
  301. <xsl:value-of select="round($cwidth.in.points div 72.0 * $pixels.per.inch * $scale)"/>
  302. </xsl:if>
  303. </xsl:variable>
  304. <xsl:variable name="html.width">
  305. <xsl:choose>
  306. <xsl:when test="$ignore.image.scaling != 0"/>
  307. <xsl:when test="$width-units = '%'">
  308. <xsl:value-of select="$width"/>
  309. </xsl:when>
  310. <xsl:when test="$width != ''">
  311. <xsl:variable name="width.in.points">
  312. <xsl:call-template name="length-in-points">
  313. <xsl:with-param name="length" select="$width"/>
  314. <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
  315. <xsl:with-param name="em.size" select="$points.per.em"/>
  316. </xsl:call-template>
  317. </xsl:variable>
  318. <xsl:value-of select="round($width.in.points div 72.0 * $pixels.per.inch)"/>
  319. </xsl:when>
  320. <xsl:otherwise/>
  321. </xsl:choose>
  322. </xsl:variable>
  323. <xsl:variable name="contentdepth">
  324. <xsl:choose>
  325. <xsl:when test="$ignore.image.scaling != 0"/>
  326. <xsl:when test="@contentdepth">
  327. <xsl:variable name="units">
  328. <xsl:call-template name="length-units">
  329. <xsl:with-param name="length" select="@contentdepth"/>
  330. </xsl:call-template>
  331. </xsl:variable>
  332. <xsl:choose>
  333. <xsl:when test="$units = '%'">
  334. <xsl:variable name="cmagnitude">
  335. <xsl:call-template name="length-magnitude">
  336. <xsl:with-param name="length" select="@contentdepth"/>
  337. </xsl:call-template>
  338. </xsl:variable>
  339. <xsl:value-of select="$intrinsicdepth * $cmagnitude div 100.0"/>
  340. <xsl:text>px</xsl:text>
  341. </xsl:when>
  342. <xsl:otherwise>
  343. <xsl:call-template name="length-spec">
  344. <xsl:with-param name="length" select="@contentdepth"/>
  345. </xsl:call-template>
  346. </xsl:otherwise>
  347. </xsl:choose>
  348. </xsl:when>
  349. <xsl:otherwise>
  350. <xsl:value-of select="$intrinsicdepth"/>
  351. <xsl:text>px</xsl:text>
  352. </xsl:otherwise>
  353. </xsl:choose>
  354. </xsl:variable>
  355. <xsl:variable name="scaled.contentdepth">
  356. <xsl:if test="$contentdepth != ''">
  357. <xsl:variable name="cdepth.in.points">
  358. <xsl:call-template name="length-in-points">
  359. <xsl:with-param name="length" select="$contentdepth"/>
  360. <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
  361. <xsl:with-param name="em.size" select="$points.per.em"/>
  362. </xsl:call-template>
  363. </xsl:variable>
  364. <xsl:value-of select="round($cdepth.in.points div 72.0 * $pixels.per.inch * $scale)"/>
  365. </xsl:if>
  366. </xsl:variable>
  367. <xsl:variable name="depth-units">
  368. <xsl:if test="@depth">
  369. <xsl:call-template name="length-units">
  370. <xsl:with-param name="length" select="@depth"/>
  371. </xsl:call-template>
  372. </xsl:if>
  373. </xsl:variable>
  374. <xsl:variable name="depth">
  375. <xsl:if test="@depth">
  376. <xsl:choose>
  377. <xsl:when test="$depth-units = '%'">
  378. <xsl:value-of select="@depth"/>
  379. </xsl:when>
  380. <xsl:otherwise>
  381. <xsl:call-template name="length-spec">
  382. <xsl:with-param name="length" select="@depth"/>
  383. </xsl:call-template>
  384. </xsl:otherwise>
  385. </xsl:choose>
  386. </xsl:if>
  387. </xsl:variable>
  388. <xsl:variable name="html.depth">
  389. <xsl:choose>
  390. <xsl:when test="$ignore.image.scaling != 0"/>
  391. <xsl:when test="$depth-units = '%'">
  392. <xsl:value-of select="$depth"/>
  393. </xsl:when>
  394. <xsl:when test="@depth and @depth != ''">
  395. <xsl:variable name="depth.in.points">
  396. <xsl:call-template name="length-in-points">
  397. <xsl:with-param name="length" select="$depth"/>
  398. <xsl:with-param name="pixels.per.inch" select="$pixels.per.inch"/>
  399. <xsl:with-param name="em.size" select="$points.per.em"/>
  400. </xsl:call-template>
  401. </xsl:variable>
  402. <xsl:value-of select="round($depth.in.points div 72.0 * $pixels.per.inch)"/>
  403. </xsl:when>
  404. <xsl:otherwise/>
  405. </xsl:choose>
  406. </xsl:variable>
  407. <xsl:variable name="viewport">
  408. <xsl:choose>
  409. <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
  410. <xsl:when test="local-name(.) = 'inlinegraphic' or ancestor::inlinemediaobject or ancestor::inlineequation">0</xsl:when>
  411. <xsl:otherwise>
  412. <xsl:value-of select="$make.graphic.viewport"/>
  413. </xsl:otherwise>
  414. </xsl:choose>
  415. </xsl:variable>
  416. <!--
  417. <xsl:message>=====================================
  418. scale: <xsl:value-of select="$scale"/>, <xsl:value-of select="$scalefit"/>
  419. @contentwidth <xsl:value-of select="@contentwidth"/>
  420. $contentwidth <xsl:value-of select="$contentwidth"/>
  421. scaled.contentwidth: <xsl:value-of select="$scaled.contentwidth"/>
  422. @width: <xsl:value-of select="@width"/>
  423. width: <xsl:value-of select="$width"/>
  424. html.width: <xsl:value-of select="$html.width"/>
  425. @contentdepth <xsl:value-of select="@contentdepth"/>
  426. $contentdepth <xsl:value-of select="$contentdepth"/>
  427. scaled.contentdepth: <xsl:value-of select="$scaled.contentdepth"/>
  428. @depth: <xsl:value-of select="@depth"/>
  429. depth: <xsl:value-of select="$depth"/>
  430. html.depth: <xsl:value-of select="$html.depth"/>
  431. align: <xsl:value-of select="@align"/>
  432. valign: <xsl:value-of select="@valign"/></xsl:message>
  433. -->
  434. <xsl:variable name="scaled" select="@width|@depth|@contentwidth|@contentdepth |@scale|@scalefit"/>
  435. <xsl:variable name="img">
  436. <xsl:choose>
  437. <xsl:when test="@format = 'SVG'">
  438. <object type="image/svg+xml">
  439. <xsl:attribute name="data">
  440. <xsl:choose>
  441. <xsl:when test="$img.src.path != '' and $tag = 'img' and not(starts-with($output_filename, '/')) and not(contains($output_filename, '://'))">
  442. <xsl:value-of select="$img.src.path"/>
  443. </xsl:when>
  444. </xsl:choose>
  445. <xsl:value-of select="$output_filename"/>
  446. </xsl:attribute>
  447. <xsl:call-template name="process.image.attributes">
  448. <!--xsl:with-param name="alt" select="$alt"/ there's no alt here-->
  449. <xsl:with-param name="html.depth" select="$html.depth"/>
  450. <xsl:with-param name="html.width" select="$html.width"/>
  451. <xsl:with-param name="longdesc" select="$longdesc"/>
  452. <xsl:with-param name="scale" select="$scale"/>
  453. <xsl:with-param name="scalefit" select="$scalefit"/>
  454. <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
  455. <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
  456. <xsl:with-param name="viewport" select="$viewport"/>
  457. </xsl:call-template>
  458. <xsl:if test="@align">
  459. <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
  460. <xsl:choose>
  461. <xsl:when test="@align = 'center'">middle</xsl:when>
  462. <xsl:otherwise>
  463. <xsl:value-of select="@align"/>
  464. </xsl:otherwise>
  465. </xsl:choose>
  466. </xsl:attribute>
  467. </xsl:if>
  468. <xsl:if test="$use.embed.for.svg != 0">
  469. <embed type="image/svg+xml">
  470. <xsl:attribute name="src">
  471. <xsl:choose>
  472. <xsl:when test="$img.src.path != '' and $tag = 'img' and not(starts-with($output_filename, '/')) and not(contains($output_filename, '://'))">
  473. <xsl:value-of select="$img.src.path"/>
  474. </xsl:when>
  475. </xsl:choose>
  476. <xsl:value-of select="$output_filename"/>
  477. </xsl:attribute>
  478. <xsl:call-template name="process.image.attributes">
  479. <!--xsl:with-param name="alt" select="$alt"/ there's no alt here -->
  480. <xsl:with-param name="html.depth" select="$html.depth"/>
  481. <xsl:with-param name="html.width" select="$html.width"/>
  482. <xsl:with-param name="longdesc" select="$longdesc"/>
  483. <xsl:with-param name="scale" select="$scale"/>
  484. <xsl:with-param name="scalefit" select="$scalefit"/>
  485. <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
  486. <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
  487. <xsl:with-param name="viewport" select="$viewport"/>
  488. </xsl:call-template>
  489. </embed>
  490. </xsl:if>
  491. </object>
  492. </xsl:when>
  493. <xsl:otherwise>
  494. <xsl:element name="{$tag}" namespace="http://www.w3.org/1999/xhtml">
  495. <xsl:if test="$tag = 'img' and ../../self::imageobjectco">
  496. <xsl:variable name="mapname">
  497. <xsl:call-template name="object.id">
  498. <xsl:with-param name="object" select="../../areaspec"/>
  499. </xsl:call-template>
  500. </xsl:variable>
  501. <xsl:choose>
  502. <xsl:when test="$scaled">
  503. <!-- It might be possible to handle some scaling; needs -->
  504. <!-- more investigation -->
  505. <xsl:message>
  506. <xsl:text>Warning: imagemaps not supported </xsl:text>
  507. <xsl:text>on scaled images</xsl:text>
  508. </xsl:message>
  509. </xsl:when>
  510. <xsl:otherwise>
  511. <xsl:attribute name="border">0</xsl:attribute>
  512. <xsl:attribute name="usemap">
  513. <xsl:value-of select="concat('#', $mapname)"/>
  514. </xsl:attribute>
  515. </xsl:otherwise>
  516. </xsl:choose>
  517. </xsl:if>
  518. <xsl:attribute name="src">
  519. <xsl:choose>
  520. <xsl:when test="$img.src.path != '' and $tag = 'img' and not(starts-with($output_filename, '/')) and not(contains($output_filename, '://'))">
  521. <xsl:value-of select="$img.src.path"/>
  522. </xsl:when>
  523. </xsl:choose>
  524. <xsl:value-of select="$output_filename"/>
  525. </xsl:attribute>
  526. <xsl:if test="@align">
  527. <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
  528. <xsl:choose>
  529. <xsl:when test="@align = 'center'">middle</xsl:when>
  530. <xsl:otherwise>
  531. <xsl:value-of select="@align"/>
  532. </xsl:otherwise>
  533. </xsl:choose>
  534. </xsl:attribute>
  535. </xsl:if>
  536. <xsl:call-template name="process.image.attributes">
  537. <xsl:with-param name="alt">
  538. <xsl:choose>
  539. <xsl:when test="$alt != ''">
  540. <xsl:copy-of select="$alt"/>
  541. </xsl:when>
  542. <xsl:when test="ancestor::figure">
  543. <xsl:variable name="fig.title">
  544. <xsl:apply-templates select="ancestor::figure/title/node()"/>
  545. </xsl:variable>
  546. <xsl:value-of select="normalize-space($fig.title)"/>
  547. </xsl:when>
  548. </xsl:choose>
  549. </xsl:with-param>
  550. <xsl:with-param name="html.depth" select="$html.depth"/>
  551. <xsl:with-param name="html.width" select="$html.width"/>
  552. <xsl:with-param name="longdesc" select="$longdesc"/>
  553. <xsl:with-param name="scale" select="$scale"/>
  554. <xsl:with-param name="scalefit" select="$scalefit"/>
  555. <xsl:with-param name="scaled.contentdepth" select="$scaled.contentdepth"/>
  556. <xsl:with-param name="scaled.contentwidth" select="$scaled.contentwidth"/>
  557. <xsl:with-param name="viewport" select="$viewport"/>
  558. </xsl:call-template>
  559. </xsl:element>
  560. </xsl:otherwise>
  561. </xsl:choose>
  562. </xsl:variable>
  563. <xsl:variable name="bgcolor">
  564. <xsl:call-template name="pi.dbhtml_background-color">
  565. <xsl:with-param name="node" select=".."/>
  566. </xsl:call-template>
  567. </xsl:variable>
  568. <xsl:variable name="use.viewport" select="0"/>
  569. <xsl:choose>
  570. <xsl:when test="$use.viewport">
  571. <table border="{$table.border.off}">
  572. <xsl:if test="$div.element != 'section'">
  573. <xsl:attribute name="summary">manufactured viewport for HTML img</xsl:attribute>
  574. </xsl:if>
  575. <xsl:if test="$css.decoration != ''">
  576. <xsl:attribute name="style">cellpadding: 0; cellspacing: 0;</xsl:attribute>
  577. </xsl:if>
  578. <xsl:if test="$html.width != ''">
  579. <xsl:attribute name="width">
  580. <xsl:value-of select="$html.width"/>
  581. </xsl:attribute>
  582. </xsl:if>
  583. <tr>
  584. <xsl:if test="$html.depth != '' and $depth-units != '%'">
  585. <!-- don't do this for percentages because browsers get confused -->
  586. <xsl:choose>
  587. <xsl:when test="$css.decoration != 0">
  588. <xsl:attribute name="style">
  589. <xsl:text>height: </xsl:text>
  590. <xsl:value-of select="$html.depth"/>
  591. <xsl:text>px</xsl:text>
  592. </xsl:attribute>
  593. </xsl:when>
  594. <xsl:otherwise>
  595. <xsl:attribute name="height">
  596. <xsl:value-of select="$html.depth"/>
  597. </xsl:attribute>
  598. </xsl:otherwise>
  599. </xsl:choose>
  600. </xsl:if>
  601. <td>
  602. <xsl:if test="$bgcolor != ''">
  603. <xsl:choose>
  604. <xsl:when test="$css.decoration != 0">
  605. <xsl:attribute name="style">
  606. <xsl:text>background-color: </xsl:text>
  607. <xsl:value-of select="$bgcolor"/>
  608. </xsl:attribute>
  609. </xsl:when>
  610. <xsl:otherwise>
  611. <xsl:attribute name="style"><xsl:text>background-color: </xsl:text>
  612. <xsl:value-of select="$bgcolor"/>
  613. </xsl:attribute>
  614. </xsl:otherwise>
  615. </xsl:choose>
  616. </xsl:if>
  617. <xsl:if test="@align">
  618. <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
  619. <xsl:value-of select="@align"/>
  620. </xsl:attribute>
  621. </xsl:if>
  622. <xsl:if test="@valign">
  623. <xsl:attribute name="valign">
  624. <xsl:value-of select="@valign"/>
  625. </xsl:attribute>
  626. </xsl:if>
  627. <xsl:copy-of select="$img"/>
  628. </td>
  629. </tr>
  630. </table>
  631. </xsl:when>
  632. <xsl:otherwise>
  633. <xsl:copy-of select="$img"/>
  634. </xsl:otherwise>
  635. </xsl:choose>
  636. <xsl:if test="$tag = 'img' and ../../self::imageobjectco and not($scaled)">
  637. <xsl:variable name="mapname">
  638. <xsl:call-template name="object.id">
  639. <xsl:with-param name="object" select="../../areaspec"/>
  640. </xsl:call-template>
  641. </xsl:variable>
  642. <map name="{$mapname}">
  643. <xsl:for-each select="../../areaspec//area">
  644. <xsl:variable name="units">
  645. <xsl:choose>
  646. <xsl:when test="@units = 'other' and @otherunits">
  647. <xsl:value-of select="@otherunits"/>
  648. </xsl:when>
  649. <xsl:when test="@units">
  650. <xsl:value-of select="@units"/>
  651. </xsl:when>
  652. <!-- areaspec|areaset/area -->
  653. <xsl:when test="../@units = 'other' and ../@otherunits">
  654. <xsl:value-of select="../@otherunits"/>
  655. </xsl:when>
  656. <xsl:when test="../@units">
  657. <xsl:value-of select="../@units"/>
  658. </xsl:when>
  659. <!-- areaspec/areaset/area -->
  660. <xsl:when test="../../@units = 'other' and ../../@otherunits">
  661. <xsl:value-of select="../@otherunits"/>
  662. </xsl:when>
  663. <xsl:when test="../../@units">
  664. <xsl:value-of select="../../@units"/>
  665. </xsl:when>
  666. <xsl:otherwise>calspair</xsl:otherwise>
  667. </xsl:choose>
  668. </xsl:variable>
  669. <xsl:choose>
  670. <xsl:when test="$units = 'calspair' or $units = 'imagemap'">
  671. <xsl:variable name="coords" select="normalize-space(@coords)"/>
  672. <area shape="rect">
  673. <xsl:variable name="linkends">
  674. <xsl:choose>
  675. <xsl:when test="@linkends">
  676. <xsl:value-of select="normalize-space(@linkends)"/>
  677. </xsl:when>
  678. <xsl:otherwise>
  679. <xsl:value-of select="normalize-space(../@linkends)"/>
  680. </xsl:otherwise>
  681. </xsl:choose>
  682. </xsl:variable>
  683. <xsl:variable name="href">
  684. <xsl:choose>
  685. <xsl:when test="@xlink:href">
  686. <xsl:value-of select="@xlink:href"/>
  687. </xsl:when>
  688. <xsl:otherwise>
  689. <xsl:value-of select="../@xlink:href"/>
  690. </xsl:otherwise>
  691. </xsl:choose>
  692. </xsl:variable>
  693. <xsl:choose>
  694. <xsl:when test="$linkends != ''">
  695. <xsl:variable name="linkend">
  696. <xsl:choose>
  697. <xsl:when test="contains($linkends, ' ')">
  698. <xsl:value-of select="substring-before($linkends, ' ')"/>
  699. </xsl:when>
  700. <xsl:otherwise>
  701. <xsl:value-of select="$linkends"/>
  702. </xsl:otherwise>
  703. </xsl:choose>
  704. </xsl:variable>
  705. <xsl:variable name="target" select="key('id', $linkend)[1]"/>
  706. <xsl:if test="$target">
  707. <xsl:attribute name="href">
  708. <xsl:call-template name="href.target">
  709. <xsl:with-param name="object" select="$target"/>
  710. </xsl:call-template>
  711. </xsl:attribute>
  712. </xsl:if>
  713. </xsl:when>
  714. <xsl:when test="$href != ''">
  715. <xsl:attribute name="href">
  716. <xsl:value-of select="$href"/>
  717. </xsl:attribute>
  718. </xsl:when>
  719. </xsl:choose>
  720. <xsl:if test="alt">
  721. <xsl:attribute name="alt">
  722. <xsl:value-of select="alt[1]"/>
  723. </xsl:attribute>
  724. </xsl:if>
  725. <xsl:attribute name="coords">
  726. <xsl:choose>
  727. <xsl:when test="$units = 'calspair'">
  728. <xsl:variable name="p1" select="substring-before($coords, ' ')"/>
  729. <xsl:variable name="p2" select="substring-after($coords, ' ')"/>
  730. <xsl:variable name="x1" select="substring-before($p1,',')"/>
  731. <xsl:variable name="y1" select="substring-after($p1,',')"/>
  732. <xsl:variable name="x2" select="substring-before($p2,',')"/>
  733. <xsl:variable name="y2" select="substring-after($p2,',')"/>
  734. <xsl:variable name="x1p" select="$x1 div 100.0"/>
  735. <xsl:variable name="y1p" select="$y1 div 100.0"/>
  736. <xsl:variable name="x2p" select="$x2 div 100.0"/>
  737. <xsl:variable name="y2p" select="$y2 div 100.0"/>
  738. <!--
  739. <xsl:message>
  740. <xsl:text>units: </xsl:text>
  741. <xsl:value-of select="$units"/>
  742. <xsl:text> </xsl:text>
  743. <xsl:value-of select="$x1p"/><xsl:text>, </xsl:text>
  744. <xsl:value-of select="$y1p"/><xsl:text>, </xsl:text>
  745. <xsl:value-of select="$x2p"/><xsl:text>, </xsl:text>
  746. <xsl:value-of select="$y2p"/><xsl:text>, </xsl:text>
  747. </xsl:message>
  748. <xsl:message>
  749. <xsl:text> </xsl:text>
  750. <xsl:value-of select="$intrinsicwidth"/>
  751. <xsl:text>, </xsl:text>
  752. <xsl:value-of select="$intrinsicdepth"/>
  753. </xsl:message>
  754. <xsl:message>
  755. <xsl:text> </xsl:text>
  756. <xsl:value-of select="$units"/>
  757. <xsl:text> </xsl:text>
  758. <xsl:value-of
  759. select="round($x1p * $intrinsicwidth div 100.0)"/>
  760. <xsl:text>,</xsl:text>
  761. <xsl:value-of select="round($intrinsicdepth
  762. - ($y2p * $intrinsicdepth div 100.0))"/>
  763. <xsl:text>,</xsl:text>
  764. <xsl:value-of select="round($x2p *
  765. $intrinsicwidth div 100.0)"/>
  766. <xsl:text>,</xsl:text>
  767. <xsl:value-of select="round($intrinsicdepth
  768. - ($y1p * $intrinsicdepth div 100.0))"/>
  769. </xsl:message>
  770. -->
  771. <xsl:value-of select="round($x1p * $intrinsicwidth div 100.0)"/>
  772. <xsl:text>,</xsl:text>
  773. <xsl:value-of select="round($intrinsicdepth - ($y2p * $intrinsicdepth div 100.0))"/>
  774. <xsl:text>,</xsl:text>
  775. <xsl:value-of select="round($x2p * $intrinsicwidth div 100.0)"/>
  776. <xsl:text>,</xsl:text>
  777. <xsl:value-of select="round($intrinsicdepth - ($y1p * $intrinsicdepth div 100.0))"/>
  778. </xsl:when>
  779. <xsl:otherwise>
  780. <xsl:copy-of select="$coords"/>
  781. </xsl:otherwise>
  782. </xsl:choose>
  783. </xsl:attribute>
  784. </area>
  785. </xsl:when>
  786. <xsl:otherwise>
  787. <xsl:message>
  788. <xsl:text>Warning: only calspair or </xsl:text>
  789. <xsl:text>otherunits='imagemap' supported </xsl:text>
  790. <xsl:text>in imageobjectco</xsl:text>
  791. </xsl:message>
  792. </xsl:otherwise>
  793. </xsl:choose>
  794. </xsl:for-each>
  795. </map>
  796. </xsl:if>
  797. </xsl:template>
  798. <xsl:template name="process.image.attributes">
  799. <xsl:param name="alt"/>
  800. <xsl:param name="html.width"/>
  801. <xsl:param name="html.depth"/>
  802. <xsl:param name="longdesc"/>
  803. <xsl:param name="scale"/>
  804. <xsl:param name="scalefit"/>
  805. <xsl:param name="scaled.contentdepth"/>
  806. <xsl:param name="scaled.contentwidth"/>
  807. <xsl:param name="viewport"/>
  808. <xsl:choose>
  809. <xsl:when test="@contentwidth or @contentdepth">
  810. <!-- ignore @width/@depth, @scale, and @scalefit if specified -->
  811. <xsl:if test="@contentwidth and $scaled.contentwidth != ''">
  812. <xsl:attribute name="width">
  813. <xsl:value-of select="$scaled.contentwidth"/>
  814. </xsl:attribute>
  815. </xsl:if>
  816. <xsl:if test="@contentdepth and $scaled.contentdepth != ''">
  817. <xsl:attribute name="height">
  818. <xsl:value-of select="$scaled.contentdepth"/>
  819. </xsl:attribute>
  820. </xsl:if>
  821. </xsl:when>
  822. <xsl:when test="number($scale) != 1.0">
  823. <!-- scaling is always uniform, so we only have to specify one dimension -->
  824. <!-- ignore @scalefit if specified -->
  825. <xsl:attribute name="width">
  826. <xsl:value-of select="$scaled.contentwidth"/>
  827. </xsl:attribute>
  828. </xsl:when>
  829. <xsl:when test="$scalefit != 0">
  830. <xsl:choose>
  831. <xsl:when test="contains($html.width, '%')">
  832. <xsl:choose>
  833. <xsl:when test="$viewport != 0">
  834. <!-- The *viewport* will be scaled, so use 100% here! -->
  835. <xsl:attribute name="width">
  836. <xsl:value-of select="'100%'"/>
  837. </xsl:attribute>
  838. </xsl:when>
  839. <xsl:otherwise>
  840. <xsl:attribute name="width">
  841. <xsl:value-of select="$html.width"/>
  842. </xsl:attribute>
  843. </xsl:otherwise>
  844. </xsl:choose>
  845. </xsl:when>
  846. <xsl:when test="contains($html.depth, '%')">
  847. <!-- HTML doesn't deal with this case very well...do nothing -->
  848. </xsl:when>
  849. <xsl:when test="$scaled.contentwidth != '' and $html.width != '' and $scaled.contentdepth != '' and $html.depth != ''">
  850. <!-- scalefit should not be anamorphic; figure out which direction -->
  851. <!-- has the limiting scale factor and scale in that direction -->
  852. <xsl:choose>
  853. <xsl:when test="$html.width div $scaled.contentwidth &gt; $html.depth div $scaled.contentdepth">
  854. <xsl:attribute name="height">
  855. <xsl:value-of select="$html.depth"/>
  856. </xsl:attribute>
  857. </xsl:when>
  858. <xsl:otherwise>
  859. <xsl:attribute name="width">
  860. <xsl:value-of select="$html.width"/>
  861. </xsl:attribute>
  862. </xsl:otherwise>
  863. </xsl:choose>
  864. </xsl:when>
  865. <xsl:when test="$scaled.contentwidth != '' and $html.width != ''">
  866. <xsl:attribute name="width">
  867. <xsl:value-of select="$html.width"/>
  868. </xsl:attribute>
  869. </xsl:when>
  870. <xsl:when test="$scaled.contentdepth != '' and $html.depth != ''">
  871. <xsl:attribute name="height">
  872. <xsl:value-of select="$html.depth"/>
  873. </xsl:attribute>
  874. </xsl:when>
  875. </xsl:choose>
  876. </xsl:when>
  877. </xsl:choose>
  878. <xsl:if test="$alt != ''">
  879. <xsl:attribute name="alt">
  880. <xsl:value-of select="normalize-space($alt)"/>
  881. </xsl:attribute>
  882. </xsl:if>
  883. <!-- Turn off longdesc attribute since not supported by browsers
  884. <xsl:if test="$longdesc != ''">
  885. <xsl:attribute name="longdesc">
  886. <xsl:value-of select="$longdesc"/>
  887. </xsl:attribute>
  888. </xsl:if>
  889. -->
  890. <xsl:if test="@align and $viewport = 0">
  891. <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
  892. <xsl:choose>
  893. <xsl:when test="@align = 'center'">middle</xsl:when>
  894. <xsl:otherwise>
  895. <xsl:value-of select="@align"/>
  896. </xsl:otherwise>
  897. </xsl:choose>
  898. </xsl:attribute>
  899. </xsl:if>
  900. <xsl:call-template name="extension.process.image.attributes"/>
  901. </xsl:template>
  902. <xsl:template name="extension.process.image.attributes"/>
  903. <!-- ==================================================================== -->
  904. <xsl:template match="graphic">
  905. <xsl:choose>
  906. <xsl:when test="parent::inlineequation">
  907. <span>
  908. <xsl:call-template name="id.attribute"/>
  909. <xsl:call-template name="anchor"/>
  910. <xsl:call-template name="process.image"/>
  911. </span>
  912. </xsl:when>
  913. <xsl:otherwise>
  914. <div>
  915. <xsl:call-template name="id.attribute"/>
  916. <xsl:if test="@align">
  917. <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
  918. <xsl:value-of select="@align"/>
  919. </xsl:attribute>
  920. </xsl:if>
  921. <xsl:call-template name="anchor"/>
  922. <xsl:call-template name="process.image"/>
  923. </div>
  924. </xsl:otherwise>
  925. </xsl:choose>
  926. </xsl:template>
  927. <xsl:template match="inlinegraphic">
  928. <xsl:variable name="filename">
  929. <xsl:choose>
  930. <xsl:when test="@entityref">
  931. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  932. </xsl:when>
  933. <xsl:otherwise>
  934. <xsl:apply-templates select="@fileref"/>
  935. </xsl:otherwise>
  936. </xsl:choose>
  937. </xsl:variable>
  938. <xsl:call-template name="anchor"/>
  939. <xsl:choose>
  940. <xsl:when test="@format='linespecific'">
  941. <xsl:choose>
  942. <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
  943. <xsl:choose>
  944. <xsl:when test="element-available('stext:insertfile')">
  945. <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
  946. </xsl:when>
  947. <xsl:when test="element-available('xtext:insertfile')">
  948. <xtext:insertfile href="{$filename}"/>
  949. </xsl:when>
  950. <xsl:otherwise>
  951. <xsl:message terminate="yes">
  952. <xsl:text>No insertfile extension available.</xsl:text>
  953. </xsl:message>
  954. </xsl:otherwise>
  955. </xsl:choose>
  956. </xsl:when>
  957. <xsl:otherwise>
  958. <xsl:message terminate="yes">
  959. <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
  960. <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
  961. </xsl:message>
  962. </xsl:otherwise>
  963. </xsl:choose>
  964. </xsl:when>
  965. <xsl:otherwise>
  966. <xsl:call-template name="process.image"/>
  967. </xsl:otherwise>
  968. </xsl:choose>
  969. </xsl:template>
  970. <!-- ==================================================================== -->
  971. <xsl:template match="mediaobject|mediaobjectco">
  972. <xsl:variable name="olist" select="imageobject|imageobjectco |videoobject|audioobject |textobject"/>
  973. <xsl:variable name="object.index">
  974. <xsl:call-template name="select.mediaobject.index">
  975. <xsl:with-param name="olist" select="$olist"/>
  976. <xsl:with-param name="count" select="1"/>
  977. </xsl:call-template>
  978. </xsl:variable>
  979. <xsl:variable name="object" select="$olist[position() = $object.index]"/>
  980. <xsl:variable name="align">
  981. <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
  982. </xsl:variable>
  983. <div>
  984. <xsl:apply-templates select="." mode="common.html.attributes"/>
  985. <xsl:if test="$align != '' ">
  986. <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
  987. <xsl:value-of select="$align"/>
  988. </xsl:attribute>
  989. </xsl:if>
  990. <xsl:call-template name="id.attribute"/>
  991. <xsl:call-template name="anchor"/>
  992. <xsl:apply-templates select="$object"/>
  993. <xsl:apply-templates select="caption"/>
  994. </div>
  995. </xsl:template>
  996. <xsl:template match="inlinemediaobject">
  997. <span>
  998. <xsl:apply-templates select="." mode="common.html.attributes"/>
  999. <xsl:call-template name="id.attribute"/>
  1000. <xsl:call-template name="anchor"/>
  1001. <xsl:call-template name="select.mediaobject"/>
  1002. </span>
  1003. </xsl:template>
  1004. <xsl:template match="programlisting/inlinemediaobject |screen/inlinemediaobject" priority="2">
  1005. <!-- the additional span causes problems in some cases -->
  1006. <xsl:call-template name="select.mediaobject"/>
  1007. </xsl:template>
  1008. <!-- ==================================================================== -->
  1009. <xsl:template match="imageobjectco">
  1010. <xsl:call-template name="anchor"/>
  1011. <xsl:choose>
  1012. <!-- select one imageobject? -->
  1013. <xsl:when test="$use.role.for.mediaobject != 0 and count(imageobject) &gt; 1 and imageobject[@role]">
  1014. <xsl:variable name="olist" select="imageobject"/>
  1015. <xsl:variable name="object.index">
  1016. <xsl:call-template name="select.mediaobject.index">
  1017. <xsl:with-param name="olist" select="$olist"/>
  1018. <xsl:with-param name="count" select="1"/>
  1019. </xsl:call-template>
  1020. </xsl:variable>
  1021. <xsl:variable name="object" select="$olist[position() = $object.index]"/>
  1022. <xsl:apply-templates select="$object"/>
  1023. </xsl:when>
  1024. <xsl:otherwise>
  1025. <!-- otherwise process them all -->
  1026. <xsl:apply-templates select="imageobject"/>
  1027. </xsl:otherwise>
  1028. </xsl:choose>
  1029. <xsl:apply-templates select="calloutlist"/>
  1030. </xsl:template>
  1031. <xsl:template match="imageobject">
  1032. <xsl:apply-templates select="imagedata"/>
  1033. </xsl:template>
  1034. <xsl:template match="imagedata">
  1035. <xsl:variable name="filename">
  1036. <xsl:call-template name="mediaobject.filename">
  1037. <xsl:with-param name="object" select=".."/>
  1038. </xsl:call-template>
  1039. </xsl:variable>
  1040. <xsl:choose>
  1041. <!-- Handle MathML and SVG markup in imagedata -->
  1042. <xsl:when xmlns:mml="http://www.w3.org/1998/Math/MathML" test="mml:*">
  1043. <xsl:apply-templates/>
  1044. </xsl:when>
  1045. <xsl:when xmlns:svg="http://www.w3.org/2000/svg" test="svg:*">
  1046. <xsl:apply-templates/>
  1047. </xsl:when>
  1048. <xsl:when test="@format='linespecific'">
  1049. <xsl:choose>
  1050. <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
  1051. <xsl:choose>
  1052. <xsl:when test="element-available('stext:insertfile')">
  1053. <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
  1054. </xsl:when>
  1055. <xsl:when test="element-available('xtext:insertfile')">
  1056. <xtext:insertfile href="{$filename}"/>
  1057. </xsl:when>
  1058. <xsl:otherwise>
  1059. <xsl:message terminate="yes">
  1060. <xsl:text>No insertfile extension available.</xsl:text>
  1061. </xsl:message>
  1062. </xsl:otherwise>
  1063. </xsl:choose>
  1064. </xsl:when>
  1065. <xsl:otherwise>
  1066. <a xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" href="{$filename}"/>
  1067. </xsl:otherwise>
  1068. </xsl:choose>
  1069. </xsl:when>
  1070. <xsl:otherwise>
  1071. <xsl:variable name="longdesc.uri">
  1072. <xsl:call-template name="longdesc.uri">
  1073. <xsl:with-param name="mediaobject" select="ancestor::imageobject/parent::*"/>
  1074. </xsl:call-template>
  1075. </xsl:variable>
  1076. <xsl:variable name="phrases" select="ancestor::mediaobject/textobject[phrase] |ancestor::inlinemediaobject/textobject[phrase] |ancestor::mediaobjectco/textobject[phrase]"/>
  1077. <xsl:call-template name="process.image">
  1078. <xsl:with-param name="alt">
  1079. <xsl:choose>
  1080. <xsl:when test="ancestor::mediaobject/alt">
  1081. <xsl:apply-templates select="ancestor::mediaobject/alt"/>
  1082. </xsl:when>
  1083. <xsl:otherwise>
  1084. <xsl:apply-templates select="$phrases[not(@role) or @role!='tex'][1]"/>
  1085. </xsl:otherwise>
  1086. </xsl:choose>
  1087. </xsl:with-param>
  1088. <xsl:with-param name="longdesc">
  1089. <xsl:call-template name="write.longdesc">
  1090. <xsl:with-param name="mediaobject" select="ancestor::imageobject/parent::*"/>
  1091. </xsl:call-template>
  1092. </xsl:with-param>
  1093. </xsl:call-template>
  1094. <xsl:if test="$html.longdesc != 0 and $html.longdesc.link != 0 and ancestor::imageobject/parent::*/textobject[not(phrase)]">
  1095. <xsl:call-template name="longdesc.link">
  1096. <xsl:with-param name="longdesc.uri" select="$longdesc.uri"/>
  1097. </xsl:call-template>
  1098. </xsl:if>
  1099. </xsl:otherwise>
  1100. </xsl:choose>
  1101. </xsl:template>
  1102. <!-- ==================================================================== -->
  1103. <xsl:template name="longdesc.uri">
  1104. <xsl:param name="mediaobject" select="."/>
  1105. <xsl:if test="$html.longdesc">
  1106. <xsl:if test="$mediaobject/textobject[not(phrase)]">
  1107. <xsl:variable name="dbhtml.dir">
  1108. <xsl:call-template name="dbhtml-dir"/>
  1109. </xsl:variable>
  1110. <xsl:variable name="filename">
  1111. <xsl:call-template name="make-relative-filename">
  1112. <xsl:with-param name="base.dir">
  1113. <xsl:choose>
  1114. <xsl:when test="$dbhtml.dir != ''">
  1115. <xsl:value-of select="$dbhtml.dir"/>
  1116. </xsl:when>
  1117. <xsl:otherwise>
  1118. <xsl:value-of select="$chunk.base.dir"/>
  1119. </xsl:otherwise>
  1120. </xsl:choose>
  1121. </xsl:with-param>
  1122. <xsl:with-param name="base.name">
  1123. <xsl:choose>
  1124. <xsl:when test=" $mediaobject/@*[local-name() = 'id'] and not($use.id.as.filename = 0)">
  1125. <!-- * if this mediaobject has an ID, then we use the -->
  1126. <!-- * value of that ID as basename for the "longdesc" -->
  1127. <!-- * file (that is, without prepending an "ld-" too it) -->
  1128. <xsl:value-of select="$mediaobject/@*[local-name() = 'id']"/>
  1129. <xsl:value-of select="$html.ext"/>
  1130. </xsl:when>
  1131. <xsl:otherwise>
  1132. <!-- * otherwise, if this mediaobject does not have an -->
  1133. <!-- * ID, then we generate an ID... -->
  1134. <xsl:variable name="image-id">
  1135. <xsl:call-template name="object.id">
  1136. <xsl:with-param name="object" select="$mediaobject"/>
  1137. </xsl:call-template>
  1138. </xsl:variable>
  1139. <!-- * ...and then we take that generated ID, prepend an -->
  1140. <!-- * "ld-" to it, and use that as the basename for the file -->
  1141. <xsl:value-of select="concat('ld-',$image-id,$html.ext)"/>
  1142. </xsl:otherwise>
  1143. </xsl:choose>
  1144. </xsl:with-param>
  1145. </xsl:call-template>
  1146. </xsl:variable>
  1147. <xsl:value-of select="$filename"/>
  1148. </xsl:if>
  1149. </xsl:if>
  1150. </xsl:template>
  1151. <xsl:template name="write.longdesc">
  1152. <xsl:param name="mediaobject" select="."/>
  1153. <xsl:if test="$html.longdesc != 0 and $mediaobject/textobject[not(phrase)]">
  1154. <xsl:variable name="filename">
  1155. <xsl:call-template name="longdesc.uri">
  1156. <xsl:with-param name="mediaobject" select="$mediaobject"/>
  1157. </xsl:call-template>
  1158. </xsl:variable>
  1159. <xsl:value-of select="$filename"/>
  1160. <xsl:call-template name="write.chunk">
  1161. <xsl:with-param name="filename" select="$filename"/>
  1162. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  1163. <xsl:with-param name="content">
  1164. <xsl:call-template name="user.preroot"/>
  1165. <html>
  1166. <head>
  1167. <xsl:call-template name="system.head.content"/>
  1168. <xsl:call-template name="head.content">
  1169. <xsl:with-param name="title" select="'Long Description'"/>
  1170. </xsl:call-template>
  1171. <xsl:call-template name="user.head.content"/>
  1172. </head>
  1173. <body>
  1174. <xsl:call-template name="body.attributes"/>
  1175. <xsl:for-each select="$mediaobject/textobject[not(phrase)]">
  1176. <xsl:apply-templates select="./*"/>
  1177. </xsl:for-each>
  1178. </body>
  1179. </html>
  1180. <xsl:value-of select="$chunk.append"/>
  1181. </xsl:with-param>
  1182. </xsl:call-template>
  1183. </xsl:if>
  1184. </xsl:template>
  1185. <xsl:template name="longdesc.link">
  1186. <xsl:param name="longdesc.uri" select="''"/>
  1187. <xsl:variable name="this.uri">
  1188. <xsl:call-template name="make-relative-filename">
  1189. <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
  1190. <xsl:with-param name="base.name">
  1191. <xsl:call-template name="href.target.uri"/>
  1192. </xsl:with-param>
  1193. </xsl:call-template>
  1194. </xsl:variable>
  1195. <xsl:variable name="href.to">
  1196. <xsl:call-template name="trim.common.uri.paths">
  1197. <xsl:with-param name="uriA" select="$longdesc.uri"/>
  1198. <xsl:with-param name="uriB" select="$this.uri"/>
  1199. <xsl:with-param name="return" select="'A'"/>
  1200. </xsl:call-template>
  1201. </xsl:variable>
  1202. <div class="longdesc-link" align="{$direction.align.end}">
  1203. <br clear="all"/>
  1204. <span class="longdesc-link">
  1205. <xsl:text>[</xsl:text>
  1206. <a href="{$href.to}" target="longdesc">D</a>
  1207. <xsl:text>]</xsl:text>
  1208. </span>
  1209. </div>
  1210. </xsl:template>
  1211. <!-- ==================================================================== -->
  1212. <xsl:template match="mediaobject/alt">
  1213. <xsl:apply-templates/>
  1214. </xsl:template>
  1215. <xsl:template match="videoobject">
  1216. <xsl:apply-templates select="videodata"/>
  1217. </xsl:template>
  1218. <xsl:template match="videodata">
  1219. <xsl:call-template name="process.image">
  1220. <xsl:with-param name="tag" select="'embed'"/>
  1221. <xsl:with-param name="alt">
  1222. <xsl:choose>
  1223. <xsl:when test="ancestor::mediaobject/alt">
  1224. <xsl:apply-templates select="ancestor::mediaobject/alt"/>
  1225. </xsl:when>
  1226. <xsl:otherwise>
  1227. <xsl:apply-templates select="(ancestor::mediaobject/textobject/phrase)[1]"/>
  1228. </xsl:otherwise>
  1229. </xsl:choose>
  1230. </xsl:with-param>
  1231. </xsl:call-template>
  1232. </xsl:template>
  1233. <!-- ==================================================================== -->
  1234. <xsl:template match="audioobject">
  1235. <xsl:apply-templates select="audiodata"/>
  1236. </xsl:template>
  1237. <xsl:template match="audiodata">
  1238. <xsl:call-template name="process.image">
  1239. <xsl:with-param name="tag" select="'embed'"/>
  1240. <xsl:with-param name="alt">
  1241. <xsl:choose>
  1242. <xsl:when test="ancestor::mediaobject/alt">
  1243. <xsl:apply-templates select="ancestor::mediaobject/alt"/>
  1244. </xsl:when>
  1245. <xsl:otherwise>
  1246. <xsl:apply-templates select="(ancestor::mediaobject/textobject/phrase)[1]"/>
  1247. </xsl:otherwise>
  1248. </xsl:choose>
  1249. </xsl:with-param>
  1250. </xsl:call-template>
  1251. </xsl:template>
  1252. <!-- ==================================================================== -->
  1253. <xsl:template match="textobject">
  1254. <xsl:apply-templates/>
  1255. </xsl:template>
  1256. <xsl:template match="textdata">
  1257. <xsl:variable name="filename">
  1258. <xsl:choose>
  1259. <xsl:when test="@entityref">
  1260. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  1261. </xsl:when>
  1262. <xsl:otherwise>
  1263. <xsl:apply-templates select="@fileref"/>
  1264. </xsl:otherwise>
  1265. </xsl:choose>
  1266. </xsl:variable>
  1267. <xsl:variable name="encoding">
  1268. <xsl:choose>
  1269. <xsl:when test="@encoding">
  1270. <xsl:value-of select="@encoding"/>
  1271. </xsl:when>
  1272. <xsl:otherwise>
  1273. <xsl:value-of select="$textdata.default.encoding"/>
  1274. </xsl:otherwise>
  1275. </xsl:choose>
  1276. </xsl:variable>
  1277. <xsl:choose>
  1278. <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
  1279. <xsl:choose>
  1280. <xsl:when test="element-available('stext:insertfile')">
  1281. <stext:insertfile href="{$filename}" encoding="{$encoding}"/>
  1282. </xsl:when>
  1283. <xsl:when test="element-available('xtext:insertfile')">
  1284. <xtext:insertfile href="{$filename}"/>
  1285. </xsl:when>
  1286. <xsl:otherwise>
  1287. <xsl:message terminate="yes">
  1288. <xsl:text>No insertfile extension available.</xsl:text>
  1289. </xsl:message>
  1290. </xsl:otherwise>
  1291. </xsl:choose>
  1292. </xsl:when>
  1293. <xsl:otherwise>
  1294. <xsl:message terminate="yes">
  1295. <xsl:text>Cannot insert </xsl:text><xsl:value-of select="$filename"/>
  1296. <xsl:text>. Check use.extensions and textinsert.extension parameters.</xsl:text>
  1297. </xsl:message>
  1298. </xsl:otherwise>
  1299. </xsl:choose>
  1300. </xsl:template>
  1301. <!-- ==================================================================== -->
  1302. <xsl:template match="caption">
  1303. <div>
  1304. <xsl:apply-templates select="." mode="common.html.attributes"/>
  1305. <xsl:call-template name="id.attribute"/>
  1306. <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
  1307. <xsl:attribute name="style"><xsl:text>text-align: </xsl:text><xsl:value-of select="@align"/></xsl:attribute>
  1308. </xsl:if>
  1309. <xsl:apply-templates/>
  1310. </div>
  1311. </xsl:template>
  1312. <!-- ==================================================================== -->
  1313. <!-- "Support" for SVG -->
  1314. <xsl:template xmlns:svg="http://www.w3.org/2000/svg" match="svg:*">
  1315. <xsl:copy>
  1316. <xsl:copy-of select="@*"/>
  1317. <xsl:apply-templates/>
  1318. </xsl:copy>
  1319. </xsl:template>
  1320. <!-- The following works sometimes, but needs to take into account
  1321. 1. When there is no /*/@xml:base
  1322. 2. When the chunks are going somewhere else
  1323. <xsl:variable name="relpath">
  1324. <xsl:call-template name="relative-uri">
  1325. <xsl:with-param name="filename" select="@fileref"/>
  1326. </xsl:call-template>
  1327. </xsl:variable>
  1328. <xsl:choose>
  1329. <xsl:when test="/*/@xml:base
  1330. and starts-with($relpath,/*/@xml:base)">
  1331. <xsl:value-of select="substring-after($relpath,/*/@xml:base)"/>
  1332. </xsl:when>
  1333. <xsl:otherwise>
  1334. <xsl:value-of select="@fileref"/>
  1335. </xsl:otherwise>
  1336. </xsl:choose>
  1337. <xsl:value-of select="@fileref"/>
  1338. </xsl:when>
  1339. -->
  1340. <!-- Resolve xml:base attributes -->
  1341. <xsl:template match="@fileref">
  1342. <!-- need a check for absolute urls -->
  1343. <xsl:choose>
  1344. <xsl:when test="contains(., ':')">
  1345. <!-- it has a uri scheme so it is an absolute uri -->
  1346. <xsl:value-of select="."/>
  1347. </xsl:when>
  1348. <xsl:when test="$keep.relative.image.uris != 0">
  1349. <!-- leave it alone -->
  1350. <xsl:value-of select="."/>
  1351. </xsl:when>
  1352. <xsl:otherwise>
  1353. <!-- its a relative uri that needs xml:base processing -->
  1354. <xsl:call-template name="relative-uri">
  1355. </xsl:call-template>
  1356. </xsl:otherwise>
  1357. </xsl:choose>
  1358. </xsl:template>
  1359. </xsl:stylesheet>