Search in sources :

Example 1 with CTShapeStyle

use of org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle in project poi by apache.

the class XSLFSimpleShape method getDefaultLineProperties.

/**
     * Get default line properties defined in the theme (if any).
     * Used internally to resolve shape properties.
     *
     * @return line properties from the theme of null
     */
CTLineProperties getDefaultLineProperties() {
    CTShapeStyle style = getSpStyle();
    if (style == null) {
        return null;
    }
    CTStyleMatrixReference lnRef = style.getLnRef();
    if (lnRef == null) {
        return null;
    }
    // 1-based index of a line style within the style matrix
    int idx = (int) lnRef.getIdx();
    XSLFTheme theme = getSheet().getTheme();
    if (theme == null) {
        return null;
    }
    CTBaseStyles styles = theme.getXmlObject().getThemeElements();
    if (styles == null) {
        return null;
    }
    CTStyleMatrix styleMatrix = styles.getFmtScheme();
    if (styleMatrix == null) {
        return null;
    }
    CTLineStyleList lineStyles = styleMatrix.getLnStyleLst();
    if (lineStyles == null || lineStyles.sizeOfLnArray() < idx) {
        return null;
    }
    return lineStyles.getLnArray(idx - 1);
}
Also used : CTStyleMatrix(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix) CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) CTBaseStyles(org.openxmlformats.schemas.drawingml.x2006.main.CTBaseStyles) CTLineStyleList(org.openxmlformats.schemas.drawingml.x2006.main.CTLineStyleList) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)

Example 2 with CTShapeStyle

use of org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle 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 3 with CTShapeStyle

use of org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle 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 4 with CTShapeStyle

use of org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle in project poi by apache.

the class XSLFTextRun method getFontColor.

@Override
public PaintStyle getFontColor() {
    final boolean hasPlaceholder = getParentParagraph().getParentShape().getPlaceholder() != null;
    CharacterPropertyFetcher<PaintStyle> fetcher = new CharacterPropertyFetcher<PaintStyle>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props == null) {
                return false;
            }
            XSLFShape shape = _p.getParentShape();
            CTShapeStyle style = shape.getSpStyle();
            CTSchemeColor phClr = null;
            if (style != null && style.getFontRef() != null) {
                phClr = style.getFontRef().getSchemeClr();
            }
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
            XSLFSheet sheet = shape.getSheet();
            PackagePart pp = sheet.getPackagePart();
            XSLFTheme theme = sheet.getTheme();
            PaintStyle ps = XSLFShape.selectPaint(fp, phClr, pp, theme, hasPlaceholder);
            if (ps != null) {
                setValue(ps);
                return true;
            }
            return false;
        }
    };
    fetchCharacterProperty(fetcher);
    return fetcher.getValue();
}
Also used : CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 5 with CTShapeStyle

use of org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle in project poi by apache.

the class XSLFShape method getFillPaint.

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

        public boolean fetch(XSLFShape shape) {
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(shape.getShapeProperties());
            if (fp == null) {
                return false;
            }
            if (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.getFillRef());
                paint = selectPaint(fp, null, pp, theme, hasPlaceholder);
            }
            if (paint != null) {
                setValue(paint);
                return true;
            }
            return false;
        }
    };
    fetchShapeProperty(fetcher);
    return fetcher.getValue();
}
Also used : CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Aggregations

CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)6 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)3 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)3 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)3 PropertyFetcher (org.apache.poi.xslf.model.PropertyFetcher)3 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)3 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)3 CTStyleMatrixReference (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference)3 CTStyleMatrix (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix)2 CharacterPropertyFetcher (org.apache.poi.xslf.model.CharacterPropertyFetcher)1 XSLFEffectProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFEffectProperties)1 CTBaseStyles (org.openxmlformats.schemas.drawingml.x2006.main.CTBaseStyles)1 CTEffectStyleItem (org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem)1 CTFontReference (org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference)1 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)1 CTLineStyleList (org.openxmlformats.schemas.drawingml.x2006.main.CTLineStyleList)1 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)1 CTOuterShadowEffect (org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect)1 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)1