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.Ignore; 8*eba4d44aSLiu Zhe import org.junit.Test; 9*eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil; 10*eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace; 11*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp; 12*eba4d44aSLiu Zhe //import org.openoffice.test.vcl.Tester.*; 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 CharacterRotationAndScaleWidth { 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 34*eba4d44aSLiu Zhe public void testCharacterRotationZeroSetting() throws Exception { 35*eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 36*eba4d44aSLiu Zhe xText = xTextDocument.getText(); 37*eba4d44aSLiu Zhe xText.setString("we are Chinese,they are American.We are all living in one earth!" 38*eba4d44aSLiu Zhe + "and we all love our home very much!!!"); 39*eba4d44aSLiu Zhe // create text cursor for selecting and formatting text 40*eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 41*eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 42*eba4d44aSLiu Zhe xTextCursor.gotoStart(false); 43*eba4d44aSLiu Zhe xTextCursor.goRight((short) 102, true); 44*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharRotation", (short)0); 45*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharScaleWidth", (short)150); 46*eba4d44aSLiu Zhe //save to odt 47*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 48*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 49*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 50*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 51*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 52*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 53*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 54*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 55*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 56*eba4d44aSLiu Zhe //save to doc 57*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 58*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 59*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 60*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 61*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 62*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 63*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 64*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 65*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 66*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 67*eba4d44aSLiu Zhe 68*eba4d44aSLiu Zhe //reopen the document and assert character rotation and scale width 69*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 70*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 71*eba4d44aSLiu Zhe //verify set property 72*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)0,xCursorProps_assert_odt.getPropertyValue("CharRotation")); 73*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)150,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth")); 74*eba4d44aSLiu Zhe 75*eba4d44aSLiu Zhe //reopen the document and assert row height setting 76*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 77*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 78*eba4d44aSLiu Zhe //verify set property 79*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)0,xCursorProps_assert_doc.getPropertyValue("CharRotation")); 80*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)150,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth")); 81*eba4d44aSLiu Zhe } 82*eba4d44aSLiu Zhe @Test 83*eba4d44aSLiu Zhe public void testCharacterRotationNinetySetting() throws Exception { 84*eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 85*eba4d44aSLiu Zhe xText = xTextDocument.getText(); 86*eba4d44aSLiu Zhe xText.setString("we are Chinese,they are American.We are all living in one earth!" 87*eba4d44aSLiu Zhe + "and we all love our home very much!!!"); 88*eba4d44aSLiu Zhe // create text cursor for selecting and formatting text 89*eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 90*eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 91*eba4d44aSLiu Zhe xTextCursor.gotoStart(false); 92*eba4d44aSLiu Zhe xTextCursor.goRight((short) 102, true); 93*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharRotation", (short)900); 94*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharScaleWidth", (short)200); 95*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharRotationIsFitToLine", true); 96*eba4d44aSLiu Zhe //save to odt 97*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 98*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 99*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 100*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 101*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 102*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 103*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 104*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 105*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 106*eba4d44aSLiu Zhe //save to doc 107*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 108*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 109*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 110*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 111*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 112*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 113*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 114*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 115*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 116*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 117*eba4d44aSLiu Zhe 118*eba4d44aSLiu Zhe //reopen the document and assert character rotation and scale width 119*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 120*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 121*eba4d44aSLiu Zhe //verify set property 122*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)900,xCursorProps_assert_odt.getPropertyValue("CharRotation")); 123*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)200,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth")); 124*eba4d44aSLiu Zhe assertEquals("assert character rotation ",true,xCursorProps_assert_odt.getPropertyValue("CharRotationIsFitToLine")); 125*eba4d44aSLiu Zhe 126*eba4d44aSLiu Zhe //reopen the document and assert row height setting 127*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 128*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 129*eba4d44aSLiu Zhe //verify set property 130*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)900,xCursorProps_assert_doc.getPropertyValue("CharRotation")); 131*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)200,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth")); 132*eba4d44aSLiu Zhe assertEquals("assert character rotation ",true,xCursorProps_assert_odt.getPropertyValue("CharRotationIsFitToLine")); 133*eba4d44aSLiu Zhe } 134*eba4d44aSLiu Zhe //test character rotation 270 degree 135*eba4d44aSLiu Zhe @Test 136*eba4d44aSLiu Zhe @Ignore("Bug #120673 - character rotation changes to 90 from 270 degrees when saving to doc") 137*eba4d44aSLiu Zhe public void testCharacterRotationDefineSetting() throws Exception { 138*eba4d44aSLiu Zhe XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 139*eba4d44aSLiu Zhe xText = xTextDocument.getText(); 140*eba4d44aSLiu Zhe xText.setString("we are Chinese,they are American.We are all living in one earth!" 141*eba4d44aSLiu Zhe + "and we all love our home very much!!!"); 142*eba4d44aSLiu Zhe // create text cursor for selecting and formatting text 143*eba4d44aSLiu Zhe XTextCursor xTextCursor = xText.createTextCursor(); 144*eba4d44aSLiu Zhe XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 145*eba4d44aSLiu Zhe xTextCursor.gotoStart(false); 146*eba4d44aSLiu Zhe xTextCursor.goRight((short) 102, true); 147*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharRotation", (short)2700); 148*eba4d44aSLiu Zhe xCursorProps.setPropertyValue("CharScaleWidth", (short)300); 149*eba4d44aSLiu Zhe //save to odt 150*eba4d44aSLiu Zhe XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 151*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 152*eba4d44aSLiu Zhe aStoreProperties_odt[0] = new PropertyValue(); 153*eba4d44aSLiu Zhe aStoreProperties_odt[1] = new PropertyValue(); 154*eba4d44aSLiu Zhe aStoreProperties_odt[0].Name = "Override"; 155*eba4d44aSLiu Zhe aStoreProperties_odt[0].Value = true; 156*eba4d44aSLiu Zhe aStoreProperties_odt[1].Name = "FilterName"; 157*eba4d44aSLiu Zhe aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 158*eba4d44aSLiu Zhe xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 159*eba4d44aSLiu Zhe //save to doc 160*eba4d44aSLiu Zhe XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 161*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 162*eba4d44aSLiu Zhe aStoreProperties_doc[0] = new PropertyValue(); 163*eba4d44aSLiu Zhe aStoreProperties_doc[1] = new PropertyValue(); 164*eba4d44aSLiu Zhe aStoreProperties_doc[0].Name = "Override"; 165*eba4d44aSLiu Zhe aStoreProperties_doc[0].Value = true; 166*eba4d44aSLiu Zhe aStoreProperties_doc[1].Name = "FilterName"; 167*eba4d44aSLiu Zhe aStoreProperties_doc[1].Value = "MS Word 97"; 168*eba4d44aSLiu Zhe xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 169*eba4d44aSLiu Zhe app.closeDocument(xTextDocument); 170*eba4d44aSLiu Zhe 171*eba4d44aSLiu Zhe //reopen the document and assert character rotation and scale width 172*eba4d44aSLiu Zhe XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 173*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 174*eba4d44aSLiu Zhe //verify set property 175*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)2700,xCursorProps_assert_odt.getPropertyValue("CharRotation")); 176*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)300,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth")); 177*eba4d44aSLiu Zhe 178*eba4d44aSLiu Zhe //reopen the document and assert row height setting 179*eba4d44aSLiu Zhe XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 180*eba4d44aSLiu Zhe XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 181*eba4d44aSLiu Zhe //verify set property 182*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)2700,xCursorProps_assert_doc.getPropertyValue("CharRotation")); 183*eba4d44aSLiu Zhe assertEquals("assert character rotation ",(short)300,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth")); 184*eba4d44aSLiu Zhe } 185*eba4d44aSLiu Zhe } 186