Jump to content
Changes to the Jaspersoft community edition download ×

JasperReport load font extension


oroger

Recommended Posts

 I do not use JasperServer, instead I created a webapp using JasperReport directly.

 
Templates are not in the default classloader, there are added, using a ContextClassLoader before calling JasperReport.
 
In recent version of Jasper Report font management changed as indicated in this document. Therefore I need to provide the Font JARs, which works when I put them in the **WEB-INF/lib** directory directly.
 
However, for modularity reasons I would like to add them to the classpath using the same ContextClassloader as done with the templates which. But in that case, Fonts are not loaded.
 
-I do think this has something to do with the way JasperReport loads the Font during initialization.-
 
EDIT:
From what I see in debug, JARs are loaded and the SimpleFontRegistryFactory does its work. Text is still rendered with an incorect font. The issue might then be related to the classloader used when it is actually trying to load the TTF files... 


EDIT2: It seems to be related to font loading indeed.

Apparently the net.sf.jasperreports.engine.util.getFontInfo(...) method does not return the same result.

This is due to the fact that ExtensionsEnvironment.getExtensionsRegistry().getExtensions(FontFamily.class) does not returns the same familly list in both cases. Extensions are only loaded when JARs are place in WEB-INf/lib.

 

Does someone knows how the net.sf.jasperreports.extensions.getExtensionsRegistry() could be adapted to retrieve threadRegistry instance instead ? (must be initialized somehow I guess).



Post Edited by oroger at 02/28/2012 16:34
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

This issue seems to be a duplicate of  http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=76180 

When JasperReport load the extension (lazily, on first use) the font extension is uses JasperReport Classloader, not the context class loader.

 From 

JRLoader.getClassLoaderResources(String) line:

            Map<URL, ClassLoaderResource> resources =

                  new LinkedHashMap<URL, ClassLoaderResource>();

            collectResources(resource, JRLoader.class.getClassLoader(), resources);

 

JRLoader.collectResources then get a list of all classloader by iterating on .getParent().


Using Thread.currentThread().getContextClassLoader() instead an handling errors should provide the extended classloader (which need to have JRLoader.class.getClassLoader() set as parent). 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...