Search in sources :

Example 16 with CTTextCharacterProperties

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

the class TestXSLFTextShape method testBodyStyles.

@Test
public void testBodyStyles() throws IOException {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlideMaster master = ppt.getSlideMasters().get(0);
    XSLFTheme theme = master.getTheme();
    XSLFSlideLayout layout = master.getLayout(SlideLayout.TITLE_AND_CONTENT);
    XSLFSlide slide = ppt.createSlide(layout);
    assertSame(layout, slide.getSlideLayout());
    assertSame(master, slide.getSlideMaster());
    XSLFTextShape tx1 = slide.getPlaceholder(1);
    tx1.clearText();
    XSLFTextParagraph p1 = tx1.addNewTextParagraph();
    assertEquals(0, p1.getIndentLevel());
    XSLFTextRun r1 = p1.addNewTextRun();
    r1.setText("Apache POI");
    XSLFTextParagraph p2 = tx1.addNewTextParagraph();
    p2.setIndentLevel(1);
    assertEquals(1, p2.getIndentLevel());
    XSLFTextRun r2 = p2.addNewTextRun();
    r2.setText("HSLF");
    XSLFTextParagraph p3 = tx1.addNewTextParagraph();
    p3.setIndentLevel(2);
    assertEquals(2, p3.getIndentLevel());
    XSLFTextRun r3 = p3.addNewTextRun();
    r3.setText("XSLF");
    // level 1 : default title style on the master slide
    // /p:sldMaster/p:txStyles/p:bodyStyle/a:lvl1pPr
    CTTextParagraphProperties lv1PPr = master.getXmlObject().getTxStyles().getBodyStyle().getLvl1PPr();
    CTTextCharacterProperties lv1CPr = lv1PPr.getDefRPr();
    CTTextParagraphProperties lv2PPr = master.getXmlObject().getTxStyles().getBodyStyle().getLvl2PPr();
    CTTextCharacterProperties lv2CPr = lv2PPr.getDefRPr();
    CTTextParagraphProperties lv3PPr = master.getXmlObject().getTxStyles().getBodyStyle().getLvl3PPr();
    CTTextCharacterProperties lv3CPr = lv3PPr.getDefRPr();
    // lv1
    assertEquals(3200, lv1CPr.getSz());
    assertEquals(32.0, r1.getFontSize(), 0);
    assertEquals("+mn-lt", lv1CPr.getLatin().getTypeface());
    assertEquals("Calibri", theme.getMinorFont());
    assertEquals("Calibri", r1.getFontFamily());
    lv1CPr.setSz(3300);
    assertEquals(33.0, r1.getFontSize(), 0);
    lv1CPr.getLatin().setTypeface("Arial");
    assertEquals("Arial", r1.getFontFamily());
    assertEquals(STTextAlignType.L, lv1PPr.getAlgn());
    assertEquals(TextAlign.LEFT, p1.getTextAlign());
    lv1PPr.setAlgn(STTextAlignType.R);
    assertEquals(TextAlign.RIGHT, p1.getTextAlign());
    //lv2
    assertEquals(2800, lv2CPr.getSz());
    assertEquals(28.0, r2.getFontSize(), 0);
    lv2CPr.setSz(3300);
    assertEquals(33.0, r2.getFontSize(), 0);
    lv2CPr.getLatin().setTypeface("Times");
    assertEquals("Times", r2.getFontFamily());
    assertEquals(STTextAlignType.L, lv2PPr.getAlgn());
    assertEquals(TextAlign.LEFT, p2.getTextAlign());
    lv2PPr.setAlgn(STTextAlignType.R);
    assertEquals(TextAlign.RIGHT, p2.getTextAlign());
    //lv3
    assertEquals(2400, lv3CPr.getSz());
    assertEquals(24.0, r3.getFontSize(), 0);
    lv3CPr.setSz(2500);
    assertEquals(25.0, r3.getFontSize(), 0);
    lv3CPr.getLatin().setTypeface("Courier New");
    assertEquals("Courier New", r3.getFontFamily());
    assertEquals(STTextAlignType.L, lv3PPr.getAlgn());
    assertEquals(TextAlign.LEFT, p3.getTextAlign());
    lv3PPr.setAlgn(STTextAlignType.R);
    assertEquals(TextAlign.RIGHT, p3.getTextAlign());
    // level 2: body placeholder on the master slide
    // /p:sldMaster/p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="body"]
    XSLFTextShape tx2 = master.getPlaceholder(1);
    assertEquals(Placeholder.BODY, tx2.getTextType());
    lv1PPr = tx2.getTextBody(true).getLstStyle().addNewLvl1PPr();
    lv1CPr = lv1PPr.addNewDefRPr();
    lv2PPr = tx2.getTextBody(true).getLstStyle().addNewLvl2PPr();
    lv2CPr = lv2PPr.addNewDefRPr();
    lv3PPr = tx2.getTextBody(true).getLstStyle().addNewLvl3PPr();
    lv3CPr = lv3PPr.addNewDefRPr();
    lv1CPr.setSz(3300);
    assertEquals(33.0, r1.getFontSize(), 0);
    lv1CPr.addNewLatin().setTypeface("Times");
    assertEquals("Times", r1.getFontFamily());
    lv1PPr.setAlgn(STTextAlignType.L);
    assertEquals(TextAlign.LEFT, p1.getTextAlign());
    lv2CPr.setSz(3300);
    assertEquals(33.0, r2.getFontSize(), 0);
    lv2CPr.addNewLatin().setTypeface("Times");
    assertEquals("Times", r2.getFontFamily());
    lv2PPr.setAlgn(STTextAlignType.L);
    assertEquals(TextAlign.LEFT, p2.getTextAlign());
    lv3CPr.setSz(3300);
    assertEquals(33.0, r3.getFontSize(), 0);
    lv3CPr.addNewLatin().setTypeface("Times");
    assertEquals("Times", r3.getFontFamily());
    lv3PPr.setAlgn(STTextAlignType.L);
    assertEquals(TextAlign.LEFT, p3.getTextAlign());
    // level 3: body placeholder on the slide layout
    // /p:sldLayout /p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="ctrTitle"]
    XSLFTextShape tx3 = layout.getPlaceholder(1);
    assertEquals(Placeholder.BODY, tx2.getTextType());
    lv1PPr = tx3.getTextBody(true).getLstStyle().addNewLvl1PPr();
    lv1CPr = lv1PPr.addNewDefRPr();
    lv2PPr = tx3.getTextBody(true).getLstStyle().addNewLvl2PPr();
    lv2CPr = lv2PPr.addNewDefRPr();
    lv3PPr = tx3.getTextBody(true).getLstStyle().addNewLvl3PPr();
    lv3CPr = lv3PPr.addNewDefRPr();
    lv1CPr.setSz(3400);
    assertEquals(34.0, r1.getFontSize(), 0);
    lv1CPr.addNewLatin().setTypeface("Courier New");
    assertEquals("Courier New", r1.getFontFamily());
    lv1PPr.setAlgn(STTextAlignType.CTR);
    assertEquals(TextAlign.CENTER, p1.getTextAlign());
    lv2CPr.setSz(3400);
    assertEquals(34.0, r2.getFontSize(), 0);
    lv2CPr.addNewLatin().setTypeface("Courier New");
    assertEquals("Courier New", r2.getFontFamily());
    lv2PPr.setAlgn(STTextAlignType.CTR);
    assertEquals(TextAlign.CENTER, p2.getTextAlign());
    lv3CPr.setSz(3400);
    assertEquals(34.0, r3.getFontSize(), 0);
    lv3CPr.addNewLatin().setTypeface("Courier New");
    assertEquals("Courier New", r3.getFontFamily());
    lv3PPr.setAlgn(STTextAlignType.CTR);
    assertEquals(TextAlign.CENTER, p3.getTextAlign());
    // level 4: default text properties in the shape itself
    // ./p:sp/p:txBody/a:lstStyle/a:lvl1pPr
    lv1PPr = tx1.getTextBody(true).getLstStyle().addNewLvl1PPr();
    lv1CPr = lv1PPr.addNewDefRPr();
    lv2PPr = tx1.getTextBody(true).getLstStyle().addNewLvl2PPr();
    lv2CPr = lv2PPr.addNewDefRPr();
    lv3PPr = tx1.getTextBody(true).getLstStyle().addNewLvl3PPr();
    lv3CPr = lv3PPr.addNewDefRPr();
    lv1CPr.setSz(3500);
    assertEquals(35.0, r1.getFontSize(), 0);
    lv1CPr.addNewLatin().setTypeface("Arial");
    assertEquals("Arial", r1.getFontFamily());
    lv1PPr.setAlgn(STTextAlignType.L);
    assertEquals(TextAlign.LEFT, p1.getTextAlign());
    lv2CPr.setSz(3500);
    assertEquals(35.0, r2.getFontSize(), 0);
    lv2CPr.addNewLatin().setTypeface("Arial");
    assertEquals("Arial", r2.getFontFamily());
    lv2PPr.setAlgn(STTextAlignType.L);
    assertEquals(TextAlign.LEFT, p2.getTextAlign());
    lv3CPr.setSz(3500);
    assertEquals(35.0, r3.getFontSize(), 0);
    lv3CPr.addNewLatin().setTypeface("Arial");
    assertEquals("Arial", r3.getFontFamily());
    lv3PPr.setAlgn(STTextAlignType.L);
    assertEquals(TextAlign.LEFT, p3.getTextAlign());
    // level 5: text properties are defined in the text run
    lv1PPr = p1.getXmlObject().isSetPPr() ? p1.getXmlObject().getPPr() : p1.getXmlObject().addNewPPr();
    lv1CPr = r1.getRPr(false);
    lv2PPr = p2.getXmlObject().isSetPPr() ? p2.getXmlObject().getPPr() : p2.getXmlObject().addNewPPr();
    lv2CPr = r2.getRPr(false);
    lv3PPr = p3.getXmlObject().isSetPPr() ? p3.getXmlObject().getPPr() : p3.getXmlObject().addNewPPr();
    lv3CPr = r3.getRPr(false);
    lv1CPr.setSz(3600);
    assertEquals(36.0, r1.getFontSize(), 0);
    lv1CPr.addNewLatin().setTypeface("Calibri");
    assertEquals("Calibri", r1.getFontFamily());
    lv1PPr.setAlgn(STTextAlignType.CTR);
    assertEquals(TextAlign.CENTER, p1.getTextAlign());
    lv2CPr.setSz(3600);
    assertEquals(36.0, r2.getFontSize(), 0);
    lv2CPr.addNewLatin().setTypeface("Calibri");
    assertEquals("Calibri", r2.getFontFamily());
    lv2PPr.setAlgn(STTextAlignType.CTR);
    assertEquals(TextAlign.CENTER, p2.getTextAlign());
    lv3CPr.setSz(3600);
    assertEquals(36.0, r3.getFontSize(), 0);
    lv3CPr.addNewLatin().setTypeface("Calibri");
    assertEquals("Calibri", r3.getFontFamily());
    lv3PPr.setAlgn(STTextAlignType.CTR);
    assertEquals(TextAlign.CENTER, p3.getTextAlign());
    ppt.close();
}
Also used : CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTTextParagraphProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties) Test(org.junit.Test)

