diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index 28d4d9ad8..56024d9fd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -1,57 +1,20 @@ -/* - * ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2003 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache POI" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache POI", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + + package org.apache.poi.hwpf; import java.io.InputStream; @@ -61,6 +24,8 @@ import java.io.OutputStream; import java.io.ByteArrayInputStream; import java.io.FileOutputStream; +import java.util.Iterator; + import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.common.POIFSConstants; @@ -122,6 +87,7 @@ public class HWPFDocument /** Holds fonts for this document.*/ private FontTable _ft; + /** Hold list tables */ private ListTables _lt; @@ -226,6 +192,24 @@ public class HWPFDocument return new Range(0, p.getEnd(), this); } + /** + * Returns the character length of a document. + * @return + */ + public int characterLength() + { + java.util.List textPieces = _tpt.getTextPieces(); + Iterator textIt = textPieces.iterator(); + + int length = 0; + while(textIt.hasNext()) + { + TextPiece tp = (TextPiece)textIt.next(); + length += tp.characterLength(); + } + return length; + } + public ListTables getListTables() { return _lt; @@ -406,6 +390,12 @@ public class HWPFDocument return _ft; } + public void delete(int start, int length) + { + Range r = new Range(start, start + length, this); + r.delete(); + } + /** * Takes two arguments, 1) name of the Word file to read in 2) location to * write it out at. diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java index e4ca163c1..65feccf30 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Ffn.java @@ -108,7 +108,7 @@ public class Ffn offset += _fontSig.length; offsetTmp = offset - offsetTmp; - _xszFfnLength = this.getSize() - offsetTmp; + _xszFfnLength = (this.getSize() - offsetTmp)/2; _xszFfn = new char[_xszFfnLength]; for(int i = 0; i < _xszFfnLength; i++) @@ -206,13 +206,13 @@ public class Ffn for(int i = 0; i < _xszFfn.length; i++) { - buf[offset] = (byte)_xszFfn[i]; - offset += LittleEndian.BYTE_SIZE; + LittleEndian.putShort(buf, offset, (short)_xszFfn[i]); + offset += LittleEndian.SHORT_SIZE; } - return buf; + return buf; - } + } public boolean equals(Object o) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java index 6f0507f8a..23919ea20 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FontTable.java @@ -159,7 +159,7 @@ public class FontTable for(int i = 0; i < _fontNames.length; i++) { - tableStream.write(_fontNames[i].toByteArray()); + tableStream.write(_fontNames[i].toByteArray()); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java index 42cd566b2..b76821d91 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java @@ -272,15 +272,15 @@ public class PAPFormattedDiskPage extends FormattedDiskPage int maxHugeGrpprlSize = LittleEndian.getUShort(_dataStream, hugeGrpprlOffset); - if (maxHugeGrpprlSize < grpprl.length) + if (maxHugeGrpprlSize < grpprl.length-2) // grpprl.length-2 because we don't store the istd throw new UnsupportedOperationException( "This Paragraph's dataStream storage is too small."); } // store grpprl at hugeGrpprlOffset System.arraycopy(grpprl, 2, _dataStream, hugeGrpprlOffset + 2, - grpprl.length); - LittleEndian.putUShort(_dataStream, hugeGrpprlOffset, grpprl.length); + grpprl.length - 2); // grpprl.length-2 because we don't store the istd + LittleEndian.putUShort(_dataStream, hugeGrpprlOffset, grpprl.length - 2); // grpprl = grpprl containing only a sprmPHugePapx2 int istd = LittleEndian.getUShort(grpprl, 0); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java index ad5a3953c..7bca00d1a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java @@ -110,6 +110,29 @@ public abstract class PropertyNode implements Comparable _cpEnd = end; } + /** + * Adjust for a deletion that can span multiple PropertyNodes. + * @param start + * @param length + */ + public void adjustForDelete(int start, int length) + { + int end = start + length; + + if (_cpEnd > start) + { + if (_cpStart < end) + { + _cpEnd = end >= _cpEnd ? start : _cpEnd - length; + _cpStart = Math.min(start, _cpStart); + } + else + { + _cpEnd -= length; + _cpStart -= length; + } + } + } protected boolean limitsAreEqual(Object o) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java index fff36ce62..e1a856a44 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPiece.java @@ -1,56 +1,19 @@ /* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2003 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache POI" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache POI", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ + Copyright 2002-2004 Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + package org.apache.poi.hwpf.model; @@ -65,7 +28,7 @@ import java.io.UnsupportedEncodingException; public class TextPiece extends PropertyNode implements Comparable { private boolean _usesUnicode; - private int _length; + private PieceDescriptor _pd; /** @@ -77,10 +40,11 @@ public class TextPiece extends PropertyNode implements Comparable public TextPiece(int start, int end, byte[] text, PieceDescriptor pd) throws UnsupportedEncodingException { - super(start, end, new StringBuffer(new String(text, pd.isUnicode() ? "UTF-16LE" : "Cp1252"))); - _usesUnicode = pd.isUnicode(); - _length = end - start; - _pd = pd; + /** start - end is length on file. This is double the expected when its + * unicode.*/ + super(start, end, new StringBuffer(new String(text, pd.isUnicode() ? "UTF-16LE" : "Cp1252"))); + _usesUnicode = pd.isUnicode(); + _pd = pd; } /** * @return If this text piece uses unicode @@ -123,6 +87,16 @@ public class TextPiece extends PropertyNode implements Comparable return ((StringBuffer)_buf).substring(start/denominator, end/denominator); } + public void adjustForDelete(int start, int length) + { + + } + + public int characterLength() + { + return (getEnd() - getStart()) / (_usesUnicode ? 2 : 1); + } + public boolean equals(Object o) { if (limitsAreEqual(o)) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java index 1718d3a0b..2d13d4c54 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java @@ -204,6 +204,8 @@ public class TextPieceTable int size = _textPieces.size(); TextPiece tp = (TextPiece)_textPieces.get(listIndex); + + //The text piece stores the length on file. length = length * (tp.usesUnicode() ? 2 : 1); tp.setEnd(tp.getEnd() + length); for (int x = listIndex + 1; x < size; x++) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java index 2c69bde74..c4f1c81bf 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java @@ -626,7 +626,7 @@ public class CharacterSprmUncompressor { return true; } - else if ((x & 0x80) == 0x80) + else if ((x & 0x81) == 0x80) { return oldVal; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java index 47add56d5..78a8b9734 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/CharacterProperties.java @@ -420,6 +420,8 @@ public class CharacterProperties cp.field_41_xstDispFldRMark = (byte[])field_41_xstDispFldRMark.clone(); cp.field_42_shd = (ShadingDescriptor)field_42_shd.clone(); + cp._ico24 = _ico24; + return cp; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DocumentPosition.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DocumentPosition.java new file mode 100644 index 000000000..a9bc94b39 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/DocumentPosition.java @@ -0,0 +1,32 @@ +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +/** + * @author Ryan Ackley + */ +package org.apache.poi.hwpf.usermodel; + +import org.apache.poi.hwpf.HWPFDocument; + +public class DocumentPosition + extends Range +{ + public DocumentPosition(HWPFDocument doc, int pos) + { + super(pos, pos, doc); + } + +} \ No newline at end of file diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java index 66dc3bd30..001b60afd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HWPFList.java @@ -32,9 +32,13 @@ import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor; * org.apache.poi.hwpf.HWPFDocument#registerList(HWPFList) registerList} in * {@link org.apache.poi.hwpf.HWPFDocument HWPFDocument}. * - * In Word, lists are not ranged entities. Lists only act as properties for - * list entries. Once you register a list, you can add list entries to a - * document that use the list. + * In Word, lists are not ranged entities, meaning you can't actually add one + * to the document. Lists only act as properties for list entries. Once you + * register a list, you can add list entries to a document that are a part of + * the list. + * + * The only benefit of this that I see, is that you can add a list entry + * anywhere in the document and continue numbering from the previous list. * * @author Ryan Ackley */ @@ -45,6 +49,12 @@ public class HWPFList private boolean _registered; private StyleSheet _styleSheet; + /** + * + * @param numbered true if the list should be numbered; false if it should be + * bulleted. + * @param styleSheet The document's stylesheet. + */ public HWPFList(boolean numbered, StyleSheet styleSheet) { _listData = new ListData((int)(Math.random() * (double)System.currentTimeMillis()), numbered); @@ -52,6 +62,12 @@ public class HWPFList _styleSheet = styleSheet; } + /** + * Sets the character properties of the list numbers. + * + * @param level the level number that the properties should apply to. + * @param chp The character properties. + */ public void setLevelNumberProperties(int level, CharacterProperties chp) { ListLevel listLevel = _listData.getLevel(level); @@ -62,6 +78,12 @@ public class HWPFList listLevel.setNumberProperties(grpprl); } + /** + * Sets the paragraph properties for a particular level of the list. + * + * @param level The level number. + * @param pap The paragraph properties + */ public void setLevelParagraphProperties(int level, ParagraphProperties pap) { ListLevel listLevel = _listData.getLevel(level); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java index cf929a9b6..f3e9f130a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java @@ -184,7 +184,7 @@ public class Paragraph public void setJustification(byte jc) { _props.setJc(jc); - _papx.addSprm(SPRM_JC, jc); + _papx.updateSprm(SPRM_JC, jc); } public boolean keepOnPage() @@ -196,7 +196,7 @@ public class Paragraph { byte keep = (byte)(fKeep ? 1 : 0); _props.setFKeep(keep); - _papx.addSprm(SPRM_FKEEP, keep); + _papx.updateSprm(SPRM_FKEEP, keep); } public boolean keepWithNext() @@ -208,7 +208,7 @@ public class Paragraph { byte keepFollow = (byte)(fKeepFollow ? 1 : 0); _props.setFKeepFollow(keepFollow); - _papx.addSprm(SPRM_FKEEPFOLLOW, keepFollow); + _papx.updateSprm(SPRM_FKEEPFOLLOW, keepFollow); } public boolean pageBreakBefore() @@ -220,7 +220,7 @@ public class Paragraph { byte pageBreak = (byte)(fPageBreak ? 1 : 0); _props.setFPageBreakBefore(pageBreak); - _papx.addSprm(SPRM_FPAGEBREAKBEFORE, pageBreak); + _papx.updateSprm(SPRM_FPAGEBREAKBEFORE, pageBreak); } public boolean isLineNotNumbered() @@ -232,7 +232,7 @@ public class Paragraph { byte noLnn = (byte)(fNoLnn ? 1 : 0); _props.setFNoLnn(noLnn); - _papx.addSprm(SPRM_FNOLINENUMB, noLnn); + _papx.updateSprm(SPRM_FNOLINENUMB, noLnn); } public boolean isSideBySide() @@ -244,7 +244,7 @@ public class Paragraph { byte sideBySide = (byte)(fSideBySide ? 1 : 0); _props.setFSideBySide(sideBySide); - _papx.addSprm(SPRM_FSIDEBYSIDE, sideBySide); + _papx.updateSprm(SPRM_FSIDEBYSIDE, sideBySide); } public boolean isAutoHyphenated() @@ -256,7 +256,7 @@ public class Paragraph { byte auto = (byte)(!autoHyph ? 1 : 0); _props.setFNoAutoHyph(auto); - _papx.addSprm(SPRM_FNOAUTOHYPH, auto); + _papx.updateSprm(SPRM_FNOAUTOHYPH, auto); } public boolean isWidowControlled() @@ -268,7 +268,7 @@ public class Paragraph { byte widow = (byte)(widowControl ? 1 : 0); _props.setFWidowControl(widow); - _papx.addSprm(SPRM_FWIDOWCONTROL, widow); + _papx.updateSprm(SPRM_FWIDOWCONTROL, widow); } public int getIndentFromRight() @@ -279,7 +279,7 @@ public class Paragraph public void setIndentFromRight(int dxaRight) { _props.setDxaRight(dxaRight); - _papx.addSprm(SPRM_DXARIGHT, (short)dxaRight); + _papx.updateSprm(SPRM_DXARIGHT, (short)dxaRight); } public int getIndentFromLeft() @@ -290,7 +290,7 @@ public class Paragraph public void setIndentFromLeft(int dxaLeft) { _props.setDxaLeft(dxaLeft); - _papx.addSprm(SPRM_DXALEFT, (short)dxaLeft); + _papx.updateSprm(SPRM_DXALEFT, (short)dxaLeft); } public int getFirstLineIndent() @@ -301,7 +301,7 @@ public class Paragraph public void setFirstLineIndent(int first) { _props.setDxaLeft1(first); - _papx.addSprm(SPRM_DXALEFT1, (short)first); + _papx.updateSprm(SPRM_DXALEFT1, (short)first); } public LineSpacingDescriptor getLineSpacing() @@ -312,7 +312,7 @@ public class Paragraph public void setLineSpacing(LineSpacingDescriptor lspd) { _props.setLspd(lspd); - _papx.addSprm(SPRM_DYALINE, lspd.toInt()); + _papx.updateSprm(SPRM_DYALINE, lspd.toInt()); } public int getSpacingBefore() @@ -323,7 +323,7 @@ public class Paragraph public void setSpacingBefore(int before) { _props.setDyaBefore(before); - _papx.addSprm(SPRM_DYABEFORE, (short)before); + _papx.updateSprm(SPRM_DYABEFORE, (short)before); } public int getSpacingAfter() @@ -334,7 +334,7 @@ public class Paragraph public void setSpacingAfter(int after) { _props.setDyaAfter(after); - _papx.addSprm(SPRM_DYAAFTER, (short)after); + _papx.updateSprm(SPRM_DYAAFTER, (short)after); } public boolean isKinsoku() @@ -346,7 +346,7 @@ public class Paragraph { byte kin = (byte)(kinsoku ? 1 : 0); _props.setFKinsoku(kin); - _papx.addSprm(SPRM_FKINSOKU, kin); + _papx.updateSprm(SPRM_FKINSOKU, kin); } public boolean isWordWrapped() @@ -358,7 +358,7 @@ public class Paragraph { byte wordWrap = (byte)(wrap ? 1 : 0); _props.setFWordWrap(wordWrap); - _papx.addSprm(SPRM_FWORDWRAP, wordWrap); + _papx.updateSprm(SPRM_FWORDWRAP, wordWrap); } public int getFontAlignment() @@ -369,7 +369,7 @@ public class Paragraph public void setFontAlignment(int align) { _props.setWAlignFont(align); - _papx.addSprm(SPRM_WALIGNFONT, (short)align); + _papx.updateSprm(SPRM_WALIGNFONT, (short)align); } public boolean isVertical() @@ -380,7 +380,7 @@ public class Paragraph public void setVertical(boolean vertical) { _props.setFVertical(vertical); - _papx.addSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow()); + _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow()); } public boolean isBackward() @@ -391,7 +391,7 @@ public class Paragraph public void setBackward(boolean bward) { _props.setFBackward(bward); - _papx.addSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow()); + _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow()); } public BorderCode getTopBorder() @@ -402,7 +402,7 @@ public class Paragraph public void setTopBorder(BorderCode top) { _props.setBrcTop(top); - _papx.addSprm(SPRM_BRCTOP, top.toInt()); + _papx.updateSprm(SPRM_BRCTOP, top.toInt()); } public BorderCode getLeftBorder() @@ -413,7 +413,7 @@ public class Paragraph public void setLeftBorder(BorderCode left) { _props.setBrcLeft(left); - _papx.addSprm(SPRM_BRCLEFT, left.toInt()); + _papx.updateSprm(SPRM_BRCLEFT, left.toInt()); } public BorderCode getBottomBorder() @@ -424,7 +424,7 @@ public class Paragraph public void setBottomBorder(BorderCode bottom) { _props.setBrcBottom(bottom); - _papx.addSprm(SPRM_BRCBOTTOM, bottom.toInt()); + _papx.updateSprm(SPRM_BRCBOTTOM, bottom.toInt()); } public BorderCode getRightBorder() @@ -435,7 +435,7 @@ public class Paragraph public void setRightBorder(BorderCode right) { _props.setBrcRight(right); - _papx.addSprm(SPRM_BRCRIGHT, right.toInt()); + _papx.updateSprm(SPRM_BRCRIGHT, right.toInt()); } public BorderCode getBarBorder() @@ -446,7 +446,7 @@ public class Paragraph public void setBarBorder(BorderCode bar) { _props.setBrcBar(bar); - _papx.addSprm(SPRM_BRCBAR, bar.toInt()); + _papx.updateSprm(SPRM_BRCBAR, bar.toInt()); } public ShadingDescriptor getShading() @@ -457,7 +457,7 @@ public class Paragraph public void setShading(ShadingDescriptor shd) { _props.setShd(shd); - _papx.addSprm(SPRM_SHD, shd.toShort()); + _papx.updateSprm(SPRM_SHD, shd.toShort()); } public DropCapSpecifier getDropCap() @@ -468,7 +468,7 @@ public class Paragraph public void setDropCap(DropCapSpecifier dcs) { _props.setDcs(dcs); - _papx.addSprm(SPRM_DCS, dcs.toShort()); + _papx.updateSprm(SPRM_DCS, dcs.toShort()); } void setTableRowEnd(TableProperties props) @@ -481,7 +481,7 @@ public class Paragraph private void setTableRowEnd(byte val) { _props.setFTtp(val); - _papx.addSprm(SPRM_FTTP, val); + _papx.updateSprm(SPRM_FTTP, val); } public Object clone() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java index f633fc424..ed991e1c6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -63,6 +63,10 @@ import java.lang.ref.WeakReference; * It is possible to insert text and/or properties at the beginning or end of a * range. * + * Ranges are only valid if there hasn't been an insert in a prior Range since + * the Range's creation. Once an element (text, paragraph, etc.) has been + * inserted into a Range, subsequent Ranges become unstable. + * * @author Ryan Ackley */ public class Range @@ -161,6 +165,7 @@ public class Range _parent = new WeakReference(null); } + /** * Used to create Ranges that are children of other Ranges. * @@ -480,6 +485,33 @@ public class Range return getParagraph(numParagraphs() - 1); } + public void delete() + { + initAll(); + + int numSections = _sections.size(); + int numRuns = _characters.size(); + int numParagraphs = _paragraphs.size(); + + for (int x = _charStart; x < numRuns; x++) + { + CHPX chpx = (CHPX)_characters.get(x); + chpx.adjustForDelete(_start, _end - _start); + } + + for (int x = _parStart; x < numParagraphs; x++) + { + PAPX papx = (PAPX)_paragraphs.get(x); + papx.adjustForDelete(_start, _end - _start); + } + + for (int x = _sectionStart; x < numSections; x++) + { + SEPX sepx = (SEPX)_sections.get(x); + sepx.adjustForDelete(_start, _end - _start); + } + } + /** * Inserts a simple table into the beginning of this range. The number of * columns is determined by the TableProperties passed into this function. @@ -546,7 +578,7 @@ public class Range initCharacterRuns(); CHPX chpx = (CHPX)_characters.get(index + _charStart); - int[] point = findRange(_paragraphs, _parStart, chpx.getStart(), + int[] point = findRange(_paragraphs, _parStart, Math.max(chpx.getStart(), _start), chpx.getEnd()); PAPX papx = (PAPX)_paragraphs.get(point[0]); short istd = papx.getIstd();