From c89d312bad1d023e5b69de5a93a789e091beca8c Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Mon, 17 Apr 2017 17:13:23 +0000 Subject: [PATCH] #60998 - HSLFTable.setRowHeight sets row height incorrect git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1791696 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ddf/EscherProperties.java | 2 +- .../org/apache/poi/sl/TestTable.java | 11 ++++-- .../apache/poi/hslf/record/RecordTypes.java | 1 + .../apache/poi/hslf/usermodel/HSLFTable.java | 36 +++++++++++-------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/java/org/apache/poi/ddf/EscherProperties.java b/src/java/org/apache/poi/ddf/EscherProperties.java index 096a20c57..955db365f 100644 --- a/src/java/org/apache/poi/ddf/EscherProperties.java +++ b/src/java/org/apache/poi/ddf/EscherProperties.java @@ -624,7 +624,7 @@ public final class EscherProperties { addProp( m, GROUPSHAPE__BORDERBOTTOMCOLOR, "groupshape.borderBottomColor" ); // 0x039D; addProp( m, GROUPSHAPE__BORDERRIGHTCOLOR, "groupshape.borderRightColor" ); // 0x039E; addProp( m, GROUPSHAPE__TABLEPROPERTIES, "groupshape.tableProperties" ); // 0x039F; - addProp( m, GROUPSHAPE__TABLEROWPROPERTIES, "groupshape.tableRowProperties" ); // 0x03A0; + addProp( m, GROUPSHAPE__TABLEROWPROPERTIES, "groupshape.tableRowProperties", EscherPropertyMetaData.TYPE_ARRAY ); // 0x03A0; addProp( m, GROUPSHAPE__WEBBOT, "groupshape.wzWebBot" ); // 0x03A5; addProp( m, GROUPSHAPE__METROBLOB, "groupshape.metroBlob" ); // 0x03A9; addProp( m, GROUPSHAPE__ZORDER, "groupshape.dhgt" ); // 0x03AA; diff --git a/src/ooxml/testcases/org/apache/poi/sl/TestTable.java b/src/ooxml/testcases/org/apache/poi/sl/TestTable.java index 5b45f9973..602875662 100644 --- a/src/ooxml/testcases/org/apache/poi/sl/TestTable.java +++ b/src/ooxml/testcases/org/apache/poi/sl/TestTable.java @@ -88,7 +88,12 @@ public class TestTable { // assert ppt and pptx versions of the same table have the same shape confirmTableShapeEqual(ts, tsx); - + + // change row height and validate again + tsx.setRowHeight(1, 50); + ts.setRowHeight(1, 50); + confirmTableShapeEqual(ts, tsx); + pptx.close(); ppt.close(); } @@ -115,7 +120,7 @@ public class TestTable { } @Test - public void textDirectionHSLF() throws IOException { + public void directionHSLF() throws IOException { assumeFalse(xslfOnly); SlideShow ppt1 = new HSLFSlideShow(); testTextDirection(ppt1); @@ -123,7 +128,7 @@ public class TestTable { } @Test - public void textDirectionXSLF() throws IOException { + public void directionXSLF() throws IOException { SlideShow ppt1 = new XMLSlideShow(); testTextDirection(ppt1); ppt1.close(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java index c0c57255f..44595b747 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java @@ -204,6 +204,7 @@ public enum RecordTypes { EscherDeletedPspl(0xf11d,null), EscherSplitMenuColors(0xf11e,null), EscherOleObject(0xf11f,null), + // same as EscherTertiaryOptRecord.RECORD_ID EscherUserDefined(0xf122,null); private static final Map LOOKUP; diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java index b159e7ca6..586005b57 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java @@ -361,30 +361,38 @@ implements HSLFShapeContainer, TableShape { } @Override - public void setRowHeight(int row, double height) { + public void setRowHeight(int row, final double height) { if (row < 0 || row >= cells.length) { throw new IllegalArgumentException("Row index '"+row+"' is not within range [0-"+(cells.length-1)+"]"); } - int pxHeight = Units.pointsToPixel(height); - double currentHeight = cells[row][0].getAnchor().getHeight(); - double dy = pxHeight - currentHeight; - + // update row height in the table properties + AbstractEscherOptRecord opt = getEscherChild(RecordTypes.EscherUserDefined.typeID); + EscherArrayProperty p = opt.lookup(EscherProperties.GROUPSHAPE__TABLEROWPROPERTIES); + byte[] masterBytes = p.getElement(row); + double currentHeight = Units.masterToPoints(LittleEndian.getInt(masterBytes, 0)); + LittleEndian.putInt(masterBytes, 0, Units.pointsToMaster(height)); + p.setElement(row, masterBytes); + + // move the cells + double dy = height - currentHeight; for (int i = row; i < cells.length; i++) { - for (int j = 0; j < cells[i].length; j++) { - Rectangle2D anchor = cells[i][j].getAnchor(); - if(i == row) { - anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), pxHeight); - } else { - anchor.setRect(anchor.getX(), anchor.getY()+dy, anchor.getWidth(), pxHeight); + for (HSLFTableCell c : cells[i]) { + if (c == null) { + continue; } - cells[i][j].setAnchor(anchor); + Rectangle2D anchor = c.getAnchor(); + if(i == row) { + anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height); + } else { + anchor.setRect(anchor.getX(), anchor.getY()+dy, anchor.getWidth(), anchor.getHeight()); + } + c.setAnchor(anchor); } } Rectangle2D tblanchor = getAnchor(); tblanchor.setRect(tblanchor.getX(), tblanchor.getY(), tblanchor.getWidth(), tblanchor.getHeight() + dy); setExteriorAnchor(tblanchor); - } @Override @@ -453,7 +461,7 @@ implements HSLFShapeContainer, TableShape { } private void updateRowHeightsProperty() { - AbstractEscherOptRecord opt = getEscherOptRecord(); + AbstractEscherOptRecord opt = getEscherChild(RecordTypes.EscherUserDefined.typeID); EscherArrayProperty p = opt.lookup(EscherProperties.GROUPSHAPE__TABLEROWPROPERTIES); byte[] val = new byte[4]; for (int rowIdx = 0; rowIdx < cells.length; rowIdx++) {