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);
}
}
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);
}
}
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;
}
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]));
}
}
Aggregations