Package org.docx4j.wml

Examples of org.docx4j.wml.Style


   
    // NB createVirtualStylesForDocDefaults() puts 10pt there, if nothing is specified!
    // So we need to delete that!
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().createVirtualStylesForDocDefaults();
    Style dd = wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getStyleById("DocDefaults");
    dd.getRPr().setSz(null);
    dd.getRPr().setSzCs(null);
   
   
    ParagraphStylesInTableFix.process(wordMLPackage);
   
    Style s = getStyle(wordMLPackage, STYLE_NAME);
    Assert.assertTrue(s.getRPr().getSz()==null);
  }
View Full Code Here


   
//    // Revert style and save:
//    ppr.setPStyle(ps); // doesn't work - wrong ref!
//    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    Style ours = null;
    for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
      if ("testStyle-TableNormal-BR".equals(s.getStyleId())) {
        ours = s;
        break;
      }
    }
   
//    Style s = getStyle(wordMLPackage, STYLE_NAME);
    Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT);
  }
View Full Code Here

   
//    // Revert style and save:
//    ppr.setPStyle(ps); // doesn't work - wrong ref!
//    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    Style ours = null;
    for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
      if ("testStyle-TableNormal-BR".equals(s.getStyleId())) {
        ours = s;
        break;
      }
    }
   
//    Style s = getStyle(wordMLPackage, STYLE_NAME);
    Assert.assertTrue(ours.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT);
  }
View Full Code Here

//   
//    getStyle(wordMLPackage, STYLE_NAME).setBasedOn(null);
//   
//    this.saveDocx(wordMLPackage, null);
   
    Style s = getStyle(wordMLPackage, STYLE_NAME);
    Assert.assertTrue(s.getRPr().getSz().getVal().intValue()==expectedResult);
   
    return wordMLPackage;
   
  }
View Full Code Here

      // Note that this is invoked for every paragraph with a pPr node.
     
      // incoming objects are org.apache.xml.dtm.ref.DTMNodeIterator
      // which implements org.w3c.dom.traversal.NodeIterator
     
    Style defaultParagraphStyle =
        (context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false) != null ?
        context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultParagraphStyle() :
        null);
   
      String defaultParagraphStyleId;
      if (defaultParagraphStyle==null) // possible, for non MS source docx
        defaultParagraphStyleId = "Normal";
      else defaultParagraphStyleId = defaultParagraphStyle.getStyleId();
     
    if ( pStyleVal ==null || pStyleVal.equals("") ) {
//      pStyleVal = "Normal";
      pStyleVal = defaultParagraphStyleId;
    }
View Full Code Here

            log.error("Node<AugmentedStyle> unexpectedly null data" );
          }
          continue;
        }
       
        Style s = n.getData().getStyle();

        result.append( "table."+ s.getStyleId()  + " {display:table;" );
       
        // TblPr
        if (s.getTblPr()==null) {
        } else {
          log.debug("Applying tblPr..");
              createCss(s.getTblPr(), result);
             
        }
       
        // TblStylePr - STTblStyleOverrideType stuff
        if (s.getTblStylePr()==null) {
        } else {
          log.debug("Applying tblStylePr.. TODO!");
          // Its a list, created automatically
              createCss(s.getTblStylePr(), result);
        }
       
       
        // TrPr - eg jc, trHeight, wAfter, tblCellSpacing
        if (s.getTrPr()==null) {
        } else {
          log.debug("Applying trPr.. TODO!");
              createCss( s.getTrPr(), result);
        }
       
        // TcPr - includes includes TcPrInner.TcBorders, CTShd, TcMar, CTVerticalJc
        if (s.getTcPr()==null) {
        } else {
          log.debug("Applying tcPr.. ");
              createCss( s.getTcPr(), result);
        }
               
          if (s.getPPr()==null) {
            log.debug("null pPr for style " + s.getStyleId());
          } else {
            HtmlCssHelper.createCss(opcPackage, s.getPPr(), result, false );
          }
          if (s.getRPr()==null) {
            log.debug("null rPr for style " + s.getStyleId());
          } else {
              HtmlCssHelper.createCss(opcPackage, s.getRPr(), result);
          }
          result.append( "}\n" );          
      }
   
    // Second iteration - paragraph level pPr *and rPr*
    result.append("\n /* PARAGRAPH STYLES */ \n");     
    Tree<AugmentedStyle> pTree = styleTree.getParagraphStylesTree();   
      for (org.docx4j.model.styles.Node<AugmentedStyle> n : pTree.toList() ) {
       
        if (n.getData()==null) {
          if (n.equals(pTree.getRootElement() )) {
            // shouldn't happen in paragraph case, but still, that's ok
          } else {
            log.error("Node<AugmentedStyle> unexpectedly null data" );
          }
          continue;
        }
       
        Style s = n.getData().getStyle();

        result.append( "."+ s.getStyleId()  + " {display:block;" )// not just p, also inherit on ul|ol
          if (s.getPPr()==null) {
            log.debug("null pPr for style " + s.getStyleId());
          } else {
            HtmlCssHelper.createCss(opcPackage, s.getPPr(), result, false );
          }
          if (s.getRPr()==null) {
            log.debug("null rPr for style " + s.getStyleId());
          } else {
              HtmlCssHelper.createCss(opcPackage, s.getRPr(), result);
          }
          result.append( "}\n" );         
      }
         
      // Third iteration, character styles
    result.append("\n /* CHARACTER STYLES */ ");
    //result.append("\n /* These come last, so they have more weight than the paragraph _rPr component styles */ \n ");
   
    Tree<AugmentedStyle> cTree = styleTree.getCharacterStylesTree();   
      for (org.docx4j.model.styles.Node<AugmentedStyle> n : cTree.toList() ) {
       
        if (n.getData()==null) {
          if (n.equals(cTree.getRootElement() )) {
            // that's ok
          } else {
            log.error("Node<AugmentedStyle> unexpectedly null data" );
          }
          continue;
        }
       
        Style s = n.getData().getStyle();

        result.append( "span."+ s.getStyleId()  + " {display:inline;" );
          if (s.getRPr()==null) {
            log.warn("! null rPr for character style " + s.getStyleId());
          } else {
              HtmlCssHelper.createCss(opcPackage, s.getRPr(), result);
          }
          result.append( "}\n" );         
     
    }
