Fix bug #39177 - Last TextPropCollection needs a length 1 longer than the text that makes it up

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@393550 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2006-04-12 17:59:45 +00:00
parent ba0c404d40
commit 41b716e799
1 changed files with 12 additions and 2 deletions

View File

@ -216,6 +216,14 @@ public class TextRun
// Paragraph might cover other runs to, so remove old size and add new one // Paragraph might cover other runs to, so remove old size and add new one
pCol.updateTextSize( pCol.getCharactersCovered() - run.getLength() + s.length()); pCol.updateTextSize( pCol.getCharactersCovered() - run.getLength() + s.length());
// If we were dealing with the last RichTextRun in the set, then
// we need to tell the Character TextPropCollections a size 1 bigger
// than it really is
// (The Paragraph one will keep the extra 1 length from before)
if(runID == _rtRuns.length-1) {
cCol.updateTextSize( cCol.getCharactersCovered() + 1 );
}
// Build up the new text // Build up the new text
// As we go through, update the start position for all subsequent runs // As we go through, update the start position for all subsequent runs
// The building relies on the old text still being present // The building relies on the old text still being present
@ -271,10 +279,12 @@ public class TextRun
LinkedList cStyles = _styleAtom.getCharacterStyles(); LinkedList cStyles = _styleAtom.getCharacterStyles();
while(cStyles.size() > 1) { cStyles.removeLast(); } while(cStyles.size() > 1) { cStyles.removeLast(); }
// Note - TextPropCollection's idea of the text length must
// be one larger than it actually is!
TextPropCollection pCol = (TextPropCollection)pStyles.getFirst(); TextPropCollection pCol = (TextPropCollection)pStyles.getFirst();
TextPropCollection cCol = (TextPropCollection)cStyles.getFirst(); TextPropCollection cCol = (TextPropCollection)cStyles.getFirst();
pCol.updateTextSize(s.length()); pCol.updateTextSize(s.length()+1);
cCol.updateTextSize(s.length()); cCol.updateTextSize(s.length()+1);
// Recreate rich text run with first styling // Recreate rich text run with first styling
_rtRuns[0] = new RichTextRun(this,0,s.length(), pCol, cCol); _rtRuns[0] = new RichTextRun(this,0,s.length(), pCol, cCol);