From 9904ebb14d3ff4126922e07d80c3e387f3d7d07a Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sat, 18 Mar 2006 18:56:38 +0000 Subject: [PATCH] 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 --- ...oloured_Page_With_Fonts_and_Alignments.ppt | Bin 0 -> 10240 bytes .../poi/hslf/record/TestFontCollection.java | 8 +- .../poi/hslf/usermodel/TestRichTextRun.java | 79 ++++++++++++++++-- 3 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/data/Single_Coloured_Page_With_Fonts_and_Alignments.ppt 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 0000000000000000000000000000000000000000..a177642c9ec62b4bb75d5009087dbc36d3f88121 GIT binary patch literal 10240 zcmeHN4RBml6+Z91O|nT--Zq;+TeN-D3aKO|HXWvnP6ATH)57F9AhvJ7~q^h+;#DAmNJUQEM8H~p7#OiVe}L;7pzxF}`P zrsnCDu+sfYm@k6albAb~I%D}01y3~$$)U|bse7Qhi8Tv(F){^2 z^J)htdPNF6-WjiQguB~p#DbG51`XCXB=|-HA47IE}j$bCzvQ22al-}vTjNSe#&cah3Gy<^ZLk61s zkEoWM;YX}DOz`msWcF*EIM)naWX@}h@#H{i_P>cOK3B5#C&)_vW7Xox`3p*hxGlRX znlWgu)cQ1SosYElZrZV59{bVf?y9){QPvd0mba~L4w565G634-u(cS^uK>CVYM`?5 zj3KGLLAwdxS*l>=I{}6SrB4o8TwazwAl^H!68->lASNlZX%&MJzH>>TY)3dEM^=X$LYz}S={R{(R083-zxzeE8(=yA^6mh(F zpeKw#yAGqb*<7Bv02GL0dN`a#&&5z6vfaKL&-R{Z%E7;MkL#rR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&k1yqeK)kYZ? z=lki4E2EvsL@E(UJF6p+Xs7G6CI;MOYa$v?OAGol8&>V6Jj9!B>fFNU8X7Mu!qBnJh=FAqP`E zE%ip6IR<-(do$?xanKAX8;RVn?1x*+d2Q?Q9ngy@@`Z7SYSb^OQ@*4n^(hInhNa@r z`=c?vo*GBh{MYT&)?S#mb|X?E%JTlo!01aE)~P)=wpVy3rEjgufR$sNv@{b-cPQ@@ z+S2chPc$p(R^UwFN#OZJ$!kQl`plMj>!zRDGqhJQNA%iBfvZFyY+S4!kLVXi>g-28S11{dX>Hajd_|-b`2iJo-r-Pv}6BdHKIcAUL)L7nmlnA zRkg`lb&eNmRCsNBEN!TZrxW)$H9EE)2aBUnP0_WlQm^nqevR1Ens2En#K^m->Rfmn z*QijB$=otC{^<4bYR}WyqqWz5$9_`kc8`kjP*c$YWuVXzjdX0E$R1ww*5O!G8c#hL zU29EhLo5jFGR312zk-t2SZsO!YFna;ar=ABe&;BQXIT`aR@;(IMiR;58 zJPnv%G2dc-g|tNaQ1kHg@+^*79dAr^CS5n~wDlzL9m4#JwC#yxXHQ4sLZC`k{%%g0 zX))GdrD{|qYyYfiN;dXWMwa4w4g{dy)LCa8l&E;;(?ZMKNVq?ic9yxRXm?zFM0iKY z1PNj_SdlOF;k?W7D^bchC*^i2acKs2aYD`1X?J`3V&Swqsvi4kzP4Dj%f;_dxNS_0 zc8cs*HIRBw*pZf;vyDU`GT literal 0 HcmV?d00001 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); + } } -- 2.39.5