summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2014-12-17 00:59:47 +0000
committerNick Burch <nick@apache.org>2014-12-17 00:59:47 +0000
commitc67a8162debd9e28ee79b102d520c3ad7855fac8 (patch)
tree47178015084e65c25cc3d2eb6aeb60b379721baf
parentb7e6dc6256eef23093eab7796e609d8200ef3969 (diff)
downloadpoi-c67a8162debd9e28ee79b102d520c3ad7855fac8.tar.gz
poi-c67a8162debd9e28ee79b102d520c3ad7855fac8.zip
Merge two release blocking fixes from TrunkREL_3_11_BRANCH
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/REL_3_11_BRANCH@1646123 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java2
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java13
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java3
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java71
4 files changed, 71 insertions, 18 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index a5a8b311b6..49b965d0be 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -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);
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java
index 5415502b12..5628580966 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java
@@ -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 extends BaseTestPicture {
wb.close();
}
-
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
index 7a1ae1f1b6..09387f5f7c 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPicture.java
@@ -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>.
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
index 22247ebdf7..e573e79aef 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestPicture.java
@@ -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.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());
+ }
}