Package org.docx4j.wml

Examples of org.docx4j.wml.HpsMeasure


      // If default font size is not specified, set it to match Word default when unspecified (ie 10)
      // It is useful to have this explicitly, especially for XHTML Import
//          <w:sz w:val="20"/>
//          <w:szCs w:val="20"/>     
      if (documentDefaultRPr.getSz()==null) {
        HpsMeasure s10pt = Context.getWmlObjectFactory().createHpsMeasure();
        s10pt.setVal(BigInteger.valueOf(20));
        documentDefaultRPr.setSz(s10pt);
      }
      if (documentDefaultRPr.getSzCs()==null) {
        HpsMeasure s10pt = Context.getWmlObjectFactory().createHpsMeasure();
        s10pt.setVal(BigInteger.valueOf(20));
        documentDefaultRPr.setSzCs(s10pt);
      }
    }
     
    styleDocDefaults.setPPr(documentDefaultPPr);
View Full Code Here


     
      // 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();
      }
     
      // Now we can apply to table style contrib on top of docDefaults
View Full Code Here

    int mediumHP = 22;
    if (mediumHalfPts.get()!=null) {
      mediumHP = mediumHalfPts.get().intValue();
    }
       
    HpsMeasure hpsMeasure = Context.getWmlObjectFactory().createHpsMeasure();
    CSSPrimitiveValue cssPrimitiveValue = (CSSPrimitiveValue)value;
    // Assume size is in points; sanity test.
    if (cssPrimitiveValue.getPrimitiveType()==CSSPrimitiveValue.CSS_IDENT) {
     
      String adjective = cssPrimitiveValue.getStringValue();
      if (adjective.equals("medium")) {
        hpsMeasure.setVal( BigInteger.valueOf( mediumHP) );
      } else if (adjective.equals("xx-small")) {
        hpsMeasure.setVal( BigInteger.valueOf( Math.round(0.6*mediumHP) ));
      } else if (adjective.equals("x-small")) {
        hpsMeasure.setVal( BigInteger.valueOf( Math.round(0.75*mediumHP) ));
      } else if (adjective.equals("small")) {
        hpsMeasure.setVal( BigInteger.valueOf( Math.round(0.89*mediumHP) ));
      } else if (adjective.equals("large")) {
        hpsMeasure.setVal( BigInteger.valueOf( Math.round(1.2*mediumHP) ));
      } else if (adjective.equals("x-large")) {
        hpsMeasure.setVal( BigInteger.valueOf( Math.round(1.5*mediumHP) ));
      } else if (adjective.equals("xx-large")) {
        hpsMeasure.setVal( BigInteger.valueOf( Math.round(2*mediumHP) ));
      } else {
        log.warn("TODO Handle FontSize units properly: " + adjective );             
        hpsMeasure.setVal( BigInteger.valueOf( mediumHP) );
      }
      this.setObject(hpsMeasure);       
     
    } else if(cssPrimitiveValue.getPrimitiveType() == CSSPrimitiveValue.CSS_PX){
     
        float pxVal = cssPrimitiveValue.getFloatValue(CSSPrimitiveValue.CSS_PX);
        int iVal = UnitsOfMeasurement.pxToTwip(pxVal)/10;
        hpsMeasure.setVal(BigInteger.valueOf(iVal));
        this.setObject(hpsMeasure);
       
    } else  if (cssPrimitiveValue.getPrimitiveType()!=CSSPrimitiveValue.CSS_PT) {
     
      log.error("TODO FontSize Handle units: " + cssPrimitiveValue.getPrimitiveType() );
      debug(CSS_NAME, value);
     
    } else { // CSS_PT points
     
      short ignored = 1;
      float fVal = cssPrimitiveValue.getFloatValue(ignored); // unit type ignored in cssparser
      int iVal = Math.round(fVal*2);
     
      hpsMeasure.setVal( BigInteger.valueOf(iVal) );
      this.setObject(hpsMeasure);
    }
  }
View Full Code Here

          p.getContent().add( r);
              // Create object for rPr
              RPr rpr = wmlObjectFactory.createRPr();
              r.setRPr(rpr);
                  // Create object for sz
                  HpsMeasure hpsmeasure3 = wmlObjectFactory.createHpsMeasure();
                  rpr.setSz(hpsmeasure3);
                      hpsmeasure3.setVal( BigInteger.valueOf( 96) );

              // Create object for t (wrapped in JAXBElement)
              Text text = wmlObjectFactory.createText();
              JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text);
              r.getContent().add( textWrapped);
View Full Code Here

    return rPr;
 
 
  private static HpsMeasure convertFontSize(Integer in) {
    ObjectFactory factory = Context.getWmlObjectFactory();
    HpsMeasure sz = factory.createHpsMeasure();
    int halfPts = Math.round(in/50);
    sz.setVal( BigInteger.valueOf(halfPts) );
    return sz;
  }
View Full Code Here

TOP

Related Classes of org.docx4j.wml.HpsMeasure

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.