incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robw...@apache.org
Subject svn commit: r1397638 - in /incubator/odf/trunk/odfdom/src: main/java/org/odftoolkit/odfdom/incubator/doc/draw/OdfDrawImage.java test/java/org/odftoolkit/odfdom/doc/ImageTest.java test/resources/simple.svg
Date Fri, 12 Oct 2012 16:50:50 GMT
Author: robweir
Date: Fri Oct 12 16:50:50 2012
New Revision: 1397638

URL: http://svn.apache.org/viewvc?rev=1397638&view=rev
Log:
Fix for ODFTOOLKIT-341, so adding SVG images will not cause exception
Reported by: Anders Sjöström


Added:
    incubator/odf/trunk/odfdom/src/test/resources/simple.svg
Modified:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/incubator/doc/draw/OdfDrawImage.java
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/ImageTest.java

Modified: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/incubator/doc/draw/OdfDrawImage.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/incubator/doc/draw/OdfDrawImage.java?rev=1397638&r1=1397637&r2=1397638&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/incubator/doc/draw/OdfDrawImage.java
(original)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/incubator/doc/draw/OdfDrawImage.java
Fri Oct 12 16:50:50 2012
@@ -120,10 +120,14 @@ public class OdfDrawImage extends DrawIm
 		OdfDrawFrame odfFrame = (OdfDrawFrame) this.getParentNode();
 		if (odfFrame != null) {
 			BufferedImage image = ImageIO.read(is);
-			int height = image.getHeight(null);
-			int width = image.getWidth(null);
-			odfFrame.setSvgHeightAttribute(Length.mapToUnit(String.valueOf(height) + "px", Unit.CENTIMETER));
-			odfFrame.setSvgWidthAttribute(Length.mapToUnit(String.valueOf(width) + "px", Unit.CENTIMETER));
+			// some image formats like SVG might not be understood by ImageIO			
+			if (image != null)
+			{
+				int height = image.getHeight(null);
+				int width = image.getWidth(null);
+				odfFrame.setSvgHeightAttribute(Length.mapToUnit(String.valueOf(height) + "px", Unit.CENTIMETER));
+				odfFrame.setSvgWidthAttribute(Length.mapToUnit(String.valueOf(width) + "px", Unit.CENTIMETER));
+			}
 		}
 	}
 

Modified: incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/ImageTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/ImageTest.java?rev=1397638&r1=1397637&r2=1397638&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/ImageTest.java (original)
+++ incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/ImageTest.java Fri
Oct 12 16:50:50 2012
@@ -170,6 +170,32 @@ public class ImageTest {
 
 	}
 
+        @Test
+	public void testSVGInTextDocument() {
+		try {
+			OdfTextDocument doc = OdfTextDocument.newTextDocument();
+			String imagePath1 = doc.newImage(ResourceUtilities.getURI("simple.svg"));
+			Assert.assertTrue(getImageCount(doc) == 1);
+			OdfDrawImage image = getImageByPath(doc, imagePath1).get(0);
+			Assert.assertTrue(image.getImageUri().toString().equals(imagePath1));
+			OdfDrawFrame frame1 = (OdfDrawFrame) image.getParentNode();
+			frame1.setTextAnchorTypeAttribute(TextAnchorTypeAttribute.Value.PAGE.toString());
+			frame1.setTextAnchorPageNumberAttribute(1);
+
+			doc.save(ResourceUtilities.newTestOutputFile("svg-image.odt"));
+
+			//load the file again
+			OdfTextDocument doc1 = (OdfTextDocument) OdfDocument.loadDocument(ResourceUtilities.getAbsolutePath("svg-image.odt"));
+
+			Assert.assertTrue(getImageCount(doc1) == 1);
+
+		} catch (Exception ex) {
+			Logger.getLogger(ImageTest.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
+			Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
+		}
+
+	}
+
 	@Test
 	public void testRemoveAllImage() {
 		try {

Added: incubator/odf/trunk/odfdom/src/test/resources/simple.svg
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/test/resources/simple.svg?rev=1397638&view=auto
==============================================================================
--- incubator/odf/trunk/odfdom/src/test/resources/simple.svg (added)
+++ incubator/odf/trunk/odfdom/src/test/resources/simple.svg Fri Oct 12 16:50:50 2012
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   version="1.1"
+   width="744.09448"
+   height="1052.3622"
+   id="svg2">
+  <defs
+     id="defs4" />
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     id="layer1">
+    <rect
+       width="200"
+       height="125.71429"
+       x="51.42857"
+       y="226.6479"
+       id="rect2985"
+       style="fill:#5d4848;fill-opacity:1;stroke:#000000;stroke-width:5.86358643;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
/>
+    <rect
+       width="180"
+       height="125.71429"
+       x="117.14286"
+       y="280.93362"
+       id="rect2987"
+       style="fill:#5d4848;fill-opacity:1;stroke:#000000;stroke-width:5.86358643;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
/>
+  </g>
+</svg>



Mime
View raw message