You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ma...@apache.org on 2010/07/27 11:38:54 UTC

svn commit: r979618 - in /poi/trunk: src/scratchpad/src/org/apache/poi/hwpf/model/ src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/ test-data/document/

Author: maxcom
Date: Tue Jul 27 09:38:54 2010
New Revision: 979618

URL: http://svn.apache.org/viewvc?rev=979618&view=rev
Log:
wpf: More CharactedRun mapping fixes for fast-saved documents

Added:
    poi/trunk/test-data/document/ob_is.doc   (with props)
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java?rev=979618&r1=979617&r2=979618&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java Tue Jul 27 09:38:54 2010
@@ -35,7 +35,7 @@ public abstract class BytePropertyNode e
 	public BytePropertyNode(int fcStart, int fcEnd, CharIndexTranslator translator, Object buf) {
 		super(
 				translator.getCharIndex(fcStart),
-				translator.getCharIndex(fcEnd),
+				translator.getCharIndex(fcEnd, translator.getCharIndex(fcStart)),
 				buf
 		);
                 this.startBytes = fcStart;

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java?rev=979618&r1=979617&r2=979618&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java Tue Jul 27 09:38:54 2010
@@ -28,6 +28,16 @@ public interface CharIndexTranslator {
     int getCharIndex(int bytePos);
 
     /**
+     * Calculates the char index of the given byte index.
+     * Look forward if index is not in table
+     *
+     * @param bytePos The character offset to check
+     * @param startCP look from this characted position 
+     * @return the char index
+     */
+    int getCharIndex(int bytePos, int startCP);
+
+    /**
      * Check if index is in table
      *
      * @param bytePos

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java?rev=979618&r1=979617&r2=979618&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java Tue Jul 27 09:38:54 2010
@@ -198,6 +198,10 @@ public class TextPieceTable implements C
 	}
 
     public int getCharIndex(int bytePos) {
+        return getCharIndex(bytePos, 0);
+    }
+
+    public int getCharIndex(int bytePos, int startCP) {
         int charCount = 0;
 
         bytePos = lookIndexForward(bytePos);
@@ -222,7 +226,7 @@ public class TextPieceTable implements C
                 charCount += toAdd;
             }
 
-            if (bytePos>=pieceStart && bytePos<=pieceEnd) {
+            if (bytePos>=pieceStart && bytePos<=pieceEnd && charCount>=startCP) {
                 break;
             }
         }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java?rev=979618&r1=979617&r2=979618&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java Tue Jul 27 09:38:54 2010
@@ -163,4 +163,10 @@ public final class TestPictures extends 
             doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
     }
 
+    public void testFastSaved3() {
+            HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ob_is.doc");
+
+            doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
+    }
+
 }

Added: poi/trunk/test-data/document/ob_is.doc
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/ob_is.doc?rev=979618&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/ob_is.doc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org