Title: Loading font files from CLASSPATH. FOP 0.20.5 extension proposal

Dear FOP developers/users,

The Problem:
The project I am working on, needs to load the FOP Font related files from CLASSPATH (more exactly from a JAR file in CLASSPATH) in order to embed them in a client (AWT or PDF).

The Tries:
First I tried to configure FOP (in userconfig.xml) in order to achieve these needs. I was not able to get to the expected results. I checked the FOP code (org.apache.fop.tools.URLBuilder.java) and I discovered that FOP 0.20.5 supports the localization of the FOP Font related files by URLs. The building of these URLs is possible to be done only in 2 ways:

(I) from a File Object and
(II) from a base URL Object and a specification String Object.
I found no support for localizing the FOP Font related files using a URL build on the base of a CLASSPATH Loader.

FOP 0.20.5 extension proposal:
For our needs I adjusted only the org.apache.fop.tools.URLBuilder.java class.
Description: In case a URL is not possible to be build up using the 2 existing ways, the URL is build up using Class.getResource(String):URL.

Original Version of the class: $Id: URLBuilder.java,v 1.1.2.2 2003/02/25 15:19:57 jeremias Exp $
------------- ORIGINAL Start -------------
    public static URL buildURL(URL baseURL, String spec) throws MalformedURLException {
        if (spec == null) throw new NullPointerException("spec must not be null");
        try {
            URL u1 = buildURL(spec);
            return u1;
        } catch (MalformedURLException mfue) {
            if (baseURL == null) throw mfue;
            else {
                URL u2 = new URL(baseURL, spec);
                return u2;
            }
        }
    }
------------- ORIGINAL End -------------
------------- MODIFICATIONS Start -------------
    public static URL buildURL(URL baseURL, String spec) throws MalformedURLException {
        if (spec == null) throw new NullPointerException("spec must not be null");
        try {
            URL u1 = buildURL(spec);
            return u1;
        } catch (MalformedURLException mfue) {
            if (baseURL == null) {
                return URLBuilder.class.getResource(spec);
            } else {
                URL u2 = new URL(baseURL, spec);
                return u2;
            }
        }
    }
------------- MODIFICATIONS End -------------
In order these changes to take effect the fontBaseDir must not be configured in userconfig.xml.
------------- userconfig.xml Sample Start -------------
<!-- COMMENTED OUT: fontBaseDir
        <entry>
                <key>fontBaseDir</key>
                <value></value>
        </entry>
-->

        <fonts>
                <font   metrics-file="/test/fonts/Arial.xml"
                        embed-file="/test/fonts/Arial.ttf"
                        kerning="yes">
                    <font-triplet name="Arial" style="normal" weight="normal"/>
                </font>
        ...
        </fonts>
------------- userconfig.xml Sample End -------------


The code adjustments might not follow the best design decisions, what I tried was to keep FOP as much as possible unchanged.

Please correct if I am wrong,

Best Regards,
Alexandru P I Ţ I Ş
Application Developer
EBS Romania S.R.L.

ro - 400118 cluj, str. pavel rosca nr. 9
t       + 40 264 406 460
     + 40 264 406 461
m       + 40 745 138 922
@       alexandru.pitis@ebsromania.ro
i       www.ebsromania.ro

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender.


Reply via email to