From: Sergey Vladimirov Date: Fri, 15 Jul 2011 10:52:11 +0000 (+0000) Subject: fix fields processing, improve test case X-Git-Tag: REL_3_8_BETA4~182 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ee100816eb2060c5f889d225dc97a466b46a3a1d;p=poi.git fix fields processing, improve test case git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147082 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java index 64494a9c8c..5a6221e8bd 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java @@ -19,11 +19,10 @@ package org.apache.poi.hwpf.converter; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.poi.hwpf.converter.FontReplacer.Triplet; - import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocumentCore; +import org.apache.poi.hwpf.converter.FontReplacer.Triplet; import org.apache.poi.hwpf.model.Field; import org.apache.poi.hwpf.model.FieldsTables; import org.apache.poi.hwpf.model.ListFormatOverride; @@ -77,7 +76,7 @@ public abstract class AbstractWordConverter protected boolean processCharacters( HWPFDocumentCore hwpfDocument, int currentTableLevel, Range range, final Element block ) { - if (range == null) + if ( range == null ) return false; boolean haveAnyText = false; @@ -118,7 +117,15 @@ public abstract class AbstractWordConverter { processField( ( (HWPFDocument) hwpfDocument ), range, currentTableLevel, aliveField, block ); - c = aliveField.getEndOffset(); + + int continueAfter = aliveField.getEndOffset(); + while ( range.getCharacterRun( c ).getEndOffset() <= continueAfter + && c < range.numCharacterRuns() ) + c++; + + if ( c < range.numCharacterRuns() ) + c--; + continue; } } @@ -164,10 +171,11 @@ public abstract class AbstractWordConverter { if ( stringBuilder.length() > 0 ) { - outputCharacters( block, characterRun, stringBuilder.toString() ); + outputCharacters( block, characterRun, + stringBuilder.toString() ); stringBuilder.setLength( 0 ); } - processLineBreak(block, characterRun); + processLineBreak( block, characterRun ); } else { @@ -176,7 +184,8 @@ public abstract class AbstractWordConverter } if ( stringBuilder.length() > 0 ) { - outputCharacters( block, characterRun, stringBuilder.toString() ); + outputCharacters( block, characterRun, + stringBuilder.toString() ); stringBuilder.setLength( 0 ); } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java index 1537ad59d2..2a08a5a5d9 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java @@ -134,8 +134,10 @@ public class TestWordToHtmlConverter extends TestCase { String result = getHtmlText( "hyperlink.doc" ); - assertContains( result, "" ); - assertContains( result, "Hyperlink text" ); + assertContains( result, "Before text; Hyperlink text" ); + assertContains( result, "; after text" ); } public void testInnerTable() throws Exception