Search in sources :

Example 11 with CTPlaceholder

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder in project poi by apache.

the class XSLFTextRun method fetchCharacterProperty.

private boolean fetchCharacterProperty(CharacterPropertyFetcher<?> fetcher) {
    XSLFTextShape shape = _p.getParentShape();
    XSLFSheet sheet = shape.getSheet();
    CTTextCharacterProperties rPr = getRPr(false);
    if (rPr != null && fetcher.fetch(rPr)) {
        return true;
    }
    if (shape.fetchShapeProperty(fetcher)) {
        return true;
    }
    CTPlaceholder ph = shape.getCTPlaceholder();
    if (ph == null) {
        // if it is a plain text box then take defaults from presentation.xml
        @SuppressWarnings("resource") XMLSlideShow ppt = sheet.getSlideShow();
        // TODO: determine master shape
        CTTextParagraphProperties themeProps = ppt.getDefaultParagraphStyle(_p.getIndentLevel());
        if (themeProps != null && fetcher.fetch(themeProps)) {
            return true;
        }
    }
    // TODO: determine master shape
    CTTextParagraphProperties defaultProps = _p.getDefaultMasterStyle();
    if (defaultProps != null && fetcher.fetch(defaultProps)) {
        return true;
    }
    return false;
}
Also used : CTPlaceholder(org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)

Example 12 with CTPlaceholder

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder in project poi by apache.

the class TestXSLFTextShape method verifySlide3.

void verifySlide3(XSLFSlide slide) {
    XSLFSlideLayout layout = slide.getSlideLayout();
    List<XSLFShape> shapes = slide.getShapes();
    assertEquals("Section Header", layout.getName());
    XSLFTextShape shape1 = (XSLFTextShape) shapes.get(0);
    CTPlaceholder ph1 = shape1.getCTPlaceholder();
    assertEquals(STPlaceholderType.TITLE, ph1.getType());
    // anchor is not defined in the shape
    assertNull(getSpPr(shape1).getXfrm());
    XSLFTextShape masterShape1 = (XSLFTextShape) layout.getPlaceholder(ph1);
    assertNotNull(getSpPr(masterShape1).getXfrm());
    assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
    CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
    // none of the following properties are set in the shapes and fetched from the master shape
    assertTrue(!bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() && !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() && !bodyPr1.isSetAnchor());
    // 0.1"
    assertEquals(7.2, shape1.getLeftInset(), 0);
    // 0.1"
    assertEquals(7.2, shape1.getRightInset(), 0);
    // 0.05"
    assertEquals(3.6, shape1.getTopInset(), 0);
    // 0.05"
    assertEquals(3.6, shape1.getBottomInset(), 0);
    assertEquals(VerticalAlignment.TOP, shape1.getVerticalAlignment());
    // now check text properties
    assertEquals("Section Title", shape1.getText());
    XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
    assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
    assertEquals("Calibri", r1.getFontFamily());
    assertEquals(40.0, r1.getFontSize(), 0);
    assertTrue(sameColor(Color.black, r1.getFontColor()));
    assertTrue(r1.isBold());
    assertFalse(r1.isItalic());
    assertFalse(r1.isUnderlined());
    XSLFTextShape shape2 = (XSLFTextShape) shapes.get(1);
    CTPlaceholder ph2 = shape2.getCTPlaceholder();
    assertEquals(STPlaceholderType.BODY, ph2.getType());
    // anchor is not defined in the shape
    assertNull(getSpPr(shape2).getXfrm());
    XSLFTextShape masterShape2 = (XSLFTextShape) layout.getPlaceholder(ph2);
    assertNotNull(getSpPr(masterShape2).getXfrm());
    assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
    CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
    // none of the following properties are set in the shapes and fetched from the master shape
    assertTrue(!bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() && !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() && !bodyPr2.isSetAnchor());
    // 0.1"
    assertEquals(7.2, shape2.getLeftInset(), 0);
    // 0.1"
    assertEquals(7.2, shape2.getRightInset(), 0);
    // 0.05"
    assertEquals(3.6, shape2.getTopInset(), 0);
    // 0.05"
    assertEquals(3.6, shape2.getBottomInset(), 0);
    assertEquals(VerticalAlignment.BOTTOM, shape2.getVerticalAlignment());
    assertEquals("Section Header", shape2.getText());
    XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
    assertEquals(TextAlign.LEFT, r2.getParentParagraph().getTextAlign());
    assertEquals("Calibri", r2.getFontFamily());
    assertEquals(20.0, r2.getFontSize(), 0);
// TODO fix calculation of tint
//assertEquals(new Color(137, 137, 137), r2.getFontColor());
}
Also used : CTPlaceholder(org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder) CTTextBodyProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties)

