]> source.dussan.org Git - poi.git/commitdiff
#60998 - HSLFTable.setRowHeight sets row height incorrect
authorAndreas Beeker <kiwiwings@apache.org>
Mon, 17 Apr 2017 17:13:23 +0000 (17:13 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Mon, 17 Apr 2017 17:13:23 +0000 (17:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1791696 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ddf/EscherProperties.java
src/ooxml/testcases/org/apache/poi/sl/TestTable.java
src/scratchpad/src/org/apache/poi/hslf/record/RecordTypes.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java

index 096a20c574545175e5fe15433a2ca3a5b343eb2a..955db365fa5f684eeb6a8c0b2f3c49f6636f5c5e 100644 (file)
@@ -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;
index 5b45f9973e3822e2128c43326a61f6ccbfdd5a0a..6028756626d89de93e9c2d755947d624dd84a634 100644 (file)
@@ -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();
index c0c57255f334bf518125284c7086da7d58ae61aa..44595b74736fb4bd699816a0d49941a70534ae42 100644 (file)
@@ -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<Short,RecordTypes> LOOKUP;
index b159e7ca6f991accacdb8dbb5c85b598dcee05e2..586005b570dbee28a73f9ce9e7da7123a072d43e 100644 (file)
@@ -361,30 +361,38 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
     }
     
     @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();
+            for (HSLFTableCell c : cells[i]) {
+                if (c == null) {
+                    continue;
+                }
+                Rectangle2D anchor = c.getAnchor();
                 if(i == row) {
-                    anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), pxHeight);
+                    anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height);
                 } else {
-                    anchor.setRect(anchor.getX(), anchor.getY()+dy, anchor.getWidth(), pxHeight);
+                    anchor.setRect(anchor.getX(), anchor.getY()+dy, anchor.getWidth(), anchor.getHeight());
                 }
-                cells[i][j].setAnchor(anchor);
+                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<HSLFShape,HSLFTextParagraph> {
     }
 
     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++) {