Search in sources :

Example 11 with CTTextParagraphProperties

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

the class XSLFTextParagraph method setSpaceBefore.

@Override
public void setSpaceBefore(Double spaceBefore) {
    if (spaceBefore == null && !_p.isSetPPr()) {
        return;
    }
    // unset the space before on null input
    if (spaceBefore == null) {
        if (_p.getPPr().isSetSpcBef()) {
            _p.getPPr().unsetSpcBef();
        }
        return;
    }
    CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
    CTTextSpacing spc = CTTextSpacing.Factory.newInstance();
    if (spaceBefore >= 0) {
        spc.addNewSpcPct().setVal((int) (spaceBefore * 1000));
    } else {
        spc.addNewSpcPts().setVal((int) (-spaceBefore * 100));
    }
    pr.setSpcBef(spc);
}
Also used : CTTextSpacing(org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)

Example 12 with CTTextParagraphProperties

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

the class XSLFTextParagraph method fetchParagraphProperty.

private <T> boolean fetchParagraphProperty(ParagraphPropertyFetcher<T> visitor) {
    boolean ok = false;
    XSLFTextShape shape = getParentShape();
    XSLFSheet sheet = shape.getSheet();
    if (_p.isSetPPr())
        ok = visitor.fetch(_p.getPPr());
    if (ok)
        return true;
    ok = shape.fetchShapeProperty(visitor);
    if (ok)
        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();
        CTTextParagraphProperties themeProps = ppt.getDefaultParagraphStyle(getIndentLevel());
        if (themeProps != null)
            ok = visitor.fetch(themeProps);
    }
    if (ok)
        return true;
    // defaults for placeholders are defined in the slide master
    CTTextParagraphProperties defaultProps = getDefaultMasterStyle();
    // TODO: determine master shape
    if (defaultProps != null)
        ok = visitor.fetch(defaultProps);
    if (ok)
        return true;
    return false;
}
Also used : CTPlaceholder(org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)

Example 13 with CTTextParagraphProperties

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

the class XSLFTextParagraph method getTabStop.

public double getTabStop(final int idx) {
    ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getIndentLevel()) {

        public boolean fetch(CTTextParagraphProperties props) {
            if (props.isSetTabLst()) {
                CTTextTabStopList tabStops = props.getTabLst();
                if (idx < tabStops.sizeOfTabArray()) {
                    CTTextTabStop ts = tabStops.getTabArray(idx);
                    double val = Units.toPoints(ts.getPos());
                    setValue(val);
                    return true;
                }
            }
            return false;
        }
    };
    fetchParagraphProperty(fetcher);
    return fetcher.getValue() == null ? 0. : fetcher.getValue();
}
Also used : ParagraphPropertyFetcher(org.apache.poi.xslf.model.ParagraphPropertyFetcher) CTTextTabStop(org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStop) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties) CTTextTabStopList(org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStopList)

Example 14 with CTTextParagraphProperties

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

the class XSLFTextParagraph method setBullet.

/**
     *
     * @param flag whether text in this paragraph has bullets
     */
public void setBullet(boolean flag) {
    if (isBullet() == flag)
        return;
    CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
    if (flag) {
        pr.addNewBuFont().setTypeface("Arial");
        pr.addNewBuChar().setChar("•");
    } else {
        if (pr.isSetBuFont())
            pr.unsetBuFont();
        if (pr.isSetBuChar())
            pr.unsetBuChar();
        if (pr.isSetBuAutoNum())
            pr.unsetBuAutoNum();
        if (pr.isSetBuBlip())
            pr.unsetBuBlip();
        if (pr.isSetBuClr())
            pr.unsetBuClr();
        if (pr.isSetBuClrTx())
            pr.unsetBuClrTx();
        if (pr.isSetBuFont())
            pr.unsetBuFont();
        if (pr.isSetBuFontTx())
            pr.unsetBuFontTx();
        if (pr.isSetBuSzPct())
            pr.unsetBuSzPct();
        if (pr.isSetBuSzPts())
            pr.unsetBuSzPts();
        if (pr.isSetBuSzTx())
            pr.unsetBuSzTx();
        pr.addNewBuNone();
    }
}
Also used : CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)

Example 15 with CTTextParagraphProperties

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

the class XSLFTextParagraph method getLineSpacing.

@Override
public Double getLineSpacing() {
    ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getIndentLevel()) {

        public boolean fetch(CTTextParagraphProperties props) {
            if (props.isSetLnSpc()) {
                CTTextSpacing spc = props.getLnSpc();
                if (spc.isSetSpcPct())
                    setValue(spc.getSpcPct().getVal() * 0.001);
                else if (spc.isSetSpcPts())
                    setValue(-spc.getSpcPts().getVal() * 0.01);
                return true;
            }
            return false;
        }
    };
    fetchParagraphProperty(fetcher);
    Double lnSpc = fetcher.getValue();
    if (lnSpc != null && lnSpc > 0) {
        // check if the percentage value is scaled
        CTTextNormalAutofit normAutofit = getParentShape().getTextBodyPr().getNormAutofit();
        if (normAutofit != null) {
            double scale = 1 - (double) normAutofit.getLnSpcReduction() / 100000;
            lnSpc *= scale;
        }
    }
    return lnSpc;
}
Also used : ParagraphPropertyFetcher(org.apache.poi.xslf.model.ParagraphPropertyFetcher) CTTextSpacing(org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing) CTTextNormalAutofit(org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)

Aggregations

CTTextParagraphProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)22 ParagraphPropertyFetcher (org.apache.poi.xslf.model.ParagraphPropertyFetcher)6 CTTextSpacing (org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing)5 CTTextCharacterProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)4 CTPlaceholder (org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder)3 Color (java.awt.Color)2 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 Test (org.junit.Test)2 CTColor (org.openxmlformats.schemas.drawingml.x2006.main.CTColor)2 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)2 CTTextBulletSizePoint (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint)2 CTTextTabStopList (org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStopList)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 AutoNumberingScheme (org.apache.poi.sl.usermodel.AutoNumberingScheme)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTTextAutonumberBullet (org.openxmlformats.schemas.drawingml.x2006.main.CTTextAutonumberBullet)1 CTTextBulletSizePercent (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePercent)1 CTTextCharBullet (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharBullet)1 CTTextFont (org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont)1