xsl-list
[Top] [All Lists]

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

2008-06-26 14:18:13
On 6/26/08 10:49 AM, "Angela Williams" 
<Angela(_dot_)Williams(_at_)the401kcompany(_dot_)com>
wrote:

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
width.

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.

Cheers,

Eliot

----
Eliot Kimber | Senior Solutions Architect | Really Strategies, Inc.
email:  ekimber(_at_)reallysi(_dot_)com <mailto:ekimber(_at_)reallysi(_dot_)com>
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> 


--~------------------------------------------------------------------
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>
--~--