📄 testtextrun.java
字号:
assertNull(rtrA._getRawParagraphStyle()); assertNotNull(rtrB._getRawCharacterStyle()); assertNotNull(rtrB._getRawParagraphStyle()); assertNotNull(rtrC._getRawCharacterStyle()); assertNotNull(rtrC._getRawParagraphStyle()); assertNotNull(rtrD._getRawCharacterStyle()); assertNotNull(rtrD._getRawParagraphStyle()); // Same paragraph styles assertEquals(rtrB._getRawParagraphStyle(), rtrC._getRawParagraphStyle()); assertEquals(rtrB._getRawParagraphStyle(), rtrD._getRawParagraphStyle()); // Different char styles assertFalse( rtrB._getRawCharacterStyle().equals( rtrC._getRawCharacterStyle() )); assertFalse( rtrB._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() )); assertFalse( rtrC._getRawCharacterStyle().equals( rtrD._getRawCharacterStyle() )); } /** * Tests to ensure that setting the text where the text isn't rich, * ensuring that everything stays with the same default styling */ public void testSetTextWhereNotRich() throws Exception { Slide slideOne = ss.getSlides()[0]; TextRun[] textRuns = slideOne.getTextRuns(); TextRun trB = textRuns[1]; assertEquals(1, trB.getRichTextRuns().length); RichTextRun rtrB = trB.getRichTextRuns()[0]; assertEquals(trB.getText(), rtrB.getText()); assertNull(rtrB._getRawCharacterStyle()); assertNull(rtrB._getRawParagraphStyle()); // Change text via normal trB.setText("Test Foo Test"); rtrB = trB.getRichTextRuns()[0]; assertEquals("Test Foo Test", trB.getText()); assertEquals("Test Foo Test", rtrB.getText()); assertNull(rtrB._getRawCharacterStyle()); assertNull(rtrB._getRawParagraphStyle()); } /** * Tests to ensure that setting the text where the text is rich * sets everything to the same styling */ public void testSetTextWhereRich() throws Exception { Slide slideOne = ssRich.getSlides()[0]; TextRun[] textRuns = slideOne.getTextRuns(); TextRun trB = textRuns[1]; assertEquals(3, trB.getRichTextRuns().length); RichTextRun rtrB = trB.getRichTextRuns()[0]; RichTextRun rtrC = trB.getRichTextRuns()[1]; RichTextRun rtrD = trB.getRichTextRuns()[2]; TextPropCollection tpBP = rtrB._getRawParagraphStyle(); TextPropCollection tpBC = rtrB._getRawCharacterStyle(); TextPropCollection tpCP = rtrC._getRawParagraphStyle(); TextPropCollection tpCC = rtrC._getRawCharacterStyle(); TextPropCollection tpDP = rtrD._getRawParagraphStyle(); TextPropCollection tpDC = rtrD._getRawCharacterStyle(); assertEquals(trB.getText().substring(0, 30), rtrB.getText()); assertNotNull(tpBP); assertNotNull(tpBC); assertNotNull(tpCP); assertNotNull(tpCC); assertNotNull(tpDP); assertNotNull(tpDC); assertTrue(tpBP.equals(tpCP)); assertTrue(tpBP.equals(tpDP)); assertTrue(tpCP.equals(tpDP)); assertFalse(tpBC.equals(tpCC)); assertFalse(tpBC.equals(tpDC)); assertFalse(tpCC.equals(tpDC)); // Change text via normal trB.setText("Test Foo Test"); // Ensure now have first style assertEquals(1, trB.getRichTextRuns().length); rtrB = trB.getRichTextRuns()[0]; assertEquals("Test Foo Test", trB.getText()); assertEquals("Test Foo Test", rtrB.getText()); assertNotNull(rtrB._getRawCharacterStyle()); assertNotNull(rtrB._getRawParagraphStyle()); assertEquals( tpBP, rtrB._getRawParagraphStyle() ); assertEquals( tpBC, rtrB._getRawCharacterStyle() ); } /** * Test to ensure the right stuff happens if we change the text * in a rich text run, that doesn't happen to actually be rich */ public void testChangeTextInRichTextRunNonRich() throws Exception { Slide slideOne = ss.getSlides()[0]; TextRun[] textRuns = slideOne.getTextRuns(); TextRun trB = textRuns[1]; assertEquals(1, trB.getRichTextRuns().length); RichTextRun rtrB = trB.getRichTextRuns()[0]; assertEquals(trB.getText(), rtrB.getText()); assertNull(rtrB._getRawCharacterStyle()); assertNull(rtrB._getRawParagraphStyle()); // Change text via rich rtrB.setText("Test Test Test"); assertEquals("Test Test Test", trB.getText()); assertEquals("Test Test Test", rtrB.getText()); // Will now have dummy props assertNotNull(rtrB._getRawCharacterStyle()); assertNotNull(rtrB._getRawParagraphStyle()); } /** * Tests to ensure changing the text within rich text runs works * correctly */ public void testChangeTextInRichTextRun() throws Exception { Slide slideOne = ssRich.getSlides()[0]; TextRun[] textRuns = slideOne.getTextRuns(); TextRun trB = textRuns[1]; assertEquals(3, trB.getRichTextRuns().length); // We start with 3 text runs, each with their own set of styles, // but all sharing the same paragraph styles RichTextRun rtrB = trB.getRichTextRuns()[0]; RichTextRun rtrC = trB.getRichTextRuns()[1]; RichTextRun rtrD = trB.getRichTextRuns()[2]; TextPropCollection tpBP = rtrB._getRawParagraphStyle(); TextPropCollection tpBC = rtrB._getRawCharacterStyle(); TextPropCollection tpCP = rtrC._getRawParagraphStyle(); TextPropCollection tpCC = rtrC._getRawCharacterStyle(); TextPropCollection tpDP = rtrD._getRawParagraphStyle(); TextPropCollection tpDC = rtrD._getRawCharacterStyle(); // Check text and stylings assertEquals(trB.getText().substring(0, 30), rtrB.getText()); assertNotNull(tpBP); assertNotNull(tpBC); assertNotNull(tpCP); assertNotNull(tpCC); assertNotNull(tpDP); assertNotNull(tpDC); assertTrue(tpBP.equals(tpCP)); assertTrue(tpBP.equals(tpDP)); assertTrue(tpCP.equals(tpDP)); assertFalse(tpBC.equals(tpCC)); assertFalse(tpBC.equals(tpDC)); assertFalse(tpCC.equals(tpDC)); // Check text in the rich runs assertEquals("This is the subtitle, in bold\n", rtrB.getText()); assertEquals("This bit is blue and italic\n", rtrC.getText()); assertEquals("This bit is red (normal)", rtrD.getText()); String newBText = "New Subtitle, will still be bold\n"; String newCText = "New blue and italic text\n"; String newDText = "Funky new normal red text"; rtrB.setText(newBText); rtrC.setText(newCText); rtrD.setText(newDText); assertEquals(newBText, rtrB.getText()); assertEquals(newCText, rtrC.getText()); assertEquals(newDText, rtrD.getText()); assertEquals(newBText + newCText + newDText, trB.getText()); // The styles should have been updated for the new sizes assertEquals(newBText.length(), tpBC.getCharactersCovered()); assertEquals(newCText.length(), tpCC.getCharactersCovered()); assertEquals(newDText.length()+1, tpDC.getCharactersCovered()); // Last one is always one larger assertEquals( newBText.length() + newCText.length() + newDText.length(), tpBP.getCharactersCovered() ); // Paragraph style should be sum of text length assertEquals(newBText.length() + newCText.length() + newDText.length(), tpBP.getCharactersCovered()); // Check stylings still as expected TextPropCollection ntpBC = rtrB._getRawCharacterStyle(); TextPropCollection ntpCC = rtrC._getRawCharacterStyle(); TextPropCollection ntpDC = rtrD._getRawCharacterStyle(); assertEquals(tpBC.getTextPropList(), ntpBC.getTextPropList()); assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList()); assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList()); } /** * Test case for Bug 41015. * * In some cases RichTextRun.getText() threw StringIndexOutOfBoundsException because * of the wrong list of potential paragraph properties defined in StyleTextPropAtom. * */ public void testBug41015() throws Exception { RichTextRun[] rt; SlideShow ppt = new SlideShow(new HSLFSlideShow(System.getProperty("HSLF.testdata.path") + "/bug-41015.ppt")); Slide sl = ppt.getSlides()[0]; TextRun[] txt = sl.getTextRuns(); assertEquals(2, txt.length); rt = txt[0].getRichTextRuns(); assertEquals(1, rt.length); assertEquals(0, rt[0].getIndentLevel()); assertEquals("sdfsdfsdf", rt[0].getText()); rt = txt[1].getRichTextRuns(); assertEquals(2, rt.length); assertEquals(0, rt[0].getIndentLevel()); assertEquals("Sdfsdfsdf\n" + "Dfgdfg\n" + "Dfgdfgdfg\n", rt[0].getText()); assertEquals(1, rt[1].getIndentLevel()); assertEquals("Sdfsdfs\n" + "Sdfsdf\n", rt[1].getText()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -