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
This commit is contained in:
Nick Burch 2006-03-18 18:56:38 +00:00
parent 7ce58ff9d1
commit 8b1721c749
3 changed files with 80 additions and 7 deletions

View 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 {

View 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);
}
}