Search in sources :

Example 1 with Environment

use of org.apache.poi.hslf.record.Environment in project poi by apache.

the class TestSlideMaster method testSlideMaster.

/**
     * The reference ppt has two masters.
     * Check we can read their attributes.
     */
@Test
public void testSlideMaster() throws IOException {
    HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
    Environment env = ppt.getDocumentRecord().getEnvironment();
    List<HSLFSlideMaster> master = ppt.getSlideMasters();
    assertEquals(2, master.size());
    //character attributes
    assertEquals(40, master.get(0).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
    assertEquals(48, master.get(1).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
    int font1 = master.get(0).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
    int font2 = master.get(1).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
    assertEquals("Arial", env.getFontCollection().getFontWithId(font1));
    assertEquals("Georgia", env.getFontCollection().getFontWithId(font2));
    CharFlagsTextProp prop1 = (CharFlagsTextProp) master.get(0).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
    assertEquals(false, prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
    assertEquals(false, prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
    assertEquals(true, prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
    CharFlagsTextProp prop2 = (CharFlagsTextProp) master.get(1).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
    assertEquals(false, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
    assertEquals(true, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
    assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
    //now paragraph attributes
    assertEquals(0x266B, master.get(0).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
    assertEquals(0x2022, master.get(1).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
    int b1 = master.get(0).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
    int b2 = master.get(1).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
    assertEquals("Arial", env.getFontCollection().getFontWithId(b1));
    assertEquals("Georgia", env.getFontCollection().getFontWithId(b2));
    ppt.close();
}
Also used : Environment(org.apache.poi.hslf.record.Environment) HSLFSlideMaster(org.apache.poi.hslf.usermodel.HSLFSlideMaster) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) CharFlagsTextProp(org.apache.poi.hslf.model.textproperties.CharFlagsTextProp) Test(org.junit.Test)

Aggregations

CharFlagsTextProp (org.apache.poi.hslf.model.textproperties.CharFlagsTextProp)1 Environment (org.apache.poi.hslf.record.Environment)1 HSLFSlideMaster (org.apache.poi.hslf.usermodel.HSLFSlideMaster)1 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)1 Test (org.junit.Test)1