]> source.dussan.org Git - poi.git/commitdiff
fix fields processing, improve test case
authorSergey Vladimirov <sergey@apache.org>
Fri, 15 Jul 2011 10:52:11 +0000 (10:52 +0000)
committerSergey Vladimirov <sergey@apache.org>
Fri, 15 Jul 2011 10:52:11 +0000 (10:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147082 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java

index 64494a9c8c765a0da936ef4ff0cce9a5277a5ac8..5a6221e8bd699be88f03f98c6dfaf2659256693a 100644 (file)
@@ -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 );
                 }
             }
index 1537ad59d29f580f2803bc38de0662d37898ecc2..2a08a5a5d95dd1f2ef3d826072c0c37068f359f8 100644 (file)
@@ -134,8 +134,10 @@ public class TestWordToHtmlConverter extends TestCase
     {
         String result = getHtmlText( "hyperlink.doc" );
 
-        assertContains( result, "<a href=\"http://testuri.org/\">" );
-        assertContains( result, "Hyperlink text" );
+        assertContains( result, "<span>Before text; </span><a " );
+        assertContains( result,
+                "<a href=\"http://testuri.org/\"><span>Hyperlink text</span></a>" );
+        assertContains( result, "</a><span>; after text</span>" );
     }
 
     public void testInnerTable() throws Exception