use of org.apache.poi.sl.usermodel.ColorStyle in project poi by apache.
the class DrawPaint method createLinearGradientPaint.
protected Paint createLinearGradientPaint(GradientPaint fill, Graphics2D graphics) {
// TODO: we need to find the two points for gradient - the problem is, which point at the outline
// do you take? My solution would be to apply the gradient rotation to the shape in reverse
// and then scan the shape for the largest possible horizontal distance
double angle = fill.getGradientAngle();
if (!fill.isRotatedWithShape()) {
angle -= shape.getRotation();
}
Rectangle2D anchor = DrawShape.getAnchor(graphics, shape);
final double h = anchor.getHeight(), w = anchor.getWidth(), x = anchor.getX(), y = anchor.getY();
AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(angle), anchor.getCenterX(), anchor.getCenterY());
double diagonal = Math.sqrt(h * h + w * w);
Point2D p1 = new Point2D.Double(x + w / 2 - diagonal / 2, y + h / 2);
p1 = at.transform(p1, null);
Point2D p2 = new Point2D.Double(x + w, y + h / 2);
p2 = at.transform(p2, null);
if (p1.equals(p2)) {
// gradient paint on the same point throws an exception ... and doesn't make sense
return null;
}
float[] fractions = fill.getGradientFractions();
Color[] colors = new Color[fractions.length];
int i = 0;
for (ColorStyle fc : fill.getGradientColors()) {
// if fc is null, use transparent color to get color of background
colors[i++] = (fc == null) ? TRANSPARENT : applyColorTransform(fc);
}
return new LinearGradientPaint(p1, p2, fractions, colors);
}
use of org.apache.poi.sl.usermodel.ColorStyle in project poi by apache.
the class DrawPaint method getSolidPaint.
protected Paint getSolidPaint(SolidPaint fill, Graphics2D graphics, final PaintModifier modifier) {
final ColorStyle orig = fill.getSolidColor();
ColorStyle cs = new ColorStyle() {
@Override
public Color getColor() {
return orig.getColor();
}
@Override
public int getAlpha() {
return orig.getAlpha();
}
@Override
public int getHueOff() {
return orig.getHueOff();
}
@Override
public int getHueMod() {
return orig.getHueMod();
}
@Override
public int getSatOff() {
return orig.getSatOff();
}
@Override
public int getSatMod() {
return orig.getSatMod();
}
@Override
public int getLumOff() {
return orig.getLumOff();
}
@Override
public int getLumMod() {
return orig.getLumMod();
}
@Override
public int getShade() {
int shade = orig.getShade();
switch(modifier) {
case DARKEN:
return Math.min(100000, Math.max(0, shade) + 40000);
case DARKEN_LESS:
return Math.min(100000, Math.max(0, shade) + 20000);
default:
return shade;
}
}
@Override
public int getTint() {
int tint = orig.getTint();
switch(modifier) {
case LIGHTEN:
return Math.min(100000, Math.max(0, tint) + 40000);
case LIGHTEN_LESS:
return Math.min(100000, Math.max(0, tint) + 20000);
default:
return tint;
}
}
};
return applyColorTransform(cs);
}
Aggregations