Applied patches from Piers and my latest changes

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353539 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Said Ryan Ackley 2004-03-23 05:51:55 +00:00
parent a4b724d66a
commit 7e34048b96
13 changed files with 229 additions and 152 deletions

View File

@ -1,57 +1,20 @@
/* /* ====================================================================
* ==================================================================== Copyright 2002-2004 Apache Software Foundation
* The Apache Software License, Version 1.1
* Licensed under the Apache License, Version 2.0 (the "License");
* Copyright (c) 2003 The Apache Software Foundation. All rights you may not use this file except in compliance with the License.
* reserved. You may obtain a copy of the License at
*
* Redistribution and use in source and binary forms, with or without http://www.apache.org/licenses/LICENSE-2.0
* modification, are permitted provided that the following conditions
* are met: Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 1. Redistributions of source code must retain the above copyright WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* notice, this list of conditions and the following disclaimer. See the License for the specific language governing permissions and
* limitations under the License.
* 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
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf; package org.apache.poi.hwpf;
import java.io.InputStream; import java.io.InputStream;
@ -61,6 +24,8 @@ import java.io.OutputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.Iterator;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
@ -122,6 +87,7 @@ public class HWPFDocument
/** Holds fonts for this document.*/ /** Holds fonts for this document.*/
private FontTable _ft; private FontTable _ft;
/** Hold list tables */
private ListTables _lt; private ListTables _lt;
@ -226,6 +192,24 @@ public class HWPFDocument
return new Range(0, p.getEnd(), this); 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() public ListTables getListTables()
{ {
return _lt; return _lt;
@ -406,6 +390,12 @@ public class HWPFDocument
return _ft; 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 * Takes two arguments, 1) name of the Word file to read in 2) location to
* write it out at. * write it out at.

View File

@ -108,7 +108,7 @@ public class Ffn
offset += _fontSig.length; offset += _fontSig.length;
offsetTmp = offset - offsetTmp; offsetTmp = offset - offsetTmp;
_xszFfnLength = this.getSize() - offsetTmp; _xszFfnLength = (this.getSize() - offsetTmp)/2;
_xszFfn = new char[_xszFfnLength]; _xszFfn = new char[_xszFfnLength];
for(int i = 0; i < _xszFfnLength; i++) for(int i = 0; i < _xszFfnLength; i++)
@ -206,8 +206,8 @@ public class Ffn
for(int i = 0; i < _xszFfn.length; i++) for(int i = 0; i < _xszFfn.length; i++)
{ {
buf[offset] = (byte)_xszFfn[i]; LittleEndian.putShort(buf, offset, (short)_xszFfn[i]);
offset += LittleEndian.BYTE_SIZE; offset += LittleEndian.SHORT_SIZE;
} }
return buf; return buf;

View File

@ -272,15 +272,15 @@ public class PAPFormattedDiskPage extends FormattedDiskPage
int maxHugeGrpprlSize = LittleEndian.getUShort(_dataStream, int maxHugeGrpprlSize = LittleEndian.getUShort(_dataStream,
hugeGrpprlOffset); hugeGrpprlOffset);
if (maxHugeGrpprlSize < grpprl.length) if (maxHugeGrpprlSize < grpprl.length-2) // grpprl.length-2 because we don't store the istd
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"This Paragraph's dataStream storage is too small."); "This Paragraph's dataStream storage is too small.");
} }
// store grpprl at hugeGrpprlOffset // store grpprl at hugeGrpprlOffset
System.arraycopy(grpprl, 2, _dataStream, hugeGrpprlOffset + 2, System.arraycopy(grpprl, 2, _dataStream, hugeGrpprlOffset + 2,
grpprl.length); grpprl.length - 2); // grpprl.length-2 because we don't store the istd
LittleEndian.putUShort(_dataStream, hugeGrpprlOffset, grpprl.length); LittleEndian.putUShort(_dataStream, hugeGrpprlOffset, grpprl.length - 2);
// grpprl = grpprl containing only a sprmPHugePapx2 // grpprl = grpprl containing only a sprmPHugePapx2
int istd = LittleEndian.getUShort(grpprl, 0); int istd = LittleEndian.getUShort(grpprl, 0);

View File

