Package org.apache.poi.hslf.usermodel

Examples of org.apache.poi.hslf.usermodel.RichTextRun


        MasterSheet masterSheet = slide.getMasterSheet();
        assertTrue(masterSheet instanceof TitleMaster);

        TextRun[] txt = slide.getTextRuns();
        for (int i = 0; i < txt.length; i++) {
            RichTextRun rt = txt[i].getRichTextRuns()[0];
            switch(txt[i].getRunType()){
                case TextHeaderAtom.CENTER_TITLE_TYPE:
                    assertEquals("Arial", rt.getFontName());
                    assertEquals(32, rt.getFontSize());
                    assertEquals(true, rt.isBold());
                    assertEquals(true, rt.isUnderlined());
                    break;
                case TextHeaderAtom.CENTRE_BODY_TYPE:
                    assertEquals("Courier New", rt.getFontName());
                    assertEquals(20, rt.getFontSize());
                    assertEquals(true, rt.isBold());
                    assertEquals(false, rt.isUnderlined());
                    break;
            }

        }
    }
View Full Code Here


        TextRun[] trun;

        trun = slide[0].getTextRuns();
        for (int i = 0; i < trun.length; i++) {
            if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
                RichTextRun rt = trun[i].getRichTextRuns()[0];
                assertEquals(40, rt.getFontSize());
                assertEquals(true, rt.isUnderlined());
                assertEquals("Arial", rt.getFontName());
            } else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
                RichTextRun rt;
                rt = trun[i].getRichTextRuns()[0];
                assertEquals(0, rt.getIndentLevel());
                assertEquals(32, rt.getFontSize());
                assertEquals("Arial", rt.getFontName());

                rt = trun[i].getRichTextRuns()[1];
                assertEquals(1, rt.getIndentLevel());
                assertEquals(28, rt.getFontSize());
                assertEquals("Arial", rt.getFontName());

            }
        }

        trun = slide[1].getTextRuns();
        for (int i = 0; i < trun.length; i++) {
            if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
                RichTextRun rt = trun[i].getRichTextRuns()[0];
                assertEquals(48, rt.getFontSize());
                assertEquals(true, rt.isItalic());
                assertEquals("Georgia", rt.getFontName());
            } else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
                RichTextRun rt;
                rt = trun[i].getRichTextRuns()[0];
                assertEquals(0, rt.getIndentLevel());
                assertEquals(32, rt.getFontSize());
                assertEquals("Courier New", rt.getFontName());
            }
        }

    }
