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.Test;
29 import org.openoffice.test.common.FileUtil;
30 import org.openoffice.test.common.Testspace;
31 import org.openoffice.test.uno.UnoApp;
32 import com.sun.star.text.*;
33 import com.sun.star.beans.*;
34 import com.sun.star.frame.XStorable;
35 import com.sun.star.uno.UnoRuntime;
36 
37 public class CharacterFontname {
38 	private static final UnoApp app = new UnoApp();
39 	XText xText = null;
40 
41 	@Before
setUp()42 	public void setUp() throws Exception {
43 		app.start();
44 
45 	}
46 
47 	@After
tearDown()48 	public void tearDown() throws Exception {
49 		app.close();
50 	}
51 	@Test
testCharacterFontSetting()52 	public void testCharacterFontSetting() throws Exception {
53 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
54 		xText = xTextDocument.getText();
55 		xText.setString("We are Chinese,they are American. We are all living in one earth!"
56 				+ "and we all love our home very much!!!We are Chinese,they are American. " +
57 				"We are all living in one earth!We are Chinese,they are American. " +
58 				"We are all living in one earth!We are Chinese,they are American. " +
59 				"We are all living in one earth!We are Chinese,they are American. " +
60 				"We are all living in one earth!We are Chinese,they are American. " +
61 				"We are all living in one earth!We are Chinese,they are American." +
62 				" We are all living in one earth!We are Chinese,they are American. " +
63 				"We are all living in one earth!We are Chinese,they are American. " +
64 				"We are all living in one earth!We are Chinese,they are American. " +
65 				"We are all living in one earth!We are Chinese,they are American. " +
66 				"We are all living in one earth!We are Chinese,they are American. " +
67 				"We are all living in one earth!We are Chinese,they are American. " +
68 				"We are all living in one earth!We are Chinese,they are American. " +
69 				"We are all living in one earth!We are Chinese,they are American. " +
70 				"We are all living in one earth!We are Chinese,they are American. " +
71 				"We are all living in one earth!We are Chinese,they are American. " +
72 				"We are all living in one earth!We are Chinese,they are American. " +
73 				"We are all living in one earth!We are Chinese,they are American. " +
74 				"We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
75 				"We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
76 				"We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
77 				"We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
78 				"We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
79 				"We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " +
80 				"We are all living in one earth!");
81 		// create text cursor for selecting and formatting text
82 		XTextCursor xTextCursor = xText.createTextCursor();
83 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
84 		xTextCursor.gotoStart(false);
85 		xTextCursor.goRight((short) 100, true);
86 		xCursorProps.setPropertyValue("CharFontName", "Times New Roman");
87 		xTextCursor.gotoRange(xTextCursor, false);
88 		xTextCursor.goRight((short) 100, true);
89 		xCursorProps.setPropertyValue("CharFontName", "Arial Black");
90 		xTextCursor.gotoRange(xTextCursor, false);
91 		xTextCursor.goRight((short) 100, true);
92 		xCursorProps.setPropertyValue("CharFontName", "Aharoni");
93 		xTextCursor.gotoRange(xTextCursor, false);
94 		xTextCursor.goRight((short) 100, true);
95 		xCursorProps.setPropertyValue("CharFontName", "Agency FB");
96 		xTextCursor.gotoRange(xTextCursor, false);
97 		xTextCursor.goRight((short) 100, true);
98 		xCursorProps.setPropertyValue("CharFontName", "Algerian");
99 		xTextCursor.gotoRange(xTextCursor, false);
100 		xTextCursor.goRight((short) 100, true);
101 		xCursorProps.setPropertyValue("CharFontName", "Andalus");
102 		xTextCursor.gotoRange(xTextCursor, false);
103 		xTextCursor.goRight((short) 100, true);
104 		xCursorProps.setPropertyValue("CharFontName", "Bodoni MT Black");
105 		xTextCursor.gotoRange(xTextCursor, false);
106 		xTextCursor.goRight((short) 100, true);
107 		xCursorProps.setPropertyValue("CharFontName", "BatangChe");
108 		xTextCursor.gotoRange(xTextCursor, false);
109 		xTextCursor.goRight((short) 100, true);
110 		xCursorProps.setPropertyValue("CharFontName", "Britannic Bold");
111 		xTextCursor.gotoRange(xTextCursor, false);
112 		xTextCursor.goRight((short) 100, true);
113 		xCursorProps.setPropertyValue("CharFontName", "Cooper Black");
114 		xTextCursor.gotoRange(xTextCursor, false);
115 		xTextCursor.goRight((short) 100, true);
116 		xCursorProps.setPropertyValue("CharFontName", "DaunPenh");
117 		xTextCursor.gotoRange(xTextCursor, false);
118 		xTextCursor.goRight((short) 100, true);
119 		xCursorProps.setPropertyValue("CharFontName", "Estrangelo Edessa");
120 		xTextCursor.gotoRange(xTextCursor, false);
121 		xTextCursor.goRight((short) 100, true);
122 		xCursorProps.setPropertyValue("CharFontName", "Wingdings");
123 		xTextCursor.gotoRange(xTextCursor, false);
124 		xTextCursor.goRight((short) 100, true);
125 		xCursorProps.setPropertyValue("CharFontName", "Rage Italic");
126 		xTextCursor.gotoRange(xTextCursor, false);
127 		xTextCursor.goRight((short) 100, true);
128 		xCursorProps.setPropertyValue("CharFontName", "Symbol");
129 		xTextCursor.gotoRange(xTextCursor, false);
130 		xTextCursor.goRight((short) 100, true);
131 		xCursorProps.setPropertyValue("CharFontName", "Tw Cen MT Condensed Extra Bold");
132 		xTextCursor.gotoRange(xTextCursor, false);
133 		xTextCursor.goRight((short) 100, true);
134 		xCursorProps.setPropertyValue("CharFontName", "Vivaldi");
135 		xTextCursor.gotoRange(xTextCursor, false);
136 		xTextCursor.goRight((short) 100, true);
137 		xCursorProps.setPropertyValue("CharFontName", "SimSun");
138 		xTextCursor.gotoRange(xTextCursor, false);
139 		xTextCursor.goRight((short) 100, true);
140 		xCursorProps.setPropertyValue("CharFontName", "Lucida Bright");
141 		//save to odt
142 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
143 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
144 		aStoreProperties_odt[0] = new PropertyValue();
145 		aStoreProperties_odt[1] = new PropertyValue();
146 		aStoreProperties_odt[0].Name = "Override";
147 		aStoreProperties_odt[0].Value = true;
148 		aStoreProperties_odt[1].Name = "FilterName";
149 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
150 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
151 		//save to doc
152 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
153 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
154 		aStoreProperties_doc[0] = new PropertyValue();
155 		aStoreProperties_doc[1] = new PropertyValue();
156 		aStoreProperties_doc[0].Name = "Override";
157 		aStoreProperties_doc[0].Value = true;
158 		aStoreProperties_doc[1].Name = "FilterName";
159 		aStoreProperties_doc[1].Value = "MS Word 97";
160 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
161 		app.closeDocument(xTextDocument);
162 
163 		//reopen the document and assert font style
164 		XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
165 		XTextCursor xTextCursor_assert = assertDocument.getText().createTextCursor();
166 		XPropertySet xCursorProps_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert);
167 
168 		xTextCursor_assert.gotoStart(false);
169 		xTextCursor_assert.goRight((short) 100, true);
170 		assertEquals("Times New Roman",xCursorProps_assert.getPropertyValue("CharFontName"));
171 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
172 		xTextCursor_assert.goRight((short) 100, true);
173 		assertEquals("Arial Black",xCursorProps_assert.getPropertyValue("CharFontName"));
174 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
175 		xTextCursor_assert.goRight((short) 100, true);
176 		assertEquals("Aharoni",xCursorProps_assert.getPropertyValue("CharFontName"));
177 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
178 		xTextCursor_assert.goRight((short) 100, true);
179 		assertEquals("Agency FB",xCursorProps_assert.getPropertyValue("CharFontName"));
180 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
181 		xTextCursor_assert.goRight((short) 100, true);
182 		assertEquals("Algerian",xCursorProps_assert.getPropertyValue("CharFontName"));
183 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
184 		xTextCursor_assert.goRight((short) 100, true);
185 		assertEquals("Andalus",xCursorProps_assert.getPropertyValue("CharFontName"));
186 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
187 		xTextCursor_assert.goRight((short) 100, true);
188 		assertEquals("Bodoni MT Black",xCursorProps_assert.getPropertyValue("CharFontName"));
189 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
190 		xTextCursor_assert.goRight((short) 100, true);
191 		assertEquals("BatangChe",xCursorProps_assert.getPropertyValue("CharFontName"));
192 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
193 		xTextCursor_assert.goRight((short) 100, true);
194 		assertEquals("Britannic Bold",xCursorProps_assert.getPropertyValue("CharFontName"));
195 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
196 		xTextCursor_assert.goRight((short) 100, true);
197 		assertEquals("Cooper Black",xCursorProps_assert.getPropertyValue("CharFontName"));
198 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
199 		xTextCursor_assert.goRight((short) 100, true);
200 		assertEquals("DaunPenh",xCursorProps_assert.getPropertyValue("CharFontName"));
201 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
202 		xTextCursor_assert.goRight((short) 100, true);
203 		assertEquals("Estrangelo Edessa",xCursorProps_assert.getPropertyValue("CharFontName"));
204 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
205 		xTextCursor_assert.goRight((short) 100, true);
206 		assertEquals("Wingdings",xCursorProps_assert.getPropertyValue("CharFontName"));
207 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
208 		xTextCursor_assert.goRight((short) 100, true);
209 		assertEquals("Rage Italic",xCursorProps_assert.getPropertyValue("CharFontName"));
210 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
211 		xTextCursor_assert.goRight((short) 100, true);
212 		assertEquals("Symbol",xCursorProps_assert.getPropertyValue("CharFontName"));
213 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
214 		xTextCursor_assert.goRight((short) 100, true);
215 		assertEquals("Tw Cen MT Condensed Extra Bold",xCursorProps_assert.getPropertyValue("CharFontName"));
216 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
217 		xTextCursor_assert.goRight((short) 100, true);
218 		assertEquals("Vivaldi",xCursorProps_assert.getPropertyValue("CharFontName"));
219 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
220 		xTextCursor_assert.goRight((short) 100, true);
221 		assertEquals("SimSun",xCursorProps_assert.getPropertyValue("CharFontName"));
222 		xTextCursor_assert.gotoRange(xTextCursor_assert, false);
223 		xTextCursor_assert.goRight((short) 100, true);
224 		assertEquals("Lucida Bright",xCursorProps_assert.getPropertyValue("CharFontName"));
225 
226 		//reopen the document and assert font style
227 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
228 		XTextCursor xTextCursor_assert_doc = assertDocument_doc.getText().createTextCursor();
229 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc);
230 
231 		xTextCursor_assert_doc.gotoStart(false);
232 		xTextCursor_assert_doc.goRight((short) 100, true);
233 		assertEquals("Times New Roman",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
234 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
235 		xTextCursor_assert_doc.goRight((short) 100, true);
236 		assertEquals("Arial Black",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
237 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
238 		xTextCursor_assert_doc.goRight((short) 100, true);
239 		assertEquals("Aharoni",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
240 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
241 		xTextCursor_assert_doc.goRight((short) 100, true);
242 		assertEquals("Agency FB",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
243 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
244 		xTextCursor_assert_doc.goRight((short) 100, true);
245 		assertEquals("Algerian",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
246 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
247 		xTextCursor_assert_doc.goRight((short) 100, true);
248 		assertEquals("Andalus",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
249 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
250 		xTextCursor_assert_doc.goRight((short) 100, true);
251 		assertEquals("Bodoni MT Black",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
252 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
253 		xTextCursor_assert_doc.goRight((short) 100, true);
254 		assertEquals("BatangChe",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
255 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
256 		xTextCursor_assert_doc.goRight((short) 100, true);
257 		assertEquals("Britannic Bold",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
258 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
259 		xTextCursor_assert_doc.goRight((short) 100, true);
260 		assertEquals("Cooper Black",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
261 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
262 		xTextCursor_assert_doc.goRight((short) 100, true);
263 		assertEquals("DaunPenh",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
264 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
265 		xTextCursor_assert_doc.goRight((short) 100, true);
266 		assertEquals("Estrangelo Edessa",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
267 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
268 		xTextCursor_assert_doc.goRight((short) 100, true);
269 		assertEquals("Wingdings",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
270 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
271 		xTextCursor_assert_doc.goRight((short) 100, true);
272 		assertEquals("Rage Italic",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
273 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
274 		xTextCursor_assert_doc.goRight((short) 100, true);
275 		assertEquals("Symbol",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
276 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
277 		xTextCursor_assert_doc.goRight((short) 100, true);
278 		assertEquals("Tw Cen MT Condensed Extra Bold",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
279 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
280 		xTextCursor_assert_doc.goRight((short) 100, true);
281 		assertEquals("Vivaldi",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
282 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
283 		xTextCursor_assert_doc.goRight((short) 100, true);
284 		assertEquals("SimSun",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
285 		xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false);
286 		xTextCursor_assert_doc.goRight((short) 100, true);
287 		assertEquals("Lucida Bright",xCursorProps_assert_doc.getPropertyValue("CharFontName"));
288 	}
289 }
290