views:

54

answers:

0

I'm using Apache FOP 1.0. The code is running on different servers, so I put the fonts in each server's instance root. My plan is to set the font base programmatically (to the server instance root, plus "/fonts/"), and in my fop configuration file, set font paths relative to this font base. Here's the code snippet that makes the FopFactory:

    private static final String FONT_BASE = System.getProperty("com.sun.aas.instanceRoot") + "/fonts/";

public FOPWrapperBean() throws Exception {
    ClassLoader loader = this.getClass().getClassLoader();
    InputStream fopStream = loader.getResourceAsStream("META-INF/fop.xconf");
    logger.log(Level.FINE, "InputStream: {0}", fopStream.toString());
    DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
    Configuration cfg = cfgBuilder.build(fopStream);
    this.fopFactory = FopFactory.newInstance();
    this.fopFactory.setUserConfig(cfg);
    fopFactory.getFontManager().setFontBaseURL("file://" + FONT_BASE);
    logger.log(Level.FINE, "Font base url: {0}", fopFactory.getFontManager().getFontBaseURL());
    fopStream.close();
}

fop.xconf is almost entirely default. It contains

<base>.</base>

and

<fonts>
    <directory>DejaVuTtf</directory>
</fonts>

(There are several fonts in {instance-root}/fonts/DejaVuTtf , which I can load correctly if I just give an absolute path -- but that doesn't work with having multiple servers, each of which may have different instance root directories).

How do I load in a font with a programmatically-determined path?

Thanks!