diff --git a/src/java/org/apache/poi/hssf/model/ConvertAnchor.java b/src/java/org/apache/poi/hssf/model/ConvertAnchor.java index 52eb3f34e2..0288b1549e 100644 --- a/src/java/org/apache/poi/hssf/model/ConvertAnchor.java +++ b/src/java/org/apache/poi/hssf/model/ConvertAnchor.java @@ -40,14 +40,14 @@ public class ConvertAnchor anchor.setOptions( (short) 0x0000 ); anchor.setFlag( (short) a.getAnchorType() ); anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) ); - anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) ); + anchor.setDx1( (short) a.getDx1() ); anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) ); - anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) ); + anchor.setDy1( (short) a.getDy1() ); anchor.setCol2( (short) Math.max(a.getCol1(), a.getCol2()) ); - anchor.setDx2( (short) Math.max(a.getDx1(), a.getDx2()) ); + anchor.setDx2( (short) a.getDx2() ); anchor.setRow2( (short) Math.max(a.getRow1(), a.getRow2()) ); - anchor.setDy2( (short) Math.max(a.getDy1(), a.getDy2() ) ); + anchor.setDy2( (short) a.getDy2() ); return anchor; } else diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java index a337148cb2..10c4e390cb 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java @@ -18,11 +18,14 @@ package org.apache.poi.hssf.usermodel; import junit.framework.TestCase; +import org.apache.poi.ddf.EscherClientAnchorRecord; +import org.apache.poi.hssf.model.ConvertAnchor; /** * Various tests for HSSFClientAnchor. * * @author Glen Stampoultzis (glens at apache.org) + * @author Yegor Kozlov (yegor at apache.org) */ public class TestHSSFClientAnchor extends TestCase { @@ -58,4 +61,28 @@ public class TestHSSFClientAnchor extends TestCase } + /** + * When HSSFClientAnchor is converted into EscherClientAnchorRecord + * check that dx1, dx2, dy1 and dy2 are writtem "as is". + * (Bug 42999 reported that dx1 ans dx2 are swapped if dx1>dx2. It doesn't make sense for client anchors.) + */ + public void testConvertAnchor() throws Exception + { + HSSFClientAnchor[] anchor = { + new HSSFClientAnchor( 0 , 0 , 0 , 0 ,(short)0, 1,(short)1,3), + new HSSFClientAnchor( 100 , 0 , 900 , 255 ,(short)0, 1,(short)1,3), + new HSSFClientAnchor( 900 , 0 , 100 , 255 ,(short)0, 1,(short)1,3) + }; + for (int i = 0; i < anchor.length; i++) { + EscherClientAnchorRecord record = (EscherClientAnchorRecord)ConvertAnchor.createAnchor(anchor[i]); + assertEquals(anchor[i].getDx1(), record.getDx1()); + assertEquals(anchor[i].getDx2(), record.getDx2()); + assertEquals(anchor[i].getDy1(), record.getDy1()); + assertEquals(anchor[i].getDy2(), record.getDy2()); + assertEquals(anchor[i].getCol1(), record.getCol1()); + assertEquals(anchor[i].getCol2(), record.getCol2()); + assertEquals(anchor[i].getRow1(), record.getRow1()); + assertEquals(anchor[i].getRow2(), record.getRow2()); + } + } }