incubator-odf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anders Sjöström (JIRA) <j...@apache.org>
Subject [jira] [Commented] (ODFTOOLKIT-341) newImage() generates java.lang.NullPointerException when using an svg image
Date Tue, 16 Oct 2012 19:59:03 GMT

    [ https://issues.apache.org/jira/browse/ODFTOOLKIT-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13477295#comment-13477295
] 

Anders Sjöström commented on ODFTOOLKIT-341:
--------------------------------------------

Sorry for my late reply Rob. I can confirm that the program doesn't crash any more. 

However, when I open the file in Apache Open Office, the file will open properly, but lacking
height/width attributes unfortunately the image frame will default to a ridiculously small
size, something I did neglect to mention.

And I have checked, ImageIO will only work on bitmapped image formats, which this is not.

Since SVG is a vector format, it doesn't have an absolute size. The size is more about fitting
it nicely into the page, which would be hard to figure out from the image file itself. IMO
the ideal is if the image is by default maximized according to the paper size, but without
change the ratio between height and width. Which in turn still requires parsing information
from the file itself. And always maximizing might not be every ones ideal solution, since
all vector images will fill up to a page each. So I can accept if the default size is not
set according to my wishes, but it would have been nice if I could set och change the size
at will.


I tried to use Image.newImage(paragraph, uri) instead of TextDocument.newImage(uri), thinking
that it would give me easy access to the Frame so that I could set the height/width attributes
myself. This works fine for a png file. Unfortunately Image.newImage() on the svg file gives
an exception too.

Paragraph para = outputOdt.addParagraph("Hello World.");
Image image = Image.newImage(para, uri);

java.lang.NullPointerException
	at org.odftoolkit.simple.draw.Image.configureInsertedImage(Image.java:282)
	at org.odftoolkit.simple.draw.Image.newImage(Image.java:184)
	at odfgenerator.main(odfgenerator.java:16)


This is the complete program I was trying to run this time (which works for png files):

public class odfgenerator { 
  public static void main(String[] args) throws Exception { 
    TextDocument outputOdt; 
    outputOdt = TextDocument.newTextDocument(); 
    Paragraph para = outputOdt.addParagraph("Hello World."); 

    //URI uri = new URI("file:///C:/Users/myuser/Desktop/simple.png"); 
    URI uri = new URI("file:///C:/Users/myuser/Desktop/simple.svg"); 

    Image image = Image.newImage(para, uri);
    Frame frame = image.getFrame();
    DrawFrameElement drawframe = frame.getDrawFrameElement();
    drawframe.setSvgHeightAttribute("10cm");
    drawframe.setSvgWidthAttribute("10cm");
    
    outputOdt.save("C:/Users/myuser/Desktop/HelloWorld.odt"); 
  } 
} 

Do you think that it would be possible to find a solution where I could somehow set the height/width
for SVG images? Perhaps I should write a new issue about this?

                
> newImage() generates java.lang.NullPointerException when using an svg image
> ---------------------------------------------------------------------------
>
>                 Key: ODFTOOLKIT-341
>                 URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-341
>             Project: ODF Toolkit
>          Issue Type: Bug
>          Components: simple api
>    Affects Versions: 0.8
>         Environment: Windows 7 Home 32 bit
> JRE 7 32 bit
> Eclipse Indigo SR2
> odf-toolkit 0.5 
> and also tried odf-toolkit SVN revision 1395734 (built with Maven on Ubuntu): simple-odf-0.8-incubating-SNAPSHOT,
odfdoom-java-0.8.9-incubating-SNAPSHOT
>            Reporter: Anders Sjöström
>            Assignee: Rob Weir
>         Attachments: simple.svg
>
>
> I'm trying to create an odt file, and insert text and svg images, with limited success.
> Inserting a png image is no problem, but when I change the line to insert an svg image
I get an exception.
> This is the minimum program to demonstrate my problem:
> import java.net.URI;
> import org.odftoolkit.simple.TextDocument;
> public class odfgenerator {
> 	public static void main(String[] args) throws Exception {
> 		TextDocument outputOdt;
> 		outputOdt = TextDocument.newTextDocument();
> 		outputOdt.addParagraph("Hello World.");
> 		//URI uri = new URI("file:///C:/Users/myuser/Desktop/simple.png");
> 		URI uri = new URI("file:///C:/Users/myuser/Desktop/simple.svg");
> 		outputOdt.newImage(uri);
> 		outputOdt.save("C:/Users/myuser/Desktop/HelloWorld.odt");
> 	}
> }
> If I run my program (in Eclipse) I get:
> okt 08, 2012 11:30:57 EM org.odftoolkit.simple.Document newImage
> SEVERE: null
> java.lang.NullPointerException
> 	at org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawImage.configureInsertedImage(OdfDrawImage.java:123)
> 	at org.odftoolkit.odfdom.incubator.doc.draw.OdfDrawImage.newImage(OdfDrawImage.java:147)
> 	at org.odftoolkit.simple.Document.newImage(Document.java:830)
> 	at odfgenerator.main(odfgenerator.java:12)
> I delete HelloWorld.odt before every run, just to make sure. The odd thing is that despite
the exception, HelloWorld.odt is still created, with the svg file inside the Pictures directory,
and the content.xml has an draw:image tag with xlink:href="Pictures/simple.svg". The odt file
can be opened with Apache Open Office without problem, and will display the picture.
> Changing the URI to point to an png file instead results in the program terminating normally
without any errors. The resulting file can also be opened with Apache Open Office without
problems.
> simple.svg is a very simple svg file created with Inkskape containing two boxes, and
saved as "plain svg".
> Am I doing anything wrong or is this a bug?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message