git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@979618 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_7_BETA2
@@ -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; |
@@ -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 | |||
* |
@@ -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; | |||
} | |||
} |
@@ -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 | |||
} | |||
} |