Search in sources :

Example 1 with PropertyFetcher

use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.

the class XSLFSimpleShape method getLineCap.

/**
     *
     * @return the line end cap style
     */
public LineCap getLineCap() {
    PropertyFetcher<LineCap> fetcher = new PropertyFetcher<LineCap>() {

        @Override
        public boolean fetch(XSLFShape shape) {
            CTLineProperties ln = getLn(shape, false);
            if (ln != null && ln.isSetCap()) {
                setValue(LineCap.fromOoxmlId(ln.getCap().intValue()));
                return true;
            }
            return false;
        }
    };
    fetchShapeProperty(fetcher);
    LineCap cap = fetcher.getValue();
    if (cap == null) {
        CTLineProperties defaultLn = getDefaultLineProperties();
        if (defaultLn != null && defaultLn.isSetCap()) {
            cap = LineCap.fromOoxmlId(defaultLn.getCap().intValue());
        }
    }
    return cap;
}
Also used : CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) LineCap(org.apache.poi.sl.usermodel.StrokeStyle.LineCap) STLineCap(org.openxmlformats.schemas.drawingml.x2006.main.STLineCap)

Example 2 with PropertyFetcher

use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.

the class XSLFSimpleShape method getLineDash.

/**
     * @return  a preset line dashing scheme to stroke the shape outline
     */
public LineDash getLineDash() {
    PropertyFetcher<LineDash> fetcher = new PropertyFetcher<LineDash>() {

        @Override
        public boolean fetch(XSLFShape shape) {
            CTLineProperties ln = getLn(shape, false);
            if (ln == null || !ln.isSetPrstDash()) {
                return false;
            }
            setValue(LineDash.fromOoxmlId(ln.getPrstDash().getVal().intValue()));
            return true;
        }
    };
    fetchShapeProperty(fetcher);
    LineDash dash = fetcher.getValue();
    if (dash == null) {
        CTLineProperties defaultLn = getDefaultLineProperties();
        if (defaultLn != null && defaultLn.isSetPrstDash()) {
            dash = LineDash.fromOoxmlId(defaultLn.getPrstDash().getVal().intValue());
        }
    }
    return dash;
}
Also used : CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) LineDash(org.apache.poi.sl.usermodel.StrokeStyle.LineDash)

Example 3 with PropertyFetcher

use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.

the class XSLFSimpleShape method getLinePaint.

protected PaintStyle getLinePaint() {
    XSLFSheet sheet = getSheet();
    final XSLFTheme theme = sheet.getTheme();
    final boolean hasPlaceholder = getPlaceholder() != null;
    PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() {

        @Override
        public boolean fetch(XSLFShape shape) {
            CTLineProperties spPr = getLn(shape, false);
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(spPr);
            if (fp != null && fp.isSetNoFill()) {
                setValue(null);
                return true;
            }
            PackagePart pp = shape.getSheet().getPackagePart();
            PaintStyle paint = selectPaint(fp, null, pp, theme, hasPlaceholder);
            if (paint != null) {
                setValue(paint);
                return true;
            }
            CTShapeStyle style = shape.getSpStyle();
            if (style != null) {
                fp = XSLFPropertiesDelegate.getFillDelegate(style.getLnRef());
                paint = selectPaint(fp, null, pp, theme, hasPlaceholder);
                // line color was not found, check if it is defined in the theme
                if (paint == null) {
                    paint = getThemePaint(style, pp);
                }
            }
            if (paint != null) {
                setValue(paint);
                return true;
            }
            return false;
        }

        PaintStyle getThemePaint(CTShapeStyle style, PackagePart pp) {
            // get a reference to a line style within the style matrix.
            CTStyleMatrixReference lnRef = style.getLnRef();
            if (lnRef == null) {
                return null;
            }
            int idx = (int) lnRef.getIdx();
            CTSchemeColor phClr = lnRef.getSchemeClr();
            if (idx <= 0) {
                return null;
            }
            CTLineProperties props = theme.getXmlObject().getThemeElements().getFmtScheme().getLnStyleLst().getLnArray(idx - 1);
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
            return selectPaint(fp, phClr, pp, theme, hasPlaceholder);
        }
    };
    fetchShapeProperty(fetcher);
    return fetcher.getValue();
}
Also used : CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 4 with PropertyFetcher

