diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPFormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPFormattedDiskPage.java index e340676552..b453c7cffd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPFormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/CHPFormattedDiskPage.java @@ -145,7 +145,7 @@ public class CHPFormattedDiskPage extends FormattedDiskPage { byte[] buf = new byte[512]; int size = _chpxList.size(); - int grpprlOffset = 0; + int grpprlOffset = 511; int offsetOffset = 0; int fcOffset = 0; @@ -185,7 +185,7 @@ public class CHPFormattedDiskPage extends FormattedDiskPage buf[511] = (byte)index; offsetOffset = (FC_SIZE * index) + FC_SIZE; - grpprlOffset = offsetOffset + index + (grpprlOffset % 2); + //grpprlOffset = offsetOffset + index + (grpprlOffset % 2); CHPX chpx = null; for (int x = 0; x < index; x++) @@ -194,10 +194,13 @@ public class CHPFormattedDiskPage extends FormattedDiskPage byte[] grpprl = chpx.getGrpprl(); LittleEndian.putInt(buf, fcOffset, chpx.getStart() + fcMin); + grpprlOffset -= (1 + grpprl.length); + grpprlOffset -= (grpprlOffset % 2); buf[offsetOffset] = (byte)(grpprlOffset/2); - System.arraycopy(grpprl, 0, buf, grpprlOffset, grpprl.length); + buf[grpprlOffset] = (byte)grpprl.length; + System.arraycopy(grpprl, 0, buf, grpprlOffset + 1, grpprl.length); + - grpprlOffset += grpprl.length + (grpprl.length % 2); offsetOffset += 1; fcOffset += FC_SIZE; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPFormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPFormattedDiskPage.java index f23234a434..b4e1a35c27 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPFormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PAPFormattedDiskPage.java @@ -194,7 +194,7 @@ public class PAPFormattedDiskPage extends FormattedDiskPage buf[511] = (byte)index; bxOffset = (FC_SIZE * index) + FC_SIZE; - grpprlOffset = bxOffset + (BX_SIZE * index) + (grpprlOffset % 2); + grpprlOffset = 511; PAPX papx = null; for (int x = 0; x < index; x++) @@ -203,6 +203,7 @@ public class PAPFormattedDiskPage extends FormattedDiskPage byte[] phe = papx.getParagraphHeight().toByteArray(); byte[] grpprl = papx.getGrpprl(); + grpprlOffset -= (grpprl.length + (2 - grpprl.length % 2)); LittleEndian.putInt(buf, fcOffset, papx.getStart() + fcMin); buf[bxOffset] = (byte)(grpprlOffset/2); System.arraycopy(phe, 0, buf, bxOffset + 1, phe.length); @@ -210,16 +211,17 @@ public class PAPFormattedDiskPage extends FormattedDiskPage // refer to the section on PAPX in the spec. Places a size on the front // of the PAPX. Has to do with how the grpprl stays on word // boundaries. + int copyOffset = grpprlOffset; if ((grpprl.length % 2) > 0) { - buf[grpprlOffset++] = (byte)((grpprl.length + 1)/2); + buf[copyOffset++] = (byte)((grpprl.length + 1)/2); } else { - buf[++grpprlOffset] = (byte)((grpprl.length)/2); - grpprlOffset++; + buf[++copyOffset] = (byte)((grpprl.length)/2); + copyOffset++; } - System.arraycopy(grpprl, 0, buf, grpprlOffset, grpprl.length); + System.arraycopy(grpprl, 0, buf, copyOffset, grpprl.length); bxOffset += BX_SIZE; fcOffset += FC_SIZE; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java index c7255e6b69..1d94ba83aa 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/hdftypes/PropertyNode.java @@ -99,6 +99,28 @@ public class PropertyNode implements Comparable { return _buf; } + + public boolean equals(Object o) + { + if (((PropertyNode)o).getStart() == _cpStart && + ((PropertyNode)o).getEnd() == _cpEnd) + { + byte[] testBuf = ((PropertyNode)o).getBuf(); + + if (testBuf.length == _buf.length) + { + for (int x = 0; x < _buf.length; x++) + { + if (testBuf[x] != _buf[x]) + { + return false; + } + } + return true; + } + } + return false; + } /** * Used for sorting in collections. */