From: Yegor Kozlov Date: Sat, 21 Mar 2009 16:28:26 +0000 (+0000) Subject: added modifiers for anchor type to XSSFClientAnchor X-Git-Tag: REL_3_5_BETA6~92 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a7816b7bdbcbe0c773d5035fb3c8bf615e3fbe4d;p=poi.git added modifiers for anchor type to XSSFClientAnchor git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@756965 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 395df7134f..ed635f9abd 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + added modifiers for anchor type to XSSFClientAnchor 46772 - support built-in data formats in XSSFDataFormat 46719 - fixed XSSFSheet.shiftRows to correctly preserve row heights 46715 - preserve custom column widths across re-serialization of XSSFWorkbook diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b22fd9d385..eb6a56f0b6 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + added modifiers for anchor type to XSSFClientAnchor 46772 - support built-in data formats in XSSFDataFormat 46719 - fixed XSSFSheet.shiftRows to correctly preserve row heights 46715 - preserve custom column widths across re-serialization of XSSFWorkbook diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ClientAnchor.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ClientAnchor.java index 736f5e6ff5..6a51a7288c 100755 --- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ClientAnchor.java +++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ClientAnchor.java @@ -23,6 +23,44 @@ package org.apache.poi.ss.usermodel; * @author Yegor Kozlov */ public interface ClientAnchor { + /** + * Move and Resize With Anchor Cells + *

+ * Specifies that the current drawing shall move and + * resize to maintain its row and column anchors (i.e. the + * object is anchored to the actual from and to row and column) + *

+ */ + public static final int MOVE_AND_RESIZE = 0; + + /** + * Move With Cells but Do Not Resize + *

+ * Specifies that the current drawing shall move with its + * row and column (i.e. the object is anchored to the + * actual from row and column), but that the size shall remain absolute. + *

+ *

+ * If additional rows/columns are added between the from and to locations of the drawing, + * the drawing shall move its to anchors as needed to maintain this same absolute size. + *

+ */ + public static final int MOVE_DONT_RESIZE = 2; + + /** + * Do Not Move or Resize With Underlying Rows/Columns + *

+ * Specifies that the current start and end positions shall + * be maintained with respect to the distances from the + * absolute start point of the worksheet. + *

+ *

+ * If additional rows/columns are added before the + * drawing, the drawing shall move its anchors as needed + * to maintain this same absolute position. + *

+ */ + public static final int DONT_MOVE_AND_RESIZE = 3; /** * Returns the column (0 based) of the first cell. @@ -135,4 +173,30 @@ public interface ClientAnchor { * @param dx2 the x coordinate within the second cell */ public void setDx2(int dx2); + + + /** + * Sets the anchor type + *

+ * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. + *

+ * @param anchorType the anchor type + * @see #MOVE_AND_RESIZE + * @see #MOVE_DONT_RESIZE + * @see #DONT_MOVE_AND_RESIZE + */ + public void setAnchorType( int anchorType ); + + /** + * Gets the anchor type + *

+ * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. + *

+ * @return the anchor type + * @see #MOVE_AND_RESIZE + * @see #MOVE_DONT_RESIZE + * @see #DONT_MOVE_AND_RESIZE + */ + public int getAnchorType(); + } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java index 468ff8f6c3..b23429fa01 100755 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java @@ -26,6 +26,7 @@ import org.apache.poi.ss.usermodel.ClientAnchor; * @author Yegor Kozlov */ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { + private int anchorType; /** * Starting anchor point @@ -193,4 +194,26 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor { protected void setTo(CTMarker to){ cell2 = to; } + + + /** + * Sets the anchor type + *

+ * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. + */ + public void setAnchorType( int anchorType ) + { + this.anchorType = anchorType; + } + + /** + * Gets the anchor type + *

+ * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells. + */ + public int getAnchorType() + { + return anchorType; + } + } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java index 92be5e373c..24943ba834 100755 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java @@ -138,7 +138,6 @@ public class XSSFDrawing extends POIXMLDocumentPart implements Drawing { PackageRelationship rel = addPictureReference(pictureIndex); CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor); - ctAnchor.setEditAs(STEditAs.ONE_CELL); CTPicture ctShape = ctAnchor.addNewPic(); ctShape.set(XSSFPicture.prototype()); @@ -235,6 +234,14 @@ public class XSSFDrawing extends POIXMLDocumentPart implements Drawing { ctAnchor.addNewClientData(); anchor.setTo(ctAnchor.getTo()); anchor.setFrom(ctAnchor.getFrom()); + STEditAs.Enum aditAs; + switch(anchor.getAnchorType()) { + case ClientAnchor.DONT_MOVE_AND_RESIZE: aditAs = STEditAs.ABSOLUTE; break; + case ClientAnchor.MOVE_AND_RESIZE: aditAs = STEditAs.TWO_CELL; break; + case ClientAnchor.MOVE_DONT_RESIZE: aditAs = STEditAs.ONE_CELL; break; + default: aditAs = STEditAs.ONE_CELL; + } + ctAnchor.setEditAs(aditAs); return ctAnchor; } } 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 eb405f1e12..4fb3589ecc 100755 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java @@ -17,13 +17,12 @@ package org.apache.poi.xssf.usermodel; import junit.framework.TestCase; -import org.apache.poi.xssf.XSSFTestDataSamples; -import org.apache.poi.POIXMLDocumentPart; -import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing; +import org.apache.poi.ss.usermodel.ClientAnchor; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs; import java.util.List; import java.util.Arrays; -import java.io.IOException; /** * @author Yegor Kozlov @@ -46,10 +45,17 @@ public class TestXSSFPicture extends TestCase { assertTrue(Arrays.equals(jpegData, pictures.get(jpegIdx).getData())); XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30); + assertEquals(ClientAnchor.MOVE_AND_RESIZE, anchor.getAnchorType()); + anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE); + assertEquals(ClientAnchor.DONT_MOVE_AND_RESIZE, anchor.getAnchorType()); + XSSFPicture shape = drawing.createPicture(anchor, jpegIdx); assertTrue(anchor.equals(shape.getAnchor())); assertNotNull(shape.getPictureData()); assertTrue(Arrays.equals(jpegData, shape.getPictureData().getData())); + CTTwoCellAnchor ctShapeHolder = drawing.getCTDrawing().getTwoCellAnchorArray(0); + // STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE + assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs()); } }