View Full Code Here

        TextRun[] trun;

        trun = slide.getTextRuns();
        for (int i = 0; i < trun.length; i++) {
            if (trun[i].getRunType() == TextHeaderAtom.TITLE_TYPE){
                RichTextRun rt = trun[i].getRichTextRuns()[0];
                assertEquals(40, rt.getFontSize());
                assertEquals(true, rt.isUnderlined());
                assertEquals("Arial", rt.getFontName());
            } else if (trun[i].getRunType() == TextHeaderAtom.BODY_TYPE){
                RichTextRun[] rt = trun[i].getRichTextRuns();
                for (int j = 0; j < rt.length; j++) {
                    int indent = rt[j].getIndentLevel();
                    switch (indent){
View Full Code Here

     * and set some of the style attributes
     */
    public void testTextBoxWriteBytes() throws Exception {
        ppt = new SlideShow();
        Slide sl = ppt.createSlide();
        RichTextRun rt;

        String val = "Hello, World!";

        // Create a new textbox, and give it lots of properties
        TextBox txtbox = new TextBox();
        rt = txtbox.getTextRun().getRichTextRuns()[0];
        txtbox.setText(val);
        rt.setFontName("Arial");
        rt.setFontSize(42);
        rt.setBold(true);
        rt.setItalic(true);
        rt.setUnderlined(false);
        rt.setFontColor(Color.red);
        sl.addShape(txtbox);

        // Check it before save
        rt = txtbox.getTextRun().getRichTextRuns()[0];
        assertEquals(val, rt.getText());
        assertEquals(42, rt.getFontSize());
        assertTrue(rt.isBold());
        assertTrue(rt.isItalic());
        assertFalse(rt.isUnderlined());
        assertEquals("Arial", rt.getFontName());
        assertEquals(Color.red, rt.getFontColor());

        // Serialize and read again
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ppt.write(out);
        out.close();

        ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
        sl = ppt.getSlides()[0];
       
        txtbox = (TextBox)sl.getShapes()[0];
        rt = txtbox.getTextRun().getRichTextRuns()[0];

        // Check after save
        assertEquals(val, rt.getText());
        assertEquals(42, rt.getFontSize());
        assertTrue(rt.isBold());
        assertTrue(rt.isItalic());
        assertFalse(rt.isUnderlined());
        assertEquals("Arial", rt.getFontName());
        assertEquals(Color.red, rt.getFontColor());
    }
View Full Code Here

    TextRun trB = textRuns[1];
   
    assertEquals(1, trA.getRichTextRuns().length);
    assertEquals(1, trB.getRichTextRuns().length);
   
    RichTextRun rtrA = trA.getRichTextRuns()[0];
    RichTextRun rtrB = trB.getRichTextRuns()[0];
   
    assertEquals(trA.getText(), rtrA.getText());
    assertEquals(trB.getText(), rtrB.getText());
   
    assertNull(rtrA._getRawCharacterStyle());
    assertNull(rtrA._getRawParagraphStyle());
    assertNull(rtrB._getRawCharacterStyle());
    assertNull(rtrB._getRawParagraphStyle());
    }
View Full Code Here

    TextRun trB = textRuns[1];
   
    assertEquals(1, trA.getRichTextRuns().length);
    assertEquals(3, trB.getRichTextRuns().length);
   
    RichTextRun rtrA = trA.getRichTextRuns()[0];
    RichTextRun rtrB = trB.getRichTextRuns()[0];
    RichTextRun rtrC = trB.getRichTextRuns()[1];
    RichTextRun rtrD = trB.getRichTextRuns()[2];
   
    assertEquals(trA.getText(), rtrA.getText());
   
    assertEquals(trB.getText().substring(0, 30), rtrB.getText());
    assertEquals(trB.getText().substring(30,58), rtrC.getText());
    assertEquals(trB.getText().substring(58,82), rtrD.getText());
   
    assertNull(rtrA._getRawCharacterStyle());
    assertNull(rtrA._getRawParagraphStyle());
    assertNotNull(rtrB._getRawCharacterStyle());
    assertNotNull(rtrB._getRawParagraphStyle());
    assertNotNull(rtrC._getRawCharacterStyle());
    assertNotNull(rtrC._getRawParagraphStyle());
    assertNotNull(rtrD._getRawCharacterStyle());
    assertNotNull(rtrD._getRawParagraphStyle());
   
    // Same paragraph styles
    assertEquals(rtrB._getRawParagraphStyle(), rtrC._getRawParagraphStyle());
    assertEquals(rtrB._getRawParagraphStyle(), rtrD._getRawParagraphStyle());
   
    // Different char styles
    assertFalse( rtrB._getRawCharacterStyle().equals( rtrC._getRawCharacterStyle() ));
    assertFalse( rtrB._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
    assertFalse( rtrC._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() ));
    }
View Full Code Here

    Slide slideOne = ss.getSlides()[0];
    TextRun[] textRuns = slideOne.getTextRuns();
    TextRun trB = textRuns[1];
    assertEquals(1, trB.getRichTextRuns().length);
   
    RichTextRun rtrB = trB.getRichTextRuns()[0];
    assertEquals(trB.getText(), rtrB.getText());
    assertNull(rtrB._getRawCharacterStyle());
    assertNull(rtrB._getRawParagraphStyle());
   
    // Change text via normal
    trB.setText("Test Foo Test");
    rtrB = trB.getRichTextRuns()[0];
    assertEquals("Test Foo Test", trB.getText());
    assertEquals("Test Foo Test", rtrB.getText());
    assertNull(rtrB._getRawCharacterStyle());
    assertNull(rtrB._getRawParagraphStyle());
    }
View Full Code Here

    Slide slideOne = ssRich.getSlides()[0];
    TextRun[] textRuns = slideOne.getTextRuns();
    TextRun trB = textRuns[1];
    assertEquals(3, trB.getRichTextRuns().length);
   
    RichTextRun rtrB = trB.getRichTextRuns()[0];
    RichTextRun rtrC = trB.getRichTextRuns()[1];
    RichTextRun rtrD = trB.getRichTextRuns()[2];
    TextPropCollection tpBP = rtrB._getRawParagraphStyle();
    TextPropCollection tpBC = rtrB._getRawCharacterStyle();
    TextPropCollection tpCP = rtrC._getRawParagraphStyle();
    TextPropCollection tpCC = rtrC._getRawCharacterStyle();
    TextPropCollection tpDP = rtrD._getRawParagraphStyle();
    TextPropCollection tpDC = rtrD._getRawCharacterStyle();
   
    assertEquals(trB.getText().substring(0, 30), rtrB.getText());
    assertNotNull(tpBP);
    assertNotNull(tpBC);
    assertNotNull(tpCP);
View Full Code Here

    Slide slideOne = ss.getSlides()[0];
    TextRun[] textRuns = slideOne.getTextRuns();
    TextRun trB = textRuns[1];
    assertEquals(1, trB.getRichTextRuns().length);
   
    RichTextRun rtrB = trB.getRichTextRuns()[0];
    assertEquals(trB.getText(), rtrB.getText());
    assertNull(rtrB._getRawCharacterStyle());
    assertNull(rtrB._getRawParagraphStyle());
   
    // Change text via rich
    rtrB.setText("Test Test Test");
    assertEquals("Test Test Test", trB.getText());
    assertEquals("Test Test Test", rtrB.getText());
   
    // Will now have dummy props
    assertNotNull(rtrB._getRawCharacterStyle());
    assertNotNull(rtrB._getRawParagraphStyle());
    }
