xsl-list
[Top] [All Lists]

RE: [xsl] XSL:FO dynamic font size based on width

2008-06-27 05:41:58
Thank you Dave! I've implemented something similar to what you were
suggesting, but instead the title remains on one line:

I checked how many characters I could safely get in the space then came up
with this formula to auto-fit the text.

      <xsl:attribute name="font-size">
         <xsl:variable name="title">
            <xsl:value-of select="."/>
         </xsl:variable>
         <xsl:choose>
            <xsl:when test="string-length($title) > 28">
               <xsl:value-of select="46 div (string-length($title) div
28)"/>pt
            </xsl:when>
            <xsl:otherwise>46pt</xsl:otherwise>
         </xsl:choose>
      </xsl:attribute>

Initial font size / (length of string / # of safe chars)

The formula is reflective exponential. This means if there are way too many
characters, font size value will be small but will eventually flatten out if
more characters are added, thereby causing an overflow.

In this case I would need about 200+ characters in a string to cause an
overflow at roughly 6pt font size.

..maybe there's a better formula...

Cheers,

WS

-----Original Message-----
From: Dave Pawson [mailto:davep(_at_)dpawson(_dot_)co(_dot_)uk] 
Sent: Thursday, June 26, 2008 8:57 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] XSL:FO dynamic font size based on width

Wasiq Shaikh wrote:
Hello everyone!

Quick question ...

I have a title of a book (fo:block) that needs to be one line on an 8.5in
x
11in page. If the title is too long for the page (overflow), is there a
way
to dynamically decrease the font-size so that the entire title is shown on
one line?

Basically, I'm looking for the exact behaviour of PowerPoint's "AutoFit
Text
to Placeholder" feature.

No. That would require feedback from the rendering engine
to the XSLT. Doesn't happen.

 From use, you might determine that you get x chars
'safely' on the line.
Chop the line up based on that and create a number
of lines.

HTH




regards

-- 
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--