whitespace (2 spaces to 4 spaces)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1748487 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
46a36df416
commit
2b7649cbd6
@ -50,11 +50,11 @@ public class PAPBinTable
|
|||||||
private static final POILogger logger = POILogFactory
|
private static final POILogger logger = POILogFactory
|
||||||
.getLogger( PAPBinTable.class );
|
.getLogger( PAPBinTable.class );
|
||||||
|
|
||||||
protected final ArrayList<PAPX> _paragraphs = new ArrayList<PAPX>();
|
protected final ArrayList<PAPX> _paragraphs = new ArrayList<PAPX>();
|
||||||
|
|
||||||
public PAPBinTable()
|
public PAPBinTable()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public PAPBinTable( byte[] documentStream, byte[] tableStream,
|
public PAPBinTable( byte[] documentStream, byte[] tableStream,
|
||||||
byte[] dataStream, int offset, int size,
|
byte[] dataStream, int offset, int size,
|
||||||
@ -285,107 +285,107 @@ public class PAPBinTable
|
|||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insert(int listIndex, int cpStart, SprmBuffer buf)
|
public void insert(int listIndex, int cpStart, SprmBuffer buf)
|
||||||
{
|
|
||||||
|
|
||||||
PAPX forInsert = new PAPX(0, 0, buf);
|
|
||||||
|
|
||||||
// Ensure character offsets are really characters
|
|
||||||
forInsert.setStart(cpStart);
|
|
||||||
forInsert.setEnd(cpStart);
|
|
||||||
|
|
||||||
if (listIndex == _paragraphs.size())
|
|
||||||
{
|
{
|
||||||
_paragraphs.add(forInsert);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PAPX currentPap = _paragraphs.get(listIndex);
|
|
||||||
if (currentPap != null && currentPap.getStart() < cpStart)
|
|
||||||
{
|
|
||||||
SprmBuffer clonedBuf = currentPap.getSprmBuf().clone();
|
|
||||||
|
|
||||||
// Copy the properties of the one before to afterwards
|
PAPX forInsert = new PAPX(0, 0, buf);
|
||||||
// Will go:
|
|
||||||
// Original, until insert at point
|
|
||||||
// New one
|
|
||||||
// Clone of original, on to the old end
|
|
||||||
PAPX clone = new PAPX(0, 0, clonedBuf);
|
|
||||||
// Again ensure contains character based offsets no matter what
|
|
||||||
clone.setStart(cpStart);
|
|
||||||
clone.setEnd(currentPap.getEnd());
|
|
||||||
|
|
||||||
currentPap.setEnd(cpStart);
|
// Ensure character offsets are really characters
|
||||||
|
forInsert.setStart(cpStart);
|
||||||
|
forInsert.setEnd(cpStart);
|
||||||
|
|
||||||
|
if (listIndex == _paragraphs.size())
|
||||||
|
{
|
||||||
|
_paragraphs.add(forInsert);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PAPX currentPap = _paragraphs.get(listIndex);
|
||||||
|
if (currentPap != null && currentPap.getStart() < cpStart)
|
||||||
|
{
|
||||||
|
SprmBuffer clonedBuf = currentPap.getSprmBuf().clone();
|
||||||
|
|
||||||
|
// Copy the properties of the one before to afterwards
|
||||||
|
// Will go:
|
||||||
|
// Original, until insert at point
|
||||||
|
// New one
|
||||||
|
// Clone of original, on to the old end
|
||||||
|
PAPX clone = new PAPX(0, 0, clonedBuf);
|
||||||
|
// Again ensure contains character based offsets no matter what
|
||||||
|
clone.setStart(cpStart);
|
||||||
|
clone.setEnd(currentPap.getEnd());
|
||||||
|
|
||||||
|
currentPap.setEnd(cpStart);
|
||||||
|
|
||||||
|
_paragraphs.add(listIndex + 1, forInsert);
|
||||||
|
_paragraphs.add(listIndex + 2, clone);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_paragraphs.add(listIndex, forInsert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_paragraphs.add(listIndex + 1, forInsert);
|
|
||||||
_paragraphs.add(listIndex + 2, clone);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_paragraphs.add(listIndex, forInsert);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public void adjustForDelete(int listIndex, int offset, int length)
|
||||||
|
{
|
||||||
|
int size = _paragraphs.size();
|
||||||
|
int endMark = offset + length;
|
||||||
|
int endIndex = listIndex;
|
||||||
|
|
||||||
public void adjustForDelete(int listIndex, int offset, int length)
|
PAPX papx = _paragraphs.get(endIndex);
|
||||||
{
|
while (papx.getEnd() < endMark)
|
||||||
int size = _paragraphs.size();
|
{
|
||||||
int endMark = offset + length;
|
papx = _paragraphs.get(++endIndex);
|
||||||
int endIndex = listIndex;
|
}
|
||||||
|
if (listIndex == endIndex)
|
||||||
|
{
|
||||||
|
papx = _paragraphs.get(endIndex);
|
||||||
|
papx.setEnd((papx.getEnd() - endMark) + offset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
papx = _paragraphs.get(listIndex);
|
||||||
|
papx.setEnd(offset);
|
||||||
|
for (int x = listIndex + 1; x < endIndex; x++)
|
||||||
|
{
|
||||||
|
papx = _paragraphs.get(x);
|
||||||
|
papx.setStart(offset);
|
||||||
|
papx.setEnd(offset);
|
||||||
|
}
|
||||||
|
papx = _paragraphs.get(endIndex);
|
||||||
|
papx.setEnd((papx.getEnd() - endMark) + offset);
|
||||||
|
}
|
||||||
|
|
||||||
PAPX papx = _paragraphs.get(endIndex);
|
for (int x = endIndex + 1; x < size; x++)
|
||||||
while (papx.getEnd() < endMark)
|
{
|
||||||
{
|
papx = _paragraphs.get(x);
|
||||||
papx = _paragraphs.get(++endIndex);
|
papx.setStart(papx.getStart() - length);
|
||||||
}
|
papx.setEnd(papx.getEnd() - length);
|
||||||
if (listIndex == endIndex)
|
}
|
||||||
{
|
|
||||||
papx = _paragraphs.get(endIndex);
|
|
||||||
papx.setEnd((papx.getEnd() - endMark) + offset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
papx = _paragraphs.get(listIndex);
|
|
||||||
papx.setEnd(offset);
|
|
||||||
for (int x = listIndex + 1; x < endIndex; x++)
|
|
||||||
{
|
|
||||||
papx = _paragraphs.get(x);
|
|
||||||
papx.setStart(offset);
|
|
||||||
papx.setEnd(offset);
|
|
||||||
}
|
|
||||||
papx = _paragraphs.get(endIndex);
|
|
||||||
papx.setEnd((papx.getEnd() - endMark) + offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = endIndex + 1; x < size; x++)
|
|
||||||
|
public void adjustForInsert(int listIndex, int length)
|
||||||
{
|
{
|
||||||
papx = _paragraphs.get(x);
|
int size = _paragraphs.size();
|
||||||
papx.setStart(papx.getStart() - length);
|
PAPX papx = _paragraphs.get(listIndex);
|
||||||
papx.setEnd(papx.getEnd() - length);
|
papx.setEnd(papx.getEnd() + length);
|
||||||
|
|
||||||
|
for (int x = listIndex + 1; x < size; x++)
|
||||||
|
{
|
||||||
|
papx = _paragraphs.get(x);
|
||||||
|
papx.setStart(papx.getStart() + length);
|
||||||
|
papx.setEnd(papx.getEnd() + length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void adjustForInsert(int listIndex, int length)
|
public ArrayList<PAPX> getParagraphs()
|
||||||
{
|
|
||||||
int size = _paragraphs.size();
|
|
||||||
PAPX papx = _paragraphs.get(listIndex);
|
|
||||||
papx.setEnd(papx.getEnd() + length);
|
|
||||||
|
|
||||||
for (int x = listIndex + 1; x < size; x++)
|
|
||||||
{
|
{
|
||||||
papx = _paragraphs.get(x);
|
return _paragraphs;
|
||||||
papx.setStart(papx.getStart() + length);
|
|
||||||
papx.setEnd(papx.getEnd() + length);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<PAPX> getParagraphs()
|
|
||||||
{
|
|
||||||
return _paragraphs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void writeTo( HWPFFileSystem sys, CharIndexTranslator translator )
|
public void writeTo( HWPFFileSystem sys, CharIndexTranslator translator )
|
||||||
@ -402,55 +402,54 @@ public class PAPBinTable
|
|||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
|
||||||
PlexOfCps binTable = new PlexOfCps(4);
|
PlexOfCps binTable = new PlexOfCps(4);
|
||||||
|
|
||||||
// each FKP must start on a 512 byte page.
|
// each FKP must start on a 512 byte page.
|
||||||
int docOffset = wordDocumentStream.getOffset();
|
int docOffset = wordDocumentStream.getOffset();
|
||||||
int mod = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE;
|
int mod = docOffset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE;
|
||||||
if (mod != 0)
|
if (mod != 0)
|
||||||
{
|
{
|
||||||
byte[] padding = new byte[POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod];
|
byte[] padding = new byte[POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod];
|
||||||
wordDocumentStream.write(padding);
|
wordDocumentStream.write(padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the page number for the first fkp
|
// get the page number for the first fkp
|
||||||
docOffset = wordDocumentStream.getOffset();
|
docOffset = wordDocumentStream.getOffset();
|
||||||
int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE;
|
int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE;
|
||||||
|
|
||||||
// get the ending fc
|
// get the ending fc
|
||||||
// int endingFc = _paragraphs.get(_paragraphs.size() - 1).getEnd();
|
// int endingFc = _paragraphs.get(_paragraphs.size() - 1).getEnd();
|
||||||
// endingFc += fcMin;
|
// endingFc += fcMin;
|
||||||
int endingFc = translator.getByteIndex( _paragraphs.get(
|
int endingFc = translator.getByteIndex( _paragraphs.get(_paragraphs.size() - 1 ).getEnd() );
|
||||||
_paragraphs.size() - 1 ).getEnd() );
|
|
||||||
|
|
||||||
ArrayList<PAPX> overflow = _paragraphs;
|
ArrayList<PAPX> overflow = _paragraphs;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
PAPX startingProp = overflow.get(0);
|
PAPX startingProp = overflow.get(0);
|
||||||
|
|
||||||
// int start = startingProp.getStart() + fcMin;
|
// int start = startingProp.getStart() + fcMin;
|
||||||
int start = translator.getByteIndex( startingProp.getStart() );
|
int start = translator.getByteIndex( startingProp.getStart() );
|
||||||
|
|
||||||
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage();
|
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage();
|
||||||
pfkp.fill(overflow);
|
pfkp.fill(overflow);
|
||||||
|
|
||||||
byte[] bufFkp = pfkp.toByteArray(tableStream, translator);
|
byte[] bufFkp = pfkp.toByteArray(tableStream, translator);
|
||||||
wordDocumentStream.write(bufFkp);
|
wordDocumentStream.write(bufFkp);
|
||||||
overflow = pfkp.getOverflow();
|
overflow = pfkp.getOverflow();
|
||||||
|
|
||||||
int end = endingFc;
|
int end = endingFc;
|
||||||
if (overflow != null)
|
if (overflow != null)
|
||||||
{
|
{
|
||||||
// end = overflow.get(0).getStart() + fcMin;
|
// end = overflow.get(0).getStart() + fcMin;
|
||||||
end = translator.getByteIndex( overflow.get( 0 ).getStart() );
|
end = translator.getByteIndex( overflow.get( 0 ).getStart() );
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] intHolder = new byte[4];
|
byte[] intHolder = new byte[4];
|
||||||
LittleEndian.putInt(intHolder, 0, pageNum++);
|
LittleEndian.putInt(intHolder, 0, pageNum++);
|
||||||
binTable.addProperty(new GenericPropertyNode(start, end, intHolder));
|
binTable.addProperty(new GenericPropertyNode(start, end, intHolder));
|
||||||
|
|
||||||
|
}
|
||||||
|
while (overflow != null);
|
||||||
|
tableStream.write(binTable.toByteArray());
|
||||||
}
|
}
|
||||||
while (overflow != null);
|
|
||||||
tableStream.write(binTable.toByteArray());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user