From 1d8d9608b6e7212e0bb8783314241f2e5790ea1f Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Tue, 5 Jul 2011 10:58:04 +0000 Subject: [PATCH] correct range calculation for non-complex file git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1142977 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/apache/poi/hwpf/HWPFDocument.java | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) 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. -- 2.39.5