Browse Source

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
tags/REL_3_7_BETA2
Maxim Valyanskiy 13 years ago
parent
commit
0864608375

+ 1
- 1
src/scratchpad/src/org/apache/poi/hwpf/model/BytePropertyNode.java View 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;

+ 10
- 0
src/scratchpad/src/org/apache/poi/hwpf/model/CharIndexTranslator.java View File

@@ -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
*

+ 5
- 1
src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java View 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;
}
}

+ 6
- 0
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java View 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
}

}

BIN
test-data/document/ob_is.doc View File


Loading…
Cancel
Save