I've found that if I process more than one document with Fop without restarting my application then only the first document is able to use autodetected fonts (using the support added in Bug 41831). Fonts that were resolved and used correctly in the first document are unable to be found for the subsequent documents. The problem seems to be caused by the static autodetectedFonts variable in org/apache/fop/render/PrintRendererConfigurator.java. This occurs whether I reuse the FopFactory or whether I recreate it between documents.
Created attachment 20496 [details] reuseFontTripletMap20070711.diff The quickest solution is just to remove the autodetectedFonts variable, but that would result in unnecessary parsing of the fonts. Another solution would be to store the Font maps in the FOUserAgent so that new FontInfo objects can reuse the maps from the previous lookup. A patch based on this idea is attached.
Having the fontMap and FontTripletInfo in the FOUserAgent is not the correct place for this, it should remain in the FontCache where it can be serialized.
Created attachment 20498 [details] font autodetection fix * Created new FontManager class. * Moved static boolean autoDetectedFonts member of PrintRendererConfigurator to be a member of FontManager * Moved FontCache from FopFactory to FontManager. * Added FontManager get accessor in FopFactory. * Moved FontCache related accessors to FontManager. * PrintRendererConfigurator static methods modified to normal and signature footprint reduced. * PDFDocumentGraphics2DConfigurator now extends PDFRendererConfigurator and makes use of member methods calls rather than making static method calls. * Cleaned up javadocs in FontCache and PDFTranscoder In the future some of the code could be reorganised a little so all font detection related activities stem/flow from the FontManager rather than directly from PrintRendererConfigurator. FontManager could also be the holder of a centralized list of available fonts. Each renderer would then request the availability of a font from the FontManager rather than each storing its own font list as is the current situation. I do not have time to make these changes *at the moment* but this patch should fix the autodetection problem. Adrian.
Created attachment 20499 [details] fo2pdfExampleOfBug.java Thanks for the patch. Unfortunately, it still shows the bug if I don't recreate the FopFactory. To demonstrate this bug you can try this java file, which is a modified version of examples/embedding/java/embedding/ExampleFO2PDF.java. Obviously, you also need to add an autodetected font to the Hello World fo:block in xml/fo/helloworld.fo and add <auto-detect/> in the <fonts/> section of the conf/fop.xconf. You should find that the first and third pdf have the correct font, but the second pdf, which was created by reusing the FopFactory, has the wrong font.
Created attachment 20500 [details] cacheFontTripletMap20070712.diff I still think you need to cache the font triplet maps in FontInfo some how since the FontInfo object is recreated for each Fop object. The attached patch caches them on FontCache as you suggest.
I cannot reproduce this bug with the given resources. I'm calling FOP multiple times the whole time in my applications and have never had a problem although auto-detection is enabled. Maybe Adrian's refactoring fixed the problem in the end. Please re-open if the problem is still present in the current FOP Trunk.
batch transition to closed remaining pre-FOP1.0 resolved bugs