xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gregory Buchenberger <gr...@eightfoldconsulting.com>
Subject Re: Relative path to font directory
Date Thu, 17 Dec 2009 21:39:49 GMT
Thanks for your reply. I've tried that. It sort-of works because my Java
project is in my home folder. In other words, <font-base>./</font-base>
points to /home/greg (I'm on linux). I've set FOP to look for fonts
recursively and so it finds them there. However, if I move the
application somewhere else with the font folder out of my home directory
it fails to find the fonts. What's odd is that the behavior is different
on Windows Vista. Can anyone shed some light on the issue? I would like
my app to be portable. How can I make my font base the application
folder?

fopFactory.setUserConfig(new File(jarDir, "conf/fopconf.xml")) works
just fine but fopFactory.setFontBaseURL("file:///"+jarDir); doesn't.

On Thu, 2009-12-17 at 12:07 +0000, Venkat Reddy wrote:
> Hi,
> 
> Have you tried the following?
> 
> <!-- Base URL for resolving relative URLs -->
> <base>./</base>
> <!-- Font Base URL for resolving relative font URLs -->
> <font-base>./</font-base>
> 
> Source:
> http://xmlgraphics.apache.org/fop/trunk/configuration.html#general-elements
> 
> Thanks,
> Venkat.
> 
> 
> 
> Gregory Buchenberger wrote:
> > I'm embedding FOP version 627324 (trunk) in a Java application and
> am
> > trying to register a font directory using the configuration file and
> > the method fopFactory.setFontBaseURL(). The font directory is in the
> > same parent directory as the jar file. The jar file directory
> > basically looks like this (using indentation to represent folder
> > hierarchy) :
> >
> > MyJar.jar
> > conf/
> >     fopconf.xml
> > xml/
> >     xslt/
> >         mystylesheet.xsl
> >         includes/
> > lib/
> >     fop.jar
> > fonts/
> >     dejavu-ttf-2.30/
> >         DejaVuSans.ttf
> >
> > The file conf/fopconf.xml contains the following:
> >
> > <?xml version="1.0"?>
> > <fop version="1.0">
> >   <renderers>
> >     <renderer mime="application/pdf">
> >       <fonts>
> >         <directory recursive="true">./fonts</directory>
> >       </fonts>
> >     </renderer>
> >   </renderers>
> > </fop>
> >
> > The class in my Java code that interacts with FOP contains this:
> >
> > public class XMLConverter {
> >
> >     private Logger logger =
> Logger.getLogger(this.getClass().getName());
> >     private File xmlFile;
> >     private File xsltFile;
> >     private FopFactory fopFactory;
> >
> >      public XMLConverter(File xmlfile, File xsltfile) {
> >         this.xmlFile = xmlfile;
> >         this.xsltFile = xsltfile;
> >         initFopFactory();
> >     }
> >
> >      private void initFopFactory() {
> >         try {
> >             File jarFile = new File
> >
> (MainFrame.class.getProtectionDomain().getCodeSource().getLocation().getPath().toString());
> >             String jarDir = jarFile.getParent();
> >             String xmlDir = xmlFile.getParent();
> >             this.fopFactory = FopFactory.newInstance();
> >             fopFactory.setUserConfig(new File(jarDir,
> "conf/fopconf.xml"));
> >             fopFactory.setFontBaseURL("file:///"+jarDir);
> >             fopFactory.setBaseURL("file:///"+xmlDir);
> >         } catch (Exception ex) {
> >             logger.severe(ex.getMessage());
> >         }
> >     }
> >
> > ..........
> >
> > The setUserConfig() and setBaseURL() methods seem to work as
> expected.
> > I've tried using the following to my FOP configuration file as well.
> >
> > <font-base>../</font-base>
> >
> > The only way I can get it to work is by using an absolute path in
> the
> > config , like so:
> >
> > <?xml version="1.0"?>
> > <fop version="1.0">
> >   <renderers>
> >     <renderer mime="application/pdf">
> >       <fonts>
> >         <directory
> >
> recursive="true">/home/greg/NetBeansProjects/NIMAS2PDF/dist/fonts</directory>
> >       </fonts>
> >     </renderer>
> >   </renderers>
> > </fop>
> >
> > Have any of you any idea what stupid thing I am doing wrong here?
> > While it's possible to obtain an absolute path via interaction with
> > the user, I would prefer to store at least a base set of fonts
> within
> > the jar directory that is installed with the application.
> >
> > Kind Regards,
> >
> > Gregory Buchenberger
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail:
> fop-users-help@xmlgraphics.apache.org
> >
> >
> >   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Mime
View raw message