Example 17 with CTTextCharacterProperties

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

the class XSLFTextRun method getFontColor.

@Override
public PaintStyle getFontColor() {
    final boolean hasPlaceholder = getParentParagraph().getParentShape().getPlaceholder() != null;
    CharacterPropertyFetcher<PaintStyle> fetcher = new CharacterPropertyFetcher<PaintStyle>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props == null) {
                return false;
            }
            XSLFShape shape = _p.getParentShape();
            CTShapeStyle style = shape.getSpStyle();
            CTSchemeColor phClr = null;
            if (style != null && style.getFontRef() != null) {
                phClr = style.getFontRef().getSchemeClr();
            }
            XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(props);
            XSLFSheet sheet = shape.getSheet();
            PackagePart pp = sheet.getPackagePart();
            XSLFTheme theme = sheet.getTheme();
            PaintStyle ps = XSLFShape.selectPaint(fp, phClr, pp, theme, hasPlaceholder);
            if (ps != null) {
                setValue(ps);
                return true;
            }
            return false;
        }
    };
    fetchCharacterProperty(fetcher);
    return fetcher.getValue();
}
Also used : CTShapeStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeStyle) CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties)

Example 18 with CTTextCharacterProperties

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

the class XSLFTextRun method getTextCap.

/**
     * @return whether a run of text will be formatted as a superscript text. Default is false.
     */