Example 13 with CTPlaceholder

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder in project poi by apache.

the class TestXSLFTextShape method verifySlide2.

void verifySlide2(XSLFSlide slide) {
    XSLFSlideLayout layout = slide.getSlideLayout();
    List<XSLFShape> shapes = slide.getShapes();
    assertEquals("Title and Content", layout.getName());
    XSLFTextShape shape1 = (XSLFTextShape) shapes.get(0);
    CTPlaceholder ph1 = shape1.getCTPlaceholder();
    assertEquals(STPlaceholderType.TITLE, ph1.getType());
    // anchor is not defined in the shape
    assertNull(getSpPr(shape1).getXfrm());
    XSLFTextShape masterShape1 = (XSLFTextShape) layout.getPlaceholder(ph1);
    // layout does not have anchor info either, it is in the slide master
    assertNull(getSpPr(masterShape1).getXfrm());
    masterShape1 = (XSLFTextShape) layout.getSlideMaster().getPlaceholder(ph1);
    assertNotNull(getSpPr(masterShape1).getXfrm());
    assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
    CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
    // none of the following properties are set in the shapes and fetched from the master shape
    assertTrue(!bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() && !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() && !bodyPr1.isSetAnchor());
    // 0.1"
    assertEquals(7.2, shape1.getLeftInset(), 0);
    // 0.1"
    assertEquals(7.2, shape1.getRightInset(), 0);
    // 0.05"
    assertEquals(3.6, shape1.getTopInset(), 0);
    // 0.05"
    assertEquals(3.6, shape1.getBottomInset(), 0);
    assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
    // now check text properties
    assertEquals("Title", shape1.getText());
    XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
    assertEquals("Calibri", r1.getFontFamily());
    assertEquals(44.0, r1.getFontSize(), 0);
    assertTrue(sameColor(Color.black, r1.getFontColor()));
    XSLFTextShape shape2 = (XSLFTextShape) shapes.get(1);
    CTPlaceholder ph2 = shape2.getCTPlaceholder();
    // <p:ph idx="1"/>
    assertFalse(ph2.isSetType());
    assertTrue(ph2.isSetIdx());
    assertEquals(1, ph2.getIdx());
    // anchor is not defined in the shape
    assertNull(getSpPr(shape2).getXfrm());
    XSLFTextShape masterShape2 = (XSLFTextShape) layout.getPlaceholder(ph2);
    // anchor of the body text is missing in the slide layout, llokup in the slide master
    assertNull(getSpPr(masterShape2).getXfrm());
    masterShape2 = (XSLFTextShape) layout.getSlideMaster().getPlaceholder(ph2);
    assertNotNull(getSpPr(masterShape2).getXfrm());
    assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
    CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
    // none of the following properties are set in the shapes and fetched from the master shape
    assertTrue(!bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() && !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() && !bodyPr2.isSetAnchor());
    // 0.1"
    assertEquals(7.2, shape2.getLeftInset(), 0);
    // 0.1"
    assertEquals(7.2, shape2.getRightInset(), 0);
    // 0.05"
    assertEquals(3.6, shape2.getTopInset(), 0);
    // 0.05"
    assertEquals(3.6, shape2.getBottomInset(), 0);
    assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
    XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
    assertEquals(0, pr1.getParentParagraph().getIndentLevel());
    assertEquals("Content", pr1.getRawText());
    assertEquals("Calibri", pr1.getFontFamily());
    assertEquals(32.0, pr1.getFontSize(), 0);
    assertEquals(27.0, pr1.getParentParagraph().getLeftMargin(), 0);
    assertEquals("•", pr1.getParentParagraph().getBulletCharacter());
    assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
    XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
    assertEquals(1, pr2.getParentParagraph().getIndentLevel());
    assertEquals("Level 2", pr2.getRawText());
    assertEquals("Calibri", pr2.getFontFamily());
    assertEquals(28.0, pr2.getFontSize(), 0);
    assertEquals(58.5, pr2.getParentParagraph().getLeftMargin(), 0);
    assertEquals("–", pr2.getParentParagraph().getBulletCharacter());
    assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
    XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
    assertEquals(2, pr3.getParentParagraph().getIndentLevel());
    assertEquals("Level 3", pr3.getRawText());
    assertEquals("Calibri", pr3.getFontFamily());
    assertEquals(24.0, pr3.getFontSize(), 0);
    assertEquals(90.0, pr3.getParentParagraph().getLeftMargin(), 0);
    assertEquals("•", pr3.getParentParagraph().getBulletCharacter());
    assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
    XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
    assertEquals(3, pr4.getParentParagraph().getIndentLevel());
    assertEquals("Level 4", pr4.getRawText());
    assertEquals("Calibri", pr4.getFontFamily());
    assertEquals(20.0, pr4.getFontSize(), 0);
    assertEquals(126.0, pr4.getParentParagraph().getLeftMargin(), 0);
    assertEquals("–", pr4.getParentParagraph().getBulletCharacter());
    assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
    XSLFTextRun pr5 = shape2.getTextParagraphs().get(4).getTextRuns().get(0);
    assertEquals(4, pr5.getParentParagraph().getIndentLevel());
    assertEquals("Level 5", pr5.getRawText());
    assertEquals("Calibri", pr5.getFontFamily());
    assertEquals(20.0, pr5.getFontSize(), 0);
    assertEquals(162.0, pr5.getParentParagraph().getLeftMargin(), 0);
    assertEquals("»", pr5.getParentParagraph().getBulletCharacter());
    assertEquals("Arial", pr5.getParentParagraph().getBulletFont());
}
Also used : CTPlaceholder(org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder) CTTextBodyProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties)

