Bug 42861 - [PATCH] Font detection only works for first document.
Summary: [PATCH] Font detection only works for first document.
Status: CLOSED WORKSFORME
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: fonts (show other bugs)
Version: trunk
Hardware: Other Linux
: P2 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-11 15:19 UTC by Keith Stribley
Modified: 2012-04-01 13:49 UTC (History)
0 users



Attachments
reuseFontTripletMap20070711.diff (4.93 KB, patch)
2007-07-11 15:21 UTC, Keith Stribley
Details | Diff
font autodetection fix (25.09 KB, patch)
2007-07-12 07:48 UTC, Adrian Cumiskey
Details | Diff
fo2pdfExampleOfBug.java (5.81 KB, text/x-java)
2007-07-12 14:05 UTC, Keith Stribley
Details
cacheFontTripletMap20070712.diff (3.64 KB, patch)
2007-07-12 15:30 UTC, Keith Stribley
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Keith Stribley 2007-07-11 15:19:54 UTC
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.
Comment 1 Keith Stribley 2007-07-11 15:21:12 UTC
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.
Comment 2 Adrian Cumiskey 2007-07-12 05:49:18 UTC
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.
Comment 3 Adrian Cumiskey 2007-07-12 07:48:46 UTC
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.
Comment 4 Keith Stribley 2007-07-12 14:05:39 UTC
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.
Comment 5 Keith Stribley 2007-07-12 15:30:33 UTC
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.
Comment 6 Jeremias Maerki 2010-06-08 15:20:59 UTC
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.
Comment 7 Glenn Adams 2012-04-01 13:49:26 UTC
batch transition to closed remaining pre-FOP1.0 resolved bugs