You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Ondra Nekola <on...@twin.jikos.cz> on 2004/07/27 11:40:42 UTC
FOP in tomcat servlet - path to fonts
I'm using FOP in a home-written tomcat servlet.
The core of my java code looks like this:
InputStream in =
getClass().getResourceAsStream("/component/resources/fopconfig.xml");
try {
Options options = new Options(in);
} catch (Exception e1) {
...
}
Driver driver = new Driver(new InputSource(new StringReader(myXmlString)),
response.getOutputStream());
...
driver.setRenderer(Driver.RENDER_PDF);
try {
driver.run();
} catch (Exception e) {
...
}
I have a custom fopconfig.xml, because I need to use local fonts. This
configuration is placed in the ..myApp\WEB-INF\classes\component\resources
directory. In the same directory there is myFont.xml - xml metrics of my
font.
The only change to the configuration is this:
<font
metrics-file="file:///projekty/projekt/WEB-INF/classes/component/resources/timescs.xml"
kerning="yes" embed-file="C:\WINNT\Fonts\times.ttf">
<font-triplet name="TimesCS" style="normal" weight="normal" />
<font-triplet name="TimesCS" style="normal" weight="bold" />
</font>
This configuration works ok. But it seems impossible to change
filesystem paths to relative ones - the font metrics aren't found.
I use 1.4.2_04-b05, Apache Tomcat/5.0.24, Windows 2000 x86, and FOP
0.20.5. I have found the same problem in the history of this conference
several years ago - it was said to be bug of FOP. Is this still bug in FOP
or do I do something wrong?
--
S pozdravem
Ondrej Nekola
ondra@matfyz.cz
http://www.matfyz.cz/ondra
ICQ# 160692888
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
Partial solution: FOP in tomcat servlet - path to fonts
Posted by Ondra Nekola <on...@twin.jikos.cz>.
The problem seems to be caused mainly by the fact, that working direcory
is set to some obscure directory ($CATALINA_HOME/bin/ in
my case) in the container, so relative paths are relative to the middle of
nowhere and not to a well defined point inside the application.
OK, I have found a partial solution. I have changed code for the
org.apache.fop.tools.URLBuilder.buildURL(String s), so it can use a
special format of URL in form resource:/my/direcory/file. The method now
looks like this:
if (spec == null)
throw new NullPointerException("spec must not be null");
File f = new File(spec);
if (f.exists()) {
return f.toURL();
}
if (spec.startsWith("resource:")) {
URL result = URLBuilder.class.getResource(spec.replaceFirst("resource:", ""));
if (result != null)
return result;
}
URL u1 = new URL(spec);
return u1;
This "solution" isn't perfect, but someone other can find it usefull for
purpose of his own.
> I'm using FOP in a home-written tomcat servlet.
....
>
> <font
> metrics-file="file:///projekty/projekt/WEB-INF/classes/component/resources/timescs.xml"
> kerning="yes" embed-file="C:\WINNT\Fonts\times.ttf">
> <font-triplet name="TimesCS" style="normal" weight="normal" />
> <font-triplet name="TimesCS" style="normal" weight="bold" />
> </font>
>
...
> This configuration works ok. But it seems impossible to change
> filesystem paths to relative ones - the font metrics aren't found.
>
--
S pozdravem
Ondrej Nekola
ondra@matfyz.cz
http://www.matfyz.cz/ondra
ICQ# 160692888
PS: The font configuration now looks like this:
<font metrics-file="resource:/module/resources/timescs.xml"
kerning="yes" embed-file="resource:/module/resources/times.ttf">
<font-triplet name="TimesCS" style="normal" weight="normal" />
<font-triplet name="TimesCS" style="normal" weight="bold" />
</font>
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org
Re: FOP in tomcat servlet - path to fonts
Posted by "J.Pietschmann" <j3...@yahoo.de>.
Ondra Nekola wrote:
> This configuration works ok. But it seems impossible to change
> filesystem paths to relative ones - the font metrics aren't found.
There is a fontBaseURL for setting a base URL for
resolving relative paths to font metrics files.
I think it should be possible to create an Options
object, then set the fontBaseURL to whatever
"/" resolves in your servlet.
J.Pietschmann
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org