[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSL:FO dynamic font size based on width

Subject: Re: XSL:FO dynamic font size based on width
From: Eliot Kimber <ekimber@xxxxxxxxxxxx>
Date: Thu, 26 Jun 2008 16:16:57 -0500
Re:  XSL:FO dynamic font size based on width
On 6/26/08 10:49 AM, "Angela Williams" <Angela.Williams@xxxxxxxxxxxxxxxxxx>

> You can simulate the auto-shrink behavior in your stylesheet.
> I would pre-determine how many characters fit per line when my font size
> is 12pt, how many fit for 10pt, etc. You could use percentages or other
> size units, just be consistent.  Then I would create a template that
> would determine which font size to use based on the number of characters
> in the title.

In the past I have done this by creating an Java XSLT extension that uses
the Java 2D graphics package to determine the approximate rendered length of
a given string in a given font at a given size. It works well enough for
relatively short strings, such as single titles, definition list entries,
and so forth. For longer strings the difference between the Java-determined
length and the length the FO engine will actually use is too variable to be
reliable (you can't use it for good line casting, for example).

For example, I used it to adjust the font size used for examples so that the
longest line of the example content would fit within the available display

With XSL Formatter you could do the trick where you format stuff in
isolation and use the XSL Formatter API to get the rendered details and then
feed that into a second pass. I imagine XEP has similar capabilities. We
used this technique to determine how many pages tables would take up in
order to generate accurate lists of effective pages where the page count had
to include the length of the LOEP table itself.

I don't have access to any example code any more but it wasn't that hard.
You just need to know the font and the size. The actual Java programming
required was just a few lines, if memory serves.



Eliot Kimber | Senior Solutions Architect | Really Strategies, Inc.
email:  ekimber@xxxxxxxxxxxx <mailto:ekimber@xxxxxxxxxxxx>
office: 610.631.6770 | cell: 512.554.9368
2570 Boulevard of the Generals | Suite 213 | Audubon, PA 19403
www.reallysi.com <http://www.reallysi.com>  | http://blog.reallysi.com
<http://blog.reallysi.com> | www.rsuitecms.com <http://www.rsuitecms.com> 

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.