<!-- Override these templates for FO -->
<!-- ==================================================================== -->
+<xsl:template name="image.scalefit">
+ <xsl:choose>
+ <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
+ <xsl:when test="@contentwidth">0</xsl:when>
+ <xsl:when test="@contentdepth and
+ @contentdepth != '100%'">0</xsl:when>
+ <xsl:when test="@scale">0</xsl:when>
+ <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
+ <xsl:when test="@width or @depth">1</xsl:when>
+ <xsl:when test="$default.image.width != ''">1</xsl:when>
+ <xsl:otherwise>0</xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="image.scale">
+ <xsl:choose>
+ <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
+ <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
+ <xsl:when test="@scale">
+ <xsl:value-of select="@scale div 100.0"/>
+ </xsl:when>
+ <xsl:otherwise>1.0</xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="image.filename">
+ <xsl:choose>
+ <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
+ <!-- no filename for inline SVG content -->
+ </xsl:when>
+ <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
+ <!-- no filename for inline MathML content -->
+ </xsl:when>
+ <xsl:when test="local-name(.) = 'graphic'
+ or local-name(.) = 'inlinegraphic'">
+ <!-- handle legacy graphic and inlinegraphic by new template -->
+ <xsl:call-template name="mediaobject.filename">
+ <xsl:with-param name="object" select="."/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- imagedata, videodata, audiodata -->
+ <xsl:call-template name="mediaobject.filename">
+ <xsl:with-param name="object" select=".."/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="image.src">
+ <xsl:param name="filename"/>
+
+ <xsl:choose>
+ <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
+ <!-- no src attribute for inline SVG content -->
+ </xsl:when>
+ <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
+ <!-- no src attribute for inline MathML content -->
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="fo-external-image">
+ <xsl:with-param name="filename">
+ <xsl:if test="$img.src.path != '' and
+ not(starts-with($filename, '/')) and
+ not(contains($filename, '://'))">
+ <xsl:value-of select="$img.src.path"/>
+ </xsl:if>
+ <xsl:value-of select="$filename"/>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="image.content.type">
+ <xsl:if test="@format">
+ <xsl:call-template name="graphic.format.content-type">
+ <xsl:with-param name="format" select="@format"/>
+ </xsl:call-template>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="image.bgcolor">
+ <xsl:call-template name="pi.dbfo_background-color">
+ <xsl:with-param name="node" select=".."/>
+ </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="image.width">
+ <xsl:choose>
+ <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
+ <xsl:when test="contains(@width,'%')">
+ <xsl:value-of select="@width"/>
+ </xsl:when>
+ <xsl:when test="@width and not(@width = '')">
+ <xsl:call-template name="length-spec">
+ <xsl:with-param name="length" select="@width"/>
+ <xsl:with-param name="default.units" select="'px'"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="not(@depth) and $default.image.width != ''">
+ <xsl:call-template name="length-spec">
+ <xsl:with-param name="length" select="$default.image.width"/>
+ <xsl:with-param name="default.units" select="'px'"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>auto</xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="image.height">
+ <xsl:choose>
+ <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
+ <xsl:when test="contains(@depth,'%')">
+ <xsl:value-of select="@depth"/>
+ </xsl:when>
+ <xsl:when test="@depth">
+ <xsl:call-template name="length-spec">
+ <xsl:with-param name="length" select="@depth"/>
+ <xsl:with-param name="default.units" select="'px'"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>auto</xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="image.content.width">
+ <xsl:param name="scalefit" select="0"/>
+ <xsl:param name="scale" select="'1.0'"/>
+
+ <xsl:choose>
+ <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
+ <xsl:when test="contains(@contentwidth,'%')">
+ <xsl:value-of select="@contentwidth"/>
+ </xsl:when>
+ <xsl:when test="@contentwidth">
+ <xsl:call-template name="length-spec">
+ <xsl:with-param name="length" select="@contentwidth"/>
+ <xsl:with-param name="default.units" select="'px'"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="number($scale) != 1.0">
+ <xsl:value-of select="$scale * 100"/>
+ <xsl:text>%</xsl:text>
+ </xsl:when>
+ <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
+ <xsl:otherwise>auto</xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="image.content.height">
+ <xsl:param name="scalefit" select="0"/>
+ <xsl:param name="scale" select="0"/>
+
+ <xsl:choose>
+ <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
+ <xsl:when test="contains(@contentdepth,'%')">
+ <xsl:value-of select="@contentdepth"/>
+ </xsl:when>
+ <xsl:when test="@contentdepth">
+ <xsl:call-template name="length-spec">
+ <xsl:with-param name="length" select="@contentdepth"/>
+ <xsl:with-param name="default.units" select="'px'"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="number($scale) != 1.0">
+ <xsl:value-of select="$scale * 100"/>
+ <xsl:text>%</xsl:text>
+ </xsl:when>
+ <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
+ <xsl:otherwise>auto</xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="image.align">
+ <xsl:value-of select="@align"/>
+</xsl:template>
+
+<xsl:template name="image.valign">
+ <xsl:choose>
+ <xsl:when test="@valign = 'top'">before</xsl:when>
+ <xsl:when test="@valign = 'middle'">center</xsl:when>
+ <xsl:when test="@valign = 'bottom'">after</xsl:when>
+ <xsl:otherwise>auto</xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
<xsl:template name="process.image">
<!-- When this template is called, the current node should be -->
<!-- a graphic, inlinegraphic, imagedata, or videodata. All -->
<!-- those elements have the same set of attributes, so we can -->
<!-- handle them all in one place. -->
+ <!-- Compute each attribute value with its own customizable template call -->
<xsl:variable name="scalefit">
- <xsl:choose>
- <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
- <xsl:when test="@contentwidth">0</xsl:when>
- <xsl:when test="@contentdepth and
- @contentdepth != '100%'">0</xsl:when>
- <xsl:when test="@scale">0</xsl:when>
- <xsl:when test="@scalefit"><xsl:value-of select="@scalefit"/></xsl:when>
- <xsl:when test="@width or @depth">1</xsl:when>
- <xsl:when test="$default.image.width != ''">1</xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
+ <xsl:call-template name="image.scalefit"/>
</xsl:variable>
<xsl:variable name="scale">
- <xsl:choose>
- <xsl:when test="$ignore.image.scaling != 0">0</xsl:when>
- <xsl:when test="@contentwidth or @contentdepth">1.0</xsl:when>
- <xsl:when test="@scale">
- <xsl:value-of select="@scale div 100.0"/>
- </xsl:when>
- <xsl:otherwise>1.0</xsl:otherwise>
- </xsl:choose>
+ <xsl:call-template name="image.scale"/>
</xsl:variable>
<xsl:variable name="filename">
- <xsl:choose>
- <xsl:when test="local-name(.) = 'graphic'
- or local-name(.) = 'inlinegraphic'">
- <!-- handle legacy graphic and inlinegraphic by new template -->
- <xsl:call-template name="mediaobject.filename">
- <xsl:with-param name="object" select="."/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <!-- imagedata, videodata, audiodata -->
- <xsl:call-template name="mediaobject.filename">
- <xsl:with-param name="object" select=".."/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
+ <xsl:call-template name="image.filename"/>
</xsl:variable>
- <xsl:variable name="content-type">
- <xsl:if test="@format">
- <xsl:call-template name="graphic.format.content-type">
- <xsl:with-param name="format" select="@format"/>
- </xsl:call-template>
- </xsl:if>
+ <xsl:variable name="src">
+ <xsl:call-template name="image.src">
+ <xsl:with-param name="filename" select="$filename"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="content.type">
+ <xsl:call-template name="image.content.type"/>
</xsl:variable>
<xsl:variable name="bgcolor">
- <xsl:call-template name="pi.dbfo_background-color">
- <xsl:with-param name="node" select=".."/>
+ <xsl:call-template name="image.bgcolor"/>
+ </xsl:variable>
+
+ <xsl:variable name="width">
+ <xsl:call-template name="image.width"/>
+ </xsl:variable>
+
+ <xsl:variable name="height">
+ <xsl:call-template name="image.height"/>
+ </xsl:variable>
+
+ <xsl:variable name="content.width">
+ <xsl:call-template name="image.content.width">
+ <xsl:with-param name="scalefit" select="$scalefit"/>
+ <xsl:with-param name="scale" select="$scale"/>
</xsl:call-template>
</xsl:variable>
- <fo:external-graphic>
- <xsl:attribute name="src">
- <xsl:call-template name="fo-external-image">
- <xsl:with-param name="filename">
- <xsl:if test="$img.src.path != '' and
- not(starts-with($filename, '/')) and
- not(contains($filename, '://'))">
- <xsl:value-of select="$img.src.path"/>
- </xsl:if>
- <xsl:value-of select="$filename"/>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:attribute>
+ <xsl:variable name="content.height">
+ <xsl:call-template name="image.content.height">
+ <xsl:with-param name="scalefit" select="$scalefit"/>
+ <xsl:with-param name="scale" select="$scale"/>
+ </xsl:call-template>
+ </xsl:variable>
- <xsl:attribute name="width">
- <xsl:choose>
- <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
- <xsl:when test="contains(@width,'%')">
- <xsl:value-of select="@width"/>
- </xsl:when>
- <xsl:when test="@width and not(@width = '')">
- <xsl:call-template name="length-spec">
- <xsl:with-param name="length" select="@width"/>
- <xsl:with-param name="default.units" select="'px'"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="not(@depth) and $default.image.width != ''">
- <xsl:call-template name="length-spec">
- <xsl:with-param name="length" select="$default.image.width"/>
- <xsl:with-param name="default.units" select="'px'"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>auto</xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
+ <xsl:variable name="align">
+ <xsl:call-template name="image.align"/>
+ </xsl:variable>
- <xsl:attribute name="height">
- <xsl:choose>
- <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
- <xsl:when test="contains(@depth,'%')">
- <xsl:value-of select="@depth"/>
- </xsl:when>
- <xsl:when test="@depth">
- <xsl:call-template name="length-spec">
- <xsl:with-param name="length" select="@depth"/>
- <xsl:with-param name="default.units" select="'px'"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>auto</xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
+ <xsl:variable name="valign">
+ <xsl:call-template name="image.valign"/>
+ </xsl:variable>
- <xsl:attribute name="content-width">
- <xsl:choose>
- <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
- <xsl:when test="contains(@contentwidth,'%')">
- <xsl:value-of select="@contentwidth"/>
- </xsl:when>
- <xsl:when test="@contentwidth">
- <xsl:call-template name="length-spec">
- <xsl:with-param name="length" select="@contentwidth"/>
- <xsl:with-param name="default.units" select="'px'"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="number($scale) != 1.0">
- <xsl:value-of select="$scale * 100"/>
- <xsl:text>%</xsl:text>
- </xsl:when>
- <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
- <xsl:otherwise>auto</xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
+ <xsl:variable name="element.name">
+ <xsl:choose>
+ <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
+ <xsl:text>fo:instream-foreign-object</xsl:text>
+ </xsl:when>
+ <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
+ <xsl:text>fo:instream-foreign-object</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>fo:external-graphic</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
- <xsl:attribute name="content-height">
- <xsl:choose>
- <xsl:when test="$ignore.image.scaling != 0">auto</xsl:when>
- <xsl:when test="contains(@contentdepth,'%')">
- <xsl:value-of select="@contentdepth"/>
- </xsl:when>
- <xsl:when test="@contentdepth">
- <xsl:call-template name="length-spec">
- <xsl:with-param name="length" select="@contentdepth"/>
- <xsl:with-param name="default.units" select="'px'"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="number($scale) != 1.0">
- <xsl:value-of select="$scale * 100"/>
- <xsl:text>%</xsl:text>
- </xsl:when>
- <xsl:when test="$scalefit = 1">scale-to-fit</xsl:when>
- <xsl:otherwise>auto</xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
+ <xsl:element name="{$element.name}">
- <xsl:if test="$content-type != ''">
+ <xsl:if test="$src != ''">
+ <xsl:attribute name="src">
+ <xsl:value-of select="$src"/>
+ </xsl:attribute>
+ </xsl:if>
+
+ <xsl:if test="$width != ''">
+ <xsl:attribute name="width">
+ <xsl:value-of select="$width"/>
+ </xsl:attribute>
+ </xsl:if>
+
+ <xsl:if test="$height != ''">
+ <xsl:attribute name="height">
+ <xsl:value-of select="$height"/>
+ </xsl:attribute>
+ </xsl:if>
+
+ <xsl:if test="$content.width != ''">
+ <xsl:attribute name="content-width">
+ <xsl:value-of select="$content.width"/>
+ </xsl:attribute>
+ </xsl:if>
+
+ <xsl:if test="$content.height != ''">
+ <xsl:attribute name="content-height">
+ <xsl:value-of select="$content.height"/>
+ </xsl:attribute>
+ </xsl:if>
+
+ <xsl:if test="$content.type != ''">
<xsl:attribute name="content-type">
- <xsl:value-of select="concat('content-type:',$content-type)"/>
+ <xsl:value-of select="concat('content-type:',$content.type)"/>
</xsl:attribute>
</xsl:if>
</xsl:attribute>
</xsl:if>
- <xsl:if test="@align">
+ <xsl:if test="$align != ''">
<xsl:attribute name="text-align">
- <xsl:value-of select="@align"/>
+ <xsl:value-of select="$align"/>
</xsl:attribute>
</xsl:if>
- <xsl:if test="@valign">
+ <xsl:if test="$valign != ''">
<xsl:attribute name="display-align">
- <xsl:choose>
- <xsl:when test="@valign = 'top'">before</xsl:when>
- <xsl:when test="@valign = 'middle'">center</xsl:when>
- <xsl:when test="@valign = 'bottom'">after</xsl:when>
- <xsl:otherwise>auto</xsl:otherwise>
- </xsl:choose>
+ <xsl:value-of select="$valign"/>
</xsl:attribute>
</xsl:if>
- </fo:external-graphic>
+
+ <!-- copy literal SVG elements to output -->
+ <xsl:if test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
+ <xsl:call-template name="process.svg"/>
+ </xsl:if>
+
+ <xsl:if test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
+ <xsl:call-template name="process.mml"/>
+ </xsl:if>
+
+ </xsl:element>
</xsl:template>
<!-- ==================================================================== -->
<xsl:copy/>
</xsl:template>
+<xsl:template name="process.mml">
+ <xsl:apply-templates mode="copy-all" select="*"/>
+</xsl:template>
+
+<xsl:template name="process.svg">
+ <xsl:apply-templates mode="copy-all" select="*"/>
+</xsl:template>
+
<!-- ==================================================================== -->
<xsl:template match="imagedata">
- <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
- <xsl:variable name="filename">
- <xsl:call-template name="mediaobject.filename">
- <xsl:with-param name="object" select=".."/>
- </xsl:call-template>
- </xsl:variable>
-
<xsl:choose>
- <xsl:when test="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
- <xsl:apply-templates/>
- </xsl:when>
-
- <xsl:when test="svg:*" xmlns:svg="http://www.w3.org/2000/svg">
- <fo:instream-foreign-object>
- <xsl:apply-templates mode="copy-all" select="*"/>
- </fo:instream-foreign-object>
- </xsl:when>
-
<xsl:when test="@format='linespecific'">
+ <xsl:variable name="vendor" select="system-property('xsl:vendor')"/>
+
+ <xsl:variable name="filename">
+ <xsl:call-template name="mediaobject.filename">
+ <xsl:with-param name="object" select=".."/>
+ </xsl:call-template>
+ </xsl:variable>
+
<xsl:choose>
<xsl:when test="$use.extensions != '0'
and $textinsert.extension != '0'">