]> source.dussan.org Git - poi.git/commitdiff
wpf: More CharactedRun mapping fixes for fast-saved documents
authorMaxim Valyanskiy <maxcom@apache.org>
Tue, 27 Jul 2010 09:38:54 +0000 (09:38 +0000)
committerMaxim Valyanskiy <maxcom@apache.org>
Tue, 27 Jul 2010 09:38:54 +0000 (09:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@979618 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java
src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java
src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
test-data/document/ob_is.doc [new file with mode: 0644]

index 1753fdbd916a14e4e5aa2d23d2a88e51a61c8bfc..4ceb2d1d8dbe0b2c50c33df5074115357bae0b60 100644 (file)
@@ -35,7 +35,7 @@ public abstract class BytePropertyNode extends PropertyNode {
        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;
index cda2fb26a5852a88633cdccf5b4c7880c65cea42..033c4ab4600611195e2f7333491c71daadc65f76 100644 (file)
@@ -27,6 +27,16 @@ public interface CharIndexTranslator {
      */\r
     int getCharIndex(int bytePos);\r
 \r
+    /**\r
+     * Calculates the char index of the given byte index.\r
+     * Look forward if index is not in table\r
+     *\r
+     * @param bytePos The character offset to check\r
+     * @param startCP look from this characted position \r
+     * @return the char index\r
+     */\r
+    int getCharIndex(int bytePos, int startCP);\r
+\r
     /**\r
      * Check if index is in table\r
      *\r
index cfff0b29378634c6046d5b88e3f899461e08b53a..ccd7cc10f3936aee65af6070e61e2cd4e7b8043e 100644 (file)
@@ -198,6 +198,10 @@ public class TextPieceTable implements CharIndexTranslator {
        }
 
     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 CharIndexTranslator {
                 charCount += toAdd;
             }
 
-            if (bytePos>=pieceStart && bytePos<=pieceEnd) {
+            if (bytePos>=pieceStart && bytePos<=pieceEnd && charCount>=startCP) {
                 break;
             }
         }
index a5c9c501e95f26a2301095e5e7059b973026457d..a5f7c3c7e4df1d974e3e58a577227819dd64c5d5 100644 (file)
@@ -163,4 +163,10 @@ public final class TestPictures extends TestCase {
             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
+    }
+
 }
diff --git a/test-data/document/ob_is.doc b/test-data/document/ob_is.doc
new file mode 100644 (file)
index 0000000..798a094
Binary files /dev/null and b/test-data/document/ob_is.doc differ