Embedding fonts

View: New views
5 Messages — Rating Filter:   Alert me  

Embedding fonts

by Thomas S. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have a problem with embedding fonts while running Apache FOP within a
web application. This seems to be caused by a problem with reading the
font metrics from a jar file.

Obviously FOP can read the configuration from the jar, it also doesn't
complain while starting:

2008-07-02 10:04:04,651 DEBUG org.apache.fop.render.PrintRendererConfigurator (PrintRendererConfigurator.java:123)  - Starting font configuration...
2008-07-02 10:04:04,656 DEBUG org.apache.fop.render.PrintRendererConfigurator (PrintRendererConfigurator.java:318)  - Adding font jar:file:/var/lib/cm4all/tomcat6/base/billy/webapps/CMAdmin/WEB-INF/lib/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/News_Gothic_MT.ttf, metric file jar:file:/var/lib/cm4all/tomcat6/base/billy/webapps/CMAdmin/WEB-INF/lib/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/ttfnewsgothic.xml
2008-07-02 10:04:04,657 DEBUG org.apache.fop.render.PrintRendererConfigurator (PrintRendererConfigurator.java:322)  -   Font triplet NewsGothicMT, normal, 400
2008-07-02 10:04:04,657 DEBUG org.apache.fop.render.PrintRendererConfigurator (PrintRendererConfigurator.java:318)  - Adding font jar:file:/var/lib/cm4all/tomcat6/base/billy/webapps/CMAdmin/WEB-INF/lib/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/News_Gothic_MT_Bold.ttf, metric file jar:file:/var/lib/cm4all/tomcat6/base/billy/webapps/CMAdmin/WEB-INF/lib/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/ttfnewsgothicbold.xml
2008-07-02 10:04:04,658 DEBUG org.apache.fop.render.PrintRendererConfigurator (PrintRendererConfigurator.java:322)  -   Font triplet NewsGothicMT, normal, 700
2008-07-02 10:04:04,659 DEBUG org.apache.fop.render.PrintRendererConfigurator (PrintRendererConfigurator.java:318)  - Adding font jar:file:/var/lib/cm4all/tomcat6/base/billy/webapps/CMAdmin/WEB-INF/lib/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/News_Gothic_MT_Italic.ttf, metric file jar:file:/var/lib/cm4all/tomcat6/base/billy/webapps/CMAdmin/WEB-INF/lib/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/ttfnewsgothicitalic.xml
2008-07-02 10:04:04,660 DEBUG org.apache.fop.render.PrintRendererConfigurator (PrintRendererConfigurator.java:322)  -   Font triplet NewsGothicMT, italic, 400
2008-07-02 10:04:04,660 DEBUG org.apache.fop.render.PrintRendererConfigurator (PrintRendererConfigurator.java:203)  - Finished font configuration in 8ms
2008-07-02 10:04:04,733 DEBUG org.apache.fop.fonts.FontSetup (FontSetup.java:224)  - Registering: NewsGothicMT,normal,400 under F15
2008-07-02 10:04:04,733 DEBUG org.apache.fop.fonts.FontSetup (FontSetup.java:224)  - Registering: NewsGothicMT,normal,700 under F16
2008-07-02 10:04:04,734 DEBUG org.apache.fop.fonts.FontSetup (FontSetup.java:224)  - Registering: NewsGothicMT,italic,400 under F17

Also embedding images from the same jar isn't a problem, but using the
font leads to trouble, the error message in the logfile is:

2008-07-02 10:04:14,068 ERROR org.apache.fop.fo.FOTreeBuilder (FOTreeBuilder.java:229)  - javax.xml.transform.TransformerException: java.lang.RuntimeException: Cannot load font: failed to create Source from metrics file jar:file:/var/lib/cm4all/tomcat6/base/billy/webapps/CMAdmin/WEB-INF/lib/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/ttfnewsgothic.xml

Running FOP having the font metrics as a normal file works perfectly,
but for productive usage this isn't very helpful.

I would be very grateful, if someone has an idea to get this working!

Kind regards,
Thomas

Re: Embedding fonts

