Search in sources :

Example 11 with CTSolidColorFillProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties in project poi by apache.

the class XSLFSimpleShape method setFillColor.

@Override
public void setFillColor(Color color) {
    XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(getShapeProperties());
    if (fp == null) {
        return;
    }
    if (color == null) {
        if (fp.isSetSolidFill()) {
            fp.unsetSolidFill();
        }
        if (fp.isSetGradFill()) {
            fp.unsetGradFill();
        }
        if (fp.isSetPattFill()) {
            fp.unsetGradFill();
        }
        if (fp.isSetBlipFill()) {
            fp.unsetBlipFill();
        }
        if (!fp.isSetNoFill()) {
            fp.addNewNoFill();
        }
    } else {
        if (fp.isSetNoFill()) {
            fp.unsetNoFill();
        }
        CTSolidColorFillProperties fill = fp.isSetSolidFill() ? fp.getSolidFill() : fp.addNewSolidFill();
        XSLFColor col = new XSLFColor(fill, getSheet().getTheme(), fill.getSchemeClr());
        col.setColor(color);
    }
}
Also used : CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 12 with CTSolidColorFillProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties in project poi by apache.

the class XSLFSimpleShape method setLineColor.

/**
    * @param color  the color to paint the shape outline.
     * A <code>null</code> value turns off the shape outline.
     */
public void setLineColor(Color color) {
    CTLineProperties ln = getLn(this, true);
    if (ln == null) {
        return;
    }
    if (ln.isSetSolidFill()) {
        ln.unsetSolidFill();
    }
    if (ln.isSetGradFill()) {
        ln.unsetGradFill();
    }
    if (ln.isSetPattFill()) {
        ln.unsetPattFill();
    }
    if (ln.isSetNoFill()) {
        ln.unsetNoFill();
    }
    if (color == null) {
        ln.addNewNoFill();
    } else {
        CTSolidColorFillProperties fill = ln.addNewSolidFill();
        XSLFColor col = new XSLFColor(fill, getSheet().getTheme(), fill.getSchemeClr());
        col.setColor(color);
    }
}
Also used : CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties)

Example 13 with CTSolidColorFillProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties in project poi by apache.

the class XSLFPropertiesDelegate method getDelegate.

@SuppressWarnings("unchecked")
private static <T> T getDelegate(Class<T> clazz, XmlObject props) {
    Object obj = null;
    if (props == null) {
        return null;
    } else if (props instanceof CTShapeProperties) {
        obj = new ShapeDelegate((CTShapeProperties) props);
    } else if (props instanceof CTBackgroundProperties) {
        obj = new BackgroundDelegate((CTBackgroundProperties) props);
    } else if (props instanceof CTStyleMatrixReference) {
        obj = new StyleMatrixDelegate((CTStyleMatrixReference) props);
    } else if (props instanceof CTTableCellProperties) {
        obj = new TableCellDelegate((CTTableCellProperties) props);
    } else if (props instanceof CTNoFillProperties || props instanceof CTSolidColorFillProperties || props instanceof CTGradientFillProperties || props instanceof CTBlipFillProperties || props instanceof CTPatternFillProperties || props instanceof CTGroupFillProperties) {
        obj = new FillPartDelegate(props);
    } else if (props instanceof CTFillProperties) {
        obj = new FillDelegate((CTFillProperties) props);
    } else if (props instanceof CTLineProperties) {
        obj = new LineStyleDelegate((CTLineProperties) props);
    } else if (props instanceof CTTextCharacterProperties) {
        obj = new TextCharDelegate((CTTextCharacterProperties) props);
    } else {
        LOG.log(POILogger.ERROR, props.getClass() + " is an unknown properties type");
        return null;
    }
    if (clazz.isInstance(obj)) {
        return (T) obj;
    }
    LOG.log(POILogger.WARN, obj.getClass() + " doesn't implement " + clazz);
    return null;
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTNoFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) CTBackgroundProperties(org.openxmlformats.schemas.presentationml.x2006.main.CTBackgroundProperties) CTTableCellProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties) CTPatternFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTPatternFillProperties) CTGradientFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties) CTBlipFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties) XmlObject(org.apache.xmlbeans.XmlObject) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) CTFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties) CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties) CTGroupFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupFillProperties)

Example 14 with CTSolidColorFillProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties in project poi by apache.

the class XSLFColor method setColor.

/**
     * Sets the solid color
     *
     * @param color solid color
     */
@Internal
protected void setColor(Color color) {
    if (!(_xmlObject instanceof CTSolidColorFillProperties)) {
        LOGGER.log(POILogger.ERROR, "XSLFColor.setColor currently only supports CTSolidColorFillProperties");
        return;
    }
    CTSolidColorFillProperties fill = (CTSolidColorFillProperties) _xmlObject;
    if (fill.isSetSrgbClr()) {
        fill.unsetSrgbClr();
    }
    if (fill.isSetScrgbClr()) {
        fill.unsetScrgbClr();
    }
    if (fill.isSetHslClr()) {
        fill.unsetHslClr();
    }
    if (fill.isSetPrstClr()) {
        fill.unsetPrstClr();
    }
    if (fill.isSetSchemeClr()) {
        fill.unsetSchemeClr();
    }
    if (fill.isSetSysClr()) {
        fill.unsetSysClr();
    }
    float[] rgbaf = color.getRGBComponents(null);
    boolean addAlpha = (rgbaf.length == 4 && rgbaf[3] < 1f);
    CTPositiveFixedPercentage alphaPct;
    // see office open xml part 4 - 5.1.2.2.30 and 5.1.2.2.32
    if (isInt(rgbaf[0]) && isInt(rgbaf[1]) && isInt(rgbaf[2])) {
        // sRGB has a gamma of 2.2
        CTSRgbColor rgb = fill.addNewSrgbClr();
        byte[] rgbBytes = { (byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue() };
        rgb.setVal(rgbBytes);
        alphaPct = (addAlpha) ? rgb.addNewAlpha() : null;
    } else {
        CTScRgbColor rgb = fill.addNewScrgbClr();
        rgb.setR(DrawPaint.srgb2lin(rgbaf[0]));
        rgb.setG(DrawPaint.srgb2lin(rgbaf[1]));
        rgb.setB(DrawPaint.srgb2lin(rgbaf[2]));
        alphaPct = (addAlpha) ? rgb.addNewAlpha() : null;
    }
    // alpha (%)
    if (alphaPct != null) {
        alphaPct.setVal((int) (100000 * rgbaf[3]));
    }
}
Also used : CTScRgbColor(org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor) CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties) CTSRgbColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor) CTPositiveFixedPercentage(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveFixedPercentage) Internal(org.apache.poi.util.Internal)

Aggregations

CTSolidColorFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties)13 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)5 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)5 CTTextCharacterProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)4 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)3 Color (java.awt.Color)2 CTTableCellProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties)2 CTBackgroundProperties (org.openxmlformats.schemas.presentationml.x2006.main.CTBackgroundProperties)2 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 Internal (org.apache.poi.util.Internal)1 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)1 CTFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties)1 CTGradientFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties)1 CTGroupFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupFillProperties)1 CTNoFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties)1 CTPatternFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTPatternFillProperties)1 CTPositiveFixedPercentage (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveFixedPercentage)1 CTScRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor)1