From 3f9cbe9a38c6b237aba18e75ec41fe878c4ae238 Mon Sep 17 00:00:00 2001 From: Greg Woolsey Date: Fri, 23 Jun 2017 05:16:38 +0000 Subject: Bug 61203 - XSSFDrawing.getAnchorFromParent handles CTOneCellAnchor incorrectly, ignores CTAbsoluteAnchor This is likely incomplete, but closer to where things should be. It is backward compatible with previous uses of XSSFClientAnchor. This fixes a bug in XSSFGraphicFrame that was hiding the parent class anchor property (which is a protected field set directly from XSSFDrawing). This is a peril of using direct property access - the hiding wasn't obvious because there was no setter being overridden. XSSFGraphicFrame now notices when it relates to a chart, and setts the frame property of the XSSFChart. That was not being set on parse previously, only when creating charts from scratch. That didn't seem right. XSSFClientAnchor now calculates size and position correctly based on initial inputs from the different types of anchors. It DOES NOT update those initial inputs, however. It does properly adjust if the size or initial position are absolute and the corresponding row/column values are requested. Added new class EMUUtils to centralize the measurement constants and conversions since there are so many units in play in the OOXML spec and POI APIs: * EMUs (English Metric Units) * Inches * Centimeters * Points * Pixels * Twips (1/20th of a point) I'm sure there are more conversions that could be done there, I just started with what I needed. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1799643 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ss/usermodel/ClientAnchor.java | 40 +++++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/java') diff --git a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java index 702970c69e..d11edc56ae 100644 --- a/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java +++ b/src/java/org/apache/poi/ss/usermodel/ClientAnchor.java @@ -20,10 +20,17 @@ import org.apache.poi.util.Internal; import org.apache.poi.util.Removal; /** - * A client anchor is attached to an excel worksheet. It anchors against a - * top-left and bottom-right cell. - * - * @author Yegor Kozlov + * A client anchor is attached to an excel worksheet. It anchors against + * absolute coordinates, a top-left cell and fixed height and width, or + * a top-left and bottom-right cell, depending on the {@link AnchorType}: + *
    + *
  1. {@link AnchorType#DONT_MOVE_AND_RESIZE} == absolute top-left coordinates and width/height, no cell references + *
  2. {@link AnchorType#MOVE_DONT_RESIZE} == fixed top-left cell reference, absolute width/height + *
  3. {@link AnchorType#MOVE_AND_RESIZE} == fixed top-left and bottom-right cell references, dynamic width/height + *
+ * Note this class only reports the current values for possibly calculated positions and sizes. + * If the sheet row/column sizes or positions shift, this needs updating via external calculations. + * */ public interface ClientAnchor { @@ -91,8 +98,9 @@ public interface ClientAnchor { *

* Specifies that the current drawing shall not move with its * row and column, but should be resized. This option is not normally - * used, but is included for completeness. + * used, but is included for completeness. *

+ * Note: Excel has no setting for this combination, nor does the ECMA standard. */ DONT_MOVE_DO_RESIZE(1), @@ -145,9 +153,10 @@ public interface ClientAnchor { } /** - * Returns the column (0 based) of the first cell. + * Returns the column (0 based) of the first cell, or -1 if there is no top-left anchor cell. + * This is the case for absolute positioning (AnchorType{@link #DONT_MOVE_AND_RESIZE}). * - * @return 0-based column of the first cell. + * @return 0-based column of the first cell or -1 if none. */ public short getCol1(); @@ -159,9 +168,11 @@ public interface ClientAnchor { public void setCol1(int col1); /** - * Returns the column (0 based) of the second cell. + * Returns the column (0 based) of the second cell, or -1 if there is no bottom-right anchor cell. + * This is the case for absolute positioning ({@link AnchorType#DONT_MOVE_AND_RESIZE}) + * and absolute sizing ({@link AnchorType#MOVE_DONT_RESIZE}. * - * @return 0-based column of the second cell. + * @return 0-based column of the second cell or -1 if none. */ public short getCol2(); @@ -173,9 +184,10 @@ public interface ClientAnchor { public void setCol2(int col2); /** - * Returns the row (0 based) of the first cell. + * Returns the row (0 based) of the first cell, or -1 if there is no bottom-right anchor cell. + * This is the case for absolute positioning ({@link AnchorType#DONT_MOVE_AND_RESIZE}). * - * @return 0-based row of the first cell. + * @return 0-based row of the first cell or -1 if none. */ public int getRow1(); @@ -187,9 +199,11 @@ public interface ClientAnchor { public void setRow1(int row1); /** - * Returns the row (0 based) of the second cell. + * Returns the row (0 based) of the second cell, or -1 if there is no bottom-right anchor cell. + * This is the case for absolute positioning ({@link AnchorType#DONT_MOVE_AND_RESIZE}) + * and absolute sizing ({@link AnchorType#MOVE_DONT_RESIZE}. * - * @return 0-based row of the second cell. + * @return 0-based row of the second cell or -1 if none. */ public int getRow2(); -- cgit v1.2.3