[#3719] - Cannot use font extension with relative path to font

Category:
Bug report
Priority:
Urgent
Status:
New
Project: Severity:
Critical
Resolution:
Reopened
Component: Reproducibility:
Always
Assigned to:

I have a custom font (Rockwell) that I want to use in a PDF and ship with my application.
So I created a jasperreport_extension.properties and a fonts.xml file, which points to my rockwell ttf files.

Creating a pdf with my new font works fine as long as in my fonts.xml file, the path to the rockwell ttf fonts is absolute. E.g. "/home/misja/myProject/src/main/resources/rockwell-regular.ttf".
But having absolute file paths is a no-go when shipping my application, so I want to have classpath-relative paths in my fonts.xml. So just "rockwell-regular.ttf".

However when I do this, generating the pdf gives the following error:

...
Caused by: org.springframework.beans.PropertyBatchUpdateException: Failed properties: Property 'normal' threw exception; nested exception is net.sf.jasperreports.engine.JRRuntimeException: java.awt.FontFormatException: bad table, tag=90701824; Property 'bold' threw exception; nested exception is net.sf.jasperreports.engine.JRRuntimeException: java.awt.FontFormatException: bad table, tag=-1078132736
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) ~[spring-beans-3.1.4.RELEASE.jar:3.1.4.RELEASE]
...

I have debugged JasperReports as far as I could, and I can see that the rockwell-regular.ttf file is found and read when it is read from the classpath. But then eventually an Exception is thrown when the Font is about to be created in FontManager.createFont2D

I attached my jasperreports_extension and my fonts file.

AttachmentSize
File fonts.xml711 bytes
Binary Data jasperreports_extension.properties186 bytes
v5.6
malma's picture
4
Joined: Jun 23 2014 - 2:08am
Last seen: 8 years 5 months ago

4 Comments:

#1
  • Assigned:nobody»

Never mind, the problem was not in the relative url but in the fact that I was reading the ttf from the classpath. My ttf's were copied to the target folder by Maven, but I found out that they were modified by Maven as well, because of resource filtering. I had to add the following snippet to my pom.xml, and now classpath urls are working as they should:

<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.ttf</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.ttf</include>
</includes>
</resource>

#2
  • Resolution:Open» No Change Required
  • Status:New» Closed
  • Assigned:» anonymous
#3
  • Resolution:No Change Required» Reopened
  • Status:Closed» New
  • Assigned:nobody»

I face into the same problem. But when I am starting with the IDE, your way works. But when I run from jar, I see that the font was not available to the JVM, but I put custom font. How did you solve this problem when you ran it from the jar?
Can't work on font Roboto.

AttachmentSize
File fonts.xml655 bytes
#4
  • Assigned:nobody» lucianc
Feedback
randomness