Search in sources :

Example 1 with XSLFFillProperties

use of org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties 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 XSLFFillProperties

use of org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties in project poi by apache.

the class XSLFTableCell method getFillPaint.

@SuppressWarnings("resource")
@Override
public PaintStyle getFillPaint() {
    XSLFSheet sheet = getSheet();
    XSLFTheme theme = sheet.getTheme();
    final boolean hasPlaceholder = getPlaceholder() != null;
    XmlObject props = getCellProperties(false);
    XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
    if (fp != null) {
        PaintStyle paint = selectPaint(fp, null, sheet.getPackagePart(), theme, hasPlaceholder);
        if (paint != null) {
            return paint;
        }
    }
    CTTablePartStyle tps = getTablePartStyle(null);
    if (tps == null || !tps.isSetTcStyle()) {
        tps = getTablePartStyle(TablePartStyle.wholeTbl);
        if (tps == null || !tps.isSetTcStyle()) {
            return null;
        }
    }
    XMLSlideShow slideShow = sheet.getSlideShow();
    CTTableStyleCellStyle tcStyle = tps.getTcStyle();
    if (tcStyle.isSetFill()) {
        props = tcStyle.getFill();
    } else if (tcStyle.isSetFillRef()) {
        props = tcStyle.getFillRef();
    } else {
        return null;
    }
    fp = XSLFPropertiesDelegate.getFillDelegate(props);
    if (fp != null) {
        PaintStyle paint = XSLFShape.selectPaint(fp, null, slideShow.getPackagePart(), theme, hasPlaceholder);
        if (paint != null) {
            return paint;
        }
    }
    return null;
}
Also used : CTTableStyleCellStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyleCellStyle) CTTablePartStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTTablePartStyle) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) XmlObject(org.apache.xmlbeans.XmlObject) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 3 with XSLFFillProperties

use of org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties in project poi by apache.

the class XSLFSimpleShape method setFillColor.

@Override
public void setFillColor(Color color) {
    XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(getShapeProperties());
    if (fp == null) {
        return;
    }
    if (color == null) {
        if (fp.isSetSolidFill()) {
            fp.unsetSolidFill();
        }
        if (fp.isSetGradFill()) {
            fp.unsetGradFill();
        }
        if (fp.isSetPattFill()) {
            fp.unsetGradFill();
        }
        if (fp.isSetBlipFill()) {
            fp.unsetBlipFill();
        }
        if (!fp.isSetNoFill()) {
            fp.addNewNoFill();
        }
    } else {
        if (fp.isSetNoFill()) {
            fp.unsetNoFill();
        }
        CTSolidColorFillProperties fill = fp.isSetSolidFill() ? fp.getSolidFill() : fp.addNewSolidFill();
        XSLFColor col = new XSLFColor(fill, getSheet().getTheme(), fill.getSchemeClr());
        col.setColor(color);
    }
}
Also used : CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 4 with XSLFFillProperties

use of org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties 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 5 with XSLFFillProperties

use of org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties in project poi by apache.

the class XSLFSimpleShape method copy.

@Override
void copy(XSLFShape sh) {
    super.copy(sh);
    XSLFSimpleShape s = (XSLFSimpleShape) sh;
    Color srsSolidFill = s.getFillColor();
    Color tgtSoliFill = getFillColor();
    if (srsSolidFill != null && !srsSolidFill.equals(tgtSoliFill)) {
        setFillColor(srsSolidFill);
    }
    XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(getShapeProperties());
    if (fp != null && fp.isSetBlipFill()) {
        CTBlip blip = fp.getBlipFill().getBlip();
        String blipId = blip.getEmbed();
        String relId = getSheet().importBlip(blipId, s.getSheet().getPackagePart());
        blip.setEmbed(relId);
    }
    Color srcLineColor = s.getLineColor();
    Color tgtLineColor = getLineColor();
    if (srcLineColor != null && !srcLineColor.equals(tgtLineColor)) {
        setLineColor(srcLineColor);
    }
    double srcLineWidth = s.getLineWidth();
    double tgtLineWidth = getLineWidth();
    if (srcLineWidth != tgtLineWidth) {
        setLineWidth(srcLineWidth);
    }
    LineDash srcLineDash = s.getLineDash();
    LineDash tgtLineDash = getLineDash();
    if (srcLineDash != null && srcLineDash != tgtLineDash) {
        setLineDash(srcLineDash);
    }
    LineCap srcLineCap = s.getLineCap();
    LineCap tgtLineCap = getLineCap();
    if (srcLineCap != null && srcLineCap != tgtLineCap) {
        setLineCap(srcLineCap);
    }
}
Also used : CTBlip(org.openxmlformats.schemas.drawingml.x2006.main.CTBlip) Color(java.awt.Color) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) LineDash(org.apache.poi.sl.usermodel.StrokeStyle.LineDash) LineCap(org.apache.poi.sl.usermodel.StrokeStyle.LineCap) STLineCap(org.openxmlformats.schemas.drawingml.x2006.main.STLineCap) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Aggregations

XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)7 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)5 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)4 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)3 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)3 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 PropertyFetcher (org.apache.poi.xslf.model.PropertyFetcher)2 XmlObject (org.apache.xmlbeans.XmlObject)2 Color (java.awt.Color)1 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)1 LineCap (org.apache.poi.sl.usermodel.StrokeStyle.LineCap)1 LineDash (org.apache.poi.sl.usermodel.StrokeStyle.LineDash)1 CharacterPropertyFetcher (org.apache.poi.xslf.model.CharacterPropertyFetcher)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 CTBlip (org.openxmlformats.schemas.drawingml.x2006.main.CTBlip)1 CTLineProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties)1 CTSolidColorFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties)1 CTStyleMatrix (org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix)1