1*eba4d44aSLiu Zhe package fvt.uno.sw.paragraph; 2*eba4d44aSLiu Zhe 3*eba4d44aSLiu Zhe import static org.junit.Assert.*; 4*eba4d44aSLiu Zhe 5*eba4d44aSLiu Zhe import org.junit.After; 6*eba4d44aSLiu Zhe import org.junit.Before; 7*eba4d44aSLiu Zhe import org.junit.Test; 8*eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil; 9*eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace; 10*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp; 11*eba4d44aSLiu Zhe 12*eba4d44aSLiu Zhe import com.sun.star.style.DropCapFormat; 13*eba4d44aSLiu Zhe import com.sun.star.text.*; 14*eba4d44aSLiu Zhe import com.sun.star.beans.*; 15*eba4d44aSLiu Zhe import com.sun.star.frame.XStorable; 16*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime; 17*eba4d44aSLiu Zhe 18*eba4d44aSLiu Zhe public class ParagraphDropcap { 19*eba4d44aSLiu Zhe private static final UnoApp app = new UnoApp(); 20*eba4d44aSLiu Zhe XText xText = null; 21*eba4d44aSLiu Zhe 22*eba4d44aSLiu Zhe @Before 23*eba4d44aSLiu Zhe public void setUp() throws Exception { 24*eba4d44aSLiu Zhe app.start(); 25*eba4d44aSLiu Zhe 26*eba4d44aSLiu Zhe } 27*eba4d44aSLiu Zhe 28*eba4d44aSLiu Zhe @After 29*eba4d44aSLiu Zhe public void tearDown() throws Exception { 30*eba4d44aSLiu Zhe app.close(); 31*eba4d44aSLiu Zhe } 32*eba4d44aSLiu Zhe /* 33*eba4d44aSLiu Zhe * test paragraph background color 34*eba4d44aSLiu Zhe * 1.new a text document 35*eba4d44aSLiu Zhe * 2.insert some text 36*eba4d44aSLiu Zhe * 3.set paragraph drop 37*eba4d44aSLiu Zhe * 4.save and close the document 38*eba4d44aSLiu Zhe * 5.reload the saved document and check the paragraph drop cap 39*eba4d44aSLiu Zhe */ 40*eba4d44aSLiu Zhe @Test 41*eba4d44aSLiu Zhe public void testParagraphDropcapSetting() throws Exception { 42*eba4d44aSLiu Zhe 43*eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 44*eba4d44aSLiu Zhe xText = xTextDocument.getText(); 45*eba4d44aSLiu Zhe xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" + 46*eba4d44aSLiu Zhe "Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!"); 47*eba4d44aSLiu Zhe // create text cursor for selecting and formatting text 48*eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 49*eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 50*eba4d44aSLiu Zhe //set paragraph dropcaps 51*eba4d44aSLiu Zhe DropCapFormat dropcapFormat=new DropCapFormat(); 52*eba4d44aSLiu Zhe dropcapFormat.Lines=3; 53*eba4d44aSLiu Zhe dropcapFormat.Distance=101; 54*eba4d44aSLiu Zhe dropcapFormat.Count=9; 55*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("DropCapFormat",dropcapFormat); 56*eba4d44aSLiu Zhe //xCursorProps.setPropertyValue("DropCapWholeWord",true); 57*eba4d44aSLiu Zhe //save to odt 58*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 59*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 60*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 61*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 62*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 63*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 64*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 65*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 66*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 67*eba4d44aSLiu Zhe //save to doc 68*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 69*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 70*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 71*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 72*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 73*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 74*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 75*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 76*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 77*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 78*eba4d44aSLiu Zhe 79*eba4d44aSLiu Zhe //reopen the document 80*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 81*eba4d44aSLiu Zhe XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 82*eba4d44aSLiu Zhe //verify paragraph dropcap 83*eba4d44aSLiu Zhe DropCapFormat dropcapFormat_assert_odt = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_odt.getPropertyValue("DropCapFormat")); 84*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",9,dropcapFormat_assert_odt.Count); 85*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_odt.Lines); 86*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_odt.Distance); 87*eba4d44aSLiu Zhe 88*eba4d44aSLiu Zhe //reopen the document 89*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 90*eba4d44aSLiu Zhe XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 91*eba4d44aSLiu Zhe //verify paragraph dropcap 92*eba4d44aSLiu Zhe DropCapFormat dropcapFormat_assert_doc = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_doc.getPropertyValue("DropCapFormat")); 93*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",9,dropcapFormat_assert_doc.Count); 94*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_doc.Lines); 95*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_doc.Distance); 96*eba4d44aSLiu Zhe } 97*eba4d44aSLiu Zhe @Test 98*eba4d44aSLiu Zhe public void testParagraphDropcapWholewordSetting() throws Exception { 99*eba4d44aSLiu Zhe 100*eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 101*eba4d44aSLiu Zhe xText = xTextDocument.getText(); 102*eba4d44aSLiu Zhe xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" + 103*eba4d44aSLiu Zhe "Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!"); 104*eba4d44aSLiu Zhe // create text cursor for selecting and formatting text 105*eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 106*eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 107*eba4d44aSLiu Zhe //set paragraph dropcaps 108*eba4d44aSLiu Zhe DropCapFormat dropcapFormat=new DropCapFormat(); 109*eba4d44aSLiu Zhe dropcapFormat.Lines=3; 110*eba4d44aSLiu Zhe dropcapFormat.Distance=101; 111*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("DropCapFormat",dropcapFormat); 112*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("DropCapWholeWord",true); 113*eba4d44aSLiu Zhe //save to odt 114*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 115*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 116*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 117*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 118*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 119*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 120*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 121*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 122*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 123*eba4d44aSLiu Zhe //save to doc 124*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 125*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 126*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 127*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 128*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 129*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 130*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 131*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 132*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 133*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 134*eba4d44aSLiu Zhe 135*eba4d44aSLiu Zhe //reopen the document 136*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 137*eba4d44aSLiu Zhe XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 138*eba4d44aSLiu Zhe //verify paragraph dropcap 139*eba4d44aSLiu Zhe DropCapFormat dropcapFormat_assert_odt = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_odt.getPropertyValue("DropCapFormat")); 140*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",true,xCursorProps_Assert_odt.getPropertyValue("DropCapWholeWord")); 141*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_odt.Lines); 142*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_odt.Distance); 143*eba4d44aSLiu Zhe 144*eba4d44aSLiu Zhe //reopen the document 145*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 146*eba4d44aSLiu Zhe XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 147*eba4d44aSLiu Zhe //verify paragraph dropcap 148*eba4d44aSLiu Zhe DropCapFormat dropcapFormat_assert_doc = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_doc.getPropertyValue("DropCapFormat")); 149*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_doc.Lines); 150*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_doc.Distance); 151*eba4d44aSLiu Zhe //when save to doc,the DropCapWholeWord option will disable,and enable dropcapFormat.count 152*eba4d44aSLiu Zhe assertEquals("assert paragraph dropcaps",false,xCursorProps_Assert_doc.getPropertyValue("DropCapWholeWord")); 153*eba4d44aSLiu Zhe } 154*eba4d44aSLiu Zhe } 155