From 3520bc379e0c90de5643c5045755072a2e5d48b8 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Tue, 20 Sep 2011 14:14:17 +0000 Subject: [PATCH] handle lists margins git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1173161 13f79535-47bb-0310-9956-ffa450edef68 --- .../hwpf/converter/WordToHtmlConverter.java | 37 +++++++++++++++++- .../poi/hwpf/converter/WordToHtmlUtils.java | 2 +- .../converter/TestWordToHtmlConverter.java | 16 ++++++++ test-data/document/lists-margins.doc | Bin 0 -> 10752 bytes 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 test-data/document/lists-margins.doc 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 0000000000000000000000000000000000000000..348a926f06e8f7b2479709e2d9ecc29d92e89812 GIT binary patch literal 10752 zcmeI2?{8Dr8OP7HuN^z2i3v0m$`4agVEk~MWC4d1a1t6^14|&ZS=U07kkDi$apr`z zoi-`!GHH`miK*4r7n4ReDpi`svh@!b+NQp0)kssN_D$8jnS`_#5LKFJA@1in_u9Gj zlH7}7-H?2u?>#@C=RD^*&pr2fjx+oI%1_?- zXaJ3%3CJ3n$@hT0cD;psA7}-Sg8kqCI0%xU4YY#}a0omGI>BL(0*`|W8fR0 z3v`3y-~{LaC&3foNzes~#gXh6H zFbc*%28;t)bJormtiXH8fPFDK9qU> z{OHiwr2Zxx>yfrYnKSxJAmtbp-5*P+Ph0-<9gER&Ps4H}mK(BcUo93^i5K!TUnEO< zt=Gu)oKNewLaj98=3euF*=QayTlmDum#m>)?Wi}}Ft{ewzC(4T{pvXANI#$^Qfp1Y zk(8mj)213rnW59^fa<63*;I=;2^Nv4U9~0Wa&Kr`T8mW;s0sFVQhg7L?IG`H*9LiJ zc}}p~!<0tYY3a%Gbf$JSziBRa{f>C0G!MfN8(xn!_991VQl&Mgm4>_p8%pLR@2R{& zva-#Fyh$7HfS1KBuDLZBat=h)W;0G5J62h4qpxsOw9)un4{^`#e8u-@Pd>q-YPjv&UdUK@mE4C_@wwMT?kg4wIp zMzhV_udPg;ElAML?E7eKhifJ0;;KuWkZ_fA?vcoGW5B4V97OJeNY`f1@8k3|)#-Ev zyDze44LO}cYJ;}oMxOf_-K-^D1J4&V&nhIX)#ke=WC*cX>#2|t(>z`#7f)^r^2oao zN2X@9bQCTDRw&fgoD5Tc0CZGKSxyDXZ##uJ4(Kp>~?cj`osc0Kn*yWu}@U=kJ@ocvJK4^Sh3|#^{JO`kMRbDXeblbIp6obmbkv;;wzBM@Is#qs2b^tkKw~ z+bZM1zUkQ;ns+?NXi>1}+?f`XZnes3U?u6P(C2poZ|FQ;iFG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