From: Nick Burch Date: Sat, 18 Mar 2006 18:56:38 +0000 (+0000) Subject: Tests for getting and changing the font of a rich text run X-Git-Tag: REL_3_0_ALPHA3~165 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9904ebb14d3ff4126922e07d80c3e387f3d7d07a;p=poi.git Tests for getting and changing the font of a rich text run git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@386873 13f79535-47bb-0310-9956-ffa450edef68 --- 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 index 0000000000..a177642c9e Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hslf/data/Single_Coloured_Page_With_Fonts_and_Alignments.ppt differ diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java index eb759a5689..7e256853d5 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestFontCollection.java @@ -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 { diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java index 6bb47673e7..c2dbe5731d 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestRichTextRun.java @@ -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); + } }