1*eba4d44aSLiu Zhe package fvt.uno.sw.puretext; 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 import com.sun.star.text.*; 12*eba4d44aSLiu Zhe import com.sun.star.beans.*; 13*eba4d44aSLiu Zhe import com.sun.star.frame.XStorable; 14*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime; 15*eba4d44aSLiu Zhe 16*eba4d44aSLiu Zhe public class CharacterSpacing { 17*eba4d44aSLiu Zhe private static final UnoApp app = new UnoApp(); 18*eba4d44aSLiu Zhe XText xText = null; 19*eba4d44aSLiu Zhe 20*eba4d44aSLiu Zhe @Before 21*eba4d44aSLiu Zhe public void setUp() throws Exception { 22*eba4d44aSLiu Zhe app.start(); 23*eba4d44aSLiu Zhe 24*eba4d44aSLiu Zhe } 25*eba4d44aSLiu Zhe 26*eba4d44aSLiu Zhe @After 27*eba4d44aSLiu Zhe public void tearDown() throws Exception { 28*eba4d44aSLiu Zhe app.close(); 29*eba4d44aSLiu Zhe } 30*eba4d44aSLiu Zhe 31*eba4d44aSLiu Zhe @Test 32*eba4d44aSLiu Zhe public void testCharacterSpacing_Default() throws Exception { 33*eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 34*eba4d44aSLiu Zhe xText = xTextDocument.getText(); 35*eba4d44aSLiu Zhe xText.setString("we are Chinese,they are American.We are all living in one earth!" 36*eba4d44aSLiu Zhe + "and we all love our home very much!!!"); 37*eba4d44aSLiu Zhe // create text cursor for selecting and formatting text 38*eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 39*eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 40*eba4d44aSLiu Zhe xTextCursor.gotoStart(false); 41*eba4d44aSLiu Zhe xTextCursor.goRight((short) 102, true); 42*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharAutoKerning", true); 43*eba4d44aSLiu Zhe //save to odt 44*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 45*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 46*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 47*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 48*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 49*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 50*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 51*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 52*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 53*eba4d44aSLiu Zhe //save to doc 54*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 55*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 56*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 57*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 58*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 59*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 60*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 61*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 62*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 63*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 64*eba4d44aSLiu Zhe 65*eba4d44aSLiu Zhe //reopen the document and assert row height setting 66*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 67*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 68*eba4d44aSLiu Zhe //verify set property 69*eba4d44aSLiu Zhe assertEquals("assert character color",true,xCursorProps_assert_odt.getPropertyValue("CharAutoKerning")); 70*eba4d44aSLiu Zhe 71*eba4d44aSLiu Zhe //reopen the document and assert row height setting 72*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 73*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 74*eba4d44aSLiu Zhe //verify set property 75*eba4d44aSLiu Zhe assertEquals("assert character color",true,xCursorProps_assert_doc.getPropertyValue("CharAutoKerning")); 76*eba4d44aSLiu Zhe } 77*eba4d44aSLiu Zhe @Test 78*eba4d44aSLiu Zhe public void testCharacterSpacing_Expand() throws Exception { 79*eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 80*eba4d44aSLiu Zhe xText = xTextDocument.getText(); 81*eba4d44aSLiu Zhe xText.setString("we are Chinese,they are American.We are all living in one earth!" 82*eba4d44aSLiu Zhe + "and we all love our home very much!!!"); 83*eba4d44aSLiu Zhe // create text cursor for selecting and formatting text 84*eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 85*eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 86*eba4d44aSLiu Zhe xTextCursor.gotoStart(false); 87*eba4d44aSLiu Zhe xTextCursor.goRight((short) 102, true); 88*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharKerning", (short)101); 89*eba4d44aSLiu Zhe //save to odt 90*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 91*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 92*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 93*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 94*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 95*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 96*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 97*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 98*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 99*eba4d44aSLiu Zhe //save to doc 100*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 101*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 102*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 103*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 104*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 105*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 106*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 107*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 108*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 109*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 110*eba4d44aSLiu Zhe 111*eba4d44aSLiu Zhe //reopen the document and assert row height setting 112*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 113*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 114*eba4d44aSLiu Zhe //verify set property 115*eba4d44aSLiu Zhe assertEquals("assert character color",(short)101,xCursorProps_assert_odt.getPropertyValue("CharKerning")); 116*eba4d44aSLiu Zhe 117*eba4d44aSLiu Zhe //reopen the document and assert row height setting 118*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 119*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 120*eba4d44aSLiu Zhe //verify set property 121*eba4d44aSLiu Zhe assertEquals("assert character color",(short)101,xCursorProps_assert_doc.getPropertyValue("CharKerning")); 122*eba4d44aSLiu Zhe } 123*eba4d44aSLiu Zhe @Test 124*eba4d44aSLiu Zhe public void testCharacterSpacing_Condens() throws Exception { 125*eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 126*eba4d44aSLiu Zhe xText = xTextDocument.getText(); 127*eba4d44aSLiu Zhe xText.setString("we are Chinese,they are American.We are all living in one earth!" 128*eba4d44aSLiu Zhe + "and we all love our home very much!!!"); 129*eba4d44aSLiu Zhe // create text cursor for selecting and formatting text 130*eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 131*eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 132*eba4d44aSLiu Zhe xTextCursor.gotoStart(false); 133*eba4d44aSLiu Zhe xTextCursor.goRight((short) 102, true); 134*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharKerning", (short)-101); 135*eba4d44aSLiu Zhe //save to odt 136*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 137*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 138*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 139*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 140*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 141*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 142*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 143*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 144*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 145*eba4d44aSLiu Zhe //save to doc 146*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 147*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 148*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 149*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 150*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 151*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 152*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 153*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 154*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 155*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 156*eba4d44aSLiu Zhe 157*eba4d44aSLiu Zhe //reopen the document and assert row height setting 158*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 159*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 160*eba4d44aSLiu Zhe //verify set property 161*eba4d44aSLiu Zhe assertEquals("assert character color",(short)-101,xCursorProps_assert_odt.getPropertyValue("CharKerning")); 162*eba4d44aSLiu Zhe 163*eba4d44aSLiu Zhe //reopen the document and assert row height setting 164*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 165*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 166*eba4d44aSLiu Zhe //verify set property 167*eba4d44aSLiu Zhe assertEquals("assert character color",(short)-101,xCursorProps_assert_doc.getPropertyValue("CharKerning")); 168*eba4d44aSLiu Zhe } 169*eba4d44aSLiu Zhe } 170