[#3252] - Missing pdf fonts after upgrade to v5.5

Category:
Bug report
Priority:
Normal
Status:
Resolved
Project: Severity:
Major
Resolution:
Fixed
Component: Reproducibility:
Always
Assigned to:
0

After upgrading to latest version the pdf exporter can't find custom fonts. Fonts are in jvm classpath and imported like jars into jasperserver repository.
A tipical error message when a pdf report is generated:
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName : Helvetica pdfEncoding : Identity-H isPdfEmbedded : true

v5.5.0
m.longo's picture
63
Joined: Oct 24 2012 - 4:42am
Last seen: 1 month 3 weeks ago

9 Comments:

#1
  • Assigned:nobody»

Hi,

Can you attach here your font extension JAR? or at least, its XML file.

Thank you,
Teodor

#2
  • Assigned:» anonymous

I also ran into this problem. I fixed it - as far as i can see - by upgrading my xml file of the extension to 5.5.
For this you have to change the xml like this:

<fontFamily name="XXX">
<normal>Normal.ttf</normal>
<bold>Bold.ttf</bold>
...
</fontFamily>

To (mind the additional ttf tags!):

<fontFamily name="XXX">
<normal><ttf>Normal.ttf</ttf></normal>
<bold><ttf>Bold.ttf</ttf></bold>
...
</fontFamily>

Seems like the 5.5 PDF exporter is not downward compatible to older font extensions...

#3

Hi,

Please attach the entire XML of your font extension and also the complete stack trace of the exceptions you get.
If you look at the DejaVu font extension that we ship with JR Libray in /demo/fonts older, you'll see its XML did not change, which is an indication that old XMLs should still work fine.

Thanks,
Teodor

#4
  • Severity:Major» Minor

Hi Teodor,

We used the following font extension XML:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="Comic Sans MS"><!-- Version 5.11 -->
<normal><![CDATA[com/trivadis/corefonts/COMIC.TTF]]></normal>
<bold><![CDATA[com/trivadis/corefonts/COMICBD.TTF]]></bold>
<italic><![CDATA[com/trivadis/corefonts/COMICI.TTF]]></italic>
<boldItalic><![CDATA[com/trivadis/corefonts/COMICZ.TTF]]></boldItalic>
<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
<pdfEmbedded><![CDATA[true]]></pdfEmbedded>
</fontFamily>
<fontFamily name="Trebuchet MS"><!-- Version 5.10 -->
<normal><![CDATA[com/trivadis/corefonts/TREBUC.TTF]]></normal>
<bold><![CDATA[com/trivadis/corefonts/TREBUCBD.TTF]]></bold>
<italic><![CDATA[com/trivadis/corefonts/TREBUCIT.TTF]]></italic>
<boldItalic><![CDATA[com/trivadis/corefonts/TREBUCBI.TTF]]></boldItalic>
<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
<pdfEmbedded><![CDATA[true]]></pdfEmbedded>
</fontFamily>
</fontFamilies>

Up to 5.2.0 this was working fine. In the test report only these two fonts are used.

With version 5.5 we'll get this exception (stack trace):

net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font :
pdfFontName : Helvetica
pdfEncoding : Identity-H
isPdfEmbedded : true
at net.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:2036)
at net.sf.jasperreports.engine.export.JRPdfExporter.writePageAnchor(JRPdfExporter.java:753)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:695)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:399)
at com.trivadis.jasperreports.JRWorker.run(JRWorker.java:229)

Now, as i've writen early i fixed this by including the new ttf tags.

But i just found out that - IF i remove the CDATA - the following XML works also with 5.5:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="Comic Sans MS"><!-- Version 5.11 -->
<normal>com/trivadis/corefonts/COMIC.TTF</normal>
<bold>com/trivadis/corefonts/COMICBD.TTF</bold>
<italic>com/trivadis/corefonts/COMICI.TTF</italic>
<boldItalic>com/trivadis/corefonts/COMICZ.TTF</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
</fontFamily>
<fontFamily name="Trebuchet MS"><!-- Version 5.10 -->
<normal>com/trivadis/corefonts/TREBUC.TTF</normal>
<bold>com/trivadis/corefonts/TREBUCBD.TTF</bold>
<italic>com/trivadis/corefonts/TREBUCIT.TTF</italic>
<boldItalic>com/trivadis/corefonts/TREBUCBI.TTF</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
</fontFamily>
</fontFamilies>

And the DejaVu extension that you mentioned do also NOT include any CDATA.
So, i think there is some problem with the handling of these CDATA stuff - and i think that this CDATA stuff should work.

I took a look at the sources and i suppose that i found the reason:

In class net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper, there is a method parseFontFace with the following code:

private SimpleFontFace parseFontFace(JasperReportsContext jasperReportsContext, Node fontFaceNode) throws SAXException
{
SimpleFontFace fontFace = new SimpleFontFace(jasperReportsContext);

NodeList nodeList = fontFaceNode.getChildNodes();

if (nodeList.getLength() == 1 && fontFaceNode.getFirstChild().getNodeType() == Node.TEXT_NODE)
{
fontFace.setTtf(fontFaceNode.getFirstChild().getTextContent());
}
else
{
for (int i = 0; i < nodeList.getLength(); i++)
{
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
if (NODE_ttf.equals(node.getNodeName()))
{
fontFace.setTtf(node.getTextContent());
}
else if (NODE_pdf.equals(node.getNodeName()))
{
fontFace.setPdf(node.getTextContent());
}
else if (NODE_eot.equals(node.getNodeName()))
{
fontFace.setEot(node.getTextContent());
}
else if (NODE_svg.equals(node.getNodeName()))
{
fontFace.setSvg(node.getTextContent());
}
else if (NODE_woff.equals(node.getNodeName()))
{
fontFace.setWoff(node.getTextContent());
}
}
}
}

return fontFace;
}

And here, i think, that the following line of code (no. 7) that should implement some compatibility logic has a problem:

if (nodeList.getLength() == 1 && fontFaceNode.getFirstChild().getNodeType() == Node.TEXT_NODE)

It only considers Node.TEXT_NODE - but CDATA nodes are *not* text nodes.

I think the fix to this problem could look like this:

if (nodeList.getLength() == 1 && (fontFaceNode.getFirstChild().getNodeType() == Node.TEXT_NODE || fontFaceNode.getFirstChild().getNodeType() == Node.CDATA_SECTION_NODE))

Hope this findings help to solve this issue.

Regards,
Michael

#5
  • Severity:Minor» Major

Hi,

This is a very good catch. Thank your for your help.
We'll include a fix for the next JR release to come out soon.

Thanks,
Teodor

#6

Hi,

This is now fixed on trunk and in jr-5-5-0-x and jr-5-5-1-x branches, if you prefer to build the library from source code and want to use more stable versions.

Thanks,
Teodor

#7
  • Resolution:Open» Fixed
  • Status:New» Resolved
  • Assigned:anonymous» teodord

System Message

#8

Hi,

The ireport 5.5.1 has fixed the missing font problem.

However, jasperServer 5.5 has the font problem when exporting output to pdf with the following error message

The server has encountered an error. Please excuse the inconvenience.
Error Message
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName : Helvetica pdfEncoding : Identity-H isPdfEmbedded : true

jasperServer 4.5 does not have the problem.

Waybill

AttachmentSize
Image icon screenhunter_06_feb._28_11.08.jpg241.74 KB
#9

Hi all, there is a fix for the 5.5 jasperserver version to make it work whith fonts (is arial.ttf font) or you suggest to downgrade to 4.5 version ?

Best regards
Fabio

Feedback