]> source.dussan.org Git - poi.git/commitdiff
More rich text work
authorNick Burch <nick@apache.org>
Sun, 12 Feb 2006 12:56:26 +0000 (12:56 +0000)
committerNick Burch <nick@apache.org>
Sun, 12 Feb 2006 12:56:26 +0000 (12:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@377169 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/model/TextRun.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java

index ddcc357f3cb037e72e8bc601660a61391d932806..3b079ec5629776659cde2ebeaec5b75b4ee808b7 100644 (file)
@@ -208,25 +208,19 @@ public class TextRun
                ensureStyleAtomPresent();
                
                // Update the text length for its Paragraph and Character stylings
-               LinkedList pStyles = _styleAtom.getParagraphStyles();
-               LinkedList cStyles = _styleAtom.getCharacterStyles();
-               TextPropCollection pCol = (TextPropCollection)pStyles.get(runID);
-               TextPropCollection cCol = (TextPropCollection)cStyles.get(runID);
-               pCol.updateTextSize(s.length());
+               TextPropCollection pCol = run._getRawParagraphStyle();
+               TextPropCollection cCol = run._getRawCharacterStyle();
+               // Character style covers the new run
                cCol.updateTextSize(s.length());
+               // Paragraph might cover other runs to, so remove old size and add new one
+               pCol.updateTextSize( pCol.getCharactersCovered() - run.getLength() + s.length());
                
                // Build up the new text
                // As we go through, update the start position for all subsequent runs
                // The building relies on the old text still being present
                StringBuffer newText = new StringBuffer();
                for(int i=0; i<_rtRuns.length; i++) {
-                       // Do we need to update the start position of this run?
-                       if(i <= runID) {
-                               // Change is after this, so don't need to change start position
-                       } else {
-                               // Change has occured, so update start position
-                               _rtRuns[i].updateStartPosition(newText.length());
-                       }
+                       int newStartPos = newText.length();
                        
                        // Build up the new text
                        if(i != runID) {
@@ -236,6 +230,15 @@ public class TextRun
                                // Affected run, so use new text
                                newText.append(s);
                        }
+                       
+                       // Do we need to update the start position of this run?
+                       // (Need to get the text before we update the start pos)
+                       if(i <= runID) {
+                               // Change is after this, so don't need to change start position
+                       } else {
+                               // Change has occured, so update start position
+                               _rtRuns[i].updateStartPosition(newStartPos);
+                       }
                }
                
                // Now we can save the new text
index e38b936be7f6abb1b12c1e3515c7ae1728b4e299..1ccfea5d787605b776c06869819cd0e0cf520b12 100644 (file)
@@ -87,6 +87,13 @@ public class RichTextRun
                characterStyle = cStyle;
        }
        
+       /**
+        * Get the length of the text
+        */
+       public int getLength() {
+               return length;
+       }
+       
        /**
         * Fetch the text, in output suitable form
         */
@@ -119,12 +126,12 @@ public class RichTextRun
        
        
        /**
-        * Unit Testing Only - get the underlying paragraph style collection.
+        * Internal Use Only - get the underlying paragraph style collection.
         * For normal use, use the friendly setters and getters 
         */
        public TextPropCollection _getRawParagraphStyle() { return paragraphStyle; }
        /**
-        * Unit Testing Only - get the underlying character style collection.
+        * Internal Use Only - get the underlying character style collection.
         * For normal use, use the friendly setters and getters 
         */
        public TextPropCollection _getRawCharacterStyle() { return characterStyle; }