From: Maxim Valyanskiy Date: Tue, 27 Jul 2010 09:38:54 +0000 (+0000) Subject: wpf: More CharactedRun mapping fixes for fast-saved documents X-Git-Tag: REL_3_7_BETA2~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0864608375b811274c8f11121d1cfb30373ec125;p=poi.git wpf: More CharactedRun mapping fixes for fast-saved documents git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@979618 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java index 1753fdbd91..4ceb2d1d8d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java @@ -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; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java index cda2fb26a5..033c4ab460 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java @@ -27,6 +27,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 * diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java index cfff0b2937..ccd7cc10f3 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java @@ -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; } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java index a5c9c501e9..a5f7c3c7e4 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java @@ -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 index 0000000000..798a094677 Binary files /dev/null and b/test-data/document/ob_is.doc differ