]> granicus.if.org Git - docbook-dsssl/commitdiff
Reworked support for graphic attributes; now support DocBook 4.2CR1 attributes
authorNorman Walsh <ndw@nwalsh.com>
Sun, 12 May 2002 11:15:31 +0000 (11:15 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Sun, 12 May 2002 11:15:31 +0000 (11:15 +0000)
xsl/fo/graphics.xsl

index 412f0c56075c12e1a9a1028fb73cf72942aadd17..333daaad6437ea02b3cada85e79abc4bb683be88 100644 (file)
@@ -73,7 +73,7 @@ FIXME: make is.graphic.* work correctly depending on the backend!
 <!-- Override these templates for FO -->
 <!-- ==================================================================== -->
 
-<xsl:template name="process.image">
+<xsl:template name="X.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 -->
@@ -190,6 +190,165 @@ FIXME: make is.graphic.* work correctly depending on the backend!
   </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.                             -->
+
+  <xsl:variable name="scalefit">
+    <xsl:choose>
+      <xsl:when test="@contentwidth or @contentdepth">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:otherwise>0</xsl:otherwise>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:variable name="scale">
+    <xsl:choose>
+      <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: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:variable>
+
+  <xsl:variable name="bgcolor">
+    <xsl:call-template name="dbfo-attribute">
+      <xsl:with-param name="pis"
+                      select="../processing-instruction('dbfo')"/>
+      <xsl:with-param name="attribute" select="'background-color'"/>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <fo:external-graphic>
+    <xsl:attribute name="src">
+      <xsl:choose>
+        <xsl:when test="$passivetex.extensions != 0
+                        or $fop.extensions != 0
+                        or $arbortext.extensions != 0">
+          <xsl:value-of select="$filename"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="concat('url(', $filename, ')')"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:attribute>
+
+    <xsl:attribute name="width">
+      <xsl:choose>
+        <xsl:when test="contains(@width,'%')">
+          <xsl:value-of select="@width"/>
+        </xsl:when>
+        <xsl:when test="@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:otherwise>auto</xsl:otherwise>
+      </xsl:choose>
+    </xsl:attribute>
+
+    <xsl:attribute name="height">
+      <xsl:choose>
+        <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:attribute name="content-width">
+      <xsl:choose>
+        <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="$scale != 1.0">
+          <xsl:value-of select="$scale * 100"/>
+          <xsl:text>%</xsl:text>
+        </xsl:when>
+        <xsl:otherwise>auto</xsl:otherwise>
+      </xsl:choose>
+    </xsl:attribute>
+
+    <xsl:attribute name="content-height">
+      <xsl:choose>
+        <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="$scale != 1.0">
+          <xsl:value-of select="$scale * 100"/>
+          <xsl:text>%</xsl:text>
+        </xsl:when>
+        <xsl:otherwise>auto</xsl:otherwise>
+      </xsl:choose>
+    </xsl:attribute>
+
+    <xsl:if test="$bgcolor != ''">
+      <xsl:attribute name="background-color">
+        <xsl:value-of select="$bgcolor"/>
+      </xsl:attribute>
+    </xsl:if>
+
+    <xsl:if test="@align">
+      <xsl:attribute name="text-align">
+        <xsl:value-of select="@align"/>
+      </xsl:attribute>
+    </xsl:if>
+
+    <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:attribute>
+    </xsl:if>
+  </fo:external-graphic>
+</xsl:template>
+
 <!-- ==================================================================== -->
 
 <xsl:template match="graphic">