From 79c4de256f76c7b372333552975c8701c7f6a798 Mon Sep 17 00:00:00 2001 From: Maxim Valyanskiy Date: Wed, 4 Aug 2010 12:43:58 +0000 Subject: [PATCH] hwpf: append any character data before paragraphs to first paragraph (workaround for bug#48075) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@982238 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hwpf/usermodel/Paragraph.java | 8 ++++++++ .../org/apache/poi/hwpf/usermodel/Range.java | 6 +++++- .../poi/hwpf/extractor/TestWordExtractor.java | 10 ++++++++++ test-data/document/MBD001D0B89.doc | Bin 0 -> 35840 bytes 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test-data/document/MBD001D0B89.doc diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java index a1462ffe0a..087c6c5c16 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Paragraph.java @@ -101,6 +101,14 @@ public class Paragraph extends Range implements Cloneable { _istd = papx.getIstd(); } + protected Paragraph(PAPX papx, Range parent, int start) + { + super(Math.max(parent._start, start), Math.min(parent._end, papx.getEnd()), parent); + _props = papx.getParagraphProperties(_doc.getStyleSheet()); + _papx = papx.getSprmBuf(); + _istd = papx.getIstd(); + } + public short getStyleIndex() { return _istd; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java index 7c9b541d7c..df9cb0c46d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java @@ -830,7 +830,11 @@ public class Range { // TODO -instantiable superclass if (props.getIlfo() > 0) { pap = new ListEntry(papx, this, _doc.getListTables()); } else { - pap = new Paragraph(papx, this); + if (((index + _parStart)==0) && papx.getStart()>0) { + pap = new Paragraph(papx, this, 0); + } else { + pap = new Paragraph(papx, this); + } } return pap; diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java index 22eaf0ade4..ea69824daa 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java @@ -298,4 +298,14 @@ public final class TestWordExtractor extends TestCase { assertTrue(text.contains("\u0425\u0425\u0425\u0425\u0425")); assertTrue(text.contains("\u0423\u0423\u0423\u0423\u0423")); } + + public void testFirstParagraphFix() throws Exception { + extractor = new WordExtractor( + POIDataSamples.getDocumentInstance().openResourceAsStream("MBD001D0B89.doc") + ); + + String text = extractor.getText(); + + assertTrue(text.startsWith("\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435")); + } } diff --git a/test-data/document/MBD001D0B89.doc b/test-data/document/MBD001D0B89.doc new file mode 100644 index 0000000000000000000000000000000000000000..386b5305be0e58421d03606390392dec480e8c0b GIT binary patch literal 35840 zcmeHQ2V7Lg)}LMO(#wi~G<8KpZ1g5b7euhdny67hnu?%+EjCm%s8OuZSh2U*5?kzD zv1=4HYQ&Be?3%pD_doY?VSxqF_}=%-WB8q&xl_)ZIp@sGnYlBUGpDO$FWP8+gOzYz zOpU$E*JA2Q@e+i6#b-HVfe2IFyZrooif#%(u+n`-9C);BA5%*);~2{`+(SZS43dS@ zWX#2aF?|-%JEHf)qYsbrvBiGOI1^UC31j0I3(#DvSaPX{{CtDLxU#}xhOO);L&jot zglEwgQ&ss@bQv>Jl~6|9c;L21+FJOLN_o!fGj^BM`fob(8jMLl0>^gn{|)N5MERvC zPi?RD5qLgzk-ebj3XsmN$(Ttw$Tz+xy_}-|mZUn+i-{1#2FP{&#|Y#-R2@NkP2ZD; zlCLA5CwwynW7-r^;A$%by>*B0AV$KE!Lyyx^GrPV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