Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial FontInfo Cache for ignoreCase=false. #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mpscheidt
Copy link

The motivation for this pull request comes from the very long durations needed for exporting Excel files from the JasperViewer, when JasperFonts are installed and when the JVM's Locale was changed from its startup value.

Looking at the JasperReports source code, there are several places with comments suggesting that performance is not optimal regarding font handling. For example, in net.sf.jasperreports.engine.fonts.FontUtil.getFontInfo(String name, boolean ignoreCase, Locale locale) line 190 there is the comment:
//FIXMEFONT do some cache

Looking further for the place that causes the delay, java.awt.Font.getFamily() can be identified, which in turn calls sun.font.TrueTypeFont.getFonName(Locale locale). Here, when the given locale (corresponds to Locale.getDefault() in this case) is different from sun.awt.SunToolkit.getStartupLocale(), a rather expensive operation starts to determine the font name. Therefore, avoiding the call to java.awt.Font.getFamily() is desirable.

This pull request includes a simpe cache, which utilizes a map to remember resolved net.sf.jasperreports.engine.fonts.FontInfo objects. The key to the map is defined in the new class FontInfoKey and has currently only two properties, name and local. It only caters for the case when the getFontInfo()'s ignoreCase is false. This flag is false when the method is called from the two-params method getFontInfo(String name, Locale locale), such as when exporting Excel from JasperViewer via JRXlsExporter. For the case when ignoreCase is true, a separate map could be implemented, so that the two cases do not interfere with each other.

The impact of this little cache is rather enormous. In a specific Excel export case, duration without cache was about 1000 seconds, and with cache about 1 second.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant