You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stephen Winnall <st...@winnall.ch> on 2006/07/05 22:38:47 UTC

SVG serializer renders PNGs to arbitrary width

I am trying to generate PNG text icons from SVG in Cocoon. I just  
want a PNG with no extra
space around the text.

I use the following match in my sitemap and generate the appropriate  
text icon by calling

	1) .../nav2.png?icon-text=abc
	2) .../nav2.png?icon- 
text=Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogoch
	3) ...

<map:match pattern="nav2.png">
	<map:generate src="resources/svg/nav2.svg" type="file" />
	<map:transform src="resources/svg/nav2.xslt">
		<map:parameter name="icon-text" value="{request-param:icon-text}" />
	</map:transform>
	<map:serialize type="svg2png" />
</map:match>





The generated icon should contain the text and nothing else. The  
following is the template I
use (see <map:generate> above).


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
    xmlns:svg="http://www.w3.org/2000/svg"
    xmlns="http://www.w3.org/2000/svg">
   <text />
</svg>




And this is the transformation (see <map:transform> above).


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
version="2.0"
	xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/ 
svg">

	<xsl:param name="icon-text" />

	<xsl:template match="/svg:svg/svg:text">
		<text
			style="font-size:15px;font-style:normal;font-variant:normal;font- 
weight:normal;font-stretch:normal;writing-mode:lr-tb;fill:black;fill- 
opacity:1;font-family:VAG Rounded Std Thin"
			x="0"
			y="15px"
			id="icon-text">
			<xsl:value-of select="$icon-text" />
		</text>
	</xsl:template>

	<xsl:template match="svg:*">
		<xsl:copy>
			<xsl:apply-templates select="*|@*|text()" />
		</xsl:copy>
	</xsl:template>

	<xsl:template match="@*">
		<xsl:copy-of select="." />
	</xsl:template>
	
</xsl:stylesheet>



This all works in principle but the PNGs generated have non- 
predictable widths (with a
variance in height in occasional cases). It is as though the text is  
being padded with
blanks to the right. I can't pass a parameter "height" to the SVG  
serializer because I don't
know how long the rendered text is.

Can anyone point to my error? How can I specify that I want to  
generate a text icon whose
width is defined by the rendered length of the text?


Steve

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: SVG serializer renders PNGs to arbitrary width

Posted by Stephen Winnall <st...@winnall.ch>.
OK, I misrepresented the SVG serializer here... It appears to create  
by default icons of constant
size, namely 111px wide by 32px high. I can modify that by specifying  
that the height of the icon
is to be 15px by adding <map:parameter name="height" value="15"/> to  
the <map:serialize>
element and adding the attribute height="15px" to the <svg> element.

I then get icons which are consistently 60px by 15px, but this is  
still not what I want.

Does noone know a way to crop white space on the left and right sides  
of an image from Cocoon?

The arbitrary widths are still displayed on the web pages so that  
must be down to the rendering
of the HTML by the browsers. Since the problem is present in all the  
browsers I use (on Mac OS X
and Windows), it is presumably a problem with my coding.

Steve

On 5 Jul 2006, at 22:38, Stephen Winnall wrote:

> I am trying to generate PNG text icons from SVG in Cocoon. I just  
> want a PNG with no extra
> space around the text.
>
> I use the following match in my sitemap and generate the  
> appropriate text icon by calling
>
> 	1) .../nav2.png?icon-text=abc
> 	2) .../nav2.png?icon- 
> text=Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogoch
> 	3) ...
>
> <map:match pattern="nav2.png">
> 	<map:generate src="resources/svg/nav2.svg" type="file" />
> 	<map:transform src="resources/svg/nav2.xslt">
> 		<map:parameter name="icon-text" value="{request-param:icon-text}" />
> 	</map:transform>
> 	<map:serialize type="svg2png" />
> </map:match>
>
>
>
>
>
> The generated icon should contain the text and nothing else. The  
> following is the template I
> use (see <map:generate> above).
>
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <svg
>    xmlns:svg="http://www.w3.org/2000/svg"
>    xmlns="http://www.w3.org/2000/svg">
>   <text />
> </svg>
>
>
>
>
> And this is the transformation (see <map:transform> above).
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
> version="2.0"
> 	xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/ 
> 2000/svg">
>
> 	<xsl:param name="icon-text" />
>
> 	<xsl:template match="/svg:svg/svg:text">
> 		<text
> 			style="font-size:15px;font-style:normal;font-variant:normal;font- 
> weight:normal;font-stretch:normal;writing-mode:lr- 
> tb;fill:black;fill-opacity:1;font-family:VAG Rounded Std Thin"
> 			x="0"
> 			y="15px"
> 			id="icon-text">
> 			<xsl:value-of select="$icon-text" />
> 		</text>
> 	</xsl:template>
>
> 	<xsl:template match="svg:*">
> 		<xsl:copy>
> 			<xsl:apply-templates select="*|@*|text()" />
> 		</xsl:copy>
> 	</xsl:template>
>
> 	<xsl:template match="@*">
> 		<xsl:copy-of select="." />
> 	</xsl:template>
> 	
> </xsl:stylesheet>
>
>
>
> This all works in principle but the PNGs generated have non- 
> predictable widths (with a
> variance in height in occasional cases). It is as though the text  
> is being padded with
> blanks to the right. I can't pass a parameter "height" to the SVG  
> serializer because I don't
> know how long the rendered text is.
>
> Can anyone point to my error? How can I specify that I want to  
> generate a text icon whose
> width is defined by the rendered length of the text?
>
>
> Steve
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org