poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1645900 - in /poi/trunk/src: ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/ss/usermodel/
Date Tue, 16 Dec 2014 10:40:02 GMT
Author: centic
Date: Tue Dec 16 10:40:02 2014
New Revision: 1645900

URL: http://svn.apache.org/r1645900
Log:
Bug 57355: Fix ArrayIndexOutOfBoundsException by removing two unnecessary lines in XSSFSheet.getColumnWidthInPixels()

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1645900&r1=1645899&r2=1645900&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Tue Dec 16 10:40:02
2014
@@ -714,8 +714,6 @@ public class XSSFSheet extends POIXMLDoc
      */
     @Override
     public float getColumnWidthInPixels(int columnIndex) {
-        int styleIdx = getColumnHelper().getColDefaultStyle(columnIndex);
-        CellStyle cs = getWorkbook().getStylesSource().getStyleAt(styleIdx);
         float widthIn256 = getColumnWidth(columnIndex);
         return (float)(widthIn256/256.0*XSSFWorkbook.DEFAULT_CHARACTER_WIDTH);
     }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java?rev=1645900&r1=1645899&r2=1645900&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java Tue Dec
16 10:40:02 2014
@@ -17,25 +17,15 @@
 
 package org.apache.poi.xssf.usermodel;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.poi.hssf.usermodel.HSSFPatriarch;
-import org.apache.poi.hssf.usermodel.HSSFPicture;
-import org.apache.poi.hssf.usermodel.HSSFShape;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.BaseTestPicture;
 import org.apache.poi.ss.usermodel.ClientAnchor;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
@@ -169,5 +159,4 @@ public final class TestXSSFPicture exten
 
         wb.close();
     }
-
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java?rev=1645900&r1=1645899&r2=1645900&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java Tue Dec 16
10:40:02 2014
@@ -20,8 +20,6 @@ package org.apache.poi.hssf.usermodel;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.List;
 
@@ -36,7 +34,6 @@ import org.apache.poi.ss.usermodel.Creat
 import org.apache.poi.ss.usermodel.PictureData;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.junit.Test;
-import org.junit.Ignore;
 
 /**
  * Test <code>HSSFPicture</code>.

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java?rev=1645900&r1=1645899&r2=1645900&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java Tue Dec 16 10:40:02
2014
@@ -18,13 +18,21 @@
 package org.apache.poi.ss.usermodel;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.awt.Dimension;
-import java.io.FileOutputStream;
+import java.awt.Point;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
 
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.util.ImageUtils;
 import org.apache.poi.util.Units;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.junit.Test;
 
 /**
  * @author Yegor Kozlov
@@ -65,4 +73,65 @@ public abstract class BaseTestPicture {
         assertEquals("the image width differs",  imgDim.getWidth(), inpDim.getWidth()/emuPX,
 1);
     }
 
+
+    @Test
+    public void testResizeNoColumns() throws IOException {
+        Workbook wb = _testDataProvider.createWorkbook();
+        try {
+            Sheet sheet = wb.createSheet();
+    
+            Row row = sheet.createRow(0);
+            
+            handleResize(wb, sheet, row);
+        } finally {
+            wb.close();
+        }
+    }
+
+    @Test
+    public void testResizeWithColumns() throws IOException {
+        Workbook wb = _testDataProvider.createWorkbook();
+        try {
+            Sheet sheet = wb.createSheet();
+    
+            Row row = sheet.createRow(0);
+            row.createCell(0);
+            
+            handleResize(wb, sheet, row);
+        } finally {
+            wb.close();
+        }
+    }
+
+
+    private void handleResize(Workbook wb, Sheet sheet, Row row) throws IOException {
+        Drawing drawing = sheet.createDrawingPatriarch();
+        CreationHelper createHelper = wb.getCreationHelper();
+
+        final byte[] bytes = XSSFITestDataProvider.instance.getTestDataFileContent("logoKarmokar4.png");
+        
+        row.setHeightInPoints(getImageSize(bytes).y);
+   
+        int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
+   
+        //add a picture shape
+        ClientAnchor anchor = createHelper.createClientAnchor();
+        //set top-left corner of the picture,
+        //subsequent call of Picture#resize() will operate relative to it
+        anchor.setCol1(0);
+        anchor.setRow1(0);
+   
+        Picture pict = drawing.createPicture(anchor, pictureIdx);
+   
+        //auto-size picture relative to its top-left corner
+        pict.resize();
+    }
+    
+    private static Point getImageSize( byte [] image) throws IOException {
+        BufferedImage img = ImageIO.read(new ByteArrayInputStream(image));
+        
+        assertNotNull(img);
+        
+        return new Point(img.getWidth(), img.getHeight());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message