Search in sources :

Example 1 with CTStyleMatrix

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

the class XSLFShape method selectPaint.

protected static PaintStyle selectPaint(CTStyleMatrixReference fillRef, final XSLFTheme theme, boolean isLineStyle, boolean hasPlaceholder) {
    if (fillRef == null)
        return null;
    // The idx attribute refers to the index of a fill style or
    // background fill style within the presentation's style matrix, defined by the fmtScheme element.
    // value of 0 or 1000 indicates no background,
    // values 1-999 refer to the index of a fill style within the fillStyleLst element
    // values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
    int idx = (int) fillRef.getIdx();
    CTStyleMatrix matrix = theme.getXmlObject().getThemeElements().getFmtScheme();
    final XmlObject styleLst;
    int childIdx;
    if (idx >= 1 && idx <= 999) {
        childIdx = idx - 1;
        styleLst = (isLineStyle) ? matrix.getLnStyleLst() : matrix.getFillStyleLst();
    } else if (idx >= 1001) {
        childIdx = idx - 1001;
        styleLst = matrix.getBgFillStyleLst();
    } else {
        return null;
    }
    XmlCursor cur = styleLst.newCursor();
    XSLFFillProperties fp = null;
    if (cur.toChild(childIdx)) {
        fp = XSLFPropertiesDelegate.getFillDelegate(cur.getObject());
    }
    cur.dispose();
    CTSchemeColor phClr = fillRef.getSchemeClr();
    PaintStyle res = selectPaint(fp, phClr, theme.getPackagePart(), theme, hasPlaceholder);
    // see http://officeopenxml.com/prSlide-color.php - "Color Placeholders within Themes"
    if (res != null || hasPlaceholder) {
        return res;
    }
    XSLFColor col = new XSLFColor(fillRef, theme, phClr);
    return DrawPaint.createSolidPaint(col.getColorStyle());
}
Also used : CTStyleMatrix(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) XmlObject(org.apache.xmlbeans.XmlObject) DrawPaint(org.apache.poi.sl.draw.DrawPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 2 with CTStyleMatrix

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

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

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

the class TestXSLFSimpleShape method testShadowEffects.

@SuppressWarnings("unused")
@Test
public void testShadowEffects() throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlide slide = ppt.createSlide();
    CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme();
    CTEffectStyleList lst = styleMatrix.getEffectStyleLst();
    assertNotNull(lst);
    for (CTEffectStyleItem ef : lst.getEffectStyleArray()) {
        CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw();
    }
    ppt.close();
}
Also used : CTStyleMatrix(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix) CTEffectStyleList(org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleList) CTEffectStyleItem(org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem) CTOuterShadowEffect(org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect) Test(org.junit.Test)

Aggregations

CTStyleMatrix (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix)4 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 CTEffectStyleItem (org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem)2 CTOuterShadowEffect (org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect)2 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)2 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)1 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)1 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)1 PropertyFetcher (org.apache.poi.xslf.model.PropertyFetcher)1 XSLFEffectProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFEffectProperties)1 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlObject (org.apache.xmlbeans.XmlObject)1 Test (org.junit.Test)1 CTBaseStyles (org.openxmlformats.schemas.drawingml.x2006.main.CTBaseStyles)1 CTEffectStyleList (org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleList)1 CTLineStyleList (org.openxmlformats.schemas.drawingml.x2006.main.CTLineStyleList)1 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)1 CTStyleMatrixReference (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference)1