View Full Code Here

    TextRun trB = textRuns[1];
    assertEquals(3, trB.getRichTextRuns().length);
   
    // We start with 3 text runs, each with their own set of styles,
    //  but all sharing the same paragraph styles
    RichTextRun rtrB = trB.getRichTextRuns()[0];
    RichTextRun rtrC = trB.getRichTextRuns()[1];
    RichTextRun rtrD = trB.getRichTextRuns()[2];
    TextPropCollection tpBP = rtrB._getRawParagraphStyle();
    TextPropCollection tpBC = rtrB._getRawCharacterStyle();
    TextPropCollection tpCP = rtrC._getRawParagraphStyle();
    TextPropCollection tpCC = rtrC._getRawCharacterStyle();
    TextPropCollection tpDP = rtrD._getRawParagraphStyle();
    TextPropCollection tpDC = rtrD._getRawCharacterStyle();
   
    // Check text and stylings
    assertEquals(trB.getText().substring(0, 30), rtrB.getText());
    assertNotNull(tpBP);
    assertNotNull(tpBC);
    assertNotNull(tpCP);
    assertNotNull(tpCC);
    assertNotNull(tpDP);
    assertNotNull(tpDC);
    assertTrue(tpBP.equals(tpCP));
    assertTrue(tpBP.equals(tpDP));
    assertTrue(tpCP.equals(tpDP));
    assertFalse(tpBC.equals(tpCC));
    assertFalse(tpBC.equals(tpDC));
    assertFalse(tpCC.equals(tpDC));
   
    // Check text in the rich runs
    assertEquals("This is the subtitle, in bold\n", rtrB.getText());
    assertEquals("This bit is blue and italic\n", rtrC.getText());
    assertEquals("This bit is red (normal)", rtrD.getText());
   
    String newBText = "New Subtitle, will still be bold\n";
    String newCText = "New blue and italic text\n";
    String newDText = "Funky new normal red text";
    rtrB.setText(newBText);
    rtrC.setText(newCText);
    rtrD.setText(newDText);
    assertEquals(newBText, rtrB.getText());
    assertEquals(newCText, rtrC.getText());
    assertEquals(newDText, rtrD.getText());
   
    assertEquals(newBText + newCText + newDText, trB.getText());
   
    // The styles should have been updated for the new sizes
    assertEquals(newBText.length(), tpBC.getCharactersCovered());
    assertEquals(newCText.length(), tpCC.getCharactersCovered());
    assertEquals(newDText.length()+1, tpDC.getCharactersCovered()); // Last one is always one larger
   
    assertEquals(
        newBText.length() + newCText.length() + newDText.length(),
        tpBP.getCharactersCovered()
    );
   
    // Paragraph style should be sum of text length
    assertEquals(newBText.length() + newCText.length() + newDText.length(), tpBP.getCharactersCovered());
   
    // Check stylings still as expected
    TextPropCollection ntpBC = rtrB._getRawCharacterStyle();
    TextPropCollection ntpCC = rtrC._getRawCharacterStyle();
    TextPropCollection ntpDC = rtrD._getRawCharacterStyle();
    assertEquals(tpBC.getTextPropList(), ntpBC.getTextPropList());
    assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList());
    assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList());
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.hslf.usermodel.RichTextRun

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.