Search in sources :

Example 6 with GradientPaint

use of org.apache.poi.sl.usermodel.PaintStyle.GradientPaint in project poi by apache.

the class TestXSLFTheme method slide10.

void slide10(XSLFSlide slide) {
    PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
    assertTrue(fs instanceof GradientPaint);
    XSLFTextShape sh1 = (XSLFTextShape) getShape(slide, "Title 3");
    XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
    assertTrue(sameColor(Color.white, run1.getFontColor()));
    // no fill
    assertNull(sh1.getFillColor());
    XSLFTextShape sh2 = (XSLFTextShape) getShape(slide, "Subtitle 4");
    XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
    assertTrue(sameColor(Color.white, run2.getFontColor()));
    // no fill
    assertNull(sh2.getFillColor());
}
Also used : PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)

Example 7 with GradientPaint

use of org.apache.poi.sl.usermodel.PaintStyle.GradientPaint in project poi by apache.

the class TestXSLFTheme method slide3.

void slide3(XSLFSlide slide) {
    PaintStyle fs = slide.getBackground().getFillStyle().getPaint();
    assertTrue(fs instanceof GradientPaint);
}
Also used : PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)

Example 8 with GradientPaint

use of org.apache.poi.sl.usermodel.PaintStyle.GradientPaint 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;
        }
    };
}
Also used : STPathShadeType(org.openxmlformats.schemas.drawingml.x2006.main.STPathShadeType) CTGradientStop(org.openxmlformats.schemas.drawingml.x2006.main.CTGradientStop) ColorStyle(org.apache.poi.sl.usermodel.ColorStyle) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) DrawPaint(org.apache.poi.sl.draw.DrawPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)

Aggregations

GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)8 Color (java.awt.Color)5 ColorStyle (org.apache.poi.sl.usermodel.ColorStyle)5 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)5 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)4 LinearGradientPaint (java.awt.LinearGradientPaint)3 Paint (java.awt.Paint)3 RadialGradientPaint (java.awt.RadialGradientPaint)3 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)3 Point2D (java.awt.geom.Point2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 AffineTransform (java.awt.geom.AffineTransform)1 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)1 EscherArrayProperty (org.apache.poi.ddf.EscherArrayProperty)1 EscherColorRef (org.apache.poi.ddf.EscherColorRef)1 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)1 TestCommonSL.sameColor (org.apache.poi.sl.TestCommonSL.sameColor)1 CTGradientStop (org.openxmlformats.schemas.drawingml.x2006.main.CTGradientStop)1 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)1