by J.Pietschmann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thomas S. wrote:
> I have a problem with embedding fonts while running Apache FOP within a
> web application. This seems to be caused by a problem with reading the
> font metrics from a jar file.

Which FOP version are you using?

> java.lang.RuntimeException: Cannot load font: failed to create Source from
> metrics file
> jar:file:/var/lib/ [snip]
The embedded file URL ist malformed, maybe the recursive URL resolver
doesn't like this. Try jar:file:///var/lib/... and check whether this
helps.

J.Pietschmann

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


Re: Embedding fonts

by Thomas S. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

J.Pietschmann wrote:
Which FOP version are you using?
I'm using 0.94, but I tried this also with 0.95b, which gives me the same result!

J.Pietschmann wrote:
 
> java.lang.RuntimeException: Cannot load font: failed to create Source from
> metrics file
> jar:file:/var/lib/ [snip]
The embedded file URL ist malformed, maybe the recursive URL resolver
doesn't like this. Try jar:file:///var/lib/... and check whether this
helps.
I use Classloader.getSystemResource() to get a URL to a directory
containing the resources used within the XSL-FO. This directory is used
both as baseURL and as fontBaseURL. Including images works, but the
fonts causing the problem already described.

I can't deliver more information right now, especially which URL is used
as baseURL / fontBaseURL and which image URLs are include
successfully, but I will be back in the office on wednesday and I will post
more information then.

Re: Embedding fonts

by Thomas S. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

J.Pietschmann wrote:
> java.lang.RuntimeException: Cannot load font: failed to create Source from
> metrics file
> jar:file:/var/lib/ [snip]
The embedded file URL ist malformed, maybe the recursive URL resolver
doesn't like this. Try jar:file:///var/lib/... and check whether this
helps.
Now some more information. To ease the reading, I replaced the path to the JAR file with "path"!

The URL I'm setting as baseURL and fontBaseURL is
jar:file:/path/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/

This is the URL I'm getting from
   this.getClass().getClassLoader().getResource(baseURLString);
for the argument "layouts/LIVINGNET_2008_06_05/", so I think that this should be a valid URL.
And as already written: Reading the configuration and including images works with this URL.

But I tried it with the suggested URL, unfortunately with the same error:

2008-07-09 09:45:06,928 [btpool0-0] ERROR org.apache.fop.fo.FOTreeBuilder.fatalError(FOTreeBuilder.java:229) - javax.xml.transform.TransformerException: java.lang.RuntimeException: Cannot load font: failed to create Source from metrics file jar:file:///path/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/ttfnewsgothic.xml

So what else can I do?


Embedding fonts from JAR: Bug in FOURIResolver.resolve() ?

by Thomas S. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

J.Pietschmann wrote:
> java.lang.RuntimeException: Cannot load font: failed to create Source from
> metrics file
> jar:file:/var/lib/ [snip]
The embedded file URL ist malformed, maybe the recursive URL resolver
doesn't like this. Try jar:file:///var/lib/... and check whether this
helps.
Ok, now I stepped down into the  code of FOP 0.94...

Loading the configuration and images uses relative URLs,
in FOURIResolver.resolve(String href, String base) we see
  href="fonts/News_Gothic_MT.ttf" and
  base="jar:file:/path/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/"
as an example.

But laterly while FO-Processing, FOURIResolver.resolve(String href, String base) is
indirectly called from LazyFont.load() line: 79, now href is an absolute URL.

So FOURIResolver.resolve(String href, String base) is called with
href="jar:file:/path/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/ttfnewsgothic.xml"
and  base="jar:file:/path/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/"

The problem is, that lines 194-196 remove "jar:" from href, and we run into the problem,
that  in line 208 new URL(URL basURL, String href) is called with  a href still containing a
protocol (file:), which is different from the protocol of the baseURL (jar:), so
  absoluteURL = new URL(baseURL, href);
sets
absoluteURL=file:/path/CMBilling-0.0.1-SNAPSHOT.jar!/layouts/LIVINGNET_2008_06_05/fonts/ttfnewsgothic.xml.

This URL doesn't work, of course, it's is missing the proper protocol specification (jar:)!
Who can I talk to for getting around this problem?
LightInTheBox - Buy quality products at wholesale price