use of org.openxmlformats.schemas.drawingml.x2006.main.CTGradientStop 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;
}
};
}
Aggregations