]> source.dussan.org Git - poi.git/commitdiff
handle lists margins
authorSergey Vladimirov <sergey@apache.org>
Tue, 20 Sep 2011 14:14:17 +0000 (14:14 +0000)
committerSergey Vladimirov <sergey@apache.org>
Tue, 20 Sep 2011 14:14:17 +0000 (14:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1173161 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java
src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java
src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java
test-data/document/lists-margins.doc [new file with mode: 0644]

index 3b4f4c55253b43586172bcb62a636826c785c45e..cffcea56994191a28283fa5cf4cbbe03126e680a 100644 (file)
@@ -553,8 +553,41 @@ public class WordToHtmlConverter extends AbstractWordConverter
         {
             if ( WordToHtmlUtils.isNotEmpty( bulletText ) )
             {
-                Text textNode = htmlDocumentFacade.createText( bulletText );
-                pElement.appendChild( textNode );
+                if ( bulletText.endsWith( "\t" ) )
+                {
+                    /*
+                     * We don't know how to handle all cases in HTML, but at
+                     * least simplest case shall be handled
+                     */
+                    final float defaultTab = TWIPS_PER_INCH / 2;
+                    float firstLinePosition = paragraph.getIndentFromLeft()
+                            + paragraph.getFirstLineIndent() + 20; // char have
+                                                                   // some space
+
+                    float nextStop = (float) ( Math.ceil( firstLinePosition
+                            / defaultTab ) * defaultTab );
+
+                    final float spanMinWidth = nextStop - firstLinePosition;
+
+                    Element span = htmlDocumentFacade.getDocument()
+                            .createElement( "span" );
+                    htmlDocumentFacade
+                            .addStyleClass( span, "s",
+                                    "display: inline-block; text-indent: 0; min-width: "
+                                            + ( spanMinWidth / TWIPS_PER_INCH )
+                                            + "in;" );
+                    pElement.appendChild( span );
+
+                    Text textNode = htmlDocumentFacade.createText( bulletText
+                            .substring( 0, bulletText.length() - 1 ) );
+                    span.appendChild( textNode );
+                }
+                else
+                {
+                    Text textNode = htmlDocumentFacade.createText( bulletText
+                            .substring( 0, bulletText.length() - 1 ) );
+                    pElement.appendChild( textNode );
+                }
             }
 
             processCharacters( hwpfDocument, currentTableLevel, paragraph,
index 5b51af101b30bbfbde61ffa7dbd93cb01cd12b64..484d367788eb7d5bc90ebff1b4bc363525f38cc4 100644 (file)
@@ -143,7 +143,7 @@ public class WordToHtmlUtils extends AbstractWordUtils
         if ( twipsValue == 0 )
             return;
 
-        style.append( cssName + ":" + ( twipsValue / TWIPS_PER_PT ) + "pt;" );
+        style.append( cssName + ":" + ( twipsValue / TWIPS_PER_INCH ) + "in;" );
     }
 
     public static void addJustification( Paragraph paragraph,
index 9a4d1d8b8d61c7324d5ac8deb15dcf2412bab8dd..a3efb666a1e75fa91945ecb50b573e8a6342729c 100644 (file)
@@ -191,6 +191,22 @@ public class TestWordToHtmlConverter extends TestCase
         getHtmlText( "innertable.doc" );
     }
 
+    public void testListsMargins() throws Exception
+    {
+        String result = getHtmlText( "lists-margins.doc" );
+
+        assertContains( result,
+                ".s1{display: inline-block; text-indent: 0; min-width: 0.4861111in;}" );
+        assertContains( result,
+                ".s2{display: inline-block; text-indent: 0; min-width: 0.23055555in;}" );
+        assertContains( result,
+                ".s3{display: inline-block; text-indent: 0; min-width: 0.28541666in;}" );
+        assertContains( result,
+                ".s4{display: inline-block; text-indent: 0; min-width: 0.28333333in;}" );
+        assertContains( result,
+                ".p4{text-indent:-0.59652776in;margin-left:-0.70069444in;" );
+    }
+
     public void testO_kurs_doc() throws Exception
     {
         getHtmlText( "o_kurs.doc" );
diff --git a/test-data/document/lists-margins.doc b/test-data/document/lists-margins.doc
new file mode 100644 (file)
index 0000000..348a926
Binary files /dev/null and b/test-data/document/lists-margins.doc differ