From: Sergey Vladimirov Date: Tue, 5 Jul 2011 10:58:04 +0000 (+0000) Subject: correct range calculation for non-complex file X-Git-Tag: REL_3_8_BETA4~317 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1d8d9608b6e7212e0bb8783314241f2e5790ea1f;p=poi.git correct range calculation for non-complex file git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1142977 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index c5c4d82aa8..7890e9241b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -300,18 +300,40 @@ public final class HWPFDocument extends HWPFDocumentCore * Returns the range which covers the whole of the * document, but excludes any headers and footers. */ - public Range getRange() { - // First up, trigger a full-recalculate - // Needed in case of deletes etc - getOverallRange(); - - // Now, return the real one - return new Range( - _cpSplit.getMainDocumentStart(), - _cpSplit.getMainDocumentEnd(), - this - ); - } + public Range getRange() + { + // First up, trigger a full-recalculate + // Needed in case of deletes etc + getOverallRange(); + + if ( getFileInformationBlock().isFComplex() ) + { + /* + * Page 31: + * + * main document must be found by examining the piece table entries + * from the 0th piece table entry from the piece table entry that + * describes cp=fib.ccpText. + */ + // TODO: review + return new Range( _cpSplit.getMainDocumentStart(), + _cpSplit.getMainDocumentEnd(), this ); + } + + /* + * Page 31: + * + * "In a non-complex file, this means text of the: main document begins + * at fib.fcMin in the file and continues through + * fib.fcMin+fib.ccpText." + */ + int bytesStart = getFileInformationBlock().getFcMin(); + + int charsStart = getTextTable().getCharIndex( bytesStart ); + int charsEnd = charsStart + getFileInformationBlock().getCcpText(); + + return new Range( charsStart, charsEnd, this ); + } /** * Returns the range which covers all the Footnotes.