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