diff options
author | Javen O'Neal <onealj@apache.org> | 2016-10-09 10:02:36 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2016-10-09 10:02:36 +0000 |
commit | 63b9090007cbaa55cb37edb4a25d731197b95ef8 (patch) | |
tree | bccb692778731201583f879134b4703f9c7f189b /src/testcases/org | |
parent | 7c141433f7ef9d329db2b5ab92880d8f706e4faf (diff) | |
download | poi-63b9090007cbaa55cb37edb4a25d731197b95ef8.tar.gz poi-63b9090007cbaa55cb37edb4a25d731197b95ef8.zip |
bug 55075,51233: create drawings with correct height when rows are custom height
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1763950 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java | 9 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java | 58 |
2 files changed, 67 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index 07fd7910f8..55e1d77db6 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -73,6 +73,7 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.RecordFormatException; import org.apache.poi.util.TempFile; +import org.junit.Ignore; import org.junit.Test; /** @@ -1315,4 +1316,12 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { assertEquals(3, wb.getNumberOfSheets()); wb.close(); } + + @Ignore + @Test + @Override + public void createDrawing() throws Exception { + super.createDrawing(); + // the dimensions for this image are different than for XSSF and SXSSF + } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java index 52f542281a..2c7c15add6 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java @@ -26,15 +26,19 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ConcurrentModificationException; import java.util.Iterator; +import org.apache.poi.POIDataSamples; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.ss.ITestDataProvider; +import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.NullOutputStream; +import org.apache.poi.util.TempFile; import org.junit.Test; public abstract class BaseTestWorkbook { @@ -895,5 +899,59 @@ public abstract class BaseTestWorkbook { wb.close(); } + + // bug 51233 and 55075: correctly size image if added to a row with a custom height + @Test + public void createDrawing() throws Exception { + Workbook wb = _testDataProvider.createWorkbook(); + Sheet sheet = wb.createSheet("Main Sheet"); + Row row0 = sheet.createRow(0); + Row row1 = sheet.createRow(1); + Cell cell = row1.createCell(0); + row0.createCell(1); + row1.createCell(0); + row1.createCell(1); + + byte[] pictureData = _testDataProvider.getTestDataFileContent("logoKarmokar4.png"); + + int handle = wb.addPicture(pictureData, Workbook.PICTURE_TYPE_PNG); + Drawing drawing = sheet.createDrawingPatriarch(); + CreationHelper helper = wb.getCreationHelper(); + ClientAnchor anchor = helper.createClientAnchor(); + anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); + anchor.setCol1(0); + anchor.setRow1(0); + Picture picture = drawing.createPicture(anchor, handle); + + row0.setHeightInPoints(144); + // set a column width so that XSSF and SXSSF have the same width (default widths may be different otherwise) + sheet.setColumnWidth(0, 100*256); + picture.resize(); + + // The actual dimensions don't matter as much as having XSSF and SXSSF produce the same size drawings + + // Check drawing height + assertEquals(0, anchor.getRow1()); + assertEquals(0, anchor.getRow2()); + assertEquals(0, anchor.getDy1()); + assertEquals(1609725, anchor.getDy2()); //HSSF: 225 + + // Check drawing width + assertEquals(0, anchor.getCol1()); + assertEquals(0, anchor.getCol2()); + assertEquals(0, anchor.getDx1()); + assertEquals(1114425, anchor.getDx2()); //HSSF: 171 + + final boolean writeOut = false; + if (writeOut) { + String ext = "." + _testDataProvider.getStandardFileNameExtension(); + String prefix = wb.getClass().getName() + "-createDrawing"; + File f = TempFile.createTempFile(prefix, ext); + FileOutputStream out = new FileOutputStream(f); + wb.write(out); + out.close(); + } + wb.close(); + } } |