Example 14 with CTPlaceholder

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder in project poi by apache.

the class XSLFShape method fetchShapeProperty.

/**
     * Walk up the inheritance tree and fetch shape properties.<p>
     *
     * The following order of inheritance is assumed:<p>
     * <ol>
     * <li>slide
     * <li>slideLayout
     * <li>slideMaster
     * </ol>
     * 
     * Currently themes and their defaults aren't correctly handled
     *
     * @param visitor the object that collects the desired property
     * @return true if the property was fetched
     */
protected boolean fetchShapeProperty(PropertyFetcher<?> visitor) {
    // try shape properties in slide
    if (visitor.fetch(this)) {
        return true;
    }
    CTPlaceholder ph = getCTPlaceholder();
    if (ph == null) {
        return false;
    }
    MasterSheet<XSLFShape, XSLFTextParagraph> sm = getSheet().getMasterSheet();
    // try slide layout
    if (sm instanceof XSLFSlideLayout) {
        XSLFSlideLayout slideLayout = (XSLFSlideLayout) sm;
        XSLFSimpleShape placeholderShape = slideLayout.getPlaceholder(ph);
        if (placeholderShape != null && visitor.fetch(placeholderShape)) {
            return true;
        }
        sm = slideLayout.getMasterSheet();
    }
    // try slide master
    if (sm instanceof XSLFSlideMaster) {
        XSLFSlideMaster master = (XSLFSlideMaster) sm;
        int textType = getPlaceholderType(ph);
        XSLFSimpleShape masterShape = master.getPlaceholderByType(textType);
        if (masterShape != null && visitor.fetch(masterShape)) {
            return true;
        }
    }
    return false;
}
Also used : CTPlaceholder(org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder) DrawPaint(org.apache.poi.sl.draw.DrawPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)

Example 15 with CTPlaceholder

use of org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder in project poi by apache.

the class XSLFSheet method initPlaceholders.

void initPlaceholders() {
    if (_placeholders == null) {
        _placeholders = new ArrayList<XSLFTextShape>();
        _placeholderByIdMap = new HashMap<Integer, XSLFSimpleShape>();
        _placeholderByTypeMap = new HashMap<Integer, XSLFSimpleShape>();
        for (XSLFShape sh : getShapes()) {
            if (sh instanceof XSLFTextShape) {
                XSLFTextShape sShape = (XSLFTextShape) sh;
                CTPlaceholder ph = sShape.getCTPlaceholder();
                if (ph != null) {
                    _placeholders.add(sShape);
                    if (ph.isSetIdx()) {
                        int idx = (int) ph.getIdx();
                        _placeholderByIdMap.put(idx, sShape);
                    }
                    if (ph.isSetType()) {
                        _placeholderByTypeMap.put(ph.getType().intValue(), sShape);
                    }
                }
            }
        }
    }
}
Also used : CTPlaceholder(org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder)

Aggregations

CTPlaceholder (org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder)15 CTTextBodyProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties)6 DrawPaint (org.apache.poi.sl.draw.DrawPaint)3 CTTextParagraphProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)3 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 CTTextBulletSizePoint (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint)2 GradientPaint (org.apache.poi.sl.usermodel.PaintStyle.GradientPaint)1 TexturePaint (org.apache.poi.sl.usermodel.PaintStyle.TexturePaint)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTTextCharacterProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)1