You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Martin Hönings (JIRA)" <ji...@apache.org> on 2015/12/18 17:01:46 UTC
[jira] [Comment Edited] (FOP-2532) FontCache throws
java.lang.IllegalArgumentException: URI scheme is not "file" for jar
embedded fonts
[ https://issues.apache.org/jira/browse/FOP-2532?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15064133#comment-15064133 ]
Martin Hönings edited comment on FOP-2532 at 12/18/15 4:01 PM:
---------------------------------------------------------------
Why not using the method:
public static long getLastModified(URI uri)
which I already proposed before and which is already defined in the class FontCache?
This method works correctly and is already used, when fonts are removed from cache.
If you use two different methods with different results for lastModification calculation during adding and removing fonts, this will not work correktly for JARs.
Neither the patch proposed here nor in https://issues.apache.org/jira/browse/FOP-2554 works correktly.
The result is the following:
[TRACE ] [http-apr-8080-exec-1] [2015-12-18 16:39:40,821] [Font removed from cache: jar:file:/D:/apache-tomcat-8.0.28/webapps/XXX/WEB-INF/lib/yyy.jar!/fonts/arialuni.ttf] [org.apache.fop.fonts.FontCache]
[TRACE ] [http-apr-8080-exec-1] [2015-12-18 16:39:41,021] [Font added to cache: jar:file:/D:/apache-tomcat-8.0.28/webapps/XXX/WEB-INF/lib/yyy.jar!/fonts/arialuni.ttf] [org.apache.fop.fonts.FontCache]
The fonts are always removed and then added again. So the FontCache is not really a cache any more.
The lastModification calculation during remove executes the following code:
FontInfoFinder from line 179:
fileLastModified = FontCache.getLastModified(fontURI);
// firstly try and fetch it from cache before loading/parsing the font file
if (fontCache.containsFont(embedStr)) {
EmbedFontInfo[] fontInfos = fontCache.getFontInfos(embedStr, fileLastModified);
FontCache from line 384:
public EmbedFontInfo[] getFontInfos(String embedUrl, long lastModified) {
CachedFontFile cff = getFontFile(embedUrl);
if (cff.lastModified() == lastModified) {
return cff.getEmbedFontInfos();
} else {
removeFont(embedUrl);
You can see here the usage of the method getLastModified during font removal.
The lastModified calculated there is compared with the lastModified before adding a font. Since the calculation is done in two different ways with two different results, the font is always removed.
So simply use the working method
public static long getLastModified(URI uri) fom class FontCache
everywhere. The correction must be:
In the class "FontCache" in the method "addFont" replace:
File fontFile = new File(fontUri);
long lastModified = fontFile.lastModified();
with:
long lastModified = getLastModified(fontUri);
That works.
was (Author: martinx):
Why not using the method:
public static long getLastModified(URI uri)
which I already proposed before and which is already defined in the class FontCache?
This method works correctly and is already used, when fonts are removed from cache.
If you use two different methods with different results for lastModification calculation during adding and removing fonts, this will not work correktly for JARs.
Neither the patch proposed here nor in https://issues.apache.org/jira/browse/FOP-2554 works correktly.
The result is the following:
[TRACE ] [http-apr-8080-exec-1] [2015-12-18 16:39:40,821] [Font removed from cache: jar:file:/D:/apache-tomcat-8.0.28/webapps/XXX/WEB-INF/lib/yyy-3.8.0.0.jar!/fonts/arialuni.ttf] [org.apache.fop.fonts.FontCache]
[TRACE ] [http-apr-8080-exec-1] [2015-12-18 16:39:41,021] [Font added to cache: jar:file:/D:/apache-tomcat-8.0.28/webapps/XXX/WEB-INF/lib/yyy-3.8.0.0.jar!/fonts/arialuni.ttf] [org.apache.fop.fonts.FontCache]
The fonts are always removed and then added again. So the FontCache is not really a cache any more.
The lastModification calculation during remove executes the following code:
FontInfoFinder from line 179:
fileLastModified = FontCache.getLastModified(fontURI);
// firstly try and fetch it from cache before loading/parsing the font file
if (fontCache.containsFont(embedStr)) {
EmbedFontInfo[] fontInfos = fontCache.getFontInfos(embedStr, fileLastModified);
FontCache from line 384:
public EmbedFontInfo[] getFontInfos(String embedUrl, long lastModified) {
CachedFontFile cff = getFontFile(embedUrl);
if (cff.lastModified() == lastModified) {
return cff.getEmbedFontInfos();
} else {
removeFont(embedUrl);
You can see here the usage of the method getLastModified during font removal.
The lastModified calculated there is compared with the lastModified before adding a font. Since the calculation is done in two different ways with two different results, the font is always removed.
So simply use the working method
public static long getLastModified(URI uri) fom class FontCache
everywhere. The correction must be:
In the class "FontCache" in the method "addFont" replace:
File fontFile = new File(fontUri);
long lastModified = fontFile.lastModified();
with:
long lastModified = getLastModified(fontUri);
That works.
> FontCache throws java.lang.IllegalArgumentException: URI scheme is not "file" for jar embedded fonts
> ----------------------------------------------------------------------------------------------------
>
> Key: FOP-2532
> URL: https://issues.apache.org/jira/browse/FOP-2532
> Project: FOP
> Issue Type: Bug
> Affects Versions: 2.0
> Reporter: Brian Preuß
> Attachments: lastModified-value-on-opaque-URI.patch
>
>
> If using <auto-detect /> fop finds fonts embedded in jar files (via MANIFEST.MF entries as described at http://xmlgraphics.apache.org/fop/2.0/fonts.html#autodetect) and tries to add them to the font cache. This throws the following exception:
> {code}
> java.lang.IllegalArgumentException: URI scheme is not "file"
> 26677/0| at java.io.File.<init>(File.java:421)
> 26677/0| at org.apache.fop.fonts.FontCache.addFont(FontCache.java:335)
> 26677/0| at org.apache.fop.fonts.autodetect.FontInfoFinder.getFontInfoFromCustomFont(FontInfoFinder.java:157)
> 26677/0| at org.apache.fop.fonts.autodetect.FontInfoFinder.find(FontInfoFinder.java:269)
> 26677/0| at org.apache.fop.fonts.FontAdder.add(FontAdder.java:63)
> 26677/0| at org.apache.fop.fonts.FontDetectorFactory$DefaultFontDetector.detect(FontDetectorFactory.java:110)
> 26677/0| at org.apache.fop.fonts.FontManager.autoDetectFonts(FontManager.java:229)
> 26677/0| at org.apache.fop.fonts.DefaultFontConfigurator.configure(DefaultFontConfigurator.java:82)
> 26677/0| at org.apache.fop.render.PrintRendererConfigurator.getCustomFontCollection(PrintRendererConfigurator.java:147)
> 26677/0| at org.apache.fop.render.PrintRendererConfigurator.setupFontInfo(PrintRendererConfigurator.java:127)
> 26677/0| at org.apache.fop.render.intermediate.IFUtil.setupFonts(IFUtil.java:170)
> 26677/0| at org.apache.fop.render.intermediate.IFRenderer.setupFontInfo(IFRenderer.java:187)
> 26677/0| at org.apache.fop.area.RenderPagesModel.<init>(RenderPagesModel.java:75)
> 26677/0| at org.apache.fop.area.AreaTreeHandler.setupModel(AreaTreeHandler.java:135)
> 26677/0| at org.apache.fop.area.AreaTreeHandler.<init>(AreaTreeHandler.java:105)
> 26677/0| at org.apache.fop.render.RendererFactory.createFOEventHandler(RendererFactory.java:350)
> 26677/0| at org.apache.fop.fo.FOTreeBuilder.<init>(FOTreeBuilder.java:107)
> 26677/0| at org.apache.fop.apps.Fop.createDefaultHandler(Fop.java:104)
> 26677/0| at org.apache.fop.apps.Fop.<init>(Fop.java:78)
> 26677/0| at org.apache.fop.apps.FOUserAgent.newFop(FOUserAgent.java:179)
> 26677/0| at org.apache.fop.apps.FopFactory.newFop(FopFactory.java:240)
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)