Search in sources :

Example 1 with CTGradientFillProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties 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)

Example 2 with CTGradientFillProperties

use of org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties 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;
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTNoFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) CTBackgroundProperties(org.openxmlformats.schemas.presentationml.x2006.main.CTBackgroundProperties) CTTableCellProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties) CTPatternFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTPatternFillProperties) CTGradientFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties) CTBlipFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties) XmlObject(org.apache.xmlbeans.XmlObject) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) CTFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties) CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties) CTGroupFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupFillProperties)

Aggregations

DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 ColorStyle (org.apache.poi.sl.usermodel.ColorStyle)1 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)1 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)1 CTFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties)1 CTGradientFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties)1 CTGradientStop (org.openxmlformats.schemas.drawingml.x2006.main.CTGradientStop)1 CTGroupFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupFillProperties)1 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)1 CTNoFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties)1 CTPatternFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTPatternFillProperties)1 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)1 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)1 CTSolidColorFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties)1 CTStyleMatrixReference (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference)1 CTTableCellProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties)1 CTTextCharacterProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)1 STPathShadeType (org.openxmlformats.schemas.drawingml.x2006.main.STPathShadeType)1