Package org.docx4j.wml

Examples of org.docx4j.wml.Style


        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

  }
 
    protected static Style createVirtualStylesForDocDefaults(FontScheme fontScheme) {
     
    ObjectFactory factory = Context.getWmlObjectFactory();
    Style style = factory.createStyle();
     
      String ROOT_NAME = "DocDefaults";
     
      style.setStyleId(ROOT_NAME);
      style.setType("paragraph");
   
    Name styleName = factory.createStyleName();
    styleName.setVal(ROOT_NAME);
    style.setName(styleName);
   
//    <w:rPr>
    RPr rPr = factory.createRPr();
    style.setRPr(rPr);

//    <w:rFonts w:asciiTheme="majorHAnsi" w:eastAsiaTheme="majorEastAsia" w:hAnsiTheme="majorHAnsi" w:cstheme="majorBidi" />
    RFonts rFonts = factory.createRFonts();
    rFonts.setAscii( fontScheme.getMinorFont().getLatin().getTypeface() );
    rPr.setRFonts(rFonts);
View Full Code Here

   
    // 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() ) {
        Style s = n.getData().getStyle();

        result.append( "."+ s.getStyleId()  + " {display:block;" );
          if (s.getPPr()==null) {
            log.debug("null pPr for style " + s.getStyleId());
          } else {
            HtmlCssHelper.createCss(context.getPmlPackage(), s.getPPr(), result, false );
          }
          if (s.getRPr()==null) {
            log.debug("null rPr for style " + s.getStyleId());
          } else {
            HtmlCssHelper.createCss(context.getPmlPackage(), s.getRPr(), result);
          }
          result.append( "}\n" );         
      }
               
      if (log.isDebugEnabled()) {
View Full Code Here

    // Initialise styles
    styles = (org.docx4j.wml.Styles)styleDefinitionsPart.getJaxbElement()
    initialiseLiveStyles();   
   
    Style docDefaults = styleDefinitionsPart.getStyleById("DocDefaults");
    log.debug(XmlUtils.marshaltoString(docDefaults, true, true));
    documentDefaultPPr = docDefaults.getPPr();
    documentDefaultRPr = docDefaults.getRPr();

      addNormalToResolvedStylePPrComponent();
    addDefaultParagraphFontToResolvedStyleRPrComponent();
  }
View Full Code Here

      fillTableStyleStack(styleId, tableStyleStack);
    } else {
      log.debug("No table style specified");
    }
   
    Style result;
    if (tableStyleStack.size()>0 ) {
      result = XmlUtils.deepCopy(tableStyleStack.pop());
    } else {
      result = Context.getWmlObjectFactory().createStyle();
      CTTblPrBase emptyPr = Context.getWmlObjectFactory().createCTTblPrBase();
      result.setTblPr(emptyPr);
      if (tblPr==null) {
        // Return empty style object
        log.info("Generated empty tblPr" );
        return result;
      }     
    }
    while (!tableStyleStack.empty() ) {
      StyleUtil.apply(tableStyleStack.pop(), result);
    }
   
    // Finally apply the tblPr we were passed
    result.setTblPr(StyleUtil.apply(tblPr, result.getTblPr()));
   
    // Sanity check
    if (result.getTblPr()==null) {
      log.error("Null tblPr. FIXME" );
    }
   
    return result;
  }
View Full Code Here

   * @param stylename
   * @param effectivePPr
   */
  private void fillTableStyleStack(String styleId, Stack<Style> tableStyleStack) {
    // get the style
    Style style = liveStyles.get(styleId);
   
    // add it to the stack
    if (style==null) {
      // No such style!
      // For now, just log it..
      log.error("Style definition not found: " + styleId);
      return;
    }
   
    tableStyleStack.push(style);
    log.debug("Added " + styleId + " to table style stack");
   
    // if it is based on, recurse
      if (style.getBasedOn()==null) {
      log.debug("Style " + styleId + " is a root style.");
      } else if (style.getBasedOn().getVal()!=null) {
          String basedOnStyleName = style.getBasedOn().getVal();            
          fillTableStyleStack( basedOnStyleName, tableStyleStack);
      } else {
        log.debug("No basedOn set for: " + style.getStyleId() );
      }
   
  }
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.