]> source.dussan.org Git - poi.git/commitdiff
Merge two release blocking fixes from Trunk REL_3_11_BRANCH REL_3_11_BRANCH
authorNick Burch <nick@apache.org>
Wed, 17 Dec 2014 00:59:47 +0000 (00:59 +0000)
committerNick Burch <nick@apache.org>
Wed, 17 Dec 2014 00:59:47 +0000 (00:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/REL_3_11_BRANCH@1646123 13f79535-47bb-0310-9956-ffa450edef68

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

index a5a8b311b685df5be6e5f2908be4ab6912c626ce..49b965d0be8abdf152a17cf99dc15381aa3c5472 100644 (file)
@@ -714,8 +714,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
      */
     @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);
     }
index 5415502b12f4ed969a21ba8905f0c1413aff4160..56285809662573b95e3b3f5406fa7fce136b8fee 100644 (file)
 
 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 extends BaseTestPicture {
 
         wb.close();
     }
-
 }
index 7a1ae1f1b69b52236c0b518298ed573527f54f80..09387f5f7c2924ff3ff69a30b8ec7238bad33a9e 100644 (file)
@@ -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.CreationHelper;
 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>.
index 22247ebdf772fa759edfde8dbb33e5dbf6bcb9e3..e573e79aef79033a0241b3ed474cfe91e2d88632 100644 (file)
 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.hssf.HSSFITestDataProvider;
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.util.ImageUtils;
 import org.apache.poi.util.Units;
+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 = HSSFITestDataProvider.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());
+    }
 }