RE: [xep-support] scale-when-image-is-too-big

From: Matthias.Belz@Springer.de
Date: Tue Oct 15 2002 - 01:31:58 PDT


> Do you have example code for passing the new image height & width values
to
> the XSL template? Are you using xsl:param & with-param coupled with
> xsl:call-template?

Yes, this is what I use. Here's some code:

My xml data file has this format:

<?xml version="1.0" encoding="UTF-8"?>
<graphics>
  <pic1.jpg>
    <width>6.29</width>
    <height>13.12</height>
  </pic1.jpg>
  <pic2.gif>
    <width>17.76</width>
    <height>2.16</height>
  </pic2.gif>
</graphics>

When I handle graphics, I call the template setScaling...

<fo:external-graphic alignment-baseline="middle">
  <xsl:attribute name="src"><xsl:value-of select="$filename"
/></xsl:attribute>
  <xsl:call-template name="setScaling">
    <xsl:with-param name="filename" select="$filename" />
  </xsl:call-template>
</fo:external-graphic>

...which looks like this:

<xsl:template name="setScaling">
  <xsl:param name="filename" />
  <xsl:variable name="imageWidth">
    <xsl:value-of
select="document($dataFile)//*[name()=$filename]/*[name()='width']" />
  </xsl:variable>
  <xsl:variable name="imageHeight">
    <xsl:value-of
select="document($dataFile)//*[name()=$filename]/*[name()='height']" />
  </xsl:variable>
  <xsl:variable name="xScale">
    <xsl:choose>
      <xsl:when test="number($imageWidth) > number($typeAreaWidth)">
        <xsl:value-of select="100 * number($typeAreaWidth) div
number($imageWidth)" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="100" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="yScale">
    <xsl:choose>
      <xsl:when test="number($imageHeight) > number($typeAreaHeight)">
        <xsl:value-of select="100 * number($typeAreaHeight) div
number($imageHeight)" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="100" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="scale">
    <xsl:choose>
      <xsl:when test="number($yScale) > number($xScale)">
        <xsl:value-of select="$xScale" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$yScale" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:attribute name="content-width"><xsl:value-of select="$scale"
/>%</xsl:attribute>
  <xsl:attribute name="content-height"><xsl:value-of select="$scale"
/>%</xsl:attribute>
</xsl:template>

(Actually this is a simplified version because I support pictures inside
tables as well).

> However, I would like to attract your and other users' attention to the
fact
> that acrobat (or any other pdf/ps interpreter) is usually a poor quality
> performer when it comes to scaling raster images.

For our needs, the image quality is sufficient.

Regards,
Matthias

-- 
Matthias Belz <Matthias.Belz@springer.de>
Electronic Technologies, Springer-Verlag Heidelberg
-------------------
By using the Service, you expressly agree to these Terms of Service http://www.renderx.com/tos.html


This archive was generated by hypermail 2.1.5 : Wed Dec 18 2002 - 08:41:28 PST