Search in sources :

Example 21 with CTTextCharacterProperties

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

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

the class XSLFTextShape method appendText.

@Override
public XSLFTextRun appendText(String text, boolean newParagraph) {
    if (text == null)
        return null;
    // copy properties from last paragraph / textrun or paragraph end marker
    CTTextParagraphProperties otherPPr = null;
    CTTextCharacterProperties otherRPr = null;
    boolean firstPara;
    XSLFTextParagraph para;
    if (_paragraphs.isEmpty()) {
        firstPara = false;
        para = null;
    } else {
        firstPara = !newParagraph;
        para = _paragraphs.get(_paragraphs.size() - 1);
        CTTextParagraph ctp = para.getXmlObject();
        otherPPr = ctp.getPPr();
        List<XSLFTextRun> runs = para.getTextRuns();
        if (!runs.isEmpty()) {
            XSLFTextRun r0 = runs.get(runs.size() - 1);
            otherRPr = r0.getRPr(false);
            if (otherRPr == null) {
                otherRPr = ctp.getEndParaRPr();
            }
        }
    // don't copy endParaRPr to the run in case there aren't any other runs
    // this is the case when setText() was called initially
    // otherwise the master style will be overridden/ignored
    }
    XSLFTextRun run = null;
    for (String lineTxt : text.split("\\r\\n?|\\n")) {
        if (!firstPara) {
            if (para != null) {
                CTTextParagraph ctp = para.getXmlObject();
                CTTextCharacterProperties unexpectedRPr = ctp.getEndParaRPr();
                if (unexpectedRPr != null && unexpectedRPr != otherRPr) {
                    ctp.unsetEndParaRPr();
                }
            }
            para = addNewTextParagraph();
            if (otherPPr != null) {
                para.getXmlObject().setPPr(otherPPr);
            }
        }
        boolean firstRun = true;
        for (String runText : lineTxt.split("[]")) {
            if (!firstRun) {
                para.addLineBreak();
            }
            run = para.addNewTextRun();
            run.setText(runText);
            if (otherRPr != null) {
                run.getRPr(true).set(otherRPr);
            }
            firstRun = false;
        }
        firstPara = false;
    }
    assert (run != null);
    return run;
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties)

Example 23 with CTTextCharacterProperties

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

the class XSSFTextRun method getFontSize.

/**
     * @return font size in points or -1 if font size is not set.
     */
public double getFontSize() {
    double scale = 1;
    // default font size
    double size = XSSFFont.DEFAULT_FONT_SIZE;
    CTTextNormalAutofit afit = getParentParagraph().getParentShape().getTxBody().getBodyPr().getNormAutofit();
    if (afit != null)
        scale = (double) afit.getFontScale() / 100000;
    CTTextCharacterProperties rPr = getRPr();
    if (rPr.isSetSz()) {
        size = rPr.getSz() * 0.01;
    }
    return size * scale;
}
Also used : CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextNormalAutofit(org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit)

Example 24 with CTTextCharacterProperties

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

the class XSSFTextRun method setFontFamily.

public void setFontFamily(String typeface, byte charset, byte pictAndFamily, boolean isSymbol) {
    CTTextCharacterProperties rPr = getRPr();
    if (typeface == null) {
        if (rPr.isSetLatin())
            rPr.unsetLatin();
        if (rPr.isSetCs())
            rPr.unsetCs();
        if (rPr.isSetSym())
            rPr.unsetSym();
    } else {
        if (isSymbol) {
            CTTextFont font = rPr.isSetSym() ? rPr.getSym() : rPr.addNewSym();
            font.setTypeface(typeface);
        } else {
            CTTextFont latin = rPr.isSetLatin() ? rPr.getLatin() : rPr.addNewLatin();
            latin.setTypeface(typeface);
            if (charset != -1)
                latin.setCharset(charset);
            if (pictAndFamily != -1)
                latin.setPitchFamily(pictAndFamily);
        }
    }
}
Also used : CTTextFont(org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)

Example 25 with CTTextCharacterProperties

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

the class XSSFTextRun method getFontFamily.

/**
     * @return  font family or null if not set
     */
public String getFontFamily() {
    CTTextCharacterProperties rPr = getRPr();
    CTTextFont font = rPr.getLatin();
    if (font != null) {
        return font.getTypeface();
    }
    return XSSFFont.DEFAULT_FONT_NAME;
}
Also used : CTTextFont(org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties)

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