Search in sources :

Example 1 with CTStyleMatrixReference

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

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

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

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

Example 5 with CTStyleMatrixReference

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

the class XSSFConnector method prototype.

/**
     * Initialize default structure of a new auto-shape
     *
     */
protected static CTConnector prototype() {
    if (prototype == null) {
        CTConnector shape = CTConnector.Factory.newInstance();
        CTConnectorNonVisual nv = shape.addNewNvCxnSpPr();
        CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
        nvp.setId(1);
        nvp.setName("Shape 1");
        nv.addNewCNvCxnSpPr();
        CTShapeProperties sp = shape.addNewSpPr();
        CTTransform2D t2d = sp.addNewXfrm();
        CTPositiveSize2D p1 = t2d.addNewExt();
        p1.setCx(0);
        p1.setCy(0);
        CTPoint2D p2 = t2d.addNewOff();
        p2.setX(0);
        p2.setY(0);
        CTPresetGeometry2D geom = sp.addNewPrstGeom();
        geom.setPrst(STShapeType.LINE);
        geom.addNewAvLst();
        CTShapeStyle style = shape.addNewStyle();
        CTSchemeColor scheme = style.addNewLnRef().addNewSchemeClr();
        scheme.setVal(STSchemeColorVal.ACCENT_1);
        style.getLnRef().setIdx(1);
        CTStyleMatrixReference fillref = style.addNewFillRef();
        fillref.setIdx(0);
        fillref.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
        CTStyleMatrixReference effectRef = style.addNewEffectRef();
        effectRef.setIdx(0);
        effectRef.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
        CTFontReference fontRef = style.addNewFontRef();
        fontRef.setIdx(STFontCollectionIndex.MINOR);
        fontRef.addNewSchemeClr().setVal(STSchemeColorVal.TX_1);
        prototype = shape;
    }
    return prototype;
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) CTConnector(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTPresetGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D) CTFontReference(org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference) CTConnectorNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnectorNonVisual)

Aggregations

CTStyleMatrixReference (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference)4 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)3 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)3 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 XmlObject (org.apache.xmlbeans.XmlObject)2 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)2 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)2 CTStyleMatrix (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix)2 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)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 XmlCursor (org.apache.xmlbeans.XmlCursor)1 CTBaseStyles (org.openxmlformats.schemas.drawingml.x2006.main.CTBaseStyles)1 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)1 CTFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties)1 CTFontReference (org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference)1