Page 1 of 1

Issue with double spacing in HTML

PostPosted: Tue Apr 09, 2013 11:48 am
by jallen
Hi Jason,

A while back I reported issues with double spacing in the html conversion:
http://www.docx4java.org/forums/docx-java-f6/issue-with-double-spacing-in-html-t1171.html#p4050

I have found a couple of issue that are still happening. It appears that if the paragraph is set to the defaults, there is no pPr node and it never gets in to the code to set the default margin-top at line 364 of the HtmlExporterNG2 code. Also, the same issue happens with the bottom margin. When it is not defined, it adds a margin in the browser, so that would need to be inline styled as well.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
// Does our pPr contain anything else?
                        boolean ignoreBorders = (htmlElementName.equals("p"));
                        if (pPr!=null) {
                                StringBuffer inlineStyle =  new StringBuffer();
                                HtmlCssHelper.createCss(context.getWmlPackage(), pPr, inlineStyle, ignoreBorders);                             
                                if (!inlineStyle.toString().equals("") ) {
                                        xhtmlBlock.setAttribute("style", inlineStyle.toString() );
                                }
                                if (!inlineStyle.toString().contains(SpaceBefore.CSS_NAME) ) {
                                // If there is no w:spacing/@w:before, it should be 0.
                                // unless it is set to anything in the effective style
                                PropertyResolver propertyResolver = context.getPropertyResolver();
                                        PPr stylePPr = propertyResolver.getEffectivePPr(pStyleVal);
                                        if (stylePPr.getSpacing()!=null
                                                        && stylePPr.getSpacing().getBefore()!=null) {
                                                // it is specified in the style
                                        } else {
                                                /* For a doc where there is no w:spacing/@w:before specified
                                                 * in the styles, Word's HTML output defaults to
 
                                                         p.MsoNormal, li.MsoNormal, div.MsoNormal
                                                                {
                                                                margin-top:0cm;
                                                                margin-right:0cm;
                                                                margin-bottom:10.0pt;
                                                                margin-left:0cm;
                                                                line-height:115%;  <------- from w:spacing/@w:line?
                                                                mso-pagination:widow-orphan;
                                                                font-size:11.0pt;
                                                                font-family:"Calibri","sans-serif";
                                                               
                                                        Here, for now, we are just dealing with
                                                        w:spacing/@w:before.
                                                 */

                                                xhtmlBlock.setAttribute("style", inlineStyle.toString() + "; margin-top:0cm; " );
                                               
                                        }
                                }
                                       
                        }
 
Parsed in 0.017 seconds, using GeSHi 1.0.8.4

Re: Issue with double spacing in HTML

PostPosted: Tue Apr 09, 2013 12:34 pm
by jason
Could you please attach a short sample docx which exhibits the issue?

Re: Issue with double spacing in HTML

PostPosted: Tue Apr 09, 2013 2:13 pm
by jallen
Here is the resulting html for the paragraph.
Code: Select all
<p class="Normal DocDefaults ">XXXXX</p>

Re: Issue with double spacing in HTML

PostPosted: Mon Apr 15, 2013 10:49 am
by jason
I've fixed this; the code will be pushed to GitHub over the next couple of days, and I'll create a nightly in the same timeframe.