Package org.docx4j.wml

Examples of org.docx4j.wml.Jc


 
  public Justification(CSSValue value) { 
   
    debug(CSS_NAME, value);
       
    Jc jc = Context.getWmlObjectFactory().createJc();
   
    if (value.getCssText().toLowerCase().equals("left")) {
      jc.setVal(JcEnumeration.LEFT);
    } else if (value.getCssText().toLowerCase().equals("center")) {
      jc.setVal(JcEnumeration.CENTER);
    } else if (value.getCssText().toLowerCase().equals("right")) {
      jc.setVal(JcEnumeration.RIGHT);
    } else if (value.getCssText().toLowerCase().equals("justify")) {
      jc.setVal(JcEnumeration.BOTH);
    } else {
      log.warn("How to handle justification: " + value.getCssText());
    }   

    this.setObject( jc  );
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);

          for (int i = tblStyles.size()-1; i>=0; i--) {
            styleToApply = tblStyles.get(i);
            log.debug("Applying " + styleToApply.getStyleId() + "\n" + XmlUtils.marshaltoString(styleToApply, true, true));
           
            tableStyleContrib = StyleUtil.apply(styleToApply, tableStyleContrib);
            log.debug(XmlUtils.marshaltoString(tableStyleContrib, true, true));
          }
      }
     
      if (tableStyleContrib==null) {
        // will happen if the style was Normal Table, since we break above..
        // .. so just make an empty object, to avoid having to do isNull tests below..
        tableStyleContrib = Context.getWmlObjectFactory().createStyle();
      }

      // What do the table styles contribute?
      Jc tableStyleJc = tableStyleContrib.getPPr()==null ? null : tableStyleContrib.getPPr().getJc();
     
      HpsMeasure tableStyleFontSize = null;
      if (tableStyleContrib.getRPr()!=null) {
        tableStyleFontSize=tableStyleContrib.getRPr().getSz();
      }
View Full Code Here

//    *marL eg 342900 EMU
//    *indent eg -342900
   
//    *algn l|ctr|r
    if (lvlPPr.getAlgn()!=null) {
      Jc jc = factory.createJc();
      String algn = lvlPPr.getAlgn().value();
      log.debug("algn: " + algn);
      if algn.equals("l")) {
        jc.setVal(JcEnumeration.LEFT);
      } else if (algn.equals("ctr")) {
        jc.setVal(JcEnumeration.CENTER);
      } else if (algn.equals("r")) {
        jc.setVal(JcEnumeration.RIGHT);
  //    } else if (value.getCssText().toLowerCase().equals("justify")) {
  //      jc.setVal(JcEnumeration.BOTH);
      } else {
        log.warn("How to handle algn: " + algn);
      }   
View Full Code Here

TOP

Related Classes of org.docx4j.wml.Jc

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.