Search in sources :

Example 1 with PaintStyle

use of org.apache.poi.sl.usermodel.PaintStyle 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 PaintStyle

use of org.apache.poi.sl.usermodel.PaintStyle 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 PaintStyle

use of org.apache.poi.sl.usermodel.PaintStyle in project poi by apache.

the class XSLFTextParagraph method copy.

void copy(XSLFTextParagraph other) {
    if (other == this)
        return;
    CTTextParagraph thisP = getXmlObject();
    CTTextParagraph otherP = other.getXmlObject();
    if (thisP.isSetPPr())
        thisP.unsetPPr();
    if (thisP.isSetEndParaRPr())
        thisP.unsetEndParaRPr();
    _runs.clear();
    for (int i = thisP.sizeOfBrArray(); i > 0; i--) {
        thisP.removeBr(i - 1);
    }
    for (int i = thisP.sizeOfRArray(); i > 0; i--) {
        thisP.removeR(i - 1);
    }
    for (int i = thisP.sizeOfFldArray(); i > 0; i--) {
        thisP.removeFld(i - 1);
    }
    XmlCursor thisC = thisP.newCursor();
    thisC.toEndToken();
    XmlCursor otherC = otherP.newCursor();
    otherC.copyXmlContents(thisC);
    otherC.dispose();
    thisC.dispose();
    List<XSLFTextRun> otherRs = other.getTextRuns();
    int i = 0;
    for (CTRegularTextRun rtr : thisP.getRArray()) {
        XSLFTextRun run = newTextRun(rtr);
        run.copy(otherRs.get(i++));
        _runs.add(run);
    }
    // set properties again, in case we are based on a different
    // template
    TextAlign srcAlign = other.getTextAlign();
    if (srcAlign != getTextAlign()) {
        setTextAlign(srcAlign);
    }
    boolean isBullet = other.isBullet();
    if (isBullet != isBullet()) {
        setBullet(isBullet);
        if (isBullet) {
            String buFont = other.getBulletFont();
            if (buFont != null && !buFont.equals(getBulletFont())) {
                setBulletFont(buFont);
            }
            String buChar = other.getBulletCharacter();
            if (buChar != null && !buChar.equals(getBulletCharacter())) {
                setBulletCharacter(buChar);
            }
            PaintStyle buColor = other.getBulletFontColor();
            if (buColor != null && !buColor.equals(getBulletFontColor())) {
                setBulletFontColor(buColor);
            }
            Double buSize = other.getBulletFontSize();
            if (!doubleEquals(buSize, getBulletFontSize())) {
                setBulletFontSize(buSize);
            }
        }
    }
    Double leftMargin = other.getLeftMargin();
    if (!doubleEquals(leftMargin, getLeftMargin())) {
        setLeftMargin(leftMargin);
    }
    Double indent = other.getIndent();
    if (!doubleEquals(indent, getIndent())) {
        setIndent(indent);
    }
    Double spaceAfter = other.getSpaceAfter();
    if (!doubleEquals(spaceAfter, getSpaceAfter())) {
        setSpaceAfter(spaceAfter);
    }
    Double spaceBefore = other.getSpaceBefore();
    if (!doubleEquals(spaceBefore, getSpaceBefore())) {
        setSpaceBefore(spaceBefore);
    }
    Double lineSpacing = other.getLineSpacing();
    if (!doubleEquals(lineSpacing, getLineSpacing())) {
        setLineSpacing(lineSpacing);
    }
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) CTTextBulletSizePoint(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint) XmlCursor(org.apache.xmlbeans.XmlCursor) CTRegularTextRun(org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)

Example 4 with PaintStyle

use of org.apache.poi.sl.usermodel.PaintStyle in project poi by apache.

the class XSLFTextRun method copy.

void copy(XSLFTextRun r) {
    String srcFontFamily = r.getFontFamily();
    if (srcFontFamily != null && !srcFontFamily.equals(getFontFamily())) {
        setFontFamily(srcFontFamily);
    }
    PaintStyle srcFontColor = r.getFontColor();
    if (srcFontColor != null && !srcFontColor.equals(getFontColor())) {
        setFontColor(srcFontColor);
    }
    double srcFontSize = r.getFontSize();
    if (srcFontSize != getFontSize()) {
        setFontSize(srcFontSize);
    }
    boolean bold = r.isBold();
    if (bold != isBold())
        setBold(bold);
    boolean italic = r.isItalic();
    if (italic != isItalic())
        setItalic(italic);
    boolean underline = r.isUnderlined();
    if (underline != isUnderlined())
        setUnderlined(underline);
    boolean strike = r.isStrikethrough();
    if (strike != isStrikethrough())
        setStrikethrough(strike);
}
Also used : PaintStyle(org.apache.poi.sl.usermodel.PaintStyle)

Example 5 with PaintStyle

use of org.apache.poi.sl.usermodel.PaintStyle in project poi by apache.

the class TestXSLFBugs method bug55714.

@Test
public void bug55714() throws IOException {
    XMLSlideShow srcPptx = XSLFTestDataSamples.openSampleDocument("pptx2svg.pptx");
    XMLSlideShow newPptx = new XMLSlideShow();
    XSLFSlide srcSlide = srcPptx.getSlides().get(0);
    XSLFSlide newSlide = newPptx.createSlide();
    XSLFSlideLayout srcSlideLayout = srcSlide.getSlideLayout();
    XSLFSlideLayout newSlideLayout = newSlide.getSlideLayout();
    newSlideLayout.importContent(srcSlideLayout);
    XSLFSlideMaster srcSlideMaster = srcSlide.getSlideMaster();
    XSLFSlideMaster newSlideMaster = newSlide.getSlideMaster();
    newSlideMaster.importContent(srcSlideMaster);
    newSlide.importContent(srcSlide);
    XMLSlideShow rwPptx = XSLFTestDataSamples.writeOutAndReadBack(newPptx);
    PaintStyle ps = rwPptx.getSlides().get(0).getBackground().getFillStyle().getPaint();
    assertTrue(ps instanceof TexturePaint);
    rwPptx.close();
    newPptx.close();
    srcPptx.close();
}
Also used : TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) Test(org.junit.Test)

Aggregations

PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)20 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)6 Color (java.awt.Color)5 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)5 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)5 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)4 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)3 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 Test (org.junit.Test)3 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)3 CTShapeStyle (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle)3 Paint (java.awt.Paint)2 AttributedString (java.text.AttributedString)2 TestCommonSL.sameColor (org.apache.poi.sl.TestCommonSL.sameColor)2 TextRun (org.apache.poi.sl.usermodel.TextRun)2 PropertyFetcher (org.apache.poi.xslf.model.PropertyFetcher)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 XmlObject (org.apache.xmlbeans.XmlObject)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Font (java.awt.Font)1