use of org.apache.poi.sl.usermodel.ColorStyle in project poi by apache.
the class DrawPaint method createRadialGradientPaint.
protected Paint createRadialGradientPaint(GradientPaint fill, Graphics2D graphics) {
Rectangle2D anchor = DrawShape.getAnchor(graphics, shape);
Point2D pCenter = new Point2D.Double(anchor.getX() + anchor.getWidth() / 2, anchor.getY() + anchor.getHeight() / 2);
float radius = (float) Math.max(anchor.getWidth(), anchor.getHeight());
float[] fractions = fill.getGradientFractions();
Color[] colors = new Color[fractions.length];
int i = 0;
for (ColorStyle fc : fill.getGradientColors()) {
colors[i++] = applyColorTransform(fc);
}
return new RadialGradientPaint(pCenter, radius, fractions, colors);
}
use of org.apache.poi.sl.usermodel.ColorStyle in project poi by apache.
the class HSLFFill method getGradientPaint.
private GradientPaint getGradientPaint(final GradientType gradientType) {
AbstractEscherOptRecord opt = shape.getEscherOptRecord();
final EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
final int colorCnt = (ep == null) ? 0 : ep.getNumberOfElementsInArray();
// NOFILLHITTEST can be in the normal escher opt record but also in the tertiary record
// the extended bit fields seem to be in the second
opt = (AbstractEscherOptRecord) shape.getEscherChild(RecordTypes.EscherUserDefined);
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
int propVal = (p == null) ? 0 : p.getPropertyValue();
final boolean rotateWithShape = FILL_USE_USE_SHAPE_ANCHOR.isSet(propVal) && FILL_USE_SHAPE_ANCHOR.isSet(propVal);
return new GradientPaint() {
@Override
public double getGradientAngle() {
// A value of type FixedPoint, as specified in [MS-OSHARED] section 2.2.1.6,
// that specifies the angle of the gradient fill. Zero degrees represents a vertical vector from
// bottom to top. The default value for this property is 0x00000000.
int rot = shape.getEscherProperty(EscherProperties.FILL__ANGLE);
return 90 - Units.fixedPointToDouble(rot);
}
@Override
public ColorStyle[] getGradientColors() {
ColorStyle[] cs;
if (colorCnt == 0) {
cs = new ColorStyle[2];
cs[0] = wrapColor(getBackgroundColor());
cs[1] = wrapColor(getForegroundColor());
} else {
cs = new ColorStyle[colorCnt];
int idx = 0;
// TODO: handle palette colors and alpha(?) value
for (byte[] data : ep) {
EscherColorRef ecr = new EscherColorRef(data, 0, 4);
cs[idx++] = wrapColor(shape.getColor(ecr));
}
}
return cs;
}
private ColorStyle wrapColor(Color col) {
return (col == null) ? null : DrawPaint.createSolidPaint(col).getSolidColor();
}
@Override
public float[] getGradientFractions() {
float[] frc;
if (colorCnt == 0) {
frc = new float[] { 0, 1 };
} else {
frc = new float[colorCnt];
int idx = 0;
for (byte[] data : ep) {
double pos = Units.fixedPointToDouble(LittleEndian.getInt(data, 4));
frc[idx++] = (float) pos;
}
}
return frc;
}
@Override
public boolean isRotatedWithShape() {
return rotateWithShape;
}
@Override
public GradientType getGradientType() {
return gradientType;
}
};
}
use of org.apache.poi.sl.usermodel.ColorStyle in project poi by apache.
the class XSLFShape method selectPaint.
protected static PaintStyle selectPaint(final CTGradientFillProperties gradFill, CTSchemeColor phClr, final XSLFTheme theme) {
final CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
Arrays.sort(gs, new Comparator<CTGradientStop>() {
public int compare(CTGradientStop o1, CTGradientStop o2) {
Integer pos1 = o1.getPos();
Integer pos2 = o2.getPos();
return pos1.compareTo(pos2);
}
});
final ColorStyle[] cs = new ColorStyle[gs.length];
final float[] fractions = new float[gs.length];
int i = 0;
for (CTGradientStop cgs : gs) {
CTSchemeColor phClrCgs = phClr;
if (phClrCgs == null && cgs.isSetSchemeClr()) {
phClrCgs = cgs.getSchemeClr();
}
cs[i] = new XSLFColor(cgs, theme, phClrCgs).getColorStyle();
fractions[i] = cgs.getPos() / 100000.f;
i++;
}
return new GradientPaint() {
public double getGradientAngle() {
return (gradFill.isSetLin()) ? gradFill.getLin().getAng() / 60000.d : 0;
}
public ColorStyle[] getGradientColors() {
return cs;
}
public float[] getGradientFractions() {
return fractions;
}
public boolean isRotatedWithShape() {
return gradFill.getRotWithShape();
}
public GradientType getGradientType() {
if (gradFill.isSetLin()) {
return GradientType.linear;
}
if (gradFill.isSetPath()) {
/* TODO: handle rect path */
STPathShadeType.Enum ps = gradFill.getPath().getPath();
if (ps == STPathShadeType.CIRCLE) {
return GradientType.circular;
} else if (ps == STPathShadeType.SHAPE) {
return GradientType.shape;
}
}
return GradientType.linear;
}
};
}
use of org.apache.poi.sl.usermodel.ColorStyle in project poi by apache.
the class TestBugs method bug55983.
@Test
public void bug55983() throws IOException {
HSLFSlideShow ppt1 = new HSLFSlideShow();
HSLFSlide sl = ppt1.createSlide();
sl.getBackground().getFill().setForegroundColor(Color.blue);
HSLFFreeformShape fs = sl.createFreeform();
Ellipse2D.Double el = new Ellipse2D.Double(0, 0, 300, 200);
fs.setAnchor(new Rectangle2D.Double(100, 100, 300, 200));
fs.setPath(new Path2D.Double(el));
Color cExp = new Color(50, 100, 150, 200);
fs.setFillColor(cExp);
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
ppt1.close();
sl = ppt2.getSlides().get(0);
fs = (HSLFFreeformShape) sl.getShapes().get(0);
Color cAct = fs.getFillColor();
assertEquals(cExp.getRed(), cAct.getRed());
assertEquals(cExp.getGreen(), cAct.getGreen());
assertEquals(cExp.getBlue(), cAct.getBlue());
assertEquals(cExp.getAlpha(), cAct.getAlpha(), 1);
PaintStyle ps = fs.getFillStyle().getPaint();
assertTrue(ps instanceof SolidPaint);
ColorStyle cs = ((SolidPaint) ps).getSolidColor();
cAct = cs.getColor();
assertEquals(cExp.getRed(), cAct.getRed());
assertEquals(cExp.getGreen(), cAct.getGreen());
assertEquals(cExp.getBlue(), cAct.getBlue());
assertEquals(255, cAct.getAlpha());
assertEquals(cExp.getAlpha() * 100000. / 255., cs.getAlpha(), 1);
ppt2.close();
}
use of org.apache.poi.sl.usermodel.ColorStyle in project poi by apache.
the class DrawPaint method createPathGradientPaint.
protected Paint createPathGradientPaint(GradientPaint fill, Graphics2D graphics) {
// currently we ignore an eventually center setting
float[] fractions = fill.getGradientFractions();
Color[] colors = new Color[fractions.length];
int i = 0;
for (ColorStyle fc : fill.getGradientColors()) {
colors[i++] = applyColorTransform(fc);
}
return new PathGradientPaint(colors, fractions);
}
Aggregations