views:

233

answers:

1

I have an xml file which I need to visualize in a pdf file. I use xslt to do transformations and an svg image in the pdf.

The svg will finally draw some information and also display a tiff image, for which the path and the resolution is in the xml file. The problem is that the image can have different resolutions which I need to fit into the same boxed area. I do have the resolution and I have it working for two different resolutions, but a third resolution doesn't work. So what I need is a more generic solution.

At this moent I have the following code to draw the tiff image in the svg:

<!-- Draw the tiff image -->
<svg:g transform="translate({$svg_image_width_first},
                            {$svg_image_height_first})">
    <svg:g transform="rotate({$tiff_rotation})">
        <svg:g transform="scale({$scale_x} 1)">
            <svg:image xlink:href="{$xml_bitmap_path}"
                                x="{$tiff_height_offset}"
                                y="{$tiff_width_offset}"
                                width="{$svg_image_height}"
                                height="{$svg_image_width}">
                <svg:title>Front Image</svg:title>
            </svg:image>
        </svg:g>  
    </svg:g>
</svg:g>

I figured out that I need to do something with the scaleing so I leave the y scaling constant and alter the x scaling accordingly:

<xsl:variable name="scale_x" select="$horizontal_resolution div $vertical_resolution"/>

Due to the scaling the view of the svg changes and I need to alter the tiff_height_offset variable to be able to cope with the changes in the scale:

<!-- After rotation place of the image should be corrected-->
<xsl:variable name="tiff_height_offset">
    <xsl:choose>
        <xsl:when test="$tiff_rotation = '-90'">
            <xsl:value-of select="0 - (($svg_image_height + ($svg_image_height * (1 div $scale_x )))div $scale_x)"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="0"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>

So these pieces of code seem to work for some resolutions but not for all. I hope someone can give me a solution or hint for how to make this generic for all kinds of resolutions.

A: 

After some extensive deeper look into the problem I figured out a solution. First I figured out that also the rotation changes the vie too, so the width becomes the height etc. So I don't need to scale in the x direction, but in the y direction:

<xsl:variable name="scale_y" select="$horizontal_resolution div $vertical_resolution"/>

And I don't need to alter the height but the width according the scale:

<xsl:variable name="tiff_width_offset">
  <xsl:choose>
    <xsl:when test="$tiff_rotation = '90'">
      <xsl:value-of select="(0 - $svg_image_width) * $scale_y" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="0"/>
    </xsl:otherwise>
  </xsl:choose>  
</xsl:variable>

So the drawing of the image now looks like this:

<svg:g transform="translate({$svg_image_width_first}, {$svg_image_height_first})">
  <svg:g transform="rotate({$tiff_rotation})">
    <svg:image xlink:href="{$xml_bitmap_path}"
                        x="{$tiff_height_offset}"
                        y="{$tiff_width_offset}"
                        width="{$svg_image_height}"
                        height="{$svg_image_width * $scale_y}"
                        transform="scale(1 {1 div $scale_y})" >
      <svg:title>Front Image</svg:title>
    </svg:image> 
  </svg:g>
</svg:g>

Now I can understand all calculations, and I tested it with several resolutions.

miepmuts