poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r474253 - in /jakarta/poi/trunk/src/scratchpad: src/org/apache/poi/hslf/model/Picture.java testcases/org/apache/poi/hslf/usermodel/TestPictures.java
Date Mon, 13 Nov 2006 11:13:56 GMT
Author: nick
Date: Mon Nov 13 03:13:55 2006
New Revision: 474253

URL: http://svn.apache.org/viewvc?view=rev&rev=474253
Log:
Avoid an exception when getting the default bitmap image size on some JVMs

Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java?view=diff&rev=474253&r1=474252&r2=474253
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java Mon Nov 13
03:13:55 2006
@@ -122,12 +122,19 @@
     public void setDefaultSize(){
         PictureData pict = getPictureData();
         if (pict  instanceof Bitmap){
+            BufferedImage img = null;
             try {
-                BufferedImage img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
-                if(img != null) setAnchor(new java.awt.Rectangle(0, 0, img.getWidth(), img.getHeight()));
-                else setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
-            } catch (IOException e){
-                ;
+               	img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
+            } 
+            catch (IOException e){}
+        	catch (NegativeArraySizeException ne) {}
+        	
+            if(img != null) {
+            	// Valid image, set anchor from it
+            	setAnchor(new java.awt.Rectangle(0, 0, img.getWidth(), img.getHeight()));
+            } else {
+            	// Invalid image, go with the default metafile size
+            	setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
             }
         } else {
             //default size of a metafile picture is 200x200 

Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java?view=diff&rev=474253&r1=474252&r2=474253
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
Mon Nov 13 03:13:55 2006
@@ -257,6 +257,11 @@
 
         Slide slide = ppt.createSlide();
         File img = new File(cwd, "sci_cec.dib");
+        
+        // Check we can read the test DIB image
+        assertTrue(img.exists());
+        
+        // Add the image
         int idx = ppt.addPicture(img, Picture.DIB);
         Picture pict = new Picture(idx);
         assertEquals(idx, pict.getPictureIndex());



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message