You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Eric Douglas <ed...@blockhouse.com> on 2010/08/06 17:58:55 UTC

Embedding font from jar

I created some embedded code using EmbedFontInfo to load custom font
files into the Renderer setFontList and setupFontInfo methods.
I have a program with embedded Java running on the server which is
working fine for creating a PDF and getting output to a printer.
Now I'm trying to use client Java through Webstart to get the awt
PreviewPanel working and it doesn't like the file path to the fonts.
I'm trying to simplify file references by putting fonts, images in a
jar.  That jar should be on the classpath and the server and client
should be able to reference the files in it the same way.
I recompiled my FOP 0.95 jar to embed those files.  I can put them in a
separate jar if it makes more sense.
Is there a simple way to reference the jar font file from embedded code?
I tried creating an EmbedFontInfo object using
"jar:file:c:/web/public/fop.jar!/Fonts/LTYPEB.TTF" for the embedFile
parameter, and it crashes on the createFont method in the
CustomFontMetricsMapper object.

WARNING: Unable to load custom font from file
'jar:file:c:/web/public/fop.jar!/Fonts/LTYPEB.TTF'
java.io.IOException: Problem reading font data.
	at java.awt.Font.createFont(Unknown Source)
	at
org.apache.fop.render.java2d.CustomFontMetricsMapper.initialize(CustomFo
ntMetricsMapper.java:109)
...

RE: Embedding font from jar

Posted by Eric Douglas <ed...@blockhouse.com>.
If you prefer I can send coding issues to fop-users.  I'm aware of the
auto detect.  I'm just not aware of how it works, if it will find the
file I'm specifically trying to reference or if it might use a search
path which would refer to a different file.  I was trying to pass it a
specific path to the font file I put in a jar rather than use the auto
detection and it doesn't seem to handle specific paths to files inside
jars unless I'm missing something.  It appears the EmbedFileInfo string
path parameter gets used to create a StreamSource for
CustomFontMetricsMapper and doesn't like that StreamSource as a
sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream.


-----Original Message-----
From: Jeremias Maerki [mailto:dev@jeremias-maerki.ch] 
Sent: Tuesday, August 10, 2010 5:21 AM
To: fop-dev@xmlgraphics.apache.org
Subject: Re: Embedding font from jar

Eric,
once again, a post that should have gone to fop-users.

Please see:
http://xmlgraphics.apache.org/fop/latest/fonts.html#autodetect
It will tell you how to create a JAR with fonts that FOP will
automatically detect. No Java code necessary.

On 06.08.2010 17:58:55 Eric Douglas wrote:
> I created some embedded code using EmbedFontInfo to load custom font 
> files into the Renderer setFontList and setupFontInfo methods.
> I have a program with embedded Java running on the server which is 
> working fine for creating a PDF and getting output to a printer.
> Now I'm trying to use client Java through Webstart to get the awt 
> PreviewPanel working and it doesn't like the file path to the fonts.
> I'm trying to simplify file references by putting fonts, images in a 
> jar.  That jar should be on the classpath and the server and client 
> should be able to reference the files in it the same way.
> I recompiled my FOP 0.95 jar to embed those files.  I can put them in 
> a separate jar if it makes more sense.
> Is there a simple way to reference the jar font file from embedded
code?
> I tried creating an EmbedFontInfo object using 
> "jar:file:c:/web/public/fop.jar!/Fonts/LTYPEB.TTF" for the embedFile 
> parameter, and it crashes on the createFont method in the 
> CustomFontMetricsMapper object.
> 
> WARNING: Unable to load custom font from file 
> 'jar:file:c:/web/public/fop.jar!/Fonts/LTYPEB.TTF'
> java.io.IOException: Problem reading font data.
> 	at java.awt.Font.createFont(Unknown Source)
> 	at
> org.apache.fop.render.java2d.CustomFontMetricsMapper.initialize(Custom
> Fo
> ntMetricsMapper.java:109)
> ...




Jeremias Maerki


Re: Embedding font from jar

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Eric,
once again, a post that should have gone to fop-users.

Please see: http://xmlgraphics.apache.org/fop/latest/fonts.html#autodetect
It will tell you how to create a JAR with fonts that FOP will
automatically detect. No Java code necessary.

On 06.08.2010 17:58:55 Eric Douglas wrote:
> I created some embedded code using EmbedFontInfo to load custom font
> files into the Renderer setFontList and setupFontInfo methods.
> I have a program with embedded Java running on the server which is
> working fine for creating a PDF and getting output to a printer.
> Now I'm trying to use client Java through Webstart to get the awt
> PreviewPanel working and it doesn't like the file path to the fonts.
> I'm trying to simplify file references by putting fonts, images in a
> jar.  That jar should be on the classpath and the server and client
> should be able to reference the files in it the same way.
> I recompiled my FOP 0.95 jar to embed those files.  I can put them in a
> separate jar if it makes more sense.
> Is there a simple way to reference the jar font file from embedded code?
> I tried creating an EmbedFontInfo object using
> "jar:file:c:/web/public/fop.jar!/Fonts/LTYPEB.TTF" for the embedFile
> parameter, and it crashes on the createFont method in the
> CustomFontMetricsMapper object.
> 
> WARNING: Unable to load custom font from file
> 'jar:file:c:/web/public/fop.jar!/Fonts/LTYPEB.TTF'
> java.io.IOException: Problem reading font data.
> 	at java.awt.Font.createFont(Unknown Source)
> 	at
> org.apache.fop.render.java2d.CustomFontMetricsMapper.initialize(CustomFo
> ntMetricsMapper.java:109)
> ...




Jeremias Maerki