@ -110,6 +110,29 @@ public abstract class PropertyNode implements Comparable
_cpEnd = end; _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) protected boolean limitsAreEqual(Object o)
{ {

View File

@ -1,56 +1,19 @@
/* ==================================================================== /* ====================================================================
* The Apache Software License, Version 1.1 Copyright 2002-2004 Apache Software Foundation
*
* Copyright (c) 2003 The Apache Software Foundation. All rights Licensed under the Apache License, Version 2.0 (the "License");
* reserved. you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions http://www.apache.org/licenses/LICENSE-2.0
* are met:
* Unless required by applicable law or agreed to in writing, software
* 1. Redistributions of source code must retain the above copyright distributed under the License is distributed on an "AS IS" BASIS,
* notice, this list of conditions and the following disclaimer. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* 2. Redistributions in binary form must reproduce the above copyright limitations under the License.
* 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
* <http://www.apache.org/>.
*/
package org.apache.poi.hwpf.model; package org.apache.poi.hwpf.model;
@ -65,7 +28,7 @@ import java.io.UnsupportedEncodingException;
public class TextPiece extends PropertyNode implements Comparable public class TextPiece extends PropertyNode implements Comparable
{ {
private boolean _usesUnicode; private boolean _usesUnicode;
private int _length;
private PieceDescriptor _pd; private PieceDescriptor _pd;
/** /**
@ -77,9 +40,10 @@ public class TextPiece extends PropertyNode implements Comparable
public TextPiece(int start, int end, byte[] text, PieceDescriptor pd) public TextPiece(int start, int end, byte[] text, PieceDescriptor pd)
throws UnsupportedEncodingException throws UnsupportedEncodingException
{ {
/** 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"))); super(start, end, new StringBuffer(new String(text, pd.isUnicode() ? "UTF-16LE" : "Cp1252")));
_usesUnicode = pd.isUnicode(); _usesUnicode = pd.isUnicode();
_length = end - start;
_pd = pd; _pd = pd;
} }
/** /**
@ -123,6 +87,16 @@ public class TextPiece extends PropertyNode implements Comparable
return ((StringBuffer)_buf).substring(start/denominator, end/denominator); 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) public boolean equals(Object o)
{ {
if (limitsAreEqual(o)) if (limitsAreEqual(o))

View File

@ -204,6 +204,8 @@ public class TextPieceTable
int size = _textPieces.size(); int size = _textPieces.size();
TextPiece tp = (TextPiece)_textPieces.get(listIndex); TextPiece tp = (TextPiece)_textPieces.get(listIndex);
//The text piece stores the length on file.
length = length * (tp.usesUnicode() ? 2 : 1); length = length * (tp.usesUnicode() ? 2 : 1);
tp.setEnd(tp.getEnd() + length); tp.setEnd(tp.getEnd() + length);
for (int x = listIndex + 1; x < size; x++) for (int x = listIndex + 1; x < size; x++)

View File

@ -626,7 +626,7 @@ public class CharacterSprmUncompressor
{ {
return true; return true;
} }
else if ((x & 0x80) == 0x80) else if ((x & 0x81) == 0x80)
{ {
return oldVal; return oldVal;
} }

View File

@ -420,6 +420,8 @@ public class CharacterProperties
cp.field_41_xstDispFldRMark = (byte[])field_41_xstDispFldRMark.clone(); cp.field_41_xstDispFldRMark = (byte[])field_41_xstDispFldRMark.clone();
cp.field_42_shd = (ShadingDescriptor)field_42_shd.clone(); cp.field_42_shd = (ShadingDescriptor)field_42_shd.clone();
cp._ico24 = _ico24;
return cp; return cp;
} }

View File

@ -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);
}
}

View File

@ -32,9 +32,13 @@ import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
* org.apache.poi.hwpf.HWPFDocument#registerList(HWPFList) registerList} in * org.apache.poi.hwpf.HWPFDocument#registerList(HWPFList) registerList} in
* {@link org.apache.poi.hwpf.HWPFDocument HWPFDocument}. * {@link org.apache.poi.hwpf.HWPFDocument HWPFDocument}.
* *
* In Word, lists are not ranged entities. Lists only act as properties for * In Word, lists are not ranged entities, meaning you can't actually add one
* list entries. Once you register a list, you can add list entries to a * to the document. Lists only act as properties for list entries. Once you
* document that use the list. * 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 * @author Ryan Ackley
*/ */
@ -45,6 +49,12 @@ public class HWPFList
private boolean _registered; private boolean _registered;
private StyleSheet _styleSheet; 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) public HWPFList(boolean numbered, StyleSheet styleSheet)
{ {
_listData = new ListData((int)(Math.random() * (double)System.currentTimeMillis()), numbered); _listData = new ListData((int)(Math.random() * (double)System.currentTimeMillis()), numbered);
@ -52,6 +62,12 @@ public class HWPFList
_styleSheet = styleSheet; _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) public void setLevelNumberProperties(int level, CharacterProperties chp)
{ {
ListLevel listLevel = _listData.getLevel(level); ListLevel listLevel = _listData.getLevel(level);
@ -62,6 +78,12 @@ public class HWPFList
listLevel.setNumberProperties(grpprl); 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) public void setLevelParagraphProperties(int level, ParagraphProperties pap)
{ {
ListLevel listLevel = _listData.getLevel(level); ListLevel listLevel = _listData.getLevel(level);

View File

@ -184,7 +184,7 @@ public class Paragraph
public void setJustification(byte jc) public void setJustification(byte jc)
{ {
_props.setJc(jc); _props.setJc(jc);
_papx.addSprm(SPRM_JC, jc); _papx.updateSprm(SPRM_JC, jc);
} }
public boolean keepOnPage() public boolean keepOnPage()
@ -196,7 +196,7 @@ public class Paragraph
{ {
byte keep = (byte)(fKeep ? 1 : 0); byte keep = (byte)(fKeep ? 1 : 0);
_props.setFKeep(keep); _props.setFKeep(keep);
_papx.addSprm(SPRM_FKEEP, keep); _papx.updateSprm(SPRM_FKEEP, keep);
} }
public boolean keepWithNext() public boolean keepWithNext()
@ -208,7 +208,7 @@ public class Paragraph
{ {
byte keepFollow = (byte)(fKeepFollow ? 1 : 0); byte keepFollow = (byte)(fKeepFollow ? 1 : 0);
_props.setFKeepFollow(keepFollow); _props.setFKeepFollow(keepFollow);
_papx.addSprm(SPRM_FKEEPFOLLOW, keepFollow); _papx.updateSprm(SPRM_FKEEPFOLLOW, keepFollow);
} }
public boolean pageBreakBefore() public boolean pageBreakBefore()
@ -220,7 +220,7 @@ public class Paragraph
{ {
byte pageBreak = (byte)(fPageBreak ? 1 : 0); byte pageBreak = (byte)(fPageBreak ? 1 : 0);
_props.setFPageBreakBefore(pageBreak); _props.setFPageBreakBefore(pageBreak);
_papx.addSprm(SPRM_FPAGEBREAKBEFORE, pageBreak); _papx.updateSprm(SPRM_FPAGEBREAKBEFORE, pageBreak);
} }
public boolean isLineNotNumbered() public boolean isLineNotNumbered()
@ -232,7 +232,7 @@ public class Paragraph
{ {
byte noLnn = (byte)(fNoLnn ? 1 : 0); byte noLnn = (byte)(fNoLnn ? 1 : 0);
_props.setFNoLnn(noLnn); _props.setFNoLnn(noLnn);
_papx.addSprm(SPRM_FNOLINENUMB, noLnn); _papx.updateSprm(SPRM_FNOLINENUMB, noLnn);
} }
public boolean isSideBySide() public boolean isSideBySide()
@ -244,7 +244,7 @@ public class Paragraph
{ {
byte sideBySide = (byte)(fSideBySide ? 1 : 0); byte sideBySide = (byte)(fSideBySide ? 1 : 0);
_props.setFSideBySide(sideBySide); _props.setFSideBySide(sideBySide);
_papx.addSprm(SPRM_FSIDEBYSIDE, sideBySide); _papx.updateSprm(SPRM_FSIDEBYSIDE, sideBySide);
} }
public boolean isAutoHyphenated() public boolean isAutoHyphenated()
@ -256,7 +256,7 @@ public class Paragraph
{ {
byte auto = (byte)(!autoHyph ? 1 : 0); byte auto = (byte)(!autoHyph ? 1 : 0);
_props.setFNoAutoHyph(auto); _props.setFNoAutoHyph(auto);
_papx.addSprm(SPRM_FNOAUTOHYPH, auto); _papx.updateSprm(SPRM_FNOAUTOHYPH, auto);
} }
public boolean isWidowControlled() public boolean isWidowControlled()
@ -268,7 +268,7 @@ public class Paragraph
{ {
byte widow = (byte)(widowControl ? 1 : 0); byte widow = (byte)(widowControl ? 1 : 0);
_props.setFWidowControl(widow); _props.setFWidowControl(widow);
_papx.addSprm(SPRM_FWIDOWCONTROL, widow); _papx.updateSprm(SPRM_FWIDOWCONTROL, widow);
} }
public int getIndentFromRight() public int getIndentFromRight()
@ -279,7 +279,7 @@ public class Paragraph
public void setIndentFromRight(int dxaRight) public void setIndentFromRight(int dxaRight)
{ {
_props.setDxaRight(dxaRight); _props.setDxaRight(dxaRight);
_papx.addSprm(SPRM_DXARIGHT, (short)dxaRight); _papx.updateSprm(SPRM_DXARIGHT, (short)dxaRight);
} }
public int getIndentFromLeft() public int getIndentFromLeft()
@ -290,7 +290,7 @@ public class Paragraph
public void setIndentFromLeft(int dxaLeft) public void setIndentFromLeft(int dxaLeft)
{ {
_props.setDxaLeft(dxaLeft); _props.setDxaLeft(dxaLeft);
_papx.addSprm(SPRM_DXALEFT, (short)dxaLeft); _papx.updateSprm(SPRM_DXALEFT, (short)dxaLeft);
} }
public int getFirstLineIndent() public int getFirstLineIndent()
@ -301,7 +301,7 @@ public class Paragraph
public void setFirstLineIndent(int first) public void setFirstLineIndent(int first)
{ {
_props.setDxaLeft1(first); _props.setDxaLeft1(first);
_papx.addSprm(SPRM_DXALEFT1, (short)first); _papx.updateSprm(SPRM_DXALEFT1, (short)first);
} }
public LineSpacingDescriptor getLineSpacing() public LineSpacingDescriptor getLineSpacing()
@ -312,7 +312,7 @@ public class Paragraph
public void setLineSpacing(LineSpacingDescriptor lspd) public void setLineSpacing(LineSpacingDescriptor lspd)
{ {
_props.setLspd(lspd); _props.setLspd(lspd);
_papx.addSprm(SPRM_DYALINE, lspd.toInt()); _papx.updateSprm(SPRM_DYALINE, lspd.toInt());
} }
public int getSpacingBefore() public int getSpacingBefore()
@ -323,7 +323,7 @@ public class Paragraph
public void setSpacingBefore(int before) public void setSpacingBefore(int before)
{ {
_props.setDyaBefore(before); _props.setDyaBefore(before);
_papx.addSprm(SPRM_DYABEFORE, (short)before); _papx.updateSprm(SPRM_DYABEFORE, (short)before);
} }
public int getSpacingAfter() public int getSpacingAfter()
@ -334,7 +334,7 @@ public class Paragraph
public void setSpacingAfter(int after) public void setSpacingAfter(int after)
{ {
_props.setDyaAfter(after); _props.setDyaAfter(after);
_papx.addSprm(SPRM_DYAAFTER, (short)after); _papx.updateSprm(SPRM_DYAAFTER, (short)after);
} }
public boolean isKinsoku() public boolean isKinsoku()
@ -346,7 +346,7 @@ public class Paragraph
{ {
byte kin = (byte)(kinsoku ? 1 : 0); byte kin = (byte)(kinsoku ? 1 : 0);
_props.setFKinsoku(kin); _props.setFKinsoku(kin);
_papx.addSprm(SPRM_FKINSOKU, kin); _papx.updateSprm(SPRM_FKINSOKU, kin);
} }
public boolean isWordWrapped() public boolean isWordWrapped()
@ -358,7 +358,7 @@ public class Paragraph
{ {
byte wordWrap = (byte)(wrap ? 1 : 0); byte wordWrap = (byte)(wrap ? 1 : 0);
_props.setFWordWrap(wordWrap); _props.setFWordWrap(wordWrap);
_papx.addSprm(SPRM_FWORDWRAP, wordWrap); _papx.updateSprm(SPRM_FWORDWRAP, wordWrap);
} }
public int getFontAlignment() public int getFontAlignment()
@ -369,7 +369,7 @@ public class Paragraph
public void setFontAlignment(int align) public void setFontAlignment(int align)
{ {
_props.setWAlignFont(align); _props.setWAlignFont(align);
_papx.addSprm(SPRM_WALIGNFONT, (short)align); _papx.updateSprm(SPRM_WALIGNFONT, (short)align);
} }
public boolean isVertical() public boolean isVertical()
@ -380,7 +380,7 @@ public class Paragraph
public void setVertical(boolean vertical) public void setVertical(boolean vertical)
{ {
_props.setFVertical(vertical); _props.setFVertical(vertical);
_papx.addSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow()); _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
} }
public boolean isBackward() public boolean isBackward()
@ -391,7 +391,7 @@ public class Paragraph
public void setBackward(boolean bward) public void setBackward(boolean bward)
{ {
_props.setFBackward(bward); _props.setFBackward(bward);
_papx.addSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow()); _papx.updateSprm(SPRM_FRAMETEXTFLOW, getFrameTextFlow());
} }
public BorderCode getTopBorder() public BorderCode getTopBorder()
@ -402,7 +402,7 @@ public class Paragraph
public void setTopBorder(BorderCode top) public void setTopBorder(BorderCode top)
{ {
_props.setBrcTop(top); _props.setBrcTop(top);
_papx.addSprm(SPRM_BRCTOP, top.toInt()); _papx.updateSprm(SPRM_BRCTOP, top.toInt());
} }
public BorderCode getLeftBorder() public BorderCode getLeftBorder()
@ -413,7 +413,7 @@ public class Paragraph
public void setLeftBorder(BorderCode left) public void setLeftBorder(BorderCode left)
{ {
_props.setBrcLeft(left); _props.setBrcLeft(left);
_papx.addSprm(SPRM_BRCLEFT, left.toInt()); _papx.updateSprm(SPRM_BRCLEFT, left.toInt());
} }
public BorderCode getBottomBorder() public BorderCode getBottomBorder()
@ -424,7 +424,7 @@ public class Paragraph
public void setBottomBorder(BorderCode bottom) public void setBottomBorder(BorderCode bottom)
{ {
_props.setBrcBottom(bottom); _props.setBrcBottom(bottom);
_papx.addSprm(SPRM_BRCBOTTOM, bottom.toInt()); _papx.updateSprm(SPRM_BRCBOTTOM, bottom.toInt());
} }
public BorderCode getRightBorder() public BorderCode getRightBorder()
@ -435,7 +435,7 @@ public class Paragraph
public void setRightBorder(BorderCode right) public void setRightBorder(BorderCode right)
{ {
_props.setBrcRight(right); _props.setBrcRight(right);
_papx.addSprm(SPRM_BRCRIGHT, right.toInt()); _papx.updateSprm(SPRM_BRCRIGHT, right.toInt());
} }
public BorderCode getBarBorder() public BorderCode getBarBorder()
@ -446,7 +446,7 @@ public class Paragraph
public void setBarBorder(BorderCode bar) public void setBarBorder(BorderCode bar)
{ {
_props.setBrcBar(bar); _props.setBrcBar(bar);
_papx.addSprm(SPRM_BRCBAR, bar.toInt()); _papx.updateSprm(SPRM_BRCBAR, bar.toInt());
} }
public ShadingDescriptor getShading() public ShadingDescriptor getShading()
@ -457,7 +457,7 @@ public class Paragraph
public void setShading(ShadingDescriptor shd) public void setShading(ShadingDescriptor shd)
{ {
_props.setShd(shd); _props.setShd(shd);
_papx.addSprm(SPRM_SHD, shd.toShort()); _papx.updateSprm(SPRM_SHD, shd.toShort());
} }
public DropCapSpecifier getDropCap() public DropCapSpecifier getDropCap()
@ -468,7 +468,7 @@ public class Paragraph
public void setDropCap(DropCapSpecifier dcs) public void setDropCap(DropCapSpecifier dcs)
{ {
_props.setDcs(dcs); _props.setDcs(dcs);
_papx.addSprm(SPRM_DCS, dcs.toShort()); _papx.updateSprm(SPRM_DCS, dcs.toShort());
} }
void setTableRowEnd(TableProperties props) void setTableRowEnd(TableProperties props)
@ -481,7 +481,7 @@ public class Paragraph
private void setTableRowEnd(byte val) private void setTableRowEnd(byte val)
{ {
_props.setFTtp(val); _props.setFTtp(val);
_papx.addSprm(SPRM_FTTP, val); _papx.updateSprm(SPRM_FTTP, val);
} }
public Object clone() public Object clone()

View File

@ -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 * It is possible to insert text and/or properties at the beginning or end of a
* range. * 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 * @author Ryan Ackley
*/ */
public class Range public class Range
@ -161,6 +165,7 @@ public class Range
_parent = new WeakReference(null); _parent = new WeakReference(null);
} }
/** /**
* Used to create Ranges that are children of other Ranges. * Used to create Ranges that are children of other Ranges.
* *
@ -480,6 +485,33 @@ public class Range
return getParagraph(numParagraphs() - 1); 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 * Inserts a simple table into the beginning of this range. The number of
* columns is determined by the TableProperties passed into this function. * columns is determined by the TableProperties passed into this function.
@ -546,7 +578,7 @@ public class Range
initCharacterRuns(); initCharacterRuns();
CHPX chpx = (CHPX)_characters.get(index + _charStart); 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()); chpx.getEnd());
PAPX papx = (PAPX)_paragraphs.get(point[0]); PAPX papx = (PAPX)_paragraphs.get(point[0]);
short istd = papx.getIstd(); short istd = papx.getIstd();