Package org.openxmlformats.schemas.drawingml.x2006.main

Examples of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties


     *
     * @param fontSize  font size in points.
     * The value of <code>-1</code> unsets the Sz attribyte from the underlying xml bean
     */
    public void setFontSize(double fontSize){
        CTTextCharacterProperties rPr = getRPr();
        if(fontSize == -1.0) {
            if(rPr.isSetSz()) rPr.unsetSz();
        } else {
            if(fontSize < 1.0) {
                throw new IllegalArgumentException("Minimum font size is 1pt but was " + fontSize);
            }

            rPr.setSz((int)(100*fontSize));
        }
    }
View Full Code Here


     * </p>
     *
     * @param spc  character spacing in points.
     */
    public void setCharacterSpacing(double spc){
        CTTextCharacterProperties rPr = getRPr();
        if(spc == 0.0) {
            if(rPr.isSetSpc()) rPr.unsetSpc();
        } else {
            rPr.setSpc((int)(100*spc));
        }
    }
View Full Code Here

    public void setFontFamily(String typeface){
        setFontFamily(typeface, (byte)-1, (byte)-1, false);
    }

    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);
            }
        }
View Full Code Here

        shape.setText(rt);

        CTTextParagraph pr = shape.getCTShape().getTxBody().getPArray(0);
        assertEquals(1, pr.sizeOfRArray());

        CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
        assertEquals(true, rPr.getB());
        assertEquals(true, rPr.getI());
        assertEquals(STTextUnderlineType.SNG, rPr.getU());
        assertTrue(Arrays.equals(
                new byte[]{0, (byte)128, (byte)128} ,
                rPr.getSolidFill().getSrgbClr().getVal()));

    }
View Full Code Here

            CTTextBodyProperties bodypr = body.addNewBodyPr();
            bodypr.setAnchor(STTextAnchoringType.CTR);
            bodypr.setRtlCol(false);
            CTTextParagraph p = body.addNewP();
            p.addNewPPr().setAlgn(STTextAlignType.CTR);
            CTTextCharacterProperties endPr = p.addNewEndParaRPr();
            endPr.setLang("en-US");
            endPr.setSz(1100);

            body.addNewLstStyle();

            prototype = shape;
        }
