make Table elements constructors accepts char positions (as other constructors); fix SprmBuffer usage for PAPX

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1145377 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-07-11 21:59:33 +00:00
parent 98c52813dd
commit c8bb280df0
7 changed files with 40 additions and 57 deletions

View File

@ -41,7 +41,7 @@ public final class PAPX extends BytePropertyNode<PAPX> {
public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, byte[] papx, ParagraphHeight phe, byte[] dataStream) public PAPX(int fcStart, int fcEnd, CharIndexTranslator translator, byte[] papx, ParagraphHeight phe, byte[] dataStream)
{ {
super(fcStart, fcEnd, translator, new SprmBuffer(papx, 0)); super(fcStart, fcEnd, translator, new SprmBuffer(papx, 2));
_phe = phe; _phe = phe;
SprmBuffer buf = findHuge(new SprmBuffer(papx, 2), dataStream); SprmBuffer buf = findHuge(new SprmBuffer(papx, 2), dataStream);
if(buf != null) if(buf != null)

View File

@ -84,9 +84,12 @@ public class Paragraph extends Range implements Cloneable {
protected ParagraphProperties _props; protected ParagraphProperties _props;
protected SprmBuffer _papx; protected SprmBuffer _papx;
protected Paragraph(int startIdxInclusive, int endIdxExclusive, Table parent) protected Paragraph( int startIdxInclusive, int endIdxExclusive,
Table parent )
{ {
super(startIdxInclusive, endIdxExclusive, Range.TYPE_PARAGRAPH, parent); super( startIdxInclusive, endIdxExclusive, parent );
initAll();
PAPX papx = _paragraphs.get( _parEnd - 1 ); PAPX papx = _paragraphs.get( _parEnd - 1 );
_props = papx.getParagraphProperties( _doc.getStyleSheet() ); _props = papx.getParagraphProperties( _doc.getStyleSheet() );
_papx = papx.getSprmBuf(); _papx = papx.getSprmBuf();

View File

@ -186,6 +186,7 @@ public class Range { // TODO -instantiable superclass
* @param parent * @param parent
* The parent Range this range belongs to. * The parent Range this range belongs to.
*/ */
@Deprecated
protected Range(int startIdx, int endIdx, int idxType, Range parent) { protected Range(int startIdx, int endIdx, int idxType, Range parent) {
_doc = parent._doc; _doc = parent._doc;
_sections = parent._sections; _sections = parent._sections;
@ -194,37 +195,6 @@ public class Range { // TODO -instantiable superclass
_text = parent._text; _text = parent._text;
_parent = new WeakReference<Range>(parent); _parent = new WeakReference<Range>(parent);
switch (idxType) {
case TYPE_PARAGRAPH:
_parStart = parent._parStart + startIdx;
_parEnd = parent._parStart + endIdx;
_start = _paragraphs.get(_parStart).getStart();
_end = _paragraphs.get(_parEnd - 1).getEnd();
_parRangeFound = true;
break;
case TYPE_CHARACTER:
_charStart = parent._charStart + startIdx;
_charEnd = parent._charStart + endIdx;
_start = _characters.get(_charStart - 1).getStart();
_end = _characters.get(_charEnd).getEnd();
_charRangeFound = true;
break;
case TYPE_SECTION:
_sectionStart = parent._sectionStart + startIdx;
_sectionEnd = parent._sectionStart + endIdx;
_start = _sections.get(_sectionStart - 1).getStart();
_end = _sections.get(_sectionEnd).getEnd();
_sectionRangeFound = true;
break;
case TYPE_TEXT:
_textStart = parent._textStart + startIdx;
_textEnd = parent._textStart + endIdx;
_start = _text.get(_textStart - 1).getStart();
_end = _text.get(_textEnd).getEnd();
_textRangeFound = true;
break;
}
sanityCheckStartEnd(); sanityCheckStartEnd();
} }
@ -534,7 +504,7 @@ public class Range { // TODO -instantiable superclass
byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE]; byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
LittleEndian.putShort(withIndex, (short) styleIndex); LittleEndian.putShort(withIndex, (short) styleIndex);
System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length); System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
SprmBuffer buf = new SprmBuffer(withIndex, 0); SprmBuffer buf = new SprmBuffer(withIndex, 2);
_doc.getParagraphTable().insert(_parStart, _start, buf); _doc.getParagraphTable().insert(_parStart, _start, buf);
insertBefore(text, baseChp); insertBefore(text, baseChp);
@ -584,7 +554,7 @@ public class Range { // TODO -instantiable superclass
byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE]; byte[] withIndex = new byte[grpprl.length + LittleEndian.SHORT_SIZE];
LittleEndian.putShort(withIndex, (short) styleIndex); LittleEndian.putShort(withIndex, (short) styleIndex);
System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length); System.arraycopy(grpprl, 0, withIndex, LittleEndian.SHORT_SIZE, grpprl.length);
SprmBuffer buf = new SprmBuffer(withIndex, 0); SprmBuffer buf = new SprmBuffer(withIndex, 2);
_doc.getParagraphTable().insert(_parEnd, _end, buf); _doc.getParagraphTable().insert(_parEnd, _end, buf);
_parEnd++; _parEnd++;
@ -902,12 +872,12 @@ public class Range { // TODO -instantiable superclass
} }
} }
final Range overallrange = getDocument().getOverallRange(); Range overallRange = _doc.getOverallRange();
int limit = _paragraphs.size(); int limit = _paragraphs.size();
for ( ; tableEndInclusive < limit - 1; tableEndInclusive++ ) for ( ; tableEndInclusive < limit - 1; tableEndInclusive++ )
{ {
Paragraph next = new Paragraph( _paragraphs.get( tableEndInclusive + 1 ), Paragraph next = new Paragraph(
overallrange ); _paragraphs.get( tableEndInclusive + 1 ), overallRange );
if ( !next.isInTable() || next.getTableLevel() < tableLevel ) if ( !next.isInTable() || next.getTableLevel() < tableLevel )
break; break;
} }
@ -923,8 +893,11 @@ public class Range { // TODO -instantiable superclass
throw new ArrayIndexOutOfBoundsException( throw new ArrayIndexOutOfBoundsException(
"The table's end is negative, which isn't allowed!" ); "The table's end is negative, which isn't allowed!" );
} }
return new Table( r._parStart, tableEndInclusive + 1, r._doc.getRange(),
paragraph.getTableLevel() ); int endOffsetExclusive = _paragraphs.get( tableEndInclusive ).getEnd();
return new Table( paragraph.getStartOffset(), endOffsetExclusive,
this, paragraph.getTableLevel() );
} }
/** /**

View File

@ -30,7 +30,7 @@ public final class Table extends Range
Table( int startIdxInclusive, int endIdxExclusive, Range parent, Table( int startIdxInclusive, int endIdxExclusive, Range parent,
int levelNum ) int levelNum )
{ {
super( startIdxInclusive, endIdxExclusive, Range.TYPE_PARAGRAPH, parent ); super( startIdxInclusive, endIdxExclusive, parent );
_tableLevel = levelNum; _tableLevel = levelNum;
initRows(); initRows();
} }
@ -58,11 +58,14 @@ public final class Table extends Range
int numParagraphs = numParagraphs(); int numParagraphs = numParagraphs();
while ( rowEnd < numParagraphs ) while ( rowEnd < numParagraphs )
{ {
Paragraph p = getParagraph( rowEnd ); Paragraph startRowP = getParagraph( rowStart );
Paragraph endRowP = getParagraph( rowEnd );
rowEnd++; rowEnd++;
if ( p.isTableRowEnd() && p.getTableLevel() == _tableLevel ) if ( endRowP.isTableRowEnd()
&& endRowP.getTableLevel() == _tableLevel )
{ {
_rows.add( new TableRow( rowStart, rowEnd, this, _tableLevel ) ); _rows.add( new TableRow( startRowP.getStartOffset(), endRowP
.getEndOffset(), this, _tableLevel ) );
rowStart = rowEnd; rowStart = rowEnd;
} }
} }

View File

@ -29,7 +29,7 @@ public final class TableCell
TableRow parent, int levelNum, TableCellDescriptor tcd, TableRow parent, int levelNum, TableCellDescriptor tcd,
int leftEdge, int width ) int leftEdge, int width )
{ {
super( startIdxInclusive, endIdxExclusive, Range.TYPE_PARAGRAPH, parent ); super( startIdxInclusive, endIdxExclusive, parent );
_tcd = tcd; _tcd = tcd;
_leftEdge = leftEdge; _leftEdge = leftEdge;
_width = width; _width = width;

View File

@ -66,7 +66,9 @@ public final class TableIterator
break; break;
} }
} }
return new Table(startIndex, endIndex, _range, _levelNum); return new Table( _range.getParagraph( startIndex ).getStartOffset(),
_range.getParagraph( endIndex - 1 ).getEndOffset(), _range,
_levelNum );
} }
} }

View File

@ -51,7 +51,8 @@ public final class TableRow extends Range
super( startIdxInclusive, endIdxExclusive, parent ); super( startIdxInclusive, endIdxExclusive, parent );
Paragraph last = getParagraph( numParagraphs() - 1 ); Paragraph last = getParagraph( numParagraphs() - 1 );
_tprops = TableSprmUncompressor.uncompressTAP( last._papx ); _papx = last._papx;
_tprops = TableSprmUncompressor.uncompressTAP( _papx );
_levelNum = levelNum; _levelNum = levelNum;
initCells(); initCells();
} }
@ -146,9 +147,10 @@ public final class TableRow extends Range
&& _tprops.getRgdxaCenter().length > cells.size() + 1 ? _tprops && _tprops.getRgdxaCenter().length > cells.size() + 1 ? _tprops
.getRgdxaCenter()[cells.size() + 1] : 0; .getRgdxaCenter()[cells.size() + 1] : 0;
TableCell tableCell = new TableCell( lastCellStart, p + 1, TableCell tableCell = new TableCell( getParagraph(
this, _levelNum, tableCellDescriptor, leftEdge, lastCellStart ).getStartOffset(), getParagraph( p )
rightEdge - leftEdge ); .getEndOffset(), this, _levelNum, tableCellDescriptor,
leftEdge, rightEdge - leftEdge );
cells.add( tableCell ); cells.add( tableCell );
lastCellStart = p + 1; lastCellStart = p + 1;
} }