Package org.docx4j.wml

Examples of org.docx4j.wml.Style$Name


            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

        HTMLConversionContext context,
        String pStyleVal,
        NodeIterator rPrNodeIt,
        NodeIterator childResults ) {

    Style defaultRunStyle =
        (context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false) != null ?
        context.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultCharacterStyle() :
        null);
   
      String defaultCharacterStyleId;
      if (defaultRunStyle.getStyleId()==null) // possible, for non MS source docx
        defaultCharacterStyleId = "DefaultParagraphFont";
      else defaultCharacterStyleId = defaultRunStyle.getStyleId();
     
     
      StyleTree styleTree = context.getWmlPackage().getMainDocumentPart().getStyleTree();
           
      // Note that this is invoked for every paragraph with a pPr node.
View Full Code Here

      PropertyResolver propertyResolver = conversionContext.getPropertyResolver();
     

      String defaultParagraphStyleId = "Normal";
      if (conversionContext.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false) != null) {
          Style defaultParagraphStyle =
              conversionContext.getWmlPackage().getMainDocumentPart().getStyleDefinitionsPart(false).getDefaultParagraphStyle();
          if (defaultParagraphStyle != null) {
            defaultParagraphStyleId = defaultParagraphStyle.getStyleId();
          }
      }
     
      String pStyleVal = null;
      if (pPrDirect!=null && pPrDirect.getPStyle()!=null) {
View Full Code Here

    // Set up Table style tree
    tableTree.setRootElement(new Node<AugmentedStyle>(tableTree, "table-root", null)); // a dummy root node
        for (String styleId : stylesInUse ) {
          if (tableTree.get(styleId)==null) {
           
              Style style = allStyles.get(styleId);
                if (style == null ) {
                  log.warn("Couldn't find style: " + styleId);
                  continue;
                } else if (style.getType()==null) {
                  log.warn("missing type: " + XmlUtils.marshaltoString(style));
                } else
            // Is it a table style?
            if (style.getType().equals("table")) {               
                // Need to create a node for this
              this.addNode(styleId, allStyles, tableTree);
            }
          }
        }
   

    // Set up Paragraph style tree
        Style rootStyle = allStyles.get("DocDefaults");
        if (rootStyle==null) {
          pTree.setRootElement(new Node<AugmentedStyle>(pTree, "p-root", null));
        } else {
          AugmentedStyle as = new AugmentedStyle(rootStyle);         
          pTree.setRootElement(new Node<AugmentedStyle>(pTree, "DocDefaults", as));         
        }
         
        for (String styleId : stylesInUse ) {
          if (pTree.get(styleId)==null) {
           
              Style style = allStyles.get(styleId);
                if (style == null ) {
                  log.warn("Couldn't find style: " + styleId);
                  // See BrokenStyleRemediator for some causes of this, and potential fix
                  continue;
                }
                               
            // Is it a paragraph style?
            if (style.getType()!=null
                && style.getType().equals("paragraph")) {               
                // Need to create a node for this
              log.debug("Adding '" +  styleId + "' to paragraph tree" );
              this.addNode(styleId, allStyles, pTree);
            }
          } else {
            log.debug(styleId + " is already in paragraph tree");
          }
        }
       
    // Set up Character style tree
    cTree.setRootElement(new Node<AugmentedStyle>(cTree, "c-root", null));
        for (String styleId : stylesInUse ) {
          if (cTree.get(styleId)==null) {
           
              Style style = allStyles.get(styleId);
                if (style == null ) {
                  log.warn("Couldn't find style: " + styleId);
                  continue;
                }              
            // Is it a character style?
            if (style.getType()!=null
                && style.getType().equals("character")) {               
                // Need to create a node for this
              this.addNode(styleId, allStyles, cTree);
            }
          } else {
            log.debug(styleId + " is already in character tree");
View Full Code Here

 
  private Node<AugmentedStyle> addNode(String styleId, Map<String, Style> allStyles,
      Tree<AugmentedStyle> tree) {

    log.debug(styleId);
      Style style = allStyles.get(styleId);
        if (style == null ) {
          log.error("Couldn't find style: " + styleId);
          return null;
        }              
   
      AugmentedStyle as = new AugmentedStyle(style);         
      Node<AugmentedStyle> n =
         new Node<AugmentedStyle>(tree, styleId, as);
     
      // Find its parent
      if (style.getBasedOn()==null) {
       
        // You can have more than 1 node which isn't based on anything
      log.debug("Style " + styleId + " is not based on anything.");
      tree.getRootElement().addChild(n);
     
      // TODO: this should be basedOn DocDefaults.    Consider whether to do this
      // at this point, or in SDP.createVirtualStylesForDocDefaults()
           
      } else if (style.getBasedOn().getVal()!=null) {
          String basedOnStyleName = style.getBasedOn().getVal();  
          log.debug("..based on " + basedOnStyleName);         
          if (tree.get(basedOnStyleName)==null) {
//              log.debug("..can disregard that null, but it shouldn't happen again for this style");         
            Node<AugmentedStyle> parent = addNode(basedOnStyleName, allStyles, tree);
            if (parent!=null) {
              parent.addChild(n);
            }
          } else {
            tree.get(basedOnStyleName).addChild(n);
          }
         
      } else {
        log.error("No basedOn set for: " + style.getStyleId() );
      }
     
      return n;
   
  }
View Full Code Here

      String id, String name,
      String basedOn,
      FontScheme fontScheme) {
   
    ObjectFactory factory = Context.getWmlObjectFactory();
    Style style = factory.createStyle();
   
//    <w:style w:type="paragraph" w:styleId="Heading1">
    style.setType("paragraph");
    style.setStyleId(id);
   
    System.out.println("created " + id);
   
//    <w:name w:val="heading 1" />
    Name styleName = factory.createStyleName();
    styleName.setVal(name);
    style.setName(styleName);
   
//    <w:basedOn w:val="Normal" />
    Style.BasedOn basedon = factory.createStyleBasedOn();
    basedon.setVal(basedOn);
    style.setBasedOn(basedon);
   
//    <w:pPr>
    if (lvlPPr ==null) {
      log.warn("Empty style: " + id);
      if (log.isDebugEnabled() ) {
       
        log.debug( XmlUtils.marshaltoString(lvlPPr, true, true, Context.jc,
            "URI", "lvl1pPr", // BEWARE: could be lvl2 etc
            CTTextParagraphProperties.class));
       
        log.debug("Converted to: " +  XmlUtils.marshaltoString(style, true, true));
      }
      return style;
    }
   
    style.setPPr(
        getWmlPPr(lvlPPr) );
   
    style.setRPr(
        getWmlRPr(lvlPPr, fontScheme) );
       
   
   
    if (log.isDebugEnabled() ) {
View Full Code Here

TOP

Related Classes of org.docx4j.wml.Style$Name

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.