public TextCap getTextCap() {
    CharacterPropertyFetcher<TextCap> fetcher = new CharacterPropertyFetcher<TextCap>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props != null && props.isSetCap()) {
                int idx = props.getCap().intValue() - 1;
                setValue(TextCap.values()[idx]);
                return true;
            }
            return false;
        }
    };
    fetchCharacterProperty(fetcher);
    return fetcher.getValue() == null ? TextCap.NONE : fetcher.getValue();
}
Also used : CharacterPropertyFetcher(org.apache.poi.xslf.model.CharacterPropertyFetcher) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)

Example 19 with CTTextCharacterProperties

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

the class XSLFTextRun method getPitchAndFamily.

public byte getPitchAndFamily() {
    // final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
    CharacterPropertyFetcher<Byte> visitor = new CharacterPropertyFetcher<Byte>(_p.getIndentLevel()) {

        public boolean fetch(CTTextCharacterProperties props) {
            if (props != null) {
                CTTextFont font = props.getLatin();
                if (font != null) {
                    setValue(font.getPitchFamily());
                    return true;
                }
            }
            return false;
        }
    };
    fetchCharacterProperty(visitor);
    return visitor.getValue() == null ? 0 : 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 20 with CTTextCharacterProperties

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

the class XSLFTextRun method createHyperlink.

@Override
public XSLFHyperlink createHyperlink() {
    XSLFHyperlink hl = getHyperlink();
    if (hl != null) {
        return hl;
    }
    CTTextCharacterProperties rPr = getRPr(true);
    return new XSLFHyperlink(rPr.addNewHlinkClick(), _p.getParentShape().getSheet());
}
Also used : 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