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
This commit is contained in:
Maxim Valyanskiy 2010-07-27 09:38:54 +00:00
parent 247f441b31
commit 0864608375
5 changed files with 22 additions and 2 deletions

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;

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
*

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;
}
}

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
}
}

Binary file not shown.