View Full Code Here

          .getStyleDefinitionsPart().getDefaultParagraphStyle().getStyleId());
    } catch (NullPointerException npe) {
      log.warn("No default paragraph style!!");
    }
   
    Style defaultTableStyle = wmlPackage.getMainDocumentPart()
        .getStyleDefinitionsPart().getDefaultTableStyle();
    if (defaultTableStyle != null) {
      styleRenamer.setDefaultTableStyle(defaultTableStyle);
    }
   
View Full Code Here

     */
    private String getCellPStyle(String styleVal, boolean pStyleIsDefault) {
     
      // Font size and jc for the style (which could be the default style),
      // without following its based on values
      Style expressStyle = allStyles.get(styleVal);
      Jc expressStyleJc = expressStyle.getPPr()==null ? null : expressStyle.getPPr().getJc();
      HpsMeasure expressStyleFontSize = null;
      if (expressStyle.getRPr()!=null) {
        expressStyleFontSize=expressStyle.getRPr().getSz();
      }
      // Font size and jc for the style following its based on values
      PPr effectivePPr = propertyResolver.getEffectivePPr(styleVal);
      Jc effectiveJc = effectivePPr.getJc();
     
      RPr effectiveRPr = propertyResolver.getEffectiveRPr(styleVal);
      HpsMeasure effectiveFontSize = null;
      if (effectiveRPr!=null) {
        effectiveFontSize=effectiveRPr.getSz();
      }
     
      String tableStyle=null;
      TblPr tblPr = tblStack.peek().getTblPr();
      if (tblPr!=null && tblPr.getTblStyle()!=null) {
        tableStyle = tblPr.getTblStyle().getVal();
      } else if (defaultTableStyle==null) {
        log.warn("No default table style defined in docx Style Definitions part");
        return null;           
      } else {
        if (defaultTableStyle.getName()!=null
            && defaultTableStyle.getName().getVal()!=null
            && defaultTableStyle.getName().getVal().equals("Normal Table")) {
          // Word 2010 x64 ignores any table style with that name!
          log.debug("Ignoring style with name 'Normal Table' (mimicking Word)");
          return null;
        } else {
          // We have a default table style
          tableStyle = defaultTableStyle.getStyleId();
          // shouldn't happen, but just in case..
          if (tableStyle==null) {
            log.error("Default table style has no ID!");
            log.error(XmlUtils.marshaltoString(tableStyle));
            return null;           
          }
        }
      }
      String resultStyleID = styleVal+"-"+tableStyle;
      if (tableStyle.endsWith("-BR")) {
        // don't want to add this twice
      } else {
        resultStyleID = resultStyleID +"-BR";
      }
         
      if (cellPStyles.contains(resultStyleID)) return resultStyleID;
     
      List<Style> hierarchy = new ArrayList<Style>();
     
      Style basedOn = null;
      String currentStyle = styleVal;
      do {
//        System.out.println("Getting " + currentStyle);
        Style thisStyle = allStyles.get(currentStyle);
        hierarchy.add(thisStyle);
        if (thisStyle.getBasedOn()!=null) {
          currentStyle = thisStyle.getBasedOn().getVal();
        } else {
          currentStyle = null;
        }
      } while (currentStyle != null);
     
 
     
      Style newStyle = Context.getWmlObjectFactory().createStyle();
      newStyle.setType("paragraph");
     
      // First, docDefaults
      Style styleToApply = hierarchy.get(hierarchy.size()-1); // DocDefault
      log.debug("DocDefault");
      log.debug(XmlUtils.marshaltoString(styleToApply, true, true));
      StyleUtil.apply(styleToApply, newStyle);
      log.debug("Result");
      log.debug(XmlUtils.marshaltoString(newStyle, true, true));
     
      // Next, table style - first/temporarily in tableStyleContrib
      Style tableStyleContrib = null;
      List<Style> tblStyles = new ArrayList<Style>();
      if (tableStyle!=null) {
        currentStyle = tableStyle;
          do {
            log.debug(currentStyle);               
            Style thisStyle = allStyles.get(currentStyle);
           
            if (thisStyle.getName().getVal().equals("Normal Table")) {
              // Very surprising, but testing using Word 2010 SP1,
              // it turns out that table style with name "Normal Table"
              // is IGNORED (whatever its ID, and whether default or not)!!
              // Change the name to something
              // else, and it is given effect! GO figure..
              //TBD how localisation affects this.
              // In theory, this style could be based on
              // another.  Haven't tested to see whether that is
              // honoured or not. Assume not.
              break;
            }
           
            tblStyles.add(thisStyle);
           
            if (thisStyle.getBasedOn()!=null) {
              currentStyle = thisStyle.getBasedOn().getVal();
            } else {
              currentStyle = null;
            }
          } while (currentStyle != null);

View Full Code Here

    private static String getCssForTableCells(HTMLConversionContext context,
        Tbl tbl, int idx) {
     
      StringBuffer result = new StringBuffer();   
    PropertyResolver pr = context.getPropertyResolver();
    Style s = pr.getEffectiveTableStyle(tbl.getTblPr() );
   
    result.append("#" + TableWriter.getId(idx) + " td { ");
      List<Property> properties =  new ArrayList<Property>();
      if (s.getTblPr()!=null
          && s.getTblPr().getTblBorders()!=null ) {
        TblBorders tblBorders = s.getTblPr().getTblBorders();
        if (tblBorders.getInsideH()!=null) {
          if (tblBorders.getInsideH().getVal()==STBorder.NONE
              || tblBorders.getInsideH().getVal()==STBorder.NIL
              || tblBorders.getInsideH().getSz()==BigInteger.ZERO ) {
            properties.add( new AdHocProperty("border-top-style", "none", null, null));
            properties.add( new AdHocProperty("border-top-width", "0mm", null, null));
            properties.add( new AdHocProperty("border-bottom-style", "none", null, null));
            properties.add( new AdHocProperty("border-bottom-width", "0mm", null, null));
          } else {
            properties.add( new BorderTop(tblBorders.getTop() ));
            properties.add( new BorderBottom(tblBorders.getBottom() ));
          }
        }
        if (tblBorders.getInsideV()!=null) {
          if (tblBorders.getInsideV().getVal()==STBorder.NONE
              || tblBorders.getInsideV().getVal()==STBorder.NIL
              || tblBorders.getInsideV().getSz()==BigInteger.ZERO ) {
            properties.add( new AdHocProperty("border-left-style", "none", null, null));
            properties.add( new AdHocProperty("border-left-width", "0mm", null, null));
            properties.add( new AdHocProperty("border-right-style", "none", null, null));
            properties.add( new AdHocProperty("border-right-width", "0mm", null, null));
          } else {
            properties.add( new BorderRight(tblBorders.getRight() ));
            properties.add( new BorderLeft(tblBorders.getLeft() ));
          }
        }
      }
      if (s.getTcPr()!=null ) {
        PropertyFactory.createProperties(properties, s.getTcPr() );
      }
    // Ensure empty cells have a sensible height
      // TODO - this is no good with IE8, which doesn't treat this
      // as a minimum; it won't resize if there is more :-(
      properties.add(new AdHocProperty("height", "5mm", null, null));
View Full Code Here

      // Note that this is invoked for every paragraph with a pPr node.
     
      // incoming objects are org.apache.xml.dtm.ref.DTMNodeIterator
      // which implements org.w3c.dom.traversal.NodeIterator

    Style defaultParagraphStyle =
        (context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false) != null ?
        context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultParagraphStyle() :
        null);
   
      String defaultParagraphStyleId;
      if (defaultParagraphStyle==null) // possible, for non MS source docx
        defaultParagraphStyleId = "Normal";
      else defaultParagraphStyleId = defaultParagraphStyle.getStyleId();
     
    if ( pStyleVal ==null || pStyleVal.equals("") ) {
//      pStyleVal = "Normal";
      pStyleVal = defaultParagraphStyleId;
    }
View Full Code Here

TOP

Related Classes of org.docx4j.wml.Style

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.