xsl-list
[Top] [All Lists]

RE: [xsl] Using Java in XSLT to determine font metrics

2008-12-22 12:18:32

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/


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