<xsl:template match="tei:graphic">
<!-- perform some tests on the graphic -->
<xsl:variable name="maxWidth" select="number(number($pageWidth)*100) cast as xs:integer"/>
<xsl:variable name="maxHeight" select="number(number($pageHeight)*100) cast as xs:integer"/>
<xsl:choose>
<xsl:when test="@url and ( (@teidocx:width and @teidocx:height) or (@width and @height))">
<!--
is there a number present?
not(number(substring(@width,0,string-length(@width)-1))=NAN) and
not(number(substring(@height,0,string-length(@height)-1))=NAN)">
-->
<xsl:variable name="Width">
<xsl:choose>
<xsl:when test="contains(@width,'%')">
<xsl:value-of select="number($pageWidth * number(substring-before(@width,'%'))) cast as xs:integer"/>
</xsl:when>
<xsl:when test="@width">
<xsl:value-of select="teidocx:convert-dim-emu(@width)"/>
</xsl:when>
<xsl:when test="@scale and @teidocx:width">
<xsl:value-of select="(@teidocx:width * number(@scale)) cast as xs:integer"/>
</xsl:when>
<xsl:when test="@height and @teidocx:height">
<xsl:variable name="h">
<xsl:value-of select="teidocx:convert-dim-emu(@height)"/>
</xsl:variable>
<xsl:value-of select="(@teidocx:width * ($h div number(@teidocx:height))) cast as xs:integer"/>
</xsl:when>
<xsl:when test="@teidocx:width">
<xsl:value-of select="@teidocx:width"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">no way to work out image width for
<xsl:value-of select="@url"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="Height">
<xsl:choose>
<xsl:when test="contains(@height,'%')">
<xsl:value-of select="number($pageHeight * (number(substring-before(@height,'%')))) cast as xs:integer"/>
</xsl:when>
<xsl:when test="@height">
<xsl:value-of select="teidocx:convert-dim-emu(@height)"/>
</xsl:when>
<xsl:when test="@scale and @teidocx:height">
<xsl:value-of select="(@teidocx:height * number(@scale)) cast as xs:integer"/>
</xsl:when>
<xsl:when test="@width and @teidocx:height and @teidocx:width">
<xsl:value-of select="(($Width * @teidocx:height) div @teidocx:width) cast as xs:integer"/>
</xsl:when>
<xsl:when test="@teidocx:height">
<xsl:value-of select="@teidocx:height"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">no way to work out image height for
<xsl:value-of select="@url"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- check for sense -->
<xsl:variable name="imageHeight">
<xsl:choose>
<xsl:when test="$Height = -1">
<xsl:value-of select="$maxHeight"/>
</xsl:when>
<xsl:when test="$Height > $maxHeight">
<xsl:value-of select="$maxHeight"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Height"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="imageWidth">
<xsl:choose>
<xsl:when test="$Width = -1">
<xsl:value-of select="$maxWidth"/>
</xsl:when>
<xsl:when test="$Width > $maxWidth">
<xsl:value-of select="$maxWidth"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Width"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- DEBUG
<xsl:message>
maxWidth: <xsl:value-of select="$maxWidth"/>
maxHeight: <xsl:value-of select="$maxHeight"/>
Width: <xsl:value-of select="$Width"/>
Height: <xsl:value-of select="$Height"/>
imageWidth: <xsl:value-of select="$imageWidth"/>
imageHeight: <xsl:value-of select="$imageHeight"/>
@width: <xsl:value-of select="@width"/>
@height: <xsl:value-of select="@height"/>
@teidocx:width: <xsl:value-of select="@teidocx:width"/>
@teidocx:height: <xsl:value-of select="@teidocx:height"/>
</xsl:message>
-->
<!-- prepare actual graphic -->
<xsl:variable name="generatedID">
<xsl:choose>
<xsl:when test="@n">
<xsl:value-of select="@n"/>
</xsl:when>
<xsl:otherwise>
<xsl:number level="any"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="graphic-element">
<a:graphic>
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic>
<pic:nvPicPr>
<pic:cNvPr name="{tokenize(@url, '/')[last()]}">
<xsl:attribute name="id">
<xsl:number level="any"/>
</xsl:attribute>
</pic:cNvPr>
<pic:cNvPicPr/>
</pic:nvPicPr>
<pic:blipFill>
<a:blip>
<xsl:attribute name="r:embed">
<xsl:choose>
<xsl:when test="$isofreestanding='true'">
<xsl:text>rId</xsl:text>
<xsl:value-of select="number($generatedID) + 300"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="url" select="@url"/>
<xsl:value-of select="document(concat($word-directory,'/word/_rels/document.xml.rels'))//rel:Relationship[@Target=$url]/@Id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</a:blip>
<a:stretch>
<a:fillRect/>
</a:stretch>
</pic:blipFill>
<pic:spPr>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="{$imageWidth}00" cy="{$imageHeight}00"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</xsl:variable>
<!-- end graphic element -->
<w:r>
<w:drawing>
<!-- choose between inline and block -->
<xsl:choose>
<xsl:when test="parent::tei:figure[@rend='display']">
<!-- render as block -->
<wp:anchor simplePos="0" relativeHeight="10" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1">
<wp:simplePos x="0" y="0"/>
<wp:positionH relativeFrom="margin">
<wp:align>center</wp:align>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:align>center</wp:align>
</wp:positionV>
<wp:extent cx="{$imageWidth}00" cy="{$imageHeight}00"/>
<wp:wrapTopAndBottom/>
<wp:docPr name="{tokenize(@url, '/')[last()]}">
<xsl:attribute name="id">
<xsl:value-of select="$generatedID"/>
</xsl:attribute>
</wp:docPr>
<xsl:copy-of select="$graphic-element"/>
</wp:anchor>
</xsl:when>
<xsl:otherwise>
<wp:inline>
<wp:extent cx="{$imageWidth}00" cy="{$imageHeight}00"/>
<wp:docPr name="{tokenize(@url, '/')[last()]}">
<xsl:attribute name="id">
<xsl:value-of select="$generatedID"/>
</xsl:attribute>
</wp:docPr>
<xsl:copy-of select="$graphic-element"/>
</wp:inline>
</xsl:otherwise>
</xsl:choose>
<!-- end inline/block -->
</w:drawing>
</w:r>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">ERROR. no image size info for
<xsl:value-of select="@url"/>, cannot proceed</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template> |