]> source.dussan.org Git - poi.git/commitdiff
Tests for getting and changing the font of a rich text run
authorNick Burch <nick@apache.org>
Sat, 18 Mar 2006 18:56:38 +0000 (18:56 +0000)
committerNick Burch <nick@apache.org>
Sat, 18 Mar 2006 18:56:38 +0000 (18:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@386873 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/testcases/org/apache/poi/hslf/data/Single_Coloured_Page_With_Fonts_and_Alignments.ppt [new file with mode: 0644]
src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java

diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/data/Single_Coloured_Page_With_Fonts_and_Alignments.ppt b/src/scratchpad/testcases/org/apache/poi/hslf/data/Single_Coloured_Page_With_Fonts_and_Alignments.ppt
new file mode 100644 (file)
index 0000000..a177642
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/Single_Coloured_Page_With_Fonts_and_Alignments.ppt differ
index eb759a5689bffff5df0bbd0c89b8a14606c9d72b..7e256853d5de805f1a9597100bebd21e37767e4e 100644 (file)
@@ -60,9 +60,15 @@ public class TestFontCollection extends TestCase {
         idx = fonts.addFont("Arial"); //the font being added twice
         assertEquals(idx, 2);
 
-        //font collection should contain 3 fonts
+        // Font collection should contain 3 fonts
         Record[] child = fonts.getChildRecords();
         assertEquals(child.length, 3);
+        
+        // Check we get the right font name for the indicies
+        assertEquals("Times New Roman", fonts.getFontWithId(0));
+        assertEquals("Helvetica", fonts.getFontWithId(1));
+        assertEquals("Arial", fonts.getFontWithId(2));
+        assertNull(fonts.getFontWithId(3));
     }
 
     public void testWrite() throws Exception {
index 6bb47673e748ee64a9385bb87fb5a8766bb271f4..c2dbe5731dabfe2ac82cc546718da344179c7bf8 100644 (file)
@@ -15,9 +15,11 @@ import junit.framework.TestCase;
 public class TestRichTextRun extends TestCase {
        // SlideShow primed on the test data
        private SlideShow ss;
-       private SlideShow ssRich;
+       private SlideShow ssRichA;
+       private SlideShow ssRichB;
        private HSLFSlideShow hss;
-       private HSLFSlideShow hssRich;
+       private HSLFSlideShow hssRichA;
+       private HSLFSlideShow hssRichB;
        
     protected void setUp() throws Exception {
                String dirname = System.getProperty("HSLF.testdata.path");
@@ -27,10 +29,15 @@ public class TestRichTextRun extends TestCase {
                hss = new HSLFSlideShow(filename);
                ss = new SlideShow(hss);
                
-               // Rich test file
+               // Rich test file A
                filename = dirname + "/Single_Coloured_Page.ppt";
-               hssRich = new HSLFSlideShow(filename);
-               ssRich = new SlideShow(hssRich);
+               hssRichA = new HSLFSlideShow(filename);
+               ssRichA = new SlideShow(hssRichA);
+               
+               // Rich test file B
+               filename = dirname + "/Single_Coloured_Page_With_Fonts_and_Alignments.ppt";
+               hssRichB = new HSLFSlideShow(filename);
+               ssRichB = new SlideShow(hssRichB);
        }
 
        /**
@@ -64,7 +71,7 @@ public class TestRichTextRun extends TestCase {
         *  on a rich text run
         */
        public void testBoldRich() throws Exception {
-               Slide slideOneR = ssRich.getSlides()[0];
+               Slide slideOneR = ssRichA.getSlides()[0];
                TextRun[] textRunsR = slideOneR.getTextRuns();
                RichTextRun[] rtrs = textRunsR[1].getRichTextRuns();
                assertEquals(3, rtrs.length);
@@ -85,4 +92,64 @@ public class TestRichTextRun extends TestCase {
                assertFalse(rtrs[0].isBold());
                assertFalse(rtrs[1].isBold());
        }
+       
+       /**
+        * Tests getting and setting the font size on rich and non
+        *  rich text runs
+        */
+       public void testFontSize() throws Exception {
+               Slide slideOne = ss.getSlides()[0];
+               TextRun[] textRuns = slideOne.getTextRuns();
+               RichTextRun rtr = textRuns[0].getRichTextRuns()[0];
+               
+               Slide slideOneR = ssRichB.getSlides()[0];
+               TextRun[] textRunsR = slideOneR.getTextRuns();
+               RichTextRun rtrRa = textRunsR[0].getRichTextRuns()[0];
+               RichTextRun rtrRb = textRunsR[1].getRichTextRuns()[0];
+               RichTextRun rtrRc = textRunsR[1].getRichTextRuns()[3];
+
+               // Start off with rich one
+               // First run has defaults
+               assertEquals(-1, rtrRa.getFontSize());
+               assertEquals(null, rtrRa.getFontName());
+               // Second is size 20, default font
+               assertEquals(20, rtrRb.getFontSize());
+               assertEquals(null, rtrRb.getFontName());
+               // Third is size 24, alt font
+               assertEquals(24, rtrRc.getFontSize());
+               assertEquals("Times New Roman", rtrRc.getFontName());
+               
+               // Change 2nd to different size and font
+               assertEquals(2, ssRichB.getFontCollection().getChildRecords().length); // Default + TNR
+               rtrRb.setFontSize(18);
+               rtrRb.setFontName("Courier");
+               assertEquals(3, ssRichB.getFontCollection().getChildRecords().length); // Default + TNR + Courier
+               assertEquals(18, rtrRb.getFontSize());
+               assertEquals("Courier", rtrRb.getFontName());
+               
+               
+               // Now do non rich one
+               assertEquals(-1, rtr.getFontSize());
+               assertEquals(null, rtr.getFontName());
+               assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
+               assertNull(rtr._getRawCharacterStyle());
+               assertNull(rtr._getRawParagraphStyle());
+               
+               // Change Font size
+               rtr.setFontSize(99);
+               assertEquals(99, rtr.getFontSize());
+               assertEquals(null, rtr.getFontName());
+               assertNotNull(rtr._getRawCharacterStyle());
+               assertNotNull(rtr._getRawParagraphStyle());
+               assertEquals(1, ss.getFontCollection().getChildRecords().length); // Default
+               
+               // Change Font size and name
+               rtr.setFontSize(25);
+               rtr.setFontName("Times New Roman");
+               assertEquals(25, rtr.getFontSize());
+               assertEquals("Times New Roman", rtr.getFontName());
+               assertNotNull(rtr._getRawCharacterStyle());
+               assertNotNull(rtr._getRawParagraphStyle());
+               assertEquals(2, ss.getFontCollection().getChildRecords().length);
+       }
 }