コード例 #1
0
ファイル: PShading.java プロジェクト: BobFleischman/docx4j
  public PShading(CSSValue value) {

    CTShd shd = Context.getWmlObjectFactory().createCTShd();

    // PrimitiveType 25 -> RGBCOLOR
    short ignored = 1;

    float fRed;
    float fGreen;
    float fBlue;

    CSSPrimitiveValue cssPrimitiveValue = (CSSPrimitiveValue) value;
    try {
      fRed = cssPrimitiveValue.getRGBColorValue().getRed().getFloatValue(ignored);
      fGreen = cssPrimitiveValue.getRGBColorValue().getGreen().getFloatValue(ignored);
      fBlue = cssPrimitiveValue.getRGBColorValue().getBlue().getFloatValue(ignored);
      shd.setFill(UnitsOfMeasurement.rgbTripleToHex(fRed, fGreen, fBlue));

    } catch (UnsupportedOperationException e) {

      try {
        Class<?> xhtmlImporterClass =
            Class.forName("org.docx4j.convert.in.xhtml.FSColorToHexString");
        Method rgbToHexMethod = xhtmlImporterClass.getMethod("rgbToHex", CSSPrimitiveValue.class);
        shd.setFill((String) rgbToHexMethod.invoke(null, cssPrimitiveValue));
      } catch (Exception e2) {
        log.error("docx4j-XHTMLImport jar not found. Please add this to your classpath.");
        log.error(e2.getMessage(), e2);
        throw e; // same as before
      }
    }

    this.setObject(shd);
  }
コード例 #2
0
ファイル: DOCXWriter.java プロジェクト: haxdai/SWBPDocumenter
 /**
  * Fills table cell with given hex color
  *
  * @param cell
  * @param hexColor
  */
 private void fillTableCell(Tc cell, String hexColor) {
   TcPr cellProps = cell.getTcPr();
   if (null == cellProps) cellProps = objectFactory.createTcPr();
   CTShd shd = objectFactory.createCTShd();
   shd.setFill(hexColor);
   shd.setThemeFill(STThemeColor.BACKGROUND_2);
   cellProps.setShd(shd);
   cell.setTcPr(cellProps);
 }
コード例 #3
0
 protected Property createShading(int fgColor, int bgColor, int pctFg) {
   CTShd shd = null;
   Shading ret = null;
   int resColor = UnitsOfMeasurement.combineColors(fgColor, bgColor, pctFg);
   String hResColor = UnitsOfMeasurement.toHexColor(resColor);
   shd = Context.getWmlObjectFactory().createCTShd();
   shd.setVal(STShd.CLEAR);
   shd.setFill(calcHexColor(resColor));
   return new Shading(shd);
 }
コード例 #4
0
 private void setCellColor(Tc tableCell, String color) {
   if (color != null) {
     TcPr tableCellProperties = tableCell.getTcPr();
     if (tableCellProperties == null) {
       tableCellProperties = new TcPr();
       tableCell.setTcPr(tableCellProperties);
     }
     CTShd shd = new CTShd();
     shd.setFill(color);
     tableCellProperties.setShd(shd);
   }
 }
コード例 #5
0
 protected void appendNoneBordersAndShading(List<Property> tableProperties) {
   CTBorder ctBrdr = null;
   CTShd shd = Context.getWmlObjectFactory().createCTShd();
   ctBrdr = Context.getWmlObjectFactory().createCTBorder();
   ctBrdr.setVal(STBorder.NONE);
   tableProperties.add(new BorderLeft(ctBrdr));
   ctBrdr = Context.getWmlObjectFactory().createCTBorder();
   ctBrdr.setVal(STBorder.NONE);
   tableProperties.add(new BorderRight(ctBrdr));
   ctBrdr = Context.getWmlObjectFactory().createCTBorder();
   ctBrdr.setVal(STBorder.NONE);
   tableProperties.add(new BorderTop(ctBrdr));
   ctBrdr = Context.getWmlObjectFactory().createCTBorder();
   ctBrdr.setVal(STBorder.NONE);
   tableProperties.add(new BorderBottom(ctBrdr));
   shd.setColor("auto");
   shd.setFill("auto");
   shd.setVal(STShd.CLEAR);
   tableProperties.add(new Shading(shd));
 }