Search in sources :

Example 1 with CTTextCharacterProperties

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

the class XSLFTextParagraph method clearButKeepProperties.

/**
     * Helper method for appending text and keeping paragraph and character properties.
     * The character properties are moved to the end paragraph marker
     */
/* package */
void clearButKeepProperties() {
    CTTextParagraph thisP = getXmlObject();
    for (int i = thisP.sizeOfBrArray(); i > 0; i--) {
        thisP.removeBr(i - 1);
    }
    for (int i = thisP.sizeOfFldArray(); i > 0; i--) {
        thisP.removeFld(i - 1);
    }
    if (!_runs.isEmpty()) {
        int size = _runs.size();
        XSLFTextRun lastRun = _runs.get(size - 1);
        CTTextCharacterProperties cpOther = lastRun.getRPr(false);
        if (cpOther != null) {
            if (thisP.isSetEndParaRPr()) {
                thisP.unsetEndParaRPr();
            }
            CTTextCharacterProperties cp = thisP.addNewEndParaRPr();
            cp.set(cpOther);
        }
        for (int i = size; i > 0; i--) {
            thisP.removeR(i - 1);
        }
        _runs.clear();
    }
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) CTTextBulletSizePoint(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint)

Example 2 with CTTextCharacterProperties

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

the class XSLFTextRun method setFontColor.

@Override
public void setFontColor(PaintStyle color) {
    if (!(color instanceof SolidPaint)) {
        throw new IllegalArgumentException("Currently only SolidPaint is supported!");
    }
    SolidPaint sp = (SolidPaint) color;
    Color c = DrawPaint.applyColorTransform(sp.getSolidColor());
    CTTextCharacterProperties rPr = getRPr(true);
    CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();
    XSLFColor col = new XSLFColor(fill, getParentParagraph().getParentShape().getSheet().getTheme(), fill.getSchemeClr());
    col.setColor(c);
}
Also used : SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) Color(java.awt.Color) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties)

Example 3 with CTTextCharacterProperties

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

the class XSLFTextRun method getFontSize.

@Override
public Double getFontSize() {
    double scale = 1;
    CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTextBodyPr().getNormAutofit();
    if (afit != null)
        scale = (double) afit.getFontScale() / 100000;
    CharacterPropertyFetcher<Double> fetcher = new CharacterPropertyFetcher<Double>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props != null && props.isSetSz()) {
                setValue(props.getSz() * 0.01);
                return true;
            }
            return false;
        }
    };
    fetchCharacterProperty(fetcher);
    return fetcher.getValue() == null ? null : fetcher.getValue() * scale;
}
Also used : CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextNormalAutofit(org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit)

Example 4 with CTTextCharacterProperties

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

the class XSLFTextRun method getFontFamily.

@Override
public String getFontFamily() {
    final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
    CharacterPropertyFetcher<String> visitor = new CharacterPropertyFetcher<String>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props != null) {
                CTTextFont font = props.getLatin();
                if (font != null) {
                    String typeface = font.getTypeface();
                    if ("+mj-lt".equals(typeface)) {
                        typeface = theme.getMajorFont();
                    } else if ("+mn-lt".equals(typeface)) {
                        typeface = theme.getMinorFont();
                    }
                    setValue(typeface);
                    return true;
                }
            }
            return false;
        }
    };
    fetchCharacterProperty(visitor);
    return visitor.getValue();
}
Also used : CTTextFont(org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont) CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)

Example 5 with CTTextCharacterProperties

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

the class XSLFTextRun method getHyperlink.

@Override
public XSLFHyperlink getHyperlink() {
    CTTextCharacterProperties rPr = getRPr(false);
    if (rPr == null) {
        return null;
    }
    CTHyperlink hl = rPr.getHlinkClick();
    if (hl == null) {
        return null;
    }
    return new XSLFHyperlink(hl, _p.getParentShape().getSheet());
}
Also used : CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTHyperlink(org.openxmlformats.schemas.drawingml.x2006.main.CTHyperlink)

Aggregations

CTTextCharacterProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)28 Test (org.junit.Test)6 CTTextFont (org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont)6 CharacterPropertyFetcher (org.apache.poi.xslf.model.CharacterPropertyFetcher)5 CTTextParagraph (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph)5 CTSolidColorFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties)4 CTTextParagraphProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)4 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)3 Color (java.awt.Color)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 CTSRgbColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor)2 CTSchemeColor (org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor)2 CTTextNormalAutofit (org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit)2 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)1 PaintStyle (org.apache.poi.sl.usermodel.PaintStyle)1 XSLFFillProperties (org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)1 XmlObject (org.apache.xmlbeans.XmlObject)1 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)1 CTFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties)1 CTGradientFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties)1