Re: XSL:FO dynamic font size based on width
On 6/26/08 10:49 AM, "Angela Williams" <Angela.Williams@xxxxxxxxxxxxxxxxxx> 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@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>
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format