View Full Code Here

        str.setStylesTableReference(wb.getStylesSource());

        CTTextParagraph p = CTTextParagraph.Factory.newInstance();
        if(str.numFormattingRuns() == 0){
            CTRegularTextRun r = p.addNewR();
            CTTextCharacterProperties rPr = r.addNewRPr();
            rPr.setLang("en-US");
            rPr.setSz(1100);
            r.setT(str.getString());

        } else {
            for (int i = 0; i < str.getCTRst().sizeOfRArray(); i++) {
                CTRElt lt = str.getCTRst().getRArray(i);
                CTRPrElt ltPr = lt.getRPr();
                if(ltPr == null) ltPr = lt.addNewRPr();

                CTRegularTextRun r = p.addNewR();
                CTTextCharacterProperties rPr = r.addNewRPr();
                rPr.setLang("en-US");

                applyAttributes(ltPr, rPr);

                r.setT(lt.getT());
            }
View Full Code Here

    public void testDefaultTextStyle() {
        XMLSlideShow ppt = new XMLSlideShow();
        XSLFSlide slide = ppt.createSlide();

        // default character properties for paragraphs with level=1
        CTTextCharacterProperties pPr = ppt.getCTPresentation().getDefaultTextStyle().getLvl1PPr().getDefRPr();

        XSLFTextBox shape = slide.createTextBox();
        shape.setText("Apache POI");
        assertEquals(1, shape.getTextParagraphs().size());
        assertEquals(1, shape.getTextParagraphs().get(0).getTextRuns().size());

        XSLFTextRun r = shape.getTextParagraphs().get(0).getTextRuns().get(0);

        assertEquals(1800, pPr.getSz());
        assertEquals(18.0, r.getFontSize());
        assertEquals("Calibri", r.getFontFamily());

        pPr.setSz(900);
        pPr.getLatin().setTypeface("Arial");
        assertEquals(9.0, r.getFontSize());
        assertEquals("Arial", r.getFontFamily());

        // unset font size in presentation.xml. The value should be taken from master slide
        // from /p:sldMaster/p:txStyles/p:otherStyle/a:lvl1pPr/a:defRPr
        ppt.getCTPresentation().getDefaultTextStyle().getLvl1PPr().getDefRPr().unsetSz();
        pPr = slide.getSlideMaster().getXmlObject().getTxStyles().getOtherStyle().getLvl1PPr().getDefRPr();
        assertEquals(1800, pPr.getSz());
        assertEquals(18.0, r.getFontSize());
        pPr.setSz(2000);
        assertEquals(20.0, r.getFontSize());

        pPr.unsetSz()// Should never be
        assertEquals(-1.0, r.getFontSize());

    }
View Full Code Here

        XSLFTextRun textRun = paragraph.getTextRuns().get(0);

        // level 1 : default title style on the master slide
        // /p:sldMaster/p:txStyles/p:titleStyle/a:lvl1pPr
        CTTextParagraphProperties lv1PPr = master.getXmlObject().getTxStyles().getTitleStyle().getLvl1PPr();
        CTTextCharacterProperties lv1CPr = lv1PPr.getDefRPr();
        assertEquals(4400, lv1CPr.getSz());
        assertEquals(44.0, textRun.getFontSize());
        assertEquals("+mj-lt", lv1CPr.getLatin().getTypeface());
        assertEquals("Calibri", theme.getMajorFont());
        assertEquals("Calibri", textRun.getFontFamily());
        lv1CPr.setSz(3200);
        assertEquals(32.0, textRun.getFontSize());
        lv1CPr.getLatin().setTypeface("Arial");
        assertEquals("Arial", textRun.getFontFamily());
        assertEquals(STTextAlignType.CTR, lv1PPr.getAlgn());
        assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
        lv1PPr.setAlgn(STTextAlignType.L);
        assertEquals(TextAlign.LEFT, paragraph.getTextAlign());

        // level 2: title placeholder on the master slide
        // /p:sldMaster/p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="title"]
        XSLFTextShape tx2 = master.getPlaceholder(0);
        CTTextParagraphProperties lv2PPr = tx2.getTextBody(true).getLstStyle().addNewLvl1PPr();
        CTTextCharacterProperties lv2CPr = lv2PPr.addNewDefRPr();
        lv2CPr.setSz(3300);
        assertEquals(33.0, textRun.getFontSize());
        lv2CPr.addNewLatin().setTypeface("Times");
        assertEquals("Times", textRun.getFontFamily());
        lv2PPr.setAlgn(STTextAlignType.R);
        assertEquals(TextAlign.RIGHT, paragraph.getTextAlign());


        // level 3: title placeholder on the slide layout
        // /p:sldLayout /p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="ctrTitle"]
        XSLFTextShape tx3 = layout.getPlaceholder(0);
        CTTextParagraphProperties lv3PPr = tx3.getTextBody(true).getLstStyle().addNewLvl1PPr();
        CTTextCharacterProperties lv3CPr = lv3PPr.addNewDefRPr();
        lv3CPr.setSz(3400);
        assertEquals(34.0, textRun.getFontSize());
        lv3CPr.addNewLatin().setTypeface("Courier New");
        assertEquals("Courier New", textRun.getFontFamily());
        lv3PPr.setAlgn(STTextAlignType.CTR);
        assertEquals(TextAlign.CENTER, paragraph.getTextAlign());

        // level 4: default text properties in the shape itself
        // ./p:sp/p:txBody/a:lstStyle/a:lvl1pPr
        CTTextParagraphProperties lv4PPr = titleShape.getTextBody(true).getLstStyle().addNewLvl1PPr();
        CTTextCharacterProperties lv4CPr = lv4PPr.addNewDefRPr();
        lv4CPr.setSz(3500);
        assertEquals(35.0, textRun.getFontSize());
        lv4CPr.addNewLatin().setTypeface("Arial");
        assertEquals("Arial", textRun.getFontFamily());
        lv4PPr.setAlgn(STTextAlignType.L);
        assertEquals(TextAlign.LEFT, paragraph.getTextAlign());

        // level 5: text properties are defined in the text run
        CTTextParagraphProperties lv5PPr = paragraph.getXmlObject().addNewPPr();
        CTTextCharacterProperties lv5CPr = textRun.getXmlObject().getRPr();
        lv5CPr.setSz(3600);
        assertEquals(36.0, textRun.getFontSize());
        lv5CPr.addNewLatin().setTypeface("Calibri");
        assertEquals("Calibri", textRun.getFontFamily());
        lv5PPr.setAlgn(STTextAlignType.CTR);
        assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
    }
View Full Code Here

        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());
        assertEquals("+mn-lt", lv1CPr.getLatin().getTypeface());
        assertEquals("Calibri", theme.getMinorFont());
        assertEquals("Calibri", r1.getFontFamily());
        lv1CPr.setSz(3300);
        assertEquals(33.0, r1.getFontSize());
        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());
        lv2CPr.setSz(3300);
        assertEquals(33.0, r2.getFontSize());
        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());
        lv3CPr.setSz(2500);
        assertEquals(25.0, r3.getFontSize());
        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());
        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());
        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());
        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());
        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());
        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());
        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());
        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());
        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());
        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.getXmlObject().getRPr();
        lv2PPr = p2.getXmlObject().isSetPPr() ? p2.getXmlObject().getPPr() : p2.getXmlObject().addNewPPr();
        lv2CPr = r2.getXmlObject().getRPr();
        lv3PPr = p3.getXmlObject().isSetPPr() ? p3.getXmlObject().getPPr() : p3.getXmlObject().addNewPPr();
        lv3CPr = r3.getXmlObject().getRPr();

        lv1CPr.setSz(3600);
        assertEquals(36.0, r1.getFontSize());
        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());
        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());
        lv3CPr.addNewLatin().setTypeface("Calibri");
        assertEquals("Calibri", r3.getFontFamily());
        lv3PPr.setAlgn(STTextAlignType.CTR);
        assertEquals(TextAlign.CENTER, p3.getTextAlign());

    }
View Full Code Here

    public CTRegularTextRun getXmlObject(){
        return _r;
    }

    public void setFontColor(Color color){
        CTTextCharacterProperties rPr = getRPr();
        CTSolidColorFillProperties fill = rPr.isSetSolidFill() ? rPr.getSolidFill() : rPr.addNewSolidFill();
        CTSRgbColor clr = fill.isSetSrgbClr() ? fill.getSrgbClr() : fill.addNewSrgbClr();
        clr.setVal(new byte[]{(byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue()});

        if(fill.isSetHslClr()) fill.unsetHslClr();
        if(fill.isSetPrstClr()) fill.unsetPrstClr();
View Full Code Here

TOP

Related Classes of org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.