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

RE: Using Java in XSLT to determine font metrics

Subject: RE: Using Java in XSLT to determine font metrics
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 22 Dec 2008 17:18:00 -0000
RE:  Using Java in XSLT to determine font metrics
> I think I found the method getFontMetrics(font) in Java class 
> java.awt.Graphics 
> http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html

You would be less likely to confuse your readers if you changed the
namespace prefix from FontMetrics to Graphics.

> 
> I added -TJ as a parameter but I'm not convinced <oXygen/> is 
> paying attention to it.
> 
> My error message now seems to be the result of my incorrect 
> use of the method:
> 
> Error in call to extension function {public 
> java.awt.FontMetrics java.awt.Graphics.getFontMetrics()}: 
> Cannot convert supplied XPath value to the required type for 
> the extension function.
> 
> I have tried several values for $font as well as placing the 
> font name directly in the parameter list with the same result.

The method is not static, so you will need to create an instance of
java.awt.Graphics and supply it as your first argument. Since it is an
abstract class, you can't do this directly: presumably there is a static
factory method somewhere.

The second argument needs to be an instance of java.awt.Font, whereas you
are supplying a string.

Note that when the Java logic starts to become complex and to involve
several intermediate steps, it's often best to write the method you actually
want in user-written Java code to hide the complexity, so that it becomes a
single function call from the stylesheet.

Michael Kay
http://www.saxonica.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.