Search in sources :

Example 1 with CTPositiveFixedPercentage

use of org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveFixedPercentage 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

Internal (org.apache.poi.util.Internal)1 CTPositiveFixedPercentage (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveFixedPercentage)1 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)1 CTScRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor)1 CTSolidColorFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties)1