|Summary:||PDFGraphics2D.drawString(AttributedCharacterIterator it, float x, float y) throws NullPointerException|
|Product:||Fop - Now in Jira||Reporter:||Yegor Kozlov <yegor>|
Description Yegor Kozlov 2008-04-03 02:18:14 UTC
PDFGraphics2D.drawString(AttributedCharacterIterator it, float x, float y) throws NullPointerException: Exception in thread "main" java.lang.NullPointerException at org.apache.fop.svg.PDFGraphics2D.drawString(PDFGraphics2D.java:1559) at org.apache.xmlgraphics.java2d.AbstractGraphics2D.drawString(AbstractGraphics2D.java:652) at com.yegor.fop.TestPDFGraphics.main(TestPDFGraphics.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) A failing test is attached. It looks like drawString(AttributedCharacterIterator it, float x, float y) is not finished. The variable fontState which results in NPE is assigned to null and never initialized. If possible, I'd like to have it fixed in FOP 0.95. I would be happy to upload a patch but my knowledge of PDF is not enough for that :). Please suggest how it can be fixed. Shouldn't this method be re-written so that drawString(String str, float x, float y) is called for each individual text run in the AttributedString? If so, how can I measure the length of a text run and advance the x co-ordinate? Regards, Yegor
Comment 2 Andreas L. Delmelle 2008-04-03 09:33:05 UTC
(In reply to comment #0) <snip /> Looking at it closer, the possibility of the NPE is immediately signaled by my IDE when I open the file in question. > Shouldn't this method be re-written so that drawString(String str, float x, > float y) is called for each individual text run in the AttributedString? Not sure, but this could actually turn out to be suboptimal, since the former method may contain code that should only be called once. The initialization of the fontState falls in that category. I'm not really an expert on this part of the FOP-code, but have you tried copy-pasting the first few lines of the drawString(String...) variant, where the fontState is initialized?
Comment 3 Jeremias Maerki 2008-04-04 05:42:09 UTC
I've disabled the method which makes PDFGraphics2D use the fallback implementation from AbstractGraphics2D (which uses the TextLayout approach). But I consider this to be suboptimal, just a temporary solution (whatever "temporary" means in our project). http://svn.apache.org/viewvc?rev=644697&view=rev In the end, drawString(String, float, float) should rather call drawString(AttributedCharacterIterator, float, float) than the other way around. Mapping the more complex method to a number of calls to the simpler method is not the most efficient method. PDFTextPainter may provide some inspiration for an optimized implementation. It already contains some code to paint an AttributedCharacterIterator, even if that one is highly Batik-specific. So I'm leaving this bug open as a reminder.
Comment 4 Glenn Adams 2012-04-07 01:41:53 UTC
resetting P2 open bugs to P3 pending further review