Changeset 1754 for trunk


Ignore:
Timestamp:
01/24/12 01:35:16 (4 months ago)
Author:
jharrop
Message:

Improvements to indentation (direct indent values are given priority over values in numbering, which in turn is given priority over values in styles), plus associated unit tests.

Location:
trunk/docx4j/src
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/html/AbstractHtmlExporter.java

    r1637 r1754  
    1212import org.apache.log4j.Logger; 
    1313import org.docx4j.UnitsOfMeasurement; 
     14import org.docx4j.XmlUtils; 
    1415import org.docx4j.convert.out.AbstractConversionSettings; 
    1516import org.docx4j.convert.out.Output; 
     
    157158         */ 
    158159    public static DocumentFragment getNumberXmlNode(WordprocessingMLPackage wmlPackage, 
     160                NodeIterator pPrNodeIt, 
    159161                String pStyleVal, String numId, String levelId) { 
    160162         
     
    199201//              } 
    200202                         
    201                         NumberingDefinitionsPart ndp = wmlPackage.getMainDocumentPart().getNumberingDefinitionsPart(); 
    202                         Ind ind = ndp.getInd(numId, levelId); 
    203                         if (ind!=null && ind.getHanging()!=null) { 
    204                                 String hanging = UnitsOfMeasurement.twipToBest(ind.getHanging().intValue()); 
    205                                 styleVal="position: absolute; left:-" + hanging + "; max-width: " + hanging +";";                                                        
     203                PPr pPr = null; 
     204                if (pPrNodeIt!=null) { 
     205                        Node n = pPrNodeIt.nextNode(); 
     206                        if (n!=null) { 
     207                                        log.debug( XmlUtils.w3CDomNodeToString(n) ); 
     208                                Unmarshaller u = Context.jc.createUnmarshaller();                        
     209                                u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); 
     210                                pPr = (PPr)u.unmarshal(n); 
     211                        } 
     212                }    
     213                        if (pPr.getInd()==null) { 
     214                         
     215                                NumberingDefinitionsPart ndp = wmlPackage.getMainDocumentPart().getNumberingDefinitionsPart(); 
     216                                Ind ind = ndp.getInd(numId, levelId); 
     217                                if (ind!=null && ind.getHanging()!=null) { 
     218                                        String hanging = UnitsOfMeasurement.twipToBest(ind.getHanging().intValue()); 
     219                                        styleVal="position: absolute; left:-" + hanging + "; max-width: " + hanging +";";                                                        
     220                                } 
     221                                // TODO: position bullets correctly where there is no hanging 
     222                                // TODO: The suff element tells us what separates the number from 
     223                                // the text (tab, space or nothing).  If its a tab, 
     224                                // we'll need to know the tab values here. Currently, we're  
     225                                // assuming hanging overrides all that. 
     226                        } else { 
     227                                 
     228                                Ind ind = pPr.getInd(); 
     229                                if (ind!=null && ind.getHanging()!=null) { 
     230                                        String hanging = UnitsOfMeasurement.twipToBest(ind.getHanging().intValue()); 
     231                                        styleVal="position: absolute; left:-" + hanging + "; max-width: " + hanging +";";                                                        
     232                                } 
     233                                 
    206234                        } 
    207                         // TODO: position bullets correctly where there is no hanging 
    208                         // TODO: The suff element tells us what separates the number from 
    209                         // the text (tab, space or nothing).  If its a tab, 
    210                         // we'll need to know the tab values here. Currently, we're  
    211                         // assuming hanging overrides all that. 
    212235                         
    213236                // Set the font 
  • trunk/docx4j/src/main/java/org/docx4j/model/ImmutablePropertyResolver.java

    r864 r1754  
    2424        } 
    2525 
    26         public ImmutablePropertyResolver(StyleDefinitionsPart styleDefinitionsPart, 
    27                         ThemePart themePart, 
    28                         NumberingDefinitionsPart numberingDefinitionsPart) 
    29                         throws Docx4JException { 
    30                 super(styleDefinitionsPart, themePart, numberingDefinitionsPart); 
    31         } 
     26//      public ImmutablePropertyResolver(StyleDefinitionsPart styleDefinitionsPart, 
     27//                      ThemePart themePart, 
     28//                      NumberingDefinitionsPart numberingDefinitionsPart) 
     29//                      throws Docx4JException { 
     30//              super(styleDefinitionsPart, themePart, numberingDefinitionsPart); 
     31//      } 
    3232 
    3333        protected void applyPPr(PPr src, PPr dest) { 
  • trunk/docx4j/src/main/java/org/docx4j/model/PropertyResolver.java

    r1665 r1754  
    1717import org.docx4j.model.properties.PropertyFactory; 
    1818import org.docx4j.model.properties.paragraph.AbstractParagraphProperty; 
     19import org.docx4j.model.properties.paragraph.Indent; 
    1920import org.docx4j.model.properties.run.AbstractRunProperty; 
    2021import org.docx4j.openpackaging.exceptions.Docx4JException; 
     
    107108        private StyleDefinitionsPart styleDefinitionsPart; 
    108109         
     110        private WordprocessingMLPackage wordMLPackage; 
    109111         
    110112        /** 
     
    133135        public PropertyResolver(WordprocessingMLPackage wordMLPackage) throws Docx4JException { 
    134136                 
     137                this.wordMLPackage = wordMLPackage; 
     138                 
    135139                MainDocumentPart mdp = wordMLPackage.getMainDocumentPart(); 
    136140                 
     
    141145        } 
    142146         
    143         public PropertyResolver(StyleDefinitionsPart styleDefinitionsPart, 
    144                                                         ThemePart themePart, 
    145                                                         NumberingDefinitionsPart numberingDefinitionsPart) throws Docx4JException { 
    146                  
    147                 this.styleDefinitionsPart= styleDefinitionsPart; 
    148                 this.themePart = themePart; 
    149                 this.numberingDefinitionsPart = numberingDefinitionsPart; 
    150                 init(); 
    151         } 
     147//      public PropertyResolver(StyleDefinitionsPart styleDefinitionsPart, 
     148//                                                      ThemePart themePart, 
     149//                                                      NumberingDefinitionsPart numberingDefinitionsPart) throws Docx4JException { 
     150//               
     151//              this.styleDefinitionsPart= styleDefinitionsPart; 
     152//              this.themePart = themePart; 
     153//              this.numberingDefinitionsPart = numberingDefinitionsPart; 
     154//              init(); 
     155//      } 
    152156         
    153157        String defaultParagraphStyleId;  // "Normal" in English, but ... 
     
    918922        protected void applyPPr(PPr pPrToApply, PPr effectivePPr) { 
    919923                 
     924                log.debug( "apply " + XmlUtils.marshaltoString(pPrToApply,  true, true) 
     925                + "\n\r to " + XmlUtils.marshaltoString(effectivePPr,  true, true) ); 
     926                 
    920927                if (pPrToApply==null) { 
    921928                        return; 
    922929                } 
    923930                 
    924         List<Property> properties = PropertyFactory.createProperties(null, pPrToApply); // wmlPackage null 
    925          
     931        List<Property> properties = PropertyFactory.createProperties(wordMLPackage, pPrToApply);  
    926932        for( Property p :  properties ) { 
    927933                        if (p!=null) { 
     
    931937        } 
    932938 
    933  
     939                log.debug( "result " + XmlUtils.marshaltoString(effectivePPr,  true, true) ); 
     940         
    934941        } 
    935942         
  • trunk/docx4j/src/main/java/org/docx4j/model/properties/PropertyFactory.java

    r1700 r1754  
    2525 
    2626import org.apache.log4j.Logger; 
     27import org.docx4j.XmlUtils; 
    2728import org.docx4j.model.properties.paragraph.Indent; 
    2829import org.docx4j.model.properties.paragraph.Justification; 
     
    396397//              if (pPr.getMirrorIndents() != null) 
    397398//                      dest.setMirrorIndents(pPr.getMirrorIndents()); 
    398                 Ind ind = null; 
    399                 if (pPr.getNumPr() != null) { 
     399                 
     400                /* 
     401                 * Where a p has indentation specified by both w:numPr and direct w:ind, eg: 
     402                 *   
     403                    <w:p> 
     404                      <w:pPr> 
     405                        <w:numPr> 
     406                          <w:ilvl w:val="0"/> 
     407                          <w:numId w:val="2"/> 
     408                        </w:numPr> 
     409                        <w:ind w:left="0" w:firstLine="0"/> 
     410                      </w:pPr> 
     411 
     412                        we want to ensure that the direct values are given effect. 
     413                         
     414                        ie indent on direct pPr trumps indent in pPr in numbering, which trumps indent 
     415                        specified in a style.   
     416 
     417                 */ 
     418                Indent indent = null;  
     419                boolean numberingIndent = false; 
     420                if (pPr.getNumPr() == null) { 
     421                        log.debug("No numPr.. ") ;                                                                       
     422                } else { 
    400423                        // Numbering is mostly handled directly in the HTML & PDF stylesheets                    
    401424                        properties.add(new NumberingProperty(pPr.getNumPr())); 
    402                         // but we do want to override w:ind above 
    403                         if (pPr.getNumPr()!=null) { 
    404                                 if (wmlPackage instanceof WordprocessingMLPackage) { 
    405                                         NumberingDefinitionsPart ndp = ((WordprocessingMLPackage)wmlPackage).getMainDocumentPart().getNumberingDefinitionsPart(); 
    406                     if (ndp != null) { 
    407                                         ind = ndp.getInd(pPr.getNumPr()); 
    408                                         if (ind!=null) { 
    409                                                 properties.add(new Indent(ind));                         
     425                        // but we do want to get w:ind (in case not set elsewhere) 
     426                        if (wmlPackage instanceof WordprocessingMLPackage) { 
     427                                NumberingDefinitionsPart ndp  
     428                                        = ((WordprocessingMLPackage)wmlPackage).getMainDocumentPart().getNumberingDefinitionsPart(); 
     429                if (ndp == null) { 
     430                                        log.debug("No NDP?.. ") ;                                                                        
     431                } else { 
     432                                        Ind ind = ndp.getInd(pPr.getNumPr()); 
     433                                        if (ind==null) { 
     434                                                log.debug("No Indent in numbering.. ") ;                                                 
     435                                        } else { 
     436                                                log.debug("Indent from numbering: " + XmlUtils.marshaltoString(ind,  true, true)) ;  
     437                                                indent = new Indent(ind); 
     438                                                properties.add(indent);                  
    410439                                                log.debug("Using w:ind from list level"); 
     440                                                numberingIndent = true; 
    411441                                        } 
    412                     } 
     442                } 
     443                        } else { 
     444                                log.info(wmlPackage + " " + wmlPackage.getClass().getName() ) ; 
     445                        } 
     446                } 
     447                 
     448                // Give effect to the prioritisation 
     449                        if (pPr.getInd() != null) { 
     450                                log.debug("Indent from ppr: " + XmlUtils.marshaltoString(pPr.getInd(),  true, true)) ;  
     451                                if (indent!=null) { 
     452                                        properties.remove(indent); 
    413453                                } 
     454                                properties.add(new Indent(pPr.getInd()));                        
    414455                        } 
    415                 } 
    416                 if (ind==null) { 
    417                         if (pPr.getInd() != null) 
    418                                 properties.add(new Indent(pPr.getInd()));                        
    419                 } 
     456                 
    420457//              if (pPr.getOutlineLvl() != null) 
    421458//                      dest.setOutlineLvl(pPr.getOutlineLvl()); 
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/parts/WordprocessingML/NumberingDefinitionsPart.java

    r1726 r1754  
    142142 
    143143        // instantiate the list number definitions 
    144         //foreach (XmlNode numNode in numberNodes) 
    145144        for( Numbering.Num numNode : numbering.getNum() ) 
    146145        { 
     
    235234                // Operating on the docx4j.listnumbering plane, 
    236235                // not the JAXB plane.. 
    237                 ListNumberingDefinition lnd = instanceListDefinitions.get(numId ); 
     236                ListNumberingDefinition lnd = getInstanceListDefinitions().get(numId ); 
    238237                if (lnd==null) { 
    239238                        log.debug("couldn't find list for numId: " + numId); 
Note: See TracChangeset for help on using the changeset viewer.