#60998 - HSLFTable.setRowHeight sets row height incorrect

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1791696 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2017-04-17 17:13:23 +00:00
parent 7df2a8804c
commit c89d312bad
4 changed files with 32 additions and 18 deletions

View 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;

View 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();

View 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;

View 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();
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<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++) {