use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.

the class XSLFSimpleShape method getShadow.

/**
     * @return shadow of this shape or null if shadow is disabled
     */
@Override
public XSLFShadow getShadow() {
    PropertyFetcher<CTOuterShadowEffect> fetcher = new PropertyFetcher<CTOuterShadowEffect>() {

        @Override
        public boolean fetch(XSLFShape shape) {
            XSLFEffectProperties ep = XSLFPropertiesDelegate.getEffectDelegate(shape.getShapeProperties());
            if (ep != null && ep.isSetEffectLst()) {
                CTOuterShadowEffect obj = ep.getEffectLst().getOuterShdw();
                setValue(obj == null ? NO_SHADOW : obj);
                return true;
            }
            return false;
        }
    };
    fetchShapeProperty(fetcher);
    CTOuterShadowEffect obj = fetcher.getValue();
    if (obj == null) {
        // fill color was not found, check if it is defined in the theme
        CTShapeStyle style = getSpStyle();
        if (style != null && style.getEffectRef() != null) {
            // 1-based index of a shadow style within the style matrix
            int idx = (int) style.getEffectRef().getIdx();
            if (idx != 0) {
                CTStyleMatrix styleMatrix = getSheet().getTheme().getXmlObject().getThemeElements().getFmtScheme();
                CTEffectStyleItem ef = styleMatrix.getEffectStyleLst().getEffectStyleArray(idx - 1);
                obj = ef.getEffectLst().getOuterShdw();
            }
        }
    }
    return (obj == null || obj == NO_SHADOW) ? null : new XSLFShadow(obj, this);
}
Also used : CTStyleMatrix(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix) CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) XSLFEffectProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFEffectProperties) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) CTEffectStyleItem(org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem) CTOuterShadowEffect(org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)

Example 5 with PropertyFetcher

use of org.apache.poi.xslf.model.PropertyFetcher in project poi by apache.

the class XSLFSimpleShape method getXfrm.

protected CTTransform2D getXfrm(boolean create) {
    PropertyFetcher<CTTransform2D> fetcher = new PropertyFetcher<CTTransform2D>() {

        @Override
        public boolean fetch(XSLFShape shape) {
            XmlObject xo = shape.getShapeProperties();
            if (xo instanceof CTShapeProperties && ((CTShapeProperties) xo).isSetXfrm()) {
                setValue(((CTShapeProperties) xo).getXfrm());
                return true;
            }
            return false;
        }
    };
    fetchShapeProperty(fetcher);
    CTTransform2D xfrm = fetcher.getValue();
    if (!create || xfrm != null) {
        return xfrm;
    } else {
        XmlObject xo = getShapeProperties();
        if (xo instanceof CTShapeProperties) {
            return ((CTShapeProperties) xo).addNewXfrm();
        } else {
            // ... group shapes have their own getXfrm()
            LOG.log(POILogger.WARN, getClass() + " doesn't have xfrm element.");
            return null;
        }
    }
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

PropertyFetcher (org.apache.poi.xslf.model.PropertyFetcher)8 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)5 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)3 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)2 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)2 LineCap (org.apache.poi.sl.usermodel.StrokeStyle.LineCap)1 LineDash (org.apache.poi.sl.usermodel.StrokeStyle.LineDash)1 XSLFEffectProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFEffectProperties)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTEffectStyleItem (org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem)1 CTOuterShadowEffect (org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect)1 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)1 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)1 CTStyleMatrix (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix)1 CTStyleMatrixReference (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference)1 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)1 STCompoundLine (org.openxmlformats.schemas.drawingml.x2006.main.STCompoundLine)1