From: Sergey Vladimirov Date: Tue, 20 Sep 2011 14:14:17 +0000 (+0000) Subject: handle lists margins X-Git-Tag: REL_3_8_BETA5~150 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3520bc379e0c90de5643c5045755072a2e5d48b8;p=poi.git handle lists margins git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1173161 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java index 3b4f4c5525..cffcea5699 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java @@ -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, diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java index 5b51af101b..484d367788 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java @@ -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, 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 9a4d1d8b8d..a3efb666a1 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java @@ -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 index 0000000000..348a926f06 Binary files /dev/null and b/test-data/document/lists-margins.doc differ