SVG Fonts.
You can use SVG Fonts to calculate text width and text height.
This can all be done with XSLT. You load the external SVG Font
document into a variable <xsl:variable name="myDisplayFont"
select="document('mySvgFontFile.svg')"/>. The do an xpath into the
svg font based on whatever character
<xsl:template name="calculateWidth">
<xsl:param name="text" select="''"/>
<xsl:param name="width" select="0"/>
<xsl:choose>
<xsl:when test="$text != ''">
<xsl:variable name="firstChar" select="substring($text,1,1)"/>
<xsl:variable name="charWidth" select="$myDisplayFont/fooFont[
@char=$firstChar ]/@width"/>
<xsl:call-template name="">
<xsl:with-param name="text" select="substring($text,2)"/>
<xsl:with-param name="width" select="$width +
number($charWidth)"/>
</xsl:call-template/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$width"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
My char width select isn't correct but you can figure that out when
you look at the svg font file. What you can then do is when you
calculate out the width of the text, you can then wrap it manually
with tspans by looping along the text then when you hit your line
width, break it using the following trick:
<xsl:text disable-output-escaping="yes"></tspan><tspan dy="1em"
x="0"></xsl:text>
Breaks the xslt processing model but its a nice hack. Then getting
the height is super easy: just take the total width of the text and
divide it by the line width, multiply the ceiling of this by your font
height and boom you gots your width/height of the box.
Have fun.
Alastair
--- In [email protected], "redsoftfab" <[EMAIL PROTECTED]>
wrote:
>
> Dear All,
>
> I am trying to use XSLT to render some models (HL7 MIF) into an SVG
> diagram.
>
> Model elements (an act/entity/relationships are shown on the diagram
> as nice straightforward coloured squares or large arrows (i.e. a
> coloured rectangle where one end is pointy/a triangle).
>
> I can draw these shapes happily etc but then obviously each model
> contains textual information which is shown in the shape.
>
> What I am wondering is anyone knows of any XSLT/Method etc for making
> sure the shape is big enough etc to fit the text.
>
> i.e. imagine I have a square/rectangle. Now i add x text elements of
> varying length. How do I make sure the width is sufficient to cope
> with the longest piece of text & the height is sufficient to cope with
> the number of text elements I have added one below the other e.g. draw
> a square to fit something like:
>
>
> Some Text
> Some More Text
> Some really really long piece of text
> Some text
> some text
>
>
>
> etc.
>
> TIA
>
> Adam
>
-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my
membership"
----
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/svg-developers/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/