<xsl:template name="graphicsAttributes">
<xsl:param name="mode">fo</xsl:param>
<xsl:if test="@width">
<xsl:choose>
<xsl:when test="ends-with(@width,'%')">
<xsl:choose>
<xsl:when test="$mode='fo'">
<xsl:attribute name="content-width">
<xsl:value-of select="@width"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="$mode='latex'">
<xsl:text>width=</xsl:text>
<xsl:value-of select="number(substring-before(@width,'%')) div 100"/>
<xsl:text>\textwidth,</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="width">
<xsl:value-of select="@width"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="w">
<xsl:choose>
<xsl:when test="ends-with(@width,'pt')">
<xsl:value-of select="@width"/>
</xsl:when>
<xsl:when test="ends-with(@width,'px') and $mode='latex'">
<xsl:value-of select="substring-before(@width,'px')"/>
<xsl:text>pt</xsl:text>
</xsl:when>
<xsl:when test="ends-with(@width,'em')">
<xsl:value-of select="@width"/>
</xsl:when>
<xsl:when test="ends-with(@width,'in')">
<xsl:value-of select="@width"/>
</xsl:when>
<xsl:when test="ends-with(@width,'px')">
<xsl:value-of select="@width"/>
</xsl:when>
<xsl:when test="ends-with(@width,'cm')">
<xsl:value-of select="@width"/>
</xsl:when>
<xsl:when test="ends-with(@width,'mm')">
<xsl:value-of select="@width"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@width"/>
<xsl:text>pt</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$mode='fo'">
<xsl:attribute name="content-width">
<xsl:value-of select="$w"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="$mode='latex'">
<xsl:text>width=</xsl:text>
<xsl:value-of select="$w"/>
<xsl:text>,</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="@height">
<xsl:choose>
<xsl:when test="ends-with(@height,'%')">
<xsl:choose>
<xsl:when test="$mode='fo'">
<xsl:attribute name="content-height">
<xsl:value-of select="@height"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="$mode='latex'">
<xsl:text>height=</xsl:text>
<xsl:value-of select="number(substring-before(@height,'%')) div 100"/>
<xsl:text>\textheight,</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="height">
<xsl:value-of select="@height"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="h">
<xsl:choose>
<xsl:when test="ends-with(@height,'pt')">
<xsl:value-of select="@height"/>
</xsl:when>
<xsl:when test="ends-with(@height,'px') and $mode='latex'">
<xsl:value-of select="substring-before(@height,'px')"/>
<xsl:text>pt</xsl:text>
</xsl:when>
<xsl:when test="ends-with(@height,'in')">
<xsl:value-of select="@height"/>
</xsl:when>
<xsl:when test="ends-with(@height,'px')">
<xsl:value-of select="@height"/>
</xsl:when>
<xsl:when test="ends-with(@height,'cm')">
<xsl:value-of select="@height"/>
</xsl:when>
<xsl:when test="ends-with(@height,'mm')">
<xsl:value-of select="@height"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@height"/>
<xsl:text>pt</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$mode='fo'">
<xsl:attribute name="content-height">
<xsl:value-of select="$h"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="$mode='latex'">
<xsl:text>height=</xsl:text>
<xsl:value-of select="$h"/>
<xsl:text>,</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<!-- For larger graphics in XSL:FO, we want to make sure they're scaled
nicely to fit on the page. -->
<xsl:choose>
<xsl:when test="$mode eq 'fo' and ends-with( @width,'px')">
<xsl:variable name="pxW" select="xs:integer( substring-before( @width,'px') )"/>
<xsl:variable name="pxH" select="if (ends-with( @height,'px')) then xs:integer( substring-before( @height,'px') ) else -1"/>
<xsl:choose>
<xsl:when test="($pxW gt $pxH) and ($pxW gt 200)">
<xsl:attribute name="max-width" select="'80%'"/>
</xsl:when>
<xsl:when test="($pxH gt $pxW) and ($pxW gt 200)">
<xsl:variable name="percentH" select="round(($pxW div $pxH) * 80)"/>
<xsl:attribute name="width" select="concat($percentH, '%')"/>
<xsl:attribute name="content-width" select="'scale-to-fit'"/>
<xsl:attribute name="content-height" select="'scale-to-fit'"/>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- We have no idea how the height & width were specified, so do no harm -->
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="s">
<xsl:choose>
<xsl:when test="@scale and ends-with(@scale,'%')">
<xsl:value-of select="number(substring-before(@scale,'%')) div 100"/>
</xsl:when>
<xsl:when test="@scale">
<xsl:value-of select="@scale"/>
</xsl:when>
<xsl:when test="not(@width) and not(@height) and not($standardScale=1)">
<xsl:value-of select="$standardScale"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:if test="not($s='')">
<xsl:choose>
<xsl:when test="$mode='fo'">
<xsl:attribute name="content-width">
<xsl:value-of select="$s"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="$mode='latex'">
<xsl:text>scale=</xsl:text>
<xsl:value-of select="$s"/>
<xsl:text>,</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:template> |