1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package fvt.uno.sw.puretext;
23 
24 import static org.junit.Assert.*;
25 
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.openoffice.test.common.FileUtil;
31 import org.openoffice.test.common.Testspace;
32 import org.openoffice.test.uno.UnoApp;
33 //import org.openoffice.test.vcl.Tester.*;
34 import com.sun.star.text.*;
35 import com.sun.star.beans.*;
36 import com.sun.star.frame.XStorable;
37 import com.sun.star.uno.UnoRuntime;
38 
39 public class CharacterRotationAndScaleWidth {
40 	private static final UnoApp app = new UnoApp();
41 	XText xText = null;
42 
43 	@Before
setUp()44 	public void setUp() throws Exception {
45 		app.start();
46 
47 	}
48 
49 	@After
tearDown()50 	public void tearDown() throws Exception {
51 		app.close();
52 	}
53 
54 	@Test
testCharacterRotationZeroSetting()55 	public void testCharacterRotationZeroSetting() throws Exception {
56 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
57 		xText = xTextDocument.getText();
58 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
59 				+ "and we all love our home very much!!!");
60 		// create text cursor for selecting and formatting text
61 		XTextCursor xTextCursor = xText.createTextCursor();
62 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
63 		xTextCursor.gotoStart(false);
64 		xTextCursor.goRight((short) 102, true);
65 		xCursorProps.setPropertyValue("CharRotation", (short)0);
66 		xCursorProps.setPropertyValue("CharScaleWidth", (short)150);
67 		//save to odt
68 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
69 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
70 		aStoreProperties_odt[0] = new PropertyValue();
71 		aStoreProperties_odt[1] = new PropertyValue();
72 		aStoreProperties_odt[0].Name = "Override";
73 		aStoreProperties_odt[0].Value = true;
74 		aStoreProperties_odt[1].Name = "FilterName";
75 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
76 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
77 		//save to doc
78 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
79 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
80 		aStoreProperties_doc[0] = new PropertyValue();
81 		aStoreProperties_doc[1] = new PropertyValue();
82 		aStoreProperties_doc[0].Name = "Override";
83 		aStoreProperties_doc[0].Value = true;
84 		aStoreProperties_doc[1].Name = "FilterName";
85 		aStoreProperties_doc[1].Value = "MS Word 97";
86 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
87 		app.closeDocument(xTextDocument);
88 
89 		//reopen the document and assert character rotation and scale width
90 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
91 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
92 		//verify set property
93 		assertEquals("assert character rotation ",(short)0,xCursorProps_assert_odt.getPropertyValue("CharRotation"));
94 		assertEquals("assert character rotation ",(short)150,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth"));
95 
96 		//reopen the document and assert row height setting
97 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
98 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
99 		//verify set property
100 		assertEquals("assert character rotation ",(short)0,xCursorProps_assert_doc.getPropertyValue("CharRotation"));
101 		assertEquals("assert character rotation ",(short)150,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth"));
102 	}
103 	@Test
testCharacterRotationNinetySetting()104 	public void testCharacterRotationNinetySetting() throws Exception {
105 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
106 		xText = xTextDocument.getText();
107 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
108 				+ "and we all love our home very much!!!");
109 		// create text cursor for selecting and formatting text
110 		XTextCursor xTextCursor = xText.createTextCursor();
111 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
112 		xTextCursor.gotoStart(false);
113 		xTextCursor.goRight((short) 102, true);
114 		xCursorProps.setPropertyValue("CharRotation", (short)900);
115 		xCursorProps.setPropertyValue("CharScaleWidth", (short)200);
116 		xCursorProps.setPropertyValue("CharRotationIsFitToLine", true);
117 		//save to odt
118 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
119 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
120 		aStoreProperties_odt[0] = new PropertyValue();
121 		aStoreProperties_odt[1] = new PropertyValue();
122 		aStoreProperties_odt[0].Name = "Override";
123 		aStoreProperties_odt[0].Value = true;
124 		aStoreProperties_odt[1].Name = "FilterName";
125 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
126 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
127 		//save to doc
128 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
129 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
130 		aStoreProperties_doc[0] = new PropertyValue();
131 		aStoreProperties_doc[1] = new PropertyValue();
132 		aStoreProperties_doc[0].Name = "Override";
133 		aStoreProperties_doc[0].Value = true;
134 		aStoreProperties_doc[1].Name = "FilterName";
135 		aStoreProperties_doc[1].Value = "MS Word 97";
136 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
137 		app.closeDocument(xTextDocument);
138 
139 		//reopen the document and assert character rotation and scale width
140 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
141 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
142 		//verify set property
143 		assertEquals("assert character rotation ",(short)900,xCursorProps_assert_odt.getPropertyValue("CharRotation"));
144 		assertEquals("assert character rotation ",(short)200,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth"));
145 		assertEquals("assert character rotation ",true,xCursorProps_assert_odt.getPropertyValue("CharRotationIsFitToLine"));
146 
147 		//reopen the document and assert row height setting
148 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
149 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
150 		//verify set property
151 		assertEquals("assert character rotation ",(short)900,xCursorProps_assert_doc.getPropertyValue("CharRotation"));
152 		assertEquals("assert character rotation ",(short)200,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth"));
153 		assertEquals("assert character rotation ",true,xCursorProps_assert_odt.getPropertyValue("CharRotationIsFitToLine"));
154 	}
155 	//test character rotation 270 degree
156 	@Test
157 	@Ignore("Bug #120673 - character rotation changes to 90 from 270 degrees when saving to doc")
testCharacterRotationDefineSetting()158 	public void testCharacterRotationDefineSetting() throws Exception {
159 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
160 		xText = xTextDocument.getText();
161 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
162 				+ "and we all love our home very much!!!");
163 		// create text cursor for selecting and formatting text
164 		XTextCursor xTextCursor = xText.createTextCursor();
165 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
166 		xTextCursor.gotoStart(false);
167 		xTextCursor.goRight((short) 102, true);
168 		xCursorProps.setPropertyValue("CharRotation", (short)2700);
169 		xCursorProps.setPropertyValue("CharScaleWidth", (short)300);
170 		//save to odt
171 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
172 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
173 		aStoreProperties_odt[0] = new PropertyValue();
174 		aStoreProperties_odt[1] = new PropertyValue();
175 		aStoreProperties_odt[0].Name = "Override";
176 		aStoreProperties_odt[0].Value = true;
177 		aStoreProperties_odt[1].Name = "FilterName";
178 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
179 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
180 		//save to doc
181 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
182 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
183 		aStoreProperties_doc[0] = new PropertyValue();
184 		aStoreProperties_doc[1] = new PropertyValue();
185 		aStoreProperties_doc[0].Name = "Override";
186 		aStoreProperties_doc[0].Value = true;
187 		aStoreProperties_doc[1].Name = "FilterName";
188 		aStoreProperties_doc[1].Value = "MS Word 97";
189 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
190 		app.closeDocument(xTextDocument);
191 
192 		//reopen the document and assert character rotation and scale width
193 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
194 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
195 		//verify set property
196 		assertEquals("assert character rotation ",(short)2700,xCursorProps_assert_odt.getPropertyValue("CharRotation"));
197 		assertEquals("assert character rotation ",(short)300,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth"));
198 
199 		//reopen the document and assert row height setting
200 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
201 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
202 		//verify set property
203 		assertEquals("assert character rotation ",(short)2700,xCursorProps_assert_doc.getPropertyValue("CharRotation"));
204 		assertEquals("assert character rotation ",(short)300,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth"));
205 	}
206 }
207