01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17: package org.apache.poi.hslf.model;
18:
19: import junit.framework.TestCase;
20: import org.apache.poi.hslf.usermodel.SlideShow;
21: import org.apache.poi.hslf.usermodel.RichTextRun;
22: import org.apache.poi.hslf.HSLFSlideShow;
23:
24: import java.io.ByteArrayOutputStream;
25: import java.io.ByteArrayInputStream;
26:
27: /**
28: * Test setting text properties of newly added TextBoxes
29: *
30: * @author Yegor Kozlov
31: */
32: public class TestSetBoldItalic extends TestCase {
33: /**
34: * Verify that we can add TextBox shapes to a slide
35: * and set some of the style attributes
36: */
37: public void testTextBoxWrite() throws Exception {
38: //String dirname = System.getProperty("HSLF.testdata.path");
39: //String filename = dirname + "/with_textbox.ppt";
40: //new SlideShow(new HSLFSlideShow(filename));
41:
42: SlideShow ppt = new SlideShow();
43: Slide sl = ppt.createSlide();
44: RichTextRun rt;
45:
46: String val = "Hello, World!";
47:
48: // Create a new textbox, and give it lots of properties
49: TextBox txtbox = new TextBox();
50: rt = txtbox.getTextRun().getRichTextRuns()[0];
51: txtbox.setText(val);
52: rt.setFontSize(42);
53: rt.setBold(true);
54: rt.setItalic(true);
55: rt.setUnderlined(false);
56: sl.addShape(txtbox);
57:
58: // Check it before save
59: rt = txtbox.getTextRun().getRichTextRuns()[0];
60: assertEquals(val, rt.getText());
61: assertEquals(42, rt.getFontSize());
62: assertTrue(rt.isBold());
63: assertTrue(rt.isItalic());
64:
65: // Serialize and read again
66: ByteArrayOutputStream out = new ByteArrayOutputStream();
67: ppt.write(out);
68: out.close();
69:
70: ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(
71: out.toByteArray())));
72: sl = ppt.getSlides()[0];
73:
74: txtbox = (TextBox) sl.getShapes()[0];
75: rt = txtbox.getTextRun().getRichTextRuns()[0];
76:
77: // Check after save
78: assertEquals(val, rt.getText());
79: assertEquals(42, rt.getFontSize());
80: assertTrue(rt.isBold());
81: assertTrue(rt.isItalic());
82: assertFalse(rt.isUnderlined());
83: }
84:
85: }
|