FileDocCategorySizeDatePackage
TestSetBoldItalic.javaAPI DocApache Poi 3.0.13038Sun Mar 11 12:59:30 GMT 2007org.apache.poi.hslf.model

TestSetBoldItalic

public class TestSetBoldItalic extends TestCase
Test setting text properties of newly added TextBoxes
author
Yegor Kozlov

Fields Summary
Constructors Summary
Methods Summary
public voidtestTextBoxWrite()
Verify that we can add TextBox shapes to a slide and set some of the style attributes

        //String dirname = System.getProperty("HSLF.testdata.path");
        //String filename = dirname + "/with_textbox.ppt";
        //new SlideShow(new HSLFSlideShow(filename));

        SlideShow 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.setFontSize(42);
        rt.setBold(true);
        rt.setItalic(true);
        rt.setUnderlined(false);
        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());

        // 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());