在SVG中解析图像的通用解决方案
问题描述:
我有一个需要在pdf文件中可视化的xml文件。 我使用xslt在pdf中进行转换和svg图像。在SVG中解析图像的通用解决方案
svg将最终绘制一些信息,并显示一个tiff图像,路径和分辨率位于xml文件中。 问题是,图像可以有不同的分辨率,我需要适应相同的盒装区域。我确实有这个决议,我有两个不同的决议,但第三个决议不起作用。所以我需要的是更通用的解决方案。
在这个moent我有以下代码绘制TIFF图像中的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>
我想通了,我需要做的scaleing东西,所以我离开Y轴缩放不变和改变X相应地按比例:
<xsl:variable name="scale_x" select="$horizontal_resolution div $vertical_resolution"/>
由于的SVG变化缩放视图和我需要改变tiff_height_offset变量,以便能够应付变化的规模:
<!-- 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>
所以这些代码似乎适用于某些解决方案,但不是所有。 我希望有人能给我一个解决方案或提示如何使这种通用的各种决议。
答
经过一番深入的研究后,我想出了一个解决方案。 首先,我想通了,也转动改变VIE太多,所以宽度变高度等,所以我不需要在x方向扩展,但在y方向:
<xsl:variable name="scale_y" select="$horizontal_resolution div $vertical_resolution"/>
我不需要改变根据标尺的高度,但宽度:
<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>
,因此图像的绘制,现在看起来是这样的:
<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>
现在我能理解所有演算我用几种分辨率测试了它。