Search in sources :

Example 1 with CTTextSpacing

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

the class XSLFTextParagraph method getSpaceAfter.

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

        public boolean fetch(CTTextParagraphProperties props) {
            if (props.isSetSpcAft()) {
                CTTextSpacing spc = props.getSpcAft();
                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);
    return fetcher.getValue();
}
Also used : ParagraphPropertyFetcher(org.apache.poi.xslf.model.ParagraphPropertyFetcher) CTTextSpacing(org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)

Example 2 with CTTextSpacing

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

the class XSLFTextParagraph method setSpaceAfter.

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

Example 3 with CTTextSpacing

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

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

Example 5 with CTTextSpacing

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

the class XSLFTextParagraph method getSpaceBefore.

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

        public boolean fetch(CTTextParagraphProperties props) {
            if (props.isSetSpcBef()) {
                CTTextSpacing spc = props.getSpcBef();
                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);
    return fetcher.getValue();
}
Also used : ParagraphPropertyFetcher(org.apache.poi.xslf.model.ParagraphPropertyFetcher) CTTextSpacing(org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)

Aggregations

CTTextParagraphProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)5 CTTextSpacing (org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing)5 ParagraphPropertyFetcher (org.apache.poi.xslf.model.ParagraphPropertyFetcher)3 CTTextNormalAutofit (org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit)1