graphics.xsl 59 KB

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